- if (p_sys->direct_rendering) {
- picture_sys_t *p_picsys = p_pic->p_sys;
- p_picsys->pf_lock_pic = NULL;
- p_picsys->pf_unlock_pic = UnlockPicture;
- p_picsys->priv.hw.p_dec = p_dec;
- p_picsys->priv.hw.i_index = index;
- p_picsys->priv.hw.b_valid = true;
-
- vlc_mutex_lock(get_android_opaque_mutex());
- InsertInflightPicture(p_dec, p_pic, index);
- vlc_mutex_unlock(get_android_opaque_mutex());
- } else {
- jobject buf;
- if (p_sys->get_output_buffers)
- buf = (*env)->GetObjectArrayElement(env, p_sys->output_buffers, index);
- else
- buf = (*env)->CallObjectMethod(env, p_sys->codec,
- p_sys->get_output_buffer, index);
- //jsize buf_size = (*env)->GetDirectBufferCapacity(env, buf);
- uint8_t *ptr = (*env)->GetDirectBufferAddress(env, buf);
-
- //int size = (*env)->GetIntField(env, p_sys->buffer_info, p_sys->size_field);
- int offset = (*env)->GetIntField(env, p_sys->buffer_info, p_sys->offset_field);
- ptr += offset; // Check the size parameter as well
-
- unsigned int chroma_div;
- GetVlcChromaSizes(p_dec->fmt_out.i_codec, p_dec->fmt_out.video.i_width,
- p_dec->fmt_out.video.i_height, NULL, NULL, &chroma_div);
- CopyOmxPicture(p_sys->pixel_format, p_pic, p_sys->slice_height, p_sys->stride,
- ptr, chroma_div, &p_sys->architecture_specific_data);
- (*env)->CallVoidMethod(env, p_sys->codec, p_sys->release_output_buffer, index, false);
-
- jthrowable exception = (*env)->ExceptionOccurred(env);
- if (exception != NULL) {
- jclass illegalStateException = (*env)->FindClass(env, "java/lang/IllegalStateException");
- if((*env)->IsInstanceOf(env, exception, illegalStateException)) {
- msg_Err(p_dec, "Codec error (IllegalStateException) in MediaCodec.releaseOutputBuffer");
- (*env)->ExceptionClear(env);
- (*env)->DeleteLocalRef(env, illegalStateException);
- (*env)->DeleteLocalRef(env, buf);
- return -1;
- }
- }
+ *pp_pic = decoder_NewPicture(p_dec);
+ if (!*pp_pic) {
+ msg_Warn(p_dec, "NewPicture failed");
+ return ReleaseOutputBuffer(p_dec, env, index, false);
+ }
+ picture_t *p_pic = *pp_pic;
+ /* If the oldest input block had no PTS, the timestamp
+ * of the frame returned by MediaCodec might be wrong
+ * so we overwrite it with the corresponding dts. */
+ int64_t forced_ts = timestamp_FifoGet(p_sys->timestamp_fifo);
+ if (forced_ts == VLC_TS_INVALID)
+ p_pic->date = (*env)->GetLongField(env, p_sys->buffer_info, p_sys->pts_field);
+ else
+ p_pic->date = forced_ts;
+
+ if (p_sys->direct_rendering) {
+ picture_sys_t *p_picsys = p_pic->p_sys;
+ p_picsys->pf_lock_pic = NULL;
+ p_picsys->pf_unlock_pic = UnlockPicture;
+ p_picsys->priv.hw.p_dec = p_dec;
+ p_picsys->priv.hw.i_index = index;
+ p_picsys->priv.hw.b_valid = true;
+
+ vlc_mutex_lock(get_android_opaque_mutex());
+ InsertInflightPicture(p_dec, p_pic, index);
+ vlc_mutex_unlock(get_android_opaque_mutex());
+ } else {
+ jobject buf;
+ if (p_sys->get_output_buffers)
+ buf = (*env)->GetObjectArrayElement(env, p_sys->output_buffers, index);
+ else
+ buf = (*env)->CallObjectMethod(env, p_sys->codec,
+ p_sys->get_output_buffer, index);
+ //jsize buf_size = (*env)->GetDirectBufferCapacity(env, buf);
+ uint8_t *ptr = (*env)->GetDirectBufferAddress(env, buf);
+
+ //int size = (*env)->GetIntField(env, p_sys->buffer_info, p_sys->size_field);
+ int offset = (*env)->GetIntField(env, p_sys->buffer_info, p_sys->offset_field);
+ ptr += offset; // Check the size parameter as well
+
+ unsigned int chroma_div;
+ GetVlcChromaSizes(p_dec->fmt_out.i_codec, p_dec->fmt_out.video.i_width,
+ p_dec->fmt_out.video.i_height, NULL, NULL, &chroma_div);
+ CopyOmxPicture(p_sys->pixel_format, p_pic, p_sys->slice_height, p_sys->stride,
+ ptr, chroma_div, &p_sys->architecture_specific_data);
+ (*env)->CallVoidMethod(env, p_sys->codec, p_sys->release_output_buffer, index, false);
+
+ jthrowable exception = (*env)->ExceptionOccurred(env);
+ if (exception != NULL) {
+ jclass illegalStateException = (*env)->FindClass(env, "java/lang/IllegalStateException");
+ if((*env)->IsInstanceOf(env, exception, illegalStateException)) {
+ msg_Err(p_dec, "Codec error (IllegalStateException) in MediaCodec.releaseOutputBuffer");
+ (*env)->ExceptionClear(env);
+ (*env)->DeleteLocalRef(env, illegalStateException);