Tunnel Mode Playback (Applicable to 4K @ 60 FPS Fire TV Devices Only)
The hardware decoder for some Fire TV devices support playback of 4K @ 60 FPS. To play a video at such high resolution and frame rate, the timing requirement of media pipeline is very aggressive and the app may not be able to render 4K frames at 16 msec interval due to thread and process scheduling limitations of the kernel. This may cause frame drops and a sub-par movie experience. To get the best out of the hardware, use Tunnel Mode playback.
How to Enable Tunnel Mode Playback
The main changes required to enable Tunnel Mode playback are as follows:
Query the AudioTrack session ID from AudioManager:
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int audioSessionId = audioManager.generateAudioSessionId();
Configure Video Decoder for Tunnel mode:
Configure Video decoder with the AudioTrack session ID.
Create AudioTrack with the above queried session ID and set the AudioAttributes flag F
AudioAttributes attributes = new AudioAttributes.Builder() .setLegacyStreamType(AudioManager.STREAM_MUSIC) .setFlags(AudioAttributes.FLAG_HW_AV_SYNC) .build(); AudioFormat format = new AudioFormat.Builder() .setEncoding(targetEncoding) .setSampleRate(sampleRate) .setChannelMask(channelConfig) .build(); int mode = AudioTrack.MODE_STREAM; AudioTrack audioTrack = new AudioTrack(attributes, format, bufferSize, mode, audioSessionId);
Do not call
releaseOutputBufferfor video decoder.
AudioTrack provides a write API that will automatically construct the additional header information. For details see here.
Note: The additional parameter is the timestamp that corresponds with the data being written.
More Details about Tunnel Mode Playback
For more details refer to the Tunnel Mode Playback implementation in Exoplayer 2:
- Enable tunneling end-to-end
- Support tunneling in video renderer
- Report tunneling support via RendererCapabilities API
- Plumbing to enable tunneling on AudioTrack from renderers
Last updated: Jun 01, 2018