From 26af0953c0ba800aae2d52cbdaeca7b387a317bc Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 19 Oct 2011 23:25:01 +0200 Subject: [PATCH 01/47] Only test-compile w32pthreads.h if W32THREADS are available. This fixes 'make checkheaders' on non-W32THREADS systems. --- libavcodec/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index a566df27e1..c47424e913 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -670,6 +670,7 @@ SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_internal.h SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h +SKIPHEADERS-$(HAVE_W32THREADS) += w32pthreads.h EXAMPLES = api From 463ea05ab24ad0d27b54e985cab1a9a9c953285c Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 19 Oct 2011 23:12:56 +0200 Subject: [PATCH 02/47] avcodec.h: Move G.729/G.723 CODEC_IDs to the correct section. This is done conditional to the libavcodec version to avoid ABI breaks. --- libavcodec/avcodec.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index c2a3098eeb..06cede98ad 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -210,8 +210,10 @@ enum CodecID { CODEC_ID_DFA, CODEC_ID_WMV3IMAGE, CODEC_ID_VC1IMAGE, +#if LIBAVCODEC_VERSION_MAJOR == 53 CODEC_ID_G723_1, CODEC_ID_G729, +#endif CODEC_ID_UTVIDEO, /* various PCM "codecs" */ @@ -345,6 +347,10 @@ enum CodecID { CODEC_ID_AAC_LATM, CODEC_ID_QDMC, CODEC_ID_CELT, +#if LIBAVCODEC_VERSION_MAJOR > 53 + CODEC_ID_G723_1, + CODEC_ID_G729, +#endif /* subtitle codecs */ CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs. From 2cb7c8166920aa8dbb969de9befd0981b5a8f2ad Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Thu, 20 Oct 2011 15:59:22 +0200 Subject: [PATCH 03/47] x86: Fix linking of ProRes DSP ASM with YASM disabled. --- libavcodec/x86/proresdsp-init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/x86/proresdsp-init.c b/libavcodec/x86/proresdsp-init.c index 46ba43bc01..f202f9f0cf 100644 --- a/libavcodec/x86/proresdsp-init.c +++ b/libavcodec/x86/proresdsp-init.c @@ -31,7 +31,7 @@ void ff_prores_idct_put_10_avx (uint16_t *dst, int linesize, void ff_proresdsp_x86_init(ProresDSPContext *dsp) { -#if ARCH_X86_64 +#if ARCH_X86_64 && HAVE_YASM int flags = av_get_cpu_flags(); if (flags & AV_CPU_FLAG_SSE2) { @@ -49,6 +49,6 @@ void ff_proresdsp_x86_init(ProresDSPContext *dsp) dsp->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM; dsp->idct_put = ff_prores_idct_put_10_avx; } -#endif -#endif +#endif /* HAVE_AVX */ +#endif /* ARCH_X86_64 && HAVE_YASM */ } From 265980dabc2833a7d751edd6993d258f0048f48e Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Thu, 20 Oct 2011 15:43:16 +0200 Subject: [PATCH 04/47] x86: Move some variable declarations below the appropriat #ifdef. This avoids some unused variable warnings with YASM disabled. --- libavcodec/x86/ac3dsp_mmx.c | 2 +- libavcodec/x86/h264_intrapred_init.c | 2 +- libavcodec/x86/vp8dsp-init.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/x86/ac3dsp_mmx.c b/libavcodec/x86/ac3dsp_mmx.c index 692d240d4c..d6bb469457 100644 --- a/libavcodec/x86/ac3dsp_mmx.c +++ b/libavcodec/x86/ac3dsp_mmx.c @@ -50,9 +50,9 @@ extern void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_c av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact) { +#if HAVE_YASM int mm_flags = av_get_cpu_flags(); -#if HAVE_YASM if (mm_flags & AV_CPU_FLAG_MMX) { c->ac3_exponent_min = ff_ac3_exponent_min_mmx; c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx; diff --git a/libavcodec/x86/h264_intrapred_init.c b/libavcodec/x86/h264_intrapred_init.c index 55387f623e..414d5e6125 100644 --- a/libavcodec/x86/h264_intrapred_init.c +++ b/libavcodec/x86/h264_intrapred_init.c @@ -169,9 +169,9 @@ void ff_pred4x4_vertical_vp8_mmxext(uint8_t *src, const uint8_t *topright, int s void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth) { +#if HAVE_YASM int mm_flags = av_get_cpu_flags(); -#if HAVE_YASM if (bit_depth == 8) { if (mm_flags & AV_CPU_FLAG_MMX) { h->pred16x16[VERT_PRED8x8 ] = ff_pred16x16_vertical_mmx; diff --git a/libavcodec/x86/vp8dsp-init.c b/libavcodec/x86/vp8dsp-init.c index 8b27b0dadc..f5e89faa3c 100644 --- a/libavcodec/x86/vp8dsp-init.c +++ b/libavcodec/x86/vp8dsp-init.c @@ -283,9 +283,9 @@ DECLARE_LOOP_FILTER(sse4) av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c) { +#if HAVE_YASM int mm_flags = av_get_cpu_flags(); -#if HAVE_YASM if (mm_flags & AV_CPU_FLAG_MMX) { c->vp8_idct_dc_add = ff_vp8_idct_dc_add_mmx; c->vp8_idct_dc_add4y = ff_vp8_idct_dc_add4y_mmx; From 52375ba5677e54ebd5dc4e14ffaa0a3e9b676ce7 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 19 Oct 2011 13:16:01 -0400 Subject: [PATCH 05/47] flvenc: adjust for negative DTS for all codecs, not just H.264 --- libavformat/flvenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 23d19cd506..851ce491b0 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -410,9 +410,9 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0) return -1; } - if (!flv->delay && pkt->dts < 0) - flv->delay = -pkt->dts; } + if (!flv->delay && pkt->dts < 0) + flv->delay = -pkt->dts; ts = pkt->dts + flv->delay; // add delay to force positive dts if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { From b606a017593b2a7a5f435f2b75b8de163c367ac6 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 18 Oct 2011 12:16:27 -0700 Subject: [PATCH 06/47] libspeexenc: add libspeex encoder --- Changelog | 1 + configure | 3 +- doc/general.texi | 2 +- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 2 +- libavcodec/libspeexenc.c | 324 +++++++++++++++++++++++++++++++++++++++ libavcodec/version.h | 2 +- 7 files changed, 331 insertions(+), 4 deletions(-) create mode 100644 libavcodec/libspeexenc.c diff --git a/Changelog b/Changelog index f61d3e2b13..3041632a33 100644 --- a/Changelog +++ b/Changelog @@ -53,6 +53,7 @@ easier to use. The changes are: - lut, lutrgb, and lutyuv filters - boxblur filter - Ut Video decoder +- Speex encoding via libspeex version 0.7: diff --git a/configure b/configure index a036873682..1860dc8ae5 100755 --- a/configure +++ b/configure @@ -178,7 +178,7 @@ External library support: --enable-libopenjpeg enable JPEG 2000 decoding via OpenJPEG [no] --enable-librtmp enable RTMP[E] support via librtmp [no] --enable-libschroedinger enable Dirac support via libschroedinger [no] - --enable-libspeex enable Speex decoding via libspeex [no] + --enable-libspeex enable Speex support via libspeex [no] --enable-libtheora enable Theora encoding via libtheora [no] --enable-libvo-aacenc enable AAC encoding via libvo-aacenc [no] --enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no] @@ -1406,6 +1406,7 @@ libopenjpeg_decoder_deps="libopenjpeg" libschroedinger_decoder_deps="libschroedinger" libschroedinger_encoder_deps="libschroedinger" libspeex_decoder_deps="libspeex" +libspeex_encoder_deps="libspeex" libtheora_encoder_deps="libtheora" libvo_aacenc_encoder_deps="libvo_aacenc" libvo_amrwbenc_encoder_deps="libvo_amrwbenc" diff --git a/doc/general.texi b/doc/general.texi index c4c4414c4f..b1c2534be0 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -682,7 +682,7 @@ following image formats are supported: @tab Used in Sierra VMD files. @item Smacker audio @tab @tab X @item SMPTE 302M AES3 audio @tab @tab X -@item Speex @tab @tab E +@item Speex @tab E @tab E @tab supported through external library libspeex @item True Audio (TTA) @tab @tab X @item TrueHD @tab @tab X diff --git a/libavcodec/Makefile b/libavcodec/Makefile index c47424e913..81881e44f0 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -576,6 +576,7 @@ OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER) += libschroedingerenc.o \ libschroedinger.o \ libdirac_libschro.o OBJS-$(CONFIG_LIBSPEEX_DECODER) += libspeexdec.o +OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o OBJS-$(CONFIG_LIBTHEORA_ENCODER) += libtheoraenc.o OBJS-$(CONFIG_LIBVO_AACENC_ENCODER) += libvo-aacenc.o mpeg4audio.o OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index f85f06d6cc..64669b7c8f 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -370,7 +370,7 @@ void avcodec_register_all(void) REGISTER_DECODER (LIBOPENCORE_AMRWB, libopencore_amrwb); REGISTER_DECODER (LIBOPENJPEG, libopenjpeg); REGISTER_ENCDEC (LIBSCHROEDINGER, libschroedinger); - REGISTER_DECODER (LIBSPEEX, libspeex); + REGISTER_ENCDEC (LIBSPEEX, libspeex); REGISTER_ENCODER (LIBTHEORA, libtheora); REGISTER_ENCODER (LIBVO_AACENC, libvo_aacenc); REGISTER_ENCODER (LIBVO_AMRWBENC, libvo_amrwbenc); diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c new file mode 100644 index 0000000000..18f973f4fd --- /dev/null +++ b/libavcodec/libspeexenc.c @@ -0,0 +1,324 @@ +/* + * Copyright (C) 2009 Justin Ruggles + * Copyright (c) 2009 Xuggle Incorporated + * + * 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 + */ + +/** + * @file + * libspeex Speex audio encoder + * + * Usage Guide + * This explains the values that need to be set prior to initialization in + * order to control various encoding parameters. + * + * Channels + * Speex only supports mono or stereo, so avctx->channels must be set to + * 1 or 2. + * + * Sample Rate / Encoding Mode + * Speex has 3 modes, each of which uses a specific sample rate. + * narrowband : 8 kHz + * wideband : 16 kHz + * ultra-wideband : 32 kHz + * avctx->sample_rate must be set to one of these 3 values. This will be + * used to set the encoding mode. + * + * Rate Control + * VBR mode is turned on by setting CODEC_FLAG_QSCALE in avctx->flags. + * avctx->global_quality is used to set the encoding quality. + * For CBR mode, avctx->bit_rate can be used to set the constant bitrate. + * Alternatively, the 'cbr_quality' option can be set from 0 to 10 to set + * a constant bitrate based on quality. + * For ABR mode, set avctx->bit_rate and set the 'abr' option to 1. + * Approx. Bitrate Range: + * narrowband : 2400 - 25600 bps + * wideband : 4000 - 43200 bps + * ultra-wideband : 4400 - 45200 bps + * + * Complexity + * Encoding complexity is controlled by setting avctx->compression_level. + * The valid range is 0 to 10. A higher setting gives generally better + * quality at the expense of encoding speed. This does not affect the + * bit rate. + * + * Frames-per-Packet + * The encoder defaults to using 1 frame-per-packet. However, it is + * sometimes desirable to use multiple frames-per-packet to reduce the + * amount of container overhead. This can be done by setting the + * 'frames_per_packet' option to a value 1 to 8. + */ + +#include +#include +#include +#include "libavutil/mathematics.h" +#include "libavutil/opt.h" +#include "avcodec.h" +#include "internal.h" + +typedef struct { + AVClass *class; ///< AVClass for private options + SpeexBits bits; ///< libspeex bitwriter context + SpeexHeader header; ///< libspeex header struct + void *enc_state; ///< libspeex encoder state + int frames_per_packet; ///< number of frames to encode in each packet + float vbr_quality; ///< VBR quality 0.0 to 10.0 + int cbr_quality; ///< CBR quality 0 to 10 + int abr; ///< flag to enable ABR + int pkt_frame_count; ///< frame count for the current packet + int lookahead; ///< encoder delay + int sample_count; ///< total sample count (used for pts) +} LibSpeexEncContext; + +static av_cold void print_enc_params(AVCodecContext *avctx, + LibSpeexEncContext *s) +{ + const char *mode_str = "unknown"; + + av_log(avctx, AV_LOG_DEBUG, "channels: %d\n", avctx->channels); + switch (s->header.mode) { + case SPEEX_MODEID_NB: mode_str = "narrowband"; break; + case SPEEX_MODEID_WB: mode_str = "wideband"; break; + case SPEEX_MODEID_UWB: mode_str = "ultra-wideband"; break; + } + av_log(avctx, AV_LOG_DEBUG, "mode: %s\n", mode_str); + if (s->header.vbr) { + av_log(avctx, AV_LOG_DEBUG, "rate control: VBR\n"); + av_log(avctx, AV_LOG_DEBUG, " quality: %f\n", s->vbr_quality); + } else if (s->abr) { + av_log(avctx, AV_LOG_DEBUG, "rate control: ABR\n"); + av_log(avctx, AV_LOG_DEBUG, " bitrate: %d bps\n", avctx->bit_rate); + } else { + av_log(avctx, AV_LOG_DEBUG, "rate control: CBR\n"); + av_log(avctx, AV_LOG_DEBUG, " bitrate: %d bps\n", avctx->bit_rate); + } + av_log(avctx, AV_LOG_DEBUG, "complexity: %d\n", + avctx->compression_level); + av_log(avctx, AV_LOG_DEBUG, "frame size: %d samples\n", + avctx->frame_size); + av_log(avctx, AV_LOG_DEBUG, "frames per packet: %d\n", + s->frames_per_packet); + av_log(avctx, AV_LOG_DEBUG, "packet size: %d\n", + avctx->frame_size * s->frames_per_packet); +} + +static av_cold int encode_init(AVCodecContext *avctx) +{ + LibSpeexEncContext *s = avctx->priv_data; + const SpeexMode *mode; + uint8_t *header_data; + int header_size; + int32_t complexity; + + /* channels */ + if (avctx->channels < 1 || avctx->channels > 2) { + av_log(avctx, AV_LOG_ERROR, "Invalid channels (%d). Only stereo and " + "mono are supported\n", avctx->channels); + return AVERROR(EINVAL); + } + + /* sample rate and encoding mode */ + switch (avctx->sample_rate) { + case 8000: mode = &speex_nb_mode; break; + case 16000: mode = &speex_wb_mode; break; + case 32000: mode = &speex_uwb_mode; break; + default: + av_log(avctx, AV_LOG_ERROR, "Sample rate of %d Hz is not supported. " + "Resample to 8, 16, or 32 kHz.\n", avctx->sample_rate); + return AVERROR(EINVAL); + } + + /* initialize libspeex */ + s->enc_state = speex_encoder_init(mode); + if (!s->enc_state) { + av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex\n"); + return -1; + } + speex_init_header(&s->header, avctx->sample_rate, avctx->channels, mode); + + /* rate control method and parameters */ + if (avctx->flags & CODEC_FLAG_QSCALE) { + /* VBR */ + s->header.vbr = 1; + speex_encoder_ctl(s->enc_state, SPEEX_SET_VBR, &s->header.vbr); + s->vbr_quality = av_clipf(avctx->global_quality / (float)FF_QP2LAMBDA, + 0.0f, 10.0f); + speex_encoder_ctl(s->enc_state, SPEEX_SET_VBR_QUALITY, &s->vbr_quality); + } else { + s->header.bitrate = avctx->bit_rate; + if (avctx->bit_rate > 0) { + /* CBR or ABR by bitrate */ + if (s->abr) { + speex_encoder_ctl(s->enc_state, SPEEX_SET_ABR, + &s->header.bitrate); + speex_encoder_ctl(s->enc_state, SPEEX_GET_ABR, + &s->header.bitrate); + } else { + speex_encoder_ctl(s->enc_state, SPEEX_SET_BITRATE, + &s->header.bitrate); + speex_encoder_ctl(s->enc_state, SPEEX_GET_BITRATE, + &s->header.bitrate); + } + } else { + /* CBR by quality */ + speex_encoder_ctl(s->enc_state, SPEEX_SET_QUALITY, + &s->cbr_quality); + speex_encoder_ctl(s->enc_state, SPEEX_GET_BITRATE, + &s->header.bitrate); + } + /* stereo side information adds about 800 bps to the base bitrate */ + /* TODO: this should be calculated exactly */ + avctx->bit_rate = s->header.bitrate + (avctx->channels == 2 ? 800 : 0); + } + + /* set encoding complexity */ + if (avctx->compression_level > FF_COMPRESSION_DEFAULT) { + complexity = av_clip(avctx->compression_level, 0, 10); + speex_encoder_ctl(s->enc_state, SPEEX_SET_COMPLEXITY, &complexity); + } + speex_encoder_ctl(s->enc_state, SPEEX_GET_COMPLEXITY, &complexity); + avctx->compression_level = complexity; + + /* set packet size */ + avctx->frame_size = s->header.frame_size; + s->header.frames_per_packet = s->frames_per_packet; + + /* set encoding delay */ + speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &s->lookahead); + s->sample_count = -s->lookahead; + + /* create header packet bytes from header struct */ + /* note: libspeex allocates the memory for header_data, which is freed + below with speex_header_free() */ + header_data = speex_header_to_packet(&s->header, &header_size); + + /* allocate extradata and coded_frame */ + avctx->extradata = av_malloc(header_size + FF_INPUT_BUFFER_PADDING_SIZE); + avctx->coded_frame = avcodec_alloc_frame(); + if (!avctx->extradata || !avctx->coded_frame) { + speex_header_free(header_data); + speex_encoder_destroy(s->enc_state); + av_log(avctx, AV_LOG_ERROR, "memory allocation error\n"); + return AVERROR(ENOMEM); + } + + /* copy header packet to extradata */ + memcpy(avctx->extradata, header_data, header_size); + avctx->extradata_size = header_size; + speex_header_free(header_data); + + /* init libspeex bitwriter */ + speex_bits_init(&s->bits); + + print_enc_params(avctx, s); + return 0; +} + +static int encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, + void *data) +{ + LibSpeexEncContext *s = avctx->priv_data; + int16_t *samples = data; + int sample_count = s->sample_count; + + if (data) { + /* encode Speex frame */ + if (avctx->channels == 2) + speex_encode_stereo_int(samples, s->header.frame_size, &s->bits); + speex_encode_int(s->enc_state, samples, &s->bits); + s->pkt_frame_count++; + s->sample_count += avctx->frame_size; + } else { + /* handle end-of-stream */ + if (!s->pkt_frame_count) + return 0; + /* add extra terminator codes for unused frames in last packet */ + while (s->pkt_frame_count < s->frames_per_packet) { + speex_bits_pack(&s->bits, 15, 5); + s->pkt_frame_count++; + } + } + + /* write output if all frames for the packet have been encoded */ + if (s->pkt_frame_count == s->frames_per_packet) { + s->pkt_frame_count = 0; + avctx->coded_frame->pts = + av_rescale_q(sample_count, (AVRational){ 1, avctx->sample_rate }, + avctx->time_base); + if (buf_size > speex_bits_nbytes(&s->bits)) { + int ret = speex_bits_write(&s->bits, frame, buf_size); + speex_bits_reset(&s->bits); + return ret; + } else { + av_log(avctx, AV_LOG_ERROR, "output buffer too small"); + return AVERROR(EINVAL); + } + } + return 0; +} + +static av_cold int encode_close(AVCodecContext *avctx) +{ + LibSpeexEncContext *s = avctx->priv_data; + + speex_bits_destroy(&s->bits); + speex_encoder_destroy(s->enc_state); + + av_freep(&avctx->coded_frame); + av_freep(&avctx->extradata); + + return 0; +} + +#define OFFSET(x) offsetof(LibSpeexEncContext, x) +#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM +static const AVOption options[] = { + { "abr", "Use average bit rate", OFFSET(abr), AV_OPT_TYPE_INT, { 0 }, 0, 1, AE }, + { "cbr_quality", "Set quality value (0 to 10) for CBR", OFFSET(cbr_quality), AV_OPT_TYPE_INT, { 8 }, 0, 10, AE }, + { "frames_per_packet", "Number of frames to encode in each packet", OFFSET(frames_per_packet), AV_OPT_TYPE_INT, { 1 }, 1, 8, AE }, + { NULL }, +}; + +static const AVClass class = { + .class_name = "libspeex", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +static const AVCodecDefault defaults[] = { + { "b", "0" }, + { "compression_level", "3" }, + { NULL }, +}; + +AVCodec ff_libspeex_encoder = { + .name = "libspeex", + .type = AVMEDIA_TYPE_AUDIO, + .id = CODEC_ID_SPEEX, + .priv_data_size = sizeof(LibSpeexEncContext), + .init = encode_init, + .encode = encode_frame, + .close = encode_close, + .capabilities = CODEC_CAP_DELAY, + .sample_fmts = (const enum SampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, + .long_name = NULL_IF_CONFIG_SMALL("libspeex Speex"), + .priv_class = &class, + .defaults = defaults, +}; diff --git a/libavcodec/version.h b/libavcodec/version.h index b89e6f17cc..ef30a694ee 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -21,7 +21,7 @@ #define AVCODEC_VERSION_H #define LIBAVCODEC_VERSION_MAJOR 53 -#define LIBAVCODEC_VERSION_MINOR 13 +#define LIBAVCODEC_VERSION_MINOR 14 #define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ From 4ee247a2bdf2fbe81026a428d4affc46c81f28db Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 19 Oct 2011 13:20:15 -0400 Subject: [PATCH 07/47] flvenc: check packet duration in speex using timestamps Using AVCodecContext.frame_size is not reliable. --- libavformat/flvenc.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 851ce491b0..cf77157636 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -58,7 +58,7 @@ typedef struct FLVContext { int64_t filesize_offset; int64_t duration; int delay; ///< first dts delay for AVC - int64_t last_video_ts; + int64_t last_ts; } FLVContext; static int get_audio_flags(AVCodecContext *enc){ @@ -75,11 +75,6 @@ static int get_audio_flags(AVCodecContext *enc){ av_log(enc, AV_LOG_ERROR, "flv only supports mono Speex audio\n"); return -1; } - if (enc->frame_size / 320 > 8) { - av_log(enc, AV_LOG_WARNING, "Warning: Speex stream has more than " - "8 frames per packet. Adobe Flash " - "Player cannot handle this!\n"); - } return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT; } else { switch (enc->sample_rate) { @@ -220,7 +215,7 @@ static int flv_write_header(AVFormatContext *s) } } - flv->last_video_ts = -1; + flv->last_ts = -1; /* write meta_tag */ avio_w8(pb, 18); // tag type META @@ -349,7 +344,7 @@ static int flv_write_trailer(AVFormatContext *s) AVCodecContext *enc = s->streams[i]->codec; if (enc->codec_type == AVMEDIA_TYPE_VIDEO && enc->codec_id == CODEC_ID_H264) { - put_avc_eos_tag(pb, flv->last_video_ts); + put_avc_eos_tag(pb, flv->last_ts); } } @@ -415,10 +410,17 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) flv->delay = -pkt->dts; ts = pkt->dts + flv->delay; // add delay to force positive dts - if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { - if (flv->last_video_ts < ts) - flv->last_video_ts = ts; + + /* check Speex packet duration */ + if (enc->codec_id == CODEC_ID_SPEEX && ts - flv->last_ts > 160) { + av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than " + "8 frames per packet. Adobe Flash " + "Player cannot handle this!\n"); } + + if (flv->last_ts < ts) + flv->last_ts = ts; + avio_wb24(pb,size + flags_size); avio_wb24(pb,ts); avio_w8(pb,(ts >> 24) & 0x7F); // timestamps are 32bits _signed_ From 0e69c0477399a5545d42456d6c3aec4a3650bb67 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 19 Oct 2011 13:28:12 -0400 Subject: [PATCH 08/47] ogg/speex: set correct timestamp and duration for the first packet. The first timestamp should be negative due to delay. Also, do not set AVCodecContext.frame_size unnecessarily. --- libavformat/oggparsespeex.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c index 2f4aec7f07..bbeeb20d60 100644 --- a/libavformat/oggparsespeex.c +++ b/libavformat/oggparsespeex.c @@ -31,6 +31,7 @@ #include "oggdec.h" struct speex_params { + int packet_size; int final_packet_duration; int seq; }; @@ -58,14 +59,10 @@ static int speex_header(AVFormatContext *s, int idx) { st->codec->sample_rate = AV_RL32(p + 36); st->codec->channels = AV_RL32(p + 48); - /* We treat the whole Speex packet as a single frame everywhere Speex - is handled in Libav. This avoids the complexities of splitting - and joining individual Speex frames, which are not always - byte-aligned. */ - st->codec->frame_size = AV_RL32(p + 56); - frames_per_packet = AV_RL32(p + 64); + spxp->packet_size = AV_RL32(p + 56); + frames_per_packet = AV_RL32(p + 64); if (frames_per_packet) - st->codec->frame_size *= frames_per_packet; + spxp->packet_size *= frames_per_packet; st->codec->extradata_size = os->psize; st->codec->extradata = av_malloc(st->codec->extradata_size @@ -95,7 +92,7 @@ static int speex_packet(AVFormatContext *s, int idx) struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; struct speex_params *spxp = os->private; - int packet_size = s->streams[idx]->codec->frame_size; + int packet_size = spxp->packet_size; if (os->flags & OGG_FLAG_EOS && os->lastpts != AV_NOPTS_VALUE && os->granule > 0) { @@ -108,9 +105,10 @@ static int speex_packet(AVFormatContext *s, int idx) if (!os->lastpts && os->granule > 0) /* first packet */ - os->pduration = os->granule - packet_size * (ogg_page_packets(os) - 1); - else if (os->flags & OGG_FLAG_EOS && os->segp == os->nsegs && - spxp->final_packet_duration) + os->lastpts = os->lastdts = os->granule - packet_size * + ogg_page_packets(os); + if (os->flags & OGG_FLAG_EOS && os->segp == os->nsegs && + spxp->final_packet_duration) /* final packet */ os->pduration = spxp->final_packet_duration; else From 9ef6c7977f827e73fcc6e7f5ef6165936142eab4 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 19 Oct 2011 14:00:06 -0400 Subject: [PATCH 09/47] avformat: do not require frame_size for Speex. Having it there forces decoding of a frame in order to get frame_size, but it is not really needed for proper demuxing or decoding. --- libavformat/utils.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 9735d455d9..5e3e60b198 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2070,7 +2070,6 @@ static int has_codec_parameters(AVCodecContext *avctx) avctx->codec_id == CODEC_ID_MP1 || avctx->codec_id == CODEC_ID_MP2 || avctx->codec_id == CODEC_ID_MP3 || - avctx->codec_id == CODEC_ID_SPEEX || avctx->codec_id == CODEC_ID_CELT)) return 0; break; From a1f7885a8b40e475c1f7b8651e7b536701a2e770 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 14 Sep 2011 15:02:35 -0400 Subject: [PATCH 10/47] shorten: split reading of file header into a separate functions --- libavcodec/shorten.c | 131 +++++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 61 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index dd1bef8a18..af12e08bfc 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -273,6 +273,73 @@ static void decode_subframe_lpc(ShortenContext *s, int channel, int residual_siz } } +static int read_header(ShortenContext *s) +{ + int i; + int maxnlpc = 0; + /* shorten signature */ + if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) { + av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n"); + return -1; + } + + s->lpcqoffset = 0; + s->blocksize = DEFAULT_BLOCK_SIZE; + s->channels = 1; + s->nmean = -1; + s->version = get_bits(&s->gb, 8); + s->internal_ftype = get_uint(s, TYPESIZE); + + s->channels = get_uint(s, CHANSIZE); + if (s->channels > MAX_CHANNELS) { + av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels); + return -1; + } + + /* get blocksize if version > 0 */ + if (s->version > 0) { + int skip_bytes; + s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE)); + maxnlpc = get_uint(s, LPCQSIZE); + s->nmean = get_uint(s, 0); + + skip_bytes = get_uint(s, NSKIPSIZE); + for (i=0; igb, 8); + } + } + s->nwrap = FFMAX(NWRAP, maxnlpc); + + if (allocate_buffers(s)) + return -1; + + init_offset(s); + + if (s->version > 1) + s->lpcqoffset = V2LPCQOFFSET; + + if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) { + av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n"); + return -1; + } + + s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); + if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) { + av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size); + return -1; + } + + for (i=0; iheader_size; i++) + s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); + + if (decode_wave_header(s->avctx, s->header, s->header_size) < 0) + return -1; + + s->cur_chan = 0; + s->bitshift = 0; + + return 0; +} static int shorten_decode_frame(AVCodecContext *avctx, void *data, int *data_size, @@ -311,67 +378,9 @@ static int shorten_decode_frame(AVCodecContext *avctx, skip_bits(&s->gb, s->bitindex); if (!s->blocksize) { - int maxnlpc = 0; - /* shorten signature */ - if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) { - av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n"); - return -1; - } - - s->lpcqoffset = 0; - s->blocksize = DEFAULT_BLOCK_SIZE; - s->channels = 1; - s->nmean = -1; - s->version = get_bits(&s->gb, 8); - s->internal_ftype = get_uint(s, TYPESIZE); - - s->channels = get_uint(s, CHANSIZE); - if (s->channels > MAX_CHANNELS) { - av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels); - return -1; - } - - /* get blocksize if version > 0 */ - if (s->version > 0) { - int skip_bytes; - s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE)); - maxnlpc = get_uint(s, LPCQSIZE); - s->nmean = get_uint(s, 0); - - skip_bytes = get_uint(s, NSKIPSIZE); - for (i=0; igb, 8); - } - } - s->nwrap = FFMAX(NWRAP, maxnlpc); - - if (allocate_buffers(s)) - return -1; - - init_offset(s); - - if (s->version > 1) - s->lpcqoffset = V2LPCQOFFSET; - - if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) { - av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n"); - return -1; - } - - s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); - if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) { - av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size); - return -1; - } - - for (i=0; iheader_size; i++) - s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); - - if (decode_wave_header(avctx, s->header, s->header_size) < 0) - return -1; - - s->cur_chan = 0; - s->bitshift = 0; + int ret; + if ((ret = read_header(s)) < 0) + return ret; } else { From 07745485ef70bd38485c6a391ec2300687528a6d Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 14 Sep 2011 15:20:22 -0400 Subject: [PATCH 11/47] shorten: skip some fields in the WAV header embedded in the shorten header. fixes incorrect bitrate reporting and potential misreporting of the number of channels. --- libavcodec/shorten.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index af12e08bfc..af798da1b3 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -231,10 +231,10 @@ static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header return -1; } - avctx->channels = get_le16(&hb); + skip_bits(&hb, 16); // skip channels (already got from shorten header) avctx->sample_rate = get_le32(&hb); - avctx->bit_rate = get_le32(&hb) * 8; - avctx->block_align = get_le16(&hb); + skip_bits(&hb, 32); // skip bit rate (represents original uncompressed bit rate) + skip_bits(&hb, 16); // skip block align (not needed) avctx->bits_per_coded_sample = get_le16(&hb); if (avctx->bits_per_coded_sample != 16) { @@ -295,6 +295,7 @@ static int read_header(ShortenContext *s) av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels); return -1; } + s->avctx->channels = s->channels; /* get blocksize if version > 0 */ if (s->version > 0) { From 9000b6db22dd05ff00807e233951d4b225852b0b Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 14 Sep 2011 18:46:37 -0400 Subject: [PATCH 12/47] shorten: separate processing of audio commands from non-audio commands --- libavcodec/shorten.c | 73 +++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index af798da1b3..2a9b9ab47a 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -69,6 +69,9 @@ #define FN_ZERO 8 #define FN_VERBATIM 9 +/** indicates if the FN_* command is audio or non-audio */ +static const uint8_t is_audio_command[10] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 }; + #define VERBATIM_CKSIZE_SIZE 5 #define VERBATIM_BYTE_SIZE 8 #define CANONICAL_HEADER_SIZE 44 @@ -388,14 +391,42 @@ static int shorten_decode_frame(AVCodecContext *avctx, int cmd; int len; cmd = get_ur_golomb_shorten(&s->gb, FNSIZE); - switch (cmd) { - case FN_ZERO: - case FN_DIFF0: - case FN_DIFF1: - case FN_DIFF2: - case FN_DIFF3: - case FN_QLPC: - { + + if (cmd > FN_VERBATIM) { + av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd); + if (s->bitstream_size > 0) { + s->bitstream_index++; + s->bitstream_size--; + } + return -1; + } + + if (!is_audio_command[cmd]) { + /* process non-audio command */ + switch (cmd) { + case FN_VERBATIM: + len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); + while (len--) { + get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); + } + break; + case FN_BITSHIFT: + s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE); + break; + case FN_BLOCKSIZE: { + int blocksize = get_uint(s, av_log2(s->blocksize)); + if (blocksize > s->blocksize) { + av_log(avctx, AV_LOG_ERROR, "Increasing block size is not supported\n"); + return AVERROR_PATCHWELCOME; + } + s->blocksize = blocksize; + break; + } + case FN_QUIT: + goto frame_done; + } + } else { + /* process audio command */ int residual_size = 0; int channel = s->cur_chan; int32_t coffset; @@ -481,32 +512,6 @@ static int shorten_decode_frame(AVCodecContext *avctx, s->cur_chan = 0; goto frame_done; } - } - break; - case FN_VERBATIM: - len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); - while (len--) { - get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); - } - break; - case FN_BITSHIFT: - s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE); - break; - case FN_BLOCKSIZE: { - int blocksize = get_uint(s, av_log2(s->blocksize)); - if (blocksize > s->blocksize) { - av_log(avctx, AV_LOG_ERROR, "Increasing block size is not supported\n"); - return AVERROR_PATCHWELCOME; - } - s->blocksize = blocksize; - break; - } - case FN_QUIT: - *data_size = 0; - return buf_size; - default: - av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd); - return -1; } } frame_done: From e9e37f2d1051ba71985878a5239deb976183a23b Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 15 Sep 2011 00:03:35 -0400 Subject: [PATCH 13/47] cosmetics: reindent --- libavcodec/shorten.c | 158 +++++++++++++++++++++---------------------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 2a9b9ab47a..62cead49e1 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -427,91 +427,91 @@ static int shorten_decode_frame(AVCodecContext *avctx, } } else { /* process audio command */ - int residual_size = 0; - int channel = s->cur_chan; - int32_t coffset; - if (cmd != FN_ZERO) { - residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE); - /* this is a hack as version 0 differed in defintion of get_sr_golomb_shorten */ - if (s->version == 0) - residual_size--; - } + int residual_size = 0; + int channel = s->cur_chan; + int32_t coffset; + if (cmd != FN_ZERO) { + residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE); + /* this is a hack as version 0 differed in defintion of get_sr_golomb_shorten */ + if (s->version == 0) + residual_size--; + } - if (s->nmean == 0) - coffset = s->offset[channel][0]; - else { - int32_t sum = (s->version < 2) ? 0 : s->nmean / 2; - for (i=0; inmean; i++) - sum += s->offset[channel][i]; - coffset = sum / s->nmean; - if (s->version >= 2) - coffset >>= FFMIN(1, s->bitshift); + if (s->nmean == 0) + coffset = s->offset[channel][0]; + else { + int32_t sum = (s->version < 2) ? 0 : s->nmean / 2; + for (i=0; inmean; i++) + sum += s->offset[channel][i]; + coffset = sum / s->nmean; + if (s->version >= 2) + coffset >>= FFMIN(1, s->bitshift); + } + switch (cmd) { + case FN_ZERO: + for (i=0; iblocksize; i++) + s->decoded[channel][i] = 0; + break; + case FN_DIFF0: + for (i=0; iblocksize; i++) + s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + coffset; + break; + case FN_DIFF1: + for (i=0; iblocksize; i++) + s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + s->decoded[channel][i - 1]; + break; + case FN_DIFF2: + for (i=0; iblocksize; i++) + s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 2*s->decoded[channel][i-1] + - s->decoded[channel][i-2]; + break; + case FN_DIFF3: + for (i=0; iblocksize; i++) + s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 3*s->decoded[channel][i-1] + - 3*s->decoded[channel][i-2] + + s->decoded[channel][i-3]; + break; + case FN_QLPC: + { + int pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE); + if (pred_order > s->nwrap) { + av_log(avctx, AV_LOG_ERROR, + "invalid pred_order %d\n", + pred_order); + return -1; + } + for (i=0; idecoded[channel][i - pred_order] -= coffset; + decode_subframe_lpc(s, channel, residual_size, pred_order); + if (coffset != 0) + for (i=0; i < s->blocksize; i++) + s->decoded[channel][i] += coffset; } - switch (cmd) { - case FN_ZERO: - for (i=0; iblocksize; i++) - s->decoded[channel][i] = 0; - break; - case FN_DIFF0: - for (i=0; iblocksize; i++) - s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + coffset; - break; - case FN_DIFF1: - for (i=0; iblocksize; i++) - s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + s->decoded[channel][i - 1]; - break; - case FN_DIFF2: - for (i=0; iblocksize; i++) - s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 2*s->decoded[channel][i-1] - - s->decoded[channel][i-2]; - break; - case FN_DIFF3: - for (i=0; iblocksize; i++) - s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 3*s->decoded[channel][i-1] - - 3*s->decoded[channel][i-2] - + s->decoded[channel][i-3]; - break; - case FN_QLPC: - { - int pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE); - if (pred_order > s->nwrap) { - av_log(avctx, AV_LOG_ERROR, - "invalid pred_order %d\n", - pred_order); - return -1; - } - for (i=0; idecoded[channel][i - pred_order] -= coffset; - decode_subframe_lpc(s, channel, residual_size, pred_order); - if (coffset != 0) - for (i=0; i < s->blocksize; i++) - s->decoded[channel][i] += coffset; - } - } - if (s->nmean > 0) { - int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2; - for (i=0; iblocksize; i++) - sum += s->decoded[channel][i]; + } + if (s->nmean > 0) { + int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2; + for (i=0; iblocksize; i++) + sum += s->decoded[channel][i]; - for (i=1; inmean; i++) - s->offset[channel][i-1] = s->offset[channel][i]; + for (i=1; inmean; i++) + s->offset[channel][i-1] = s->offset[channel][i]; - if (s->version < 2) - s->offset[channel][s->nmean - 1] = sum / s->blocksize; - else - s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift; - } - for (i=-s->nwrap; i<0; i++) - s->decoded[channel][i] = s->decoded[channel][i + s->blocksize]; + if (s->version < 2) + s->offset[channel][s->nmean - 1] = sum / s->blocksize; + else + s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift; + } + for (i=-s->nwrap; i<0; i++) + s->decoded[channel][i] = s->decoded[channel][i + s->blocksize]; - fix_bitshift(s, s->decoded[channel]); + fix_bitshift(s, s->decoded[channel]); - s->cur_chan++; - if (s->cur_chan == s->channels) { - samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded); - s->cur_chan = 0; - goto frame_done; - } + s->cur_chan++; + if (s->cur_chan == s->channels) { + samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded); + s->cur_chan = 0; + goto frame_done; + } } } frame_done: From 0f97c5014b63f94ebffeb3b0f48c21bbe77b11f3 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 14 Sep 2011 18:54:42 -0400 Subject: [PATCH 14/47] shorten: only calculate output size when returning decoded samples, otherwise just set data_size to zero. --- libavcodec/shorten.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 62cead49e1..a4313aeb37 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -385,6 +385,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, int ret; if ((ret = read_header(s)) < 0) return ret; + *data_size = 0; } else { @@ -423,8 +424,9 @@ static int shorten_decode_frame(AVCodecContext *avctx, break; } case FN_QUIT: - goto frame_done; + break; } + *data_size = 0; } else { /* process audio command */ int residual_size = 0; @@ -510,12 +512,12 @@ static int shorten_decode_frame(AVCodecContext *avctx, if (s->cur_chan == s->channels) { samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded); s->cur_chan = 0; - goto frame_done; + *data_size = (int8_t *)samples - (int8_t *)data; + } else { + *data_size = 0; } } } -frame_done: - *data_size = (int8_t *)samples - (int8_t *)data; // s->last_blocksize = s->blocksize; s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8); From fe31a637f1ec5b8a22194d0f8d643c1a567b39b8 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 14 Sep 2011 19:16:14 -0400 Subject: [PATCH 15/47] shorten: move decoding of prediction order and applying of global offset to decode_subframe_lpc(). --- libavcodec/shorten.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index a4313aeb37..52bf2b2471 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -260,20 +260,41 @@ static int16_t * interleave_buffer(int16_t *samples, int nchan, int blocksize, i return samples; } -static void decode_subframe_lpc(ShortenContext *s, int channel, int residual_size, int pred_order) +static int decode_subframe_lpc(ShortenContext *s, int channel, + int residual_size, int32_t coffset) { - int sum, i, j; + int pred_order, sum, i, j; int *coeffs = s->coeffs; + /* read/validate prediction order */ + pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE); + if (pred_order > s->nwrap) { + av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n", pred_order); + return AVERROR(EINVAL); + } + /* read LPC coefficients */ for (i=0; igb, LPCQUANT); + /* subtract offset from previous samples to use in prediction */ + if (coffset) + for (i = -pred_order; i < 0; i++) + s->decoded[channel][i] -= coffset; + + /* decode residual and do LPC prediction */ for (i=0; i < s->blocksize; i++) { sum = s->lpcqoffset; for (j=0; jdecoded[channel][i-j-1]; s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> LPCQUANT); } + + /* add offset to current samples */ + if (coffset != 0) + for (i = 0; i < s->blocksize; i++) + s->decoded[channel][i] += coffset; + + return 0; } static int read_header(ShortenContext *s) @@ -429,6 +450,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, *data_size = 0; } else { /* process audio command */ + int ret; int residual_size = 0; int channel = s->cur_chan; int32_t coffset; @@ -474,21 +496,9 @@ static int shorten_decode_frame(AVCodecContext *avctx, + s->decoded[channel][i-3]; break; case FN_QLPC: - { - int pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE); - if (pred_order > s->nwrap) { - av_log(avctx, AV_LOG_ERROR, - "invalid pred_order %d\n", - pred_order); - return -1; - } - for (i=0; idecoded[channel][i - pred_order] -= coffset; - decode_subframe_lpc(s, channel, residual_size, pred_order); - if (coffset != 0) - for (i=0; i < s->blocksize; i++) - s->decoded[channel][i] += coffset; - } + if ((ret = decode_subframe_lpc(s, channel, residual_size, coffset)) < 0) + return ret; + break; } if (s->nmean > 0) { int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2; From 9e5e2c2d010c05c10337e9c1ec9d0d61495e0c9c Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 15 Sep 2011 18:08:52 -0400 Subject: [PATCH 16/47] shorten: check for realloc failure --- libavcodec/shorten.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 52bf2b2471..ad274b4b04 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -116,6 +116,7 @@ static int allocate_buffers(ShortenContext *s) { int i, chan; int *coeffs; + void *tmp_ptr; for (chan=0; chanchannels; chan++) { if(FFMAX(1, s->nmean) >= UINT_MAX/sizeof(int32_t)){ @@ -127,9 +128,15 @@ static int allocate_buffers(ShortenContext *s) return -1; } - s->offset[chan] = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean)); + tmp_ptr = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean)); + if (!tmp_ptr) + return AVERROR(ENOMEM); + s->offset[chan] = tmp_ptr; - s->decoded[chan] = av_realloc(s->decoded[chan], sizeof(int32_t)*(s->blocksize + s->nwrap)); + tmp_ptr = av_realloc(s->decoded[chan], sizeof(int32_t)*(s->blocksize + s->nwrap)); + if (!tmp_ptr) + return AVERROR(ENOMEM); + s->decoded[chan] = tmp_ptr; for (i=0; inwrap; i++) s->decoded[chan][i] = 0; s->decoded[chan] += s->nwrap; @@ -376,8 +383,15 @@ static int shorten_decode_frame(AVCodecContext *avctx, int i, input_buf_size = 0; int16_t *samples = data; if(s->max_framesize == 0){ + void *tmp_ptr; s->max_framesize= 1024; // should hopefully be enough for the first header - s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize); + tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, + s->max_framesize); + if (!tmp_ptr) { + av_log(avctx, AV_LOG_ERROR, "error allocating bitstream buffer\n"); + return AVERROR(ENOMEM); + } + s->bitstream = tmp_ptr; } if(1 && s->max_framesize){//FIXME truncated From a8055992c0a15b6fc76c593c8cbee9a611ca28ff Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 16 Sep 2011 11:22:37 -0400 Subject: [PATCH 17/47] shorten: pass on error value from allocate_buffers() instead of returning -1 --- libavcodec/shorten.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index ad274b4b04..638d886c4f 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -306,7 +306,7 @@ static int decode_subframe_lpc(ShortenContext *s, int channel, static int read_header(ShortenContext *s) { - int i; + int i, ret; int maxnlpc = 0; /* shorten signature */ if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) { @@ -342,8 +342,8 @@ static int read_header(ShortenContext *s) } s->nwrap = FFMAX(NWRAP, maxnlpc); - if (allocate_buffers(s)) - return -1; + if ((ret = allocate_buffers(s)) < 0) + return ret; init_offset(s); From 45d7d31fb94ded19de2bfdb064804e617c068879 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 16 Sep 2011 11:24:14 -0400 Subject: [PATCH 18/47] shorten: move declaration of 'ret' to top of shorten_decode_frame() --- libavcodec/shorten.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 638d886c4f..2502587604 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -382,6 +382,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, ShortenContext *s = avctx->priv_data; int i, input_buf_size = 0; int16_t *samples = data; + int ret; + if(s->max_framesize == 0){ void *tmp_ptr; s->max_framesize= 1024; // should hopefully be enough for the first header @@ -417,7 +419,6 @@ static int shorten_decode_frame(AVCodecContext *avctx, skip_bits(&s->gb, s->bitindex); if (!s->blocksize) { - int ret; if ((ret = read_header(s)) < 0) return ret; *data_size = 0; @@ -464,7 +465,6 @@ static int shorten_decode_frame(AVCodecContext *avctx, *data_size = 0; } else { /* process audio command */ - int ret; int residual_size = 0; int channel = s->cur_chan; int32_t coffset; From cfa317f67d023443c8f097524b367ec9c48f5c81 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 16 Sep 2011 15:31:31 -0400 Subject: [PATCH 19/47] shorten: validate block size --- libavcodec/shorten.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 2502587604..3f06e57084 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -330,8 +330,16 @@ static int read_header(ShortenContext *s) /* get blocksize if version > 0 */ if (s->version > 0) { - int skip_bytes; - s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE)); + int skip_bytes, blocksize; + + blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE)); + if (!blocksize || blocksize > MAX_BLOCKSIZE) { + av_log(s->avctx, AV_LOG_ERROR, "invalid or unsupported block size: %d\n", + blocksize); + return AVERROR(EINVAL); + } + s->blocksize = blocksize; + maxnlpc = get_uint(s, LPCQSIZE); s->nmean = get_uint(s, 0); @@ -456,6 +464,11 @@ static int shorten_decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "Increasing block size is not supported\n"); return AVERROR_PATCHWELCOME; } + if (!blocksize || blocksize > MAX_BLOCKSIZE) { + av_log(avctx, AV_LOG_ERROR, "invalid or unsupported " + "block size: %d\n", blocksize); + return AVERROR(EINVAL); + } s->blocksize = blocksize; break; } From 034f42dfce8ef8069959707bfbc6d0e79ab86885 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 16 Sep 2011 15:39:51 -0400 Subject: [PATCH 20/47] cosmetics: remove some needless commented-out stuff --- libavcodec/shorten.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 3f06e57084..aeb07d77e4 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -409,7 +409,6 @@ static int shorten_decode_frame(AVCodecContext *avctx, input_buf_size= buf_size; if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){ - // printf("memmove\n"); memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size); s->bitstream_index=0; } @@ -556,7 +555,6 @@ static int shorten_decode_frame(AVCodecContext *avctx, } } - // s->last_blocksize = s->blocksize; s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8); i= (get_bits_count(&s->gb))/8; if (i > buf_size) { From 15d146c958ec1af1935c2f2b2518f41e0e625d87 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 16 Sep 2011 15:55:27 -0400 Subject: [PATCH 21/47] shorten: merge decoding of FN_DIFF* subblocks into decode_subframe_lpc() --- libavcodec/shorten.c | 81 +++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index aeb07d77e4..f6f920ca7d 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -267,37 +267,54 @@ static int16_t * interleave_buffer(int16_t *samples, int nchan, int blocksize, i return samples; } -static int decode_subframe_lpc(ShortenContext *s, int channel, +static const int fixed_coeffs[3][3] = { + { 1, 0, 0 }, + { 2, -1, 0 }, + { 3, -3, 1 } +}; + +static int decode_subframe_lpc(ShortenContext *s, int command, int channel, int residual_size, int32_t coffset) { - int pred_order, sum, i, j; - int *coeffs = s->coeffs; + int pred_order, sum, qshift, init_sum, i, j; + const int *coeffs; - /* read/validate prediction order */ - pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE); - if (pred_order > s->nwrap) { - av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n", pred_order); - return AVERROR(EINVAL); + if (command == FN_QLPC) { + /* read/validate prediction order */ + pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE); + if (pred_order > s->nwrap) { + av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n", pred_order); + return AVERROR(EINVAL); + } + /* read LPC coefficients */ + for (i=0; icoeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT); + coeffs = s->coeffs; + + qshift = LPCQUANT; + } else { + /* fixed LPC coeffs */ + pred_order = command; + coeffs = fixed_coeffs[pred_order-1]; + qshift = 0; } - /* read LPC coefficients */ - for (i=0; igb, LPCQUANT); /* subtract offset from previous samples to use in prediction */ - if (coffset) + if (command == FN_QLPC && coffset) for (i = -pred_order; i < 0; i++) s->decoded[channel][i] -= coffset; /* decode residual and do LPC prediction */ + init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset; for (i=0; i < s->blocksize; i++) { - sum = s->lpcqoffset; + sum = init_sum; for (j=0; jdecoded[channel][i-j-1]; - s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> LPCQUANT); + s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> qshift); } /* add offset to current samples */ - if (coffset != 0) + if (command == FN_QLPC && coffset) for (i = 0; i < s->blocksize; i++) s->decoded[channel][i] += coffset; @@ -497,34 +514,12 @@ static int shorten_decode_frame(AVCodecContext *avctx, if (s->version >= 2) coffset >>= FFMIN(1, s->bitshift); } - switch (cmd) { - case FN_ZERO: - for (i=0; iblocksize; i++) - s->decoded[channel][i] = 0; - break; - case FN_DIFF0: - for (i=0; iblocksize; i++) - s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + coffset; - break; - case FN_DIFF1: - for (i=0; iblocksize; i++) - s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + s->decoded[channel][i - 1]; - break; - case FN_DIFF2: - for (i=0; iblocksize; i++) - s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 2*s->decoded[channel][i-1] - - s->decoded[channel][i-2]; - break; - case FN_DIFF3: - for (i=0; iblocksize; i++) - s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 3*s->decoded[channel][i-1] - - 3*s->decoded[channel][i-2] - + s->decoded[channel][i-3]; - break; - case FN_QLPC: - if ((ret = decode_subframe_lpc(s, channel, residual_size, coffset)) < 0) - return ret; - break; + if (cmd == FN_ZERO) { + for (i=0; iblocksize; i++) + s->decoded[channel][i] = 0; + } else { + if ((ret = decode_subframe_lpc(s, cmd, channel, residual_size, coffset)) < 0) + return ret; } if (s->nmean > 0) { int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2; From c25762fcf1dd61f6b38daf714d72070471e5f76d Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 16 Sep 2011 17:31:12 -0400 Subject: [PATCH 22/47] shorten: add some comments --- libavcodec/shorten.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index f6f920ca7d..a06eb3c497 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -409,6 +409,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, int16_t *samples = data; int ret; + /* allocate internal bitstream buffer */ if(s->max_framesize == 0){ void *tmp_ptr; s->max_framesize= 1024; // should hopefully be enough for the first header @@ -421,6 +422,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, s->bitstream = tmp_ptr; } + /* append current packet data to bitstream buffer */ if(1 && s->max_framesize){//FIXME truncated buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size); input_buf_size= buf_size; @@ -434,13 +436,17 @@ static int shorten_decode_frame(AVCodecContext *avctx, buf_size += s->bitstream_size; s->bitstream_size= buf_size; + /* do not decode until buffer has at least max_framesize bytes */ if(buf_size < s->max_framesize){ *data_size = 0; return input_buf_size; } } + /* init and position bitstream reader */ init_get_bits(&s->gb, buf, buf_size*8); skip_bits(&s->gb, s->bitindex); + + /* process header or next subblock */ if (!s->blocksize) { if ((ret = read_header(s)) < 0) @@ -497,6 +503,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, int residual_size = 0; int channel = s->cur_chan; int32_t coffset; + + /* get Rice code for residual decoding */ if (cmd != FN_ZERO) { residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE); /* this is a hack as version 0 differed in defintion of get_sr_golomb_shorten */ @@ -504,6 +512,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, residual_size--; } + /* calculate sample offset using means from previous blocks */ if (s->nmean == 0) coffset = s->offset[channel][0]; else { @@ -514,6 +523,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, if (s->version >= 2) coffset >>= FFMIN(1, s->bitshift); } + + /* decode samples for this channel */ if (cmd == FN_ZERO) { for (i=0; iblocksize; i++) s->decoded[channel][i] = 0; @@ -521,6 +532,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, if ((ret = decode_subframe_lpc(s, cmd, channel, residual_size, coffset)) < 0) return ret; } + + /* update means with info from the current block */ if (s->nmean > 0) { int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2; for (i=0; iblocksize; i++) @@ -534,11 +547,16 @@ static int shorten_decode_frame(AVCodecContext *avctx, else s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift; } + + /* copy wrap samples for use with next block */ for (i=-s->nwrap; i<0; i++) s->decoded[channel][i] = s->decoded[channel][i + s->blocksize]; + /* shift samples to add in unused zero bits which were removed + during encoding */ fix_bitshift(s, s->decoded[channel]); + /* if this is the last channel in the block, output the samples */ s->cur_chan++; if (s->cur_chan == s->channels) { samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded); From 069ada46c1445babdec543210b93d98f37ef618e Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 16 Sep 2011 17:40:44 -0400 Subject: [PATCH 23/47] shorten: use bytestream functions to decode the embedded WAVE header --- libavcodec/shorten.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index a06eb3c497..5ffd634e24 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -28,6 +28,7 @@ #include #include "avcodec.h" +#include "bytestream.h" #include "get_bits.h" #include "golomb.h" @@ -191,47 +192,37 @@ static void init_offset(ShortenContext *s) s->offset[chan][i] = mean; } -static inline int get_le32(GetBitContext *gb) +static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header, + int header_size) { - return av_bswap32(get_bits_long(gb, 32)); -} - -static inline short get_le16(GetBitContext *gb) -{ - return av_bswap16(get_bits_long(gb, 16)); -} - -static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header_size) -{ - GetBitContext hb; int len; short wave_format; - init_get_bits(&hb, header, header_size*8); - if (get_le32(&hb) != MKTAG('R','I','F','F')) { + + if (bytestream_get_le32(&header) != MKTAG('R','I','F','F')) { av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n"); return -1; } - skip_bits_long(&hb, 32); /* chunk_size */ + header += 4; /* chunk size */; - if (get_le32(&hb) != MKTAG('W','A','V','E')) { + if (bytestream_get_le32(&header) != MKTAG('W','A','V','E')) { av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n"); return -1; } - while (get_le32(&hb) != MKTAG('f','m','t',' ')) { - len = get_le32(&hb); - skip_bits(&hb, 8*len); + while (bytestream_get_le32(&header) != MKTAG('f','m','t',' ')) { + len = bytestream_get_le32(&header); + header += len; } - len = get_le32(&hb); + len = bytestream_get_le32(&header); if (len < 16) { av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n"); return -1; } - wave_format = get_le16(&hb); + wave_format = bytestream_get_le16(&header); switch (wave_format) { case WAVE_FORMAT_PCM: @@ -241,11 +232,11 @@ static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header return -1; } - skip_bits(&hb, 16); // skip channels (already got from shorten header) - avctx->sample_rate = get_le32(&hb); - skip_bits(&hb, 32); // skip bit rate (represents original uncompressed bit rate) - skip_bits(&hb, 16); // skip block align (not needed) - avctx->bits_per_coded_sample = get_le16(&hb); + header += 2; // skip channels (already got from shorten header) + avctx->sample_rate = bytestream_get_le32(&header); + header += 4; // skip bit rate (represents original uncompressed bit rate) + header += 2; // skip block align (not needed) + avctx->bits_per_coded_sample = bytestream_get_le16(&header); if (avctx->bits_per_coded_sample != 16) { av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample\n"); From bd7f7d6c7813ccf4ef1daaa7b01463f31fe7a7d4 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 16 Sep 2011 17:51:40 -0400 Subject: [PATCH 24/47] shorten: use av_clip_int16() for output sample clipping --- libavcodec/shorten.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 5ffd634e24..ec50fc1c6e 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -254,7 +254,7 @@ static int16_t * interleave_buffer(int16_t *samples, int nchan, int blocksize, i int i, chan; for (i=0; i Date: Fri, 16 Sep 2011 18:01:28 -0400 Subject: [PATCH 25/47] shorten: check output buffer size before decoding --- libavcodec/shorten.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index ec50fc1c6e..803175827d 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -550,9 +550,15 @@ static int shorten_decode_frame(AVCodecContext *avctx, /* if this is the last channel in the block, output the samples */ s->cur_chan++; if (s->cur_chan == s->channels) { + int out_size = s->blocksize * s->channels * + av_get_bytes_per_sample(avctx->sample_fmt); + if (*data_size < out_size) { + av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n"); + return AVERROR(EINVAL); + } samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded); s->cur_chan = 0; - *data_size = (int8_t *)samples - (int8_t *)data; + *data_size = out_size; } else { *data_size = 0; } From d03f9f65c090e29cfae5658e0a2e450b0e780346 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 16 Sep 2011 20:54:11 -0400 Subject: [PATCH 26/47] shorten: do not use block size to determine whether to read the header. --- libavcodec/shorten.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 803175827d..2732aabd5d 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -102,6 +102,7 @@ typedef struct ShortenContext { int blocksize; int bitindex; int32_t lpcqoffset; + int got_header; } ShortenContext; static av_cold int shorten_decode_init(AVCodecContext * avctx) @@ -386,6 +387,8 @@ static int read_header(ShortenContext *s) s->cur_chan = 0; s->bitshift = 0; + s->got_header = 1; + return 0; } @@ -438,8 +441,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, skip_bits(&s->gb, s->bitindex); /* process header or next subblock */ - if (!s->blocksize) - { + if (!s->got_header) { if ((ret = read_header(s)) < 0) return ret; *data_size = 0; From 1baa25c7dae0b43f0ff845f8ab4a94bf15b02440 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 16 Sep 2011 21:34:42 -0400 Subject: [PATCH 27/47] shorten: fix end-of-stream decoding. enable CODEC_CAP_DELAY to flush any remaining frames in the buffer. Stop decoding when the FN_QUIT command is found so that a trailing seek table isn't decoded as a normal frame. decode all channels in the same call to avcodec_decode_audio3() so that decoding will not stop after the first channel of the last frame. Updated FATE reference. More valid audio is now decoded. --- libavcodec/shorten.c | 47 +++++++++++++++++++--------- tests/ref/fate/lossless-shortenaudio | 2 +- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 2732aabd5d..f510bcc380 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -103,6 +103,7 @@ typedef struct ShortenContext { int bitindex; int32_t lpcqoffset; int got_header; + int got_quit_command; } ShortenContext; static av_cold int shorten_decode_init(AVCodecContext * avctx) @@ -425,13 +426,15 @@ static int shorten_decode_frame(AVCodecContext *avctx, memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size); s->bitstream_index=0; } - memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size); + if (buf) + memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size); buf= &s->bitstream[s->bitstream_index]; buf_size += s->bitstream_size; s->bitstream_size= buf_size; - /* do not decode until buffer has at least max_framesize bytes */ - if(buf_size < s->max_framesize){ + /* do not decode until buffer has at least max_framesize bytes or + the end of the file has been reached */ + if (buf_size < s->max_framesize && avpkt->data) { *data_size = 0; return input_buf_size; } @@ -445,20 +448,31 @@ static int shorten_decode_frame(AVCodecContext *avctx, if ((ret = read_header(s)) < 0) return ret; *data_size = 0; + goto finish_frame; } - else - { + + /* if quit command was read previously, don't decode anything */ + if (s->got_quit_command) { + *data_size = 0; + return avpkt->size; + } + + s->cur_chan = 0; + while (s->cur_chan < s->channels) { int cmd; int len; + + if (get_bits_left(&s->gb) < 3+FNSIZE) { + *data_size = 0; + break; + } + cmd = get_ur_golomb_shorten(&s->gb, FNSIZE); if (cmd > FN_VERBATIM) { av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd); - if (s->bitstream_size > 0) { - s->bitstream_index++; - s->bitstream_size--; - } - return -1; + *data_size = 0; + break; } if (!is_audio_command[cmd]) { @@ -488,9 +502,13 @@ static int shorten_decode_frame(AVCodecContext *avctx, break; } case FN_QUIT: + s->got_quit_command = 1; break; } - *data_size = 0; + if (cmd == FN_BLOCKSIZE || cmd == FN_QUIT) { + *data_size = 0; + break; + } } else { /* process audio command */ int residual_size = 0; @@ -559,14 +577,14 @@ static int shorten_decode_frame(AVCodecContext *avctx, return AVERROR(EINVAL); } samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded); - s->cur_chan = 0; *data_size = out_size; - } else { - *data_size = 0; } } } + if (s->cur_chan < s->channels) + *data_size = 0; +finish_frame: s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8); i= (get_bits_count(&s->gb))/8; if (i > buf_size) { @@ -606,5 +624,6 @@ AVCodec ff_shorten_decoder = { .init = shorten_decode_init, .close = shorten_decode_close, .decode = shorten_decode_frame, + .capabilities = CODEC_CAP_DELAY, .long_name= NULL_IF_CONFIG_SMALL("Shorten"), }; diff --git a/tests/ref/fate/lossless-shortenaudio b/tests/ref/fate/lossless-shortenaudio index 9448052733..9cdb3690e3 100644 --- a/tests/ref/fate/lossless-shortenaudio +++ b/tests/ref/fate/lossless-shortenaudio @@ -1 +1 @@ -9949141c405524f37ef1058b1ef4114b +da93c50961443b88fce416ae61c8ca8a From ffeeae923b03b2b923d58a3c2e00f728ceaf5f87 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 25 Sep 2011 17:05:34 -0400 Subject: [PATCH 28/47] avcodec: clarify documentation of CODEC_CAP_DELAY --- libavcodec/avcodec.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 06cede98ad..2e735f9acc 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -674,8 +674,10 @@ typedef struct RcOverride{ /* Codec can export data for HW decoding (XvMC). */ #define CODEC_CAP_HWACCEL 0x0010 /** - * Codec has a nonzero delay and needs to be fed with NULL at the end to get the delayed data. - * If this is not set, the codec is guaranteed to never be fed with NULL data. + * Codec has a nonzero delay and needs to be fed with avpkt->data=NULL, + * avpkt->size=0 at the end to get the delayed data until the decoder no longer + * returns frames. If this is not set, the codec is guaranteed to never be fed + * with NULL data. */ #define CODEC_CAP_DELAY 0x0020 /** From 352fc5f1286bff600890903bf4a1eb0ce0842fdc Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 25 Sep 2011 17:09:03 -0400 Subject: [PATCH 29/47] avcodec: clarify the CODEC_CAP_DELAY note in avcodec_decode_video2() --- libavcodec/avcodec.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 2e735f9acc..623da5e166 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3865,8 +3865,9 @@ int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, * * In practice, avpkt->data should have 4 byte alignment at minimum. * - * @note Some codecs have a delay between input and output, these need to be - * fed with avpkt->data=NULL, avpkt->size=0 at the end to return the remaining frames. + * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay + * between input and output, these need to be fed with avpkt->data=NULL, + * avpkt->size=0 at the end to return the remaining frames. * * @param avctx the codec context * @param[out] picture The AVFrame in which the decoded video frame will be stored. From 68d3aec819138183cedb11cd2783a830bc3a3866 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 25 Sep 2011 17:09:57 -0400 Subject: [PATCH 30/47] avcodec: add CODEC_CAP_DELAY note to avcodec_decode_audio3() documentation --- libavcodec/avcodec.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 623da5e166..a5fd2e7386 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3832,6 +3832,10 @@ int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options) * samples should be 16 byte aligned unless the CPU doesn't need it * (AltiVec and SSE do). * + * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay + * between input and output, these need to be fed with avpkt->data=NULL, + * avpkt->size=0 at the end to return the remaining frames. + * * @param avctx the codec context * @param[out] samples the output buffer, sample type in avctx->sample_fmt * @param[in,out] frame_size_ptr the output buffer size in bytes From 1fa395e471d563166f3fe3071fce8148e27679a8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 08:58:50 +0200 Subject: [PATCH 31/47] lavf: use avpriv_ prefix for ff_new_chapter(). It's used in libavdevice. --- libavdevice/libcdio.c | 2 +- libavformat/asfdec.c | 2 +- libavformat/ffmetadec.c | 2 +- libavformat/internal.h | 4 ++-- libavformat/matroskadec.c | 2 +- libavformat/mov.c | 4 ++-- libavformat/nutdec.c | 2 +- libavformat/oggparsevorbis.c | 2 +- libavformat/utils.c | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libavdevice/libcdio.c b/libavdevice/libcdio.c index bade74e5f0..6d0671a609 100644 --- a/libavdevice/libcdio.c +++ b/libavdevice/libcdio.c @@ -97,7 +97,7 @@ static av_cold int read_header(AVFormatContext *ctx, AVFormatParameters *ap) for (i = 0; i < s->drive->tracks; i++) { char title[16]; snprintf(title, sizeof(title), "track %02d", s->drive->disc_toc[i].bTrack); - ff_new_chapter(ctx, i, st->time_base, s->drive->disc_toc[i].dwStartSector, + avpriv_new_chapter(ctx, i, st->time_base, s->drive->disc_toc[i].dwStartSector, s->drive->disc_toc[i+1].dwStartSector, title); } diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c index 48ecec78b4..88091a5c9e 100644 --- a/libavformat/asfdec.c +++ b/libavformat/asfdec.c @@ -573,7 +573,7 @@ static int asf_read_marker(AVFormatContext *s, int64_t size) name_len = avio_rl32(pb); // name length if ((ret = avio_get_str16le(pb, name_len * 2, name, sizeof(name))) < name_len) avio_skip(pb, name_len - ret); - ff_new_chapter(s, i, (AVRational){1, 10000000}, pres_time, AV_NOPTS_VALUE, name ); + avpriv_new_chapter(s, i, (AVRational){1, 10000000}, pres_time, AV_NOPTS_VALUE, name ); } return 0; diff --git a/libavformat/ffmetadec.c b/libavformat/ffmetadec.c index b2415155f1..21e5ee9da4 100644 --- a/libavformat/ffmetadec.c +++ b/libavformat/ffmetadec.c @@ -75,7 +75,7 @@ static AVChapter *read_chapter(AVFormatContext *s) end = AV_NOPTS_VALUE; } - return ff_new_chapter(s, s->nb_chapters, tb, start, end, NULL); + return avpriv_new_chapter(s, s->nb_chapters, tb, start, end, NULL); } static uint8_t *unescape(uint8_t *buf, int size) diff --git a/libavformat/internal.h b/libavformat/internal.h index 8440e6bd0a..9ef9d64051 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -225,8 +225,8 @@ int ff_add_index_entry(AVIndexEntry **index_entries, * * @return AVChapter or NULL on error */ -AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, - int64_t start, int64_t end, const char *title); +AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, + int64_t start, int64_t end, const char *title); /** * Ensure the index uses less memory than the maximum specified in diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 78b27b6bd3..b3466db003 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1599,7 +1599,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) if (chapters[i].start != AV_NOPTS_VALUE && chapters[i].uid && (max_start==0 || chapters[i].start > max_start)) { chapters[i].chapter = - ff_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000}, + avpriv_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000}, chapters[i].start, chapters[i].end, chapters[i].title); av_dict_set(&chapters[i].chapter->metadata, diff --git a/libavformat/mov.c b/libavformat/mov.c index d93969ce2a..62c3be36a2 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -287,7 +287,7 @@ static int mov_read_chpl(MOVContext *c, AVIOContext *pb, MOVAtom atom) avio_read(pb, str, str_len); str[str_len] = 0; - ff_new_chapter(c->fc, i, (AVRational){1,10000000}, start, AV_NOPTS_VALUE, str); + avpriv_new_chapter(c->fc, i, (AVRational){1,10000000}, start, AV_NOPTS_VALUE, str); } return 0; } @@ -2420,7 +2420,7 @@ static void mov_read_chapters(AVFormatContext *s) } } - ff_new_chapter(s, i, st->time_base, sample->timestamp, end, title); + avpriv_new_chapter(s, i, st->time_base, sample->timestamp, end, title); av_freep(&title); } finish: diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index 730d6884cf..fb5ccf7fa9 100644 --- a/libavformat/nutdec.c +++ b/libavformat/nutdec.c @@ -416,7 +416,7 @@ static int decode_info_header(NUTContext *nut){ if(chapter_id && !stream_id_plus1){ int64_t start= chapter_start / nut->time_base_count; - chapter= ff_new_chapter(s, chapter_id, + chapter= avpriv_new_chapter(s, chapter_id, nut->time_base[chapter_start % nut->time_base_count], start, start + chapter_len, NULL); metadata = &chapter->metadata; diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index 86951f3e2f..8a406976b5 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -45,7 +45,7 @@ static int ogm_chapter(AVFormatContext *as, uint8_t *key, uint8_t *val) if (sscanf(val, "%02d:%02d:%02d.%03d", &h, &m, &s, &ms) < 4) return 0; - ff_new_chapter(as, cnum, (AVRational){1,1000}, + avpriv_new_chapter(as, cnum, (AVRational){1,1000}, ms + 1000*(s + 60*(m + 60*h)), AV_NOPTS_VALUE, NULL); av_free(val); diff --git a/libavformat/utils.c b/libavformat/utils.c index 5e3e60b198..1c1a7482e5 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2739,7 +2739,7 @@ AVProgram *av_new_program(AVFormatContext *ac, int id) return program; } -AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title) +AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title) { AVChapter *chapter = NULL; int i; From ab88b25f99a29b131ff72bf9a833425fe5db5a3b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 08:58:50 +0200 Subject: [PATCH 32/47] lavf: use avpriv_ prefix for some dv functions. They are used in libavdevice. --- libavdevice/dv1394.c | 6 +++--- libavformat/avidec.c | 6 +++--- libavformat/dv.c | 12 ++++++------ libavformat/dv.h | 6 +++--- libavformat/mov.c | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/libavdevice/dv1394.c b/libavdevice/dv1394.c index 3e286dcb4c..1ac9a81c97 100644 --- a/libavdevice/dv1394.c +++ b/libavdevice/dv1394.c @@ -86,7 +86,7 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap { struct dv1394_data *dv = context->priv_data; - dv->dv_demux = dv_init_demux(context); + dv->dv_demux = avpriv_dv_init_demux(context); if (!dv->dv_demux) goto failed; @@ -124,7 +124,7 @@ static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt) struct dv1394_data *dv = context->priv_data; int size; - size = dv_get_packet(dv->dv_demux, pkt); + size = avpriv_dv_get_packet(dv->dv_demux, pkt); if (size > 0) return size; @@ -186,7 +186,7 @@ restart_poll: av_dlog(context, "index %d, avail %d, done %d\n", dv->index, dv->avail, dv->done); - size = dv_produce_packet(dv->dv_demux, pkt, + size = avpriv_dv_produce_packet(dv->dv_demux, pkt, dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE), DV1394_PAL_FRAME_SIZE); dv->index = (dv->index + 1) % DV1394_RING_FRAMES; diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 71aa0365d3..68d652a120 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -462,7 +462,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) av_freep(&s->streams[0]); s->nb_streams = 0; if (CONFIG_DV_DEMUXER) { - avi->dv_demux = dv_init_demux(s); + avi->dv_demux = avpriv_dv_init_demux(s); if (!avi->dv_demux) goto fail; } @@ -979,7 +979,7 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) void* dstr; if (CONFIG_DV_DEMUXER && avi->dv_demux) { - int size = dv_get_packet(avi->dv_demux, pkt); + int size = avpriv_dv_get_packet(avi->dv_demux, pkt); if (size >= 0) return size; } @@ -1079,7 +1079,7 @@ resync: if (CONFIG_DV_DEMUXER && avi->dv_demux) { dstr = pkt->destruct; - size = dv_produce_packet(avi->dv_demux, pkt, + size = avpriv_dv_produce_packet(avi->dv_demux, pkt, pkt->data, pkt->size); pkt->destruct = dstr; pkt->flags |= AV_PKT_FLAG_KEY; diff --git a/libavformat/dv.c b/libavformat/dv.c index 5b229e9f07..5b6fb6210b 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -270,7 +270,7 @@ static int dv_extract_video_info(DVDemuxContext *c, uint8_t* frame) * The following 3 functions constitute our interface to the world */ -DVDemuxContext* dv_init_demux(AVFormatContext *s) +DVDemuxContext* avpriv_dv_init_demux(AVFormatContext *s) { DVDemuxContext *c; @@ -299,7 +299,7 @@ DVDemuxContext* dv_init_demux(AVFormatContext *s) return c; } -int dv_get_packet(DVDemuxContext *c, AVPacket *pkt) +int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt) { int size = -1; int i; @@ -316,7 +316,7 @@ int dv_get_packet(DVDemuxContext *c, AVPacket *pkt) return size; } -int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, +int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, uint8_t* buf, int buf_size) { int size, i; @@ -407,7 +407,7 @@ static int dv_read_header(AVFormatContext *s, unsigned state, marker_pos = 0; RawDVContext *c = s->priv_data; - c->dv_demux = dv_init_demux(s); + c->dv_demux = avpriv_dv_init_demux(s); if (!c->dv_demux) return -1; @@ -450,7 +450,7 @@ static int dv_read_packet(AVFormatContext *s, AVPacket *pkt) int size; RawDVContext *c = s->priv_data; - size = dv_get_packet(c->dv_demux, pkt); + size = avpriv_dv_get_packet(c->dv_demux, pkt); if (size < 0) { if (!c->dv_demux->sys) @@ -459,7 +459,7 @@ static int dv_read_packet(AVFormatContext *s, AVPacket *pkt) if (avio_read(s->pb, c->buf, size) <= 0) return AVERROR(EIO); - size = dv_produce_packet(c->dv_demux, pkt, c->buf, size); + size = avpriv_dv_produce_packet(c->dv_demux, pkt, c->buf, size); } return size; diff --git a/libavformat/dv.h b/libavformat/dv.h index 650699d2d7..b4bb10d4bc 100644 --- a/libavformat/dv.h +++ b/libavformat/dv.h @@ -31,9 +31,9 @@ #include "avformat.h" typedef struct DVDemuxContext DVDemuxContext; -DVDemuxContext* dv_init_demux(AVFormatContext* s); -int dv_get_packet(DVDemuxContext*, AVPacket *); -int dv_produce_packet(DVDemuxContext*, AVPacket*, uint8_t*, int); +DVDemuxContext* avpriv_dv_init_demux(AVFormatContext* s); +int avpriv_dv_get_packet(DVDemuxContext*, AVPacket *); +int avpriv_dv_produce_packet(DVDemuxContext*, AVPacket*, uint8_t*, int); void dv_offset_reset(DVDemuxContext *c, int64_t frame_offset); typedef struct DVMuxContext DVMuxContext; diff --git a/libavformat/mov.c b/libavformat/mov.c index 62c3be36a2..6baddebb82 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1249,7 +1249,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) #if CONFIG_DV_DEMUXER case CODEC_ID_DVAUDIO: c->dv_fctx = avformat_alloc_context(); - c->dv_demux = dv_init_demux(c->dv_fctx); + c->dv_demux = avpriv_dv_init_demux(c->dv_fctx); if (!c->dv_demux) { av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n"); return -1; @@ -2528,10 +2528,10 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) } #if CONFIG_DV_DEMUXER if (mov->dv_demux && sc->dv_audio_container) { - dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size); + avpriv_dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size); av_free(pkt->data); pkt->size = 0; - ret = dv_get_packet(mov->dv_demux, pkt); + ret = avpriv_dv_get_packet(mov->dv_demux, pkt); if (ret < 0) return ret; } From 8d74bf17c6d6280195854f4dadb19ef37d054566 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 09:14:04 +0200 Subject: [PATCH 33/47] lavf: hide private symbols. Overhead as reported by rbelf-size goes from 40147 to 20877. --- libavformat/libavformat.v | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/libavformat/libavformat.v b/libavformat/libavformat.v index 0ec1c3c4de..2a49539f0a 100644 --- a/libavformat/libavformat.v +++ b/libavformat/libavformat.v @@ -1,7 +1,23 @@ LIBAVFORMAT_$MAJOR { - global: *; - local: - ff_*_demuxer; - ff_*_muxer; - ff_*_protocol; + 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_*; + local: *; }; From 73ae27e17be5fd0a4e34e7ea8a449ca59bc09664 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 09:22:04 +0200 Subject: [PATCH 34/47] lavc: use avpriv_ prefix for ff_aac_parse_header(). It's used in lavf. --- libavcodec/aac_adtstoasc_bsf.c | 2 +- libavcodec/aac_parser.c | 2 +- libavcodec/aacadtsdec.c | 2 +- libavcodec/aacadtsdec.h | 2 +- libavcodec/aacdec.c | 2 +- libavformat/spdifdec.c | 2 +- libavformat/spdifenc.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/aac_adtstoasc_bsf.c b/libavcodec/aac_adtstoasc_bsf.c index d1310c4149..be12e99587 100644 --- a/libavcodec/aac_adtstoasc_bsf.c +++ b/libavcodec/aac_adtstoasc_bsf.c @@ -55,7 +55,7 @@ static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc, if (show_bits(&gb, 12) != 0xfff) return 0; - if (ff_aac_parse_header(&gb, &hdr) < 0) { + if (avpriv_aac_parse_header(&gb, &hdr) < 0) { av_log(avctx, AV_LOG_ERROR, "Error parsing ADTS frame header!\n"); return -1; } diff --git a/libavcodec/aac_parser.c b/libavcodec/aac_parser.c index 1c5546e7aa..ca016d1b89 100644 --- a/libavcodec/aac_parser.c +++ b/libavcodec/aac_parser.c @@ -40,7 +40,7 @@ static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info, tmp.u64 = av_be2ne64(state); init_get_bits(&bits, tmp.u8+8-AAC_ADTS_HEADER_SIZE, AAC_ADTS_HEADER_SIZE * 8); - if ((size = ff_aac_parse_header(&bits, &hdr)) < 0) + if ((size = avpriv_aac_parse_header(&bits, &hdr)) < 0) return 0; *need_next_header = 0; *new_frame_start = 1; diff --git a/libavcodec/aacadtsdec.c b/libavcodec/aacadtsdec.c index a9ff8ef63d..09bf1392c4 100644 --- a/libavcodec/aacadtsdec.c +++ b/libavcodec/aacadtsdec.c @@ -26,7 +26,7 @@ #include "get_bits.h" #include "mpeg4audio.h" -int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr) +int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr) { int size, rdb, ch, sr; int aot, crc_abs; diff --git a/libavcodec/aacadtsdec.h b/libavcodec/aacadtsdec.h index 2fa1b4b2fc..60fdd221a2 100644 --- a/libavcodec/aacadtsdec.h +++ b/libavcodec/aacadtsdec.h @@ -49,6 +49,6 @@ typedef struct { * -2 if the version element is invalid, -3 if the sample rate * element is invalid, or -4 if the bit rate element is invalid. */ -int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr); +int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr); #endif /* AVCODEC_AACADTSDEC_H */ diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index 8e7e74e10d..d03363d782 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -2075,7 +2075,7 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) int size; AACADTSHeaderInfo hdr_info; - size = ff_aac_parse_header(gb, &hdr_info); + size = avpriv_aac_parse_header(gb, &hdr_info); if (size > 0) { if (ac->output_configured != OC_LOCKED && hdr_info.chan_config) { enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; diff --git a/libavformat/spdifdec.c b/libavformat/spdifdec.c index 0cbbc54e0f..3daf23fb69 100644 --- a/libavformat/spdifdec.c +++ b/libavformat/spdifdec.c @@ -57,7 +57,7 @@ static int spdif_get_offset_and_codec(AVFormatContext *s, break; case IEC61937_MPEG2_AAC: init_get_bits(&gbc, buf, AAC_ADTS_HEADER_SIZE * 8); - if (ff_aac_parse_header(&gbc, &aac_hdr)) { + if (avpriv_aac_parse_header(&gbc, &aac_hdr)) { if (s) /* be silent during a probe */ av_log(s, AV_LOG_ERROR, "Invalid AAC packet in IEC 61937\n"); return AVERROR_INVALIDDATA; diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c index 9e571518d8..d541aba848 100644 --- a/libavformat/spdifenc.c +++ b/libavformat/spdifenc.c @@ -349,7 +349,7 @@ static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt) int ret; init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8); - ret = ff_aac_parse_header(&gbc, &hdr); + ret = avpriv_aac_parse_header(&gbc, &hdr); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Wrong AAC file format\n"); return AVERROR_INVALIDDATA; From 82ab61f9015659419e0a2766ee031c367e3f2908 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 09:28:53 +0200 Subject: [PATCH 35/47] lavc: use avpriv_ prefix for some mpegaudio symbols used in lavf. Specifically, ff_mpa_freq_tab, ff_mpa_bitrate_tab, ff_mpa_decode_header, ff_mpegaudio_decode_header. --- libavcodec/mp3_header_decompress_bsf.c | 4 ++-- libavcodec/mpegaudio_parser.c | 2 +- libavcodec/mpegaudiodata.c | 4 ++-- libavcodec/mpegaudiodata.h | 4 ++-- libavcodec/mpegaudiodec.c | 6 +++--- libavcodec/mpegaudiodecheader.c | 10 +++++----- libavcodec/mpegaudiodecheader.h | 4 ++-- libavcodec/mpegaudioenc.c | 6 +++--- libavformat/isom.c | 2 +- libavformat/mp3dec.c | 4 ++-- libavformat/mp3enc.c | 8 ++++---- libavformat/nutenc.c | 4 ++-- 12 files changed, 29 insertions(+), 29 deletions(-) diff --git a/libavcodec/mp3_header_decompress_bsf.c b/libavcodec/mp3_header_decompress_bsf.c index 3f3074286a..78025ccc41 100644 --- a/libavcodec/mp3_header_decompress_bsf.c +++ b/libavcodec/mp3_header_decompress_bsf.c @@ -50,10 +50,10 @@ static int mp3_header_decompress(AVBitStreamFilterContext *bsfc, AVCodecContext lsf = sample_rate < (24000+32000)/2; mpeg25 = sample_rate < (12000+16000)/2; sample_rate_index= (header>>10)&3; - sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off + sample_rate= avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off for(bitrate_index=2; bitrate_index<30; bitrate_index++){ - frame_size = ff_mpa_bitrate_tab[lsf][2][bitrate_index>>1]; + frame_size = avpriv_mpa_bitrate_tab[lsf][2][bitrate_index>>1]; frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); if(frame_size == buf_size + 4) break; diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c index f07d34bd29..17d329dc1c 100644 --- a/libavcodec/mpegaudio_parser.c +++ b/libavcodec/mpegaudio_parser.c @@ -64,7 +64,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1, state= (state<<8) + buf[i++]; - ret = ff_mpa_decode_header(avctx, state, &sr, &channels, &frame_size, &bit_rate); + ret = avpriv_mpa_decode_header(avctx, state, &sr, &channels, &frame_size, &bit_rate); if (ret < 4) { s->header_count= -2; } else { diff --git a/libavcodec/mpegaudiodata.c b/libavcodec/mpegaudiodata.c index b850d22c9e..81a43656a9 100644 --- a/libavcodec/mpegaudiodata.c +++ b/libavcodec/mpegaudiodata.c @@ -27,7 +27,7 @@ #include "mpegaudiodata.h" -const uint16_t ff_mpa_bitrate_tab[2][3][15] = { +const uint16_t avpriv_mpa_bitrate_tab[2][3][15] = { { {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 }, {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 }, {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } }, @@ -37,7 +37,7 @@ const uint16_t ff_mpa_bitrate_tab[2][3][15] = { } }; -const uint16_t ff_mpa_freq_tab[3] = { 44100, 48000, 32000 }; +const uint16_t avpriv_mpa_freq_tab[3] = { 44100, 48000, 32000 }; /*******************************************************/ /* half mpeg encoding window (full precision) */ diff --git a/libavcodec/mpegaudiodata.h b/libavcodec/mpegaudiodata.h index 84458836fa..24ea536a6c 100644 --- a/libavcodec/mpegaudiodata.h +++ b/libavcodec/mpegaudiodata.h @@ -32,8 +32,8 @@ #define MODE_EXT_MS_STEREO 2 #define MODE_EXT_I_STEREO 1 -extern const uint16_t ff_mpa_bitrate_tab[2][3][15]; -extern const uint16_t ff_mpa_freq_tab[3]; +extern const uint16_t avpriv_mpa_bitrate_tab[2][3][15]; +extern const uint16_t avpriv_mpa_freq_tab[3]; extern const int32_t ff_mpa_enwindow[257]; extern const int ff_mpa_sblimit_table[5]; extern const int ff_mpa_quant_steps[17]; diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 6f841e87b1..1b36937e69 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -1790,7 +1790,7 @@ static int decode_frame(AVCodecContext * avctx, return -1; } - if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) { + if (avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) { /* free format: prepare to compute frame size */ s->frame_size = -1; return -1; @@ -1863,7 +1863,7 @@ static int decode_frame_adu(AVCodecContext * avctx, return buf_size; } - ff_mpegaudio_decode_header((MPADecodeHeader *)s, header); + avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header); /* update codec info */ avctx->sample_rate = s->sample_rate; avctx->channels = s->nb_channels; @@ -2016,7 +2016,7 @@ static int decode_frame_mp3on4(AVCodecContext * avctx, if (ff_mpa_check_header(header) < 0) // Bad header, discard block break; - ff_mpegaudio_decode_header((MPADecodeHeader *)m, header); + avpriv_mpegaudio_decode_header((MPADecodeHeader *)m, header); out_size += mp_decode_frame(m, outptr, buf, fsize); buf += fsize; len -= fsize; diff --git a/libavcodec/mpegaudiodecheader.c b/libavcodec/mpegaudiodecheader.c index be7abc619d..dbd67ff0e3 100644 --- a/libavcodec/mpegaudiodecheader.c +++ b/libavcodec/mpegaudiodecheader.c @@ -31,7 +31,7 @@ #include "mpegaudiodecheader.h" -int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) +int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) { int sample_rate, frame_size, mpeg25, padding; int sample_rate_index, bitrate_index; @@ -46,7 +46,7 @@ int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) s->layer = 4 - ((header >> 17) & 3); /* extract frequency */ sample_rate_index = (header >> 10) & 3; - sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25); + sample_rate = avpriv_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25); sample_rate_index += 3 * (s->lsf + mpeg25); s->sample_rate_index = sample_rate_index; s->error_protection = ((header >> 16) & 1) ^ 1; @@ -67,7 +67,7 @@ int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) s->nb_channels = 2; if (bitrate_index != 0) { - frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index]; + frame_size = avpriv_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index]; s->bit_rate = frame_size * 1000; switch(s->layer) { case 1: @@ -109,14 +109,14 @@ int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) return 0; } -int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate) +int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate) { MPADecodeHeader s1, *s = &s1; if (ff_mpa_check_header(head) != 0) return -1; - if (ff_mpegaudio_decode_header(s, head) != 0) { + if (avpriv_mpegaudio_decode_header(s, head) != 0) { return -1; } diff --git a/libavcodec/mpegaudiodecheader.h b/libavcodec/mpegaudiodecheader.h index 2991595b02..764e8abde4 100644 --- a/libavcodec/mpegaudiodecheader.h +++ b/libavcodec/mpegaudiodecheader.h @@ -50,11 +50,11 @@ typedef struct MPADecodeHeader { /* header decoding. MUST check the header before because no consistency check is done there. Return 1 if free format found and that the frame size must be computed externally */ -int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header); +int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header); /* useful helper to get mpeg audio stream infos. Return -1 if error in header, otherwise the coded frame size in bytes */ -int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate); +int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate); /* fast header check for resync */ static inline int ff_mpa_check_header(uint32_t header){ diff --git a/libavcodec/mpegaudioenc.c b/libavcodec/mpegaudioenc.c index 1cadef7175..71ea39373e 100644 --- a/libavcodec/mpegaudioenc.c +++ b/libavcodec/mpegaudioenc.c @@ -84,9 +84,9 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx) /* encoding freq */ s->lsf = 0; for(i=0;i<3;i++) { - if (ff_mpa_freq_tab[i] == freq) + if (avpriv_mpa_freq_tab[i] == freq) break; - if ((ff_mpa_freq_tab[i] / 2) == freq) { + if ((avpriv_mpa_freq_tab[i] / 2) == freq) { s->lsf = 1; break; } @@ -99,7 +99,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx) /* encoding bitrate & frequency */ for(i=0;i<15;i++) { - if (ff_mpa_bitrate_tab[s->lsf][1][i] == bitrate) + if (avpriv_mpa_bitrate_tab[s->lsf][1][i] == bitrate) break; } if (i == 15){ diff --git a/libavformat/isom.c b/libavformat/isom.c index d7c0af101e..e5fd859472 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -437,7 +437,7 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext st->codec->extradata_size); st->codec->channels = cfg.channels; if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4 - st->codec->sample_rate = ff_mpa_freq_tab[cfg.sampling_index]; + st->codec->sample_rate = avpriv_mpa_freq_tab[cfg.sampling_index]; else if (cfg.ext_sample_rate) st->codec->sample_rate = cfg.ext_sample_rate; else diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 09494de136..9011f9f996 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -51,7 +51,7 @@ static int mp3_read_probe(AVProbeData *p) for(frames = 0; buf2 < end; frames++) { header = AV_RB32(buf2); - fsize = ff_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate); + fsize = avpriv_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate); if(fsize < 0) break; buf2 += fsize; @@ -86,7 +86,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base) if(ff_mpa_check_header(v) < 0) return -1; - if (ff_mpegaudio_decode_header(&c, v) == 0) + if (avpriv_mpegaudio_decode_header(&c, v) == 0) vbrtag_size = c.frame_size; if(c.layer != 3) return -1; diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index 07c28e176d..64f8957a4c 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -217,12 +217,12 @@ static void mp3_write_xing(AVFormatContext *s) MPADecodeHeader mpah; int srate_idx, i, channels; - for (i = 0; i < FF_ARRAY_ELEMS(ff_mpa_freq_tab); i++) - if (ff_mpa_freq_tab[i] == codec->sample_rate) { + for (i = 0; i < FF_ARRAY_ELEMS(avpriv_mpa_freq_tab); i++) + if (avpriv_mpa_freq_tab[i] == codec->sample_rate) { srate_idx = i; break; } - if (i == FF_ARRAY_ELEMS(ff_mpa_freq_tab)) { + if (i == FF_ARRAY_ELEMS(avpriv_mpa_freq_tab)) { av_log(s, AV_LOG_ERROR, "Unsupported sample rate.\n"); return; } @@ -240,7 +240,7 @@ static void mp3_write_xing(AVFormatContext *s) header |= channels << 6; avio_wb32(s->pb, header); - ff_mpegaudio_decode_header(&mpah, header); + avpriv_mpegaudio_decode_header(&mpah, header); ffio_fill(s->pb, 0, xing_offset); ffio_wfourcc(s->pb, "Xing"); diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index f8a078cb8a..bde6ba26a8 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -59,10 +59,10 @@ static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint else if(sample_rate < (44100 + 48000)/2) sample_rate_index=0; else sample_rate_index=1; - sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); + sample_rate= avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); for(bitrate_index=2; bitrate_index<30; bitrate_index++){ - frame_size = ff_mpa_bitrate_tab[lsf][layer-1][bitrate_index>>1]; + frame_size = avpriv_mpa_bitrate_tab[lsf][layer-1][bitrate_index>>1]; frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); if(frame_size == size) From 59a9a235811dc5f6a2c8b631a320968a06a867d1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 09:28:53 +0200 Subject: [PATCH 36/47] lavc: use avpriv_ prefix for some mpeg4audio symbols used in lavf. Specifically, ff_mpeg4audio_sample_rates, ff_mpeg4audio_get_config and ff_copy_pce_data --- libavcodec/aac_adtstoasc_bsf.c | 2 +- libavcodec/aacadtsdec.c | 4 ++-- libavcodec/aacdec.c | 2 +- libavcodec/aacenc.c | 2 +- libavcodec/alsdec.c | 2 +- libavcodec/libvo-aacenc.c | 2 +- libavcodec/mpeg4audio.c | 8 ++++---- libavcodec/mpeg4audio.h | 6 +++--- libavcodec/mpegaudiodec.c | 2 +- libavformat/adtsenc.c | 4 ++-- libavformat/flvdec.c | 2 +- libavformat/isom.c | 2 +- libavformat/latmenc.c | 4 ++-- libavformat/matroskadec.c | 4 ++-- libavformat/matroskaenc.c | 2 +- libavformat/sdp.c | 2 +- 16 files changed, 25 insertions(+), 25 deletions(-) diff --git a/libavcodec/aac_adtstoasc_bsf.c b/libavcodec/aac_adtstoasc_bsf.c index be12e99587..55181bbf55 100644 --- a/libavcodec/aac_adtstoasc_bsf.c +++ b/libavcodec/aac_adtstoasc_bsf.c @@ -78,7 +78,7 @@ static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc, return -1; } init_put_bits(&pb, pce_data, MAX_PCE_SIZE); - pce_size = ff_copy_pce_data(&pb, &gb)/8; + pce_size = avpriv_copy_pce_data(&pb, &gb)/8; flush_put_bits(&pb); buf_size -= get_bits_count(&gb)/8; buf += get_bits_count(&gb)/8; diff --git a/libavcodec/aacadtsdec.c b/libavcodec/aacadtsdec.c index 09bf1392c4..30f92e0b10 100644 --- a/libavcodec/aacadtsdec.c +++ b/libavcodec/aacadtsdec.c @@ -39,7 +39,7 @@ int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr) crc_abs = get_bits1(gbc); /* protection_absent */ aot = get_bits(gbc, 2); /* profile_objecttype */ sr = get_bits(gbc, 4); /* sample_frequency_index */ - if(!ff_mpeg4audio_sample_rates[sr]) + if(!avpriv_mpeg4audio_sample_rates[sr]) return AAC_AC3_PARSE_ERROR_SAMPLE_RATE; skip_bits1(gbc); /* private_bit */ ch = get_bits(gbc, 3); /* channel_configuration */ @@ -62,7 +62,7 @@ int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr) hdr->crc_absent = crc_abs; hdr->num_aac_frames = rdb + 1; hdr->sampling_index = sr; - hdr->sample_rate = ff_mpeg4audio_sample_rates[sr]; + hdr->sample_rate = avpriv_mpeg4audio_sample_rates[sr]; hdr->samples = (rdb + 1) * 1024; hdr->bit_rate = size * 8 * hdr->sample_rate / hdr->samples; diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index d03363d782..a3a6b429d5 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -470,7 +470,7 @@ static int decode_audio_specific_config(AACContext *ac, init_get_bits(&gb, data, data_size * 8); - if ((i = ff_mpeg4audio_get_config(m4ac, data, data_size)) < 0) + if ((i = avpriv_mpeg4audio_get_config(m4ac, data, data_size)) < 0) return -1; if (m4ac->sampling_index > 12) { av_log(avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", m4ac->sampling_index); diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index d5021a4f51..31d740f57a 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -171,7 +171,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) avctx->frame_size = 1024; for (i = 0; i < 16; i++) - if (avctx->sample_rate == ff_mpeg4audio_sample_rates[i]) + if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i]) break; if (i == 16) { av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", avctx->sample_rate); diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index 1ab72ad4dd..4301fab72f 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -289,7 +289,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx) init_get_bits(&gb, avctx->extradata, avctx->extradata_size * 8); - config_offset = ff_mpeg4audio_get_config(&m4ac, avctx->extradata, + config_offset = avpriv_mpeg4audio_get_config(&m4ac, avctx->extradata, avctx->extradata_size); if (config_offset < 0) diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c index 18aa8240d8..647971a892 100644 --- a/libavcodec/libvo-aacenc.c +++ b/libavcodec/libvo-aacenc.c @@ -63,7 +63,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) } for (index = 0; index < 16; index++) - if (avctx->sample_rate == ff_mpeg4audio_sample_rates[index]) + if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[index]) break; if (index == 16) { av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", diff --git a/libavcodec/mpeg4audio.c b/libavcodec/mpeg4audio.c index f0399af8fe..aa5ae4d463 100644 --- a/libavcodec/mpeg4audio.c +++ b/libavcodec/mpeg4audio.c @@ -52,7 +52,7 @@ static int parse_config_ALS(GetBitContext *gb, MPEG4AudioConfig *c) return 0; } -const int ff_mpeg4audio_sample_rates[16] = { +const int avpriv_mpeg4audio_sample_rates[16] = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 }; @@ -73,10 +73,10 @@ static inline int get_sample_rate(GetBitContext *gb, int *index) { *index = get_bits(gb, 4); return *index == 0x0f ? get_bits(gb, 24) : - ff_mpeg4audio_sample_rates[*index]; + avpriv_mpeg4audio_sample_rates[*index]; } -int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size) +int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size) { GetBitContext gb; int specific_config_bitindex; @@ -151,7 +151,7 @@ static av_always_inline unsigned int copy_bits(PutBitContext *pb, return el; } -int ff_copy_pce_data(PutBitContext *pb, GetBitContext *gb) +int avpriv_copy_pce_data(PutBitContext *pb, GetBitContext *gb) { int five_bit_ch, four_bit_ch, comment_size, bits; int offset = put_bits_count(pb); diff --git a/libavcodec/mpeg4audio.h b/libavcodec/mpeg4audio.h index c729c04660..d6730b97b3 100644 --- a/libavcodec/mpeg4audio.h +++ b/libavcodec/mpeg4audio.h @@ -40,7 +40,7 @@ typedef struct { int ps; ///< -1 implicit, 1 presence } MPEG4AudioConfig; -extern const int ff_mpeg4audio_sample_rates[16]; +extern const int avpriv_mpeg4audio_sample_rates[16]; extern const uint8_t ff_mpeg4audio_channels[8]; /** * Parse MPEG-4 systems extradata to retrieve audio configuration. @@ -49,7 +49,7 @@ extern const uint8_t ff_mpeg4audio_channels[8]; * @param[in] buf_size Extradata size. * @return On error -1 is returned, on success AudioSpecificConfig bit index in extradata. */ -int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size); +int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size); enum AudioObjectType { AOT_NULL, @@ -101,6 +101,6 @@ enum AudioObjectType { #define MAX_PCE_SIZE 304 ///extradata, avctx->extradata_size); + avpriv_mpeg4audio_get_config(&cfg, avctx->extradata, avctx->extradata_size); if (!cfg.chan_config || cfg.chan_config > 7) { av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n"); return -1; diff --git a/libavformat/adtsenc.c b/libavformat/adtsenc.c index 7f61e948fb..ce002fe4db 100644 --- a/libavformat/adtsenc.c +++ b/libavformat/adtsenc.c @@ -35,7 +35,7 @@ int ff_adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf int off; init_get_bits(&gb, buf, size * 8); - off = ff_mpeg4audio_get_config(&m4ac, buf, size); + off = avpriv_mpeg4audio_get_config(&m4ac, buf, size); if (off < 0) return off; skip_bits_long(&gb, off); @@ -67,7 +67,7 @@ int ff_adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf init_put_bits(&pb, adts->pce_data, MAX_PCE_SIZE); put_bits(&pb, 3, 5); //ID_PCE - adts->pce_size = (ff_copy_pce_data(&pb, &gb) + 3) / 8; + adts->pce_size = (avpriv_copy_pce_data(&pb, &gb) + 3) / 8; flush_put_bits(&pb); } diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 5e354b11be..395c8f8a57 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -531,7 +531,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) return ret; if (st->codec->codec_id == CODEC_ID_AAC) { MPEG4AudioConfig cfg; - ff_mpeg4audio_get_config(&cfg, st->codec->extradata, + avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata, st->codec->extradata_size); st->codec->channels = cfg.channels; if (cfg.ext_sample_rate) diff --git a/libavformat/isom.c b/libavformat/isom.c index e5fd859472..c5b01f22e3 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -433,7 +433,7 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext st->codec->extradata_size = len; if (st->codec->codec_id == CODEC_ID_AAC) { MPEG4AudioConfig cfg; - ff_mpeg4audio_get_config(&cfg, st->codec->extradata, + avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata, st->codec->extradata_size); st->codec->channels = cfg.channels; if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4 diff --git a/libavformat/latmenc.c b/libavformat/latmenc.c index 7c6d1eaf72..2e72c489bc 100644 --- a/libavformat/latmenc.c +++ b/libavformat/latmenc.c @@ -54,7 +54,7 @@ static int latm_decode_extradata(LATMContext *ctx, uint8_t *buf, int size) MPEG4AudioConfig m4ac; init_get_bits(&gb, buf, size * 8); - ctx->off = ff_mpeg4audio_get_config(&m4ac, buf, size); + ctx->off = avpriv_mpeg4audio_get_config(&m4ac, buf, size); if (ctx->off < 0) return ctx->off; skip_bits_long(&gb, ctx->off); @@ -111,7 +111,7 @@ static int latm_write_frame_header(AVFormatContext *s, PutBitContext *bs) ff_copy_bits(bs, avctx->extradata, ctx->off + 3); if (!ctx->channel_conf) { - ff_copy_pce_data(bs, &gb); + avpriv_copy_pce_data(bs, &gb); } } diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index b3466db003..8ee3698ac4 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1263,8 +1263,8 @@ static int matroska_aac_sri(int samplerate) { int sri; - for (sri=0; sriextradata, codec->extradata_size) < 0) { + if (avpriv_mpeg4audio_get_config(&mp4ac, codec->extradata, codec->extradata_size) < 0) { av_log(s, AV_LOG_WARNING, "Error parsing AAC extradata, unable to determine samplerate.\n"); return; } diff --git a/libavformat/sdp.c b/libavformat/sdp.c index a586690d3f..5adf14dfd1 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -342,7 +342,7 @@ static char *latm_context2config(AVCodecContext *c) char *config; for (rate_index = 0; rate_index < 16; rate_index++) - if (ff_mpeg4audio_sample_rates[rate_index] == c->sample_rate) + if (avpriv_mpeg4audio_sample_rates[rate_index] == c->sample_rate) break; if (rate_index == 16) { av_log(c, AV_LOG_ERROR, "Unsupported sample rate\n"); From d9cca9fc6a4796c0a4235b25f5f7fd7191813f3a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 09:28:53 +0200 Subject: [PATCH 37/47] lavc: use avpriv_ prefix for some flac symbols used in lavf. Specifically, ff_flac_parse_streaminfo, ff_flac_is_extradata_valid and ff_flac_parse_block_header --- libavcodec/flac.h | 14 +++++++------- libavcodec/flacdec.c | 16 ++++++++-------- libavformat/flacdec.c | 4 ++-- libavformat/flacenc.c | 2 +- libavformat/flacenc_header.c | 2 +- libavformat/oggenc.c | 2 +- libavformat/oggparseflac.c | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libavcodec/flac.h b/libavcodec/flac.h index 6ec8a3752d..b826fd43bd 100644 --- a/libavcodec/flac.h +++ b/libavcodec/flac.h @@ -95,8 +95,8 @@ typedef struct FLACFrameInfo { * @param[out] s where parsed information is stored * @param[in] buffer pointer to start of 34-byte streaminfo data */ -void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, - const uint8_t *buffer); +void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, + const uint8_t *buffer); /** * Validate the FLAC extradata. @@ -105,9 +105,9 @@ void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, * @param[out] streaminfo_start pointer to start of 34-byte STREAMINFO data. * @return 1 if valid, 0 if not valid. */ -int ff_flac_is_extradata_valid(AVCodecContext *avctx, - enum FLACExtradataFormat *format, - uint8_t **streaminfo_start); +int avpriv_flac_is_extradata_valid(AVCodecContext *avctx, + enum FLACExtradataFormat *format, + uint8_t **streaminfo_start); /** * Parse the metadata block parameters from the header. @@ -116,8 +116,8 @@ int ff_flac_is_extradata_valid(AVCodecContext *avctx, * @param[out] type metadata block type * @param[out] size metadata block size */ -void ff_flac_parse_block_header(const uint8_t *block_header, - int *last, int *type, int *size); +void avpriv_flac_parse_block_header(const uint8_t *block_header, + int *last, int *type, int *size); /** * Calculate an estimate for the maximum frame size based on verbatim mode. diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c index 3eb117acf6..633a1386ae 100644 --- a/libavcodec/flacdec.c +++ b/libavcodec/flacdec.c @@ -63,7 +63,7 @@ typedef struct FLACContext { static void allocate_buffers(FLACContext *s); -int ff_flac_is_extradata_valid(AVCodecContext *avctx, +int avpriv_flac_is_extradata_valid(AVCodecContext *avctx, enum FLACExtradataFormat *format, uint8_t **streaminfo_start) { @@ -104,11 +104,11 @@ static av_cold int flac_decode_init(AVCodecContext *avctx) if (!avctx->extradata) return 0; - if (!ff_flac_is_extradata_valid(avctx, &format, &streaminfo)) + if (!avpriv_flac_is_extradata_valid(avctx, &format, &streaminfo)) return -1; /* initialize based on the demuxer-supplied streamdata header */ - ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo); + avpriv_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo); if (s->bps > 16) avctx->sample_fmt = AV_SAMPLE_FMT_S32; else @@ -140,7 +140,7 @@ static void allocate_buffers(FLACContext *s) } } -void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, +void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, const uint8_t *buffer) { GetBitContext gb; @@ -174,7 +174,7 @@ void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, dump_headers(avctx, s); } -void ff_flac_parse_block_header(const uint8_t *block_header, +void avpriv_flac_parse_block_header(const uint8_t *block_header, int *last, int *type, int *size) { int tmp = bytestream_get_byte(&block_header); @@ -201,12 +201,12 @@ static int parse_streaminfo(FLACContext *s, const uint8_t *buf, int buf_size) /* need more data */ return 0; } - ff_flac_parse_block_header(&buf[4], NULL, &metadata_type, &metadata_size); + avpriv_flac_parse_block_header(&buf[4], NULL, &metadata_type, &metadata_size); if (metadata_type != FLAC_METADATA_TYPE_STREAMINFO || metadata_size != FLAC_STREAMINFO_SIZE) { return AVERROR_INVALIDDATA; } - ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, &buf[8]); + avpriv_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, &buf[8]); allocate_buffers(s); s->got_streaminfo = 1; @@ -228,7 +228,7 @@ static int get_metadata_size(const uint8_t *buf, int buf_size) do { if (buf_end - buf < 4) return 0; - ff_flac_parse_block_header(buf, &metadata_last, NULL, &metadata_size); + avpriv_flac_parse_block_header(buf, &metadata_last, NULL, &metadata_size); buf += 4; if (buf_end - buf < metadata_size) { /* need more data in order to read the complete header */ diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index e6098adf4a..41912854b7 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -48,7 +48,7 @@ static int flac_read_header(AVFormatContext *s, /* process metadata blocks */ while (!s->pb->eof_reached && !metadata_last) { avio_read(s->pb, header, 4); - ff_flac_parse_block_header(header, &metadata_last, &metadata_type, + avpriv_flac_parse_block_header(header, &metadata_last, &metadata_type, &metadata_size); switch (metadata_type) { /* allocate and read metadata block for supported types */ @@ -87,7 +87,7 @@ static int flac_read_header(AVFormatContext *s, buffer = NULL; /* get codec params from STREAMINFO header */ - ff_flac_parse_streaminfo(st->codec, &si, st->codec->extradata); + avpriv_flac_parse_streaminfo(st->codec, &si, st->codec->extradata); /* set time base and duration */ if (si.samplerate > 0) { diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c index f14b30b0c5..00e89002fe 100644 --- a/libavformat/flacenc.c +++ b/libavformat/flacenc.c @@ -94,7 +94,7 @@ static int flac_write_trailer(struct AVFormatContext *s) enum FLACExtradataFormat format; int64_t file_size; - if (!ff_flac_is_extradata_valid(s->streams[0]->codec, &format, &streaminfo)) + if (!avpriv_flac_is_extradata_valid(s->streams[0]->codec, &format, &streaminfo)) return -1; if (pb->seekable) { diff --git a/libavformat/flacenc_header.c b/libavformat/flacenc_header.c index 90c5a776d3..ad8d55b380 100644 --- a/libavformat/flacenc_header.c +++ b/libavformat/flacenc_header.c @@ -34,7 +34,7 @@ int ff_flac_write_header(AVIOContext *pb, AVCodecContext *codec, enum FLACExtradataFormat format; header[4] = last_block ? 0x80 : 0x00; - if (!ff_flac_is_extradata_valid(codec, &format, &streaminfo)) + if (!avpriv_flac_is_extradata_valid(codec, &format, &streaminfo)) return -1; /* write "fLaC" stream marker and first metadata block header if needed */ diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index 49dedb35d7..d554b07c5b 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -254,7 +254,7 @@ static int ogg_build_flac_headers(AVCodecContext *avctx, uint8_t *streaminfo; uint8_t *p; - if (!ff_flac_is_extradata_valid(avctx, &format, &streaminfo)) + if (!avpriv_flac_is_extradata_valid(avctx, &format, &streaminfo)) return -1; // first packet: STREAMINFO diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c index 53cd0fa582..e5f517fbdb 100644 --- a/libavformat/oggparseflac.c +++ b/libavformat/oggparseflac.c @@ -55,7 +55,7 @@ flac_header (AVFormatContext * s, int idx) if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE) return -1; - ff_flac_parse_streaminfo(st->codec, &si, streaminfo_start); + avpriv_flac_parse_streaminfo(st->codec, &si, streaminfo_start); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_FLAC; From 242c73a0fd664be8fc1d69cc3e383c13524914b5 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 09:28:53 +0200 Subject: [PATCH 38/47] lavc: use avpriv_ prefix for some dv symbols used in lavf. Specifically, ff_dv_frame_profile and ff_dv_codec_profile. --- libavcodec/dv.c | 6 +++--- libavcodec/dvdata.c | 4 ++-- libavcodec/dvdata.h | 6 +++--- libavformat/dv.c | 6 +++--- libavformat/dvenc.c | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libavcodec/dv.c b/libavcodec/dv.c index 976242235b..f16ed624e7 100644 --- a/libavcodec/dv.c +++ b/libavcodec/dv.c @@ -349,7 +349,7 @@ static av_cold int dvvideo_init(AVCodecContext *avctx) static av_cold int dvvideo_init_encoder(AVCodecContext *avctx) { - if (!ff_dv_codec_profile(avctx)) { + if (!avpriv_dv_codec_profile(avctx)) { av_log(avctx, AV_LOG_ERROR, "Found no DV profile for %ix%i %s video\n", avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt)); return -1; @@ -1072,7 +1072,7 @@ static int dvvideo_decode_frame(AVCodecContext *avctx, const uint8_t* vsc_pack; int apt, is16_9; - s->sys = ff_dv_frame_profile(s->sys, buf, buf_size); + s->sys = avpriv_dv_frame_profile(s->sys, buf, buf_size); if (!s->sys || buf_size < s->sys->frame_size || dv_init_dynamic_tables(s->sys)) { av_log(avctx, AV_LOG_ERROR, "could not find dv frame profile\n"); return -1; /* NOTE: we only accept several full frames */ @@ -1245,7 +1245,7 @@ static int dvvideo_encode_frame(AVCodecContext *c, uint8_t *buf, int buf_size, { DVVideoContext *s = c->priv_data; - s->sys = ff_dv_codec_profile(c); + s->sys = avpriv_dv_codec_profile(c); if (!s->sys || buf_size < s->sys->frame_size || dv_init_dynamic_tables(s->sys)) return -1; diff --git a/libavcodec/dvdata.c b/libavcodec/dvdata.c index a80d2da803..3a135a9ac7 100644 --- a/libavcodec/dvdata.c +++ b/libavcodec/dvdata.c @@ -245,7 +245,7 @@ static const DVprofile dv_profiles[] = { } }; -const DVprofile* ff_dv_frame_profile(const DVprofile *sys, +const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys, const uint8_t* frame, unsigned buf_size) { int i; @@ -270,7 +270,7 @@ const DVprofile* ff_dv_frame_profile(const DVprofile *sys, return NULL; } -const DVprofile* ff_dv_codec_profile(AVCodecContext* codec) +const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec) { int i; diff --git a/libavcodec/dvdata.h b/libavcodec/dvdata.h index 817b50639f..b2fb127ae6 100644 --- a/libavcodec/dvdata.h +++ b/libavcodec/dvdata.h @@ -274,9 +274,9 @@ enum dv_pack_type { */ #define DV_MAX_BPM 8 -const DVprofile* ff_dv_frame_profile(const DVprofile *sys, - const uint8_t* frame, unsigned buf_size); -const DVprofile* ff_dv_codec_profile(AVCodecContext* codec); +const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys, + const uint8_t* frame, unsigned buf_size); +const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec); static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num, uint8_t seq_num, uint8_t dif_num, diff --git a/libavformat/dv.c b/libavformat/dv.c index 5b6fb6210b..2813bc3b67 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -323,7 +323,7 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, uint8_t *ppcm[4] = {0}; if (buf_size < DV_PROFILE_BYTES || - !(c->sys = ff_dv_frame_profile(c->sys, buf, buf_size)) || + !(c->sys = avpriv_dv_frame_profile(c->sys, buf, buf_size)) || buf_size < c->sys->frame_size) { return -1; /* Broken frame, or not enough data */ } @@ -369,7 +369,7 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c, int64_t timestamp, int flags) { // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk) - const DVprofile* sys = ff_dv_codec_profile(c->vst->codec); + const DVprofile* sys = avpriv_dv_codec_profile(c->vst->codec); int64_t offset; int64_t size = avio_size(s->pb) - s->data_offset; int64_t max_offset = ((size-1) / sys->frame_size) * sys->frame_size; @@ -432,7 +432,7 @@ static int dv_read_header(AVFormatContext *s, avio_seek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) return AVERROR(EIO); - c->dv_demux->sys = ff_dv_frame_profile(c->dv_demux->sys, c->buf, DV_PROFILE_BYTES); + c->dv_demux->sys = avpriv_dv_frame_profile(c->dv_demux->sys, c->buf, DV_PROFILE_BYTES); if (!c->dv_demux->sys) { av_log(s, AV_LOG_ERROR, "Can't determine profile of DV input stream.\n"); return -1; diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c index 5c55338e2c..bffad44b9f 100644 --- a/libavformat/dvenc.c +++ b/libavformat/dvenc.c @@ -325,7 +325,7 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s) c->ast[i]->codec->channels != 2)) goto bail_out; } - c->sys = ff_dv_codec_profile(vst->codec); + c->sys = avpriv_dv_codec_profile(vst->codec); if (!c->sys) goto bail_out; From 2361e59b98f1c78d9720e72aabfb847dd9906f12 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 09:45:27 +0200 Subject: [PATCH 39/47] lavc: use avpriv_ prefix for ff_dirac_parse_sequence_header. It's used in lavf. --- libavcodec/dirac.c | 2 +- libavcodec/dirac.h | 4 ++-- libavformat/oggparsedirac.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/dirac.c b/libavcodec/dirac.c index 09da1cbd56..543a342525 100644 --- a/libavcodec/dirac.c +++ b/libavcodec/dirac.c @@ -242,7 +242,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, return 0; } -int ff_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, +int avpriv_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, dirac_source_params *source) { unsigned version_major; diff --git a/libavcodec/dirac.h b/libavcodec/dirac.h index 0be66c2d91..f8063d9e28 100644 --- a/libavcodec/dirac.h +++ b/libavcodec/dirac.h @@ -51,7 +51,7 @@ typedef struct { uint8_t color_spec_index; ///< index into dirac_color_spec_presets[] } dirac_source_params; -int ff_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, - dirac_source_params *source); +int avpriv_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, + dirac_source_params *source); #endif /* AVCODEC_DIRAC_H */ diff --git a/libavformat/oggparsedirac.c b/libavformat/oggparsedirac.c index f6afafd0e4..9991d5692c 100644 --- a/libavformat/oggparsedirac.c +++ b/libavformat/oggparsedirac.c @@ -36,7 +36,7 @@ static int dirac_header(AVFormatContext *s, int idx) return 0; init_get_bits(&gb, os->buf + os->pstart + 13, (os->psize - 13) * 8); - if (ff_dirac_parse_sequence_header(st->codec, &gb, &source) < 0) + if (avpriv_dirac_parse_sequence_header(st->codec, &gb, &source) < 0) return -1; st->codec->codec_type = AVMEDIA_TYPE_VIDEO; From 357db4c263bb7edfd9790414f0f378e752f924e9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 09:45:27 +0200 Subject: [PATCH 40/47] lavc: use avpriv_ prefix for ff_split_xiph_headers. It's used in lavf. --- libavcodec/vorbisdec.c | 2 +- libavcodec/vp3.c | 2 +- libavcodec/xiph.c | 2 +- libavcodec/xiph.h | 6 +++--- libavformat/matroskaenc.c | 2 +- libavformat/oggenc.c | 2 +- libavformat/sdp.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c index 7c07de646a..2662a6cf15 100644 --- a/libavcodec/vorbisdec.c +++ b/libavcodec/vorbisdec.c @@ -987,7 +987,7 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext) return -1; } - if (ff_split_xiph_headers(headers, headers_len, 30, header_start, header_len) < 0) { + if (avpriv_split_xiph_headers(headers, headers_len, 30, header_start, header_len) < 0) { av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n"); return -1; } diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 9262c27f05..36715bb0c7 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -2275,7 +2275,7 @@ static av_cold int theora_decode_init(AVCodecContext *avctx) return -1; } - if (ff_split_xiph_headers(avctx->extradata, avctx->extradata_size, + if (avpriv_split_xiph_headers(avctx->extradata, avctx->extradata_size, 42, header_start, header_len) < 0) { av_log(avctx, AV_LOG_ERROR, "Corrupt extradata\n"); return -1; diff --git a/libavcodec/xiph.c b/libavcodec/xiph.c index 0bcfd45eea..7c3c7100c6 100644 --- a/libavcodec/xiph.c +++ b/libavcodec/xiph.c @@ -21,7 +21,7 @@ #include "libavutil/intreadwrite.h" #include "xiph.h" -int ff_split_xiph_headers(uint8_t *extradata, int extradata_size, +int avpriv_split_xiph_headers(uint8_t *extradata, int extradata_size, int first_header_size, uint8_t *header_start[3], int header_len[3]) { diff --git a/libavcodec/xiph.h b/libavcodec/xiph.h index da18c9c094..afaece7cee 100644 --- a/libavcodec/xiph.h +++ b/libavcodec/xiph.h @@ -36,8 +36,8 @@ * @param[out] header_len The sizes of each of the three headers. * @return On error a negative value is returned, on success zero. */ -int ff_split_xiph_headers(uint8_t *extradata, int extradata_size, - int first_header_size, uint8_t *header_start[3], - int header_len[3]); +int avpriv_split_xiph_headers(uint8_t *extradata, int extradata_size, + int first_header_size, uint8_t *header_start[3], + int header_len[3]); #endif /* AVCODEC_XIPH_H */ diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index a35a2fa09a..1adb479dd8 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -423,7 +423,7 @@ static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContex else first_header_size = 42; - if (ff_split_xiph_headers(codec->extradata, codec->extradata_size, + if (avpriv_split_xiph_headers(codec->extradata, codec->extradata_size, first_header_size, header_start, header_len) < 0) { av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n"); return -1; diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index d554b07c5b..7549b3a0a3 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -377,7 +377,7 @@ static int ogg_write_header(AVFormatContext *s) int header_type = st->codec->codec_id == CODEC_ID_VORBIS ? 3 : 0x81; int framing_bit = st->codec->codec_id == CODEC_ID_VORBIS ? 1 : 0; - if (ff_split_xiph_headers(st->codec->extradata, st->codec->extradata_size, + if (avpriv_split_xiph_headers(st->codec->extradata, st->codec->extradata_size, st->codec->codec_id == CODEC_ID_VORBIS ? 30 : 42, oggstream->header, oggstream->header_len) < 0) { av_log(s, AV_LOG_ERROR, "Extradata corrupted\n"); diff --git a/libavformat/sdp.c b/libavformat/sdp.c index 5adf14dfd1..ba3d4dd611 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -252,7 +252,7 @@ static char *xiph_extradata2config(AVCodecContext *c) return NULL; } - if (ff_split_xiph_headers(c->extradata, c->extradata_size, + if (avpriv_split_xiph_headers(c->extradata, c->extradata_size, first_header_size, header_start, header_len) < 0) { av_log(c, AV_LOG_ERROR, "Extradata corrupt.\n"); From 773375c3d04bc3436563d7128311f06767432e22 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 09:51:55 +0200 Subject: [PATCH 41/47] lavc: rename ff_find_start_code to avpriv_mpv_find_start_code It's used in lavf. --- libavcodec/cavsdec.c | 2 +- libavcodec/h264_parser.c | 2 +- libavcodec/mpeg12.c | 8 ++++---- libavcodec/mpegvideo.c | 2 +- libavcodec/mpegvideo.h | 2 +- libavcodec/mpegvideo_parser.c | 2 +- libavformat/mpegtsenc.c | 2 +- libavformat/rtpenc_mpv.c | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index 88034068ff..ed3538c121 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -663,7 +663,7 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size, buf_ptr = buf; buf_end = buf + buf_size; for(;;) { - buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc); + buf_ptr = avpriv_mpv_find_start_code(buf_ptr,buf_end, &stc); if((stc & 0xFFFFFE00) || buf_ptr == buf_end) return FFMAX(0, buf_ptr - buf - s->parse_context.last_index); input_size = (buf_end - buf_ptr)*8; diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 56102691a8..52ff88b3a4 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -131,7 +131,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, for(;;) { int src_length, dst_length, consumed; - buf = ff_find_start_code(buf, buf_end, &state); + buf = avpriv_mpv_find_start_code(buf, buf_end, &state); if(buf >= buf_end) break; --buf; diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 4e95e02a9b..16e27e873a 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1697,7 +1697,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, if (avctx->hwaccel) { const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */ int start_code = -1; - buf_end = ff_find_start_code(buf_start + 2, *buf + buf_size, &start_code); + buf_end = avpriv_mpv_find_start_code(buf_start + 2, *buf + buf_size, &start_code); if (buf_end < *buf + buf_size) buf_end -= 4; s->mb_y = mb_y; @@ -1888,7 +1888,7 @@ static int slice_decode_thread(AVCodecContext *c, void *arg) return 0; start_code = -1; - buf = ff_find_start_code(buf, s->gb.buffer_end, &start_code); + buf = avpriv_mpv_find_start_code(buf, s->gb.buffer_end, &start_code); mb_y= (start_code - SLICE_MIN_START_CODE) << field_pic; if (s->picture_structure == PICT_BOTTOM_FIELD) mb_y++; @@ -2168,7 +2168,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, } state++; } else { - i = ff_find_start_code(buf + i, buf + buf_size, &state) - buf - 1; + i = avpriv_mpv_find_start_code(buf + i, buf + buf_size, &state) - buf - 1; if (pc->frame_start_found == 0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE) { i++; pc->frame_start_found = 4; @@ -2259,7 +2259,7 @@ static int decode_chunks(AVCodecContext *avctx, for (;;) { /* find next start code */ uint32_t start_code = -1; - buf_ptr = ff_find_start_code(buf_ptr, buf_end, &start_code); + buf_ptr = avpriv_mpv_find_start_code(buf_ptr, buf_end, &start_code); if (start_code > 0x1ff) { if (s2->pict_type != AV_PICTURE_TYPE_B || avctx->skip_frame <= AVDISCARD_DEFAULT) { if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) { diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index cbc7d99818..7b0cac19e3 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -122,7 +122,7 @@ const enum PixelFormat ff_hwaccel_pixfmt_list_420[] = { PIX_FMT_NONE }; -const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){ +const uint8_t *avpriv_mpv_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){ int i; assert(p<=end); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 7de72172b1..f1627c463b 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -719,7 +719,7 @@ void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src); int MPV_lowest_referenced_row(MpegEncContext *s, int dir); void MPV_report_decode_progress(MpegEncContext *s); int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src); -const uint8_t *ff_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state); +const uint8_t *avpriv_mpv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state); void ff_set_qscale(MpegEncContext * s, int qscale); void ff_er_frame_start(MpegEncContext *s); diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index 9688e18625..93001f7b14 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -40,7 +40,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, while (buf < buf_end) { start_code= -1; - buf= ff_find_start_code(buf, buf_end, &start_code); + buf= avpriv_mpv_find_start_code(buf, buf_end, &start_code); bytes_left = buf_end - buf; switch(start_code) { case PICTURE_START_CODE: diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index d600d18b62..9f45f13247 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -950,7 +950,7 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) } do { - p = ff_find_start_code(p, buf_end, &state); + p = avpriv_mpv_find_start_code(p, buf_end, &state); //av_log(s, AV_LOG_INFO, "nal %d\n", state & 0x1f); } while (p < buf_end && (state & 0x1f) != 9 && (state & 0x1f) != 5 && (state & 0x1f) != 1); diff --git a/libavformat/rtpenc_mpv.c b/libavformat/rtpenc_mpv.c index f6a5d7726a..1c67f9593b 100644 --- a/libavformat/rtpenc_mpv.c +++ b/libavformat/rtpenc_mpv.c @@ -56,7 +56,7 @@ void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size) r1 = buf1; while (1) { start_code = -1; - r = ff_find_start_code(r1, end, &start_code); + r = avpriv_mpv_find_start_code(r1, end, &start_code); if((start_code & 0xFFFFFF00) == 0x100) { /* New start code found */ if (start_code == 0x100) { From 9138a130cd69e6828da5796a0555eac5a0af2357 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 09:59:31 +0200 Subject: [PATCH 42/47] lavc: use avpriv_ prefix for ff_frame_rate_tab. It's used in lavf. --- libavcodec/cavsdec.c | 4 ++-- libavcodec/dirac.c | 2 +- libavcodec/mpeg12.c | 8 ++++---- libavcodec/mpeg12data.c | 2 +- libavcodec/mpeg12data.h | 2 +- libavcodec/mpeg12enc.c | 8 ++++---- libavcodec/mpegvideo_parser.c | 4 ++-- libavformat/gxf.c | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c index ed3538c121..514752afc9 100644 --- a/libavcodec/cavsdec.c +++ b/libavcodec/cavsdec.c @@ -624,8 +624,8 @@ static int decode_seq_header(AVSContext *h) { s->low_delay = get_bits1(&s->gb); h->mb_width = (s->width + 15) >> 4; h->mb_height = (s->height + 15) >> 4; - h->s.avctx->time_base.den = ff_frame_rate_tab[frame_rate_code].num; - h->s.avctx->time_base.num = ff_frame_rate_tab[frame_rate_code].den; + h->s.avctx->time_base.den = avpriv_frame_rate_tab[frame_rate_code].num; + h->s.avctx->time_base.num = avpriv_frame_rate_tab[frame_rate_code].den; h->s.avctx->width = s->width; h->s.avctx->height = s->height; if(!h->top_qp) diff --git a/libavcodec/dirac.c b/libavcodec/dirac.c index 543a342525..bf56088c75 100644 --- a/libavcodec/dirac.c +++ b/libavcodec/dirac.c @@ -145,7 +145,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, } if (source->frame_rate_index > 0) { if (source->frame_rate_index <= 8) - frame_rate = ff_frame_rate_tab[source->frame_rate_index]; + frame_rate = avpriv_frame_rate_tab[source->frame_rate_index]; else frame_rate = dirac_frame_rate[source->frame_rate_index-9]; } diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 16e27e873a..b7b8abd285 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1253,8 +1253,8 @@ static int mpeg_decode_postinit(AVCodecContext *avctx) assert((avctx->sub_id == 1) == (avctx->codec_id == CODEC_ID_MPEG1VIDEO)); if (avctx->codec_id == CODEC_ID_MPEG1VIDEO) { //MPEG-1 fps - avctx->time_base.den = ff_frame_rate_tab[s->frame_rate_index].num; - avctx->time_base.num = ff_frame_rate_tab[s->frame_rate_index].den; + avctx->time_base.den = avpriv_frame_rate_tab[s->frame_rate_index].num; + avctx->time_base.num = avpriv_frame_rate_tab[s->frame_rate_index].den; //MPEG-1 aspect avctx->sample_aspect_ratio = av_d2q(1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255); avctx->ticks_per_frame=1; @@ -1262,8 +1262,8 @@ static int mpeg_decode_postinit(AVCodecContext *avctx) //MPEG-2 fps av_reduce(&s->avctx->time_base.den, &s->avctx->time_base.num, - ff_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num*2, - ff_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den, + avpriv_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num*2, + avpriv_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den, 1 << 30); avctx->ticks_per_frame = 2; //MPEG-2 aspect diff --git a/libavcodec/mpeg12data.c b/libavcodec/mpeg12data.c index 299215f91e..5ac8c243a5 100644 --- a/libavcodec/mpeg12data.c +++ b/libavcodec/mpeg12data.c @@ -305,7 +305,7 @@ const uint8_t ff_mpeg12_mbMotionVectorTable[17][2] = { { 0xc, 10 }, }; -const AVRational ff_frame_rate_tab[] = { +const AVRational avpriv_frame_rate_tab[] = { { 0, 0}, {24000, 1001}, { 24, 1}, diff --git a/libavcodec/mpeg12data.h b/libavcodec/mpeg12data.h index 3586a614aa..86ba3ec15f 100644 --- a/libavcodec/mpeg12data.h +++ b/libavcodec/mpeg12data.h @@ -48,7 +48,7 @@ extern const uint8_t ff_mpeg12_mbPatTable[64][2]; extern const uint8_t ff_mpeg12_mbMotionVectorTable[17][2]; -extern const AVRational ff_frame_rate_tab[]; +extern const AVRational avpriv_frame_rate_tab[]; extern const float ff_mpeg1_aspect[16]; extern const AVRational ff_mpeg2_aspect[16]; diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index 90a26177ee..738af99d68 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -120,7 +120,7 @@ static int find_frame_rate_index(MpegEncContext *s){ int64_t d; for(i=1;i<14;i++) { - int64_t n0= 1001LL/ff_frame_rate_tab[i].den*ff_frame_rate_tab[i].num*s->avctx->time_base.num; + int64_t n0= 1001LL/avpriv_frame_rate_tab[i].den*avpriv_frame_rate_tab[i].num*s->avctx->time_base.num; int64_t n1= 1001LL*s->avctx->time_base.den; if(s->avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL && i>=9) break; @@ -211,7 +211,7 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s) if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA) if (s->current_picture.f.key_frame) { - AVRational framerate= ff_frame_rate_tab[s->frame_rate_index]; + AVRational framerate= avpriv_frame_rate_tab[s->frame_rate_index]; /* mpeg1 header repeated every gop */ put_header(s, SEQ_START_CODE); @@ -972,7 +972,7 @@ AVCodec ff_mpeg1video_encoder = { .init = encode_init, .encode = MPV_encode_picture, .close = MPV_encode_end, - .supported_framerates= ff_frame_rate_tab+1, + .supported_framerates= avpriv_frame_rate_tab+1, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .capabilities= CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS, .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), @@ -987,7 +987,7 @@ AVCodec ff_mpeg2video_encoder = { .init = encode_init, .encode = MPV_encode_picture, .close = MPV_encode_end, - .supported_framerates= ff_frame_rate_tab+1, + .supported_framerates= avpriv_frame_rate_tab+1, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE}, .capabilities= CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS, .long_name= NULL_IF_CONFIG_SMALL("MPEG-2 video"), diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index 93001f7b14..b4066ba720 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -57,8 +57,8 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, did_set_size=1; } frame_rate_index = buf[3] & 0xf; - pc->frame_rate.den = avctx->time_base.den = ff_frame_rate_tab[frame_rate_index].num; - pc->frame_rate.num = avctx->time_base.num = ff_frame_rate_tab[frame_rate_index].den; + pc->frame_rate.den = avctx->time_base.den = avpriv_frame_rate_tab[frame_rate_index].num; + pc->frame_rate.num = avctx->time_base.num = avpriv_frame_rate_tab[frame_rate_index].den; avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400; avctx->codec_id = CODEC_ID_MPEG1VIDEO; avctx->sub_id = 1; diff --git a/libavformat/gxf.c b/libavformat/gxf.c index 283e3a6246..473f33a427 100644 --- a/libavformat/gxf.c +++ b/libavformat/gxf.c @@ -185,9 +185,9 @@ static void gxf_material_tags(AVIOContext *pb, int *len, struct gxf_stream_info * @return fps as AVRational, or 0 / 0 if unknown */ static AVRational fps_tag2avr(int32_t fps) { - extern const AVRational ff_frame_rate_tab[]; + extern const AVRational avpriv_frame_rate_tab[]; if (fps < 1 || fps > 9) fps = 9; - return ff_frame_rate_tab[9 - fps]; // values have opposite order + return avpriv_frame_rate_tab[9 - fps]; // values have opposite order } /** From 6f89efeaa7eceb3408abb6e593d892ec819177a7 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 10:04:12 +0200 Subject: [PATCH 43/47] lavc: use avpriv_ prefix for ff_ac3_parse_header. It's used in lavf. --- libavcodec/ac3_parser.c | 4 ++-- libavcodec/ac3_parser.h | 2 +- libavcodec/ac3dec.c | 2 +- libavformat/ac3dec.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c index 82eeda3e61..a6bdd5490f 100644 --- a/libavcodec/ac3_parser.c +++ b/libavcodec/ac3_parser.c @@ -35,7 +35,7 @@ static const uint8_t eac3_blocks[4] = { }; -int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) +int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) { int frame_size_code; @@ -141,7 +141,7 @@ static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info, GetBitContext gbc; init_get_bits(&gbc, tmp.u8+8-AC3_HEADER_SIZE, 54); - err = ff_ac3_parse_header(&gbc, &hdr); + err = avpriv_ac3_parse_header(&gbc, &hdr); if(err < 0) return 0; diff --git a/libavcodec/ac3_parser.h b/libavcodec/ac3_parser.h index d62490bc77..9322550ea5 100644 --- a/libavcodec/ac3_parser.h +++ b/libavcodec/ac3_parser.h @@ -36,6 +36,6 @@ * -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate) * element is invalid, or -4 if the frmsizecod (bit rate) element is invalid. */ -int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr); +int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr); #endif /* AVCODEC_AC3_PARSER_H */ diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index 86a4fd5cc0..134e0b5d11 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -261,7 +261,7 @@ static int parse_frame_header(AC3DecodeContext *s) AC3HeaderInfo hdr; int err; - err = ff_ac3_parse_header(&s->gbc, &hdr); + err = avpriv_ac3_parse_header(&s->gbc, &hdr); if(err) return err; diff --git a/libavformat/ac3dec.c b/libavformat/ac3dec.c index 2cb068e57c..ca6aee3685 100644 --- a/libavformat/ac3dec.c +++ b/libavformat/ac3dec.c @@ -41,7 +41,7 @@ static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id) for(frames = 0; buf2 < end; frames++) { init_get_bits(&gbc, buf2, 54); - if(ff_ac3_parse_header(&gbc, &hdr) < 0) + if(avpriv_ac3_parse_header(&gbc, &hdr) < 0) break; if(buf2 + hdr.frame_size > end || av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2)) From 9f51c682ee83ecf0995648d4574ac09b52bbcb24 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 10:10:42 +0200 Subject: [PATCH 44/47] lavc: use avpriv_ prefix for ff_copy_bits and align_put_bits. They are used in lavf. --- libavcodec/aacenc.c | 2 +- libavcodec/asv1.c | 2 +- libavcodec/bitstream.c | 4 ++-- libavcodec/cljr.c | 2 +- libavcodec/flvenc.c | 2 +- libavcodec/h261enc.c | 2 +- libavcodec/ituh263enc.c | 2 +- libavcodec/jpeglsenc.c | 2 +- libavcodec/mpeg12enc.c | 2 +- libavcodec/mpeg4audio.c | 2 +- libavcodec/mpeg4videoenc.c | 4 ++-- libavcodec/mpegvideo_enc.c | 10 +++++----- libavcodec/msmpeg4.c | 2 +- libavcodec/put_bits.h | 8 ++++---- libavcodec/rv10enc.c | 2 +- libavcodec/svq1enc.c | 4 ++-- libavcodec/vcr1.c | 2 +- libavcodec/wmaenc.c | 4 ++-- libavcodec/wmaprodec.c | 4 ++-- libavcodec/wmavoice.c | 4 ++-- libavcodec/xsubenc.c | 4 ++-- libavformat/latmenc.c | 6 +++--- 22 files changed, 38 insertions(+), 38 deletions(-) diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index 31d740f57a..b112fa8555 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -482,7 +482,7 @@ static void put_bitstream_info(AVCodecContext *avctx, AACEncContext *s, put_bits(&s->pb, 8, namelen - 16); put_bits(&s->pb, 4, 0); //extension type - filler padbits = 8 - (put_bits_count(&s->pb) & 7); - align_put_bits(&s->pb); + avpriv_align_put_bits(&s->pb); for (i = 0; i < namelen - 2; i++) put_bits(&s->pb, 8, name[i]); put_bits(&s->pb, 12 - padbits, 0); diff --git a/libavcodec/asv1.c b/libavcodec/asv1.c index 97c5e681fe..8db23c07ef 100644 --- a/libavcodec/asv1.c +++ b/libavcodec/asv1.c @@ -497,7 +497,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, } emms_c(); - align_put_bits(&a->pb); + avpriv_align_put_bits(&a->pb); while(put_bits_count(&a->pb)&31) put_bits(&a->pb, 8, 0); diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c index 70717883c1..68ea3e0bda 100644 --- a/libavcodec/bitstream.c +++ b/libavcodec/bitstream.c @@ -41,7 +41,7 @@ const uint8_t ff_log2_run[41]={ 24, }; -void align_put_bits(PutBitContext *s) +void avpriv_align_put_bits(PutBitContext *s) { put_bits(s,s->bit_left & 7,0); } @@ -56,7 +56,7 @@ void ff_put_string(PutBitContext *pb, const char *string, int terminate_string) put_bits(pb, 8, 0); } -void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) +void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length) { int words= length>>4; int bits= length&15; diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c index b1cb6f07e3..2bfe03580b 100644 --- a/libavcodec/cljr.c +++ b/libavcodec/cljr.c @@ -105,7 +105,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, emms_c(); - align_put_bits(&a->pb); + avpriv_align_put_bits(&a->pb); while(get_bit_count(&a->pb)&31) put_bits(&a->pb, 8, 0); diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c index ec637dc385..c0d9a04f62 100644 --- a/libavcodec/flvenc.c +++ b/libavcodec/flvenc.c @@ -25,7 +25,7 @@ void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number) { int format; - align_put_bits(&s->pb); + avpriv_align_put_bits(&s->pb); put_bits(&s->pb, 17, 1); put_bits(&s->pb, 5, (s->h263_flv-1)); /* 0: h263 escape codes 1: 11-bit escape codes */ diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c index 1c702de326..034237654b 100644 --- a/libavcodec/h261enc.c +++ b/libavcodec/h261enc.c @@ -53,7 +53,7 @@ void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){ H261Context * h = (H261Context *) s; int format, temp_ref; - align_put_bits(&s->pb); + avpriv_align_put_bits(&s->pb); /* Update the pointer to last GOB */ s->ptr_lastgob = put_bits_ptr(&s->pb); diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c index 783a04f64d..b9888f0ba7 100644 --- a/libavcodec/ituh263enc.c +++ b/libavcodec/ituh263enc.c @@ -126,7 +126,7 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number) coded_frame_rate= 1800000; coded_frame_rate_base= (1000+best_clock_code)*best_divisor; - align_put_bits(&s->pb); + avpriv_align_put_bits(&s->pb); /* Update the pointer to last GOB */ s->ptr_lastgob = put_bits_ptr(&s->pb); diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c index d15269e91d..2b6e54ddd4 100644 --- a/libavcodec/jpeglsenc.c +++ b/libavcodec/jpeglsenc.c @@ -357,7 +357,7 @@ static int encode_picture_ls(AVCodecContext *avctx, unsigned char *buf, int buf_ put_bits(&pb, 8, v); } } - align_put_bits(&pb); + avpriv_align_put_bits(&pb); av_free(buf2); /* End of image */ diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index 738af99d68..5dedabd268 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -192,7 +192,7 @@ static av_cold int encode_init(AVCodecContext *avctx) static void put_header(MpegEncContext *s, int header) { - align_put_bits(&s->pb); + avpriv_align_put_bits(&s->pb); put_bits(&s->pb, 16, header>>16); put_sbits(&s->pb, 16, header); } diff --git a/libavcodec/mpeg4audio.c b/libavcodec/mpeg4audio.c index aa5ae4d463..f9e866f405 100644 --- a/libavcodec/mpeg4audio.c +++ b/libavcodec/mpeg4audio.c @@ -173,7 +173,7 @@ int avpriv_copy_pce_data(PutBitContext *pb, GetBitContext *gb) copy_bits(pb, gb, 16); if (bits) copy_bits(pb, gb, bits); - align_put_bits(pb); + avpriv_align_put_bits(pb); align_get_bits(gb); comment_size = copy_bits(pb, gb, 8); for (; comment_size > 0; comment_size--) diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c index b45890f654..2f3e1d7061 100644 --- a/libavcodec/mpeg4videoenc.c +++ b/libavcodec/mpeg4videoenc.c @@ -1258,8 +1258,8 @@ void ff_mpeg4_merge_partitions(MpegEncContext *s) flush_put_bits(&s->tex_pb); set_put_bits_buffer_size(&s->pb, s->pb2.buf_end - s->pb.buf); - ff_copy_bits(&s->pb, s->pb2.buf , pb2_len); - ff_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len); + avpriv_copy_bits(&s->pb, s->pb2.buf , pb2_len); + avpriv_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len); s->last_bits= put_bits_count(&s->pb); } diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 6154384e31..ce7630ec7f 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -2044,7 +2044,7 @@ static void write_slice_end(MpegEncContext *s){ ff_mjpeg_encode_stuffing(&s->pb); } - align_put_bits(&s->pb); + avpriv_align_put_bits(&s->pb); flush_put_bits(&s->pb); if((s->flags&CODEC_FLAG_PASS1) && !s->partitioned_frame) @@ -2480,18 +2480,18 @@ static int encode_thread(AVCodecContext *c, void *arg){ pb_bits_count= put_bits_count(&s->pb); flush_put_bits(&s->pb); - ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); + avpriv_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); s->pb= backup_s.pb; if(s->data_partitioning){ pb2_bits_count= put_bits_count(&s->pb2); flush_put_bits(&s->pb2); - ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); + avpriv_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); s->pb2= backup_s.pb2; tex_pb_bits_count= put_bits_count(&s->tex_pb); flush_put_bits(&s->tex_pb); - ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); + avpriv_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); s->tex_pb= backup_s.tex_pb; } s->last_bits= put_bits_count(&s->pb); @@ -2714,7 +2714,7 @@ static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src) assert(put_bits_count(&src->pb) % 8 ==0); assert(put_bits_count(&dst->pb) % 8 ==0); - ff_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb)); + avpriv_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb)); flush_put_bits(&dst->pb); } diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c index eca2add828..cfdfd8ef28 100644 --- a/libavcodec/msmpeg4.c +++ b/libavcodec/msmpeg4.c @@ -351,7 +351,7 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number) { find_best_tables(s); - align_put_bits(&s->pb); + avpriv_align_put_bits(&s->pb); put_bits(&s->pb, 2, s->pict_type - 1); put_bits(&s->pb, 5, s->qscale); diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h index f77cfbba97..6e812670b8 100644 --- a/libavcodec/put_bits.h +++ b/libavcodec/put_bits.h @@ -97,14 +97,14 @@ static inline void flush_put_bits(PutBitContext *s) } #ifdef BITSTREAM_WRITER_LE -#define align_put_bits align_put_bits_unsupported_here +#define avpriv_align_put_bits align_put_bits_unsupported_here #define ff_put_string ff_put_string_unsupported_here -#define ff_copy_bits ff_copy_bits_unsupported_here +#define avpriv_copy_bits avpriv_copy_bits_unsupported_here #else /** * Pad the bitstream with zeros up to the next byte boundary. */ -void align_put_bits(PutBitContext *s); +void avpriv_align_put_bits(PutBitContext *s); /** * Put the string string in the bitstream. @@ -118,7 +118,7 @@ void ff_put_string(PutBitContext *pb, const char *string, int terminate_string); * * @param length the number of bits of src to copy */ -void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length); +void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length); #endif /** diff --git a/libavcodec/rv10enc.c b/libavcodec/rv10enc.c index 6fda11486d..e96e473c20 100644 --- a/libavcodec/rv10enc.c +++ b/libavcodec/rv10enc.c @@ -32,7 +32,7 @@ void rv10_encode_picture_header(MpegEncContext *s, int picture_number) { int full_frame= 0; - align_put_bits(&s->pb); + avpriv_align_put_bits(&s->pb); put_bits(&s->pb, 1, 1); /* marker */ diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c index 36787cfdce..79aaa6cb26 100644 --- a/libavcodec/svq1enc.c +++ b/libavcodec/svq1enc.c @@ -461,7 +461,7 @@ static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane s->rd_total += score[best]; for(i=5; i>=0; i--){ - ff_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]); + avpriv_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]); } if(best==0){ s->dsp.put_pixels_tab[0][0](decoded, temp, stride, 16); @@ -540,7 +540,7 @@ static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf, return -1; } -// align_put_bits(&s->pb); +// avpriv_align_put_bits(&s->pb); while(put_bits_count(&s->pb) & 31) put_bits(&s->pb, 1, 0); diff --git a/libavcodec/vcr1.c b/libavcodec/vcr1.c index f745089422..8c64afe570 100644 --- a/libavcodec/vcr1.c +++ b/libavcodec/vcr1.c @@ -132,7 +132,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, emms_c(); - align_put_bits(&a->pb); + avpriv_align_put_bits(&a->pb); while(get_bit_count(&a->pb)&31) put_bits(&a->pb, 8, 0); diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c index 2abc97a082..c762a723b9 100644 --- a/libavcodec/wmaenc.c +++ b/libavcodec/wmaenc.c @@ -311,7 +311,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1], s->coef_vlcs[tindex]->huffcodes[1]); } if (s->version == 1 && s->nb_channels >= 2) { - align_put_bits(&s->pb); + avpriv_align_put_bits(&s->pb); } } return 0; @@ -327,7 +327,7 @@ static int encode_frame(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], return INT_MAX; } - align_put_bits(&s->pb); + avpriv_align_put_bits(&s->pb); return put_bits_count(&s->pb)/8 - s->block_align; } diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c index 2811302435..b3ba9abe15 100644 --- a/libavcodec/wmaprodec.c +++ b/libavcodec/wmaprodec.c @@ -1446,14 +1446,14 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len, s->num_saved_bits += len; if (!append) { - ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), + avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), s->num_saved_bits); } else { int align = 8 - (get_bits_count(gb) & 7); align = FFMIN(align, len); put_bits(&s->pb, align, get_bits(gb, align)); len -= align; - ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len); + avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len); } skip_bits_long(gb, len); diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c index 3b805ac04b..2096d69870 100644 --- a/libavcodec/wmavoice.c +++ b/libavcodec/wmavoice.c @@ -1872,7 +1872,7 @@ static int parse_packet_header(WMAVoiceContext *s) * @param size size of the source data, in bytes * @param gb bit I/O context specifying the current position in the source. * data. This function might use this to align the bit position to - * a whole-byte boundary before calling #ff_copy_bits() on aligned + * a whole-byte boundary before calling #avpriv_copy_bits() on aligned * source data * @param nbits the amount of bits to copy from source to target * @@ -1893,7 +1893,7 @@ static void copy_bits(PutBitContext *pb, rmn_bits &= 7; rmn_bytes >>= 3; if ((rmn_bits = FFMIN(rmn_bits, nbits)) > 0) put_bits(pb, rmn_bits, get_bits(gb, rmn_bits)); - ff_copy_bits(pb, data + size - rmn_bytes, + avpriv_copy_bits(pb, data + size - rmn_bytes, FFMIN(nbits - rmn_bits, rmn_bytes << 3)); } diff --git a/libavcodec/xsubenc.c b/libavcodec/xsubenc.c index b33640dd2c..bd66f86501 100644 --- a/libavcodec/xsubenc.c +++ b/libavcodec/xsubenc.c @@ -90,7 +90,7 @@ static int xsub_encode_rle(PutBitContext *pb, const uint8_t *bitmap, if (color != PADDING_COLOR && (PADDING + (w&1))) put_xsub_rle(pb, PADDING + (w&1), PADDING_COLOR); - align_put_bits(pb); + avpriv_align_put_bits(pb); bitmap += linesize; } @@ -194,7 +194,7 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, // Enforce total height to be be multiple of 2 if (h->rects[0]->h & 1) { put_xsub_rle(&pb, h->rects[0]->w, PADDING_COLOR); - align_put_bits(&pb); + avpriv_align_put_bits(&pb); } flush_put_bits(&pb); diff --git a/libavformat/latmenc.c b/libavformat/latmenc.c index 2e72c489bc..679f2cc9c6 100644 --- a/libavformat/latmenc.c +++ b/libavformat/latmenc.c @@ -106,9 +106,9 @@ static int latm_write_frame_header(AVFormatContext *s, PutBitContext *bs) /* AudioSpecificConfig */ if (ctx->object_type == AOT_ALS) { header_size = avctx->extradata_size-(ctx->off + 7) >> 3; - ff_copy_bits(bs, &avctx->extradata[ctx->off], header_size); + avpriv_copy_bits(bs, &avctx->extradata[ctx->off], header_size); } else { - ff_copy_bits(bs, avctx->extradata, ctx->off + 3); + avpriv_copy_bits(bs, avctx->extradata, ctx->off + 3); if (!ctx->channel_conf) { avpriv_copy_pce_data(bs, &gb); @@ -161,7 +161,7 @@ static int latm_write_packet(AVFormatContext *s, AVPacket *pkt) for (i = 0; i < pkt->size; i++) put_bits(&bs, 8, pkt->data[i]); - align_put_bits(&bs); + avpriv_align_put_bits(&bs); flush_put_bits(&bs); len = put_bits_count(&bs) >> 3; From 0842d58998f441768b5e4376aa0c1d7be0e07a8b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 10:12:51 +0200 Subject: [PATCH 45/47] lavc: use avpriv_ prefix for ff_toupper4. It's used in lavf. --- libavcodec/internal.h | 2 +- libavcodec/mpegvideo.c | 4 ++-- libavcodec/utils.c | 2 +- libavformat/utils.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 9a444fcae7..e676148d75 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -53,6 +53,6 @@ AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt); */ int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b); -unsigned int ff_toupper4(unsigned int x); +unsigned int avpriv_toupper4(unsigned int x); #endif /* AVCODEC_INTERNAL_H */ diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 7b0cac19e3..c1cd1f7a1d 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -646,9 +646,9 @@ av_cold int MPV_common_init(MpegEncContext *s) yc_size = y_size + 2 * c_size; /* convert fourcc to upper case */ - s->codec_tag = ff_toupper4(s->avctx->codec_tag); + s->codec_tag = avpriv_toupper4(s->avctx->codec_tag); - s->stream_codec_tag = ff_toupper4(s->avctx->stream_codec_tag); + s->stream_codec_tag = avpriv_toupper4(s->avctx->stream_codec_tag); s->avctx->coded_frame= (AVFrame*)&s->current_picture; diff --git a/libavcodec/utils.c b/libavcodec/utils.c index ac4de7da4a..c1a5c19e04 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1269,7 +1269,7 @@ int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op)) return 0; } -unsigned int ff_toupper4(unsigned int x) +unsigned int avpriv_toupper4(unsigned int x) { return toupper( x &0xFF) + (toupper((x>>8 )&0xFF)<<8 ) diff --git a/libavformat/utils.c b/libavformat/utils.c index 1c1a7482e5..d0a7fb90be 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2148,7 +2148,7 @@ enum CodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag) return tags[i].id; } for(i=0; tags[i].id != CODEC_ID_NONE; i++) { - if (ff_toupper4(tag) == ff_toupper4(tags[i].tag)) + if (avpriv_toupper4(tag) == avpriv_toupper4(tags[i].tag)) return tags[i].id; } return CODEC_ID_NONE; @@ -2807,7 +2807,7 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st) for (n = 0; s->oformat->codec_tag[n]; n++) { avctag = s->oformat->codec_tag[n]; while (avctag->id != CODEC_ID_NONE) { - if (ff_toupper4(avctag->tag) == ff_toupper4(st->codec->codec_tag)) { + if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codec->codec_tag)) { id = avctag->id; if (id == st->codec->codec_id) return 1; From 586657c20a84ea85bfd28b9ab19aace427178922 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 20:08:02 +0200 Subject: [PATCH 46/47] lavc: deprecate img_get_alpha_info(). It's never been touched or used in any way since it was added in 2003 and only works for PIX_FMT_PAL8, which makes me conclude that nobody's ever used it. --- libavcodec/avcodec.h | 3 +++ libavcodec/imgconvert.c | 2 ++ libavcodec/version.h | 3 +++ 3 files changed, 8 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index a5fd2e7386..28dde3fe85 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3500,6 +3500,7 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_ enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt, int has_alpha, int *loss_ptr); +#if FF_API_GET_ALPHA_INFO #define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */ #define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */ @@ -3507,8 +3508,10 @@ enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelForma * Tell if an image really has transparent alpha values. * @return ored mask of FF_ALPHA_xxx constants */ +attribute_deprecated int img_get_alpha_info(const AVPicture *src, enum PixelFormat pix_fmt, int width, int height); +#endif /* deinterlace a picture */ /* deinterlace - if not supported return -1 */ diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c index c446aaca38..eb398f7107 100644 --- a/libavcodec/imgconvert.c +++ b/libavcodec/imgconvert.c @@ -862,6 +862,7 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, return 0; } +#if FF_API_GET_ALPHA_INFO /* NOTE: we scan all the pixels to have an exact information */ static int get_alpha_info_pal8(const AVPicture *src, int width, int height) { @@ -908,6 +909,7 @@ int img_get_alpha_info(const AVPicture *src, } return ret; } +#endif #if !(HAVE_MMX && HAVE_YASM) /* filter parameters: [-1 4 2 4 -1] // 8 */ diff --git a/libavcodec/version.h b/libavcodec/version.h index ef30a694ee..a361bbdf8c 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -98,5 +98,8 @@ #ifndef FF_API_MJPEG_GLOBAL_OPTS #define FF_API_MJPEG_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54) #endif +#ifndef FF_API_GET_ALPHA_INFO +#define FF_API_GET_ALPHA_INFO (LIBAVCODEC_VERSION_MAJOR < 54) +#endif #endif /* AVCODEC_VERSION_H */ From 65d3176aaf8f876e0769f200abe95cac42151c89 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 17 Oct 2011 10:13:16 +0200 Subject: [PATCH 47/47] lavc: hide private symbols. Overhead as reported by rbelf-size goes from 90860 to 20204. --- libavcodec/libavcodec.v | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libavcodec/libavcodec.v b/libavcodec/libavcodec.v index 65699038ab..a9e7674e13 100644 --- a/libavcodec/libavcodec.v +++ b/libavcodec/libavcodec.v @@ -1,9 +1,8 @@ LIBAVCODEC_$MAJOR { - global: *; - local: - ff_*_bsf; - ff_*_decoder; - ff_*_encoder; - ff_*_hwaccel; - ff_*_parser; + global: av*; + audio_resample; + audio_resample_close; + #deprecated, remove after next bump + img_get_alpha_info; + local: *; };