1*30877f79SAndroid Build Coastguard Worker# ExoPlayer VP9 module 2*30877f79SAndroid Build Coastguard Worker 3*30877f79SAndroid Build Coastguard WorkerThe VP9 module provides `LibvpxVideoRenderer`, which uses libvpx (the VPx 4*30877f79SAndroid Build Coastguard Workerdecoding library) to decode VP9 video. 5*30877f79SAndroid Build Coastguard Worker 6*30877f79SAndroid Build Coastguard Worker## License note 7*30877f79SAndroid Build Coastguard Worker 8*30877f79SAndroid Build Coastguard WorkerPlease note that whilst the code in this repository is licensed under 9*30877f79SAndroid Build Coastguard Worker[Apache 2.0][], using this module also requires building and including one or 10*30877f79SAndroid Build Coastguard Workermore external libraries as described below. These are licensed separately. 11*30877f79SAndroid Build Coastguard Worker 12*30877f79SAndroid Build Coastguard Worker[Apache 2.0]: https://github.com/google/ExoPlayer/blob/release-v2/LICENSE 13*30877f79SAndroid Build Coastguard Worker 14*30877f79SAndroid Build Coastguard Worker## Build instructions (Linux, macOS) 15*30877f79SAndroid Build Coastguard Worker 16*30877f79SAndroid Build Coastguard WorkerTo use the module you need to clone this GitHub project and depend on its 17*30877f79SAndroid Build Coastguard Workermodules locally. Instructions for doing this can be found in the 18*30877f79SAndroid Build Coastguard Worker[top level README][]. 19*30877f79SAndroid Build Coastguard Worker 20*30877f79SAndroid Build Coastguard WorkerIn addition, it's necessary to build the module's native components as follows: 21*30877f79SAndroid Build Coastguard Worker 22*30877f79SAndroid Build Coastguard Worker* Set the following environment variables: 23*30877f79SAndroid Build Coastguard Worker 24*30877f79SAndroid Build Coastguard Worker``` 25*30877f79SAndroid Build Coastguard Workercd "<path to project checkout>" 26*30877f79SAndroid Build Coastguard WorkerVP9_MODULE_PATH="$(pwd)/extensions/vp9/src/main" 27*30877f79SAndroid Build Coastguard Worker``` 28*30877f79SAndroid Build Coastguard Worker 29*30877f79SAndroid Build Coastguard Worker* Download the [Android NDK][] and set its location in an environment variable. 30*30877f79SAndroid Build Coastguard Worker This build configuration has been tested on NDK r21. 31*30877f79SAndroid Build Coastguard Worker 32*30877f79SAndroid Build Coastguard Worker``` 33*30877f79SAndroid Build Coastguard WorkerNDK_PATH="<path to Android NDK>" 34*30877f79SAndroid Build Coastguard Worker``` 35*30877f79SAndroid Build Coastguard Worker 36*30877f79SAndroid Build Coastguard Worker* Fetch an appropriate branch of libvpx. We cannot guarantee compatibility 37*30877f79SAndroid Build Coastguard Worker with all versions of libvpx. We currently recommend version 1.8.0: 38*30877f79SAndroid Build Coastguard Worker 39*30877f79SAndroid Build Coastguard Worker``` 40*30877f79SAndroid Build Coastguard Workercd "<preferred location for libvpx>" && \ 41*30877f79SAndroid Build Coastguard Workergit clone https://chromium.googlesource.com/webm/libvpx && \ 42*30877f79SAndroid Build Coastguard Workercd libvpx && \ 43*30877f79SAndroid Build Coastguard Workergit checkout tags/v1.8.0 -b v1.8.0 && \ 44*30877f79SAndroid Build Coastguard WorkerLIBVPX_PATH="$(pwd)" 45*30877f79SAndroid Build Coastguard Worker``` 46*30877f79SAndroid Build Coastguard Worker 47*30877f79SAndroid Build Coastguard Worker* Add a link to the libvpx source code in the vp9 module `jni` directory and 48*30877f79SAndroid Build Coastguard Worker run a script that generates necessary configuration files for libvpx: 49*30877f79SAndroid Build Coastguard Worker 50*30877f79SAndroid Build Coastguard Worker``` 51*30877f79SAndroid Build Coastguard Workercd ${VP9_MODULE_PATH}/jni && \ 52*30877f79SAndroid Build Coastguard Workerln -s "$LIBVPX_PATH" libvpx && \ 53*30877f79SAndroid Build Coastguard Worker./generate_libvpx_android_configs.sh 54*30877f79SAndroid Build Coastguard Worker``` 55*30877f79SAndroid Build Coastguard Worker 56*30877f79SAndroid Build Coastguard Worker* Build the JNI native libraries from the command line: 57*30877f79SAndroid Build Coastguard Worker 58*30877f79SAndroid Build Coastguard Worker``` 59*30877f79SAndroid Build Coastguard Workercd "${VP9_MODULE_PATH}"/jni && \ 60*30877f79SAndroid Build Coastguard Worker${NDK_PATH}/ndk-build APP_ABI=all -j4 61*30877f79SAndroid Build Coastguard Worker``` 62*30877f79SAndroid Build Coastguard Worker 63*30877f79SAndroid Build Coastguard Worker[top level README]: https://github.com/google/ExoPlayer/blob/release-v2/README.md 64*30877f79SAndroid Build Coastguard Worker[Android NDK]: https://developer.android.com/tools/sdk/ndk/index.html 65*30877f79SAndroid Build Coastguard Worker 66*30877f79SAndroid Build Coastguard Worker## Build instructions (Windows) 67*30877f79SAndroid Build Coastguard Worker 68*30877f79SAndroid Build Coastguard WorkerWe do not provide support for building this module on Windows, however it should 69*30877f79SAndroid Build Coastguard Workerbe possible to follow the Linux instructions in [Windows PowerShell][]. 70*30877f79SAndroid Build Coastguard Worker 71*30877f79SAndroid Build Coastguard Worker[Windows PowerShell]: https://docs.microsoft.com/en-us/powershell/scripting/getting-started/getting-started-with-windows-powershell 72*30877f79SAndroid Build Coastguard Worker 73*30877f79SAndroid Build Coastguard Worker## Notes 74*30877f79SAndroid Build Coastguard Worker 75*30877f79SAndroid Build Coastguard Worker* Every time there is a change to the libvpx checkout: 76*30877f79SAndroid Build Coastguard Worker * Android config scripts should be re-generated by running 77*30877f79SAndroid Build Coastguard Worker `generate_libvpx_android_configs.sh` 78*30877f79SAndroid Build Coastguard Worker * Clean and re-build the project. 79*30877f79SAndroid Build Coastguard Worker* If you want to use your own version of libvpx, point to it with the 80*30877f79SAndroid Build Coastguard Worker `${VP9_MODULE_PATH}/jni/libvpx` symlink. Please note that 81*30877f79SAndroid Build Coastguard Worker `generate_libvpx_android_configs.sh` and the makefiles may need to be modified 82*30877f79SAndroid Build Coastguard Worker to work with arbitrary versions of libvpx. 83*30877f79SAndroid Build Coastguard Worker 84*30877f79SAndroid Build Coastguard Worker## Using the module 85*30877f79SAndroid Build Coastguard Worker 86*30877f79SAndroid Build Coastguard WorkerOnce you've followed the instructions above to check out, build and depend on 87*30877f79SAndroid Build Coastguard Workerthe module, the next step is to tell ExoPlayer to use `LibvpxVideoRenderer`. 88*30877f79SAndroid Build Coastguard WorkerHow you do this depends on which player API you're using: 89*30877f79SAndroid Build Coastguard Worker 90*30877f79SAndroid Build Coastguard Worker* If you're passing a `DefaultRenderersFactory` to `ExoPlayer.Builder`, you 91*30877f79SAndroid Build Coastguard Worker can enable using the module by setting the `extensionRendererMode` parameter 92*30877f79SAndroid Build Coastguard Worker of the `DefaultRenderersFactory` constructor to 93*30877f79SAndroid Build Coastguard Worker `EXTENSION_RENDERER_MODE_ON`. This will use `LibvpxVideoRenderer` for 94*30877f79SAndroid Build Coastguard Worker playback if `MediaCodecVideoRenderer` doesn't support decoding the input VP9 95*30877f79SAndroid Build Coastguard Worker stream. Pass `EXTENSION_RENDERER_MODE_PREFER` to give `LibvpxVideoRenderer` 96*30877f79SAndroid Build Coastguard Worker priority over `MediaCodecVideoRenderer`. 97*30877f79SAndroid Build Coastguard Worker* If you've subclassed `DefaultRenderersFactory`, add a `LibvpxVideoRenderer` 98*30877f79SAndroid Build Coastguard Worker to the output list in `buildVideoRenderers`. ExoPlayer will use the first 99*30877f79SAndroid Build Coastguard Worker `Renderer` in the list that supports the input media format. 100*30877f79SAndroid Build Coastguard Worker* If you've implemented your own `RenderersFactory`, return a 101*30877f79SAndroid Build Coastguard Worker `LibvpxVideoRenderer` instance from `createRenderers`. ExoPlayer will use 102*30877f79SAndroid Build Coastguard Worker the first `Renderer` in the returned array that supports the input media 103*30877f79SAndroid Build Coastguard Worker format. 104*30877f79SAndroid Build Coastguard Worker* If you're using `ExoPlayer.Builder`, pass a `LibvpxVideoRenderer` in the 105*30877f79SAndroid Build Coastguard Worker array of `Renderer`s. ExoPlayer will use the first `Renderer` in the list 106*30877f79SAndroid Build Coastguard Worker that supports the input media format. 107*30877f79SAndroid Build Coastguard Worker 108*30877f79SAndroid Build Coastguard WorkerNote: These instructions assume you're using `DefaultTrackSelector`. If you have 109*30877f79SAndroid Build Coastguard Workera custom track selector the choice of `Renderer` is up to your implementation, 110*30877f79SAndroid Build Coastguard Workerso you need to make sure you are passing an `LibvpxVideoRenderer` to the 111*30877f79SAndroid Build Coastguard Workerplayer, then implement your own logic to use the renderer for a given track. 112*30877f79SAndroid Build Coastguard Worker 113*30877f79SAndroid Build Coastguard Worker## Using the module in the demo application 114*30877f79SAndroid Build Coastguard Worker 115*30877f79SAndroid Build Coastguard WorkerTo try out playback using the module in the [demo application][], see 116*30877f79SAndroid Build Coastguard Worker[enabling extension decoders][]. 117*30877f79SAndroid Build Coastguard Worker 118*30877f79SAndroid Build Coastguard Worker[demo application]: https://exoplayer.dev/demo-application.html 119*30877f79SAndroid Build Coastguard Worker[enabling extension decoders]: https://exoplayer.dev/demo-application.html#enabling-extension-decoders 120*30877f79SAndroid Build Coastguard Worker 121*30877f79SAndroid Build Coastguard Worker## Rendering options 122*30877f79SAndroid Build Coastguard Worker 123*30877f79SAndroid Build Coastguard WorkerThere are two possibilities for rendering the output `LibvpxVideoRenderer` 124*30877f79SAndroid Build Coastguard Workergets from the libvpx decoder: 125*30877f79SAndroid Build Coastguard Worker 126*30877f79SAndroid Build Coastguard Worker* GL rendering using GL shader for color space conversion 127*30877f79SAndroid Build Coastguard Worker 128*30877f79SAndroid Build Coastguard Worker * If you are using `ExoPlayer` with `PlayerView` or 129*30877f79SAndroid Build Coastguard Worker `StyledPlayerView`, enable this option by setting `surface_type` of view 130*30877f79SAndroid Build Coastguard Worker to be `video_decoder_gl_surface_view`. 131*30877f79SAndroid Build Coastguard Worker * Otherwise, enable this option by sending `LibvpxVideoRenderer` a message 132*30877f79SAndroid Build Coastguard Worker of type `Renderer.MSG_SET_VIDEO_OUTPUT` with an instance of 133*30877f79SAndroid Build Coastguard Worker `VideoDecoderOutputBufferRenderer` as its object. 134*30877f79SAndroid Build Coastguard Worker `VideoDecoderGLSurfaceView` is the concrete 135*30877f79SAndroid Build Coastguard Worker `VideoDecoderOutputBufferRenderer` implementation used by 136*30877f79SAndroid Build Coastguard Worker `PlayerView` and `StyledPlayerView`. 137*30877f79SAndroid Build Coastguard Worker 138*30877f79SAndroid Build Coastguard Worker* Native rendering using `ANativeWindow` 139*30877f79SAndroid Build Coastguard Worker 140*30877f79SAndroid Build Coastguard Worker * If you are using `ExoPlayer` with `PlayerView` or 141*30877f79SAndroid Build Coastguard Worker `StyledPlayerView`, this option is enabled by default. 142*30877f79SAndroid Build Coastguard Worker * Otherwise, enable this option by sending `LibvpxVideoRenderer` a message 143*30877f79SAndroid Build Coastguard Worker of type `Renderer.MSG_SET_VIDEO_OUTPUT` with an instance of 144*30877f79SAndroid Build Coastguard Worker `SurfaceView` as its object. 145*30877f79SAndroid Build Coastguard Worker 146*30877f79SAndroid Build Coastguard WorkerNote: Although the default option uses `ANativeWindow`, based on our testing the 147*30877f79SAndroid Build Coastguard WorkerGL rendering mode has better performance, so should be preferred. 148*30877f79SAndroid Build Coastguard Worker 149*30877f79SAndroid Build Coastguard Worker## Links 150*30877f79SAndroid Build Coastguard Worker 151*30877f79SAndroid Build Coastguard Worker* [Javadoc][] 152*30877f79SAndroid Build Coastguard Worker 153*30877f79SAndroid Build Coastguard Worker[Javadoc]: https://exoplayer.dev/doc/reference/index.html 154