+static void 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;
+ int index;
+ jobject buf;
+ jsize size;
+ uint8_t *bufptr;
+ struct H264ConvertState convert_state = { 0, 0 };
+
+ index = (*env)->CallIntMethod(env, p_sys->codec,
+ p_sys->dequeue_input_buffer, timeout);
+ if (CHECK_EXCEPTION()) {
+ msg_Err(p_dec, "Exception occurred in MediaCodec.dequeueInputBuffer");
+ p_sys->error_state = true;
+ return;
+ }
+ if (index < 0)
+ return;
+
+ if (p_sys->get_input_buffers)
+ buf = (*env)->GetObjectArrayElement(env, p_sys->input_buffers, index);
+ else
+ buf = (*env)->CallObjectMethod(env, p_sys->codec, p_sys->get_input_buffer, 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;
+ }
+ if ((size_t) size > p_block->i_buffer)
+ size = p_block->i_buffer;
+ memcpy(bufptr, p_block->p_buffer, size);
+
+ convert_h264_to_annexb(bufptr, size, p_sys->nal_size, &convert_state);
+
+ int64_t ts = p_block->i_pts;
+ if (!ts && p_block->i_dts)
+ ts = p_block->i_dts;
+ timestamp_FifoPut(p_sys->timestamp_fifo, p_block->i_pts ? VLC_TS_INVALID : p_block->i_dts);
+ (*env)->CallVoidMethod(env, p_sys->codec, p_sys->queue_input_buffer, index, 0, size, ts, 0);
+ (*env)->DeleteLocalRef(env, buf);
+ if (CHECK_EXCEPTION()) {
+ msg_Err(p_dec, "Exception in MediaCodec.queueInputBuffer");
+ return;
+ }
+ block_Release(p_block);
+ *pp_block = NULL;
+ p_sys->decoded = true;
+}
+