[vlc-devel] [PATCH 3/7] mediacodec: factorize release_output_buffer
Thomas Guillem
thomas at gllm.fr
Mon Mar 23 18:40:00 CET 2015
---
modules/codec/omxil/android_mediacodec.c | 39 +++++++++++++++++---------------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/modules/codec/omxil/android_mediacodec.c b/modules/codec/omxil/android_mediacodec.c
index 90bccb8..ee39832 100644
--- a/modules/codec/omxil/android_mediacodec.c
+++ b/modules/codec/omxil/android_mediacodec.c
@@ -263,6 +263,9 @@ static void CloseDecoder(vlc_object_t *);
static picture_t *DecodeVideo(decoder_t *, block_t **);
+static int ReleaseOutputBuffer(decoder_t *p_dec, JNIEnv *env, int i_index,
+ bool b_render);
+
static void InvalidateAllPictures(decoder_t *);
static int InsertInflightPicture(decoder_t *, picture_t *, unsigned int );
@@ -716,7 +719,6 @@ static void UnlockPicture(picture_t* p_pic, bool b_render)
{
picture_sys_t *p_picsys = p_pic->p_sys;
decoder_t *p_dec = p_picsys->priv.hw.p_dec;
- decoder_sys_t *p_sys = p_dec->p_sys;
if (!p_picsys->priv.hw.b_valid)
return;
@@ -735,10 +737,7 @@ static void UnlockPicture(picture_t* p_pic, bool b_render)
/* Release the MediaCodec buffer. */
JNIEnv *env = NULL;
jni_attach_thread(&env, THREAD_NAME);
- (*env)->CallVoidMethod(env, p_sys->codec, p_sys->release_output_buffer, i_index, b_render);
- if (CHECK_EXCEPTION())
- msg_Err(p_dec, "Exception in MediaCodec.releaseOutputBuffer (DisplayBuffer)");
-
+ ReleaseOutputBuffer(p_dec, env, i_index, b_render);
jni_detach_thread();
p_picsys->priv.hw.b_valid = false;
@@ -833,6 +832,20 @@ static int PutInput(decoder_t *p_dec, JNIEnv *env, block_t **pp_block, jlong tim
return 0;
}
+static int ReleaseOutputBuffer(decoder_t *p_dec, JNIEnv *env, int i_index,
+ bool b_render)
+{
+ decoder_sys_t *p_sys = p_dec->p_sys;
+
+ (*env)->CallVoidMethod(env, p_sys->codec, p_sys->release_output_buffer,
+ i_index, b_render);
+ if (CHECK_EXCEPTION()) {
+ msg_Err(p_dec, "Exception in MediaCodec.releaseOutputBuffer");
+ return -1;
+ }
+ return 0;
+}
+
static int GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong timeout)
{
decoder_sys_t *p_sys = p_dec->p_sys;
@@ -847,11 +860,8 @@ static int GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong ti
if (index >= 0) {
if (!p_sys->pixel_format) {
msg_Warn(p_dec, "Buffers returned before output format is set, dropping frame");
- (*env)->CallVoidMethod(env, p_sys->codec, p_sys->release_output_buffer, index, false);
- if (CHECK_EXCEPTION()) {
- msg_Err(p_dec, "Exception in MediaCodec.releaseOutputBuffer");
+ if (ReleaseOutputBuffer(p_dec, env, index, false) != 0)
return -1;
- }
continue;
}
@@ -861,12 +871,8 @@ static int GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong ti
picture_t *p_pic = *pp_pic;
picture_sys_t *p_picsys = p_pic->p_sys;
int i_prev_index = p_picsys->priv.hw.i_index;
- (*env)->CallVoidMethod(env, p_sys->codec, p_sys->release_output_buffer, i_prev_index, false);
- if (CHECK_EXCEPTION()) {
- msg_Err(p_dec, "Exception in MediaCodec.releaseOutputBuffer " \
- "(GetOutput, overwriting previous picture)");
+ if (ReleaseOutputBuffer(p_dec, env, i_prev_index, false) != 0)
return -1;
- }
// No need to lock here since the previous picture was not sent.
InsertInflightPicture(p_dec, NULL, i_prev_index);
@@ -930,11 +936,8 @@ static int GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong ti
}
} else {
msg_Warn(p_dec, "NewPicture failed");
- (*env)->CallVoidMethod(env, p_sys->codec, p_sys->release_output_buffer, index, false);
- if (CHECK_EXCEPTION()) {
- msg_Err(p_dec, "Exception in MediaCodec.releaseOutputBuffer (GetOutput)");
+ if (ReleaseOutputBuffer(p_dec, env, index, false) != 0)
return -1;
- }
}
return 0;
--
2.1.3
More information about the vlc-devel
mailing list