1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

tak: Convert to the new bitstream reader

This commit is contained in:
Alexandra Hájková 2016-04-13 21:00:34 +02:00 committed by Diego Biurrun
parent 2e0e150144
commit 381a4e31a6
5 changed files with 125 additions and 120 deletions

View File

@ -24,6 +24,7 @@
#include "libavutil/intreadwrite.h"
#define BITSTREAM_READER_LE
#include "bitstream.h"
#include "tak.h"
static const uint16_t frame_duration_type_quants[] = {
@ -85,30 +86,30 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size)
return 0;
}
void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
void avpriv_tak_parse_streaminfo(BitstreamContext *bc, TAKStreamInfo *s)
{
uint64_t channel_mask = 0;
int frame_type, i;
s->codec = get_bits(gb, TAK_ENCODER_CODEC_BITS);
skip_bits(gb, TAK_ENCODER_PROFILE_BITS);
s->codec = bitstream_read(bc, TAK_ENCODER_CODEC_BITS);
bitstream_skip(bc, TAK_ENCODER_PROFILE_BITS);
frame_type = get_bits(gb, TAK_SIZE_FRAME_DURATION_BITS);
s->samples = get_bits64(gb, TAK_SIZE_SAMPLES_NUM_BITS);
frame_type = bitstream_read(bc, TAK_SIZE_FRAME_DURATION_BITS);
s->samples = bitstream_read_63(bc, 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) +
s->data_type = bitstream_read(bc, TAK_FORMAT_DATA_TYPE_BITS);
s->sample_rate = bitstream_read(bc, TAK_FORMAT_SAMPLE_RATE_BITS) +
TAK_SAMPLE_RATE_MIN;
s->bps = get_bits(gb, TAK_FORMAT_BPS_BITS) +
s->bps = bitstream_read(bc, TAK_FORMAT_BPS_BITS) +
TAK_BPS_MIN;
s->channels = get_bits(gb, TAK_FORMAT_CHANNEL_BITS) +
s->channels = bitstream_read(bc, TAK_FORMAT_CHANNEL_BITS) +
TAK_CHANNELS_MIN;
if (get_bits1(gb)) {
skip_bits(gb, TAK_FORMAT_VALID_BITS);
if (get_bits1(gb)) {
if (bitstream_read_bit(bc)) {
bitstream_skip(bc, TAK_FORMAT_VALID_BITS);
if (bitstream_read_bit(bc)) {
for (i = 0; i < s->channels; i++) {
int value = get_bits(gb, TAK_FORMAT_CH_LAYOUT_BITS);
int value = bitstream_read(bc, TAK_FORMAT_CH_LAYOUT_BITS);
if (value > 0 && value <= 18)
channel_mask |= 1 << (value - 1);
@ -120,33 +121,33 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
s->frame_samples = tak_get_nb_samples(s->sample_rate, frame_type);
}
int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
int ff_tak_decode_frame_header(AVCodecContext *avctx, BitstreamContext *bc,
TAKStreamInfo *ti, int log_level_offset)
{
if (get_bits(gb, TAK_FRAME_HEADER_SYNC_ID_BITS) != TAK_FRAME_HEADER_SYNC_ID) {
if (bitstream_read(bc, 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;
}
ti->flags = get_bits(gb, TAK_FRAME_HEADER_FLAGS_BITS);
ti->frame_num = get_bits(gb, TAK_FRAME_HEADER_NO_BITS);
ti->flags = bitstream_read(bc, TAK_FRAME_HEADER_FLAGS_BITS);
ti->frame_num = bitstream_read(bc, TAK_FRAME_HEADER_NO_BITS);
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);
ti->last_frame_samples = bitstream_read(bc, TAK_FRAME_HEADER_SAMPLE_COUNT_BITS) + 1;
bitstream_skip(bc, 2);
} else {
ti->last_frame_samples = 0;
}
if (ti->flags & TAK_FRAME_FLAG_HAS_INFO) {
avpriv_tak_parse_streaminfo(gb, ti);
avpriv_tak_parse_streaminfo(bc, ti);
if (get_bits(gb, 6))
skip_bits(gb, 25);
align_get_bits(gb);
if (bitstream_read(bc, 6))
bitstream_skip(bc, 25);
bitstream_align(bc);
}
skip_bits(gb, 24);
bitstream_skip(bc, 24);
return 0;
}

View File

@ -30,7 +30,7 @@
#include <stdint.h>
#include "avcodec.h"
#include "get_bits.h"
#include "bitstream.h"
#define TAK_FORMAT_DATA_TYPE_BITS 3
#define TAK_FORMAT_SAMPLE_RATE_BITS 18
@ -145,21 +145,21 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size);
/**
* Parse the Streaminfo metadata block.
* @param[in] gb pointer to GetBitContext
* @param[in] bc pointer to BitstreamContext
* @param[out] s storage for parsed information
*/
void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s);
void avpriv_tak_parse_streaminfo(BitstreamContext *bc, TAKStreamInfo *s);
/**
* Validate and decode a frame header.
* @param avctx AVCodecContext to use as av_log() context
* @param[in] gb GetBitContext from which to read frame header
* @param[in] bc BitstreamContext 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
*/
int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
int ff_tak_decode_frame_header(AVCodecContext *avctx, BitstreamContext *bc,
TAKStreamInfo *s, int log_level_offset);
#endif /* AVCODEC_TAK_H */

View File

@ -25,6 +25,7 @@
**/
#define BITSTREAM_READER_LE
#include "bitstream.h"
#include "parser.h"
#include "tak.h"
@ -47,14 +48,14 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
TAKParseContext *t = s->priv_data;
ParseContext *pc = &t->pc;
int next = END_NOT_FOUND;
GetBitContext gb;
BitstreamContext bc;
int consumed = 0;
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))
bitstream_init(&bc, buf, buf_size);
if (!ff_tak_decode_frame_header(avctx, &bc, &ti, 127))
s->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples
: t->ti.frame_samples;
*poutbuf = buf;
@ -79,14 +80,14 @@ static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,
pc->buffer[t->index + 1] == 0xA0) {
TAKStreamInfo ti;
init_get_bits(&gb, pc->buffer + t->index,
8 * (pc->index - t->index));
if (!ff_tak_decode_frame_header(avctx, &gb,
bitstream_init8(&bc, pc->buffer + t->index,
pc->index - t->index);
if (!ff_tak_decode_frame_header(avctx, &bc,
pc->frame_start_found ? &ti
: &t->ti,
127) &&
!ff_tak_check_crc(pc->buffer + t->index,
get_bits_count(&gb) / 8)) {
bitstream_tell(&bc) / 8)) {
if (!pc->frame_start_found) {
pc->frame_start_found = 1;
s->duration = t->ti.last_frame_samples ?

View File

@ -31,8 +31,9 @@
#define BITSTREAM_READER_LE
#include "audiodsp.h"
#include "avcodec.h"
#include "bitstream.h"
#include "internal.h"
#include "unary_legacy.h"
#include "unary.h"
#include "tak.h"
#define MAX_SUBFRAMES 8 // max number of subframes per channel
@ -49,7 +50,7 @@ typedef struct TAKDecContext {
AVCodecContext *avctx; // parent AVCodecContext
AudioDSPContext adsp;
TAKStreamInfo ti;
GetBitContext gb; // bitstream reader initialized to start at the current frame
BitstreamContext bc; // bitstream reader initialized to start at the current frame
int uval;
int nb_samples; // number of samples in the current frame
@ -238,7 +239,7 @@ static void decode_lpc(int32_t *coeffs, int mode, int length)
}
}
static int decode_segment(GetBitContext *gb, int mode, int32_t *decoded,
static int decode_segment(BitstreamContext *bc, int mode, int32_t *decoded,
int len)
{
struct CParam code;
@ -254,20 +255,20 @@ static int decode_segment(GetBitContext *gb, int mode, int32_t *decoded,
code = xcodes[mode - 1];
for (i = 0; i < len; i++) {
int x = get_bits_long(gb, code.init);
if (x >= code.escape && get_bits1(gb)) {
int x = bitstream_read(bc, code.init);
if (x >= code.escape && bitstream_read_bit(bc)) {
x |= 1 << code.init;
if (x >= code.aescape) {
int scale = get_unary(gb, 1, 9);
int scale = get_unary(bc, 1, 9);
if (scale == 9) {
int scale_bits = get_bits(gb, 3);
int scale_bits = bitstream_read(bc, 3);
if (scale_bits > 0) {
if (scale_bits == 7) {
scale_bits += get_bits(gb, 5);
scale_bits += bitstream_read(bc, 5);
if (scale_bits > 29)
return AVERROR_INVALIDDATA;
}
scale = get_bits_long(gb, scale_bits) + 1;
scale = bitstream_read(bc, scale_bits) + 1;
x += code.scale * scale;
}
x += code.bias;
@ -284,13 +285,13 @@ static int decode_segment(GetBitContext *gb, int mode, int32_t *decoded,
static int decode_residues(TAKDecContext *s, int32_t *decoded, int length)
{
GetBitContext *gb = &s->gb;
BitstreamContext *bc = &s->bc;
int i, mode, ret;
if (length > s->nb_samples)
return AVERROR_INVALIDDATA;
if (get_bits1(gb)) {
if (bitstream_read_bit(bc)) {
int wlength, rval;
int coding_mode[128];
@ -306,20 +307,21 @@ static int decode_residues(TAKDecContext *s, int32_t *decoded, int length)
if (wlength <= 1 || wlength > 128)
return AVERROR_INVALIDDATA;
coding_mode[0] = mode = get_bits(gb, 6);
coding_mode[0] =
mode = bitstream_read(bc, 6);
for (i = 1; i < wlength; i++) {
int c = get_unary(gb, 1, 6);
int c = get_unary(bc, 1, 6);
switch (c) {
case 6:
mode = get_bits(gb, 6);
mode = bitstream_read(bc, 6);
break;
case 5:
case 4:
case 3: {
/* mode += sign ? (1 - c) : (c - 1) */
int sign = get_bits1(gb);
int sign = bitstream_read_bit(bc);
mode += (-sign ^ (c - 1)) + sign;
break;
}
@ -349,23 +351,23 @@ static int decode_residues(TAKDecContext *s, int32_t *decoded, int length)
break;
} while (coding_mode[i] == mode);
if ((ret = decode_segment(gb, mode, decoded, len)) < 0)
if ((ret = decode_segment(bc, mode, decoded, len)) < 0)
return ret;
decoded += len;
}
} else {
mode = get_bits(gb, 6);
if ((ret = decode_segment(gb, mode, decoded, length)) < 0)
mode = bitstream_read(bc, 6);
if ((ret = decode_segment(bc, mode, decoded, length)) < 0)
return ret;
}
return 0;
}
static int get_bits_esc4(GetBitContext *gb)
static int bits_esc4(BitstreamContext *bc)
{
if (get_bits1(gb))
return get_bits(gb, 4) + 1;
if (bitstream_read_bit(bc))
return bitstream_read(bc, 4) + 1;
else
return 0;
}
@ -373,23 +375,23 @@ static int get_bits_esc4(GetBitContext *gb)
static void decode_filter_coeffs(TAKDecContext *s, int filter_order, int size,
int filter_quant, int16_t *filter)
{
GetBitContext *gb = &s->gb;
BitstreamContext *bc = &s->bc;
int i, j, a, b;
int filter_tmp[MAX_PREDICTORS];
int16_t predictors[MAX_PREDICTORS];
predictors[0] = get_sbits(gb, 10);
predictors[1] = get_sbits(gb, 10);
predictors[2] = get_sbits(gb, size) << (10 - size);
predictors[3] = get_sbits(gb, size) << (10 - size);
predictors[0] = bitstream_read_signed(bc, 10);
predictors[1] = bitstream_read_signed(bc, 10);
predictors[2] = bitstream_read_signed(bc, size) << (10 - size);
predictors[3] = bitstream_read_signed(bc, size) << (10 - size);
if (filter_order > 4) {
int av_uninit(code_size);
int code_size_base = size - get_bits1(gb);
int code_size_base = size - bitstream_read_bit(bc);
for (i = 4; i < filter_order; i++) {
if (!(i & 3))
code_size = code_size_base - get_bits(gb, 2);
predictors[i] = get_sbits(gb, code_size) << (10 - size);
code_size = code_size_base - bitstream_read(bc, 2);
predictors[i] = bitstream_read_signed(bc, code_size) << (10 - size);
}
}
@ -421,18 +423,18 @@ static int decode_subframe(TAKDecContext *s, int32_t *decoded,
int subframe_size, int prev_subframe_size)
{
LOCAL_ALIGNED_16(int16_t, filter, [MAX_PREDICTORS]);
GetBitContext *gb = &s->gb;
BitstreamContext *bc = &s->bc;
int i, ret;
int dshift, size, filter_quant, filter_order;
memset(filter, 0, MAX_PREDICTORS * sizeof(*filter));
if (!get_bits1(gb))
if (!bitstream_read_bit(bc))
return decode_residues(s, decoded, subframe_size);
filter_order = predictor_sizes[get_bits(gb, 4)];
filter_order = predictor_sizes[bitstream_read(bc, 4)];
if (prev_subframe_size > 0 && get_bits1(gb)) {
if (prev_subframe_size > 0 && bitstream_read_bit(bc)) {
if (filter_order > prev_subframe_size)
return AVERROR_INVALIDDATA;
@ -447,7 +449,7 @@ static int decode_subframe(TAKDecContext *s, int32_t *decoded,
if (filter_order > subframe_size)
return AVERROR_INVALIDDATA;
lpc_mode = get_bits(gb, 2);
lpc_mode = bitstream_read(bc, 2);
if (lpc_mode > 2)
return AVERROR_INVALIDDATA;
@ -458,12 +460,12 @@ static int decode_subframe(TAKDecContext *s, int32_t *decoded,
decode_lpc(decoded, lpc_mode, filter_order);
}
dshift = get_bits_esc4(gb);
size = get_bits1(gb) + 6;
dshift = bits_esc4(bc);
size = bitstream_read_bit(bc) + 6;
filter_quant = 10;
if (get_bits1(gb)) {
filter_quant -= get_bits(gb, 3) + 1;
if (bitstream_read_bit(bc)) {
filter_quant -= bitstream_read(bc, 3) + 1;
if (filter_quant < 3)
return AVERROR_INVALIDDATA;
}
@ -502,35 +504,35 @@ static int decode_subframe(TAKDecContext *s, int32_t *decoded,
static int decode_channel(TAKDecContext *s, int chan)
{
AVCodecContext *avctx = s->avctx;
GetBitContext *gb = &s->gb;
BitstreamContext *bc = &s->bc;
int32_t *decoded = s->decoded[chan];
int left = s->nb_samples - 1;
int i, prev, ret, nb_subframes;
int subframe_len[MAX_SUBFRAMES];
s->sample_shift[chan] = get_bits_esc4(gb);
s->sample_shift[chan] = bits_esc4(bc);
if (s->sample_shift[chan] >= avctx->bits_per_coded_sample)
return AVERROR_INVALIDDATA;
/* NOTE: TAK 2.2.0 appears to set the sample value to 0 if
* bits_per_coded_sample - sample_shift is 1, but this produces
* non-bit-exact output. Reading the 1 bit using get_sbits() instead
* of skipping it produces bit-exact output. This has been reported
* to the TAK author. */
*decoded++ = get_sbits(gb,
avctx->bits_per_coded_sample -
s->sample_shift[chan]);
s->lpc_mode[chan] = get_bits(gb, 2);
nb_subframes = get_bits(gb, 3) + 1;
* non-bit-exact output. Reading the 1 bit using bitstream_read_signed()
* instead of skipping it produces bit-exact output. This has been
* reported to the TAK author. */
*decoded++ = bitstream_read_signed(bc,
avctx->bits_per_coded_sample -
s->sample_shift[chan]);
s->lpc_mode[chan] = bitstream_read(bc, 2);
nb_subframes = bitstream_read(bc, 3) + 1;
i = 0;
if (nb_subframes > 1) {
if (get_bits_left(gb) < (nb_subframes - 1) * 6)
if (bitstream_bits_left(bc) < (nb_subframes - 1) * 6)
return AVERROR_INVALIDDATA;
prev = 0;
for (; i < nb_subframes - 1; i++) {
int subframe_end = get_bits(gb, 6) * s->subframe_scale;
int subframe_end = bitstream_read(bc, 6) * s->subframe_scale;
if (subframe_end <= prev)
return AVERROR_INVALIDDATA;
subframe_len[i] = subframe_end - prev;
@ -556,7 +558,7 @@ static int decode_channel(TAKDecContext *s, int chan)
static int decorrelate(TAKDecContext *s, int c1, int c2, int length)
{
GetBitContext *gb = &s->gb;
BitstreamContext *bc = &s->bc;
int32_t *p1 = s->decoded[c1] + 1;
int32_t *p2 = s->decoded[c2] + 1;
int i;
@ -589,8 +591,8 @@ static int decorrelate(TAKDecContext *s, int c1, int c2, int length)
case 4: /* side/left with scale factor */
FFSWAP(int32_t*, p1, p2);
case 5: /* side/right with scale factor */
dshift = get_bits_esc4(gb);
dfactor = get_sbits(gb, 10);
dshift = bits_esc4(bc);
dfactor = bitstream_read_signed(bc, 10);
for (i = 0; i < length; i++) {
int32_t a = p1[i];
int32_t b = p2[i];
@ -610,15 +612,15 @@ static int decorrelate(TAKDecContext *s, int c1, int c2, int length)
if (length < 256)
return AVERROR_INVALIDDATA;
dshift = get_bits_esc4(gb);
filter_order = 8 << get_bits1(gb);
dval1 = get_bits1(gb);
dval2 = get_bits1(gb);
dshift = bits_esc4(bc);
filter_order = 8 << bitstream_read_bit(bc);
dval1 = bitstream_read_bit(bc);
dval2 = bitstream_read_bit(bc);
for (i = 0; i < filter_order; i++) {
if (!(i & 3))
code_size = 14 - get_bits(gb, 3);
filter[i] = get_sbits(gb, code_size);
code_size = 14 - bitstream_read(bc, 3);
filter[i] = bitstream_read_signed(bc, code_size);
}
order_half = filter_order / 2;
@ -675,15 +677,15 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
{
TAKDecContext *s = avctx->priv_data;
AVFrame *frame = data;
GetBitContext *gb = &s->gb;
BitstreamContext *bc = &s->bc;
int chan, i, ret, hsize;
if (pkt->size < TAK_MIN_FRAME_HEADER_BYTES)
return AVERROR_INVALIDDATA;
init_get_bits(gb, pkt->data, pkt->size * 8);
bitstream_init8(bc, pkt->data, pkt->size);
if ((ret = ff_tak_decode_frame_header(avctx, gb, &s->ti, 0)) < 0)
if ((ret = ff_tak_decode_frame_header(avctx, bc, &s->ti, 0)) < 0)
return ret;
if (s->ti.flags & TAK_FRAME_FLAG_HAS_METADATA) {
@ -691,7 +693,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
return AVERROR_PATCHWELCOME;
}
hsize = get_bits_count(gb) / 8;
hsize = bitstream_tell(bc) / 8;
if (avctx->err_recognition & AV_EF_CRCCHECK) {
if (ff_tak_check_crc(pkt->data, hsize)) {
av_log(avctx, AV_LOG_ERROR, "CRC error\n");
@ -769,7 +771,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
for (chan = 0; chan < avctx->channels; chan++) {
int32_t *decoded = s->decoded[chan];
for (i = 0; i < s->nb_samples; i++)
decoded[i] = get_sbits(gb, avctx->bits_per_coded_sample);
decoded[i] = bitstream_read_signed(bc, avctx->bits_per_coded_sample);
}
} else {
if (s->ti.codec == TAK_CODEC_MONO_STEREO) {
@ -778,25 +780,25 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
return ret;
if (avctx->channels == 2) {
if (get_bits1(gb)) {
if (bitstream_read_bit(bc)) {
// some kind of subframe length, but it seems to be unused
skip_bits(gb, 6);
bitstream_skip(bc, 6);
}
s->dmode = get_bits(gb, 3);
s->dmode = bitstream_read(bc, 3);
if (ret = decorrelate(s, 0, 1, s->nb_samples - 1))
return ret;
}
} else if (s->ti.codec == TAK_CODEC_MULTICHANNEL) {
if (get_bits1(gb)) {
if (bitstream_read_bit(bc)) {
int ch_mask = 0;
chan = get_bits(gb, 4) + 1;
chan = bitstream_read(bc, 4) + 1;
if (chan > avctx->channels)
return AVERROR_INVALIDDATA;
for (i = 0; i < chan; i++) {
int nbit = get_bits(gb, 4);
int nbit = bitstream_read(bc, 4);
if (nbit >= avctx->channels)
return AVERROR_INVALIDDATA;
@ -804,10 +806,10 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
if (ch_mask & 1 << nbit)
return AVERROR_INVALIDDATA;
s->mcdparams[i].present = get_bits1(gb);
s->mcdparams[i].present = bitstream_read_bit(bc);
if (s->mcdparams[i].present) {
s->mcdparams[i].index = get_bits(gb, 2);
s->mcdparams[i].chan2 = get_bits(gb, 4);
s->mcdparams[i].index = bitstream_read(bc, 2);
s->mcdparams[i].chan2 = bitstream_read(bc, 4);
if (s->mcdparams[i].chan2 >= avctx->channels) {
av_log(avctx, AV_LOG_ERROR,
"invalid channel 2 (%d) for %d channel(s)\n",
@ -867,16 +869,16 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
}
}
align_get_bits(gb);
skip_bits(gb, 24);
if (get_bits_left(gb) < 0)
bitstream_align(bc);
bitstream_skip(bc, 24);
if (bitstream_bits_left(bc) < 0)
av_log(avctx, AV_LOG_DEBUG, "overread\n");
else if (get_bits_left(gb) > 0)
else if (bitstream_bits_left(bc) > 0)
av_log(avctx, AV_LOG_DEBUG, "underread\n");
if (avctx->err_recognition & AV_EF_CRCCHECK) {
if (ff_tak_check_crc(pkt->data + hsize,
get_bits_count(gb) / 8 - hsize)) {
bitstream_tell(bc) / 8 - hsize)) {
av_log(avctx, AV_LOG_ERROR, "CRC error\n");
if (avctx->err_recognition & AV_EF_EXPLODE)
return AVERROR_INVALIDDATA;

View File

@ -20,6 +20,7 @@
*/
#define BITSTREAM_READER_LE
#include "libavcodec/bitstream.h"
#include "libavcodec/tak.h"
#include "apetag.h"
@ -43,7 +44,7 @@ static int tak_read_header(AVFormatContext *s)
{
TAKDemuxContext *tc = s->priv_data;
AVIOContext *pb = s->pb;
GetBitContext gb;
BitstreamContext bc;
AVStream *st;
uint8_t *buffer = NULL;
int ret;
@ -82,7 +83,7 @@ static int tak_read_header(AVFormatContext *s)
return AVERROR(EIO);
}
init_get_bits(&gb, buffer, size * 8);
bitstream_init8(&bc, buffer, size);
break;
case TAK_METADATA_MD5: {
uint8_t md5[16];
@ -118,7 +119,7 @@ static int tak_read_header(AVFormatContext *s)
if (type == TAK_METADATA_STREAMINFO) {
TAKStreamInfo ti;
avpriv_tak_parse_streaminfo(&gb, &ti);
avpriv_tak_parse_streaminfo(&bc, &ti);
if (ti.samples > 0)
st->duration = ti.samples;
st->codecpar->bits_per_coded_sample = ti.bps;
@ -135,12 +136,12 @@ static int tak_read_header(AVFormatContext *s)
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 = bitstream_read_63(&bc, TAK_LAST_FRAME_POS_BITS) +
bitstream_read(&bc, TAK_LAST_FRAME_SIZE_BITS);
av_freep(&buffer);
} else if (type == TAK_METADATA_ENCODER) {
av_log(s, AV_LOG_VERBOSE, "encoder version: %0X\n",
get_bits_long(&gb, TAK_ENCODER_VERSION_BITS));
bitstream_read(&bc, TAK_ENCODER_VERSION_BITS));
av_freep(&buffer);
}
}