diff options
author | Lajos Molnar <lajos@google.com> | 2015-05-01 15:59:35 -0700 |
---|---|---|
committer | Lajos Molnar <lajos@google.com> | 2015-05-01 17:39:37 -0700 |
commit | 5e02ba977ede1e38c9f206057ec3f0f1e89ba943 (patch) | |
tree | 7985425d3554c1a6df67f3837211a52c7bdc9fb9 /media/jni | |
parent | b6bec1a403fd3efc59acb2c2206aaf6b6840c2f1 (diff) | |
download | frameworks_base-5e02ba977ede1e38c9f206057ec3f0f1e89ba943.zip frameworks_base-5e02ba977ede1e38c9f206057ec3f0f1e89ba943.tar.gz frameworks_base-5e02ba977ede1e38c9f206057ec3f0f1e89ba943.tar.bz2 |
media: hook up MediaCodec.setSurface
Bug: 11990461
Change-Id: Id2dc952594c21c6be68e4ffd039c7f74006a2374
Diffstat (limited to 'media/jni')
-rw-r--r-- | media/jni/android_media_MediaCodec.cpp | 50 | ||||
-rw-r--r-- | media/jni/android_media_MediaCodec.h | 3 |
2 files changed, 53 insertions, 0 deletions
diff --git a/media/jni/android_media_MediaCodec.cpp b/media/jni/android_media_MediaCodec.cpp index e34f9ed..39b79de 100644 --- a/media/jni/android_media_MediaCodec.cpp +++ b/media/jni/android_media_MediaCodec.cpp @@ -245,6 +245,19 @@ status_t JMediaCodec::configure( return mCodec->configure(format, mSurfaceTextureClient, crypto, flags); } +status_t JMediaCodec::setSurface( + const sp<IGraphicBufferProducer> &bufferProducer) { + sp<Surface> client; + if (bufferProducer != NULL) { + client = new Surface(bufferProducer, true /* controlledByApp */); + } + status_t err = mCodec->setSurface(client); + if (err == OK) { + mSurfaceTextureClient = client; + } + return err; +} + status_t JMediaCodec::createInputSurface( sp<IGraphicBufferProducer>* bufferProducer) { return mCodec->createInputSurface(bufferProducer); @@ -797,6 +810,10 @@ static jint throwExceptionAsNecessary( jniThrowException(env, "java/lang/IllegalStateException", msg); return 0; + case BAD_VALUE: + jniThrowException(env, "java/lang/IllegalArgumentException", msg); + return 0; + default: if (isCryptoError(err)) { throwCryptoException(env, err, msg); @@ -869,6 +886,35 @@ static void android_media_MediaCodec_native_configure( throwExceptionAsNecessary(env, err); } +static void android_media_MediaCodec_native_setSurface( + JNIEnv *env, + jobject thiz, + jobject jsurface) { + sp<JMediaCodec> codec = getMediaCodec(env, thiz); + + if (codec == NULL) { + throwExceptionAsNecessary(env, INVALID_OPERATION); + return; + } + + sp<IGraphicBufferProducer> bufferProducer; + if (jsurface != NULL) { + sp<Surface> surface(android_view_Surface_getSurface(env, jsurface)); + if (surface != NULL) { + bufferProducer = surface->getIGraphicBufferProducer(); + } else { + jniThrowException( + env, + "java/lang/IllegalArgumentException", + "The surface has been released"); + return; + } + } + + status_t err = codec->setSurface(bufferProducer); + throwExceptionAsNecessary(env, err); +} + static jobject android_media_MediaCodec_createInputSurface(JNIEnv* env, jobject thiz) { ALOGV("android_media_MediaCodec_createInputSurface"); @@ -1530,6 +1576,10 @@ static JNINativeMethod gMethods[] = { "Landroid/media/MediaCrypto;I)V", (void *)android_media_MediaCodec_native_configure }, + { "native_setSurface", + "(Landroid/view/Surface;)V", + (void *)android_media_MediaCodec_native_setSurface }, + { "createInputSurface", "()Landroid/view/Surface;", (void *)android_media_MediaCodec_createInputSurface }, diff --git a/media/jni/android_media_MediaCodec.h b/media/jni/android_media_MediaCodec.h index 9f2785a..5041dac 100644 --- a/media/jni/android_media_MediaCodec.h +++ b/media/jni/android_media_MediaCodec.h @@ -53,6 +53,9 @@ struct JMediaCodec : public AHandler { const sp<ICrypto> &crypto, int flags); + status_t setSurface( + const sp<IGraphicBufferProducer> &surface); + status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer); status_t start(); |