Search in sources :

Example 21 with R

use of com.google.android.exoplayer2.ext.media2.test.R in project ExoPlayer by google.

the class DashManifestParserTest method parseSegmentTimeline_singleUndefinedRepeatCount.

@Test
public void parseSegmentTimeline_singleUndefinedRepeatCount() throws Exception {
    DashManifestParser parser = new DashManifestParser();
    XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser();
    xpp.setInput(new StringReader("<SegmentTimeline><S d=\"96000\" r=\"-1\"/></SegmentTimeline>" + NEXT_TAG));
    xpp.next();
    List<SegmentTimelineElement> elements = parser.parseSegmentTimeline(xpp, /* timescale= */
    48000, /* periodDurationMs= */
    10000);
    assertThat(elements).containsExactly(new SegmentTimelineElement(/* startTime= */
    0, /* duration= */
    96000), new SegmentTimelineElement(/* startTime= */
    96000, /* duration= */
    96000), new SegmentTimelineElement(/* startTime= */
    192000, /* duration= */
    96000), new SegmentTimelineElement(/* startTime= */
    288000, /* duration= */
    96000), new SegmentTimelineElement(/* startTime= */
    384000, /* duration= */
    96000)).inOrder();
    assertNextTag(xpp);
}
Also used : SegmentTimelineElement(com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SegmentTimelineElement) XmlPullParser(org.xmlpull.v1.XmlPullParser) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 22 with R

use of com.google.android.exoplayer2.ext.media2.test.R in project ExoPlayer by google.

the class RtspMediaPeriodTest method prepareMediaPeriod_refreshesSourceInfoAndCallsOnPrepared.

@Test
public void prepareMediaPeriod_refreshesSourceInfoAndCallsOnPrepared() throws Exception {
    RtpPacketStreamDump rtpPacketStreamDump = RtspTestUtils.readRtpPacketStreamDump("media/rtsp/aac-dump.json");
    rtspServer = new RtspServer(new RtspServer.ResponseProvider() {

        @Override
        public RtspResponse getOptionsResponse() {
            return new RtspResponse(/* status= */
            200, new RtspHeaders.Builder().add(RtspHeaders.PUBLIC, "OPTIONS, DESCRIBE").build());
        }

        @Override
        public RtspResponse getDescribeResponse(Uri requestedUri, RtspHeaders headers) {
            return RtspTestUtils.newDescribeResponseWithSdpMessage("v=0\r\n" + "o=- 1606776316530225 1 IN IP4 127.0.0.1\r\n" + "s=Exoplayer test\r\n" + "t=0 0\r\n" + // The session is 50.46s long.
            "a=range:npt=0-50.46\r\n", ImmutableList.of(rtpPacketStreamDump), requestedUri);
        }
    });
    AtomicBoolean prepareCallbackCalled = new AtomicBoolean();
    AtomicLong refreshedSourceDurationMs = new AtomicLong();
    mediaPeriod = new RtspMediaPeriod(new DefaultAllocator(/* trimOnReset= */
    true, C.DEFAULT_BUFFER_SEGMENT_SIZE), new TransferRtpDataChannelFactory(DEFAULT_TIMEOUT_MS), RtspTestUtils.getTestUri(rtspServer.startAndGetPortNumber()), /* listener= */
    timing -> refreshedSourceDurationMs.set(timing.getDurationMs()), /* userAgent= */
    "ExoPlayer:RtspPeriodTest", /* socketFactory= */
    SocketFactory.getDefault(), /* debugLoggingEnabled= */
    false);
    mediaPeriod.prepare(new MediaPeriod.Callback() {

        @Override
        public void onPrepared(MediaPeriod mediaPeriod) {
            prepareCallbackCalled.set(true);
        }

        @Override
        public void onContinueLoadingRequested(MediaPeriod source) {
            source.continueLoading(/* positionUs= */
            0);
        }
    }, /* positionUs= */
    0);
    RobolectricUtil.runMainLooperUntil(prepareCallbackCalled::get);
    mediaPeriod.release();
    assertThat(refreshedSourceDurationMs.get()).isEqualTo(50_460);
}
Also used : Util(com.google.android.exoplayer2.util.Util) Uri(android.net.Uri) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) SocketFactory(javax.net.SocketFactory) AtomicLong(java.util.concurrent.atomic.AtomicLong) RobolectricUtil(com.google.android.exoplayer2.robolectric.RobolectricUtil) ImmutableList(com.google.common.collect.ImmutableList) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) After(org.junit.After) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) C(com.google.android.exoplayer2.C) Uri(android.net.Uri) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) Test(org.junit.Test)

