mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Add CompositionPlayer unit test
Test the audio side only because the video side won't be testable with unit tests once we add the OpenGL components. PiperOrigin-RevId: 554508703
This commit is contained in:
parent
691bf93032
commit
f43146718c
@ -0,0 +1,52 @@
|
|||||||
|
buffer count = 14
|
||||||
|
config:
|
||||||
|
pcmEncoding = 2
|
||||||
|
channelCount = 1
|
||||||
|
sampleRate = 44100
|
||||||
|
buffer #0:
|
||||||
|
time = 1000000000000
|
||||||
|
data = -85819864
|
||||||
|
buffer #1:
|
||||||
|
time = 1000000100000
|
||||||
|
data = 566487491
|
||||||
|
buffer #2:
|
||||||
|
time = 1000000200000
|
||||||
|
data = -1256531710
|
||||||
|
buffer #3:
|
||||||
|
time = 1000000300000
|
||||||
|
data = 793455796
|
||||||
|
buffer #4:
|
||||||
|
time = 1000000400000
|
||||||
|
data = -268235582
|
||||||
|
buffer #5:
|
||||||
|
time = 1000000500000
|
||||||
|
data = -8136122
|
||||||
|
buffer #6:
|
||||||
|
time = 1000000600000
|
||||||
|
data = 1750866613
|
||||||
|
buffer #7:
|
||||||
|
time = 1000000700000
|
||||||
|
data = -1100753636
|
||||||
|
buffer #8:
|
||||||
|
time = 1000000800000
|
||||||
|
data = 507833230
|
||||||
|
buffer #9:
|
||||||
|
time = 1000000900000
|
||||||
|
data = 1472467506
|
||||||
|
discontinuity:
|
||||||
|
config:
|
||||||
|
pcmEncoding = 2
|
||||||
|
channelCount = 2
|
||||||
|
sampleRate = 48000
|
||||||
|
buffer #10:
|
||||||
|
time = 1000001000000
|
||||||
|
data = -278103001
|
||||||
|
buffer #11:
|
||||||
|
time = 1000001100000
|
||||||
|
data = 1522105084
|
||||||
|
buffer #12:
|
||||||
|
time = 1000001200000
|
||||||
|
data = 932319027
|
||||||
|
buffer #13:
|
||||||
|
time = 1000001300000
|
||||||
|
data = 325000240
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2023 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
|
||||||
|
*
|
||||||
|
* https://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 androidx.media3.transformer;
|
||||||
|
|
||||||
|
import static androidx.media3.transformer.TestUtil.ASSET_URI_PREFIX;
|
||||||
|
import static androidx.media3.transformer.TestUtil.FILE_AUDIO_RAW;
|
||||||
|
import static androidx.media3.transformer.TestUtil.FILE_AUDIO_RAW_STEREO_48000KHZ;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import androidx.media3.common.MediaItem;
|
||||||
|
import androidx.media3.common.Player;
|
||||||
|
import androidx.media3.common.util.Clock;
|
||||||
|
import androidx.media3.exoplayer.audio.DefaultAudioSink;
|
||||||
|
import androidx.media3.test.utils.CapturingAudioSink;
|
||||||
|
import androidx.media3.test.utils.DumpFileAsserts;
|
||||||
|
import androidx.media3.test.utils.FakeClock;
|
||||||
|
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
/** Unit tests for {@link CompositionPlayer}. */
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class CompositionPlayerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void playback_audioOnly_outputsSamples() throws Exception {
|
||||||
|
Context applicationContext = ApplicationProvider.getApplicationContext();
|
||||||
|
Clock clock = new FakeClock(/* isAutoAdvancing= */ true);
|
||||||
|
CapturingAudioSink capturingAudioSink =
|
||||||
|
new CapturingAudioSink(new DefaultAudioSink.Builder(applicationContext).build());
|
||||||
|
CompositionPlayer player =
|
||||||
|
new CompositionPlayer(applicationContext, /* looper= */ null, capturingAudioSink, clock);
|
||||||
|
EditedMediaItem editedMediaItem1 =
|
||||||
|
new EditedMediaItem.Builder(MediaItem.fromUri(ASSET_URI_PREFIX + FILE_AUDIO_RAW)).build();
|
||||||
|
EditedMediaItem editedMediaItem2 =
|
||||||
|
new EditedMediaItem.Builder(
|
||||||
|
MediaItem.fromUri(ASSET_URI_PREFIX + FILE_AUDIO_RAW_STEREO_48000KHZ))
|
||||||
|
.build();
|
||||||
|
EditedMediaItemSequence sequence =
|
||||||
|
new EditedMediaItemSequence(ImmutableList.of(editedMediaItem1, editedMediaItem2));
|
||||||
|
Composition composition = new Composition.Builder(ImmutableList.of(sequence)).build();
|
||||||
|
|
||||||
|
player.setComposition(composition);
|
||||||
|
player.prepare();
|
||||||
|
player.play();
|
||||||
|
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
|
||||||
|
player.release();
|
||||||
|
|
||||||
|
DumpFileAsserts.assertOutput(
|
||||||
|
applicationContext,
|
||||||
|
capturingAudioSink,
|
||||||
|
"audiosinkdumps/wav/sample.wav_then_sample_rf64.wav.dump");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user