diff options
Diffstat (limited to 'chromium/third_party/ffmpeg/libavcodec/svq3.c')
-rw-r--r-- | chromium/third_party/ffmpeg/libavcodec/svq3.c | 107 |
1 files changed, 65 insertions, 42 deletions
diff --git a/chromium/third_party/ffmpeg/libavcodec/svq3.c b/chromium/third_party/ffmpeg/libavcodec/svq3.c index 189be48c368..97233b19d61 100644 --- a/chromium/third_party/ffmpeg/libavcodec/svq3.c +++ b/chromium/third_party/ffmpeg/libavcodec/svq3.c @@ -40,10 +40,12 @@ * http://samples.mplayerhq.hu/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov */ +#include <inttypes.h> + #include "libavutil/attributes.h" #include "internal.h" #include "avcodec.h" -#include "mpegvideo.h" +#include "mpegutils.h" #include "h264.h" #include "h264data.h" // FIXME FIXME FIXME @@ -52,6 +54,7 @@ #include "golomb.h" #include "hpeldsp.h" #include "rectangle.h" +#include "tpeldsp.h" #include "vdpau_internal.h" #if CONFIG_ZLIB @@ -69,9 +72,10 @@ typedef struct { H264Context h; HpelDSPContext hdsp; - Picture *cur_pic; - Picture *next_pic; - Picture *last_pic; + TpelDSPContext tdsp; + H264Picture *cur_pic; + H264Picture *next_pic; + H264Picture *last_pic; int halfpel_flag; int thirdpel_flag; int unknown_flag; @@ -158,6 +162,8 @@ static const uint32_t svq3_dequant_coeff[32] = { 61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533 }; +static int svq3_decode_end(AVCodecContext *avctx); + void ff_svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp) { const int qmul = svq3_dequant_coeff[qp]; @@ -296,8 +302,8 @@ static inline void svq3_mc_dir_part(SVQ3Context *s, int mx, int my, int dxy, int thirdpel, int dir, int avg) { - H264Context *h = &s->h; - const Picture *pic = (dir == 0) ? s->last_pic : s->next_pic; + H264Context *h = &s->h; + const H264Picture *pic = (dir == 0) ? s->last_pic : s->next_pic; uint8_t *src, *dest; int i, emu = 0; int blocksize = 2 - (width >> 3); // 16->0, 8->1, 4->2 @@ -324,9 +330,9 @@ static inline void svq3_mc_dir_part(SVQ3Context *s, src = h->edge_emu_buffer; } if (thirdpel) - (avg ? h->dsp.avg_tpel_pixels_tab - : h->dsp.put_tpel_pixels_tab)[dxy](dest, src, h->linesize, - width, height); + (avg ? s->tdsp.avg_tpel_pixels_tab + : s->tdsp.put_tpel_pixels_tab)[dxy](dest, src, h->linesize, + width, height); else (avg ? s->hdsp.avg_pixels_tab : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src, h->linesize, @@ -352,10 +358,10 @@ static inline void svq3_mc_dir_part(SVQ3Context *s, src = h->edge_emu_buffer; } if (thirdpel) - (avg ? h->dsp.avg_tpel_pixels_tab - : h->dsp.put_tpel_pixels_tab)[dxy](dest, src, - h->uvlinesize, - width, height); + (avg ? s->tdsp.avg_tpel_pixels_tab + : s->tdsp.put_tpel_pixels_tab)[dxy](dest, src, + h->uvlinesize, + width, height); else (avg ? s->hdsp.avg_pixels_tab : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src, @@ -619,7 +625,8 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type) vlc = svq3_get_ue_golomb(&h->gb); if (vlc >= 25U) { - av_log(h->avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc); + av_log(h->avctx, AV_LOG_ERROR, + "luma prediction:%"PRIu32"\n", vlc); return -1; } @@ -688,7 +695,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type) if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || h->pict_type == AV_PICTURE_TYPE_B)) { if ((vlc = svq3_get_ue_golomb(&h->gb)) >= 48U){ - av_log(h->avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc); + av_log(h->avctx, AV_LOG_ERROR, "cbp_vlc=%"PRIu32"\n", vlc); return -1; } @@ -810,7 +817,7 @@ static int svq3_decode_slice_header(AVCodecContext *avctx) } if ((slice_id = svq3_get_ue_golomb(&h->gb)) >= 3) { - av_log(h->avctx, AV_LOG_ERROR, "illegal slice type %d \n", slice_id); + av_log(h->avctx, AV_LOG_ERROR, "illegal slice type %u \n", slice_id); return -1; } @@ -868,26 +875,28 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx) unsigned char *extradata_end; unsigned int size; int marker_found = 0; + int ret; s->cur_pic = av_mallocz(sizeof(*s->cur_pic)); s->last_pic = av_mallocz(sizeof(*s->last_pic)); s->next_pic = av_mallocz(sizeof(*s->next_pic)); if (!s->next_pic || !s->last_pic || !s->cur_pic) { - av_freep(&s->cur_pic); - av_freep(&s->last_pic); - av_freep(&s->next_pic); - return AVERROR(ENOMEM); + ret = AVERROR(ENOMEM); + goto fail; } - if (ff_h264_decode_init(avctx) < 0) - return -1; + if ((ret = ff_h264_decode_init(avctx)) < 0) + goto fail; ff_hpeldsp_init(&s->hdsp, avctx->flags); + ff_tpeldsp_init(&s->tdsp); + h->flags = avctx->flags; h->is_complex = 1; h->sps.chroma_format_idc = 1; h->picture_structure = PICT_FRAME; - avctx->pix_fmt = avctx->codec->pix_fmts[0]; + avctx->pix_fmt = AV_PIX_FMT_YUVJ420P; + avctx->color_range = AVCOL_RANGE_JPEG; h->chroma_qp[0] = h->chroma_qp[1] = 4; h->chroma_x_shift = h->chroma_y_shift = 1; @@ -915,8 +924,10 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx) int frame_size_code; size = AV_RB32(&extradata[4]); - if (size > extradata_end - extradata - 8) - return AVERROR_INVALIDDATA; + if (size > extradata_end - extradata - 8) { + ret = AVERROR_INVALIDDATA; + goto fail; + } init_get_bits(&gb, extradata + 8, size * 8); /* 'frame size code' and optional 'width, height' */ @@ -970,8 +981,10 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx) /* unknown field */ skip_bits1(&gb); - if (skip_1stop_8data_bits(&gb) < 0) - return AVERROR_INVALIDDATA; + if (skip_1stop_8data_bits(&gb) < 0) { + ret = AVERROR_INVALIDDATA; + goto fail; + } s->unknown_flag = get_bits1(&gb); avctx->has_b_frames = !h->low_delay; @@ -989,11 +1002,13 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx) uint8_t *buf; if (watermark_height <= 0 || - (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height) - return -1; + (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height) { + ret = -1; + goto fail; + } buf = av_malloc(buf_len); - av_log(avctx, AV_LOG_DEBUG, "watermark size: %dx%d\n", + av_log(avctx, AV_LOG_DEBUG, "watermark size: %ux%u\n", watermark_width, watermark_height); av_log(avctx, AV_LOG_DEBUG, "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n", @@ -1003,17 +1018,19 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "could not uncompress watermark logo\n"); av_free(buf); - return -1; + ret = -1; + goto fail; } s->watermark_key = ff_svq1_packet_checksum(buf, buf_len, 0); s->watermark_key = s->watermark_key << 16 | s->watermark_key; av_log(avctx, AV_LOG_DEBUG, - "watermark key %#x\n", s->watermark_key); + "watermark key %#"PRIx32"\n", s->watermark_key); av_free(buf); #else av_log(avctx, AV_LOG_ERROR, "this svq3 file contains watermark which need zlib support compiled in\n"); - return -1; + ret = -1; + goto fail; #endif } } @@ -1028,15 +1045,18 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx) s->h_edge_pos = h->mb_width * 16; s->v_edge_pos = h->mb_height * 16; - if (ff_h264_alloc_tables(h) < 0) { + if ((ret = ff_h264_alloc_tables(h)) < 0) { av_log(avctx, AV_LOG_ERROR, "svq3 memory allocation failed\n"); - return AVERROR(ENOMEM); + goto fail; } return 0; +fail: + svq3_decode_end(avctx); + return ret; } -static void free_picture(AVCodecContext *avctx, Picture *pic) +static void free_picture(AVCodecContext *avctx, H264Picture *pic) { int i; for (i = 0; i < 2; i++) { @@ -1048,7 +1068,7 @@ static void free_picture(AVCodecContext *avctx, Picture *pic) av_frame_unref(&pic->f); } -static int get_buffer(AVCodecContext *avctx, Picture *pic) +static int get_buffer(AVCodecContext *avctx, H264Picture *pic) { SVQ3Context *s = avctx->priv_data; H264Context *h = &s->h; @@ -1142,7 +1162,7 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data, h->pict_type = h->slice_type; if (h->pict_type != AV_PICTURE_TYPE_B) - FFSWAP(Picture*, s->next_pic, s->last_pic); + FFSWAP(H264Picture*, s->next_pic, s->last_pic); av_frame_unref(&s->cur_pic->f); @@ -1175,6 +1195,7 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data, if (h->pict_type != AV_PICTURE_TYPE_I) { if (!s->last_pic->f.data[0]) { av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n"); + av_frame_unref(&s->last_pic->f); ret = get_buffer(avctx, s->last_pic); if (ret < 0) return ret; @@ -1187,6 +1208,7 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data, if (h->pict_type == AV_PICTURE_TYPE_B && !s->next_pic->f.data[0]) { av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n"); + av_frame_unref(&s->next_pic->f); ret = get_buffer(avctx, s->next_pic); if (ret < 0) return ret; @@ -1284,9 +1306,10 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data, (h->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1; } - ff_draw_horiz_band(avctx, NULL, s->cur_pic, s->last_pic->f.data[0] ? s->last_pic : NULL, - 16 * h->mb_y, 16, h->picture_structure, 0, 0, - h->low_delay, h->mb_height * 16, h->mb_width * 16); + ff_draw_horiz_band(avctx, &s->cur_pic->f, + s->last_pic->f.data[0] ? &s->last_pic->f : NULL, + 16 * h->mb_y, 16, h->picture_structure, 0, + h->low_delay); } left = buf_size*8 - get_bits_count(&h->gb); @@ -1313,7 +1336,7 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data, *got_frame = 1; if (h->pict_type != AV_PICTURE_TYPE_B) { - FFSWAP(Picture*, s->cur_pic, s->next_pic); + FFSWAP(H264Picture*, s->cur_pic, s->next_pic); } else { av_frame_unref(&s->cur_pic->f); } |