1*30877f79SAndroid Build Coastguard Worker# ExoPlayer Opus module 2*30877f79SAndroid Build Coastguard Worker 3*30877f79SAndroid Build Coastguard WorkerThe Opus module provides `LibopusAudioRenderer`, which uses libopus (the Opus 4*30877f79SAndroid Build Coastguard Workerdecoding library) to decode Opus audio. 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 WorkerOPUS_MODULE_PATH="$(pwd)/extensions/opus/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 libopus: 37*30877f79SAndroid Build Coastguard Worker 38*30877f79SAndroid Build Coastguard Worker``` 39*30877f79SAndroid Build Coastguard Workercd "${OPUS_MODULE_PATH}/jni" && \ 40*30877f79SAndroid Build Coastguard Workergit clone https://gitlab.xiph.org/xiph/opus.git libopus 41*30877f79SAndroid Build Coastguard Worker``` 42*30877f79SAndroid Build Coastguard Worker 43*30877f79SAndroid Build Coastguard Worker* Run the script to convert arm assembly to NDK compatible format: 44*30877f79SAndroid Build Coastguard Worker 45*30877f79SAndroid Build Coastguard Worker``` 46*30877f79SAndroid Build Coastguard Workercd ${OPUS_MODULE_PATH}/jni && ./convert_android_asm.sh 47*30877f79SAndroid Build Coastguard Worker``` 48*30877f79SAndroid Build Coastguard Worker 49*30877f79SAndroid Build Coastguard Worker* Build the JNI native libraries from the command line: 50*30877f79SAndroid Build Coastguard Worker 51*30877f79SAndroid Build Coastguard Worker``` 52*30877f79SAndroid Build Coastguard Workercd "${OPUS_MODULE_PATH}"/jni && \ 53*30877f79SAndroid Build Coastguard Worker${NDK_PATH}/ndk-build APP_ABI=all -j4 54*30877f79SAndroid Build Coastguard Worker``` 55*30877f79SAndroid Build Coastguard Worker 56*30877f79SAndroid Build Coastguard Worker[top level README]: https://github.com/google/ExoPlayer/blob/release-v2/README.md 57*30877f79SAndroid Build Coastguard Worker[Android NDK]: https://developer.android.com/tools/sdk/ndk/index.html 58*30877f79SAndroid Build Coastguard Worker 59*30877f79SAndroid Build Coastguard Worker## Build instructions (Windows) 60*30877f79SAndroid Build Coastguard Worker 61*30877f79SAndroid Build Coastguard WorkerWe do not provide support for building this module on Windows, however it should 62*30877f79SAndroid Build Coastguard Workerbe possible to follow the Linux instructions in [Windows PowerShell][]. 63*30877f79SAndroid Build Coastguard Worker 64*30877f79SAndroid Build Coastguard Worker[Windows PowerShell]: https://docs.microsoft.com/en-us/powershell/scripting/getting-started/getting-started-with-windows-powershell 65*30877f79SAndroid Build Coastguard Worker 66*30877f79SAndroid Build Coastguard Worker## Notes 67*30877f79SAndroid Build Coastguard Worker 68*30877f79SAndroid Build Coastguard Worker* Every time there is a change to the libopus checkout: 69*30877f79SAndroid Build Coastguard Worker * Arm assembly should be converted by running `convert_android_asm.sh` 70*30877f79SAndroid Build Coastguard Worker * Clean and re-build the project. 71*30877f79SAndroid Build Coastguard Worker* If you want to use your own version of libopus, place it in 72*30877f79SAndroid Build Coastguard Worker `${OPUS_MODULE_PATH}/jni/libopus`. 73*30877f79SAndroid Build Coastguard Worker 74*30877f79SAndroid Build Coastguard Worker## Using the module 75*30877f79SAndroid Build Coastguard Worker 76*30877f79SAndroid Build Coastguard WorkerOnce you've followed the instructions above to check out, build and depend on 77*30877f79SAndroid Build Coastguard Workerthe module, the next step is to tell ExoPlayer to use `LibopusAudioRenderer`. 78*30877f79SAndroid Build Coastguard WorkerHow you do this depends on which player API you're using: 79*30877f79SAndroid Build Coastguard Worker 80*30877f79SAndroid Build Coastguard Worker* If you're passing a `DefaultRenderersFactory` to `ExoPlayer.Builder`, you 81*30877f79SAndroid Build Coastguard Worker can enable using the module by setting the `extensionRendererMode` parameter 82*30877f79SAndroid Build Coastguard Worker of the `DefaultRenderersFactory` constructor to 83*30877f79SAndroid Build Coastguard Worker `EXTENSION_RENDERER_MODE_ON`. This will use `LibopusAudioRenderer` for 84*30877f79SAndroid Build Coastguard Worker playback if `MediaCodecAudioRenderer` doesn't support the input format. Pass 85*30877f79SAndroid Build Coastguard Worker `EXTENSION_RENDERER_MODE_PREFER` to give `LibopusAudioRenderer` priority 86*30877f79SAndroid Build Coastguard Worker over `MediaCodecAudioRenderer`. 87*30877f79SAndroid Build Coastguard Worker* If you've subclassed `DefaultRenderersFactory`, add a `LibopusAudioRenderer` 88*30877f79SAndroid Build Coastguard Worker to the output list in `buildAudioRenderers`. ExoPlayer will use the first 89*30877f79SAndroid Build Coastguard Worker `Renderer` in the list that supports the input media format. 90*30877f79SAndroid Build Coastguard Worker* If you've implemented your own `RenderersFactory`, return a 91*30877f79SAndroid Build Coastguard Worker `LibopusAudioRenderer` instance from `createRenderers`. ExoPlayer will use 92*30877f79SAndroid Build Coastguard Worker the first `Renderer` in the returned array that supports the input media 93*30877f79SAndroid Build Coastguard Worker format. 94*30877f79SAndroid Build Coastguard Worker* If you're using `ExoPlayer.Builder`, pass a `LibopusAudioRenderer` in the 95*30877f79SAndroid Build Coastguard Worker array of `Renderer`s. ExoPlayer will use the first `Renderer` in the list 96*30877f79SAndroid Build Coastguard Worker that supports the input media format. 97*30877f79SAndroid Build Coastguard Worker 98*30877f79SAndroid Build Coastguard WorkerNote: These instructions assume you're using `DefaultTrackSelector`. If you have 99*30877f79SAndroid Build Coastguard Workera custom track selector the choice of `Renderer` is up to your implementation, 100*30877f79SAndroid Build Coastguard Workerso you need to make sure you are passing an `LibopusAudioRenderer` to the 101*30877f79SAndroid Build Coastguard Workerplayer, then implement your own logic to use the renderer for a given track. 102*30877f79SAndroid Build Coastguard Worker 103*30877f79SAndroid Build Coastguard Worker## Using the module in the demo application 104*30877f79SAndroid Build Coastguard Worker 105*30877f79SAndroid Build Coastguard WorkerTo try out playback using the module in the [demo application][], see 106*30877f79SAndroid Build Coastguard Worker[enabling extension decoders][]. 107*30877f79SAndroid Build Coastguard Worker 108*30877f79SAndroid Build Coastguard Worker[demo application]: https://exoplayer.dev/demo-application.html 109*30877f79SAndroid Build Coastguard Worker[enabling extension decoders]: https://exoplayer.dev/demo-application.html#enabling-extension-decoders 110*30877f79SAndroid Build Coastguard Worker 111*30877f79SAndroid Build Coastguard Worker## Links 112*30877f79SAndroid Build Coastguard Worker 113*30877f79SAndroid Build Coastguard Worker* [Javadoc][] 114*30877f79SAndroid Build Coastguard Worker 115*30877f79SAndroid Build Coastguard Worker[Javadoc]: https://exoplayer.dev/doc/reference/index.html 116