diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-12-21 02:46:08 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-12-21 03:40:53 +0100 |
commit | 3be1a4ba9a9d926674b33051d6539fe8d8a4106c (patch) | |
tree | c92779c80a98d94133dde283a86c4b4547dc16ab /libavcodec | |
parent | 134aaa79f7f1ce1df64afc7d10d2b3de77df7b08 (diff) | |
parent | 37c0dc626d2f8254ef623d987eb5077f9120755f (diff) | |
download | ffmpeg-3be1a4ba9a9d926674b33051d6539fe8d8a4106c.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
lavc: always align height by 32 pixel
raw: add 10bit YUV definitions
nut: support 10bit YUV
mpegvideo_enc: separate declarations and statements
oma: make header compile standalone
vp3: Reorder some functions to fix VP3 build with Theora disabled.
build: fix standalone compilation of ADX encoder
build: fix standalone compilation of ADPCM decoders
build: fix standalone compilation of mpc7/mpc8 decoders
4xm: Use bytestream2 functions to prevent overreads
bytestream: add a new set of bytestream functions with overread checking
mpegts: Suppress invalid timebase warnings on DMB streams.
mpegts: Fix typo in handling sections in the PMT.
vc1dec: Use the right pointer type for the tmp pointer
Conflicts:
libavcodec/4xm.c
libavcodec/utils.c
libavcodec/vc1dec.c
libavcodec/vp3.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/4xm.c | 42 | ||||
-rw-r--r-- | libavcodec/Makefile | 24 | ||||
-rw-r--r-- | libavcodec/bytestream.h | 44 | ||||
-rw-r--r-- | libavcodec/mpegvideo_enc.c | 3 | ||||
-rw-r--r-- | libavcodec/raw.c | 6 | ||||
-rw-r--r-- | libavcodec/utils.c | 6 | ||||
-rw-r--r-- | libavcodec/vc1dec.c | 3 | ||||
-rw-r--r-- | libavcodec/vp3.c | 151 |
8 files changed, 161 insertions, 118 deletions
diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c index 43f6a21ea8..370fe6df47 100644 --- a/libavcodec/4xm.c +++ b/libavcodec/4xm.c @@ -132,10 +132,8 @@ typedef struct FourXContext{ AVFrame current_picture, last_picture; GetBitContext pre_gb; ///< ac/dc prefix GetBitContext gb; - const uint8_t *bytestream; - const uint8_t *bytestream_end; - const uint16_t *wordstream; - const uint16_t *wordstream_end; + GetByteContext g; + GetByteContext g2; int mv[256]; VLC pre_vlc; int last_dc; @@ -330,11 +328,11 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int lo assert(code>=0 && code<=6); if(code == 0){ - if (f->bytestream_end - f->bytestream < 1){ + if (f->g.buffer_end - f->g.buffer < 1){ av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n"); return; } - src += f->mv[ *f->bytestream++ ]; + src += f->mv[ *f->g.buffer++ ]; if(start > src || src > end){ av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n"); return; @@ -351,37 +349,37 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int lo }else if(code == 3 && f->version<2){ mcdc(dst, src, log2w, h, stride, 1, 0); }else if(code == 4){ - if (f->bytestream_end - f->bytestream < 1){ + if (f->g.buffer_end - f->g.buffer < 1){ av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n"); return; } - src += f->mv[ *f->bytestream++ ]; + src += f->mv[ *f->g.buffer++ ]; if(start > src || src > end){ av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n"); return; } - if (f->wordstream_end - f->wordstream < 1){ + if (f->g2.buffer_end - f->g2.buffer < 1){ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n"); return; } - mcdc(dst, src, log2w, h, stride, 1, av_le2ne16(*f->wordstream++)); + mcdc(dst, src, log2w, h, stride, 1, bytestream2_get_le16(&f->g2)); }else if(code == 5){ - if (f->wordstream_end - f->wordstream < 1){ + if (f->g2.buffer_end - f->g2.buffer < 1){ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n"); return; } - mcdc(dst, src, log2w, h, stride, 0, av_le2ne16(*f->wordstream++)); + mcdc(dst, src, log2w, h, stride, 0, bytestream2_get_le16(&f->g2)); }else if(code == 6){ - if (f->wordstream_end - f->wordstream < 2){ + if (f->g2.buffer_end - f->g2.buffer < 2){ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n"); return; } if(log2w){ - dst[0] = av_le2ne16(*f->wordstream++); - dst[1] = av_le2ne16(*f->wordstream++); + dst[0] = bytestream2_get_le16(&f->g2); + dst[1] = bytestream2_get_le16(&f->g2); }else{ - dst[0 ] = av_le2ne16(*f->wordstream++); - dst[stride] = av_le2ne16(*f->wordstream++); + dst[0 ] = bytestream2_get_le16(&f->g2); + dst[stride] = bytestream2_get_le16(&f->g2); } } } @@ -393,7 +391,7 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){ uint16_t *src= (uint16_t*)f->last_picture.data[0]; uint16_t *dst= (uint16_t*)f->current_picture.data[0]; const int stride= f->current_picture.linesize[0]>>1; - unsigned int bitstream_size, bytestream_size, wordstream_size, extra; + unsigned int bitstream_size, bytestream_size, wordstream_size, extra, bytestream_offset, wordstream_offset; if(f->version>1){ extra=20; @@ -425,10 +423,10 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){ memset((uint8_t*)f->bitstream_buffer + bitstream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); init_get_bits(&f->gb, f->bitstream_buffer, 8*bitstream_size); - f->wordstream= (const uint16_t*)(buf + extra + bitstream_size); - f->wordstream_end= f->wordstream + wordstream_size/2; - f->bytestream= buf + extra + bitstream_size + wordstream_size; - f->bytestream_end = f->bytestream + bytestream_size; + wordstream_offset = extra + bitstream_size; + bytestream_offset = extra + bitstream_size + wordstream_size; + bytestream2_init(&f->g2, buf + wordstream_offset, length - wordstream_offset); + bytestream2_init(&f->g, buf + bytestream_offset, length - bytestream_offset); init_mv(f); diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 9289494e05..61ebe6a6ea 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -525,14 +525,14 @@ OBJS-$(CONFIG_PCM_ZORK_DECODER) += pcm.o OBJS-$(CONFIG_ADPCM_4XM_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_ADX_DECODER) += adxdec.o adx.o -OBJS-$(CONFIG_ADPCM_ADX_ENCODER) += adxenc.o +OBJS-$(CONFIG_ADPCM_ADX_ENCODER) += adxenc.o adx.o OBJS-$(CONFIG_ADPCM_CT_DECODER) += adpcm.o adpcm_data.o -OBJS-$(CONFIG_ADPCM_EA_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_EA_MAXIS_XA_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_EA_R1_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_EA_R2_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_EA_R3_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_EA_XAS_DECODER) += adpcm.o +OBJS-$(CONFIG_ADPCM_EA_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_EA_MAXIS_XA_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_EA_R1_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_EA_R2_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_EA_R3_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_EA_XAS_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_G722_DECODER) += g722.o g722dec.o OBJS-$(CONFIG_ADPCM_G722_ENCODER) += g722.o g722enc.o OBJS-$(CONFIG_ADPCM_G726_DECODER) += g726.o @@ -551,13 +551,13 @@ OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcmenc.o adpcm_data.o OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcmenc.o adpcm_data.o -OBJS-$(CONFIG_ADPCM_SBPRO_2_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_SBPRO_3_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_SBPRO_4_DECODER) += adpcm.o +OBJS-$(CONFIG_ADPCM_SBPRO_2_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_SBPRO_3_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_SBPRO_4_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_SWF_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_SWF_ENCODER) += adpcmenc.o adpcm_data.o -OBJS-$(CONFIG_ADPCM_THP_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_XA_DECODER) += adpcm.o +OBJS-$(CONFIG_ADPCM_THP_DECODER) += adpcm.o adpcm_data.o +OBJS-$(CONFIG_ADPCM_XA_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o adpcm_data.o OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcmenc.o adpcm_data.o diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h index b56f6ce743..7ca36f8ad3 100644 --- a/libavcodec/bytestream.h +++ b/libavcodec/bytestream.h @@ -26,6 +26,10 @@ #include "libavutil/common.h" #include "libavutil/intreadwrite.h" +typedef struct { + const uint8_t *buffer, *buffer_end; +} GetByteContext; + #define DEF_T(type, name, bytes, read, write) \ static av_always_inline type bytestream_get_ ## name(const uint8_t **b){\ (*b) += bytes;\ @@ -34,6 +38,18 @@ static av_always_inline type bytestream_get_ ## name(const uint8_t **b){\ static av_always_inline void bytestream_put_ ##name(uint8_t **b, const type value){\ write(*b, value);\ (*b) += bytes;\ +}\ +static av_always_inline type bytestream2_get_ ## name(GetByteContext *g)\ +{\ + if (g->buffer_end - g->buffer < bytes)\ + return 0;\ + return bytestream_get_ ## name(&g->buffer);\ +}\ +static av_always_inline type bytestream2_peek_ ## name(GetByteContext *g)\ +{\ + if (g->buffer_end - g->buffer < bytes)\ + return 0;\ + return read(g->buffer);\ } #define DEF(name, bytes, read, write) \ @@ -55,6 +71,34 @@ DEF (byte, 1, AV_RB8 , AV_WB8 ) #undef DEF64 #undef DEF_T +static av_always_inline void bytestream2_init(GetByteContext *g, + const uint8_t *buf, int buf_size) +{ + g->buffer = buf; + g->buffer_end = buf + buf_size; +} + +static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g) +{ + return g->buffer_end - g->buffer; +} + +static av_always_inline void bytestream2_skip(GetByteContext *g, + unsigned int size) +{ + g->buffer += FFMIN(g->buffer_end - g->buffer, size); +} + +static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, + uint8_t *dst, + unsigned int size) +{ + int size2 = FFMIN(g->buffer_end - g->buffer, size); + memcpy(dst, g->buffer, size2); + g->buffer += size2; + return size2; +} + static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size) { memcpy(dst, *b, size); diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 83c4932d5b..690df08708 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1213,10 +1213,11 @@ no_output_pic: if (s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_SHARED || s->avctx->rc_buffer_size) { // input is a shared pix, so we can't modifiy it -> alloc a new one & ensure that the shared one is reuseable + Picture *pic; int i= ff_find_unused_picture(s, 0); if (i < 0) return i; - Picture *pic= &s->picture[i]; + pic = &s->picture[i]; pic->f.reference = s->reordered_input_picture[0]->f.reference; if(ff_alloc_picture(s, pic, 0) < 0){ diff --git a/libavcodec/raw.c b/libavcodec/raw.c index a26dea8146..42469fdf65 100644 --- a/libavcodec/raw.c +++ b/libavcodec/raw.c @@ -108,6 +108,12 @@ const PixelFormatTag ff_raw_pix_fmt_tags[] = { { PIX_FMT_BGR48BE, MKTAG( 48, 'B', 'G', 'R') }, { PIX_FMT_GRAY16LE, MKTAG('Y', '1', 0 , 16 ) }, { PIX_FMT_GRAY16BE, MKTAG(16 , 0 , '1', 'Y') }, + { PIX_FMT_YUV420P10LE, MKTAG('Y', '3', 11 , 10 ) }, + { PIX_FMT_YUV420P10BE, MKTAG(10 , 11 , '3', 'Y') }, + { PIX_FMT_YUV422P10LE, MKTAG('Y', '3', 10 , 10 ) }, + { PIX_FMT_YUV422P10BE, MKTAG(10 , 10 , '3', 'Y') }, + { PIX_FMT_YUV444P10LE, MKTAG('Y', '3', 0 , 10 ) }, + { PIX_FMT_YUV444P10BE, MKTAG(10 , 0 , '3', 'Y') }, { PIX_FMT_YUV420P16LE, MKTAG('Y', '3', 11 , 16 ) }, { PIX_FMT_YUV420P16BE, MKTAG(16 , 11 , '3', 'Y') }, { PIX_FMT_YUV422P16LE, MKTAG('Y', '3', 10 , 16 ) }, diff --git a/libavcodec/utils.c b/libavcodec/utils.c index af872a70e7..7bf729dac7 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -167,10 +167,8 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, case PIX_FMT_GBRP9BE: case PIX_FMT_GBRP10LE: case PIX_FMT_GBRP10BE: - w_align= 16; //FIXME check for non mpeg style codecs and use less alignment - h_align= 16; - if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP || s->codec_id == CODEC_ID_H264 || s->codec_id == CODEC_ID_PRORES) - h_align= 32; // interlaced is rounded up to 2 MBs + w_align = 16; //FIXME assume 16 pixel per macroblock + h_align = 16 * 2; // interlaced needs 2 macroblocks height break; case PIX_FMT_YUV411P: case PIX_FMT_UYYVYY411: diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 96f6d655cb..e4ecf14b5b 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -5426,13 +5426,12 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, AVFrame *pict = data; uint8_t *buf2 = NULL; const uint8_t *buf_start = buf; - uint8_t *tmp; int mb_height, n_slices1=-1; struct { uint8_t *buf; GetBitContext gb; int mby_start; - } *slices = NULL; + } *slices = NULL, *tmp; if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay = 1; diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index a6a3109dba..9e59dd8127 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -45,9 +45,6 @@ #define FRAGMENT_PIXELS 8 -static av_cold int vp3_decode_end(AVCodecContext *avctx); -static void vp3_decode_flush(AVCodecContext *avctx); - //FIXME split things out into their own arrays typedef struct Vp3Fragment { int16_t dc; @@ -256,6 +253,63 @@ typedef struct Vp3DecodeContext { * VP3 specific functions ************************************************************************/ +static void vp3_decode_flush(AVCodecContext *avctx) +{ + Vp3DecodeContext *s = avctx->priv_data; + + if (s->golden_frame.data[0]) { + if (s->golden_frame.data[0] == s->last_frame.data[0]) + memset(&s->last_frame, 0, sizeof(AVFrame)); + if (s->current_frame.data[0] == s->golden_frame.data[0]) + memset(&s->current_frame, 0, sizeof(AVFrame)); + ff_thread_release_buffer(avctx, &s->golden_frame); + } + if (s->last_frame.data[0]) { + if (s->current_frame.data[0] == s->last_frame.data[0]) + memset(&s->current_frame, 0, sizeof(AVFrame)); + ff_thread_release_buffer(avctx, &s->last_frame); + } + if (s->current_frame.data[0]) + ff_thread_release_buffer(avctx, &s->current_frame); +} + +static av_cold int vp3_decode_end(AVCodecContext *avctx) +{ + Vp3DecodeContext *s = avctx->priv_data; + int i; + + av_free(s->superblock_coding); + av_free(s->all_fragments); + av_free(s->coded_fragment_list[0]); + av_free(s->dct_tokens_base); + av_free(s->superblock_fragments); + av_free(s->macroblock_coding); + av_free(s->motion_val[0]); + av_free(s->motion_val[1]); + av_free(s->edge_emu_buffer); + + if (avctx->internal->is_copy) + return 0; + + for (i = 0; i < 16; i++) { + free_vlc(&s->dc_vlc[i]); + free_vlc(&s->ac_vlc_1[i]); + free_vlc(&s->ac_vlc_2[i]); + free_vlc(&s->ac_vlc_3[i]); + free_vlc(&s->ac_vlc_4[i]); + } + + free_vlc(&s->superblock_run_length_vlc); + free_vlc(&s->fragment_run_length_vlc); + free_vlc(&s->mode_code_vlc); + free_vlc(&s->motion_vector_vlc); + + /* release all frames */ + vp3_decode_flush(avctx); + + return 0; +} + /* * This function sets up all of the various blocks mappings: * superblocks <-> fragments, macroblocks <-> fragments, @@ -2002,43 +2056,6 @@ error: static void vp3_decode_flush(AVCodecContext *avctx); -static av_cold int vp3_decode_end(AVCodecContext *avctx) -{ - Vp3DecodeContext *s = avctx->priv_data; - int i; - - av_free(s->superblock_coding); - av_free(s->all_fragments); - av_free(s->coded_fragment_list[0]); - av_free(s->dct_tokens_base); - av_free(s->superblock_fragments); - av_free(s->macroblock_coding); - av_free(s->motion_val[0]); - av_free(s->motion_val[1]); - av_free(s->edge_emu_buffer); - - if (avctx->internal->is_copy) - return 0; - - for (i = 0; i < 16; i++) { - free_vlc(&s->dc_vlc[i]); - free_vlc(&s->ac_vlc_1[i]); - free_vlc(&s->ac_vlc_2[i]); - free_vlc(&s->ac_vlc_3[i]); - free_vlc(&s->ac_vlc_4[i]); - } - - free_vlc(&s->superblock_run_length_vlc); - free_vlc(&s->fragment_run_length_vlc); - free_vlc(&s->mode_code_vlc); - free_vlc(&s->motion_vector_vlc); - - /* release all frames */ - vp3_decode_flush(avctx); - - return 0; -} - static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb) { Vp3DecodeContext *s = avctx->priv_data; @@ -2073,6 +2090,23 @@ static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb) return 0; } +static int vp3_init_thread_copy(AVCodecContext *avctx) +{ + Vp3DecodeContext *s = avctx->priv_data; + + s->superblock_coding = NULL; + s->all_fragments = NULL; + s->coded_fragment_list[0] = NULL; + s->dct_tokens_base = NULL; + s->superblock_fragments = NULL; + s->macroblock_coding = NULL; + s->motion_val[0] = NULL; + s->motion_val[1] = NULL; + s->edge_emu_buffer = NULL; + + return 0; +} + #if CONFIG_THEORA_DECODER static const enum PixelFormat theora_pix_fmts[4] = { PIX_FMT_YUV420P, PIX_FMT_NONE, PIX_FMT_YUV422P, PIX_FMT_YUV444P @@ -2334,43 +2368,6 @@ static av_cold int theora_decode_init(AVCodecContext *avctx) return vp3_decode_init(avctx); } -static void vp3_decode_flush(AVCodecContext *avctx) -{ - Vp3DecodeContext *s = avctx->priv_data; - - if (s->golden_frame.data[0]) { - if (s->golden_frame.data[0] == s->last_frame.data[0]) - memset(&s->last_frame, 0, sizeof(AVFrame)); - if (s->current_frame.data[0] == s->golden_frame.data[0]) - memset(&s->current_frame, 0, sizeof(AVFrame)); - ff_thread_release_buffer(avctx, &s->golden_frame); - } - if (s->last_frame.data[0]) { - if (s->current_frame.data[0] == s->last_frame.data[0]) - memset(&s->current_frame, 0, sizeof(AVFrame)); - ff_thread_release_buffer(avctx, &s->last_frame); - } - if (s->current_frame.data[0]) - ff_thread_release_buffer(avctx, &s->current_frame); -} - -static int vp3_init_thread_copy(AVCodecContext *avctx) -{ - Vp3DecodeContext *s = avctx->priv_data; - - s->superblock_coding = NULL; - s->all_fragments = NULL; - s->coded_fragment_list[0] = NULL; - s->dct_tokens_base = NULL; - s->superblock_fragments = NULL; - s->macroblock_coding = NULL; - s->motion_val[0] = NULL; - s->motion_val[1] = NULL; - s->edge_emu_buffer = NULL; - - return 0; -} - AVCodec ff_theora_decoder = { .name = "theora", .type = AVMEDIA_TYPE_VIDEO, |