mirror of
https://github.com/samsonjs/media.git
synced 2026-03-27 09:45:47 +00:00
Add Opus Native Extension
Add Opus Native Extension that can be used to playback Opus using the native libopus library.
This commit is contained in:
parent
dd726001a8
commit
7113d2ab6f
17 changed files with 1569 additions and 0 deletions
131
extensions/opus/README.md
Normal file
131
extensions/opus/README.md
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
# ExoPlayer Opus Extension #
|
||||
|
||||
## Description ##
|
||||
|
||||
The Opus Extension is a [Track Renderer][] implementation that helps you bundle libopus (the Opus decoding library) into your app and use it along with ExoPlayer to play Opus audio on Android devices.
|
||||
|
||||
[Track Renderer]: http://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer/TrackRenderer.html
|
||||
|
||||
## Build Instructions (Android Studio and Eclipse) ##
|
||||
|
||||
Building the Opus Extension involves building libopus and JNI bindings using the Android NDK and linking it into your app. The following steps will tell you how to do that using Android Studio or Eclipse.
|
||||
|
||||
* Checkout ExoPlayer along with Extensions
|
||||
|
||||
```
|
||||
git clone https://github.com/google/ExoPlayer.git
|
||||
```
|
||||
|
||||
* Set the following environment variables:
|
||||
|
||||
```
|
||||
cd "<path to exoplayer checkout>"
|
||||
EXOPLAYER_ROOT="$(pwd)"
|
||||
OPUS_EXT_PATH="${EXOPLAYER_ROOT}/extensions/opus/src/main"
|
||||
```
|
||||
|
||||
* Download the [Android NDK][] and set its location in an environment variable:
|
||||
|
||||
```
|
||||
NDK_PATH="<path to Android NDK>"
|
||||
```
|
||||
|
||||
* Fetch libopus
|
||||
|
||||
```
|
||||
cd "${OPUS_EXT_PATH}/jni" && \
|
||||
git clone git://git.opus-codec.org/opus.git libopus
|
||||
```
|
||||
|
||||
* Run the script to convert arm assembly to NDK compatible format
|
||||
|
||||
```
|
||||
cd ${OPUS_EXT_PATH}/jni && ./convert_android_asm.sh
|
||||
```
|
||||
|
||||
### Android Studio ###
|
||||
|
||||
For Android Studio, we build the native libraries from the command line and then Gradle will pick it up when building your app using Android Studio.
|
||||
|
||||
* Build the JNI native libraries
|
||||
|
||||
```
|
||||
cd "${OPUS_EXT_PATH}"/jni && \
|
||||
${NDK_PATH}/ndk-build APP_ABI=all -j4
|
||||
```
|
||||
|
||||
* In your project, you can add a dependency to the Opus Extension by using a rule like this:
|
||||
|
||||
```
|
||||
// in settings.gradle
|
||||
include ':..:ExoPlayer:library'
|
||||
include ':..:ExoPlayer:opus-extension'
|
||||
|
||||
// in build.gradle
|
||||
dependencies {
|
||||
compile project(':..:ExoPlayer:library')
|
||||
compile project(':..:ExoPlayer:opus-extension')
|
||||
}
|
||||
```
|
||||
|
||||
* Now, when you build your app, the Opus extension will be built and the native libraries will be packaged along with the APK.
|
||||
|
||||
### Eclipse ###
|
||||
|
||||
* The following steps assume that you have installed Eclipse and configured it with the [Android SDK][] and [Android NDK ][]:
|
||||
* Navigate to File->Import->General->Existing Projects into Workspace
|
||||
* Select the root directory of the repository
|
||||
* Import the following projects:
|
||||
* ExoPlayerLib
|
||||
* ExoPlayerExt-Opus
|
||||
* If you are able to build ExoPlayerExt-Opus project, then you're all set.
|
||||
* (Optional) To speed up the NDK build:
|
||||
* Right click on ExoPlayerExt-Opus in the Project Explorer pane and choose Properties
|
||||
* Click on C/C++ Build
|
||||
* Uncheck `Use default build command`
|
||||
* In `Build Command` enter: `ndk-build -j4` (adjust 4 to a reasonable number depending on the number of cores in your computer)
|
||||
* Click Apply
|
||||
|
||||
You can now create your own Android App project and add ExoPlayerLib along with ExoPlayerExt-Opus as a dependencies to use ExoPlayer along with the Opus Extension.
|
||||
|
||||
|
||||
[Android NDK]: https://developer.android.com/tools/sdk/ndk/index.html
|
||||
<!---
|
||||
Work around to point to two different links for the same text.
|
||||
-->
|
||||
[Android NDK ]: http://tools.android.com/recent/usingthendkplugin
|
||||
[Android SDK]: http://developer.android.com/sdk/installing/index.html?pkg=tools
|
||||
|
||||
## Building for various Architectures ##
|
||||
|
||||
### Android Studio ###
|
||||
|
||||
The manual invocation of `ndk-build` will build the library for all architectures and the correct one will be picked up from the APK based on the device its running on.
|
||||
|
||||
### Eclipse ###
|
||||
|
||||
libopus can be built for the following architectures:
|
||||
|
||||
* armeabi (the default - does not include neon optimizations)
|
||||
* armeabi-v7a (choose this to enable neon optimizations)
|
||||
* mips
|
||||
* x86
|
||||
* all (will result in a larger binary but will cover all architectures)
|
||||
|
||||
You can build for a specific architecture in two ways:
|
||||
|
||||
* Method 1 (edit `Application.mk`)
|
||||
* Edit `${OPUS_EXT_PATH}/jni/Application.mk` and add the following line `APP_ABI := <arch>` (where `<arch>` is one of the above 4 architectures)
|
||||
* Method 2 (pass NDK build flag)
|
||||
* Right click on ExoPlayerExt-Opus in the Project Explorer pane and choose Properties
|
||||
* Click on C/C++ Build
|
||||
* Uncheck `Use default build command`
|
||||
* In `Build Command` enter: `ndk-build APP_ABI=<arch>` (where `<arch>` is one of the above 4 architectures)
|
||||
* Click Apply
|
||||
|
||||
## Other Things to Note ##
|
||||
|
||||
* Every time there is a change to the libopus checkout:
|
||||
* Arm assembly should be converted by running `convert_android_asm.sh`
|
||||
* Clean and re-build the project.
|
||||
* If you want to use your own version of libopus, place it in `${OPUS_EXT_PATH}/jni/libopus`.
|
||||
45
extensions/opus/build.gradle
Normal file
45
extensions/opus/build.gradle
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 21
|
||||
buildToolsVersion "21.1.2"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 21
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
jniLibs.srcDir 'src/main/libs'
|
||||
jni.srcDirs = [] // Disable the automatic ndk-build call by Android Studio.
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':library')
|
||||
}
|
||||
|
||||
10
extensions/opus/src/main/.classpath
Normal file
10
extensions/opus/src/main/.classpath
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="src" path="java"/>
|
||||
<classpathentry kind="src" path="/ExoPlayerLib"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
57
extensions/opus/src/main/.cproject
Normal file
57
extensions/opus/src/main/.cproject
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="com.android.toolchain.gcc.423224913">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.android.toolchain.gcc.423224913" moduleId="org.eclipse.cdt.core.settings" name="Default">
|
||||
<externalSettings/>
|
||||
<extensions>
|
||||
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildProperties="" description="" id="com.android.toolchain.gcc.423224913" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
|
||||
<folderInfo id="com.android.toolchain.gcc.423224913.1376674556" name="/" resourcePath="">
|
||||
<toolChain id="com.android.toolchain.gcc.1798416430" name="Android GCC" superClass="com.android.toolchain.gcc">
|
||||
<targetPlatform binaryParser="org.eclipse.cdt.core.ELF" id="com.android.targetPlatform.1132129264" isAbstract="false" superClass="com.android.targetPlatform"/>
|
||||
<builder buildPath="${workspace_loc:/ExoPlayerExt-Opus}/jni" id="com.android.builder.532503968" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Android Builder" superClass="com.android.builder">
|
||||
<outputEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="obj"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="libs"/>
|
||||
</outputEntries>
|
||||
</builder>
|
||||
<tool id="com.android.gcc.compiler.906450637" name="Android GCC Compiler" superClass="com.android.gcc.compiler">
|
||||
<inputType id="com.android.gcc.inputType.835889068" superClass="com.android.gcc.inputType"/>
|
||||
</tool>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="jni"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="ExoPlayerExt-Opus.null.1840202624" name="ExoPlayerExt-Opus"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="com.android.toolchain.gcc.423224913;com.android.toolchain.gcc.423224913.1376674556;com.android.gcc.compiler.906450637;com.android.gcc.inputType.835889068">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.android.AndroidPerProjectProfile"/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="refreshScope" versionNumber="2">
|
||||
<configuration configurationName="Default">
|
||||
<resource resourceType="PROJECT" workspacePath="/ExoPlayerExt-Opus"/>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
</cproject>
|
||||
97
extensions/opus/src/main/.project
Normal file
97
extensions/opus/src/main/.project
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ExoPlayerExt-Opus</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>?children?</key>
|
||||
<value>?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|?name?=entry\\\\\\\|\\\|\||</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>?name?</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.append_environment</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildArguments</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildCommand</key>
|
||||
<value>ndk-build</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
|
||||
<value>clean</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.contents</key>
|
||||
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
|
||||
<value>false</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.stopOnError</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
22
extensions/opus/src/main/AndroidManifest.xml
Normal file
22
extensions/opus/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2014 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.google.android.exoplayer.ext.opus">
|
||||
|
||||
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21"/>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,442 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.ext.opus;
|
||||
|
||||
import com.google.android.exoplayer.ExoPlaybackException;
|
||||
import com.google.android.exoplayer.ExoPlayer;
|
||||
import com.google.android.exoplayer.MediaFormat;
|
||||
import com.google.android.exoplayer.MediaFormatHolder;
|
||||
import com.google.android.exoplayer.SampleSource;
|
||||
import com.google.android.exoplayer.TrackRenderer;
|
||||
import com.google.android.exoplayer.audio.AudioTrack;
|
||||
import com.google.android.exoplayer.ext.opus.OpusDecoderWrapper.InputBuffer;
|
||||
import com.google.android.exoplayer.ext.opus.OpusDecoderWrapper.OutputBuffer;
|
||||
import com.google.android.exoplayer.util.MimeTypes;
|
||||
|
||||
import android.os.Handler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Decodes and renders audio using the native Opus decoder.
|
||||
*
|
||||
* @author vigneshv@google.com (Vignesh Venkatasubramanian)
|
||||
*/
|
||||
public class LibopusAudioTrackRenderer extends TrackRenderer {
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be notified of {@link LibopusAudioTrackRenderer} events.
|
||||
*/
|
||||
public interface EventListener {
|
||||
|
||||
/**
|
||||
* Invoked when the {@link AudioTrack} fails to initialize.
|
||||
*
|
||||
* @param e The corresponding exception.
|
||||
*/
|
||||
void onAudioTrackInitializationError(AudioTrack.InitializationException e);
|
||||
|
||||
/**
|
||||
* Invoked when an {@link AudioTrack} write fails.
|
||||
*
|
||||
* @param e The corresponding exception.
|
||||
*/
|
||||
void onAudioTrackWriteError(AudioTrack.WriteException e);
|
||||
|
||||
/**
|
||||
* Invoked when decoding fails.
|
||||
*
|
||||
* @param e The corresponding exception.
|
||||
*/
|
||||
void onDecoderError(OpusDecoderException e);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of a message that can be passed to an instance of this class via
|
||||
* {@link ExoPlayer#sendMessage} or {@link ExoPlayer#blockingSendMessage}. The message object
|
||||
* should be a {@link Float} with 0 being silence and 1 being unity gain.
|
||||
*/
|
||||
public static final int MSG_SET_VOLUME = 1;
|
||||
|
||||
private final SampleSource source;
|
||||
private final Handler eventHandler;
|
||||
private final EventListener eventListener;
|
||||
private final MediaFormatHolder formatHolder;
|
||||
|
||||
private MediaFormat format;
|
||||
private OpusDecoderWrapper decoder;
|
||||
private InputBuffer inputBuffer;
|
||||
private OutputBuffer outputBuffer;
|
||||
|
||||
private int trackIndex;
|
||||
private long currentPositionUs;
|
||||
private boolean inputStreamEnded;
|
||||
private boolean outputStreamEnded;
|
||||
private boolean sourceIsReady;
|
||||
private boolean notifyDiscontinuityToDecoder;
|
||||
|
||||
private AudioTrack audioTrack;
|
||||
private int audioSessionId;
|
||||
|
||||
/**
|
||||
* @param source The upstream source from which the renderer obtains samples.
|
||||
*/
|
||||
public LibopusAudioTrackRenderer(SampleSource source) {
|
||||
this(source, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param source The upstream source from which the renderer obtains samples.
|
||||
* @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
|
||||
* null if delivery of events is not required.
|
||||
* @param eventListener A listener of events. May be null if delivery of events is not required.
|
||||
*/
|
||||
public LibopusAudioTrackRenderer(SampleSource source, Handler eventHandler,
|
||||
EventListener eventListener) {
|
||||
this.source = source;
|
||||
this.eventHandler = eventHandler;
|
||||
this.eventListener = eventListener;
|
||||
this.audioSessionId = AudioTrack.SESSION_ID_NOT_SET;
|
||||
this.audioTrack = new AudioTrack();
|
||||
formatHolder = new MediaFormatHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isTimeSource() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doPrepare() throws ExoPlaybackException {
|
||||
try {
|
||||
boolean sourcePrepared = source.prepare();
|
||||
if (!sourcePrepared) {
|
||||
return TrackRenderer.STATE_UNPREPARED;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ExoPlaybackException(e);
|
||||
}
|
||||
|
||||
for (int i = 0; i < source.getTrackCount(); i++) {
|
||||
if (source.getTrackInfo(i).mimeType.equalsIgnoreCase(MimeTypes.AUDIO_OPUS)
|
||||
|| source.getTrackInfo(i).mimeType.equalsIgnoreCase(MimeTypes.AUDIO_WEBM)) {
|
||||
trackIndex = i;
|
||||
return TrackRenderer.STATE_PREPARED;
|
||||
}
|
||||
}
|
||||
|
||||
return TrackRenderer.STATE_IGNORE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doSomeWork(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
|
||||
if (outputStreamEnded) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
sourceIsReady = source.continueBuffering(positionUs);
|
||||
checkForDiscontinuity();
|
||||
if (format == null) {
|
||||
readFormat();
|
||||
} else {
|
||||
// Create the decoder.
|
||||
if (decoder == null) {
|
||||
// For opus, the format can contain upto 3 entries in initializationData in the following
|
||||
// exact order:
|
||||
// 1) Opus Header Information (required)
|
||||
// 2) Codec Delay in nanoseconds (required if Seek Preroll is present)
|
||||
// 3) Seek Preroll in nanoseconds (required if Codec Delay is present)
|
||||
List<byte[]> initializationData = format.initializationData;
|
||||
if (initializationData.size() < 1) {
|
||||
throw new ExoPlaybackException("Missing initialization data");
|
||||
}
|
||||
long codecDelayNs = -1;
|
||||
long seekPreRollNs = -1;
|
||||
if (initializationData.size() == 3) {
|
||||
if (initializationData.get(1).length != Long.SIZE
|
||||
|| initializationData.get(2).length != Long.SIZE) {
|
||||
throw new ExoPlaybackException("Invalid Codec Delay or Seek Preroll");
|
||||
}
|
||||
codecDelayNs = ByteBuffer.wrap(initializationData.get(1)).getLong();
|
||||
seekPreRollNs = ByteBuffer.wrap(initializationData.get(2)).getLong();
|
||||
}
|
||||
decoder =
|
||||
new OpusDecoderWrapper(initializationData.get(0), codecDelayNs, seekPreRollNs);
|
||||
decoder.start();
|
||||
}
|
||||
renderBuffer();
|
||||
|
||||
// Queue input buffers.
|
||||
while (feedInputBuffer()) {}
|
||||
}
|
||||
} catch (AudioTrack.InitializationException e) {
|
||||
notifyAudioTrackInitializationError(e);
|
||||
throw new ExoPlaybackException(e);
|
||||
} catch (AudioTrack.WriteException e) {
|
||||
notifyAudioTrackWriteError(e);
|
||||
throw new ExoPlaybackException(e);
|
||||
} catch (OpusDecoderException e) {
|
||||
notifyDecoderError(e);
|
||||
throw new ExoPlaybackException(e);
|
||||
} catch (IOException e) {
|
||||
throw new ExoPlaybackException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderBuffer() throws OpusDecoderException, AudioTrack.InitializationException,
|
||||
AudioTrack.WriteException {
|
||||
if (outputStreamEnded) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (outputBuffer == null) {
|
||||
outputBuffer = decoder.dequeueOutputBuffer();
|
||||
if (outputBuffer == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (outputBuffer.getFlag(OpusDecoderWrapper.FLAG_END_OF_STREAM)) {
|
||||
outputStreamEnded = true;
|
||||
decoder.releaseOutputBuffer(outputBuffer);
|
||||
outputBuffer = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!audioTrack.isInitialized()) {
|
||||
if (audioSessionId != AudioTrack.SESSION_ID_NOT_SET) {
|
||||
audioTrack.initialize(audioSessionId);
|
||||
} else {
|
||||
audioSessionId = audioTrack.initialize();
|
||||
}
|
||||
if (getState() == TrackRenderer.STATE_STARTED) {
|
||||
audioTrack.play();
|
||||
}
|
||||
}
|
||||
|
||||
int handleBufferResult;
|
||||
handleBufferResult = audioTrack.handleBuffer(outputBuffer.data,
|
||||
outputBuffer.data.position(), outputBuffer.size, outputBuffer.timestampUs);
|
||||
|
||||
// If we are out of sync, allow currentPositionUs to jump backwards.
|
||||
if ((handleBufferResult & AudioTrack.RESULT_POSITION_DISCONTINUITY) != 0) {
|
||||
currentPositionUs = Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
// Release the buffer if it was consumed.
|
||||
if ((handleBufferResult & AudioTrack.RESULT_BUFFER_CONSUMED) != 0) {
|
||||
decoder.releaseOutputBuffer(outputBuffer);
|
||||
outputBuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean feedInputBuffer() throws IOException, OpusDecoderException {
|
||||
if (inputStreamEnded) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inputBuffer == null) {
|
||||
inputBuffer = decoder.getInputBuffer();
|
||||
if (inputBuffer == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int result = source.readData(trackIndex, currentPositionUs, formatHolder,
|
||||
inputBuffer.sampleHolder, false);
|
||||
if (result == SampleSource.NOTHING_READ) {
|
||||
return false;
|
||||
}
|
||||
if (result == SampleSource.DISCONTINUITY_READ) {
|
||||
flushDecoder();
|
||||
return true;
|
||||
}
|
||||
if (result == SampleSource.FORMAT_READ) {
|
||||
format = formatHolder.format;
|
||||
return true;
|
||||
}
|
||||
if (result == SampleSource.END_OF_STREAM) {
|
||||
inputBuffer.setFlag(OpusDecoderWrapper.FLAG_END_OF_STREAM);
|
||||
decoder.queueInputBuffer(inputBuffer);
|
||||
inputBuffer = null;
|
||||
inputStreamEnded = true;
|
||||
return false;
|
||||
}
|
||||
if (notifyDiscontinuityToDecoder) {
|
||||
notifyDiscontinuityToDecoder = false;
|
||||
inputBuffer.setFlag(OpusDecoderWrapper.FLAG_RESET_DECODER);
|
||||
}
|
||||
|
||||
decoder.queueInputBuffer(inputBuffer);
|
||||
inputBuffer = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void checkForDiscontinuity() throws IOException {
|
||||
if (decoder == null) {
|
||||
return;
|
||||
}
|
||||
int result = source.readData(trackIndex, currentPositionUs, formatHolder, null, true);
|
||||
if (result == SampleSource.DISCONTINUITY_READ) {
|
||||
flushDecoder();
|
||||
}
|
||||
}
|
||||
|
||||
private void flushDecoder() {
|
||||
inputBuffer = null;
|
||||
outputBuffer = null;
|
||||
decoder.flush();
|
||||
notifyDiscontinuityToDecoder = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEnded() {
|
||||
return outputStreamEnded && (!audioTrack.hasPendingData()
|
||||
|| !audioTrack.hasEnoughDataToBeginPlayback());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isReady() {
|
||||
return audioTrack.hasPendingData() || (format != null && sourceIsReady);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long getDurationUs() {
|
||||
return source.getTrackInfo(trackIndex).durationUs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long getCurrentPositionUs() {
|
||||
long audioTrackCurrentPositionUs = audioTrack.getCurrentPositionUs(isEnded());
|
||||
if (audioTrackCurrentPositionUs != AudioTrack.CURRENT_POSITION_NOT_SET) {
|
||||
// Make sure we don't ever report time moving backwards.
|
||||
currentPositionUs = Math.max(currentPositionUs, audioTrackCurrentPositionUs);
|
||||
}
|
||||
return currentPositionUs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long getBufferedPositionUs() {
|
||||
long sourceBufferedPosition = source.getBufferedPositionUs();
|
||||
return sourceBufferedPosition == UNKNOWN_TIME_US || sourceBufferedPosition == END_OF_TRACK_US
|
||||
? sourceBufferedPosition : Math.max(sourceBufferedPosition, getCurrentPositionUs());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void seekTo(long positionUs) throws ExoPlaybackException {
|
||||
audioTrack.reset();
|
||||
currentPositionUs = positionUs;
|
||||
source.seekToUs(positionUs);
|
||||
inputStreamEnded = false;
|
||||
outputStreamEnded = false;
|
||||
sourceIsReady = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnabled(long positionUs, boolean joining) {
|
||||
source.enable(trackIndex, positionUs);
|
||||
sourceIsReady = false;
|
||||
inputStreamEnded = false;
|
||||
outputStreamEnded = false;
|
||||
currentPositionUs = Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStarted() {
|
||||
audioTrack.play();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStopped() {
|
||||
audioTrack.pause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onReleased() {
|
||||
source.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisabled() {
|
||||
if (decoder != null) {
|
||||
decoder.release();
|
||||
decoder = null;
|
||||
}
|
||||
audioSessionId = AudioTrack.SESSION_ID_NOT_SET;
|
||||
try {
|
||||
audioTrack.reset();
|
||||
} finally {
|
||||
inputBuffer = null;
|
||||
outputBuffer = null;
|
||||
format = null;
|
||||
source.disable(trackIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void readFormat() throws IOException {
|
||||
int result = source.readData(trackIndex, currentPositionUs, formatHolder, null, false);
|
||||
if (result == SampleSource.FORMAT_READ) {
|
||||
format = formatHolder.format;
|
||||
audioTrack.reconfigure(format.getFrameworkMediaFormatV16());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(int messageType, Object message) throws ExoPlaybackException {
|
||||
if (messageType == MSG_SET_VOLUME) {
|
||||
audioTrack.setVolume((Float) message);
|
||||
} else {
|
||||
super.handleMessage(messageType, message);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyAudioTrackInitializationError(final AudioTrack.InitializationException e) {
|
||||
if (eventHandler != null && eventListener != null) {
|
||||
eventHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
eventListener.onAudioTrackInitializationError(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyAudioTrackWriteError(final AudioTrack.WriteException e) {
|
||||
if (eventHandler != null && eventListener != null) {
|
||||
eventHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
eventListener.onAudioTrackWriteError(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyDecoderError(final OpusDecoderException e) {
|
||||
if (eventHandler != null && eventListener != null) {
|
||||
eventHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
eventListener.onDecoderError(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.ext.opus;
|
||||
|
||||
import com.google.android.exoplayer.ext.opus.OpusDecoderWrapper.OpusHeader;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* JNI Wrapper for the libopus Opus decoder.
|
||||
*
|
||||
* @author vigneshv@google.com (Vignesh Venkatasubramanian)
|
||||
*/
|
||||
/* package */ class OpusDecoder {
|
||||
|
||||
private final long nativeDecoderContext;
|
||||
|
||||
static {
|
||||
System.loadLibrary("opusJNI");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Opus Decoder.
|
||||
*
|
||||
* @param opusHeader OpusHeader used to initialize the decoder.
|
||||
* @throws OpusDecoderException if the decoder initialization fails.
|
||||
*/
|
||||
public OpusDecoder(OpusHeader opusHeader) throws OpusDecoderException {
|
||||
nativeDecoderContext = opusInit(
|
||||
opusHeader.sampleRate, opusHeader.channelCount, opusHeader.numStreams,
|
||||
opusHeader.numCoupled, opusHeader.gain, opusHeader.streamMap);
|
||||
if (nativeDecoderContext == 0) {
|
||||
throw new OpusDecoderException("failed to initialize opus decoder");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes an Opus Encoded Stream.
|
||||
*
|
||||
* @param inputBuffer buffer containing the encoded data. Must be allocated using allocateDirect.
|
||||
* @param inputSize size of the input buffer.
|
||||
* @param outputBuffer buffer to write the decoded data. Must be allocated using allocateDirect.
|
||||
* @param outputSize Maximum capacity of the output buffer.
|
||||
* @return number of decoded bytes.
|
||||
* @throws OpusDecoderException if decode fails.
|
||||
*/
|
||||
public int decode(ByteBuffer inputBuffer, int inputSize, ByteBuffer outputBuffer,
|
||||
int outputSize) throws OpusDecoderException {
|
||||
int result = opusDecode(nativeDecoderContext, inputBuffer, inputSize, outputBuffer, outputSize);
|
||||
if (result < 0) {
|
||||
throw new OpusDecoderException(opusGetErrorMessage(result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the native decoder.
|
||||
*/
|
||||
public void close() {
|
||||
opusClose(nativeDecoderContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the native decode on discontinuity (during seek for example).
|
||||
*/
|
||||
public void reset() {
|
||||
opusReset(nativeDecoderContext);
|
||||
}
|
||||
|
||||
private native long opusInit(int sampleRate, int channelCount, int numStreams, int numCoupled,
|
||||
int gain, byte[] streamMap);
|
||||
private native int opusDecode(long decoder, ByteBuffer inputBuffer, int inputSize,
|
||||
ByteBuffer outputBuffer, int outputSize);
|
||||
private native void opusClose(long decoder);
|
||||
private native void opusReset(long decoder);
|
||||
private native String opusGetErrorMessage(int errorCode);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.ext.opus;
|
||||
|
||||
/**
|
||||
* Thrown when an Opus decoder error occurs.
|
||||
*/
|
||||
public class OpusDecoderException extends Exception {
|
||||
|
||||
public OpusDecoderException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,383 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer.ext.opus;
|
||||
|
||||
import com.google.android.exoplayer.SampleHolder;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Wraps {@link OpusDecoder}, exposing a higher level decoder interface.
|
||||
*
|
||||
* @author vigneshv@google.com (Vignesh Venkatasubramanian)
|
||||
*/
|
||||
/* package */ class OpusDecoderWrapper extends Thread {
|
||||
|
||||
public static final int FLAG_END_OF_STREAM = 1;
|
||||
public static final int FLAG_RESET_DECODER = 2;
|
||||
|
||||
private static final int INPUT_BUFFER_SIZE = 960 * 6;
|
||||
private static final int OUTPUT_BUFFER_SIZE = 960 * 6 * 2;
|
||||
private static final int NUM_BUFFERS = 16;
|
||||
private static final int DEFAULT_SEEK_PRE_ROLL = 3840;
|
||||
|
||||
private final Object lock;
|
||||
private final OpusHeader opusHeader;
|
||||
|
||||
private final LinkedList<InputBuffer> queuedInputBuffers;
|
||||
private final LinkedList<OutputBuffer> queuedOutputBuffers;
|
||||
private final InputBuffer[] availableInputBuffers;
|
||||
private final OutputBuffer[] availableOutputBuffers;
|
||||
private int availableInputBufferCount;
|
||||
private int availableOutputBufferCount;
|
||||
|
||||
private int skipSamples;
|
||||
private boolean flushDecodedOutputBuffer;
|
||||
private boolean released;
|
||||
|
||||
private int seekPreRoll;
|
||||
|
||||
private OpusDecoderException decoderException;
|
||||
|
||||
/**
|
||||
* @param headerBytes Opus header data that is used to initialize the decoder. For WebM Container,
|
||||
* this comes from the CodecPrivate Track element.
|
||||
* @param codecDelayNs Delay in nanoseconds added by the codec at the beginning. For WebM
|
||||
* Container, this comes from the CodecDelay Track Element. Can be -1 in which case the value
|
||||
* from the codec header will be used.
|
||||
* @param seekPreRollNs Duration in nanoseconds of samples to discard when there is a
|
||||
* discontinuity. For WebM Container, this comes from the SeekPreRoll Track Element. Can be -1
|
||||
* in which case the default value of 80ns will be used.
|
||||
* @throws OpusDecoderException if an exception occurs when initializing the decoder.
|
||||
*/
|
||||
public OpusDecoderWrapper(byte[] headerBytes, long codecDelayNs,
|
||||
long seekPreRollNs) throws OpusDecoderException {
|
||||
lock = new Object();
|
||||
opusHeader = parseOpusHeader(headerBytes);
|
||||
skipSamples = (codecDelayNs == -1) ? opusHeader.skipSamples : nsToSamples(codecDelayNs);
|
||||
seekPreRoll = (seekPreRoll == -1) ? DEFAULT_SEEK_PRE_ROLL : nsToSamples(seekPreRollNs);
|
||||
queuedInputBuffers = new LinkedList<InputBuffer>();
|
||||
queuedOutputBuffers = new LinkedList<OutputBuffer>();
|
||||
availableInputBuffers = new InputBuffer[NUM_BUFFERS];
|
||||
availableOutputBuffers = new OutputBuffer[NUM_BUFFERS];
|
||||
availableInputBufferCount = NUM_BUFFERS;
|
||||
availableOutputBufferCount = NUM_BUFFERS;
|
||||
for (int i = 0; i < NUM_BUFFERS; i++) {
|
||||
availableInputBuffers[i] = new InputBuffer();
|
||||
availableOutputBuffers[i] = new OutputBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
public InputBuffer getInputBuffer() throws OpusDecoderException {
|
||||
synchronized (lock) {
|
||||
maybeThrowDecoderError();
|
||||
if (availableInputBufferCount == 0) {
|
||||
return null;
|
||||
}
|
||||
InputBuffer inputBuffer = availableInputBuffers[--availableInputBufferCount];
|
||||
inputBuffer.reset();
|
||||
return inputBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
public void queueInputBuffer(InputBuffer inputBuffer) throws OpusDecoderException {
|
||||
synchronized (lock) {
|
||||
maybeThrowDecoderError();
|
||||
queuedInputBuffers.addLast(inputBuffer);
|
||||
maybeNotifyDecodeLoop();
|
||||
}
|
||||
}
|
||||
|
||||
public OutputBuffer dequeueOutputBuffer() throws OpusDecoderException {
|
||||
synchronized (lock) {
|
||||
maybeThrowDecoderError();
|
||||
if (queuedOutputBuffers.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return queuedOutputBuffers.removeFirst();
|
||||
}
|
||||
}
|
||||
|
||||
public void releaseOutputBuffer(OutputBuffer outputBuffer) throws OpusDecoderException {
|
||||
synchronized (lock) {
|
||||
maybeThrowDecoderError();
|
||||
outputBuffer.reset();
|
||||
availableOutputBuffers[availableOutputBufferCount++] = outputBuffer;
|
||||
maybeNotifyDecodeLoop();
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
synchronized (lock) {
|
||||
flushDecodedOutputBuffer = true;
|
||||
while (!queuedInputBuffers.isEmpty()) {
|
||||
availableInputBuffers[availableInputBufferCount++] = queuedInputBuffers.removeFirst();
|
||||
}
|
||||
while (!queuedOutputBuffers.isEmpty()) {
|
||||
availableOutputBuffers[availableOutputBufferCount++] = queuedOutputBuffers.removeFirst();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
synchronized (lock) {
|
||||
released = true;
|
||||
lock.notify();
|
||||
}
|
||||
try {
|
||||
join();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
private void maybeThrowDecoderError() throws OpusDecoderException {
|
||||
if (decoderException != null) {
|
||||
throw decoderException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the decode loop if there exists a queued input buffer and an available output buffer
|
||||
* to decode into.
|
||||
* <p>
|
||||
* Should only be called whilst synchronized on the lock object.
|
||||
*/
|
||||
private void maybeNotifyDecodeLoop() {
|
||||
if (!queuedInputBuffers.isEmpty() && availableOutputBufferCount > 0) {
|
||||
lock.notify();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
OpusDecoder decoder = null;
|
||||
try {
|
||||
decoder = new OpusDecoder(opusHeader);
|
||||
while (decodeBuffer(decoder)) {
|
||||
// Do nothing.
|
||||
}
|
||||
} catch (OpusDecoderException e) {
|
||||
synchronized (lock) {
|
||||
decoderException = e;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// Shouldn't ever happen.
|
||||
} finally {
|
||||
if (decoder != null) {
|
||||
decoder.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean decodeBuffer(OpusDecoder decoder) throws InterruptedException,
|
||||
OpusDecoderException {
|
||||
InputBuffer inputBuffer;
|
||||
OutputBuffer outputBuffer;
|
||||
|
||||
// Wait until we have an input buffer to decode, and an output buffer to decode into.
|
||||
synchronized (lock) {
|
||||
while (!released && (queuedInputBuffers.isEmpty() || availableOutputBufferCount == 0)) {
|
||||
lock.wait();
|
||||
}
|
||||
if (released) {
|
||||
return false;
|
||||
}
|
||||
inputBuffer = queuedInputBuffers.removeFirst();
|
||||
outputBuffer = availableOutputBuffers[--availableOutputBufferCount];
|
||||
flushDecodedOutputBuffer = false;
|
||||
}
|
||||
|
||||
// Decode.
|
||||
if (inputBuffer.getFlag(FLAG_END_OF_STREAM)) {
|
||||
outputBuffer.setFlag(FLAG_END_OF_STREAM);
|
||||
} else {
|
||||
if (inputBuffer.getFlag(FLAG_RESET_DECODER)) {
|
||||
decoder.reset();
|
||||
// When seeking to 0, skip number of samples as specified in opus header. When seeking to
|
||||
// any other time, skip number of samples as specified by seek preroll.
|
||||
skipSamples = (inputBuffer.sampleHolder.timeUs == 0) ? opusHeader.skipSamples : seekPreRoll;
|
||||
}
|
||||
SampleHolder sampleHolder = inputBuffer.sampleHolder;
|
||||
sampleHolder.data.position(sampleHolder.data.position() - sampleHolder.size);
|
||||
outputBuffer.timestampUs = sampleHolder.timeUs;
|
||||
outputBuffer.size = decoder.decode(sampleHolder.data, sampleHolder.size,
|
||||
outputBuffer.data, outputBuffer.data.capacity());
|
||||
outputBuffer.data.position(0);
|
||||
if (skipSamples > 0) {
|
||||
int bytesPerSample = opusHeader.channelCount * 2;
|
||||
int skipBytes = skipSamples * bytesPerSample;
|
||||
if (outputBuffer.size < skipBytes) {
|
||||
skipSamples -= outputBuffer.size / bytesPerSample;
|
||||
outputBuffer.size = 0;
|
||||
} else {
|
||||
skipSamples = 0;
|
||||
outputBuffer.data.position(skipBytes);
|
||||
outputBuffer.size -= skipBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
synchronized (lock) {
|
||||
if (flushDecodedOutputBuffer
|
||||
|| inputBuffer.sampleHolder.decodeOnly
|
||||
|| outputBuffer.size == 0) {
|
||||
// In the following cases, we make the output buffer available again rather than queuing it
|
||||
// to be consumed:
|
||||
// 1) A flush occured whilst we were decoding.
|
||||
// 2) The input sample has decodeOnly flag set.
|
||||
// 3) We skip the entire buffer due to skipSamples being greater than bytes decoded.
|
||||
outputBuffer.reset();
|
||||
availableOutputBuffers[availableOutputBufferCount++] = outputBuffer;
|
||||
} else {
|
||||
// Queue the decoded output buffer to be consumed.
|
||||
queuedOutputBuffers.addLast(outputBuffer);
|
||||
}
|
||||
// Make the input buffer available again.
|
||||
availableInputBuffers[availableInputBufferCount++] = inputBuffer;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private OpusHeader parseOpusHeader(byte[] headerBytes) throws OpusDecoderException {
|
||||
final int maxChannelCount = 8;
|
||||
final int maxChannelCountWithDefaultLayout = 2;
|
||||
final int headerSize = 19;
|
||||
final int headerChannelCountOffset = 9;
|
||||
final int headerSkipSamplesOffset = 10;
|
||||
final int headerGainOffset = 16;
|
||||
final int headerChannelMappingOffset = 18;
|
||||
final int headerNumStreamsOffset = headerSize;
|
||||
final int headerNumCoupledOffset = headerNumStreamsOffset + 1;
|
||||
final int headerStreamMapOffset = headerNumStreamsOffset + 2;
|
||||
OpusHeader opusHeader = new OpusHeader();
|
||||
try {
|
||||
// Opus streams are always decoded at 48000 hz.
|
||||
opusHeader.sampleRate = 48000;
|
||||
opusHeader.channelCount = headerBytes[headerChannelCountOffset];
|
||||
if (opusHeader.channelCount > maxChannelCount) {
|
||||
throw new OpusDecoderException("Invalid channel count: " + opusHeader.channelCount);
|
||||
}
|
||||
opusHeader.skipSamples = readLittleEndian16(headerBytes, headerSkipSamplesOffset);
|
||||
opusHeader.gain = readLittleEndian16(headerBytes, headerGainOffset);
|
||||
opusHeader.channelMapping = headerBytes[headerChannelMappingOffset];
|
||||
|
||||
if (opusHeader.channelMapping == 0) {
|
||||
// If there is no channel mapping, use the defaults.
|
||||
if (opusHeader.channelCount > maxChannelCountWithDefaultLayout) {
|
||||
throw new OpusDecoderException("Invalid Header, missing stream map.");
|
||||
}
|
||||
opusHeader.numStreams = 1;
|
||||
opusHeader.numCoupled = (opusHeader.channelCount > 1) ? 1 : 0;
|
||||
opusHeader.streamMap[0] = 0;
|
||||
opusHeader.streamMap[1] = 1;
|
||||
} else {
|
||||
// Read the channel mapping.
|
||||
opusHeader.numStreams = headerBytes[headerNumStreamsOffset];
|
||||
opusHeader.numCoupled = headerBytes[headerNumCoupledOffset];
|
||||
for (int i = 0; i < opusHeader.channelCount; i++) {
|
||||
opusHeader.streamMap[i] = headerBytes[headerStreamMapOffset + i];
|
||||
}
|
||||
}
|
||||
return opusHeader;
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new OpusDecoderException("Header size is too small.");
|
||||
}
|
||||
}
|
||||
|
||||
private int readLittleEndian16(byte[] input, int offset) {
|
||||
int value = input[offset];
|
||||
value |= input[offset + 1] << 8;
|
||||
return value;
|
||||
}
|
||||
|
||||
private int nsToSamples(long ns) {
|
||||
return (int) (ns * opusHeader.sampleRate / 1000000000);
|
||||
}
|
||||
|
||||
/* package */ static final class InputBuffer {
|
||||
|
||||
public final SampleHolder sampleHolder;
|
||||
|
||||
public int flags;
|
||||
|
||||
public InputBuffer() {
|
||||
sampleHolder = new SampleHolder(SampleHolder.BUFFER_REPLACEMENT_MODE_DIRECT);
|
||||
sampleHolder.data = ByteBuffer.allocateDirect(INPUT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
sampleHolder.data.clear();
|
||||
flags = 0;
|
||||
}
|
||||
|
||||
public void setFlag(int flag) {
|
||||
flags |= flag;
|
||||
}
|
||||
|
||||
public boolean getFlag(int flag) {
|
||||
return (flags & flag) == flag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* package */ static final class OutputBuffer {
|
||||
|
||||
public ByteBuffer data;
|
||||
public int size;
|
||||
public long timestampUs;
|
||||
public int flags;
|
||||
|
||||
public OutputBuffer() {
|
||||
data = ByteBuffer.allocateDirect(OUTPUT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
data.clear();
|
||||
size = 0;
|
||||
flags = 0;
|
||||
}
|
||||
|
||||
public void setFlag(int flag) {
|
||||
flags |= flag;
|
||||
}
|
||||
|
||||
public boolean getFlag(int flag) {
|
||||
return (flags & flag) == flag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* package */ static final class OpusHeader {
|
||||
|
||||
public int sampleRate;
|
||||
public int channelCount;
|
||||
public int skipSamples;
|
||||
public int gain;
|
||||
public int channelMapping;
|
||||
public int numStreams;
|
||||
public int numCoupled;
|
||||
public byte[] streamMap;
|
||||
|
||||
public OpusHeader() {
|
||||
streamMap = new byte[8];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
34
extensions/opus/src/main/jni/Android.mk
Normal file
34
extensions/opus/src/main/jni/Android.mk
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#
|
||||
# Copyright (C) 2014 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
WORKING_DIR := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
APP_PLATFORM := android-10
|
||||
|
||||
# build libopus.so
|
||||
LOCAL_PATH := $(WORKING_DIR)
|
||||
include libopus.mk
|
||||
|
||||
# build libopusJNI.so
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_PATH := $(WORKING_DIR)
|
||||
LOCAL_MODULE := libopusJNI
|
||||
LOCAL_ARM_MODE := arm
|
||||
LOCAL_CPP_EXTENSION := .cc
|
||||
LOCAL_SRC_FILES := opus_jni.cc
|
||||
LOCAL_LDLIBS := -llog -lz -lm
|
||||
LOCAL_SHARED_LIBRARIES := libopus
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
19
extensions/opus/src/main/jni/Application.mk
Normal file
19
extensions/opus/src/main/jni/Application.mk
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#
|
||||
# Copyright (C) 2014 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
APP_OPTIM := release
|
||||
APP_STL := gnustl_static
|
||||
APP_CPPFLAGS := -frtti
|
||||
47
extensions/opus/src/main/jni/convert_android_asm.sh
Executable file
47
extensions/opus/src/main/jni/convert_android_asm.sh
Executable file
|
|
@ -0,0 +1,47 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2014 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
set -e
|
||||
ASM_CONVERTER="./libopus/celt/arm/arm2gnu.pl"
|
||||
|
||||
if [[ ! -x "${ASM_CONVERTER}" ]]; then
|
||||
echo "Please make sure you have checked out libopus."
|
||||
exit
|
||||
fi
|
||||
|
||||
while read file; do
|
||||
# This check is required because the ASM conversion script doesn't seem to be
|
||||
# idempotent.
|
||||
if [[ ! "${file}" =~ .*_gnu\.s$ ]]; then
|
||||
gnu_file="${file%.s}_gnu.s"
|
||||
${ASM_CONVERTER} "${file}" > "${gnu_file}"
|
||||
# The ASM conversion script replaces includes with *_gnu.S. So, replace
|
||||
# occurences of "*-gnu.S" with "*_gnu.s".
|
||||
sed -i "s/-gnu\.S/_gnu\.s/g" "${gnu_file}"
|
||||
rm -f "${file}"
|
||||
fi
|
||||
done < <(find . -iname '*.s')
|
||||
|
||||
# Generate armopts.s from armopts.s.in
|
||||
sed \
|
||||
-e "s/@OPUS_ARM_MAY_HAVE_EDSP@/1/g" \
|
||||
-e "s/@OPUS_ARM_MAY_HAVE_MEDIA@/1/g" \
|
||||
-e "s/@OPUS_ARM_MAY_HAVE_NEON@/1/g" \
|
||||
libopus/celt/arm/armopts.s.in > libopus/celt/arm/armopts.s.temp
|
||||
${ASM_CONVERTER} "libopus/celt/arm/armopts.s.temp" > "libopus/celt/arm/armopts_gnu.s"
|
||||
rm "libopus/celt/arm/armopts.s.temp"
|
||||
echo "Converted all ASM files and generated armopts.s successfully."
|
||||
50
extensions/opus/src/main/jni/libopus.mk
Normal file
50
extensions/opus/src/main/jni/libopus.mk
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#
|
||||
# Copyright (C) 2014 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)/libopus
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
include $(LOCAL_PATH)/celt_headers.mk
|
||||
include $(LOCAL_PATH)/celt_sources.mk
|
||||
include $(LOCAL_PATH)/opus_headers.mk
|
||||
include $(LOCAL_PATH)/opus_sources.mk
|
||||
include $(LOCAL_PATH)/silk_headers.mk
|
||||
include $(LOCAL_PATH)/silk_sources.mk
|
||||
|
||||
LOCAL_MODULE := libopus
|
||||
LOCAL_ARM_MODE := arm
|
||||
LOCAL_CFLAGS := -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT \
|
||||
-DHAVE_LRINTF
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/src \
|
||||
$(LOCAL_PATH)/silk $(LOCAL_PATH)/celt \
|
||||
$(LOCAL_PATH)/silk/fixed
|
||||
LOCAL_SRC_FILES := $(CELT_SOURCES) $(OPUS_SOURCES) $(OPUS_SOURCES_FLOAT) \
|
||||
$(SILK_SOURCES) $(SILK_SOURCES_FIXED)
|
||||
|
||||
ifneq ($(findstring armeabi-v7a, $(TARGET_ARCH_ABI)),)
|
||||
LOCAL_SRC_FILES += $(CELT_SOURCES_ARM)
|
||||
LOCAL_SRC_FILES += celt/arm/armopts_gnu.s.neon
|
||||
LOCAL_SRC_FILES += $(subst .s,_gnu.s.neon,$(CELT_SOURCES_ARM_ASM))
|
||||
LOCAL_CFLAGS += -DOPUS_ARM_ASM -DOPUS_ARM_INLINE_ASM -DOPUS_ARM_INLINE_EDSP \
|
||||
-DOPUS_ARM_INLINE_MEDIA -DOPUS_ARM_INLINE_NEON \
|
||||
-DOPUS_ARM_MAY_HAVE_NEON -DOPUS_ARM_MAY_HAVE_MEDIA \
|
||||
-DOPUS_ARM_MAY_HAVE_EDSP
|
||||
endif
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
96
extensions/opus/src/main/jni/opus_jni.cc
Normal file
96
extensions/opus/src/main/jni/opus_jni.cc
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "opus.h" // NOLINT
|
||||
#include "opus_multistream.h" // NOLINT
|
||||
|
||||
#define LOG_TAG "libopus_native"
|
||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, \
|
||||
__VA_ARGS__))
|
||||
|
||||
#define FUNC(RETURN_TYPE, NAME, ...) \
|
||||
extern "C" { \
|
||||
JNIEXPORT RETURN_TYPE \
|
||||
Java_com_google_android_exoplayer_ext_opus_OpusDecoder_ ## NAME \
|
||||
(JNIEnv* env, jobject thiz, ##__VA_ARGS__);\
|
||||
} \
|
||||
JNIEXPORT RETURN_TYPE \
|
||||
Java_com_google_android_exoplayer_ext_opus_OpusDecoder_ ## NAME \
|
||||
(JNIEnv* env, jobject thiz, ##__VA_ARGS__)\
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
JNIEnv* env;
|
||||
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||||
return -1;
|
||||
}
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
static int channelCount;
|
||||
|
||||
FUNC(jlong, opusInit, jint sampleRate, jint channelCount, jint numStreams,
|
||||
jint numCoupled, jint gain, jbyteArray jStreamMap) {
|
||||
int status = OPUS_INVALID_STATE;
|
||||
::channelCount = channelCount;
|
||||
jbyte* streamMapBytes = env->GetByteArrayElements(jStreamMap, 0);
|
||||
uint8_t* streamMap = reinterpret_cast<uint8_t*>(streamMapBytes);
|
||||
OpusMSDecoder* decoder = opus_multistream_decoder_create(
|
||||
sampleRate, channelCount, numStreams, numCoupled, streamMap, &status);
|
||||
env->ReleaseByteArrayElements(jStreamMap, streamMapBytes, 0);
|
||||
if (!decoder || status != OPUS_OK) {
|
||||
LOGE("Failed to create Opus Decoder; status=%s", opus_strerror(status));
|
||||
return 0;
|
||||
}
|
||||
status = opus_multistream_decoder_ctl(decoder, OPUS_SET_GAIN(gain));
|
||||
if (status != OPUS_OK) {
|
||||
LOGE("Failed to set Opus header gain; status=%s", opus_strerror(status));
|
||||
return 0;
|
||||
}
|
||||
return reinterpret_cast<intptr_t>(decoder);
|
||||
}
|
||||
|
||||
FUNC(jint, opusDecode, jlong jDecoder, jobject jInputBuffer, jint inputSize,
|
||||
jobject jOutputBuffer, jint outputSize) {
|
||||
OpusMSDecoder* decoder = reinterpret_cast<OpusMSDecoder*>(jDecoder);
|
||||
const uint8_t* inputBuffer =
|
||||
reinterpret_cast<const uint8_t*>(
|
||||
env->GetDirectBufferAddress(jInputBuffer));
|
||||
int16_t* outputBuffer = reinterpret_cast<int16_t*>(
|
||||
env->GetDirectBufferAddress(jOutputBuffer));
|
||||
int numFrames = opus_multistream_decode(decoder, inputBuffer, inputSize,
|
||||
outputBuffer, outputSize, 0);
|
||||
return (numFrames < 0) ? numFrames : numFrames * 2 * channelCount;
|
||||
}
|
||||
|
||||
FUNC(void, opusClose, jlong jDecoder) {
|
||||
OpusMSDecoder* decoder = reinterpret_cast<OpusMSDecoder*>(jDecoder);
|
||||
opus_multistream_decoder_destroy(decoder);
|
||||
}
|
||||
|
||||
FUNC(void, opusReset, jlong jDecoder) {
|
||||
OpusMSDecoder* decoder = reinterpret_cast<OpusMSDecoder*>(jDecoder);
|
||||
opus_multistream_decoder_ctl(decoder, OPUS_RESET_STATE);
|
||||
}
|
||||
|
||||
FUNC(jstring, opusGetErrorMessage, jint errorCode) {
|
||||
return env->NewStringUTF(opus_strerror(errorCode));
|
||||
}
|
||||
16
extensions/opus/src/main/project.properties
Normal file
16
extensions/opus/src/main/project.properties
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-21
|
||||
android.library=true
|
||||
android.library.reference.1=../../../../library/src/main
|
||||
2
extensions/opus/src/main/res/.README.txt
Normal file
2
extensions/opus/src/main/res/.README.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
This file is needed to make sure the res directory is present.
|
||||
The file is ignored by the Android toolchain because its name starts with a dot.
|
||||
Loading…
Reference in a new issue