mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
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
This commit is contained in:
parent
b4800b8b7d
commit
d4df4e5088
@ -83,8 +83,8 @@ OBJS-$(CONFIG_FFV1_DECODER) += ffv1.o rangecoder.o
|
|||||||
OBJS-$(CONFIG_FFV1_ENCODER) += ffv1.o rangecoder.o
|
OBJS-$(CONFIG_FFV1_ENCODER) += ffv1.o rangecoder.o
|
||||||
OBJS-$(CONFIG_FFVHUFF_DECODER) += huffyuv.o
|
OBJS-$(CONFIG_FFVHUFF_DECODER) += huffyuv.o
|
||||||
OBJS-$(CONFIG_FFVHUFF_ENCODER) += huffyuv.o
|
OBJS-$(CONFIG_FFVHUFF_ENCODER) += huffyuv.o
|
||||||
OBJS-$(CONFIG_FLAC_DECODER) += flacdec.o
|
OBJS-$(CONFIG_FLAC_DECODER) += flacdec.o flacdata.o
|
||||||
OBJS-$(CONFIG_FLAC_ENCODER) += flacenc.o lpc.o
|
OBJS-$(CONFIG_FLAC_ENCODER) += flacenc.o flacdata.o lpc.o
|
||||||
OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
|
OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o
|
||||||
OBJS-$(CONFIG_FLASHSV_ENCODER) += flashsvenc.o
|
OBJS-$(CONFIG_FLASHSV_ENCODER) += flashsvenc.o
|
||||||
OBJS-$(CONFIG_FLIC_DECODER) += flicvideo.o
|
OBJS-$(CONFIG_FLIC_DECODER) += flicvideo.o
|
||||||
@ -346,17 +346,17 @@ OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcm.o
|
|||||||
|
|
||||||
# libavformat dependencies
|
# libavformat dependencies
|
||||||
OBJS-$(CONFIG_EAC3_DEMUXER) += ac3_parser.o ac3tab.o aac_ac3_parser.o
|
OBJS-$(CONFIG_EAC3_DEMUXER) += ac3_parser.o ac3tab.o aac_ac3_parser.o
|
||||||
OBJS-$(CONFIG_FLAC_DEMUXER) += flacdec.o
|
OBJS-$(CONFIG_FLAC_DEMUXER) += flacdec.o flacdata.o
|
||||||
OBJS-$(CONFIG_FLAC_MUXER) += flacdec.o
|
OBJS-$(CONFIG_FLAC_MUXER) += flacdec.o flacdata.o
|
||||||
OBJS-$(CONFIG_GXF_DEMUXER) += mpeg12data.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_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_MOV_DEMUXER) += mpeg4audio.o mpegaudiodata.o
|
||||||
OBJS-$(CONFIG_MPEGTS_MUXER) += mpegvideo.o
|
OBJS-$(CONFIG_MPEGTS_MUXER) += mpegvideo.o
|
||||||
OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o
|
OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o
|
||||||
OBJS-$(CONFIG_OGG_DEMUXER) += flacdec.o
|
OBJS-$(CONFIG_OGG_DEMUXER) += flacdec.o flacdata.o
|
||||||
OBJS-$(CONFIG_OGG_MUXER) += xiph.o flacdec.o
|
OBJS-$(CONFIG_OGG_MUXER) += xiph.o flacdec.o flacdata.o
|
||||||
OBJS-$(CONFIG_RTP_MUXER) += mpegvideo.o
|
OBJS-$(CONFIG_RTP_MUXER) += mpegvideo.o
|
||||||
|
|
||||||
# external codec libraries
|
# external codec libraries
|
||||||
|
33
libavcodec/flacdata.c
Normal file
33
libavcodec/flacdata.c
Normal file
@ -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
|
||||||
|
};
|
31
libavcodec/flacdata.h
Normal file
31
libavcodec/flacdata.h
Normal file
@ -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 */
|
@ -42,6 +42,7 @@
|
|||||||
#include "bytestream.h"
|
#include "bytestream.h"
|
||||||
#include "golomb.h"
|
#include "golomb.h"
|
||||||
#include "flac.h"
|
#include "flac.h"
|
||||||
|
#include "flacdata.h"
|
||||||
|
|
||||||
#undef NDEBUG
|
#undef NDEBUG
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -66,20 +67,9 @@ typedef struct FLACContext {
|
|||||||
unsigned int allocated_bitstream_size;
|
unsigned int allocated_bitstream_size;
|
||||||
} FLACContext;
|
} 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[] =
|
static const int sample_size_table[] =
|
||||||
{ 0, 8, 12, 0, 16, 20, 24, 0 };
|
{ 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)
|
static int64_t get_utf8(GetBitContext *gb)
|
||||||
{
|
{
|
||||||
int64_t val;
|
int64_t val;
|
||||||
@ -547,7 +537,7 @@ static int decode_frame(FLACContext *s, int alloc_data_size)
|
|||||||
else if (blocksize_code == 7)
|
else if (blocksize_code == 7)
|
||||||
blocksize = get_bits(&s->gb, 16)+1;
|
blocksize = get_bits(&s->gb, 16)+1;
|
||||||
else
|
else
|
||||||
blocksize = blocksize_table[blocksize_code];
|
blocksize = ff_flac_blocksize_table[blocksize_code];
|
||||||
|
|
||||||
if (blocksize > s->max_blocksize) {
|
if (blocksize > s->max_blocksize) {
|
||||||
av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", 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)
|
if (sample_rate_code == 0)
|
||||||
samplerate= s->samplerate;
|
samplerate= s->samplerate;
|
||||||
else if (sample_rate_code < 12)
|
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)
|
else if (sample_rate_code == 12)
|
||||||
samplerate = get_bits(&s->gb, 8) * 1000;
|
samplerate = get_bits(&s->gb, 8) * 1000;
|
||||||
else if (sample_rate_code == 13)
|
else if (sample_rate_code == 13)
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "golomb.h"
|
#include "golomb.h"
|
||||||
#include "lpc.h"
|
#include "lpc.h"
|
||||||
#include "flac.h"
|
#include "flac.h"
|
||||||
|
#include "flacdata.h"
|
||||||
|
|
||||||
#define FLAC_SUBFRAME_CONSTANT 0
|
#define FLAC_SUBFRAME_CONSTANT 0
|
||||||
#define FLAC_SUBFRAME_VERBATIM 1
|
#define FLAC_SUBFRAME_VERBATIM 1
|
||||||
@ -79,12 +80,10 @@ typedef struct FlacFrame {
|
|||||||
} FlacFrame;
|
} FlacFrame;
|
||||||
|
|
||||||
typedef struct FlacEncodeContext {
|
typedef struct FlacEncodeContext {
|
||||||
|
FLACSTREAMINFO
|
||||||
PutBitContext pb;
|
PutBitContext pb;
|
||||||
int channels;
|
|
||||||
int samplerate;
|
|
||||||
int sr_code[2];
|
int sr_code[2];
|
||||||
int min_framesize;
|
int min_framesize;
|
||||||
int max_framesize;
|
|
||||||
int max_encoded_framesize;
|
int max_encoded_framesize;
|
||||||
uint32_t frame_count;
|
uint32_t frame_count;
|
||||||
uint64_t sample_count;
|
uint64_t sample_count;
|
||||||
@ -96,20 +95,6 @@ typedef struct FlacEncodeContext {
|
|||||||
struct AVMD5 *md5ctx;
|
struct AVMD5 *md5ctx;
|
||||||
} FlacEncodeContext;
|
} 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
|
* Writes streaminfo metadata block to byte array
|
||||||
*/
|
*/
|
||||||
@ -146,11 +131,11 @@ static int select_blocksize(int samplerate, int block_time_ms)
|
|||||||
int blocksize;
|
int blocksize;
|
||||||
|
|
||||||
assert(samplerate > 0);
|
assert(samplerate > 0);
|
||||||
blocksize = flac_blocksizes[1];
|
blocksize = ff_flac_blocksize_table[1];
|
||||||
target = (samplerate * block_time_ms) / 1000;
|
target = (samplerate * block_time_ms) / 1000;
|
||||||
for(i=0; i<16; i++) {
|
for(i=0; i<16; i++) {
|
||||||
if(target >= flac_blocksizes[i] && flac_blocksizes[i] > blocksize) {
|
if(target >= ff_flac_blocksize_table[i] && ff_flac_blocksize_table[i] > blocksize) {
|
||||||
blocksize = flac_blocksizes[i];
|
blocksize = ff_flac_blocksize_table[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return blocksize;
|
return blocksize;
|
||||||
@ -181,8 +166,8 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
|
|||||||
if(freq < 1)
|
if(freq < 1)
|
||||||
return -1;
|
return -1;
|
||||||
for(i=4; i<12; i++) {
|
for(i=4; i<12; i++) {
|
||||||
if(freq == flac_samplerates[i]) {
|
if(freq == ff_flac_sample_rate_table[i]) {
|
||||||
s->samplerate = flac_samplerates[i];
|
s->samplerate = ff_flac_sample_rate_table[i];
|
||||||
s->sr_code[0] = i;
|
s->sr_code[0] = i;
|
||||||
s->sr_code[1] = 0;
|
s->sr_code[1] = 0;
|
||||||
break;
|
break;
|
||||||
@ -392,8 +377,8 @@ static void init_frame(FlacEncodeContext *s)
|
|||||||
frame = &s->frame;
|
frame = &s->frame;
|
||||||
|
|
||||||
for(i=0; i<16; i++) {
|
for(i=0; i<16; i++) {
|
||||||
if(s->avctx->frame_size == flac_blocksizes[i]) {
|
if(s->avctx->frame_size == ff_flac_blocksize_table[i]) {
|
||||||
frame->blocksize = flac_blocksizes[i];
|
frame->blocksize = ff_flac_blocksize_table[i];
|
||||||
frame->bs_code[0] = i;
|
frame->bs_code[0] = i;
|
||||||
frame->bs_code[1] = 0;
|
frame->bs_code[1] = 0;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user