Example 23 with R

use of com.google.android.exoplayer2.ext.media2.test.R in project ExoPlayer by google.

the class HlsMediaPlaylistParserTest method parseMediaPlaylist.

@Test
public void parseMediaPlaylist() throws Exception {
    Uri playlistUri = Uri.parse("https://example.com/test.m3u8");
    String playlistString = "#EXTM3U\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-PLAYLIST-TYPE:VOD\n" + "#EXT-X-START:TIME-OFFSET=-25\n" + "#EXT-X-TARGETDURATION:8\n" + "#EXT-X-MEDIA-SEQUENCE:2679\n" + "#EXT-X-DISCONTINUITY-SEQUENCE:4\n" + "#EXT-X-ALLOW-CACHE:YES\n" + "\n" + "#EXTINF:7.975,\n" + "#EXT-X-BYTERANGE:51370@0\n" + "https://priv.example.com/fileSequence2679.ts\n" + "\n" + "#EXT-X-KEY:METHOD=AES-128," + "URI=\"https://priv.example.com/key.php?r=2680\",IV=0x1566B\n" + "#EXTINF:7.975,segment title\n" + "#EXT-X-BYTERANGE:51501@2147483648\n" + "https://priv.example.com/fileSequence2680.ts\n" + "\n" + "#EXT-X-KEY:METHOD=NONE\n" + "#EXTINF:7.941,segment title .,:/# with interesting chars\n" + // @2147535149
    "#EXT-X-BYTERANGE:51501\n" + "https://priv.example.com/fileSequence2681.ts\n" + "\n" + "#EXT-X-DISCONTINUITY\n" + "#EXT-X-KEY:METHOD=AES-128,URI=\"https://priv.example.com/key.php?r=2682\"\n" + // Trailing comma is omitted.
    "#EXTINF:7.975\n" + // @2147586650
    "#EXT-X-BYTERANGE:51740\n" + "https://priv.example.com/fileSequence2682.ts\n" + "\n" + "#EXTINF:7.975,\n" + "https://priv.example.com/fileSequence2683.ts\n" + "\n" + // 2.002 tests correct rounding, see https://github.com/google/ExoPlayer/issues/9575.
    "#EXTINF:2.002,\n" + "https://priv.example.com/fileSequence2684.ts\n" + "#EXT-X-ENDLIST";
    InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString));
    HlsPlaylist playlist = new HlsPlaylistParser().parse(playlistUri, inputStream);
    HlsMediaPlaylist mediaPlaylist = (HlsMediaPlaylist) playlist;
    assertThat(mediaPlaylist.playlistType).isEqualTo(HlsMediaPlaylist.PLAYLIST_TYPE_VOD);
    assertThat(mediaPlaylist.startOffsetUs).isEqualTo(mediaPlaylist.durationUs - 25000000);
    assertThat(mediaPlaylist.mediaSequence).isEqualTo(2679);
    assertThat(mediaPlaylist.version).isEqualTo(3);
    assertThat(mediaPlaylist.hasEndTag).isTrue();
    assertThat(mediaPlaylist.protectionSchemes).isNull();
    assertThat(mediaPlaylist.targetDurationUs).isEqualTo(8000000);
    assertThat(mediaPlaylist.partTargetDurationUs).isEqualTo(C.TIME_UNSET);
    List<Segment> segments = mediaPlaylist.segments;
    assertThat(segments).isNotNull();
    assertThat(segments).hasSize(6);
    Segment segment = segments.get(0);
    assertThat(mediaPlaylist.discontinuitySequence + segment.relativeDiscontinuitySequence).isEqualTo(4);
    assertThat(segment.durationUs).isEqualTo(7975000);
    assertThat(segment.title).isEqualTo("");
    assertThat(segment.fullSegmentEncryptionKeyUri).isNull();
    assertThat(segment.encryptionIV).isNull();
    assertThat(segment.byteRangeLength).isEqualTo(51370);
    assertThat(segment.byteRangeOffset).isEqualTo(0);
    assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2679.ts");
    segment = segments.get(1);
    assertThat(segment.relativeDiscontinuitySequence).isEqualTo(0);
    assertThat(segment.durationUs).isEqualTo(7975000);
    assertThat(segment.title).isEqualTo("segment title");
    assertThat(segment.fullSegmentEncryptionKeyUri).isEqualTo("https://priv.example.com/key.php?r=2680");
    assertThat(segment.encryptionIV).isEqualTo("0x1566B");
    assertThat(segment.byteRangeLength).isEqualTo(51501);
    assertThat(segment.byteRangeOffset).isEqualTo(2147483648L);
    assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2680.ts");
    segment = segments.get(2);
    assertThat(segment.relativeDiscontinuitySequence).isEqualTo(0);
    assertThat(segment.durationUs).isEqualTo(7941000);
    assertThat(segment.title).isEqualTo("segment title .,:/# with interesting chars");
    assertThat(segment.fullSegmentEncryptionKeyUri).isNull();
    assertThat(segment.encryptionIV).isEqualTo(null);
    assertThat(segment.byteRangeLength).isEqualTo(51501);
    assertThat(segment.byteRangeOffset).isEqualTo(2147535149L);
    assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2681.ts");
    segment = segments.get(3);
    assertThat(segment.relativeDiscontinuitySequence).isEqualTo(1);
    assertThat(segment.durationUs).isEqualTo(7975000);
    assertThat(segment.title).isEqualTo("");
    assertThat(segment.fullSegmentEncryptionKeyUri).isEqualTo("https://priv.example.com/key.php?r=2682");
    // 0xA7A == 2682.
    assertThat(segment.encryptionIV).isNotNull();
    assertThat(segment.encryptionIV).ignoringCase().isEqualTo("A7A");
    assertThat(segment.byteRangeLength).isEqualTo(51740);
    assertThat(segment.byteRangeOffset).isEqualTo(2147586650L);
    assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2682.ts");
    segment = segments.get(4);
    assertThat(segment.relativeDiscontinuitySequence).isEqualTo(1);
    assertThat(segment.durationUs).isEqualTo(7975000);
    assertThat(segment.title).isEqualTo("");
    assertThat(segment.fullSegmentEncryptionKeyUri).isEqualTo("https://priv.example.com/key.php?r=2682");
    // 0xA7B == 2683.
    assertThat(segment.encryptionIV).isNotNull();
    assertThat(segment.encryptionIV).ignoringCase().isEqualTo("A7B");
    assertThat(segment.byteRangeLength).isEqualTo(C.LENGTH_UNSET);
    assertThat(segment.byteRangeOffset).isEqualTo(0);
    assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2683.ts");
    segment = segments.get(5);
    assertThat(segment.durationUs).isEqualTo(2002000);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Uri(android.net.Uri) Segment(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment) Test(org.junit.Test)

