diff options
| author | 2012-04-20 12:15:31 -0700 | |
|---|---|---|
| committer | 2012-04-20 12:15:31 -0700 | |
| commit | 987e982b6d29f005f85e3a0ab53ae80fbbd0a825 (patch) | |
| tree | 087addc9fb34e9efc5bbf9c9398e565858ae1694 | |
| parent | 362bcb06ad92c561cc23410e59e11ead7bf38e22 (diff) | |
| parent | 74a78b0f6e8c07cfc7da8f043987f6de0648bc05 (diff) | |
Merge "Add the ability to query the amount of cached data to MediaExtractor."
| -rw-r--r-- | api/current.txt | 2 | ||||
| -rw-r--r-- | media/java/android/media/MediaExtractor.java | 14 | ||||
| -rw-r--r-- | media/jni/android_media_MediaExtractor.cpp | 46 | ||||
| -rw-r--r-- | media/jni/android_media_MediaExtractor.h | 2 |
4 files changed, 64 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index 7910add980a6..e2452c19bc2f 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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); diff --git a/media/java/android/media/MediaExtractor.java b/media/java/android/media/MediaExtractor.java index 3b17a7d7703a..9fdb81fc240f 100644 --- a/media/java/android/media/MediaExtractor.java +++ b/media/java/android/media/MediaExtractor.java @@ -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(); diff --git a/media/jni/android_media_MediaExtractor.cpp b/media/jni/android_media_MediaExtractor.cpp index bf3d44aaec21..051833161c23 100644 --- a/media/jni/android_media_MediaExtractor.cpp +++ b/media/jni/android_media_MediaExtractor.cpp @@ -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) { diff --git a/media/jni/android_media_MediaExtractor.h b/media/jni/android_media_MediaExtractor.h index f7ce2ff5f9fd..ef0c48b3a3c4 100644 --- a/media/jni/android_media_MediaExtractor.h +++ b/media/jni/android_media_MediaExtractor.h @@ -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(); |