openh264dec: Properly drain codec on ::finish()

This commit is contained in:
Sebastian Dröge 2014-10-02 15:48:51 +03:00
parent 10475b6793
commit 0a31814ef3

View file

@ -237,15 +237,6 @@ static gboolean gst_openh264dec_reset(GstVideoDecoder *decoder, gboolean hard)
return TRUE;
}
static GstFlowReturn gst_openh264dec_finish(GstVideoDecoder *decoder)
{
GstOpenh264Dec *openh264dec = GST_OPENH264DEC(decoder);
GST_DEBUG_OBJECT(openh264dec, "finish");
return GST_FLOW_OK;
}
static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstVideoCodecFrame *frame)
{
GstOpenh264Dec *openh264dec = GST_OPENH264DEC(decoder);
@ -265,7 +256,7 @@ static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstV
guint8 *p;
guint row_stride, component_width, component_height, src_width, row;
if (frame) {
if (!gst_buffer_map(frame->input_buffer, &map_info, GST_MAP_READ)) {
GST_ERROR_OBJECT(openh264dec, "Cannot map input buffer!");
return GST_FLOW_ERROR;
@ -273,9 +264,8 @@ static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstV
GST_LOG_OBJECT(openh264dec, "handle frame, %d", map_info.size > 4 ? map_info.data[4] & 0x1f : -1);
memset (&dst_buf_info, 0, sizeof (SBufferInfo));
while (offset < map_info.size) {
memset (&dst_buf_info, 0, sizeof (SBufferInfo));
parser_result = gst_h264_parser_identify_nalu(openh264dec->priv->nal_parser,
map_info.data, offset, map_info.size, &nalu);
offset = nalu.offset + nalu.size;
@ -325,7 +315,22 @@ static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstV
}
}
}
gst_buffer_unmap(frame->input_buffer, &map_info);
gst_video_codec_frame_unref (frame);
frame = NULL;
} else {
memset (&dst_buf_info, 0, sizeof (SBufferInfo));
ret = openh264dec->priv->decoder->DecodeFrame2(NULL, 0, yuvdata, &dst_buf_info);
if (ret != dsErrorFree)
return GST_FLOW_EOS;
}
frame = gst_video_decoder_get_oldest_frame (decoder);
if (!frame) {
/* Can only happen in finish() */
return GST_FLOW_EOS;
}
if (dst_buf_info.iBufferStatus != 1) {
GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY(frame);
@ -382,7 +387,21 @@ static GstFlowReturn gst_openh264dec_handle_frame(GstVideoDecoder *decoder, GstV
finish:
gst_video_decoder_finish_frame(decoder, frame);
return gst_video_decoder_finish_frame(decoder, frame);
}
static GstFlowReturn gst_openh264dec_finish(GstVideoDecoder *decoder)
{
GstOpenh264Dec *openh264dec = GST_OPENH264DEC(decoder);
GST_DEBUG_OBJECT(openh264dec, "finish");
/* Decoder not negotiated yet */
if (openh264dec->priv->width == 0)
return GST_FLOW_OK;
/* Drain all pending frames */
while ((gst_openh264dec_handle_frame (decoder, NULL)) == GST_FLOW_OK);
return GST_FLOW_OK;
}