[vlc-devel] [PATCH v2 2/2] modules/codec/omxil/mediacodec.c: fix SAR for MPEG2
Thomas Guillem
thomas at gllm.fr
Wed Feb 21 08:16:22 CET 2018
On Tue, Feb 20, 2018, at 17:36, Alexandre Janniaux wrote:
> Fix the source aspect ratio of MPEG2 video decoded with mediacodec.
> It extracts the aspect_ratio_information from any block containing
> a SEQUENCE_HEADER and applies it in the UpdateVout function.
> ---
> modules/codec/omxil/mediacodec.c | 72 ++++++++++++++++++++++++++++++++++++----
> 1 file changed, 65 insertions(+), 7 deletions(-)
>
> diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
> index 8dbc0682b1..1edc0cdb9c 100644
> --- a/modules/codec/omxil/mediacodec.c
> +++ b/modules/codec/omxil/mediacodec.c
> @@ -121,6 +121,7 @@ struct decoder_sys_t
> picture_sys_t** pp_inflight_pictures;
> unsigned int i_inflight_pictures;
> timestamp_fifo_t *timestamp_fifo;
> + int i_mpeg_dar_num, i_mpeg_dar_den;
> } video;
> struct {
> date_t i_end_date;
> @@ -143,6 +144,7 @@ static void CloseDecoder(vlc_object_t *);
>
> static int Video_OnNewBlock(decoder_t *, block_t **);
> static int VideoHXXX_OnNewBlock(decoder_t *, block_t **);
> +static int VideoMPEG2_OnNewBlock(decoder_t *, block_t **);
> static int VideoVC1_OnNewBlock(decoder_t *, block_t **);
> static void Video_OnFlush(decoder_t *);
> static int Video_ProcessOutput(decoder_t *, mc_api_out *, picture_t **,
> @@ -422,20 +424,41 @@ static int ParseExtra(decoder_t *p_dec)
> case VLC_CODEC_MP4V:
> if (!i_extra && p_sys->api.i_quirks & MC_API_VIDEO_QUIRKS_ADAPTIVE)
> p_sys->b_adaptive = true;
> - /* fall through */
> - default:
> - /* Set default CSD */
> - if (p_dec->fmt_in.i_extra)
> - return CSDDup(p_dec, p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra);
> - else
> - return VLC_SUCCESS;
> + break;
> + case VLC_CODEC_MPGV:
> + case VLC_CODEC_MP2V:
> + p_dec->p_sys->pf_on_new_block = VideoMPEG2_OnNewBlock;
> + break;
> }
> + /* Set default CSD */
> + if (p_dec->fmt_in.i_extra)
> + return CSDDup(p_dec, p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra);
> + else
> + return VLC_SUCCESS;
> }
>
> static int UpdateVout(decoder_t *p_dec)
> {
> decoder_sys_t *p_sys = p_dec->p_sys;
>
> + if ((p_dec->fmt_in.i_codec == VLC_CODEC_MPGV ||
> + p_dec->fmt_in.i_codec == VLC_CODEC_MP2V))
> + {
> + if (p_sys->video.i_mpeg_dar_num * p_sys->video.i_mpeg_dar_den !
> = 0)
> + {
> + p_dec->fmt_out.video.i_sar_num =
> + p_sys->video.i_mpeg_dar_num * p_dec-
> >fmt_out.video.i_height;
> + p_dec->fmt_out.video.i_sar_den =
> + p_sys->video.i_mpeg_dar_den * p_dec-
> >fmt_out.video.i_width;
> + }
> + else
> + {
> + p_dec->fmt_out.video.i_sar_num = 1;
> + p_dec->fmt_out.video.i_sar_den = 1;
> + }
> + }
> +
> +
> /* If MediaCodec can handle the rotation, reset the orientation to
> * Normal in order to ask the vout not to rotate. */
> if (p_sys->video.i_angle != 0)
> @@ -612,6 +635,8 @@ static int OpenDecoder(vlc_object_t *p_this,
> pf_MediaCodecApi_init pf_init)
> p_sys->api.i_codec = p_dec->fmt_in.i_codec;
> p_sys->api.i_cat = p_dec->fmt_in.i_cat;
> p_sys->api.psz_mime = mime;
> + p_sys->video.i_mpeg_dar_num = 0;
> + p_sys->video.i_mpeg_dar_den = 0;
>
> if (pf_init(&p_sys->api) != 0)
> {
> @@ -1580,6 +1605,39 @@ static int VideoHXXX_OnNewBlock(decoder_t *p_dec,
> block_t **pp_block)
> return Video_OnNewBlock(p_dec, pp_block);
> }
>
> +static int VideoMPEG2_OnNewBlock(decoder_t *p_dec, block_t **pp_block)
> +{
> + if (pp_block == NULL || (*pp_block)->i_buffer <= 7)
> + return Video_OnNewBlock(p_dec, pp_block);
> +
> + decoder_sys_t *p_sys = p_dec->p_sys;
> + const int startcode = (*pp_block)->p_buffer[3];
> +
> + /* DAR aspect ratio from the DVD MPEG2 standard */
> + static const int mpeg2_aspect[16][2] =
> + {
> + {0,0}, /* reserved */
> + {0,0}, /* DAR = 0:0 will result in SAR = 1:1 */
> + {4,3}, {16,9}, {221,100},
> + /* reserved */
> + {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
> + {0,0}, {0,0}
> + };
> +
> + if (startcode == 0xB3 /* SEQUENCE_HEADER_STARTCODE */)
> + {
> + int mpeg_dar_code = (*pp_block)->p_buffer[7] >> 4;
> +
> + if (mpeg_dar_code >= 16)
> + return Video_OnNewBlock(p_dec, pp_block);
> +
> + p_sys->video.i_mpeg_dar_num = mpeg2_aspect[mpeg_dar_code][0];
> + p_sys->video.i_mpeg_dar_den = mpeg2_aspect[mpeg_dar_code][1];
> + }
> +
> + return Video_OnNewBlock(p_dec, pp_block);
> +}
> +
> static int VideoVC1_OnNewBlock(decoder_t *p_dec, block_t **pp_block)
> {
> block_t *p_block = *pp_block;
Looks good to me.
But this commit should come before 1/2 (No problem, I'll change the push order)
> --
> 2.16.1
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list