Unified · Split
| @@ -13,6 +13,9 @@ libavutil: 2013-12-xx · 12 unmodified lines | ||
| 13 | 13 | |
| 14 | 14 | API changes, most recent first: |
| 15 | 15 | |
| 16 | +2014-06-xx - xxxxxxx - lavu 53.17.0 - imgutils.h | |
| 17 | + Add av_image_check_sar(). | |
| 18 | + | |
| 16 | 19 | 2014-06-xx - xxxxxxx - lavc 55.55.0 - avcodec.h |
| 17 | 20 | Add av_packet_rescale_ts() to simplify timestamp conversion. |
| 18 | 21 | |
| @@ -316,6 +316,8 @@ int avpriv_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, · 315 unmodified lines | ||
| 316 | 316 | if (ret < 0) |
| 317 | 317 | return ret; |
| 318 | 318 | |
| 319 | + ff_set_sar(avctx, avctx->sample_aspect_ratio); | |
| 320 | + | |
| 319 | 321 | /* [DIRAC_STD] picture_coding_mode shall be 0 for fields and 1 for frames |
| 320 | 322 | * currently only used to signal field coding */ |
| 321 | 323 | picture_coding_mode = svq3_get_ue_golomb(gb); |
| @@ -150,6 +150,8 @@ static int decode_frame(AVCodecContext *avctx, · 149 unmodified lines | ||
| 150 | 150 | if ((ret = ff_set_dimensions(avctx, w, h)) < 0) |
| 151 | 151 | return ret; |
| 152 | 152 | |
| 153 | + ff_set_sar(avctx, avctx->sample_aspect_ratio); | |
| 154 | + | |
| 153 | 155 | if ((ret = ff_get_buffer(avctx, p, 0)) < 0) { |
| 154 | 156 | av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
| 155 | 157 | return ret; |
| @@ -36,6 +36,7 @@ · 35 unmodified lines | ||
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | 38 | #include "libavutil/internal.h" |
| 39 | +#include "libavutil/imgutils.h" | |
| 39 | 40 | #include "libavutil/pixdesc.h" |
| 40 | 41 | #include "avcodec.h" |
| 41 | 42 | #include "internal.h" |
| @@ -347,6 +348,14 @@ static int dvvideo_decode_frame(AVCodecContext *avctx, · 305 unmodified lines | ||
| 347 | 348 | if (ret < 0) |
| 348 | 349 | return ret; |
| 349 | 350 | |
| 351 | + /* Determine the codec's sample_aspect ratio from the packet */ | |
| 352 | + vsc_pack = buf + 80*5 + 48 + 5; | |
| 353 | + if ( *vsc_pack == dv_video_control ) { | |
| 354 | + apt = buf[4] & 0x07; | |
| 355 | + is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07))); | |
| 356 | + ff_set_sar(avctx, s->sys->sar[is16_9]); | |
| 357 | + } | |
| 358 | + | |
| 350 | 359 | if (ff_get_buffer(avctx, s->frame, 0) < 0) { |
| 351 | 360 | av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
| 352 | 361 | return -1; |
| @@ -363,14 +372,6 @@ static int dvvideo_decode_frame(AVCodecContext *avctx, · 10 unmodified lines | ||
| 363 | 372 | /* return image */ |
| 364 | 373 | *got_frame = 1; |
| 365 | 374 | |
| 366 | − /* Determine the codec's sample_aspect ratio from the packet */ | |
| 367 | − vsc_pack = buf + 80*5 + 48 + 5; | |
| 368 | − if ( *vsc_pack == dv_video_control ) { | |
| 369 | − apt = buf[4] & 0x07; | |
| 370 | − is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07))); | |
| 371 | − avctx->sample_aspect_ratio = s->sys->sar[is16_9]; | |
| 372 | − } | |
| 373 | − | |
| 374 | 375 | return s->sys->frame_size; |
| 375 | 376 | } |
| 376 | 377 | |
| @@ -1107,8 +1107,8 @@ static int decode_header(EXRContext *s) · 1106 unmodified lines | ||
| 1107 | 1107 | if (!var_size) |
| 1108 | 1108 | return AVERROR_INVALIDDATA; |
| 1109 | 1109 | |
| 1110 | − s->avctx->sample_aspect_ratio = | |
| 1111 | − av_d2q(av_int2float(bytestream2_get_le32(&s->gb)), 255); | |
| 1110 | + ff_set_sar(s->avctx, | |
| 1111 | + av_d2q(av_int2float(bytestream2_get_le32(&s->gb)), 255)); | |
| 1112 | 1112 | |
| 1113 | 1113 | continue; |
| 1114 | 1114 | } else if ((var_size = check_header_variable(s, "compression", |
| @@ -328,6 +328,14 @@ static int decode_slice_header(FFV1Context *f, FFV1Context *fs) · 327 unmodified lines | ||
| 328 | 328 | f->cur->sample_aspect_ratio.num = get_symbol(c, state, 0); |
| 329 | 329 | f->cur->sample_aspect_ratio.den = get_symbol(c, state, 0); |
| 330 | 330 | |
| 331 | + if (av_image_check_sar(f->width, f->height, | |
| 332 | + f->cur->sample_aspect_ratio) < 0) { | |
| 333 | + av_log(f->avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", | |
| 334 | + f->cur->sample_aspect_ratio.num, | |
| 335 | + f->cur->sample_aspect_ratio.den); | |
| 336 | + f->cur->sample_aspect_ratio = (AVRational){ 0, 1 }; | |
| 337 | + } | |
| 338 | + | |
| 331 | 339 | return 0; |
| 332 | 340 | } |
| 333 | 341 | |
| @@ -497,6 +497,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, · 496 unmodified lines | ||
| 497 | 497 | if (ret < 0) |
| 498 | 498 | return ret; |
| 499 | 499 | |
| 500 | + ff_set_sar(avctx, avctx->sample_aspect_ratio); | |
| 501 | + | |
| 500 | 502 | if ((ret = ff_MPV_common_frame_size_change(s))) |
| 501 | 503 | return ret; |
| 502 | 504 | } |
| @@ -1067,8 +1067,7 @@ static int h264_slice_header_init(H264Context *h, int reinit) · 1066 unmodified lines | ||
| 1067 | 1067 | h->avctx->thread_count : 1; |
| 1068 | 1068 | int i, ret; |
| 1069 | 1069 | |
| 1070 | − h->avctx->sample_aspect_ratio = h->sps.sar; | |
| 1071 | − av_assert0(h->avctx->sample_aspect_ratio.den); | |
| 1070 | + ff_set_sar(h->avctx, h->sps.sar); | |
| 1072 | 1071 | av_pix_fmt_get_chroma_sub_sample(h->avctx->pix_fmt, |
| 1073 | 1072 | &h->chroma_x_shift, &h->chroma_y_shift); |
| 1074 | 1073 | |
| @@ -400,9 +400,10 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps) · 399 unmodified lines | ||
| 400 | 400 | s->avctx->width = sps->output_width; |
| 401 | 401 | s->avctx->height = sps->output_height; |
| 402 | 402 | s->avctx->pix_fmt = sps->pix_fmt; |
| 403 | − s->avctx->sample_aspect_ratio = sps->vui.sar; | |
| 404 | 403 | s->avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics; |
| 405 | 404 | |
| 405 | + ff_set_sar(s->avctx, sps->vui.sar); | |
| 406 | + | |
| 406 | 407 | if (sps->vui.video_signal_type_present_flag) |
| 407 | 408 | s->avctx->color_range = sps->vui.video_full_range_flag ? AVCOL_RANGE_JPEG |
| 408 | 409 | : AVCOL_RANGE_MPEG; |
| @@ -176,6 +176,12 @@ const uint8_t *avpriv_find_start_code(const uint8_t *restrict p, · 175 unmodified lines | ||
| 176 | 176 | */ |
| 177 | 177 | int ff_set_dimensions(AVCodecContext *s, int width, int height); |
| 178 | 178 | |
| 179 | +/** | |
| 180 | + * Check that the provided sample aspect ratio is valid and set it on the codec | |
| 181 | + * context. | |
| 182 | + */ | |
| 183 | +int ff_set_sar(AVCodecContext *avctx, AVRational sar); | |
| 184 | + | |
| 179 | 185 | /** |
| 180 | 186 | * Add or update AV_FRAME_DATA_MATRIXENCODING side data. |
| 181 | 187 | */ |
| @@ -1222,6 +1222,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s) · 1221 unmodified lines | ||
| 1222 | 1222 | |
| 1223 | 1223 | s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 16); |
| 1224 | 1224 | s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 16); |
| 1225 | + ff_set_sar(s->avctx, s->avctx->sample_aspect_ratio); | |
| 1225 | 1226 | |
| 1226 | 1227 | if (s->avctx->debug & FF_DEBUG_PICT_INFO) |
| 1227 | 1228 | av_log(s->avctx, AV_LOG_INFO, |
| @@ -1294,6 +1294,8 @@ static int mpeg_decode_postinit(AVCodecContext *avctx) · 1293 unmodified lines | ||
| 1294 | 1294 | } |
| 1295 | 1295 | } // MPEG-2 |
| 1296 | 1296 | |
| 1297 | + ff_set_sar(s->avctx, s->avctx->sample_aspect_ratio); | |
| 1298 | + | |
| 1297 | 1299 | avctx->pix_fmt = mpeg_get_pixelformat(avctx); |
| 1298 | 1300 | // until then pix_fmt may be changed right after codec init |
| 1299 | 1301 | #if FF_API_XVMC |
| @@ -412,6 +412,8 @@ static int truemotion1_decode_header(TrueMotion1Context *s) · 411 unmodified lines | ||
| 412 | 412 | if ((ret = ff_set_dimensions(s->avctx, s->w, s->h)) < 0) |
| 413 | 413 | return ret; |
| 414 | 414 | |
| 415 | + ff_set_sar(s->avctx, s->avctx->sample_aspect_ratio); | |
| 416 | + | |
| 415 | 417 | av_fast_malloc(&s->vert_pred, &s->vert_pred_size, s->avctx->width * sizeof(unsigned int)); |
| 416 | 418 | } |
| 417 | 419 | |
| @@ -153,6 +153,21 @@ int ff_set_dimensions(AVCodecContext *s, int width, int height) · 152 unmodified lines | ||
| 153 | 153 | return ret; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | +int ff_set_sar(AVCodecContext *avctx, AVRational sar) | |
| 157 | +{ | |
| 158 | + int ret = av_image_check_sar(avctx->width, avctx->height, sar); | |
| 159 | + | |
| 160 | + if (ret < 0) { | |
| 161 | + av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", | |
| 162 | + sar.num, sar.den); | |
| 163 | + avctx->sample_aspect_ratio = (AVRational){ 0, 1 }; | |
| 164 | + return ret; | |
| 165 | + } else { | |
| 166 | + avctx->sample_aspect_ratio = sar; | |
| 167 | + } | |
| 168 | + return 0; | |
| 169 | +} | |
| 170 | + | |
| 156 | 171 | int ff_side_data_update_matrix_encoding(AVFrame *frame, |
| 157 | 172 | enum AVMatrixEncoding matrix_encoding) |
| 158 | 173 | { |
| @@ -636,6 +651,14 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) · 477 unmodified lines | ||
| 636 | 651 | if (!frame->sample_aspect_ratio.num) |
| 637 | 652 | frame->sample_aspect_ratio = avctx->sample_aspect_ratio; |
| 638 | 653 | |
| 654 | + if (av_image_check_sar(frame->width, frame->height, | |
| 655 | + frame->sample_aspect_ratio) < 0) { | |
| 656 | + av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", | |
| 657 | + frame->sample_aspect_ratio.num, | |
| 658 | + frame->sample_aspect_ratio.den); | |
| 659 | + frame->sample_aspect_ratio = (AVRational){ 0, 1 }; | |
| 660 | + } | |
| 661 | + | |
| 639 | 662 | if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) |
| 640 | 663 | return ret; |
| 641 | 664 | break; |
| @@ -1071,6 +1094,16 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 429 unmodified lines | ||
| 1071 | 1094 | ff_set_dimensions(avctx, 0, 0); |
| 1072 | 1095 | } |
| 1073 | 1096 | |
| 1097 | + if (avctx->width > 0 && avctx->height > 0) { | |
| 1098 | + if (av_image_check_sar(avctx->width, avctx->height, | |
| 1099 | + avctx->sample_aspect_ratio) < 0) { | |
| 1100 | + av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", | |
| 1101 | + avctx->sample_aspect_ratio.num, | |
| 1102 | + avctx->sample_aspect_ratio.den); | |
| 1103 | + avctx->sample_aspect_ratio = (AVRational){ 0, 1 }; | |
| 1104 | + } | |
| 1105 | + } | |
| 1106 | + | |
| 1074 | 1107 | /* if the decoder init function was already called previously, |
| 1075 | 1108 | * free the already allocated subtitle_header before overwriting it */ |
| 1076 | 1109 | if (av_codec_is_decoder(codec)) |
| @@ -478,6 +478,7 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) · 477 unmodified lines | ||
| 478 | 478 | v->s.avctx->width * h, |
| 479 | 479 | 1 << 30); |
| 480 | 480 | } |
| 481 | + ff_set_sar(v->s.avctx, v->s.avctx->sample_aspect_ratio); | |
| 481 | 482 | av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n", |
| 482 | 483 | v->s.avctx->sample_aspect_ratio.num, |
| 483 | 484 | v->s.avctx->sample_aspect_ratio.den); |
| @@ -2243,6 +2243,7 @@ static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb) · 2242 unmodified lines | ||
| 2243 | 2243 | av_reduce(&avctx->sample_aspect_ratio.num, |
| 2244 | 2244 | &avctx->sample_aspect_ratio.den, |
| 2245 | 2245 | aspect.num, aspect.den, 1 << 30); |
| 2246 | + ff_set_sar(avctx, avctx->sample_aspect_ratio); | |
| 2246 | 2247 | } |
| 2247 | 2248 | |
| 2248 | 2249 | if (s->theora < 0x030200) |
| @@ -25,7 +25,9 @@ · 24 unmodified lines | ||
| 25 | 25 | #include "imgutils.h" |
| 26 | 26 | #include "internal.h" |
| 27 | 27 | #include "log.h" |
| 28 | +#include "mathematics.h" | |
| 28 | 29 | #include "pixdesc.h" |
| 30 | +#include "rational.h" | |
| 29 | 31 | |
| 30 | 32 | void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], |
| 31 | 33 | const AVPixFmtDescriptor *pixdesc) |
| @@ -228,6 +230,27 @@ int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *lo · 196 unmodified lines | ||
| 228 | 230 | return AVERROR(EINVAL); |
| 229 | 231 | } |
| 230 | 232 | |
| 233 | +int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar) | |
| 234 | +{ | |
| 235 | + int64_t scaled_dim; | |
| 236 | + | |
| 237 | + if (!sar.den) | |
| 238 | + return AVERROR(EINVAL); | |
| 239 | + | |
| 240 | + if (!sar.num || sar.num == sar.den) | |
| 241 | + return 0; | |
| 242 | + | |
| 243 | + if (sar.num < sar.den) | |
| 244 | + scaled_dim = av_rescale_rnd(w, sar.num, sar.den, AV_ROUND_ZERO); | |
| 245 | + else | |
| 246 | + scaled_dim = av_rescale_rnd(h, sar.den, sar.num, AV_ROUND_ZERO); | |
| 247 | + | |
| 248 | + if (scaled_dim > 0) | |
| 249 | + return 0; | |
| 250 | + | |
| 251 | + return AVERROR(EINVAL); | |
| 252 | +} | |
| 253 | + | |
| 231 | 254 | void av_image_copy_plane(uint8_t *dst, int dst_linesize, |
| 232 | 255 | const uint8_t *src, int src_linesize, |
| 233 | 256 | int bytewidth, int height) |
| @@ -29,6 +29,7 @@ · 28 unmodified lines | ||
| 29 | 29 | |
| 30 | 30 | #include "avutil.h" |
| 31 | 31 | #include "pixdesc.h" |
| 32 | +#include "rational.h" | |
| 32 | 33 | |
| 33 | 34 | /** |
| 34 | 35 | * Compute the max pixel step for each plane of an image with a |
| @@ -128,6 +129,20 @@ void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], · 93 unmodified lines | ||
| 128 | 129 | */ |
| 129 | 130 | int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx); |
| 130 | 131 | |
| 132 | +/** | |
| 133 | + * Check if the given sample aspect ratio of an image is valid. | |
| 134 | + * | |
| 135 | + * It is considered invalid if the denominator is 0 or if applying the ratio | |
| 136 | + * to the image size would make the smaller dimension less than 1. If the | |
| 137 | + * sar numerator is 0, it is considered unknown and will return as valid. | |
| 138 | + * | |
| 139 | + * @param w width of the image | |
| 140 | + * @param h height of the image | |
| 141 | + * @param sar sample aspect ratio of the image | |
| 142 | + * @return 0 if valid, a negative AVERROR code otherwise | |
| 143 | + */ | |
| 144 | +int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar); | |
| 145 | + | |
| 131 | 146 | int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt); |
| 132 | 147 | |
| 133 | 148 | /** |
| @@ -54,7 +54,7 @@ · 53 unmodified lines | ||
| 54 | 54 | */ |
| 55 | 55 | |
| 56 | 56 | #define LIBAVUTIL_VERSION_MAJOR 53 |
| 57 | −#define LIBAVUTIL_VERSION_MINOR 16 | |
| 57 | +#define LIBAVUTIL_VERSION_MINOR 17 | |
| 58 | 58 | #define LIBAVUTIL_VERSION_MICRO 0 |
| 59 | 59 | |
| 60 | 60 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |