Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 129a6ccb authored by Andreas Huber's avatar Andreas Huber Committed by Android (Google) Code Review
Browse files

Merge "The MediaExtractor can now unselect tracks and has more control over seeking." into jb-dev

parents 77974166 f2855b3d
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -11076,15 +11076,20 @@ package android.media {
    method public boolean hasCacheReachedEndOfStream();
    method public int readSampleData(java.nio.ByteBuffer, int);
    method public final void release();
    method public void seekTo(long);
    method public void seekTo(long, int);
    method public void selectTrack(int);
    method public final void setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>) throws java.io.IOException;
    method public final void setDataSource(java.lang.String, java.util.Map<java.lang.String, java.lang.String>);
    method public final void setDataSource(java.lang.String);
    method public final void setDataSource(java.io.FileDescriptor);
    method public final void setDataSource(java.io.FileDescriptor, long, long);
    method public void unselectTrack(int);
    field public static final int SAMPLE_FLAG_ENCRYPTED = 2; // 0x2
    field public static final int SAMPLE_FLAG_SYNC = 1; // 0x1
    field public static final int SEEK_TO_CLOSEST = 3; // 0x3
    field public static final int SEEK_TO_CLOSEST_SYNC = 2; // 0x2
    field public static final int SEEK_TO_NEXT_SYNC = 1; // 0x1
    field public static final int SEEK_TO_PREVIOUS_SYNC = 0; // 0x0
  }
  public class MediaMetadataRetriever {
+22 −6
Original line number Diff line number Diff line
@@ -191,17 +191,33 @@ final public class MediaExtractor {

    /** Subsequent calls to {@link #readSampleData}, {@link #getSampleTrackIndex} and
     *  {@link #getSampleTime} only retrieve information for the subset of tracks
     *  selected by the call below.
     *  Selecting the same track multiple times has no effect, the track
     *  selected.
     *  Selecting the same track multiple times has no effect, the track is
     *  only selected once.
     *  Media data will be returned in the order of their timestamps.
    */
    public native void selectTrack(int index);

    /** All selected tracks seek near the requested time. The next sample
     *  returned for each selected track will be a sync sample.
    /** Subsequent calls to {@link #readSampleData}, {@link #getSampleTrackIndex} and
     *  {@link #getSampleTime} only retrieve information for the subset of tracks
     *  selected.
    */
    public native void unselectTrack(int index);

    /** If possible, seek to a sync sample at or before the specified time */
    public static final int SEEK_TO_PREVIOUS_SYNC       = 0;
    /** If possible, seek to a sync sample at or after the specified time */
    public static final int SEEK_TO_NEXT_SYNC           = 1;
    /** If possible, seek to the sync sample closest to the specified time */
    public static final int SEEK_TO_CLOSEST_SYNC        = 2;
    /** If possible, seek to a sample closest to the specified time, which may
      * NOT be a sync sample!
      */
    public static final int SEEK_TO_CLOSEST             = 3;

    /** All selected tracks seek near the requested time according to the
      * specified mode.
      */
    public native void seekTo(long timeUs);
    public native void seekTo(long timeUs, int mode);

    /** Advance to the next sample. Returns false if no more sample data
     *  is available (end of stream).
+36 −5
Original line number Diff line number Diff line
@@ -96,8 +96,13 @@ status_t JMediaExtractor::selectTrack(size_t index) {
    return mImpl->selectTrack(index);
}

status_t JMediaExtractor::seekTo(int64_t timeUs) {
    return mImpl->seekTo(timeUs);
status_t JMediaExtractor::unselectTrack(size_t index) {
    return mImpl->unselectTrack(index);
}

status_t JMediaExtractor::seekTo(
        int64_t timeUs, MediaSource::ReadOptions::SeekMode mode) {
    return mImpl->seekTo(timeUs, mode);
}

status_t JMediaExtractor::advance() {
@@ -281,8 +286,25 @@ static void android_media_MediaExtractor_selectTrack(
    }
}

static void android_media_MediaExtractor_unselectTrack(
        JNIEnv *env, jobject thiz, jint index) {
    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);

    if (extractor == NULL) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return;
    }

    status_t err = extractor->unselectTrack(index);

    if (err != OK) {
        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
        return;
    }
}

static void android_media_MediaExtractor_seekTo(
        JNIEnv *env, jobject thiz, jlong timeUs) {
        JNIEnv *env, jobject thiz, jlong timeUs, jint mode) {
    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);

    if (extractor == NULL) {
@@ -290,7 +312,13 @@ static void android_media_MediaExtractor_seekTo(
        return;
    }

    extractor->seekTo(timeUs);
    if (mode < MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC
            || mode > MediaSource::ReadOptions::SEEK_CLOSEST) {
        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
        return;
    }

    extractor->seekTo(timeUs, (MediaSource::ReadOptions::SeekMode)mode);
}

static jboolean android_media_MediaExtractor_advance(
@@ -648,7 +676,10 @@ static JNINativeMethod gMethods[] = {

    { "selectTrack", "(I)V", (void *)android_media_MediaExtractor_selectTrack },

    { "seekTo", "(J)V", (void *)android_media_MediaExtractor_seekTo },
    { "unselectTrack", "(I)V",
        (void *)android_media_MediaExtractor_unselectTrack },

    { "seekTo", "(JI)V", (void *)android_media_MediaExtractor_seekTo },

    { "advance", "()Z", (void *)android_media_MediaExtractor_advance },

+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define _ANDROID_MEDIA_MEDIAEXTRACTOR_H_

#include <media/stagefright/foundation/ABase.h>
#include <media/stagefright/MediaSource.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/RefBase.h>
@@ -43,8 +44,9 @@ struct JMediaExtractor : public RefBase {
    status_t getTrackFormat(size_t index, jobject *format) const;

    status_t selectTrack(size_t index);
    status_t unselectTrack(size_t index);

    status_t seekTo(int64_t timeUs);
    status_t seekTo(int64_t timeUs, MediaSource::ReadOptions::SeekMode mode);

    status_t advance();
    status_t readSampleData(jobject byteBuf, size_t offset, size_t *sampleSize);