From 89f6e8a20c07ad779ca374fdc5b16a22a37a6150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 30 Jan 2012 22:47:40 +0200 Subject: [PATCH 01/29] flvdec: Interpret a toplevel 'object' type metadata item as normal metadata, too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, we've only passed the key string on to the recursive amf_parse_object for the mixedarray type, not for 'object'. By passing the key string on, the recursive amf_parse_object can store the amf objects as metadata. This kind of data was seen in data from XSplit Broadcaster, received over RTMP via Wowza. This patch allows reading this metadata. Signed-off-by: Martin Storsjö --- libavformat/flvdec.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 9296ef9d31..ad38653d76 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -240,22 +240,18 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst if(amf_get_string(ioc, str_val, sizeof(str_val)) < 0) return -1; break; - case AMF_DATA_TYPE_OBJECT: { - unsigned int keylen; - + case AMF_DATA_TYPE_OBJECT: if ((vstream || astream) && key && !strcmp(KEYFRAMES_TAG, key) && depth == 1) if (parse_keyframes_index(s, ioc, vstream ? vstream : astream, max_pos) < 0) return -1; - while(avio_tell(ioc) < max_pos - 2 && (keylen = avio_rb16(ioc))) { - avio_skip(ioc, keylen); //skip key string - if(amf_parse_object(s, NULL, NULL, NULL, max_pos, depth + 1) < 0) + while (avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) { + if (amf_parse_object(s, astream, vstream, str_val, max_pos, depth + 1) < 0) return -1; //if we couldn't skip, bomb out. } if(avio_r8(ioc) != AMF_END_OF_OBJECT) return -1; - } break; case AMF_DATA_TYPE_NULL: case AMF_DATA_TYPE_UNDEFINED: From 75ab1e62d4187c8ad627835ee8fcf38501477caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 18 Jan 2012 15:12:10 +0200 Subject: [PATCH 02/29] movdec: Ignore sample_degradation_priority bits when checking first_sample_flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the first packet of a track fragment run to get the keyframe flag set properly if sample_degradation_priority is nonzero. This makes the keyframes flag be set properly for ismv files created by Microsoft. Signed-off-by: Martin Storsjö --- libavformat/mov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index b7d8a55933..0ce32e0f8e 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2250,7 +2250,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->ctts_data[sc->ctts_count].duration = (flags & 0x800) ? avio_rb32(pb) : 0; sc->ctts_count++; if ((keyframe = st->codec->codec_type == AVMEDIA_TYPE_AUDIO || - (flags & 0x004 && !i && !sample_flags) || sample_flags & 0x2000000)) + (flags & 0x004 && !i && !(sample_flags & 0xffff0000)) || sample_flags & 0x2000000)) distance = 0; av_add_index_entry(st, offset, dts, sample_size, distance, keyframe ? AVINDEX_KEYFRAME : 0); From c30b198381706e94aab1097e49d2638763312b05 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Mon, 30 Jan 2012 09:39:16 +0100 Subject: [PATCH 03/29] x86: Place mm_flags variable declaration below the appropriate #ifdef. This fixes some unused variable warnings with YASM disabled. --- libavcodec/x86/fmtconvert_mmx.c | 2 +- libavcodec/x86/rv40dsp.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/x86/fmtconvert_mmx.c b/libavcodec/x86/fmtconvert_mmx.c index 17079d3c82..42cb0bc85b 100644 --- a/libavcodec/x86/fmtconvert_mmx.c +++ b/libavcodec/x86/fmtconvert_mmx.c @@ -110,9 +110,9 @@ static void float_interleave_sse(float *dst, const float **src, void ff_fmt_convert_init_x86(FmtConvertContext *c, AVCodecContext *avctx) { +#if HAVE_YASM int mm_flags = av_get_cpu_flags(); -#if HAVE_YASM if (mm_flags & AV_CPU_FLAG_MMX) { c->float_interleave = float_interleave_mmx; diff --git a/libavcodec/x86/rv40dsp.c b/libavcodec/x86/rv40dsp.c index 9f90ad8bb6..b429de7293 100644 --- a/libavcodec/x86/rv40dsp.c +++ b/libavcodec/x86/rv40dsp.c @@ -42,9 +42,9 @@ void ff_avg_rv40_chroma_mc4_3dnow(uint8_t *dst, uint8_t *src, void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp) { - av_unused int mm_flags = av_get_cpu_flags(); - #if HAVE_YASM + int mm_flags = av_get_cpu_flags(); + if (mm_flags & AV_CPU_FLAG_MMX) { c->put_chroma_pixels_tab[0] = ff_put_rv40_chroma_mc8_mmx; c->put_chroma_pixels_tab[1] = ff_put_rv40_chroma_mc4_mmx; From 91bafb52ae31d85314e77ba84dc1e10348cd114e Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Mon, 30 Jan 2012 09:56:28 +0100 Subject: [PATCH 04/29] x86: Give RV40 init file a more suitable name. --- libavcodec/x86/Makefile | 2 +- libavcodec/x86/{rv40dsp.c => rv40dsp_init.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename libavcodec/x86/{rv40dsp.c => rv40dsp_init.c} (100%) diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile index 0576c3ad08..2f29138834 100644 --- a/libavcodec/x86/Makefile +++ b/libavcodec/x86/Makefile @@ -27,7 +27,7 @@ MMX-OBJS-$(CONFIG_H264PRED) += x86/h264_intrapred_init.o MMX-OBJS-$(CONFIG_RV30_DECODER) += x86/rv34dsp_init.o YASM-OBJS-$(CONFIG_RV30_DECODER) += x86/rv34dsp.o MMX-OBJS-$(CONFIG_RV40_DECODER) += x86/rv34dsp_init.o \ - x86/rv40dsp.o + x86/rv40dsp_init.o YASM-OBJS-$(CONFIG_RV40_DECODER) += x86/rv34dsp.o YASM-OBJS-$(CONFIG_VC1_DECODER) += x86/vc1dsp_yasm.o diff --git a/libavcodec/x86/rv40dsp.c b/libavcodec/x86/rv40dsp_init.c similarity index 100% rename from libavcodec/x86/rv40dsp.c rename to libavcodec/x86/rv40dsp_init.c From e5c9de2ab78cf18636eac2fa8e059e58a71e512b Mon Sep 17 00:00:00 2001 From: Christophe Gisquet Date: Thu, 12 Jan 2012 00:11:15 +0100 Subject: [PATCH 05/29] rv40: x86 SIMD for biweight Provide MMX, SSE2 and SSSE3 versions, with a fast-path when the weights are multiples of 512 (which is often the case when the values round up nicely). *_TIMER report for the 16x16 and 8x8 cases: C: 9015 decicycles in 16, 524257 runs, 31 skips 2656 decicycles in 8, 524271 runs, 17 skips MMX: 4156 decicycles in 16, 262090 runs, 54 skips 1206 decicycles in 8, 262131 runs, 13 skips MMX on fast-path: 2760 decicycles in 16, 524222 runs, 66 skips 995 decicycles in 8, 524252 runs, 36 skips SSE2: 2163 decicycles in 16, 262131 runs, 13 skips 832 decicycles in 8, 262137 runs, 7 skips SSE2 with fast path: 1783 decicycles in 16, 524276 runs, 12 skips 711 decicycles in 8, 524283 runs, 5 skips SSSE3: 2117 decicycles in 16, 262136 runs, 8 skips 814 decicycles in 8, 262143 runs, 1 skips SSSE3 with fast path: 1315 decicycles in 16, 524285 runs, 3 skips 578 decicycles in 8, 524286 runs, 2 skips This means around a 4% speedup for some sequences. Signed-off-by: Diego Biurrun --- libavcodec/x86/Makefile | 3 +- libavcodec/x86/rv40dsp.asm | 207 ++++++++++++++++++++++++++++++++++ libavcodec/x86/rv40dsp_init.c | 19 ++++ 3 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 libavcodec/x86/rv40dsp.asm diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile index 2f29138834..930ace78c4 100644 --- a/libavcodec/x86/Makefile +++ b/libavcodec/x86/Makefile @@ -28,7 +28,8 @@ MMX-OBJS-$(CONFIG_RV30_DECODER) += x86/rv34dsp_init.o YASM-OBJS-$(CONFIG_RV30_DECODER) += x86/rv34dsp.o MMX-OBJS-$(CONFIG_RV40_DECODER) += x86/rv34dsp_init.o \ x86/rv40dsp_init.o -YASM-OBJS-$(CONFIG_RV40_DECODER) += x86/rv34dsp.o +YASM-OBJS-$(CONFIG_RV40_DECODER) += x86/rv34dsp.o \ + x86/rv40dsp.o YASM-OBJS-$(CONFIG_VC1_DECODER) += x86/vc1dsp_yasm.o diff --git a/libavcodec/x86/rv40dsp.asm b/libavcodec/x86/rv40dsp.asm new file mode 100644 index 0000000000..bff3e7b96a --- /dev/null +++ b/libavcodec/x86/rv40dsp.asm @@ -0,0 +1,207 @@ +;****************************************************************************** +;* MMX/SSE2-optimized functions for the RV40 decoder +;* Copyright (C) 2012 Christophe Gisquet +;* +;* This file is part of Libav. +;* +;* Libav is free software; you can redistribute it and/or +;* modify it under the terms of the GNU Lesser General Public +;* License as published by the Free Software Foundation; either +;* version 2.1 of the License, or (at your option) any later version. +;* +;* Libav is distributed in the hope that it will be useful, +;* but WITHOUT ANY WARRANTY; without even the implied warranty of +;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;* Lesser General Public License for more details. +;* +;* You should have received a copy of the GNU Lesser General Public +;* License along with Libav; if not, write to the Free Software +;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +;****************************************************************************** + +%include "x86inc.asm" +%include "x86util.asm" + +SECTION_RODATA + +align 16 +shift_round: times 8 dw 1 << (16 - 6) +cextern pw_16 + +SECTION .text + +; %1=5bits weights?, %2=dst %3=src1 %4=src3 %5=stride if sse2 +%macro RV40_WCORE 4-5 + movh m4, [%3 + 0] + movh m5, [%4 + 0] +%if %0 == 4 +%define OFFSET mmsize / 2 +%else + ; 8x8 block and sse2, stride was provided +%define OFFSET %5 +%endif + movh m6, [%3 + OFFSET] + movh m7, [%4 + OFFSET] + +%if %1 == 0 + ; 14bits weights + punpcklbw m4, m0 + punpcklbw m5, m0 + punpcklbw m6, m0 + punpcklbw m7, m0 + + psllw m4, 7 + psllw m5, 7 + psllw m6, 7 + psllw m7, 7 + pmulhw m4, m3 + pmulhw m5, m2 + pmulhw m6, m3 + pmulhw m7, m2 + + paddw m4, m5 + paddw m6, m7 +%else + ; 5bits weights +%if cpuflag(ssse3) + punpcklbw m4, m5 + punpcklbw m6, m7 + + pmaddubsw m4, m3 + pmaddubsw m6, m3 +%else + punpcklbw m4, m0 + punpcklbw m5, m0 + punpcklbw m6, m0 + punpcklbw m7, m0 + + pmullw m4, m3 + pmullw m5, m2 + pmullw m6, m3 + pmullw m7, m2 + paddw m4, m5 + paddw m6, m7 +%endif + +%endif + + ; bias and shift down +%if cpuflag(ssse3) + pmulhrsw m4, m1 + pmulhrsw m6, m1 +%else + paddw m4, m1 + paddw m6, m1 + psrlw m4, 5 + psrlw m6, 5 +%endif + + packuswb m4, m6 +%if %0 == 5 + ; Only called for 8x8 blocks and sse2 + movh [%2 + 0], m4 + movhps [%2 + %5], m4 +%else + mova [%2], m4 +%endif +%endmacro + + +%macro MAIN_LOOP 2 +%if mmsize == 8 + RV40_WCORE %2, r0, r1, r2 +%if %1 == 16 + RV40_WCORE %2, r0 + 8, r1 + 8, r2 + 8 +%endif + + ; Prepare for next loop + add r0, r5 + add r1, r5 + add r2, r5 +%else +%ifidn %1, 8 + RV40_WCORE %2, r0, r1, r2, r5 + ; Prepare 2 next lines + lea r0, [r0 + 2 * r5] + lea r1, [r1 + 2 * r5] + lea r2, [r2 + 2 * r5] +%else + RV40_WCORE %2, r0, r1, r2 + ; Prepare single next line + add r0, r5 + add r1, r5 + add r2, r5 +%endif +%endif + + dec r6 +%endmacro + +; rv40_weight_func_%1(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w1, int w2, int stride) +; %1=size %2=num of xmm regs +%macro RV40_WEIGHT 2 +cglobal rv40_weight_func_%1, 6, 7, %2 +%if cpuflag(ssse3) + mova m1, [shift_round] +%else + mova m1, [pw_16] +%endif + pxor m0, m0 + mov r6, r3 + or r6, r4 + ; The weights are FP0.14 notation of fractions depending on pts. + ; For timebases without rounding error (i.e. PAL), the fractions + ; can be simplified, and several operations can be avoided. + ; Therefore, we check here whether they are multiples of 2^9 for + ; those simplifications to occur. + and r6, 0x1FF + ; Set loop counter and increments +%if mmsize == 8 + mov r6, %1 +%else + mov r6, (%1 * %1) / mmsize +%endif + + ; Use result of test now + jz .loop_512 + movd m2, r3 + movd m3, r4 + SPLATW m2, m2 + SPLATW m3, m3 + +.loop: + MAIN_LOOP %1, 0 + jnz .loop + REP_RET + + ; Weights are multiple of 512, which allows some shortcuts +.loop_512: + sar r3, 9 + sar r4, 9 + movd m2, r3 + movd m3, r4 +%if cpuflag(ssse3) + punpcklbw m3, m2 + SPLATW m3, m3 +%else + SPLATW m2, m2 + SPLATW m3, m3 +%endif +.loop2: + MAIN_LOOP %1, 1 + jnz .loop2 + REP_RET + +%endmacro + +INIT_MMX mmx +RV40_WEIGHT 8, 0 +RV40_WEIGHT 16, 0 + +INIT_XMM sse2 +RV40_WEIGHT 8, 8 +RV40_WEIGHT 16, 8 + +INIT_XMM ssse3 +RV40_WEIGHT 8, 8 +RV40_WEIGHT 16, 8 diff --git a/libavcodec/x86/rv40dsp_init.c b/libavcodec/x86/rv40dsp_init.c index b429de7293..3d6c6f0fa0 100644 --- a/libavcodec/x86/rv40dsp_init.c +++ b/libavcodec/x86/rv40dsp_init.c @@ -40,6 +40,15 @@ void ff_avg_rv40_chroma_mc4_mmx2 (uint8_t *dst, uint8_t *src, void ff_avg_rv40_chroma_mc4_3dnow(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y); +#define DECLARE_WEIGHT(opt) \ +void ff_rv40_weight_func_16_##opt(uint8_t *dst, uint8_t *src1, uint8_t *src2, \ + int w1, int w2, int stride); \ +void ff_rv40_weight_func_8_##opt (uint8_t *dst, uint8_t *src1, uint8_t *src2, \ + int w1, int w2, int stride); +DECLARE_WEIGHT(mmx) +DECLARE_WEIGHT(sse2) +DECLARE_WEIGHT(ssse3) + void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp) { #if HAVE_YASM @@ -48,6 +57,8 @@ void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp) if (mm_flags & AV_CPU_FLAG_MMX) { c->put_chroma_pixels_tab[0] = ff_put_rv40_chroma_mc8_mmx; c->put_chroma_pixels_tab[1] = ff_put_rv40_chroma_mc4_mmx; + c->rv40_weight_pixels_tab[0] = ff_rv40_weight_func_16_mmx; + c->rv40_weight_pixels_tab[1] = ff_rv40_weight_func_8_mmx; } if (mm_flags & AV_CPU_FLAG_MMX2) { c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_mmx2; @@ -56,5 +67,13 @@ void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp) c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_3dnow; c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_3dnow; } + if (mm_flags & AV_CPU_FLAG_SSE2) { + c->rv40_weight_pixels_tab[0] = ff_rv40_weight_func_16_sse2; + c->rv40_weight_pixels_tab[1] = ff_rv40_weight_func_8_sse2; + } + if (mm_flags & AV_CPU_FLAG_SSSE3) { + c->rv40_weight_pixels_tab[0] = ff_rv40_weight_func_16_ssse3; + c->rv40_weight_pixels_tab[1] = ff_rv40_weight_func_8_ssse3; + } #endif } From eac31dd163cd9168860aeed88112455cb44cc4f1 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 30 Jan 2012 14:29:05 -0500 Subject: [PATCH 06/29] mpc7: align local temp buffer DSPContext.bswap_buf() requires aligned output --- libavcodec/mpc7.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c index 290ecfb385..8bc085392b 100644 --- a/libavcodec/mpc7.c +++ b/libavcodec/mpc7.c @@ -53,7 +53,7 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx) int i, j; MPCContext *c = avctx->priv_data; GetBitContext gb; - uint8_t buf[16]; + LOCAL_ALIGNED_16(uint8_t, buf, [16]); static int vlc_initialized = 0; static VLC_TYPE scfi_table[1 << MPC7_SCFI_BITS][2]; From 3c4add27f7513f435e9daa03643fd992d5f6bcee Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 30 Jan 2012 14:33:01 -0500 Subject: [PATCH 07/29] mpc7: check for allocation failure --- libavcodec/mpc7.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c index 8bc085392b..6b6bffe357 100644 --- a/libavcodec/mpc7.c +++ b/libavcodec/mpc7.c @@ -224,6 +224,8 @@ static int mpc7_decode_frame(AVCodecContext * avctx, void *data, } bits = av_malloc(((buf_size - 1) & ~3) + FF_INPUT_BUFFER_PADDING_SIZE); + if (!bits) + return AVERROR(ENOMEM); c->dsp.bswap_buf((uint32_t*)bits, (const uint32_t*)(buf + 4), (buf_size - 4) >> 2); init_get_bits(&gb, bits, (buf_size - 4)* 8); skip_bits_long(&gb, buf[0]); From ddf70db6d71fdab15bf8626aea4301b85891c2bd Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 30 Jan 2012 12:57:34 -0500 Subject: [PATCH 08/29] adpcmenc: Do not set coded_frame->key_frame. It is already set in avcodec_alloc_frame(). --- libavcodec/adpcmenc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 9697f829d2..9cf1e39149 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -136,7 +136,6 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) } avctx->coded_frame = avcodec_alloc_frame(); - avctx->coded_frame->key_frame= 1; return 0; error: From cb023d9afe9da0a9d221b5eeddd2981c520b5978 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 30 Jan 2012 13:03:01 -0500 Subject: [PATCH 09/29] adpcmenc: check for coded_frame allocation failure --- libavcodec/adpcmenc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 9cf1e39149..26d673d4b5 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -135,7 +135,8 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) goto error; } - avctx->coded_frame = avcodec_alloc_frame(); + if (!(avctx->coded_frame = avcodec_alloc_frame())) + goto error; return 0; error: From 877a1d409c13887903cf6aa5d8ac01fd8091a3f2 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 30 Jan 2012 13:06:57 -0500 Subject: [PATCH 10/29] adpcmenc: return proper AVERROR codes instead of -1 --- libavcodec/adpcmenc.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 26d673d4b5..f0f8c1f528 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -63,12 +63,16 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) ADPCMEncodeContext *s = avctx->priv_data; uint8_t *extradata; int i; - if (avctx->channels > 2) - return -1; /* only stereo or mono =) */ + int ret = AVERROR(ENOMEM); + + if (avctx->channels > 2) { + av_log(avctx, AV_LOG_ERROR, "only stereo or mono is supported\n"); + return AVERROR(EINVAL); + } if (avctx->trellis && (unsigned)avctx->trellis > 16U) { av_log(avctx, AV_LOG_ERROR, "invalid trellis size\n"); - return -1; + return AVERROR(EINVAL); } if (avctx->trellis) { @@ -127,11 +131,13 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) avctx->sample_rate != 44100) { av_log(avctx, AV_LOG_ERROR, "Sample rate must be 11025, " "22050 or 44100\n"); + ret = AVERROR(EINVAL); goto error; } avctx->frame_size = 512 * (avctx->sample_rate / 11025); break; default: + ret = AVERROR(EINVAL); goto error; } @@ -144,7 +150,7 @@ error: av_freep(&s->node_buf); av_freep(&s->nodep_buf); av_freep(&s->trellis_hash); - return -1; + return ret; } static av_cold int adpcm_encode_close(AVCodecContext *avctx) @@ -688,10 +694,11 @@ static int adpcm_encode_frame(AVCodecContext *avctx, } break; default: - error: - return -1; + return AVERROR(EINVAL); } return dst - frame; +error: + return AVERROR(ENOMEM); } From dd88ae831a3e703ec48b28a3b28e96567eab605f Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 30 Jan 2012 13:15:18 -0500 Subject: [PATCH 11/29] adpcmenc: fix adpcm_ms extradata allocation Add FF_INPUT_BUFFER_PADDING_SIZE. If allocation fails, also free memory which was allocated previously in adpcm_encode_init(). --- libavcodec/adpcmenc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index f0f8c1f528..706c5048c7 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -110,10 +110,10 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; avctx->block_align = BLKSIZE; + if (!(avctx->extradata = av_malloc(32 + FF_INPUT_BUFFER_PADDING_SIZE))) + goto error; avctx->extradata_size = 32; - extradata = avctx->extradata = av_malloc(avctx->extradata_size); - if (!extradata) - return AVERROR(ENOMEM); + extradata = avctx->extradata; bytestream_put_le16(&extradata, avctx->frame_size); bytestream_put_le16(&extradata, 7); /* wNumCoef */ for (i = 0; i < 7; i++) { From 149f2058a4119d3130243b4e85b02c3a15bb9694 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 30 Jan 2012 13:33:05 -0500 Subject: [PATCH 12/29] adpcmenc: use int16_t and uint8_t instead of short and unsigned char. --- libavcodec/adpcm.h | 6 +++--- libavcodec/adpcmenc.c | 41 +++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/libavcodec/adpcm.h b/libavcodec/adpcm.h index aed5048d4a..3a054c0e84 100644 --- a/libavcodec/adpcm.h +++ b/libavcodec/adpcm.h @@ -30,14 +30,14 @@ typedef struct ADPCMChannelStatus { int predictor; - short int step_index; + int16_t step_index; int step; /* for encoding */ int prev_sample; /* MS version */ - short sample1; - short sample2; + int16_t sample1; + int16_t sample2; int coeff1; int coeff2; int idelta; diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 706c5048c7..cc72da5566 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -166,8 +166,8 @@ static av_cold int adpcm_encode_close(AVCodecContext *avctx) } -static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, - short sample) +static inline uint8_t adpcm_ima_compress_sample(ADPCMChannelStatus *c, + int16_t sample) { int delta = sample - c->prev_sample; int nibble = FFMIN(7, abs(delta) * 4 / @@ -179,8 +179,8 @@ static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, return nibble; } -static inline unsigned char adpcm_ima_qt_compress_sample(ADPCMChannelStatus *c, - short sample) +static inline uint8_t adpcm_ima_qt_compress_sample(ADPCMChannelStatus *c, + int16_t sample) { int delta = sample - c->prev_sample; int mask, step = ff_adpcm_step_table[c->step_index]; @@ -213,8 +213,8 @@ static inline unsigned char adpcm_ima_qt_compress_sample(ADPCMChannelStatus *c, return nibble; } -static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, - short sample) +static inline uint8_t adpcm_ms_compress_sample(ADPCMChannelStatus *c, + int16_t sample) { int predictor, nibble, bias; @@ -242,8 +242,8 @@ static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, return nibble; } -static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, - short sample) +static inline uint8_t adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, + int16_t sample) { int nibble, delta; @@ -264,8 +264,9 @@ static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, return nibble; } -static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples, - uint8_t *dst, ADPCMChannelStatus *c, int n) +static void adpcm_compress_trellis(AVCodecContext *avctx, + const int16_t *samples, uint8_t *dst, + ADPCMChannelStatus *c, int n) { //FIXME 6% faster if frontier is a compile-time constant ADPCMEncodeContext *s = avctx->priv_data; @@ -469,35 +470,35 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples, c->idelta = nodes[0]->step; } -static int adpcm_encode_frame(AVCodecContext *avctx, - unsigned char *frame, int buf_size, void *data) +static int adpcm_encode_frame(AVCodecContext *avctx, uint8_t *frame, + int buf_size, void *data) { int n, i, st; - short *samples; - unsigned char *dst; + int16_t *samples; + uint8_t *dst; ADPCMEncodeContext *c = avctx->priv_data; uint8_t *buf; dst = frame; - samples = (short *)data; + samples = data; st = avctx->channels == 2; /* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */ switch(avctx->codec->id) { case CODEC_ID_ADPCM_IMA_WAV: n = avctx->frame_size / 8; - c->status[0].prev_sample = (signed short)samples[0]; /* XXX */ + c->status[0].prev_sample = samples[0]; /* c->status[0].step_index = 0; XXX: not sure how to init the state machine */ bytestream_put_le16(&dst, c->status[0].prev_sample); - *dst++ = (unsigned char)c->status[0].step_index; + *dst++ = (uint8_t)c->status[0].step_index; *dst++ = 0; /* unknown */ samples++; if (avctx->channels == 2) { - c->status[1].prev_sample = (signed short)samples[0]; + c->status[1].prev_sample = samples[0]; /* c->status[1].step_index = 0; */ bytestream_put_le16(&dst, c->status[1].prev_sample); - *dst++ = (unsigned char)c->status[1].step_index; + *dst++ = (uint8_t)c->status[1].step_index; *dst++ = 0; samples++; } @@ -597,7 +598,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, c->status[i].step_index = av_clip(c->status[i].step_index, 0, 63); put_sbits(&pb, 16, samples[i]); put_bits(&pb, 6, c->status[i].step_index); - c->status[i].prev_sample = (signed short)samples[i]; + c->status[i].prev_sample = samples[i]; } if (avctx->trellis > 0) { From a3a0691bdecf0b2ead2d06ea06c0c278733eef91 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 30 Jan 2012 13:34:43 -0500 Subject: [PATCH 13/29] adpcmenc: remove some unneeded casts --- libavcodec/adpcmenc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index cc72da5566..a24238ccb8 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -230,12 +230,12 @@ static inline uint8_t adpcm_ms_compress_sample(ADPCMChannelStatus *c, nibble = (nibble + bias) / c->idelta; nibble = av_clip(nibble, -8, 7) & 0x0F; - predictor += (signed)((nibble & 0x08) ? (nibble - 0x10) : nibble) * c->idelta; + predictor += ((nibble & 0x08) ? (nibble - 0x10) : nibble) * c->idelta; c->sample2 = c->sample1; c->sample1 = av_clip_int16(predictor); - c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8; + c->idelta = (ff_adpcm_AdaptationTable[nibble] * c->idelta) >> 8; if (c->idelta < 16) c->idelta = 16; @@ -491,14 +491,14 @@ static int adpcm_encode_frame(AVCodecContext *avctx, uint8_t *frame, /* c->status[0].step_index = 0; XXX: not sure how to init the state machine */ bytestream_put_le16(&dst, c->status[0].prev_sample); - *dst++ = (uint8_t)c->status[0].step_index; + *dst++ = c->status[0].step_index; *dst++ = 0; /* unknown */ samples++; if (avctx->channels == 2) { c->status[1].prev_sample = samples[0]; /* c->status[1].step_index = 0; */ bytestream_put_le16(&dst, c->status[1].prev_sample); - *dst++ = (uint8_t)c->status[1].step_index; + *dst++ = c->status[1].step_index; *dst++ = 0; samples++; } From f372ce119bd2458fa0b4ddfb2af3a36621df99f7 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Wed, 25 Jan 2012 15:46:14 -0800 Subject: [PATCH 14/29] mp3dec: Fix a heap-buffer-overflow In some cases, what is left to read from ptr is smaller than EXTRABYTES. Based on a patch by Thierry Foucu . Signed-off-by: Alex Converse --- libavcodec/mpegaudiodec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 4ea5146ed6..af125d5587 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -1378,16 +1378,17 @@ static int mp_decode_layer3(MPADecodeContext *s) if (!s->adu_mode) { int skip; const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3); + int extrasize = av_clip(get_bits_left(&s->gb) >> 3, 0, EXTRABYTES); assert((get_bits_count(&s->gb) & 7) == 0); /* now we get bits from the main_data_begin offset */ av_dlog(s->avctx, "seekback: %d\n", main_data_begin); //av_log(NULL, AV_LOG_ERROR, "backstep:%d, lastbuf:%d\n", main_data_begin, s->last_buf_size); - memcpy(s->last_buf + s->last_buf_size, ptr, EXTRABYTES); + memcpy(s->last_buf + s->last_buf_size, ptr, extrasize); s->in_gb = s->gb; init_get_bits(&s->gb, s->last_buf, s->last_buf_size*8); #if !UNCHECKED_BITSTREAM_READER - s->gb.size_in_bits_plus8 += EXTRABYTES * 8; + s->gb.size_in_bits_plus8 += extrasize * 8; #endif s->last_buf_size <<= 3; for (gr = 0; gr < nb_granules && (s->last_buf_size >> 3) < main_data_begin; gr++) { From 183eaa9a2525de485fe2e0e9e39671665ffc6df2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 27 Jan 2012 12:29:37 +0100 Subject: [PATCH 15/29] lavf: reorder AVInput/OutputFormat fields. Put all private fields at the end and mark them as such so they can be easily changed/removed. This breaks ABI. --- libavformat/avformat.h | 110 +++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 49 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index a78c1e3b72..09b78a9f64 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -309,13 +309,39 @@ typedef struct AVOutputFormat { const char *long_name; const char *mime_type; const char *extensions; /**< comma-separated filename extensions */ + /* output support */ + enum CodecID audio_codec; /**< default audio codec */ + enum CodecID video_codec; /**< default video codec */ + enum CodecID subtitle_codec; /**< default subtitle codec */ + /** + * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE, + * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, + * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH + */ + int flags; + + /** + * List of supported codec_id-codec_tag pairs, ordered by "better + * choice first". The arrays are all terminated by CODEC_ID_NONE. + */ + const struct AVCodecTag * const *codec_tag; + + + const AVClass *priv_class; ///< AVClass for the private context + + /***************************************************************** + * No fields below this line are part of the public API. They + * may not be used outside of libavformat and can be changed and + * removed at will. + * New public fields should be added right above. + ***************************************************************** + */ + struct AVOutputFormat *next; /** * size of private data so that it can be allocated in the wrapper */ int priv_data_size; - /* output support */ - enum CodecID audio_codec; /**< default audio codec */ - enum CodecID video_codec; /**< default video codec */ + int (*write_header)(struct AVFormatContext *); /** * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags, @@ -326,28 +352,11 @@ typedef struct AVOutputFormat { */ int (*write_packet)(struct AVFormatContext *, AVPacket *pkt); int (*write_trailer)(struct AVFormatContext *); - /** - * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE, - * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, - * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH - */ - int flags; /** * Currently only used to set pixel format if not YUV420P. */ int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush); - - /** - * List of supported codec_id-codec_tag pairs, ordered by "better - * choice first". The arrays are all terminated by CODEC_ID_NONE. - */ - const struct AVCodecTag * const *codec_tag; - - enum CodecID subtitle_codec; /**< default subtitle codec */ - - const AVClass *priv_class; ///< AVClass for the private context - /** * Test if the given codec can be stored in this container. * @@ -355,9 +364,6 @@ typedef struct AVOutputFormat { * A negative number if unknown. */ int (*query_codec)(enum CodecID id, int std_compliance); - - /* private fields */ - struct AVOutputFormat *next; } AVOutputFormat; /** * @} @@ -381,6 +387,38 @@ typedef struct AVInputFormat { */ const char *long_name; + /** + * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, + * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH, + * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK. + */ + int flags; + + /** + * If extensions are defined, then no probe is done. You should + * usually not use extension format guessing because it is not + * reliable enough + */ + const char *extensions; + + const struct AVCodecTag * const *codec_tag; + + const AVClass *priv_class; ///< AVClass for the private context + + /***************************************************************** + * No fields below this line are part of the public API. They + * may not be used outside of libavformat and can be changed and + * removed at will. + * New public fields should be added right above. + ***************************************************************** + */ + struct AVInputFormat *next; + + /** + * General purpose read-only value that the format can use. + */ + int value; + /** * Size of private data so that it can be allocated in the wrapper. */ @@ -436,25 +474,6 @@ typedef struct AVInputFormat { int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index, int64_t *pos, int64_t pos_limit); - /** - * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, - * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH, - * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK. - */ - int flags; - - /** - * If extensions are defined, then no probe is done. You should - * usually not use extension format guessing because it is not - * reliable enough - */ - const char *extensions; - - /** - * General purpose read-only value that the format can use. - */ - int value; - /** * Start/resume playing - only meaningful if using a network-based format * (RTSP). @@ -467,8 +486,6 @@ typedef struct AVInputFormat { */ int (*read_pause)(struct AVFormatContext *); - const struct AVCodecTag * const *codec_tag; - /** * Seek to timestamp ts. * Seeking will be done so that the point from which all active streams @@ -476,11 +493,6 @@ typedef struct AVInputFormat { * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL. */ int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags); - - const AVClass *priv_class; ///< AVClass for the private context - - /* private fields */ - struct AVInputFormat *next; } AVInputFormat; /** * @} From f5f49a66a2b061f8d99e0b1e175d2f12e9d42cba Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 27 Jan 2012 12:29:37 +0100 Subject: [PATCH 16/29] lavc: reorder AVCodec fields. Put all private fields at the end and mark them as such so they can be easily changed/removed. This breaks ABI. --- libavcodec/avcodec.h | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index d8e56caeac..a6bb6863f2 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2780,31 +2780,20 @@ typedef struct AVCodec { * This is the primary way to find a codec from the user perspective. */ const char *name; + /** + * Descriptive name for the codec, meant to be more human readable than name. + * You should use the NULL_IF_CONFIG_SMALL() macro to define it. + */ + const char *long_name; enum AVMediaType type; enum CodecID id; - int priv_data_size; - int (*init)(AVCodecContext *); - int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data); - int (*close)(AVCodecContext *); - int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt); /** * Codec capabilities. * see CODEC_CAP_* */ int capabilities; - struct AVCodec *next; - /** - * Flush buffers. - * Will be called when seeking - */ - void (*flush)(AVCodecContext *); const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0} const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1 - /** - * Descriptive name for the codec, meant to be more human readable than name. - * You should use the NULL_IF_CONFIG_SMALL() macro to define it. - */ - const char *long_name; const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0 const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1 const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0 @@ -2812,6 +2801,15 @@ typedef struct AVCodec { const AVClass *priv_class; ///< AVClass for the private context const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} + /***************************************************************** + * No fields below this line are part of the public API. They + * may not be used outside of libavcodec and can be changed and + * removed at will. + * New public fields should be added right above. + ***************************************************************** + */ + int priv_data_size; + struct AVCodec *next; /** * @name Frame-level threading support functions * @{ @@ -2842,6 +2840,8 @@ typedef struct AVCodec { */ void (*init_static_data)(struct AVCodec *codec); + int (*init)(AVCodecContext *); + int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data); /** * Encode data to an AVPacket. * @@ -2854,6 +2854,13 @@ typedef struct AVCodec { */ int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr); + int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt); + int (*close)(AVCodecContext *); + /** + * Flush buffers. + * Will be called when seeking + */ + void (*flush)(AVCodecContext *); } AVCodec; /** From afa4069e3ba373ed958f5fd392c184b084287b46 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 29 Jan 2012 12:22:49 +0100 Subject: [PATCH 17/29] lavc/lavf: remove unnecessary symbols from the symbol version script. --- libavcodec/libavcodec.v | 2 -- libavformat/libavformat.v | 25 ------------------------- 2 files changed, 27 deletions(-) diff --git a/libavcodec/libavcodec.v b/libavcodec/libavcodec.v index a9e7674e13..0e1c2e1cda 100644 --- a/libavcodec/libavcodec.v +++ b/libavcodec/libavcodec.v @@ -2,7 +2,5 @@ LIBAVCODEC_$MAJOR { global: av*; audio_resample; audio_resample_close; - #deprecated, remove after next bump - img_get_alpha_info; local: *; }; diff --git a/libavformat/libavformat.v b/libavformat/libavformat.v index c5dc982878..6f11d600b9 100644 --- a/libavformat/libavformat.v +++ b/libavformat/libavformat.v @@ -1,29 +1,4 @@ LIBAVFORMAT_$MAJOR { global: av*; - #FIXME those are for avserver - ff_inet_aton; - ff_socket_nonblock; - ffm_set_write_index; - ffm_read_write_index; - ffm_write_write_index; - ff_rtsp_parse_line; - ff_rtp_get_local_rtp_port; - ff_rtp_get_local_rtcp_port; - ffio_open_dyn_packet_buf; - url_open; - url_close; - url_write; - url_get_max_packet_size; - #those are deprecated, remove on next bump - find_info_tag; - parse_date; - dump_format; - url_*; - get_*; - put_*; - udp_set_remote_url; - udp_get_local_port; - init_checksum; - init_put_byte; local: *; }; From 9a463917d30147a9728a7b19b03c217527e09046 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 31 Jan 2012 07:46:18 +0100 Subject: [PATCH 18/29] lavf: remove the pointless value field from flv and iv8 The demuxers don't use it in any way. --- libavformat/flvdec.c | 1 - libavformat/iv8.c | 1 - 2 files changed, 2 deletions(-) diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index ad38653d76..1e1c29b391 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -672,5 +672,4 @@ AVInputFormat ff_flv_demuxer = { #endif .read_close = flv_read_close, .extensions = "flv", - .value = CODEC_ID_FLV1, }; diff --git a/libavformat/iv8.c b/libavformat/iv8.c index 903de6f8a4..e597911a97 100644 --- a/libavformat/iv8.c +++ b/libavformat/iv8.c @@ -115,5 +115,4 @@ AVInputFormat ff_iv8_demuxer = { .read_header = read_header, .read_packet = read_packet, .flags= AVFMT_GENERIC_INDEX, - .value = CODEC_ID_MPEG4, }; From f7fe41a04f962707a99597d2ea49d73ca90b23a0 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 31 Jan 2012 07:50:31 +0100 Subject: [PATCH 19/29] lavf: rename AVInputFormat.value to raw_codec_id. It's only used by raw demuxers for storing the codec id. --- libavformat/aacdec.c | 4 ++-- libavformat/ac3dec.c | 4 ++-- libavformat/adxdec.c | 4 ++-- libavformat/avformat.h | 4 ++-- libavformat/dtsdec.c | 2 +- libavformat/flacdec.c | 2 +- libavformat/gsmdec.c | 4 ++-- libavformat/ingenientdec.c | 2 +- libavformat/pcmdec.c | 2 +- libavformat/rawdec.c | 16 ++++++++-------- libavformat/rawdec.h | 2 +- libavformat/rawvideodec.c | 2 +- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c index df94d15831..992376ed38 100644 --- a/libavformat/aacdec.c +++ b/libavformat/aacdec.c @@ -70,7 +70,7 @@ static int adts_aac_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->value; + st->codec->codec_id = s->iformat->raw_codec_id; st->need_parsing = AVSTREAM_PARSE_FULL; ff_id3v1_read(s); @@ -89,5 +89,5 @@ AVInputFormat ff_aac_demuxer = { .read_packet = ff_raw_read_partial_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "aac", - .value = CODEC_ID_AAC, + .raw_codec_id = CODEC_ID_AAC, }; diff --git a/libavformat/ac3dec.c b/libavformat/ac3dec.c index ca6aee3685..4078b1b6bc 100644 --- a/libavformat/ac3dec.c +++ b/libavformat/ac3dec.c @@ -78,7 +78,7 @@ AVInputFormat ff_ac3_demuxer = { .read_packet = ff_raw_read_partial_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "ac3", - .value = CODEC_ID_AC3, + .raw_codec_id = CODEC_ID_AC3, }; #endif @@ -96,6 +96,6 @@ AVInputFormat ff_eac3_demuxer = { .read_packet = ff_raw_read_partial_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "eac3", - .value = CODEC_ID_EAC3, + .raw_codec_id = CODEC_ID_EAC3, }; #endif diff --git a/libavformat/adxdec.c b/libavformat/adxdec.c index 243160940c..305c67431b 100644 --- a/libavformat/adxdec.c +++ b/libavformat/adxdec.c @@ -94,7 +94,7 @@ static int adx_read_header(AVFormatContext *s) return ret; st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->value; + st->codec->codec_id = s->iformat->raw_codec_id; avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, avctx->sample_rate); @@ -108,6 +108,6 @@ AVInputFormat ff_adx_demuxer = { .read_header = adx_read_header, .read_packet = adx_read_packet, .extensions = "adx", - .value = CODEC_ID_ADPCM_ADX, + .raw_codec_id = CODEC_ID_ADPCM_ADX, .flags = AVFMT_GENERIC_INDEX, }; diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 09b78a9f64..217d8139df 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -415,9 +415,9 @@ typedef struct AVInputFormat { struct AVInputFormat *next; /** - * General purpose read-only value that the format can use. + * Raw demuxers store their codec ID here. */ - int value; + int raw_codec_id; /** * Size of private data so that it can be allocated in the wrapper. diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c index d61855d360..95bae54519 100644 --- a/libavformat/dtsdec.c +++ b/libavformat/dtsdec.c @@ -73,5 +73,5 @@ AVInputFormat ff_dts_demuxer = { .read_packet = ff_raw_read_partial_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "dts", - .value = CODEC_ID_DTS, + .raw_codec_id = CODEC_ID_DTS, }; diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index d127dc209f..7174fcf758 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -157,5 +157,5 @@ AVInputFormat ff_flac_demuxer = { .read_packet = ff_raw_read_partial_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "flac", - .value = CODEC_ID_FLAC, + .raw_codec_id = CODEC_ID_FLAC, }; diff --git a/libavformat/gsmdec.c b/libavformat/gsmdec.c index 5d6495860a..3525a038c7 100644 --- a/libavformat/gsmdec.c +++ b/libavformat/gsmdec.c @@ -62,7 +62,7 @@ static int gsm_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->value; + st->codec->codec_id = s->iformat->raw_codec_id; st->codec->channels = 1; st->codec->sample_rate = c->sample_rate; st->codec->bit_rate = GSM_BLOCK_SIZE * 8 * c->sample_rate / GSM_BLOCK_SAMPLES; @@ -94,6 +94,6 @@ AVInputFormat ff_gsm_demuxer = { .read_packet = gsm_read_packet, .flags = AVFMT_GENERIC_INDEX, .extensions = "gsm", - .value = CODEC_ID_GSM, + .raw_codec_id = CODEC_ID_GSM, .priv_class = &class, }; diff --git a/libavformat/ingenientdec.c b/libavformat/ingenientdec.c index 35ac649695..bed525fad6 100644 --- a/libavformat/ingenientdec.c +++ b/libavformat/ingenientdec.c @@ -68,6 +68,6 @@ AVInputFormat ff_ingenient_demuxer = { .read_packet = ingenient_read_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "cgi", // FIXME - .value = CODEC_ID_MJPEG, + .raw_codec_id = CODEC_ID_MJPEG, .priv_class = &ingenient_demuxer_class, }; diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c index b61fb33764..1e36cc4e76 100644 --- a/libavformat/pcmdec.c +++ b/libavformat/pcmdec.c @@ -70,7 +70,7 @@ AVInputFormat ff_pcm_ ## name_ ## _demuxer = { \ .read_seek = pcm_read_seek, \ .flags = AVFMT_GENERIC_INDEX, \ .extensions = ext, \ - .value = codec, \ + .raw_codec_id = codec, \ .priv_class = &name_ ## _demuxer_class, \ }; diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 9400a0bd32..73b3709ac1 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -38,7 +38,7 @@ int ff_raw_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - id = s->iformat->value; + id = s->iformat->raw_codec_id; if (id == CODEC_ID_RAWVIDEO) { st->codec->codec_type = AVMEDIA_TYPE_VIDEO; } else { @@ -126,7 +126,7 @@ int ff_raw_audio_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->value; + st->codec->codec_id = s->iformat->raw_codec_id; st->need_parsing = AVSTREAM_PARSE_FULL; st->start_time = 0; /* the parameters will be extracted from the compressed bitstream */ @@ -150,7 +150,7 @@ int ff_raw_video_read_header(AVFormatContext *s) } st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = s->iformat->value; + st->codec->codec_id = s->iformat->raw_codec_id; st->need_parsing = AVSTREAM_PARSE_FULL; if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) { @@ -182,7 +182,7 @@ AVInputFormat ff_g722_demuxer = { .read_packet = ff_raw_read_partial_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "g722,722", - .value = CODEC_ID_ADPCM_G722, + .raw_codec_id = CODEC_ID_ADPCM_G722, }; #endif @@ -194,7 +194,7 @@ AVInputFormat ff_latm_demuxer = { .read_packet = ff_raw_read_partial_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "latm", - .value = CODEC_ID_AAC_LATM, + .raw_codec_id = CODEC_ID_AAC_LATM, }; #endif @@ -210,7 +210,7 @@ AVInputFormat ff_mlp_demuxer = { .read_packet = ff_raw_read_partial_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "mlp", - .value = CODEC_ID_MLP, + .raw_codec_id = CODEC_ID_MLP, }; #endif @@ -222,7 +222,7 @@ AVInputFormat ff_truehd_demuxer = { .read_packet = ff_raw_read_partial_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "thd", - .value = CODEC_ID_TRUEHD, + .raw_codec_id = CODEC_ID_TRUEHD, }; #endif @@ -234,7 +234,7 @@ AVInputFormat ff_shorten_demuxer = { .read_packet = ff_raw_read_partial_packet, .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, .extensions = "shn", - .value = CODEC_ID_SHORTEN, + .raw_codec_id = CODEC_ID_SHORTEN, }; #endif diff --git a/libavformat/rawdec.h b/libavformat/rawdec.h index cfb1689cd9..4cce2cf901 100644 --- a/libavformat/rawdec.h +++ b/libavformat/rawdec.h @@ -67,7 +67,7 @@ AVInputFormat ff_ ## shortname ## _demuxer = {\ .read_packet = ff_raw_read_partial_packet,\ .extensions = ext,\ .flags = AVFMT_GENERIC_INDEX,\ - .value = id,\ + .raw_codec_id = id,\ .priv_data_size = sizeof(FFRawVideoDemuxerContext),\ .priv_class = &shortname ## _demuxer_class,\ }; diff --git a/libavformat/rawvideodec.c b/libavformat/rawvideodec.c index 6ca17d5253..5db4e91f2e 100644 --- a/libavformat/rawvideodec.c +++ b/libavformat/rawvideodec.c @@ -68,6 +68,6 @@ AVInputFormat ff_rawvideo_demuxer = { .read_packet = rawvideo_read_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "yuv,cif,qcif,rgb", - .value = CODEC_ID_RAWVIDEO, + .raw_codec_id = CODEC_ID_RAWVIDEO, .priv_class = &rawvideo_demuxer_class, }; From af08d9aeea870de017139f7b1c44b7d816cf8e56 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 8 Dec 2011 06:57:44 +0100 Subject: [PATCH 20/29] lavc: add avcodec_is_open(). It allows to check whether an AVCodecContext is open in a documented way. Right now the undocumented way this check is done in lavf/lavc is by checking whether AVCodecContext.codec is NULL. However it's desirable to be able to set AVCodecContext.codec before avcodec_open2(). --- doc/APIchanges | 3 +++ libavcodec/avcodec.h | 6 ++++++ libavcodec/options.c | 2 +- libavcodec/utils.c | 8 ++++++++ libavformat/utils.c | 5 ++--- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 7545fa51dc..87de464ebb 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2012-01-31 - xxxxxxx - lavc 54.01.0 + Add avcodec_is_open() function. + 2012-01-30 - xxxxxxx - lavu 51.22.0 - intfloat.h Add a new installed header libavutil/intfloat.h with int/float punning functions. diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index a6bb6863f2..284c7f8cb8 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -4183,4 +4183,10 @@ enum AVMediaType avcodec_get_type(enum CodecID codec_id); */ const AVClass *avcodec_get_class(void); +/** + * @return a positive value if s is open (i.e. avcodec_open2() was called on it + * with no corresponding avcodec_close()), 0 otherwise. + */ +int avcodec_is_open(AVCodecContext *s); + #endif /* AVCODEC_AVCODEC_H */ diff --git a/libavcodec/options.c b/libavcodec/options.c index c416b4aa4f..52fc66400a 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -485,7 +485,7 @@ AVCodecContext *avcodec_alloc_context3(AVCodec *codec){ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) { - if (dest->codec) { // check that the dest context is uninitialized + if (avcodec_is_open(dest)) { // check that the dest context is uninitialized av_log(dest, AV_LOG_ERROR, "Tried to copy AVCodecContext %p into already-initialized %p\n", src, dest); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 34a4122d5d..3ee6b09f74 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -627,6 +627,9 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD int ret = 0; AVDictionary *tmp = NULL; + if (avcodec_is_open(avctx)) + return 0; + if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) return AVERROR(EINVAL); @@ -1803,3 +1806,8 @@ enum AVMediaType avcodec_get_type(enum CodecID codec_id) return AVMEDIA_TYPE_UNKNOWN; } + +int avcodec_is_open(AVCodecContext *s) +{ + return !!s->internal; +} diff --git a/libavformat/utils.c b/libavformat/utils.c index 9c59947fb7..1b2239a068 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2006,7 +2006,7 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **option AVFrame picture; AVPacket pkt = *avpkt; - if(!st->codec->codec){ + if (!avcodec_is_open(st->codec)) { AVDictionary *thread_opt = NULL; codec = avcodec_find_decoder(st->codec->codec_id); @@ -2354,8 +2354,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) // close codecs which were opened in try_decode_frame() for(i=0;inb_streams;i++) { st = ic->streams[i]; - if(st->codec->codec) - avcodec_close(st->codec); + avcodec_close(st->codec); } for(i=0;inb_streams;i++) { st = ic->streams[i]; From 0e72ad95f9fef6a6b8ae55e47339a5c40526502f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 29 Jan 2012 12:17:30 +0100 Subject: [PATCH 21/29] lavc: make avcodec_close() work properly on unopened codecs. I.e. free the priv_data and other stuff allocated in avcodec_alloc_context3() and not segfault. --- libavcodec/avcodec.h | 12 +++++++++++- libavcodec/utils.c | 19 +++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 284c7f8cb8..77abec59f6 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3417,7 +3417,8 @@ int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec); /** * Allocate an AVCodecContext and set its fields to default values. The - * resulting struct can be deallocated by simply calling av_free(). + * resulting struct can be deallocated by calling avcodec_close() on it followed + * by av_free(). * * @param codec if non-NULL, allocate private data and initialize defaults * for the given codec. It is illegal to then call avcodec_open2() @@ -3809,6 +3810,15 @@ int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub); +/** + * Close a given AVCodecContext and free all the data associated with it + * (but not the AVCodecContext itself). + * + * Calling this function on an AVCodecContext that hasn't been opened will free + * the codec-specific data allocated in avcodec_alloc_context3() / + * avcodec_get_context_defaults3() with a non-NULL codec. Subsequent calls will + * do nothing. + */ int avcodec_close(AVCodecContext *avctx); /** diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 3ee6b09f74..9cdae22305 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1267,14 +1267,17 @@ av_cold int avcodec_close(AVCodecContext *avctx) return -1; } - if (HAVE_THREADS && avctx->thread_opaque) - ff_thread_free(avctx); - if (avctx->codec && avctx->codec->close) - avctx->codec->close(avctx); - avcodec_default_free_buffers(avctx); - avctx->coded_frame = NULL; - av_freep(&avctx->internal); - if (avctx->codec && avctx->codec->priv_class) + if (avcodec_is_open(avctx)) { + if (HAVE_THREADS && avctx->thread_opaque) + ff_thread_free(avctx); + if (avctx->codec && avctx->codec->close) + avctx->codec->close(avctx); + avcodec_default_free_buffers(avctx); + avctx->coded_frame = NULL; + av_freep(&avctx->internal); + } + + if (avctx->priv_data && avctx->codec && avctx->codec->priv_class) av_opt_free(avctx->priv_data); av_opt_free(avctx); av_freep(&avctx->priv_data); From bc901998487bf9b77a423961d9f961bcc28a9291 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 28 Jan 2012 19:15:15 +0100 Subject: [PATCH 22/29] lavc: set AVCodecContext.codec in avcodec_get_context_defaults3(). This way, if the AVCodecContext is allocated for a specific codec, the caller doesn't need to store this codec separately and then pass it again to avcodec_open2(). It also allows to set codec private options using av_opt_set_* before opening the codec. --- libavcodec/avcodec.h | 5 +++++ libavcodec/options.c | 1 + libavcodec/utils.c | 17 ++++++++++++----- libavformat/utils.c | 8 +++++--- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 77abec59f6..85bb59909b 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3525,6 +3525,11 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, * @endcode * * @param avctx The context to initialize. + * @param codec The codec to open this context for. If a non-NULL codec has been + * previously passed to avcodec_alloc_context3() or + * avcodec_get_context_defaults3() for this context, then this + * parameter MUST be either NULL or equal to the previously passed + * codec. * @param options A dictionary filled with AVCodecContext and codec-private options. * On return this object will be filled with options that were not found. * diff --git a/libavcodec/options.c b/libavcodec/options.c index 52fc66400a..eb803756fc 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -432,6 +432,7 @@ int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){ s->av_class = &av_codec_context_class; s->codec_type = codec ? codec->type : AVMEDIA_TYPE_UNKNOWN; + s->codec = codec; av_opt_set_defaults(s); s->time_base = (AVRational){0,1}; diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 9cdae22305..fa609534a5 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -630,6 +630,18 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD if (avcodec_is_open(avctx)) return 0; + if ((!codec && !avctx->codec)) { + av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2().\n"); + return AVERROR(EINVAL); + } + if ((codec && avctx->codec && codec != avctx->codec)) { + av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, " + "but %s passed to avcodec_open2().\n", avctx->codec->name, codec->name); + return AVERROR(EINVAL); + } + if (!codec) + codec = avctx->codec; + if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) return AVERROR(EINVAL); @@ -649,11 +661,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD goto end; } - if(avctx->codec || !codec) { - ret = AVERROR(EINVAL); - goto end; - } - avctx->internal = av_mallocz(sizeof(AVCodecInternal)); if (!avctx->internal) { ret = AVERROR(ENOMEM); diff --git a/libavformat/utils.c b/libavformat/utils.c index 1b2239a068..cf7180b3cf 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2009,7 +2009,9 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **option if (!avcodec_is_open(st->codec)) { AVDictionary *thread_opt = NULL; - codec = avcodec_find_decoder(st->codec->codec_id); + codec = st->codec->codec ? st->codec->codec : + avcodec_find_decoder(st->codec->codec_id); + if (!codec) return -1; @@ -2169,8 +2171,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; } } - assert(!st->codec->codec); - codec = avcodec_find_decoder(st->codec->codec_id); + codec = st->codec->codec ? st->codec->codec : + avcodec_find_decoder(st->codec->codec_id); /* force thread count to 1 since the h264 decoder will not extract SPS * and PPS to extradata during multi-threaded decoding */ From dd6d3b0e025cb2a16022665dbb8ab1be18dc05e8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 27 Jan 2012 13:33:09 +0100 Subject: [PATCH 23/29] lavf: add functions for accessing the fourcc<->CodecID mapping tables. Fixes bug 212. --- doc/APIchanges | 3 +++ libavformat/Makefile | 54 +++++++++++++++++++++--------------------- libavformat/avformat.h | 24 +++++++++++++++++++ libavformat/utils.c | 9 +++++++ 4 files changed, 63 insertions(+), 27 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 87de464ebb..0d4cb596a7 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2012-01-31 - xxxxxxx - lavf 54.01.0 + Add avformat_get_riff_video_tags() and avformat_get_riff_audio_tags(). + 2012-01-31 - xxxxxxx - lavc 54.01.0 Add avcodec_is_open() function. diff --git a/libavformat/Makefile b/libavformat/Makefile index 45f757690d..06718d2485 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -10,6 +10,7 @@ OBJS = allformats.o \ metadata.o \ options.o \ os_support.o \ + riff.o \ sdp.o \ seek.o \ utils.o \ @@ -25,8 +26,8 @@ OBJS-$(CONFIG_ADX_DEMUXER) += adxdec.o OBJS-$(CONFIG_ADX_MUXER) += rawenc.o OBJS-$(CONFIG_ADTS_MUXER) += adtsenc.o OBJS-$(CONFIG_AEA_DEMUXER) += aea.o pcm.o -OBJS-$(CONFIG_AIFF_DEMUXER) += aiffdec.o riff.o pcm.o -OBJS-$(CONFIG_AIFF_MUXER) += aiffenc.o riff.o +OBJS-$(CONFIG_AIFF_DEMUXER) += aiffdec.o pcm.o +OBJS-$(CONFIG_AIFF_MUXER) += aiffenc.o OBJS-$(CONFIG_AMR_DEMUXER) += amr.o OBJS-$(CONFIG_AMR_MUXER) += amr.o OBJS-$(CONFIG_ANM_DEMUXER) += anm.o @@ -34,14 +35,14 @@ OBJS-$(CONFIG_APC_DEMUXER) += apc.o OBJS-$(CONFIG_APE_DEMUXER) += ape.o apetag.o OBJS-$(CONFIG_APPLEHTTP_DEMUXER) += applehttp.o OBJS-$(CONFIG_ASF_DEMUXER) += asfdec.o asf.o asfcrypt.o \ - riff.o avlanguage.o -OBJS-$(CONFIG_ASF_MUXER) += asfenc.o asf.o riff.o + avlanguage.o +OBJS-$(CONFIG_ASF_MUXER) += asfenc.o asf.o OBJS-$(CONFIG_ASS_DEMUXER) += assdec.o OBJS-$(CONFIG_ASS_MUXER) += assenc.o OBJS-$(CONFIG_AU_DEMUXER) += au.o pcm.o OBJS-$(CONFIG_AU_MUXER) += au.o -OBJS-$(CONFIG_AVI_DEMUXER) += avidec.o riff.o -OBJS-$(CONFIG_AVI_MUXER) += avienc.o riff.o +OBJS-$(CONFIG_AVI_DEMUXER) += avidec.o +OBJS-$(CONFIG_AVI_MUXER) += avienc.o OBJS-$(CONFIG_AVISYNTH) += avisynth.o OBJS-$(CONFIG_AVM2_MUXER) += swfenc.o OBJS-$(CONFIG_AVS_DEMUXER) += avs.o vocdec.o voc.o @@ -51,7 +52,7 @@ OBJS-$(CONFIG_BINK_DEMUXER) += bink.o OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o mov_chan.o \ - riff.o isom.o + isom.o OBJS-$(CONFIG_CAVSVIDEO_DEMUXER) += cavsvideodec.o rawdec.o OBJS-$(CONFIG_CAVSVIDEO_MUXER) += rawenc.o OBJS-$(CONFIG_CDG_DEMUXER) += cdg.o @@ -68,7 +69,7 @@ OBJS-$(CONFIG_DTS_DEMUXER) += dtsdec.o rawdec.o OBJS-$(CONFIG_DTS_MUXER) += rawenc.o OBJS-$(CONFIG_DV_DEMUXER) += dv.o OBJS-$(CONFIG_DV_MUXER) += dvenc.o -OBJS-$(CONFIG_DXA_DEMUXER) += dxa.o riff.o +OBJS-$(CONFIG_DXA_DEMUXER) += dxa.o OBJS-$(CONFIG_EA_CDATA_DEMUXER) += eacdata.o OBJS-$(CONFIG_EA_DEMUXER) += electronicarts.o OBJS-$(CONFIG_EAC3_DEMUXER) += ac3dec.o rawdec.o @@ -112,7 +113,7 @@ OBJS-$(CONFIG_INGENIENT_DEMUXER) += ingenientdec.o rawdec.o OBJS-$(CONFIG_IPMOVIE_DEMUXER) += ipmovie.o OBJS-$(CONFIG_ISS_DEMUXER) += iss.o OBJS-$(CONFIG_IV8_DEMUXER) += iv8.o -OBJS-$(CONFIG_IVF_DEMUXER) += ivfdec.o riff.o +OBJS-$(CONFIG_IVF_DEMUXER) += ivfdec.o OBJS-$(CONFIG_IVF_MUXER) += ivfenc.o OBJS-$(CONFIG_JV_DEMUXER) += jvdec.o OBJS-$(CONFIG_LATM_DEMUXER) += rawdec.o @@ -122,9 +123,9 @@ OBJS-$(CONFIG_LXF_DEMUXER) += lxfdec.o OBJS-$(CONFIG_M4V_DEMUXER) += m4vdec.o rawdec.o OBJS-$(CONFIG_M4V_MUXER) += rawenc.o OBJS-$(CONFIG_MATROSKA_DEMUXER) += matroskadec.o matroska.o \ - riff.o isom.o rmdec.o rm.o + isom.o rmdec.o rm.o OBJS-$(CONFIG_MATROSKA_MUXER) += matroskaenc.o matroska.o \ - riff.o isom.o avc.o \ + isom.o avc.o \ flacenc_header.o avlanguage.o OBJS-$(CONFIG_MD5_MUXER) += md5enc.o OBJS-$(CONFIG_MJPEG_DEMUXER) += rawdec.o @@ -133,9 +134,9 @@ OBJS-$(CONFIG_MLP_DEMUXER) += rawdec.o OBJS-$(CONFIG_MLP_MUXER) += rawenc.o OBJS-$(CONFIG_MM_DEMUXER) += mm.o OBJS-$(CONFIG_MMF_DEMUXER) += mmf.o pcm.o -OBJS-$(CONFIG_MMF_MUXER) += mmf.o riff.o -OBJS-$(CONFIG_MOV_DEMUXER) += mov.o riff.o isom.o mov_chan.o -OBJS-$(CONFIG_MOV_MUXER) += movenc.o riff.o isom.o avc.o \ +OBJS-$(CONFIG_MMF_MUXER) += mmf.o +OBJS-$(CONFIG_MOV_DEMUXER) += mov.o isom.o mov_chan.o +OBJS-$(CONFIG_MOV_MUXER) += movenc.o isom.o avc.o \ movenchint.o rtpenc_chain.o \ mov_chan.o OBJS-$(CONFIG_MP2_MUXER) += mp3enc.o rawenc.o @@ -164,9 +165,9 @@ OBJS-$(CONFIG_MXG_DEMUXER) += mxg.o OBJS-$(CONFIG_NC_DEMUXER) += ncdec.o OBJS-$(CONFIG_NSV_DEMUXER) += nsvdec.o OBJS-$(CONFIG_NULL_MUXER) += nullenc.o -OBJS-$(CONFIG_NUT_DEMUXER) += nutdec.o nut.o riff.o -OBJS-$(CONFIG_NUT_MUXER) += nutenc.o nut.o riff.o -OBJS-$(CONFIG_NUV_DEMUXER) += nuv.o riff.o +OBJS-$(CONFIG_NUT_DEMUXER) += nutdec.o nut.o +OBJS-$(CONFIG_NUT_MUXER) += nutenc.o nut.o +OBJS-$(CONFIG_NUV_DEMUXER) += nuv.o OBJS-$(CONFIG_OGG_DEMUXER) += oggdec.o \ oggparsecelt.o \ oggparsedirac.o \ @@ -176,7 +177,6 @@ OBJS-$(CONFIG_OGG_DEMUXER) += oggdec.o \ oggparsespeex.o \ oggparsetheora.o \ oggparsevorbis.o \ - riff.o \ vorbiscomment.o OBJS-$(CONFIG_OGG_MUXER) += oggenc.o \ vorbiscomment.o @@ -301,28 +301,28 @@ OBJS-$(CONFIG_VMD_DEMUXER) += sierravmd.o OBJS-$(CONFIG_VOC_DEMUXER) += vocdec.o voc.o OBJS-$(CONFIG_VOC_MUXER) += vocenc.o voc.o OBJS-$(CONFIG_VQF_DEMUXER) += vqf.o -OBJS-$(CONFIG_W64_DEMUXER) += wav.o riff.o pcm.o -OBJS-$(CONFIG_WAV_DEMUXER) += wav.o riff.o pcm.o -OBJS-$(CONFIG_WAV_MUXER) += wav.o riff.o +OBJS-$(CONFIG_W64_DEMUXER) += wav.o pcm.o +OBJS-$(CONFIG_WAV_DEMUXER) += wav.o pcm.o +OBJS-$(CONFIG_WAV_MUXER) += wav.o OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o OBJS-$(CONFIG_WEBM_MUXER) += matroskaenc.o matroska.o \ - riff.o isom.o avc.o \ + isom.o avc.o \ flacenc_header.o avlanguage.o OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood_vqa.o OBJS-$(CONFIG_WTV_DEMUXER) += wtv.o asfdec.o asf.o asfcrypt.o \ - avlanguage.o mpegts.o isom.o riff.o + avlanguage.o mpegts.o isom.o OBJS-$(CONFIG_WV_DEMUXER) += wv.o apetag.o OBJS-$(CONFIG_XA_DEMUXER) += xa.o -OBJS-$(CONFIG_XMV_DEMUXER) += xmv.o riff.o -OBJS-$(CONFIG_XWMA_DEMUXER) += xwma.o riff.o +OBJS-$(CONFIG_XMV_DEMUXER) += xmv.o +OBJS-$(CONFIG_XWMA_DEMUXER) += xwma.o OBJS-$(CONFIG_YOP_DEMUXER) += yop.o OBJS-$(CONFIG_YUV4MPEGPIPE_MUXER) += yuv4mpeg.o OBJS-$(CONFIG_YUV4MPEGPIPE_DEMUXER) += yuv4mpeg.o # external libraries -OBJS-$(CONFIG_LIBNUT_DEMUXER) += libnut.o riff.o -OBJS-$(CONFIG_LIBNUT_MUXER) += libnut.o riff.o +OBJS-$(CONFIG_LIBNUT_DEMUXER) += libnut.o +OBJS-$(CONFIG_LIBNUT_MUXER) += libnut.o # protocols I/O OBJS+= avio.o aviobuf.o diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 217d8139df..7b67889e73 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1600,6 +1600,30 @@ int av_match_ext(const char *filename, const char *extensions); */ int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance); +/** + * @defgroup riff_fourcc RIFF FourCCs + * @{ + * Get the tables mapping RIFF FourCCs to libavcodec CodecIDs. The tables are + * meant to be passed to av_codec_get_id()/av_codec_get_tag() as in the + * following code: + * @code + * uint32_t tag = MKTAG('H', '2', '6', '4'); + * const struct AVCodecTag *table[] = { avformat_get_riff_video_tags(), 0 }; + * enum CodecID id = av_codec_get_id(table, tag); + * @endcode + */ +/** + * @return the table mapping RIFF FourCCs for video to libavcodec CodecID. + */ +const struct AVCodecTag *avformat_get_riff_video_tags(void); +/** + * @return the table mapping RIFF FourCCs for audio to CodecID. + */ +const struct AVCodecTag *avformat_get_riff_audio_tags(void); +/** + * @} + */ + /** * @} */ diff --git a/libavformat/utils.c b/libavformat/utils.c index cf7180b3cf..e10348df60 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3874,3 +3874,12 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels, } return 0; } + +const struct AVCodecTag *avformat_get_riff_video_tags(void) +{ + return ff_codec_bmp_tags; +} +const struct AVCodecTag *avformat_get_riff_audio_tags(void) +{ + return ff_codec_wav_tags; +} From b010178e84c950cf9b1a8b9c94ecaca79bd41895 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Tue, 31 Jan 2012 18:41:52 +0100 Subject: [PATCH 24/29] adpcm: Add missing stdint.h #include to fix standalone header compilation. --- libavcodec/adpcm.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/adpcm.h b/libavcodec/adpcm.h index 3a054c0e84..16facb6d0f 100644 --- a/libavcodec/adpcm.h +++ b/libavcodec/adpcm.h @@ -26,6 +26,8 @@ #ifndef AVCODEC_ADPCM_H #define AVCODEC_ADPCM_H +#include + #define BLKSIZE 1024 typedef struct ADPCMChannelStatus { From 3856a2aaa6a44d80da597e932e9d475bda8546bd Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Mon, 30 Jan 2012 11:10:27 +0100 Subject: [PATCH 25/29] h264-test: Remove unused DSP and AVCodec contexts and related init calls. This also avoids a segfault on startup. --- libavcodec/h264.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libavcodec/h264.c b/libavcodec/h264.c index 581848be16..8b8c4fec1c 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -4109,11 +4109,6 @@ int main(void){ uint8_t temp[SIZE]; PutBitContext pb; GetBitContext gb; - DSPContext dsp; - AVCodecContext avctx; - - avctx.av_class = avcodec_get_class(); - dsputil_init(&dsp, &avctx); init_put_bits(&pb, temp, SIZE); printf("testing unsigned exp golomb\n"); From 4ff46af039997652b7d955b74e655077d2e8c871 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Mon, 30 Jan 2012 11:16:20 +0100 Subject: [PATCH 26/29] h264-test: cleanup: drop timer invocations, commented out code and other cruft --- libavcodec/h264.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/libavcodec/h264.c b/libavcodec/h264.c index 8b8c4fec1c..76d6f7fa65 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -4101,7 +4101,6 @@ static inline void fill_mb_avail(H264Context *h){ #ifdef TEST #undef printf -#undef random #define COUNT 8000 #define SIZE (COUNT*40) int main(void){ @@ -4113,9 +4112,7 @@ int main(void){ init_put_bits(&pb, temp, SIZE); printf("testing unsigned exp golomb\n"); for(i=0; i Date: Mon, 30 Jan 2012 12:50:16 +0100 Subject: [PATCH 27/29] h264: Split h264-test off into a separate file - golomb-test.c. The new name is more appropriate as only golomb functions are tested. --- libavcodec/Makefile | 2 +- libavcodec/golomb-test.c | 73 ++++++++++++++++++++++++++++++++++++++++ libavcodec/h264.c | 49 --------------------------- 3 files changed, 74 insertions(+), 50 deletions(-) create mode 100644 libavcodec/golomb-test.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index daf2ce3e42..6308e829f0 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -688,7 +688,7 @@ SKIPHEADERS-$(HAVE_W32THREADS) += w32pthreads.h EXAMPLES = api -TESTPROGS = cabac dct fft fft-fixed h264 iirfilter rangecoder +TESTPROGS = cabac dct fft fft-fixed golomb iirfilter rangecoder TESTPROGS-$(HAVE_MMX) += motion TESTOBJS = dctref.o diff --git a/libavcodec/golomb-test.c b/libavcodec/golomb-test.c new file mode 100644 index 0000000000..e3c89b1587 --- /dev/null +++ b/libavcodec/golomb-test.c @@ -0,0 +1,73 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "avcodec.h" +#include "dsputil.h" +#include "get_bits.h" +#include "golomb.h" +#include "put_bits.h" + +#undef printf +#define COUNT 8000 +#define SIZE (COUNT*40) + +int main(void){ + int i; + uint8_t temp[SIZE]; + PutBitContext pb; + GetBitContext gb; + + init_put_bits(&pb, temp, SIZE); + printf("testing unsigned exp golomb\n"); + for(i=0; i Date: Mon, 30 Jan 2012 11:30:13 +0100 Subject: [PATCH 28/29] golomb-test: K&R formatting cosmetics --- libavcodec/golomb-test.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/libavcodec/golomb-test.c b/libavcodec/golomb-test.c index e3c89b1587..3dbf9d14cb 100644 --- a/libavcodec/golomb-test.c +++ b/libavcodec/golomb-test.c @@ -27,9 +27,10 @@ #undef printf #define COUNT 8000 -#define SIZE (COUNT*40) +#define SIZE (COUNT * 40) -int main(void){ +int main(void) +{ int i; uint8_t temp[SIZE]; PutBitContext pb; @@ -37,36 +38,32 @@ int main(void){ init_put_bits(&pb, temp, SIZE); printf("testing unsigned exp golomb\n"); - for(i=0; i Date: Mon, 30 Jan 2012 12:58:20 +0100 Subject: [PATCH 29/29] fate: add golomb-test --- tests/fate/libavcodec.mak | 4 ++++ tests/ref/fate/golomb | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 tests/ref/fate/golomb diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak index 083f6e8b04..90c817812f 100644 --- a/tests/fate/libavcodec.mak +++ b/tests/fate/libavcodec.mak @@ -1,3 +1,7 @@ +FATE_TESTS += fate-golomb +fate-golomb: libavcodec/golomb-test$(EXESUF) +fate-golomb: CMD = run libavcodec/golomb-test + FATE_TESTS += fate-iirfilter fate-iirfilter: libavcodec/iirfilter-test$(EXESUF) fate-iirfilter: CMD = run libavcodec/iirfilter-test diff --git a/tests/ref/fate/golomb b/tests/ref/fate/golomb new file mode 100644 index 0000000000..652e97b305 --- /dev/null +++ b/tests/ref/fate/golomb @@ -0,0 +1,2 @@ +testing unsigned exp golomb +testing signed exp golomb