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

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

Merge "Add the ability to query the amount of cached data to MediaExtractor."

parents 362bcb06 74a78b0f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -11063,11 +11063,13 @@ package android.media {
    ctor public MediaExtractor();
    method public boolean advance();
    method public int countTracks();
    method public long getCachedDuration();
    method public boolean getSampleCryptoInfo(android.media.MediaCodec.CryptoInfo);
    method public int getSampleFlags();
    method public long getSampleTime();
    method public int getSampleTrackIndex();
    method public java.util.Map<java.lang.String, java.lang.Object> getTrackFormat(int);
    method public boolean hasCacheReachedEndOfStream();
    method public int readSampleData(java.nio.ByteBuffer, int);
    method public final void release();
    method public void seekTo(long);
+14 −0
Original line number Diff line number Diff line
@@ -245,6 +245,20 @@ final public class MediaExtractor {
    */
    public native boolean getSampleCryptoInfo(MediaCodec.CryptoInfo info);

    /** Returns an estimate of how much data is presently cached in memory
        expressed in microseconds. Returns -1 if that information is unavailable
        or not applicable (no cache).
     */
    public native long getCachedDuration();

    /** Returns true iff we are caching data and the cache has reached the
     *  end of the data stream (for now, a future seek may of course restart
     *  the fetching of data).
     *  This API only returns a meaningful result if {link #getCachedDuration}
     *  indicates the presence of a cache, i.e. does NOT return -1.
    */
    public native boolean hasCacheReachedEndOfStream();

    private static native final void native_init();
    private native final void native_setup();
    private native final void native_finalize();
+46 −0
Original line number Diff line number Diff line
@@ -198,6 +198,10 @@ status_t JMediaExtractor::getSampleMeta(sp<MetaData> *sampleMeta) {
    return mImpl->getSampleMeta(sampleMeta);
}

bool JMediaExtractor::getCachedDuration(int64_t *durationUs, bool *eos) const {
    return mImpl->getCachedDuration(durationUs, eos);
}

}  // namespace android

////////////////////////////////////////////////////////////////////////////////
@@ -593,6 +597,42 @@ static void android_media_MediaExtractor_setDataSourceFd(
    }
}

static jlong android_media_MediaExtractor_getCachedDurationUs(
        JNIEnv *env, jobject thiz) {
    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);

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

    int64_t cachedDurationUs;
    bool eos;
    if (!extractor->getCachedDuration(&cachedDurationUs, &eos)) {
        return -1ll;
    }

    return cachedDurationUs;
}

static jboolean android_media_MediaExtractor_hasCacheReachedEOS(
        JNIEnv *env, jobject thiz) {
    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);

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

    int64_t cachedDurationUs;
    bool eos;
    if (!extractor->getCachedDuration(&cachedDurationUs, &eos)) {
        return true;
    }

    return eos;
}

static void android_media_MediaExtractor_native_finalize(
        JNIEnv *env, jobject thiz) {
    android_media_MediaExtractor_release(env, thiz);
@@ -641,6 +681,12 @@ static JNINativeMethod gMethods[] = {

    { "setDataSource", "(Ljava/io/FileDescriptor;JJ)V",
      (void *)android_media_MediaExtractor_setDataSourceFd },

    { "getCachedDuration", "()J",
      (void *)android_media_MediaExtractor_getCachedDurationUs },

    { "hasCacheReachedEndOfStream", "()Z",
      (void *)android_media_MediaExtractor_hasCacheReachedEOS },
};

int register_android_media_MediaExtractor(JNIEnv *env) {
+2 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ struct JMediaExtractor : public RefBase {
    status_t getSampleFlags(uint32_t *sampleFlags);
    status_t getSampleMeta(sp<MetaData> *sampleMeta);

    bool getCachedDuration(int64_t *durationUs, bool *eos) const;

protected:
    virtual ~JMediaExtractor();