mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
Add opus and flac tests to MOE
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=119759105
This commit is contained in:
parent
3ae1c615d9
commit
2b0f2ec3bc
10 changed files with 334 additions and 0 deletions
34
extensions/flac/src/androidTest/AndroidManifest.xml
Normal file
34
extensions/flac/src/androidTest/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2016 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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.google.android.exoplayer.ext.flac.test">
|
||||
|
||||
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23"/>
|
||||
|
||||
<application android:debuggable="true"
|
||||
android:allowBackup="false"
|
||||
tools:ignore="MissingApplicationIcon,HardcodedDebugMode">
|
||||
<uses-library android:name="android.test.runner"/>
|
||||
</application>
|
||||
|
||||
<instrumentation
|
||||
android:targetPackage="com.google.android.exoplayer.ext.flac.test"
|
||||
android:name="android.test.InstrumentationTestRunner"
|
||||
tools:replace="android:targetPackage"/>
|
||||
|
||||
</manifest>
|
||||
BIN
extensions/flac/src/androidTest/assets/bear-flac.mka
Normal file
BIN
extensions/flac/src/androidTest/assets/bear-flac.mka
Normal file
Binary file not shown.
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.flac;
|
||||
|
||||
import com.google.android.exoplayer.DefaultTrackSelector;
|
||||
import com.google.android.exoplayer.ExoPlaybackException;
|
||||
import com.google.android.exoplayer.ExoPlayer;
|
||||
import com.google.android.exoplayer.TrackRenderer;
|
||||
import com.google.android.exoplayer.extractor.ExtractorSampleSource;
|
||||
import com.google.android.exoplayer.extractor.mkv.MatroskaExtractor;
|
||||
import com.google.android.exoplayer.upstream.DefaultAllocator;
|
||||
import com.google.android.exoplayer.upstream.DefaultDataSource;
|
||||
import com.google.android.exoplayer.util.Util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Looper;
|
||||
import android.test.InstrumentationTestCase;
|
||||
|
||||
/**
|
||||
* Playback tests using {@link LibflacAudioTrackRenderer}.
|
||||
*/
|
||||
public class FlacPlaybackTest extends InstrumentationTestCase {
|
||||
|
||||
private static final String BEAR_FLAC_URI = "asset:///bear-flac.mka";
|
||||
|
||||
public void testBasicPlayback() throws ExoPlaybackException {
|
||||
playUri(BEAR_FLAC_URI);
|
||||
}
|
||||
|
||||
private void playUri(String uri) throws ExoPlaybackException {
|
||||
TestPlaybackThread thread = new TestPlaybackThread(Uri.parse(uri),
|
||||
getInstrumentation().getContext());
|
||||
thread.start();
|
||||
try {
|
||||
thread.join();
|
||||
} catch (InterruptedException e) {
|
||||
fail(); // Should never happen.
|
||||
}
|
||||
if (thread.playbackException != null) {
|
||||
throw thread.playbackException;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestPlaybackThread extends Thread implements ExoPlayer.Listener {
|
||||
|
||||
private static final int BUFFER_SEGMENT_SIZE = 64 * 1024;
|
||||
private static final int BUFFER_SEGMENT_COUNT = 16;
|
||||
|
||||
private final Context context;
|
||||
private final Uri uri;
|
||||
|
||||
private ExoPlayer player;
|
||||
private ExoPlaybackException playbackException;
|
||||
|
||||
public TestPlaybackThread(Uri uri, Context context) {
|
||||
this.uri = uri;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Looper.prepare();
|
||||
LibflacAudioTrackRenderer audioRenderer = new LibflacAudioTrackRenderer();
|
||||
DefaultTrackSelector trackSelector = new DefaultTrackSelector(null, null);
|
||||
player = ExoPlayer.Factory.newInstance(new TrackRenderer[] {audioRenderer}, trackSelector);
|
||||
player.addListener(this);
|
||||
ExtractorSampleSource sampleSource = new ExtractorSampleSource(
|
||||
uri,
|
||||
new DefaultDataSource(context, null, Util.getUserAgent(context, "ExoPlayerExtFlacTest"),
|
||||
false),
|
||||
new DefaultAllocator(BUFFER_SEGMENT_SIZE), BUFFER_SEGMENT_SIZE * BUFFER_SEGMENT_COUNT,
|
||||
new MatroskaExtractor());
|
||||
player.prepare(sampleSource);
|
||||
player.setPlayWhenReady(true);
|
||||
Looper.loop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayWhenReadyCommitted () {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerError(ExoPlaybackException error) {
|
||||
playbackException = error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
if (playbackState == ExoPlayer.STATE_ENDED
|
||||
|| (playbackState == ExoPlayer.STATE_IDLE && playbackException != null)) {
|
||||
releasePlayerAndQuitLooper();
|
||||
}
|
||||
}
|
||||
|
||||
private void releasePlayerAndQuitLooper() {
|
||||
player.release();
|
||||
Looper.myLooper().quit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
14
extensions/flac/src/androidTest/project.properties
Normal file
14
extensions/flac/src/androidTest/project.properties
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# 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-23
|
||||
2
extensions/flac/src/androidTest/res/.README.txt
Normal file
2
extensions/flac/src/androidTest/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.
|
||||
34
extensions/opus/src/androidTest/AndroidManifest.xml
Normal file
34
extensions/opus/src/androidTest/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2016 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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.google.android.exoplayer.ext.opus.test">
|
||||
|
||||
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23"/>
|
||||
|
||||
<application android:debuggable="true"
|
||||
android:allowBackup="false"
|
||||
tools:ignore="MissingApplicationIcon,HardcodedDebugMode">
|
||||
<uses-library android:name="android.test.runner"/>
|
||||
</application>
|
||||
|
||||
<instrumentation
|
||||
android:targetPackage="com.google.android.exoplayer.ext.opus.test"
|
||||
android:name="android.test.InstrumentationTestRunner"
|
||||
tools:replace="android:targetPackage"/>
|
||||
|
||||
</manifest>
|
||||
BIN
extensions/opus/src/androidTest/assets/bear-opus.webm
Normal file
BIN
extensions/opus/src/androidTest/assets/bear-opus.webm
Normal file
Binary file not shown.
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.DefaultTrackSelector;
|
||||
import com.google.android.exoplayer.ExoPlaybackException;
|
||||
import com.google.android.exoplayer.ExoPlayer;
|
||||
import com.google.android.exoplayer.TrackRenderer;
|
||||
import com.google.android.exoplayer.extractor.ExtractorSampleSource;
|
||||
import com.google.android.exoplayer.extractor.mkv.MatroskaExtractor;
|
||||
import com.google.android.exoplayer.upstream.DefaultAllocator;
|
||||
import com.google.android.exoplayer.upstream.DefaultDataSource;
|
||||
import com.google.android.exoplayer.util.Util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Looper;
|
||||
import android.test.InstrumentationTestCase;
|
||||
|
||||
/**
|
||||
* Playback tests using {@link LibopusAudioTrackRenderer}.
|
||||
*/
|
||||
public class OpusPlaybackTest extends InstrumentationTestCase {
|
||||
|
||||
private static final String BEAR_OPUS_URI = "asset:///bear-opus.webm";
|
||||
|
||||
public void testBasicPlayback() throws ExoPlaybackException {
|
||||
playUri(BEAR_OPUS_URI);
|
||||
}
|
||||
|
||||
private void playUri(String uri) throws ExoPlaybackException {
|
||||
TestPlaybackThread thread = new TestPlaybackThread(Uri.parse(uri),
|
||||
getInstrumentation().getContext());
|
||||
thread.start();
|
||||
try {
|
||||
thread.join();
|
||||
} catch (InterruptedException e) {
|
||||
fail(); // Should never happen.
|
||||
}
|
||||
if (thread.playbackException != null) {
|
||||
throw thread.playbackException;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestPlaybackThread extends Thread implements ExoPlayer.Listener {
|
||||
|
||||
private static final int BUFFER_SEGMENT_SIZE = 64 * 1024;
|
||||
private static final int BUFFER_SEGMENT_COUNT = 16;
|
||||
|
||||
private final Context context;
|
||||
private final Uri uri;
|
||||
|
||||
private ExoPlayer player;
|
||||
private ExoPlaybackException playbackException;
|
||||
|
||||
public TestPlaybackThread(Uri uri, Context context) {
|
||||
this.uri = uri;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Looper.prepare();
|
||||
LibopusAudioTrackRenderer audioRenderer = new LibopusAudioTrackRenderer();
|
||||
DefaultTrackSelector trackSelector = new DefaultTrackSelector(null, null);
|
||||
player = ExoPlayer.Factory.newInstance(new TrackRenderer[] {audioRenderer}, trackSelector);
|
||||
player.addListener(this);
|
||||
ExtractorSampleSource sampleSource = new ExtractorSampleSource(
|
||||
uri,
|
||||
new DefaultDataSource(context, null, Util.getUserAgent(context, "ExoPlayerExtOpusTest"),
|
||||
false),
|
||||
new DefaultAllocator(BUFFER_SEGMENT_SIZE), BUFFER_SEGMENT_SIZE * BUFFER_SEGMENT_COUNT,
|
||||
new MatroskaExtractor());
|
||||
player.prepare(sampleSource);
|
||||
player.setPlayWhenReady(true);
|
||||
Looper.loop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayWhenReadyCommitted () {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerError(ExoPlaybackException error) {
|
||||
playbackException = error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
if (playbackState == ExoPlayer.STATE_ENDED
|
||||
|| (playbackState == ExoPlayer.STATE_IDLE && playbackException != null)) {
|
||||
releasePlayerAndQuitLooper();
|
||||
}
|
||||
}
|
||||
|
||||
private void releasePlayerAndQuitLooper() {
|
||||
player.release();
|
||||
Looper.myLooper().quit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
14
extensions/opus/src/androidTest/project.properties
Normal file
14
extensions/opus/src/androidTest/project.properties
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# 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-23
|
||||
2
extensions/opus/src/androidTest/res/.README.txt
Normal file
2
extensions/opus/src/androidTest/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