aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/utils.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-06-20 22:20:28 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-06-20 22:20:28 +0200
commit0dceefc5fa81a6c851b51acab695a8c149ec8e3b (patch)
treed26bf3f752e6fa622d14f44e091930004b2d12de /libavcodec/utils.c
parent329898aa45f5f8e8b89386ecd40b8db96746d53c (diff)
parent9e500efdbe0deeff1602500ebc229a0a6b6bb1a2 (diff)
downloadffmpeg-0dceefc5fa81a6c851b51acab695a8c149ec8e3b.tar.gz
Merge commit '9e500efdbe0deeff1602500ebc229a0a6b6bb1a2'
* commit '9e500efdbe0deeff1602500ebc229a0a6b6bb1a2': Add av_image_check_sar() and use it to validate SAR Conflicts: libavcodec/dpx.c libavcodec/dvdec.c libavcodec/ffv1dec.c libavcodec/utils.c libavutil/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r--libavcodec/utils.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index f06d1a62cd..9005f27bde 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -255,6 +255,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)
{
@@ -803,6 +818,15 @@ int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame)
frame->format = avctx->pix_fmt;
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 };
+ }
+
break;
case AVMEDIA_TYPE_AUDIO:
if (!frame->sample_rate)
@@ -1365,6 +1389,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))