Add test for SsMediaPeriod.getStreamKeys
PiperOrigin-RevId: 225811310
This commit is contained in:
parent
8202cb2d2a
commit
ee14b1fa40
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.exoplayer2.source.smoothstreaming;
|
||||
|
||||
import static com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils.createSsManifest;
|
||||
import static com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils.createStreamElement;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.source.CompositeSequenceableLoaderFactory;
|
||||
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
||||
import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest;
|
||||
import com.google.android.exoplayer2.testutil.MediaPeriodAsserts;
|
||||
import com.google.android.exoplayer2.testutil.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory;
|
||||
import com.google.android.exoplayer2.testutil.RobolectricUtil;
|
||||
import com.google.android.exoplayer2.upstream.Allocator;
|
||||
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
|
||||
import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
|
||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
/** Unit tests for {@link SsMediaPeriod}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {RobolectricUtil.CustomLooper.class, RobolectricUtil.CustomMessageQueue.class})
|
||||
public class SsMediaPeriodTest {
|
||||
|
||||
@Test
|
||||
public void getSteamKeys_isCompatibleWithSsManifestFilter() {
|
||||
SsManifest testManifest =
|
||||
createSsManifest(
|
||||
createStreamElement(
|
||||
/* name= */ "video",
|
||||
C.TRACK_TYPE_VIDEO,
|
||||
createVideoFormat(/* bitrate= */ 200000),
|
||||
createVideoFormat(/* bitrate= */ 400000),
|
||||
createVideoFormat(/* bitrate= */ 800000)),
|
||||
createStreamElement(
|
||||
/* name= */ "audio",
|
||||
C.TRACK_TYPE_AUDIO,
|
||||
createAudioFormat(/* bitrate= */ 48000),
|
||||
createAudioFormat(/* bitrate= */ 96000)),
|
||||
createStreamElement(
|
||||
/* name= */ "text", C.TRACK_TYPE_TEXT, createTextFormat(/* language= */ "eng")));
|
||||
FilterableManifestMediaPeriodFactory<SsManifest> mediaPeriodFactory =
|
||||
manifest ->
|
||||
new SsMediaPeriod(
|
||||
manifest,
|
||||
mock(SsChunkSource.Factory.class),
|
||||
mock(TransferListener.class),
|
||||
mock(CompositeSequenceableLoaderFactory.class),
|
||||
mock(LoadErrorHandlingPolicy.class),
|
||||
new EventDispatcher()
|
||||
.withParameters(
|
||||
/* windowIndex= */ 0,
|
||||
/* mediaPeriodId= */ new MediaPeriodId(/* periodUid= */ new Object()),
|
||||
/* mediaTimeOffsetMs= */ 0),
|
||||
mock(LoaderErrorThrower.class),
|
||||
mock(Allocator.class));
|
||||
|
||||
MediaPeriodAsserts.assertGetStreamKeysAndManifestFilterIntegration(
|
||||
mediaPeriodFactory, testManifest);
|
||||
}
|
||||
|
||||
private static Format createVideoFormat(int bitrate) {
|
||||
return Format.createContainerFormat(
|
||||
/* id= */ null,
|
||||
/* label= */ null,
|
||||
MimeTypes.VIDEO_MP4,
|
||||
MimeTypes.VIDEO_H264,
|
||||
/* codecs= */ null,
|
||||
bitrate,
|
||||
/* selectionFlags= */ 0,
|
||||
/* language= */ null);
|
||||
}
|
||||
|
||||
private static Format createAudioFormat(int bitrate) {
|
||||
return Format.createContainerFormat(
|
||||
/* id= */ null,
|
||||
/* label= */ null,
|
||||
MimeTypes.AUDIO_MP4,
|
||||
MimeTypes.AUDIO_AAC,
|
||||
/* codecs= */ null,
|
||||
bitrate,
|
||||
/* selectionFlags= */ 0,
|
||||
/* language= */ null);
|
||||
}
|
||||
|
||||
private static Format createTextFormat(String language) {
|
||||
return Format.createContainerFormat(
|
||||
/* id= */ null,
|
||||
/* label= */ null,
|
||||
MimeTypes.APPLICATION_MP4,
|
||||
MimeTypes.TEXT_VTT,
|
||||
/* codecs= */ null,
|
||||
/* bitrate= */ Format.NO_VALUE,
|
||||
/* selectionFlags= */ 0,
|
||||
language);
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.exoplayer2.source.smoothstreaming;
|
||||
|
||||
import android.util.Base64;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.ProtectionElement;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
|
||||
/** Util methods for SmoothStreaming tests. */
|
||||
public class SsTestUtils {
|
||||
|
||||
private static final int TEST_MAJOR_VERSION = 1;
|
||||
private static final int TEST_MINOR_VERSION = 2;
|
||||
private static final int TEST_TIMESCALE = 1000;
|
||||
private static final int TEST_DURATION = 5000;
|
||||
private static final int TEST_DVR_WINDOW_LENGTH = 0;
|
||||
private static final int TEST_LOOKAHEAD_COUNT = 0;
|
||||
private static final boolean TEST_IS_LIVE = false;
|
||||
private static final String TEST_BASE_URI = "baseUri";
|
||||
private static final String TEST_CHUNK_TEMPLATE = "chunkTemplate";
|
||||
private static final String TEST_SUB_TYPE = "subType";
|
||||
private static final int TEST_MAX_WIDTH = 1024;
|
||||
private static final int TEST_MAX_HEIGHT = 768;
|
||||
private static final String TEST_LANGUAGE = "eng";
|
||||
private static final ProtectionElement TEST_PROTECTION_ELEMENT =
|
||||
new ProtectionElement(
|
||||
C.WIDEVINE_UUID,
|
||||
("<KID>"
|
||||
+ Base64.encodeToString(new byte[] {0, 1, 2, 3, 4, 5, 6, 7}, Base64.DEFAULT)
|
||||
+ "</KID>")
|
||||
.getBytes(StandardCharsets.UTF_16LE));
|
||||
|
||||
private SsTestUtils() {}
|
||||
|
||||
/** Creates test manifest with the given stream elements. */
|
||||
public static SsManifest createSsManifest(StreamElement... streamElements) {
|
||||
return new SsManifest(
|
||||
TEST_MAJOR_VERSION,
|
||||
TEST_MINOR_VERSION,
|
||||
TEST_TIMESCALE,
|
||||
TEST_DURATION,
|
||||
TEST_DVR_WINDOW_LENGTH,
|
||||
TEST_LOOKAHEAD_COUNT,
|
||||
TEST_IS_LIVE,
|
||||
TEST_PROTECTION_ELEMENT,
|
||||
streamElements);
|
||||
}
|
||||
|
||||
/** Creates test video stream element with the given name, track type and formats. */
|
||||
public static StreamElement createStreamElement(String name, int trackType, Format... formats) {
|
||||
return new StreamElement(
|
||||
TEST_BASE_URI,
|
||||
TEST_CHUNK_TEMPLATE,
|
||||
trackType,
|
||||
TEST_SUB_TYPE,
|
||||
TEST_TIMESCALE,
|
||||
name,
|
||||
TEST_MAX_WIDTH,
|
||||
TEST_MAX_HEIGHT,
|
||||
TEST_MAX_WIDTH,
|
||||
TEST_MAX_HEIGHT,
|
||||
TEST_LANGUAGE,
|
||||
formats,
|
||||
/* chunkStartTimes= */ Collections.emptyList(),
|
||||
/* lastChunkDuration= */ 0);
|
||||
}
|
||||
}
|
@ -15,12 +15,13 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.source.smoothstreaming.manifest;
|
||||
|
||||
import static com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils.createSsManifest;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.offline.StreamKey;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.ProtectionElement;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import java.util.Arrays;
|
||||
@ -35,14 +36,12 @@ import org.robolectric.RobolectricTestRunner;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SsManifestTest {
|
||||
|
||||
private static final ProtectionElement DUMMY_PROTECTION_ELEMENT =
|
||||
new ProtectionElement(C.WIDEVINE_UUID, new byte[] {0, 1, 2});
|
||||
|
||||
@Test
|
||||
public void testCopy() throws Exception {
|
||||
Format[][] formats = newFormats(2, 3);
|
||||
SsManifest sourceManifest =
|
||||
newSsManifest(newStreamElement("1", formats[0]), newStreamElement("2", formats[1]));
|
||||
createSsManifest(
|
||||
createStreamElement("1", formats[0]), createStreamElement("2", formats[1]));
|
||||
|
||||
List<StreamKey> keys =
|
||||
Arrays.asList(new StreamKey(0, 0), new StreamKey(0, 2), new StreamKey(1, 0));
|
||||
@ -52,9 +51,9 @@ public class SsManifestTest {
|
||||
SsManifest copyManifest = sourceManifest.copy(keys);
|
||||
|
||||
SsManifest expectedManifest =
|
||||
newSsManifest(
|
||||
newStreamElement("1", formats[0][0], formats[0][2]),
|
||||
newStreamElement("2", formats[1][0]));
|
||||
createSsManifest(
|
||||
createStreamElement("1", formats[0][0], formats[0][2]),
|
||||
createStreamElement("2", formats[1][0]));
|
||||
assertManifestEquals(expectedManifest, copyManifest);
|
||||
}
|
||||
|
||||
@ -62,13 +61,14 @@ public class SsManifestTest {
|
||||
public void testCopyRemoveStreamElement() throws Exception {
|
||||
Format[][] formats = newFormats(2, 3);
|
||||
SsManifest sourceManifest =
|
||||
newSsManifest(newStreamElement("1", formats[0]), newStreamElement("2", formats[1]));
|
||||
createSsManifest(
|
||||
createStreamElement("1", formats[0]), createStreamElement("2", formats[1]));
|
||||
|
||||
List<StreamKey> keys = Collections.singletonList(new StreamKey(1, 0));
|
||||
|
||||
SsManifest copyManifest = sourceManifest.copy(keys);
|
||||
|
||||
SsManifest expectedManifest = newSsManifest(newStreamElement("2", formats[1][0]));
|
||||
SsManifest expectedManifest = createSsManifest(createStreamElement("2", formats[1][0]));
|
||||
assertManifestEquals(expectedManifest, copyManifest);
|
||||
}
|
||||
|
||||
@ -109,26 +109,8 @@ public class SsManifestTest {
|
||||
return formats;
|
||||
}
|
||||
|
||||
private static SsManifest newSsManifest(StreamElement... streamElements) {
|
||||
return new SsManifest(1, 2, 1000, 5000, 0, 0, false, DUMMY_PROTECTION_ELEMENT, streamElements);
|
||||
}
|
||||
|
||||
private static StreamElement newStreamElement(String name, Format... formats) {
|
||||
return new StreamElement(
|
||||
"baseUri",
|
||||
"chunkTemplate",
|
||||
C.TRACK_TYPE_VIDEO,
|
||||
"subType",
|
||||
1000,
|
||||
name,
|
||||
1024,
|
||||
768,
|
||||
1024,
|
||||
768,
|
||||
null,
|
||||
formats,
|
||||
Collections.emptyList(),
|
||||
0);
|
||||
private static StreamElement createStreamElement(String name, Format... formats) {
|
||||
return SsTestUtils.createStreamElement(name, C.TRACK_TYPE_VIDEO, formats);
|
||||
}
|
||||
|
||||
private static Format newFormat(String id) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user