diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2009-03-21 01:16:38 +0000 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2009-03-21 01:16:38 +0000 |
commit | d4df4e508854803ce3bc393c4f718096ad7cbf41 (patch) | |
tree | 4fb1974b6851b45039dcc797d12caa51d21addc6 /libavcodec | |
parent | b4800b8b7dfba22117d8edd02164b00c83ae3753 (diff) | |
download | ffmpeg-d4df4e508854803ce3bc393c4f718096ad7cbf41.tar.gz |
share sample rate and blocksize tables between the FLAC encoder and FLAC
decoder
Originally committed as revision 18089 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/Makefile | 16 | ||||
-rw-r--r-- | libavcodec/flacdata.c | 33 | ||||
-rw-r--r-- | libavcodec/flacdata.h | 31 | ||||
-rw-r--r-- | libavcodec/flacdec.c | 16 | ||||
-rw-r--r-- | libavcodec/flacenc.c | 33 |
5 files changed, 84 insertions, 45 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 1b3f93ae99..7683402f56 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -83,8 +83,8 @@ OBJS-$(CONFIG_FFV1_DECODER) += ffv1.o rangecoder.o OBJS-$(CONFIG_FFV1_ENCODER) += ffv1.o rangecoder.o OBJS-$(CONFIG_FFVHUFF_DECODER) += huffyuv.o OBJS-$(CONFIG_FFVHUFF_ENCODER) += huffyuv.o -OBJS-$(CONFIG_FLAC_DECODER) += flacdec.o -OBJS-$(CONFIG_FLAC_ENCODER) += flacenc.o lpc.o +OBJS-$(CONFIG_FLAC_DECODER) += flacdec.o flacdata.o +OBJS-$(CONFIG_FLAC_ENCODER) += flacenc.o flacdata.o lpc.o OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o OBJS-$(CONFIG_FLASHSV_ENCODER) += flashsvenc.o OBJS-$(CONFIG_FLIC_DECODER) += flicvideo.o @@ -346,17 +346,17 @@ OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcm.o # libavformat dependencies OBJS-$(CONFIG_EAC3_DEMUXER) += ac3_parser.o ac3tab.o aac_ac3_parser.o -OBJS-$(CONFIG_FLAC_DEMUXER) += flacdec.o -OBJS-$(CONFIG_FLAC_MUXER) += flacdec.o +OBJS-$(CONFIG_FLAC_DEMUXER) += flacdec.o flacdata.o +OBJS-$(CONFIG_FLAC_MUXER) += flacdec.o flacdata.o OBJS-$(CONFIG_GXF_DEMUXER) += mpeg12data.o -OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER) += xiph.o mpeg4audio.o flacdec.o +OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER) += xiph.o mpeg4audio.o flacdec.o flacdata.o OBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio.o -OBJS-$(CONFIG_MATROSKA_MUXER) += xiph.o mpeg4audio.o flacdec.o +OBJS-$(CONFIG_MATROSKA_MUXER) += xiph.o mpeg4audio.o flacdec.o flacdata.o OBJS-$(CONFIG_MOV_DEMUXER) += mpeg4audio.o mpegaudiodata.o OBJS-$(CONFIG_MPEGTS_MUXER) += mpegvideo.o OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o -OBJS-$(CONFIG_OGG_DEMUXER) += flacdec.o -OBJS-$(CONFIG_OGG_MUXER) += xiph.o flacdec.o +OBJS-$(CONFIG_OGG_DEMUXER) += flacdec.o flacdata.o +OBJS-$(CONFIG_OGG_MUXER) += xiph.o flacdec.o flacdata.o OBJS-$(CONFIG_RTP_MUXER) += mpegvideo.o # external codec libraries diff --git a/libavcodec/flacdata.c b/libavcodec/flacdata.c new file mode 100644 index 0000000000..6fcbe3955a --- /dev/null +++ b/libavcodec/flacdata.c @@ -0,0 +1,33 @@ +/* + * FLAC data + * Copyright (c) 2003 Alex Beregszaszi + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "internal.h" + +const int ff_flac_sample_rate_table[16] = +{ 0, + 88200, 176400, 192000, + 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000, + 0, 0, 0, 0 }; + +const int16_t ff_flac_blocksize_table[16] = { + 0, 192, 576<<0, 576<<1, 576<<2, 576<<3, 0, 0, +256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7 +}; diff --git a/libavcodec/flacdata.h b/libavcodec/flacdata.h new file mode 100644 index 0000000000..96a50b9183 --- /dev/null +++ b/libavcodec/flacdata.h @@ -0,0 +1,31 @@ +/* + * FLAC data header + * Copyright (c) 2003 Alex Beregszaszi + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_FLACDATA_H +#define AVCODEC_FLACDATA_H + +#include "internal.h" + +extern const int ff_flac_sample_rate_table[16]; + +extern const int16_t ff_flac_blocksize_table[16]; + +#endif /* AVCODEC_FLACDATA_H */ diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c index 7a63d8a9a4..3145d7283e 100644 --- a/libavcodec/flacdec.c +++ b/libavcodec/flacdec.c @@ -42,6 +42,7 @@ #include "bytestream.h" #include "golomb.h" #include "flac.h" +#include "flacdata.h" #undef NDEBUG #include <assert.h> @@ -66,20 +67,9 @@ typedef struct FLACContext { unsigned int allocated_bitstream_size; } FLACContext; -static const int sample_rate_table[] = -{ 0, - 88200, 176400, 192000, - 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000, - 0, 0, 0, 0 }; - static const int sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 }; -static const int blocksize_table[] = { - 0, 192, 576<<0, 576<<1, 576<<2, 576<<3, 0, 0, -256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7 -}; - static int64_t get_utf8(GetBitContext *gb) { int64_t val; @@ -547,7 +537,7 @@ static int decode_frame(FLACContext *s, int alloc_data_size) else if (blocksize_code == 7) blocksize = get_bits(&s->gb, 16)+1; else - blocksize = blocksize_table[blocksize_code]; + blocksize = ff_flac_blocksize_table[blocksize_code]; if (blocksize > s->max_blocksize) { av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize, @@ -561,7 +551,7 @@ static int decode_frame(FLACContext *s, int alloc_data_size) if (sample_rate_code == 0) samplerate= s->samplerate; else if (sample_rate_code < 12) - samplerate = sample_rate_table[sample_rate_code]; + samplerate = ff_flac_sample_rate_table[sample_rate_code]; else if (sample_rate_code == 12) samplerate = get_bits(&s->gb, 8) * 1000; else if (sample_rate_code == 13) diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index 2f33234d74..679ad57b97 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -28,6 +28,7 @@ #include "golomb.h" #include "lpc.h" #include "flac.h" +#include "flacdata.h" #define FLAC_SUBFRAME_CONSTANT 0 #define FLAC_SUBFRAME_VERBATIM 1 @@ -79,12 +80,10 @@ typedef struct FlacFrame { } FlacFrame; typedef struct FlacEncodeContext { + FLACSTREAMINFO PutBitContext pb; - int channels; - int samplerate; int sr_code[2]; int min_framesize; - int max_framesize; int max_encoded_framesize; uint32_t frame_count; uint64_t sample_count; @@ -96,20 +95,6 @@ typedef struct FlacEncodeContext { struct AVMD5 *md5ctx; } FlacEncodeContext; -static const int flac_samplerates[16] = { - 0, 0, 0, 0, - 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000, - 0, 0, 0, 0 -}; - -static const int flac_blocksizes[16] = { - 0, - 192, - 576, 1152, 2304, 4608, - 0, 0, - 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 -}; - /** * Writes streaminfo metadata block to byte array */ @@ -146,11 +131,11 @@ static int select_blocksize(int samplerate, int block_time_ms) int blocksize; assert(samplerate > 0); - blocksize = flac_blocksizes[1]; + blocksize = ff_flac_blocksize_table[1]; target = (samplerate * block_time_ms) / 1000; for(i=0; i<16; i++) { - if(target >= flac_blocksizes[i] && flac_blocksizes[i] > blocksize) { - blocksize = flac_blocksizes[i]; + if(target >= ff_flac_blocksize_table[i] && ff_flac_blocksize_table[i] > blocksize) { + blocksize = ff_flac_blocksize_table[i]; } } return blocksize; @@ -181,8 +166,8 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) if(freq < 1) return -1; for(i=4; i<12; i++) { - if(freq == flac_samplerates[i]) { - s->samplerate = flac_samplerates[i]; + if(freq == ff_flac_sample_rate_table[i]) { + s->samplerate = ff_flac_sample_rate_table[i]; s->sr_code[0] = i; s->sr_code[1] = 0; break; @@ -392,8 +377,8 @@ static void init_frame(FlacEncodeContext *s) frame = &s->frame; for(i=0; i<16; i++) { - if(s->avctx->frame_size == flac_blocksizes[i]) { - frame->blocksize = flac_blocksizes[i]; + if(s->avctx->frame_size == ff_flac_blocksize_table[i]) { + frame->blocksize = ff_flac_blocksize_table[i]; frame->bs_code[0] = i; frame->bs_code[1] = 0; break; |