Search in sources :

Example 1 with R

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

the class HlsMediaPlaylistParserTest method testParseMediaPlaylist.

public void testParseMediaPlaylist() {
    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" + "#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,\n" + "#EXT-X-BYTERANGE:51501@2147483648\n" + "https://priv.example.com/fileSequence2680.ts\n" + "\n" + "#EXT-X-KEY:METHOD=NONE\n" + "#EXTINF:7.941,\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" + "#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" + "#EXT-X-ENDLIST";
    InputStream inputStream = new ByteArrayInputStream(playlistString.getBytes(Charset.forName(C.UTF8_NAME)));
    try {
        HlsPlaylist playlist = new HlsPlaylistParser().parse(playlistUri, inputStream);
        assertNotNull(playlist);
        assertEquals(HlsPlaylist.TYPE_MEDIA, playlist.type);
        HlsMediaPlaylist mediaPlaylist = (HlsMediaPlaylist) playlist;
        assertEquals(HlsMediaPlaylist.PLAYLIST_TYPE_VOD, mediaPlaylist.playlistType);
        assertEquals(mediaPlaylist.durationUs - 25000000, mediaPlaylist.startOffsetUs);
        assertEquals(2679, mediaPlaylist.mediaSequence);
        assertEquals(3, mediaPlaylist.version);
        assertTrue(mediaPlaylist.hasEndTag);
        List<Segment> segments = mediaPlaylist.segments;
        assertNotNull(segments);
        assertEquals(5, segments.size());
        Segment segment = segments.get(0);
        assertEquals(4, mediaPlaylist.discontinuitySequence + segment.relativeDiscontinuitySequence);
        assertEquals(7975000, segment.durationUs);
        assertFalse(segment.isEncrypted);
        assertEquals(null, segment.encryptionKeyUri);
        assertEquals(null, segment.encryptionIV);
        assertEquals(51370, segment.byterangeLength);
        assertEquals(0, segment.byterangeOffset);
        assertEquals("https://priv.example.com/fileSequence2679.ts", segment.url);
        segment = segments.get(1);
        assertEquals(0, segment.relativeDiscontinuitySequence);
        assertEquals(7975000, segment.durationUs);
        assertTrue(segment.isEncrypted);
        assertEquals("https://priv.example.com/key.php?r=2680", segment.encryptionKeyUri);
        assertEquals("0x1566B", segment.encryptionIV);
        assertEquals(51501, segment.byterangeLength);
        assertEquals(2147483648L, segment.byterangeOffset);
        assertEquals("https://priv.example.com/fileSequence2680.ts", segment.url);
        segment = segments.get(2);
        assertEquals(0, segment.relativeDiscontinuitySequence);
        assertEquals(7941000, segment.durationUs);
        assertFalse(segment.isEncrypted);
        assertEquals(null, segment.encryptionKeyUri);
        assertEquals(null, segment.encryptionIV);
        assertEquals(51501, segment.byterangeLength);
        assertEquals(2147535149L, segment.byterangeOffset);
        assertEquals("https://priv.example.com/fileSequence2681.ts", segment.url);
        segment = segments.get(3);
        assertEquals(1, segment.relativeDiscontinuitySequence);
        assertEquals(7975000, segment.durationUs);
        assertTrue(segment.isEncrypted);
        assertEquals("https://priv.example.com/key.php?r=2682", segment.encryptionKeyUri);
        // 0xA7A == 2682.
        assertNotNull(segment.encryptionIV);
        assertEquals("A7A", segment.encryptionIV.toUpperCase(Locale.getDefault()));
        assertEquals(51740, segment.byterangeLength);
        assertEquals(2147586650L, segment.byterangeOffset);
        assertEquals("https://priv.example.com/fileSequence2682.ts", segment.url);
        segment = segments.get(4);
        assertEquals(1, segment.relativeDiscontinuitySequence);
        assertEquals(7975000, segment.durationUs);
        assertTrue(segment.isEncrypted);
        assertEquals("https://priv.example.com/key.php?r=2682", segment.encryptionKeyUri);
        // 0xA7B == 2683.
        assertNotNull(segment.encryptionIV);
        assertEquals("A7B", segment.encryptionIV.toUpperCase(Locale.getDefault()));
        assertEquals(C.LENGTH_UNSET, segment.byterangeLength);
        assertEquals(0, segment.byterangeOffset);
        assertEquals("https://priv.example.com/fileSequence2683.ts", segment.url);
    } catch (IOException exception) {
        fail(exception.getMessage());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Uri(android.net.Uri) Segment(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment)

Example 2 with R

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

the class VorbisUtilTest method testVerifyVorbisHeaderCapturePatternQuiteInvalidPatternQuite.

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

Example 3 with R

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

the class VorbisUtilTest method testVerifyVorbisHeaderCapturePatternInvalidHeader.

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

Example 4 with R

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

the class VorbisUtilTest method testVerifyVorbisHeaderCapturePattern.

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

Example 5 with R

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

the class TransformerActivity method startTransformation.

@RequiresNonNull({ "playerView", "debugTextView", "informationTextView", "progressIndicator", "transformationStopwatch", "progressViewGroup", "debugFrame" })
private void startTransformation() {
    requestTransformerPermission();
    Intent intent = getIntent();
    Uri uri = checkNotNull(intent.getData());
    try {
        externalCacheFile = createExternalCacheFile("transformer-output.mp4");
        String filePath = externalCacheFile.getAbsolutePath();
        @Nullable Bundle bundle = intent.getExtras();
        Transformer transformer = createTransformer(bundle, filePath);
        transformationStopwatch.start();
        transformer.startTransformation(MediaItem.fromUri(uri), filePath);
        this.transformer = transformer;
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    informationTextView.setText(R.string.transformation_started);
    playerView.setVisibility(View.GONE);
    Handler mainHandler = new Handler(getMainLooper());
    ProgressHolder progressHolder = new ProgressHolder();
    mainHandler.post(new Runnable() {

        @Override
        public void run() {
            if (transformer != null && transformer.getProgress(progressHolder) != Transformer.PROGRESS_STATE_NO_TRANSFORMATION) {
                progressIndicator.setProgress(progressHolder.progress);
                informationTextView.setText(getString(R.string.transformation_timer, transformationStopwatch.elapsed(TimeUnit.SECONDS)));
                mainHandler.postDelayed(/* r= */
                this, /* delayMillis= */
                500);
            }
        }
    });
}
Also used : Transformer(com.google.android.exoplayer2.transformer.Transformer) Bundle(android.os.Bundle) Handler(android.os.Handler) Intent(android.content.Intent) IOException(java.io.IOException) Uri(android.net.Uri) Nullable(androidx.annotation.Nullable) ProgressHolder(com.google.android.exoplayer2.transformer.ProgressHolder) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

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