From 1234267cb5a66dd2782ac7755ef1f998f6561da4 Mon Sep 17 00:00:00 2001 From: Carl-Anton Ingmarsson Date: Mon, 13 Apr 2009 21:11:54 +0200 Subject: [PATCH] vdpau: small improvement to mpeg decoder --- sys/vdpau/gstvdpaumpegdecoder.c | 28 ++++++++++++++++++++-------- sys/vdpau/gstvdpaumpegdecoder.h | 2 ++ sys/vdpau/mpegutil.c | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/sys/vdpau/gstvdpaumpegdecoder.c b/sys/vdpau/gstvdpaumpegdecoder.c index ecb801a042..efa89e3642 100644 --- a/sys/vdpau/gstvdpaumpegdecoder.c +++ b/sys/vdpau/gstvdpaumpegdecoder.c @@ -112,6 +112,7 @@ gst_vdpau_mpeg_decoder_set_caps (GstVdpauDecoder * dec, GstCaps * caps) break; } } + memcpy (&mpeg_dec->vdp_info.intra_quantizer_matrix, &hdr.intra_quantizer_matrix, 64); memcpy (&mpeg_dec->vdp_info.non_intra_quantizer_matrix, @@ -210,12 +211,15 @@ gst_vdpau_mpeg_decoder_parse_picture_coding (GstVdpauMpegDecoder * mpeg_dec, info->intra_dc_precision = pic_ext.intra_dc_precision; info->picture_structure = pic_ext.picture_structure; + GST_DEBUG ("Picture structure %d", info->picture_structure); info->top_field_first = pic_ext.top_field_first; info->frame_pred_frame_dct = pic_ext.frame_pred_frame_dct; info->concealment_motion_vectors = pic_ext.concealment_motion_vectors; info->q_scale_type = pic_ext.q_scale_type; info->intra_vlc_format = pic_ext.intra_vlc_format; + mpeg_dec->want_slice = TRUE; + return TRUE; } @@ -266,7 +270,10 @@ gst_vdpau_mpeg_decoder_parse_picture (GstVdpauMpegDecoder * mpeg_dec, mpeg_dec->vdp_info.full_pel_backward_vector = pic_hdr.full_pel_backward_vector; memcpy (&mpeg_dec->vdp_info.f_code, &pic_hdr.f_code, 4); - } + + mpeg_dec->want_slice = TRUE; + } else + mpeg_dec->want_slice = FALSE; return TRUE; } @@ -326,12 +333,14 @@ gst_vdpau_mpeg_decoder_chain (GstPad * pad, GstBuffer * buffer) GstBuffer *subbuf; GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_SLICE"); - subbuf = - gst_buffer_create_sub (buffer, - packet_start - GST_BUFFER_DATA (buffer), packet_end - packet_start); - gst_adapter_push (mpeg_dec->adapter, subbuf); - mpeg_dec->vdp_info.slice_count++; - } else if (mpeg_dec->vdp_info.slice_count > 0) { + if (mpeg_dec->want_slice) { + subbuf = + gst_buffer_create_sub (buffer, + packet_start - GST_BUFFER_DATA (buffer), packet_end - packet_start); + gst_adapter_push (mpeg_dec->adapter, subbuf); + mpeg_dec->vdp_info.slice_count++; + } + } else if (mpeg_dec->vdp_info.slice_count > 0 && mpeg_dec->want_slice) { if (gst_vdpau_mpeg_decoder_decode (mpeg_dec) != GST_FLOW_OK) return GST_FLOW_ERROR; } @@ -344,7 +353,8 @@ gst_vdpau_mpeg_decoder_chain (GstPad * pad, GstBuffer * buffer) break; case MPEG_PACKET_SEQUENCE: GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_SEQUENCE"); - gst_vdpau_mpeg_decoder_parse_sequence (mpeg_dec, data, end); + gst_vdpau_mpeg_decoder_parse_sequence (mpeg_dec, packet_start, + packet_end); break; case MPEG_PACKET_EXTENSION: GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_EXTENSION"); @@ -436,6 +446,8 @@ gst_vdpau_mpeg_decoder_init (GstVdpauMpegDecoder * mpeg_dec, mpeg_dec->adapter = gst_adapter_new (); + mpeg_dec->want_slice = FALSE; + gst_pad_set_chain_function (dec->sink, gst_vdpau_mpeg_decoder_chain); } diff --git a/sys/vdpau/gstvdpaumpegdecoder.h b/sys/vdpau/gstvdpaumpegdecoder.h index 1a97c27013..785c0c15d5 100644 --- a/sys/vdpau/gstvdpaumpegdecoder.h +++ b/sys/vdpau/gstvdpaumpegdecoder.h @@ -46,6 +46,8 @@ struct _GstVdpauMpegDecoder VdpDecoder decoder; VdpPictureInfoMPEG1Or2 vdp_info; GstBuffer *f_buffer; + + gboolean want_slice; GstAdapter *adapter; gint slices; diff --git a/sys/vdpau/mpegutil.c b/sys/vdpau/mpegutil.c index 8bba8d1f81..3a4a63de25 100644 --- a/sys/vdpau/mpegutil.c +++ b/sys/vdpau/mpegutil.c @@ -314,7 +314,7 @@ mpeg_util_parse_picture_coding_extension (MPEGPictureExt * ext, guint8 * data, { guint32 code; - if (G_UNLIKELY ((end - data) < 10)) + if (G_UNLIKELY ((end - data) < 9)) return FALSE; /* Packet too small */ code = GST_READ_UINT32_BE (data);