tak: reduce difference with qatar

Mostly cosmetics changes, but also makes
decoding little faster here.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Paul B Mahol 2012-12-08 12:18:23 +00:00
parent 461b5bf4ab
commit cef28b5602
5 changed files with 514 additions and 528 deletions

View File

@ -56,12 +56,13 @@ static int tak_get_nb_samples(int sample_rate, enum TAKFrameSizeType type)
if (type <= TAK_FST_250ms) {
nb_samples = sample_rate * frame_duration_type_quants[type] >>
TAK_FRAME_DURATION_QUANT_SHIFT;
TAK_FRAME_DURATION_QUANT_SHIFT;
max_nb_samples = 16384;
} else if (type < FF_ARRAY_ELEMS(frame_duration_type_quants)) {
nb_samples = frame_duration_type_quants[type];
max_nb_samples = sample_rate * frame_duration_type_quants[TAK_FST_250ms] >>
TAK_FRAME_DURATION_QUANT_SHIFT;
max_nb_samples = sample_rate *
frame_duration_type_quants[TAK_FST_250ms] >>
TAK_FRAME_DURATION_QUANT_SHIFT;
} else {
return AVERROR_INVALIDDATA;
}
@ -116,9 +117,12 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
s->samples = get_bits64(gb, TAK_SIZE_SAMPLES_NUM_BITS);
s->data_type = get_bits(gb, TAK_FORMAT_DATA_TYPE_BITS);
s->sample_rate = get_bits(gb, TAK_FORMAT_SAMPLE_RATE_BITS) + TAK_SAMPLE_RATE_MIN;
s->bps = get_bits(gb, TAK_FORMAT_BPS_BITS) + TAK_BPS_MIN;
s->channels = get_bits(gb, TAK_FORMAT_CHANNEL_BITS) + TAK_CHANNELS_MIN;
s->sample_rate = get_bits(gb, TAK_FORMAT_SAMPLE_RATE_BITS) +
TAK_SAMPLE_RATE_MIN;
s->bps = get_bits(gb, TAK_FORMAT_BPS_BITS) +
TAK_BPS_MIN;
s->channels = get_bits(gb, TAK_FORMAT_CHANNEL_BITS) +
TAK_CHANNELS_MIN;
if (get_bits1(gb)) {
skip_bits(gb, TAK_FORMAT_VALID_BITS);
@ -136,31 +140,25 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
s->frame_samples = tak_get_nb_samples(s->sample_rate, frame_type);
}
#define FRAME_IS_LAST 1
#define FRAME_HAVE_INFO 2
#define FRAME_HAVE_METADATA 4
int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
TAKStreamInfo *ti, int log_level_offset)
{
int flags;
if (get_bits(gb, TAK_FRAME_HEADER_SYNC_ID_BITS) != TAK_FRAME_HEADER_SYNC_ID) {
av_log(avctx, AV_LOG_ERROR + log_level_offset, "missing sync id\n");
return AVERROR_INVALIDDATA;
}
flags = get_bits(gb, TAK_FRAME_HEADER_FLAGS_BITS);
ti->flags = get_bits(gb, TAK_FRAME_HEADER_FLAGS_BITS);
ti->frame_num = get_bits(gb, TAK_FRAME_HEADER_NO_BITS);
if (flags & FRAME_IS_LAST) {
if (ti->flags & TAK_FRAME_FLAG_IS_LAST) {
ti->last_frame_samples = get_bits(gb, TAK_FRAME_HEADER_SAMPLE_COUNT_BITS) + 1;
skip_bits(gb, 2);
} else {
ti->last_frame_samples = 0;
}
if (flags & FRAME_HAVE_INFO) {
if (ti->flags & TAK_FRAME_FLAG_HAS_INFO) {
avpriv_tak_parse_streaminfo(gb, ti);
if (get_bits(gb, 6))
@ -168,7 +166,7 @@ int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
align_get_bits(gb);
}
if (flags & FRAME_HAVE_METADATA)
if (ti->flags & TAK_FRAME_FLAG_HAS_METADATA)
return AVERROR_INVALIDDATA;
skip_bits(gb, 24);

View File

@ -33,64 +33,74 @@
#include "get_bits.h"
#include "avcodec.h"
#define TAK_FORMAT_DATA_TYPE_BITS 3
#define TAK_FORMAT_DATA_TYPE_BITS 3
#define TAK_FORMAT_SAMPLE_RATE_BITS 18
#define TAK_FORMAT_BPS_BITS 5
#define TAK_FORMAT_CHANNEL_BITS 4
#define TAK_FORMAT_VALID_BITS 5
#define TAK_FORMAT_CH_LAYOUT_BITS 6
#define TAK_SIZE_FRAME_DURATION_BITS 4
#define TAK_FORMAT_BPS_BITS 5
#define TAK_FORMAT_CHANNEL_BITS 4
#define TAK_FORMAT_VALID_BITS 5
#define TAK_FORMAT_CH_LAYOUT_BITS 6
#define TAK_SIZE_FRAME_DURATION_BITS 4
#define TAK_SIZE_SAMPLES_NUM_BITS 35
#define TAK_LAST_FRAME_POS_BITS 40
#define TAK_LAST_FRAME_SIZE_BITS 24
#define TAK_ENCODER_CODEC_BITS 6
#define TAK_ENCODER_PROFILE_BITS 4
#define TAK_ENCODER_CODEC_BITS 6
#define TAK_ENCODER_PROFILE_BITS 4
#define TAK_ENCODER_VERSION_BITS 24
#define TAK_SAMPLE_RATE_MIN 6000
#define TAK_CHANNELS_MIN 1
#define TAK_BPS_MIN 8
#define TAK_FRAME_HEADER_FLAGS_BITS 3
#define TAK_FRAME_HEADER_SYNC_ID 0xA0FF
#define TAK_SAMPLE_RATE_MIN 6000
#define TAK_CHANNELS_MIN 1
#define TAK_BPS_MIN 8
#define TAK_FRAME_HEADER_FLAGS_BITS 3
#define TAK_FRAME_HEADER_SYNC_ID 0xA0FF
#define TAK_FRAME_HEADER_SYNC_ID_BITS 16
#define TAK_FRAME_HEADER_SAMPLE_COUNT_BITS 14
#define TAK_FRAME_HEADER_NO_BITS 21
#define TAK_FRAME_DURATION_QUANT_SHIFT 5
#define TAK_FRAME_DURATION_QUANT_SHIFT 5
#define TAK_CRC24_BITS 24
#define TAK_MAX_CHANNELS ( 1 << TAK_FORMAT_CHANNEL_BITS )
#define TAK_MIN_FRAME_HEADER_BITS ( TAK_FRAME_HEADER_SYNC_ID_BITS + \
TAK_FRAME_HEADER_FLAGS_BITS + \
TAK_FRAME_HEADER_NO_BITS + \
TAK_CRC24_BITS )
#define TAK_FRAME_FLAG_IS_LAST 0x1
#define TAK_FRAME_FLAG_HAS_INFO 0x2
#define TAK_FRAME_FLAG_HAS_METADATA 0x4
#define TAK_MIN_FRAME_HEADER_LAST_BITS ( TAK_MIN_FRAME_HEADER_BITS + 2 + \
TAK_FRAME_HEADER_SAMPLE_COUNT_BITS )
#define TAK_MAX_CHANNELS (1 << TAK_FORMAT_CHANNEL_BITS)
#define TAK_ENCODER_BITS ( TAK_ENCODER_CODEC_BITS + \
TAK_ENCODER_PROFILE_BITS )
#define TAK_MIN_FRAME_HEADER_BITS (TAK_FRAME_HEADER_SYNC_ID_BITS + \
TAK_FRAME_HEADER_FLAGS_BITS + \
TAK_FRAME_HEADER_NO_BITS + \
TAK_CRC24_BITS)
#define TAK_SIZE_BITS ( TAK_SIZE_SAMPLES_NUM_BITS + \
TAK_SIZE_FRAME_DURATION_BITS )
#define TAK_MIN_FRAME_HEADER_LAST_BITS (TAK_MIN_FRAME_HEADER_BITS + 2 + \
TAK_FRAME_HEADER_SAMPLE_COUNT_BITS)
#define TAK_FORMAT_BITS ( TAK_FORMAT_DATA_TYPE_BITS + \
TAK_FORMAT_SAMPLE_RATE_BITS + \
TAK_FORMAT_BPS_BITS + \
TAK_FORMAT_CHANNEL_BITS + 1 + \
TAK_FORMAT_VALID_BITS + 1 + \
TAK_FORMAT_CH_LAYOUT_BITS * \
TAK_MAX_CHANNELS )
#define TAK_ENCODER_BITS (TAK_ENCODER_CODEC_BITS + \
TAK_ENCODER_PROFILE_BITS)
#define TAK_STREAMINFO_BITS ( TAK_ENCODER_BITS + \
TAK_SIZE_BITS + \
TAK_FORMAT_BITS )
#define TAK_SIZE_BITS (TAK_SIZE_SAMPLES_NUM_BITS + \
TAK_SIZE_FRAME_DURATION_BITS)
#define TAK_MAX_FRAME_HEADER_BITS ( TAK_MIN_FRAME_HEADER_LAST_BITS + \
TAK_STREAMINFO_BITS + 31 )
#define TAK_FORMAT_BITS (TAK_FORMAT_DATA_TYPE_BITS + \
TAK_FORMAT_SAMPLE_RATE_BITS + \
TAK_FORMAT_BPS_BITS + \
TAK_FORMAT_CHANNEL_BITS + 1 + \
TAK_FORMAT_VALID_BITS + 1 + \
TAK_FORMAT_CH_LAYOUT_BITS * \
TAK_MAX_CHANNELS)
#define TAK_STREAMINFO_BYTES (( TAK_STREAMINFO_BITS + 7 ) / 8)
#define TAK_MAX_FRAME_HEADER_BYTES (( TAK_MAX_FRAME_HEADER_BITS + 7 ) / 8)
#define TAK_MIN_FRAME_HEADER_BYTES (( TAK_MIN_FRAME_HEADER_BITS + 7 ) / 8)
#define TAK_STREAMINFO_BITS (TAK_ENCODER_BITS + \
TAK_SIZE_BITS + \
TAK_FORMAT_BITS)
#define TAK_MAX_FRAME_HEADER_BITS (TAK_MIN_FRAME_HEADER_LAST_BITS + \
TAK_STREAMINFO_BITS + 31)
#define TAK_STREAMINFO_BYTES ((TAK_STREAMINFO_BITS + 7) / 8)
#define TAK_MAX_FRAME_HEADER_BYTES ((TAK_MAX_FRAME_HEADER_BITS + 7) / 8)
#define TAK_MIN_FRAME_HEADER_BYTES ((TAK_MIN_FRAME_HEADER_BITS + 7) / 8)
enum TAKCodecType {
TAK_CODEC_MONO_STEREO = 2,
TAK_CODEC_MULTICHANNEL = 4,
};
enum TAKMetaDataType {
TAK_METADATA_END = 0,
@ -117,16 +127,17 @@ enum TAKFrameSizeType {
};
typedef struct TAKStreamInfo {
int codec;
int data_type;
int sample_rate;
int channels;
int bps;
int frame_num;
int frame_samples;
int last_frame_samples;
uint64_t ch_layout;
int64_t samples;
int flags;
enum TAKCodecType codec;
int data_type;
int sample_rate;
int channels;
int bps;
int frame_num;
int frame_samples;
int last_frame_samples;
uint64_t ch_layout;
int64_t samples;
} TAKStreamInfo;
void ff_tak_init_crc(void);
@ -145,8 +156,9 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s);
* @param avctx AVCodecContext to use as av_log() context
* @param[in] gb GetBitContext from which to read frame header
* @param[out] s frame information
* @param log_level_offset log level offset. can be used to silence error messages.
* @return non-zero on error, 0 if ok
* @param log_level_offset log level offset, can be used to silence
* error messages.
* @return non-zero on error, 0 if OK
*/
int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
TAKStreamInfo *s, int log_level_offset);

