[Libva] [PATCH 1/2] Parse aspect ratio when using GStreamer codec parsers

Simon Farnsworth simon.farnsworth at onelan.co.uk
Thu Sep 27 10:05:46 PDT 2012


Not all encoded material uses square pixels. MPEG-4 part 2 already parsed
the aspect ratio from the bitstream; add equivalent code for H.264, MPEG-2
and VC-1.

Signed-off-by: Simon Farnsworth <simon.farnsworth at onelan.co.uk>
---

This is the redone and tested patch, using the information from the
gst-plugins-base parsers.

 gst-libs/gst/vaapi/gstvaapidecoder_h264.c  |  5 +++++
 gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c |  1 +
 gst-libs/gst/vaapi/gstvaapidecoder_vc1.c   | 14 ++++++++++++++
 3 files changed, 20 insertions(+)

diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_h264.c b/gst-libs/gst/vaapi/gstvaapidecoder_h264.c
index 89fef91..edfd641 100644
--- a/gst-libs/gst/vaapi/gstvaapidecoder_h264.c
+++ b/gst-libs/gst/vaapi/gstvaapidecoder_h264.c
@@ -685,6 +685,7 @@ end:
 static GstVaapiDecoderStatus
 decode_sps(GstVaapiDecoderH264 *decoder, GstH264NalUnit *nalu)
 {
+    GstVaapiDecoder * const base_decoder = GST_VAAPI_DECODER(decoder);
     GstVaapiDecoderH264Private * const priv = decoder->priv;
     GstH264SPS * const sps = &priv->last_sps;
     GstH264ParserResult result;
@@ -699,6 +700,10 @@ decode_sps(GstVaapiDecoderH264 *decoder, GstH264NalUnit *nalu)
     if (result != GST_H264_PARSER_OK)
         return get_status(result);
 
+    gst_vaapi_decoder_set_pixel_aspect_ratio(base_decoder,
+                                             sps->vui_parameters.par_n,
+                                             sps->vui_parameters.par_d);
+
     return ensure_context(decoder, sps);
 }
 
diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c
index 38ecb33..48e9c2b 100644
--- a/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c
+++ b/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c
@@ -513,6 +513,7 @@ decode_sequence(GstVaapiDecoderMpeg2 *decoder, guchar *buf, guint buf_size)
     priv->fps_d = seq_hdr->fps_d;
     pts_set_framerate(&priv->tsg, priv->fps_n, priv->fps_d);
     gst_vaapi_decoder_set_framerate(base_decoder, priv->fps_n, priv->fps_d);
+    gst_vaapi_decoder_set_pixel_aspect_ratio(base_decoder, seq_hdr->par_w, seq_hdr->par_h);
 
     priv->width                 = seq_hdr->width;
     priv->height                = seq_hdr->height;
diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_vc1.c b/gst-libs/gst/vaapi/gstvaapidecoder_vc1.c
index 63fbc73..539902c 100644
--- a/gst-libs/gst/vaapi/gstvaapidecoder_vc1.c
+++ b/gst-libs/gst/vaapi/gstvaapidecoder_vc1.c
@@ -330,6 +330,20 @@ decode_sequence(GstVaapiDecoderVC1 *decoder, GstVC1BDU *rbdu, GstVC1BDU *ebdu)
     switch (seq_hdr->profile) {
     case GST_VC1_PROFILE_SIMPLE:
     case GST_VC1_PROFILE_MAIN:
+        break;
+    case GST_VC1_PROFILE_ADVANCED:
+        gst_vaapi_decoder_set_pixel_aspect_ratio(base_decoder,
+                                                 adv_hdr->par_n,
+                                                 adv_hdr->par_d);
+        break;
+    default:
+        g_assert(0 && "XXX: we already validated the profile above");
+        break;
+    }
+
+    switch (seq_hdr->profile) {
+    case GST_VC1_PROFILE_SIMPLE:
+    case GST_VC1_PROFILE_MAIN:
         width  = seq_hdr->struct_c.coded_width;
         height = seq_hdr->struct_c.coded_height;
         break;
-- 
1.7.11.2



More information about the Libva mailing list