Commit 381a4e31 authored by Alexandra Hájková's avatar Alexandra Hájková Committed by Diego Biurrun

tak: Convert to the new bitstream reader

parent 2e0e1501
......@@ -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;
}
......@@ -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 */
......@@ -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 ?
......
This diff is collapsed.
......@@ -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);
}
}
......
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