return 0;
}
-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;
p_sys->dequeue_input_buffer, timeout);
if (CHECK_EXCEPTION()) {
msg_Err(p_dec, "Exception occurred in MediaCodec.dequeueInputBuffer");
- p_sys->error_state = true;
- return;
+ return -1;
}
if (index < 0)
- return;
+ return 0;
if (p_sys->get_input_buffers)
buf = (*env)->GetObjectArrayElement(env, p_sys->input_buffers, index);
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;
(*env)->DeleteLocalRef(env, buf);
if (CHECK_EXCEPTION()) {
msg_Err(p_dec, "Exception in MediaCodec.queueInputBuffer");
- 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) {
p_sys->buffer_info, timeout);
if (CHECK_EXCEPTION()) {
msg_Err(p_dec, "Exception in MediaCodec.dequeueOutputBuffer (GetOutput)");
- p_sys->error_state = true;
- return;
+ return -1;
}
if (index >= 0) {
(*env)->CallVoidMethod(env, p_sys->codec, p_sys->release_output_buffer, index, false);
if (CHECK_EXCEPTION()) {
msg_Err(p_dec, "Exception in MediaCodec.releaseOutputBuffer");
- p_sys->error_state = true;
- return;
+ return -1;
}
continue;
}
if (CHECK_EXCEPTION()) {
msg_Err(p_dec, "Exception in MediaCodec.releaseOutputBuffer " \
"(GetOutput, overwriting previous picture)");
- p_sys->error_state = true;
- return;
+ return -1;
}
// No need to lock here since the previous picture was not sent.
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);
(*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)");
- p_sys->error_state = true;
+ return -1;
}
}
- return;
+ return 0;
} else if (index == INFO_OUTPUT_BUFFERS_CHANGED) {
msg_Dbg(p_dec, "output buffers changed");
if (CHECK_EXCEPTION()) {
msg_Err(p_dec, "Exception in MediaCodec.getOutputBuffer (GetOutput)");
p_sys->output_buffers = NULL;
- p_sys->error_state = true;
- return;
+ return -1;
}
p_sys->output_buffers = (*env)->NewGlobalRef(env, p_sys->output_buffers);
jobject format = (*env)->CallObjectMethod(env, p_sys->codec, p_sys->get_output_format);
if (CHECK_EXCEPTION()) {
msg_Err(p_dec, "Exception in MediaCodec.getOutputFormat (GetOutput)");
- p_sys->error_state = true;
- return;
+ return -1;
}
jobject format_string = (*env)->CallObjectMethod(env, format, p_sys->tostring);
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;
}
}
}
} else {
- return;
+ return 0;
}
}
+ return 0;
}
static picture_t *DecodeVideo(decoder_t *p_dec, block_t **pp_block)
int attempts = 0;
/* return when pp_block is processed */
while (*pp_block != NULL) {
- if (*pp_block != NULL)
- PutInput(p_dec, env, pp_block, (jlong) 0);
- if (p_sys->error_state)
+ if (*pp_block != NULL && PutInput(p_dec, env, pp_block, (jlong) 0) != 0) {
+ p_sys->error_state = true;
break;
+ }
- if (p_pic == NULL) {
- GetOutput(p_dec, env, &p_pic, timeout);
- if (p_sys->error_state)
- break;
+ if (p_pic == NULL && GetOutput(p_dec, env, &p_pic, timeout) != 0) {
+ p_sys->error_state = true;
+ break;
}
if (p_pic == NULL && *pp_block != NULL) {