View File

@ -24,8 +24,8 @@
* TAK parser
**/
#include "parser.h"
#include "tak.h"
#include "parser.h"
typedef struct TAKParseContext {
ParseContext pc;
@ -44,18 +44,18 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
const uint8_t *buf, int buf_size)
{
TAKParseContext *t = s->priv_data;
ParseContext *pc = &t->pc;
int next = END_NOT_FOUND;
ParseContext *pc = &t->pc;
int next = END_NOT_FOUND;
GetBitContext gb;
int consumed = 0;
int needed = buf_size ? TAK_MAX_FRAME_HEADER_BYTES : 8;
int needed = buf_size ? TAK_MAX_FRAME_HEADER_BYTES : 8;
if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
TAKStreamInfo ti;
init_get_bits(&gb, buf, buf_size);
if (!ff_tak_decode_frame_header(avctx, &gb, &ti, 127))
s->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples :
t->ti.frame_samples;
s->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples
: t->ti.frame_samples;
*poutbuf = buf;
*poutbuf_size = buf_size;
return buf_size;
@ -63,7 +63,8 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
while (buf_size || t->index + needed <= pc->index) {
if (buf_size && t->index + TAK_MAX_FRAME_HEADER_BYTES > pc->index) {
int tmp_buf_size = FFMIN(2 * TAK_MAX_FRAME_HEADER_BYTES, buf_size);
int tmp_buf_size = FFMIN(2 * TAK_MAX_FRAME_HEADER_BYTES,
buf_size);
const uint8_t *tmp_buf = buf;
if (ff_combine_frame(pc, END_NOT_FOUND, &tmp_buf, &tmp_buf_size) != -1)
@ -86,13 +87,13 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
get_bits_count(&gb) / 8)) {
if (!pc->frame_start_found) {
pc->frame_start_found = 1;
s->duration = t->ti.last_frame_samples ?
t->ti.last_frame_samples :
t->ti.frame_samples;
s->duration = t->ti.last_frame_samples ?
t->ti.last_frame_samples :
t->ti.frame_samples;
} else {
pc->frame_start_found = 0;
next = t->index - pc->index;
t->index = 0;
next = t->index - pc->index;
t->index = 0;
goto found;
}
}
@ -109,7 +110,7 @@ found:
}
if (next != END_NOT_FOUND) {
next += consumed;
next += consumed;
pc->overread = FFMAX(0, -next);
}

