diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2014-04-29 00:08:33 +0400 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2014-06-20 18:39:33 +0400 |
commit | 9e500efdbe0deeff1602500ebc229a0a6b6bb1a2 (patch) | |
tree | ab9fefcc3d3bab4d2a75f427e96587fd61ec2770 /libavcodec/utils.c | |
parent | d349afb07bacccb62eb5369c38d6406d2909d792 (diff) |
Add av_image_check_sar() and use it to validate SAR
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index dff84197c9..33983f86fe 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -153,6 +153,21 @@ int ff_set_dimensions(AVCodecContext *s, int width, int height) return ret; } +int ff_set_sar(AVCodecContext *avctx, AVRational sar) +{ + int ret = av_image_check_sar(avctx->width, avctx->height, sar); + + if (ret < 0) { + av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", + sar.num, sar.den); + avctx->sample_aspect_ratio = (AVRational){ 0, 1 }; + return ret; + } else { + avctx->sample_aspect_ratio = sar; + } + return 0; +} + int ff_side_data_update_matrix_encoding(AVFrame *frame, enum AVMatrixEncoding matrix_encoding) { @@ -636,6 +651,14 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio; + if (av_image_check_sar(frame->width, frame->height, + frame->sample_aspect_ratio) < 0) { + av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", + frame->sample_aspect_ratio.num, + frame->sample_aspect_ratio.den); + frame->sample_aspect_ratio = (AVRational){ 0, 1 }; + } + if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) return ret; break; @@ -1071,6 +1094,16 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code ff_set_dimensions(avctx, 0, 0); } + if (avctx->width > 0 && avctx->height > 0) { + if (av_image_check_sar(avctx->width, avctx->height, + avctx->sample_aspect_ratio) < 0) { + av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", + avctx->sample_aspect_ratio.num, + avctx->sample_aspect_ratio.den); + avctx->sample_aspect_ratio = (AVRational){ 0, 1 }; + } + } + /* if the decoder init function was already called previously, * free the already allocated subtitle_header before overwriting it */ if (av_codec_is_decoder(codec)) |