From 4abcec4ce8a6aa534c7bc026eb97b565d00be73f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 2 Jan 2013 12:33:42 +0100 Subject: [PATCH] mfc: Include codec_data in the buffer with the next frame --- sys/mfc/gstmfcdec.c | 72 ++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/sys/mfc/gstmfcdec.c b/sys/mfc/gstmfcdec.c index 4adc786..5661bfd 100644 --- a/sys/mfc/gstmfcdec.c +++ b/sys/mfc/gstmfcdec.c @@ -303,7 +303,7 @@ gst_mfc_dec_queue_input (GstMFCDec * self, GstVideoCodecFrame * frame) GstBuffer *inbuf = NULL; struct mfc_buffer *mfc_inbuf = NULL; guint8 *mfc_inbuf_data; - gint mfc_inbuf_size; + gint mfc_inbuf_max_size, mfc_inbuf_size = 0; GstMapInfo map; struct timeval timestamp; @@ -319,63 +319,45 @@ gst_mfc_dec_queue_input (GstMFCDec * self, GstVideoCodecFrame * frame) goto dequeue_error; } - if (self->codec_data) { - inbuf = self->codec_data; - gst_buffer_map (inbuf, &map, GST_MAP_READ); - - mfc_inbuf_data = (guint8 *) mfc_buffer_get_input_data (mfc_inbuf); - g_assert (mfc_inbuf_data != NULL); - mfc_inbuf_size = mfc_buffer_get_input_max_size (mfc_inbuf); - - GST_DEBUG_OBJECT (self, "Have input buffer %p with size %d", mfc_inbuf_data, - mfc_inbuf_size); + mfc_inbuf_data = (guint8 *) mfc_buffer_get_input_data (mfc_inbuf); + g_assert (mfc_inbuf_data != NULL); + mfc_inbuf_max_size = mfc_buffer_get_input_max_size (mfc_inbuf); - if ((gsize) mfc_inbuf_size < map.size) - goto too_small_inbuf; - - memcpy (mfc_inbuf_data, map.data, map.size); - mfc_buffer_set_input_size (mfc_inbuf, map.size); + GST_DEBUG_OBJECT (self, "Have input buffer %p with max size %d", + mfc_inbuf_data, mfc_inbuf_max_size); - gst_buffer_unmap (inbuf, &map); - gst_buffer_replace (&self->codec_data, NULL); - inbuf = NULL; + g_assert (mfc_inbuf != NULL); - timestamp.tv_usec = 0; - timestamp.tv_sec = -1; + if (frame) { + if (self->codec_data) { + inbuf = self->codec_data; + gst_buffer_map (inbuf, &map, GST_MAP_READ); - if ((mfc_ret = - mfc_dec_enqueue_input (self->context, mfc_inbuf, ×tamp)) < 0) - goto enqueue_error; + if ((gsize) mfc_inbuf_max_size < map.size) + goto too_small_inbuf; - if ((mfc_ret = mfc_dec_dequeue_input (self->context, &mfc_inbuf)) < 0) { - if (mfc_ret == -2) { - GST_DEBUG_OBJECT (self, "Timeout dequeueing input, trying again"); - mfc_ret = mfc_dec_dequeue_input (self->context, &mfc_inbuf); - } + memcpy (mfc_inbuf_data, map.data, map.size); + mfc_inbuf_size += map.size; + mfc_inbuf_data += map.size; + mfc_inbuf_max_size -= map.size; - if (mfc_ret < 0) - goto dequeue_error; + gst_buffer_unmap (inbuf, &map); + gst_buffer_replace (&self->codec_data, NULL); + inbuf = NULL; } - } - g_assert (mfc_inbuf != NULL); - - if (frame) { inbuf = frame->input_buffer; gst_buffer_map (inbuf, &map, GST_MAP_READ); - mfc_inbuf_data = (guint8 *) mfc_buffer_get_input_data (mfc_inbuf); - g_assert (mfc_inbuf_data != NULL); - mfc_inbuf_size = mfc_buffer_get_input_max_size (mfc_inbuf); - - GST_DEBUG_OBJECT (self, "Have input buffer %p with size %d", mfc_inbuf_data, - mfc_inbuf_size); - - if ((gsize) mfc_inbuf_size < map.size) + if ((gsize) mfc_inbuf_max_size < map.size) goto too_small_inbuf; memcpy (mfc_inbuf_data, map.data, map.size); - mfc_buffer_set_input_size (mfc_inbuf, map.size); + mfc_inbuf_size += map.size; + mfc_inbuf_data += map.size; + mfc_inbuf_max_size -= map.size; + + mfc_buffer_set_input_size (mfc_inbuf, mfc_inbuf_size); gst_buffer_unmap (inbuf, &map); inbuf = NULL; @@ -409,7 +391,7 @@ dequeue_error: too_small_inbuf: { GST_ELEMENT_ERROR (self, STREAM, FORMAT, ("Too large input frames"), - ("Maximum size %d, got %d", mfc_inbuf_size, map.size)); + ("Maximum size %d, got %d", mfc_inbuf_max_size, map.size)); ret = GST_FLOW_ERROR; gst_buffer_unmap (inbuf, &map); goto done; -- 2.7.4