Example 24 with R

use of com.google.android.exoplayer2.ext.media2.test.R in project ExoPlayer by google.

the class VorbisUtilTest method testVerifyVorbisHeaderCapturePatternInvalidPattern.

public void testVerifyVorbisHeaderCapturePatternInvalidPattern() {
    ParsableByteArray header = new ParsableByteArray(new byte[] { 0x01, 'x', 'v', 'o', 'r', 'b', 'i', 's' });
    try {
        VorbisUtil.verifyVorbisHeaderCapturePattern(0x01, header, false);
        fail();
    } catch (ParserException e) {
        assertEquals("expected characters 'vorbis'", e.getMessage());
    }
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) ParserException(com.google.android.exoplayer2.ParserException)

Example 25 with R

use of com.google.android.exoplayer2.ext.media2.test.R in project ExoPlayer by google.

the class VorbisUtilTest method testVerifyVorbisHeaderCapturePatternInvalidHeaderQuite.

public void testVerifyVorbisHeaderCapturePatternInvalidHeaderQuite() throws ParserException {
    ParsableByteArray header = new ParsableByteArray(new byte[] { 0x01, 'v', 'o', 'r', 'b', 'i', 's' });
    assertFalse(VorbisUtil.verifyVorbisHeaderCapturePattern(0x99, header, true));
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray)

Aggregations

Test (org.junit.Test)16 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)12 Uri (android.net.Uri)8 ParserException (com.google.android.exoplayer2.ParserException)5 InputStream (java.io.InputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 SegmentTimelineElement (com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SegmentTimelineElement)3 Segment (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment)3 IOException (java.io.IOException)3 StringReader (java.io.StringReader)3 XmlPullParser (org.xmlpull.v1.XmlPullParser)3 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)2 C (com.google.android.exoplayer2.C)2 RobolectricUtil (com.google.android.exoplayer2.robolectric.RobolectricUtil)2 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)2 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)2 Util (com.google.android.exoplayer2.util.Util)2 ImmutableList (com.google.common.collect.ImmutableList)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 File (java.io.File)2