File diff suppressed because it is too large Load Diff

View File

@ -26,8 +26,8 @@
#include "apetag.h"
typedef struct TAKDemuxContext {
int mlast_frame;
int64_t data_end;
int mlast_frame;
int64_t data_end;
} TAKDemuxContext;
static int tak_probe(AVProbeData *p)
@ -40,7 +40,7 @@ static int tak_probe(AVProbeData *p)
static int tak_read_header(AVFormatContext *s)
{
TAKDemuxContext *tc = s->priv_data;
AVIOContext *pb = s->pb;
AVIOContext *pb = s->pb;
GetBitContext gb;
AVStream *st;
uint8_t *buffer = NULL;
@ -95,7 +95,7 @@ static int tak_read_header(AVFormatContext *s)
av_log(s, AV_LOG_VERBOSE, "%02x", md5[i]);
av_log(s, AV_LOG_VERBOSE, "\n");
break;
}
}
case TAK_METADATA_END: {
int64_t curpos = avio_tell(pb);
@ -106,8 +106,7 @@ static int tak_read_header(AVFormatContext *s)
tc->data_end += curpos;
return 0;
break;
}
}
default:
ret = avio_skip(pb, size);
if (ret < 0)
@ -123,19 +122,19 @@ static int tak_read_header(AVFormatContext *s)
st->codec->bits_per_coded_sample = ti.bps;
if (ti.ch_layout)
st->codec->channel_layout = ti.ch_layout;
st->codec->sample_rate = ti.sample_rate;
st->codec->channels = ti.channels;
st->start_time = 0;
st->codec->sample_rate = ti.sample_rate;
st->codec->channels = ti.channels;
st->start_time = 0;
avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
st->codec->extradata = buffer;
st->codec->extradata_size = size;
buffer = NULL;
st->codec->extradata = buffer;
st->codec->extradata_size = size;
buffer = NULL;
} else if (type == TAK_METADATA_LAST_FRAME) {
if (size != 11)
return AVERROR_INVALIDDATA;
tc->mlast_frame = 1;
tc->data_end = get_bits64(&gb, TAK_LAST_FRAME_POS_BITS) +
get_bits(&gb, TAK_LAST_FRAME_SIZE_BITS);
tc->data_end = get_bits64(&gb, TAK_LAST_FRAME_POS_BITS) +
get_bits(&gb, TAK_LAST_FRAME_SIZE_BITS);
av_freep(&buffer);
} else if (type == TAK_METADATA_ENCODER) {
av_log(s, AV_LOG_VERBOSE, "encoder version: %0X\n",