[vlc-devel] [PATCH 2/4] mediacodec: handle error_state in one place
Thomas Guillem
thomas at gllm.fr
Wed Oct 29 17:47:00 CET 2014
---
modules/codec/omxil/android_mediacodec.c | 55 +++++++++++++++-----------------
1 file changed, 26 insertions(+), 29 deletions(-)
diff --git a/modules/codec/omxil/android_mediacodec.c b/modules/codec/omxil/android_mediacodec.c
index 2f9f384..8507ebc 100644
--- a/modules/codec/omxil/android_mediacodec.c
+++ b/modules/codec/omxil/android_mediacodec.c
@@ -676,7 +676,7 @@ static void InvalidateAllPictures(decoder_t *p_dec)
vlc_mutex_unlock(get_android_opaque_mutex());
}
-static void PutInput(decoder_t *p_dec, JNIEnv *env, block_t **pp_block, jlong timeout)
+static int PutInput(decoder_t *p_dec, JNIEnv *env, block_t **pp_block, jlong timeout)
{
decoder_sys_t *p_sys = p_dec->p_sys;
block_t *p_block = *pp_block;
@@ -691,19 +691,17 @@ static void PutInput(decoder_t *p_dec, JNIEnv *env, block_t **pp_block, jlong ti
if ((*env)->ExceptionOccurred(env)) {
msg_Err(p_dec, "Exception occurred in MediaCodec.dequeueInputBuffer");
(*env)->ExceptionClear(env);
- p_sys->error_state = true;
- return;
+ return -1;
}
if (index < 0)
- return;
+ return 0;
buf = (*env)->GetObjectArrayElement(env, p_sys->input_buffers, index);
size = (*env)->GetDirectBufferCapacity(env, buf);
bufptr = (*env)->GetDirectBufferAddress(env, buf);
if (size < 0) {
msg_Err(p_dec, "Java buffer has invalid size");
- p_sys->error_state = true;
- return;
+ return -1;
}
if ((size_t) size > p_block->i_buffer)
size = p_block->i_buffer;
@@ -720,15 +718,16 @@ static void PutInput(decoder_t *p_dec, JNIEnv *env, block_t **pp_block, jlong ti
if ((*env)->ExceptionOccurred(env)) {
msg_Err(p_dec, "Exception in MediaCodec.queueInputBuffer");
(*env)->ExceptionClear(env);
- p_sys->error_state = true;
- return;
+ return -1;
}
block_Release(p_block);
*pp_block = NULL;
p_sys->decoded = true;
+
+ return 0;
}
-static void GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong timeout)
+static int GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong timeout)
{
decoder_sys_t *p_sys = p_dec->p_sys;
while (1) {
@@ -737,8 +736,7 @@ static void GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong t
if ((*env)->ExceptionOccurred(env)) {
msg_Err(p_dec, "Exception in MediaCodec.dequeueOutputBuffer (GetOutput)");
(*env)->ExceptionClear(env);
- p_sys->error_state = true;
- return;
+ return -1;
}
if (index >= 0) {
@@ -748,8 +746,7 @@ static void GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong t
if ((*env)->ExceptionOccurred(env)) {
msg_Err(p_dec, "Exception in MediaCodec.releaseOutputBuffer");
(*env)->ExceptionClear(env);
- p_sys->error_state = true;
- return;
+ return -1;
}
continue;
}
@@ -765,8 +762,7 @@ static void GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong t
msg_Err(p_dec, "Exception in MediaCodec.releaseOutputBuffer " \
"(GetOutput, overwriting previous picture)");
(*env)->ExceptionClear(env);
- p_sys->error_state = true;
- return;
+ return -1;
}
// No need to lock here since the previous picture was not sent.
@@ -820,7 +816,8 @@ static void GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong t
msg_Err(p_dec, "Codec error (IllegalStateException) in MediaCodec.releaseOutputBuffer");
(*env)->ExceptionClear(env);
(*env)->DeleteLocalRef(env, illegalStateException);
- p_sys->error_state = true;
+ (*env)->DeleteLocalRef(env, buf);
+ return -1;
}
}
(*env)->DeleteLocalRef(env, buf);
@@ -831,10 +828,10 @@ static void GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong t
if ((*env)->ExceptionOccurred(env)) {
msg_Err(p_dec, "Exception in MediaCodec.releaseOutputBuffer (GetOutput)");
(*env)->ExceptionClear(env);
- p_sys->error_state = true;
+ return -1;
}
}
- return;
+ return 0;
} else if (index == INFO_OUTPUT_BUFFERS_CHANGED) {
msg_Dbg(p_dec, "output buffers changed");
@@ -846,8 +843,7 @@ static void GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong t
msg_Err(p_dec, "Exception in MediaCodec.getOutputBuffer (GetOutput)");
(*env)->ExceptionClear(env);
p_sys->output_buffers = NULL;
- p_sys->error_state = true;
- return;
+ return -1;
}
p_sys->output_buffers = (*env)->NewGlobalRef(env, p_sys->output_buffers);
@@ -863,8 +859,7 @@ static void GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong t
if ((*env)->ExceptionOccurred(env)) {
msg_Err(p_dec, "Exception in MediaCodec.getOutputFormat (GetOutput)");
(*env)->ExceptionClear(env);
- p_sys->error_state = true;
- return;
+ return -1;
}
jobject format_string = (*env)->CallObjectMethod(env, format, p_sys->tostring);
@@ -898,8 +893,7 @@ static void GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong t
if (!GetVlcChromaFormat(p_sys->pixel_format,
&p_dec->fmt_out.i_codec, &name)) {
msg_Err(p_dec, "color-format not recognized");
- p_sys->error_state = true;
- return;
+ return -1;
}
}
@@ -932,9 +926,10 @@ static void GetOutput(decoder_t *p_dec, JNIEnv *env, picture_t **pp_pic, jlong t
}
} else {
- return;
+ return 0;
}
}
+ return 0;
}
static picture_t *DecodeVideo(decoder_t *p_dec, block_t **pp_block)
@@ -988,13 +983,15 @@ static picture_t *DecodeVideo(decoder_t *p_dec, block_t **pp_block)
const int max_polling_attempts = 50;
int attempts = 0;
while (*pp_block != NULL && p_pic == NULL) {
- PutInput(p_dec, env, pp_block, (jlong) 0);
- if (p_sys->error_state)
+ if (PutInput(p_dec, env, pp_block, (jlong) 0) != 0) {
+ p_sys->error_state = true;
break;
+ }
- GetOutput(p_dec, env, &p_pic, timeout);
- if (p_sys->error_state)
+ if (GetOutput(p_dec, env, &p_pic, timeout) != 0) {
+ p_sys->error_state = true;
break;
+ }
if (p_pic == NULL && *pp_block != NULL) {
timeout = 30 * 1000;
--
2.1.0
More information about the vlc-devel
mailing list