Commit cef28b56 authored by Paul B Mahol's avatar Paul B Mahol

tak: reduce difference with qatar

Mostly cosmetics changes, but also makes
decoding little faster here.
Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 461b5bf4
...@@ -60,7 +60,8 @@ static int tak_get_nb_samples(int sample_rate, enum TAKFrameSizeType type) ...@@ -60,7 +60,8 @@ static int tak_get_nb_samples(int sample_rate, enum TAKFrameSizeType type)
max_nb_samples = 16384; max_nb_samples = 16384;
} else if (type < FF_ARRAY_ELEMS(frame_duration_type_quants)) { } else if (type < FF_ARRAY_ELEMS(frame_duration_type_quants)) {
nb_samples = frame_duration_type_quants[type]; nb_samples = frame_duration_type_quants[type];
max_nb_samples = sample_rate * frame_duration_type_quants[TAK_FST_250ms] >> max_nb_samples = sample_rate *
frame_duration_type_quants[TAK_FST_250ms] >>
TAK_FRAME_DURATION_QUANT_SHIFT; TAK_FRAME_DURATION_QUANT_SHIFT;
} else { } else {
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
...@@ -116,9 +117,12 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s) ...@@ -116,9 +117,12 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
s->samples = get_bits64(gb, TAK_SIZE_SAMPLES_NUM_BITS); s->samples = get_bits64(gb, TAK_SIZE_SAMPLES_NUM_BITS);
s->data_type = get_bits(gb, TAK_FORMAT_DATA_TYPE_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->sample_rate = get_bits(gb, TAK_FORMAT_SAMPLE_RATE_BITS) +
s->bps = get_bits(gb, TAK_FORMAT_BPS_BITS) + TAK_BPS_MIN; TAK_SAMPLE_RATE_MIN;
s->channels = get_bits(gb, TAK_FORMAT_CHANNEL_BITS) + TAK_CHANNELS_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)) { if (get_bits1(gb)) {
skip_bits(gb, TAK_FORMAT_VALID_BITS); skip_bits(gb, TAK_FORMAT_VALID_BITS);
...@@ -136,31 +140,25 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s) ...@@ -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); 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, int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
TAKStreamInfo *ti, int log_level_offset) TAKStreamInfo *ti, int log_level_offset)
{ {
int flags;
if (get_bits(gb, TAK_FRAME_HEADER_SYNC_ID_BITS) != TAK_FRAME_HEADER_SYNC_ID) { 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"); av_log(avctx, AV_LOG_ERROR + log_level_offset, "missing sync id\n");
return AVERROR_INVALIDDATA; 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); 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; ti->last_frame_samples = get_bits(gb, TAK_FRAME_HEADER_SAMPLE_COUNT_BITS) + 1;
skip_bits(gb, 2); skip_bits(gb, 2);
} else { } else {
ti->last_frame_samples = 0; ti->last_frame_samples = 0;
} }
if (flags & FRAME_HAVE_INFO) { if (ti->flags & TAK_FRAME_FLAG_HAS_INFO) {
avpriv_tak_parse_streaminfo(gb, ti); avpriv_tak_parse_streaminfo(gb, ti);
if (get_bits(gb, 6)) if (get_bits(gb, 6))
...@@ -168,7 +166,7 @@ int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, ...@@ -168,7 +166,7 @@ int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
align_get_bits(gb); align_get_bits(gb);
} }
if (flags & FRAME_HAVE_METADATA) if (ti->flags & TAK_FRAME_FLAG_HAS_METADATA)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
skip_bits(gb, 24); skip_bits(gb, 24);
......
...@@ -57,40 +57,50 @@ ...@@ -57,40 +57,50 @@
#define TAK_FRAME_DURATION_QUANT_SHIFT 5 #define TAK_FRAME_DURATION_QUANT_SHIFT 5
#define TAK_CRC24_BITS 24 #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 + \ #define TAK_FRAME_FLAG_IS_LAST 0x1
#define TAK_FRAME_FLAG_HAS_INFO 0x2
#define TAK_FRAME_FLAG_HAS_METADATA 0x4
#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_FLAGS_BITS + \
TAK_FRAME_HEADER_NO_BITS + \ TAK_FRAME_HEADER_NO_BITS + \
TAK_CRC24_BITS ) TAK_CRC24_BITS)
#define TAK_MIN_FRAME_HEADER_LAST_BITS ( TAK_MIN_FRAME_HEADER_BITS + 2 + \ #define TAK_MIN_FRAME_HEADER_LAST_BITS (TAK_MIN_FRAME_HEADER_BITS + 2 + \
TAK_FRAME_HEADER_SAMPLE_COUNT_BITS ) TAK_FRAME_HEADER_SAMPLE_COUNT_BITS)
#define TAK_ENCODER_BITS ( TAK_ENCODER_CODEC_BITS + \ #define TAK_ENCODER_BITS (TAK_ENCODER_CODEC_BITS + \
TAK_ENCODER_PROFILE_BITS ) TAK_ENCODER_PROFILE_BITS)
#define TAK_SIZE_BITS ( TAK_SIZE_SAMPLES_NUM_BITS + \ #define TAK_SIZE_BITS (TAK_SIZE_SAMPLES_NUM_BITS + \
TAK_SIZE_FRAME_DURATION_BITS ) TAK_SIZE_FRAME_DURATION_BITS)
#define TAK_FORMAT_BITS ( TAK_FORMAT_DATA_TYPE_BITS + \ #define TAK_FORMAT_BITS (TAK_FORMAT_DATA_TYPE_BITS + \
TAK_FORMAT_SAMPLE_RATE_BITS + \ TAK_FORMAT_SAMPLE_RATE_BITS + \
TAK_FORMAT_BPS_BITS + \ TAK_FORMAT_BPS_BITS + \
TAK_FORMAT_CHANNEL_BITS + 1 + \ TAK_FORMAT_CHANNEL_BITS + 1 + \
TAK_FORMAT_VALID_BITS + 1 + \ TAK_FORMAT_VALID_BITS + 1 + \
TAK_FORMAT_CH_LAYOUT_BITS * \ TAK_FORMAT_CH_LAYOUT_BITS * \
TAK_MAX_CHANNELS ) TAK_MAX_CHANNELS)
#define TAK_STREAMINFO_BITS ( TAK_ENCODER_BITS + \ #define TAK_STREAMINFO_BITS (TAK_ENCODER_BITS + \
TAK_SIZE_BITS + \ TAK_SIZE_BITS + \
TAK_FORMAT_BITS ) TAK_FORMAT_BITS)
#define TAK_MAX_FRAME_HEADER_BITS ( TAK_MIN_FRAME_HEADER_LAST_BITS + \ #define TAK_MAX_FRAME_HEADER_BITS (TAK_MIN_FRAME_HEADER_LAST_BITS + \
TAK_STREAMINFO_BITS + 31 ) TAK_STREAMINFO_BITS + 31)
#define TAK_STREAMINFO_BYTES (( TAK_STREAMINFO_BITS + 7 ) / 8) #define TAK_STREAMINFO_BYTES ((TAK_STREAMINFO_BITS + 7) / 8)
#define TAK_MAX_FRAME_HEADER_BYTES (( TAK_MAX_FRAME_HEADER_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_MIN_FRAME_HEADER_BYTES ((TAK_MIN_FRAME_HEADER_BITS + 7) / 8)
enum TAKCodecType {
TAK_CODEC_MONO_STEREO = 2,
TAK_CODEC_MULTICHANNEL = 4,
};
enum TAKMetaDataType { enum TAKMetaDataType {
TAK_METADATA_END = 0, TAK_METADATA_END = 0,
...@@ -117,7 +127,8 @@ enum TAKFrameSizeType { ...@@ -117,7 +127,8 @@ enum TAKFrameSizeType {
}; };
typedef struct TAKStreamInfo { typedef struct TAKStreamInfo {
int codec; int flags;
enum TAKCodecType codec;
int data_type; int data_type;
int sample_rate; int sample_rate;
int channels; int channels;
...@@ -145,8 +156,9 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s); ...@@ -145,8 +156,9 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s);
* @param avctx AVCodecContext to use as av_log() context * @param avctx AVCodecContext to use as av_log() context
* @param[in] gb GetBitContext from which to read frame header * @param[in] gb GetBitContext from which to read frame header
* @param[out] s frame information * @param[out] s frame information
* @param log_level_offset log level offset. can be used to silence error messages. * @param log_level_offset log level offset, can be used to silence
* @return non-zero on error, 0 if ok * error messages.
* @return non-zero on error, 0 if OK
*/ */
int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
TAKStreamInfo *s, int log_level_offset); TAKStreamInfo *s, int log_level_offset);
......
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
* TAK parser * TAK parser
**/ **/
#include "parser.h"
#include "tak.h" #include "tak.h"
#include "parser.h"
typedef struct TAKParseContext { typedef struct TAKParseContext {
ParseContext pc; ParseContext pc;
...@@ -54,8 +54,8 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx, ...@@ -54,8 +54,8 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
TAKStreamInfo ti; TAKStreamInfo ti;
init_get_bits(&gb, buf, buf_size); init_get_bits(&gb, buf, buf_size);
if (!ff_tak_decode_frame_header(avctx, &gb, &ti, 127)) if (!ff_tak_decode_frame_header(avctx, &gb, &ti, 127))
s->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples : s->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples
t->ti.frame_samples; : t->ti.frame_samples;
*poutbuf = buf; *poutbuf = buf;
*poutbuf_size = buf_size; *poutbuf_size = buf_size;
return buf_size; return buf_size;
...@@ -63,7 +63,8 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx, ...@@ -63,7 +63,8 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
while (buf_size || t->index + needed <= pc->index) { while (buf_size || t->index + needed <= pc->index) {
if (buf_size && t->index + TAK_MAX_FRAME_HEADER_BYTES > 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; const uint8_t *tmp_buf = buf;
if (ff_combine_frame(pc, END_NOT_FOUND, &tmp_buf, &tmp_buf_size) != -1) if (ff_combine_frame(pc, END_NOT_FOUND, &tmp_buf, &tmp_buf_size) != -1)
......
This diff is collapsed.
...@@ -106,7 +106,6 @@ static int tak_read_header(AVFormatContext *s) ...@@ -106,7 +106,6 @@ static int tak_read_header(AVFormatContext *s)
tc->data_end += curpos; tc->data_end += curpos;
return 0; return 0;
break;
} }
default: default:
ret = avio_skip(pb, size); ret = avio_skip(pb, size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment