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 <[email protected]> --- I've chosen to only set the aspect ratio if a known ratio is provided. This means that unspecified inherits the last set aspect ratio; I think that this is what's intended in the standard, so I'm not worried about this. The patch applies cleanly to master and the 0.3-branch; I've only built amd tested it on 0.3-branch gst-libs/gst/vaapi/gstvaapidecoder_h264.c | 52 +++++++++++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c | 1 + gst-libs/gst/vaapi/gstvaapidecoder_vc1.c | 53 ++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_h264.c b/gst-libs/gst/vaapi/gstvaapidecoder_h264.c index 89fef91..556e791 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,57 @@ decode_sps(GstVaapiDecoderH264 *decoder, GstH264NalUnit *nalu) if (result != GST_H264_PARSER_OK) return get_status(result); + if (sps->vui_parameters_present_flag) { + GstH264VUIParams * vui = &sps->vui_parameters; + if (vui->aspect_ratio_info_present_flag) { + static const guint aspect_ratio_h_table[] = { + [1] = 1, + [2] = 12, + [3] = 10, + [4] = 16, + [5] = 40, + [6] = 24, + [7] = 20, + [8] = 32, + [9] = 80, + [10] = 18, + [11] = 15, + [12] = 64, + [13] = 160, + [14] = 4, + [15] = 3, + [16] = 2, + }; + static const guint aspect_ratio_v_table[] = { + [1] = 1, + [2] = 11, + [3] = 11, + [4] = 11, + [5] = 33, + [6] = 11, + [7] = 11, + [8] = 11, + [9] = 33, + [10] = 11, + [11] = 11, + [12] = 33, + [13] = 99, + [14] = 3, + [15] = 2, + [16] = 1, + }; + /* Intent is "if aspect ratio in tables above" */ + if (vui->aspect_ratio_idc >= 1 && vui->aspect_ratio_idc <= 16) + gst_vaapi_decoder_set_pixel_aspect_ratio(base_decoder, + aspect_ratio_h_table[vui->aspect_ratio_idc], + aspect_ratio_v_table[vui->aspect_ratio_idc]); + /* Extended aspect ratio */ + else if (vui->aspect_ratio_idc == 255 ) + gst_vaapi_decoder_set_pixel_aspect_ratio(base_decoder, + vui->sar_width, + vui->sar_height); + } + } 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..4a674fe 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_vc1.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_vc1.c @@ -330,6 +330,59 @@ 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: + if (adv_hdr->aspect_ratio_flag) { + static const guint aspect_ratio_h_table[] = { + [1] = 1, + [2] = 12, + [3] = 10, + [4] = 16, + [5] = 40, + [6] = 24, + [7] = 20, + [8] = 32, + [9] = 80, + [10] = 18, + [11] = 15, + [12] = 64, + [13] = 160, + }; + static const guint aspect_ratio_v_table[] = { + [1] = 1, + [2] = 11, + [3] = 11, + [4] = 11, + [5] = 33, + [6] = 11, + [7] = 11, + [8] = 11, + [9] = 33, + [10] = 11, + [11] = 11, + [12] = 33, + [13] = 99, + }; + /* Intent is "if aspect ratio in tables above" */ + if (adv_hdr->aspect_ratio >= 1 && adv_hdr->aspect_ratio <= 13) + gst_vaapi_decoder_set_pixel_aspect_ratio(base_decoder, + aspect_ratio_h_table[adv_hdr->aspect_ratio], + aspect_ratio_v_table[adv_hdr->aspect_ratio]); + /* Extended aspect ratio */ + else if (adv_hdr->aspect_ratio == 255 ) + gst_vaapi_decoder_set_pixel_aspect_ratio(base_decoder, + adv_hdr->aspect_horiz_size, + adv_hdr->aspect_vert_size); + } + 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 _______________________________________________ Libva mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libva
