diff options
Diffstat (limited to 'libavcodec/tak.c')
-rw-r--r-- | libavcodec/tak.c | 120 |
1 files changed, 70 insertions, 50 deletions
diff --git a/libavcodec/tak.c b/libavcodec/tak.c index c90e55a..8aa956b 100644 --- a/libavcodec/tak.c +++ b/libavcodec/tak.c @@ -2,31 +2,51 @@ * TAK common code * Copyright (c) 2012 Paul B Mahol * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/bswap.h" #include "libavutil/crc.h" #include "libavutil/intreadwrite.h" #define BITSTREAM_READER_LE -#include "bitstream.h" #include "tak.h" +static const int64_t tak_channel_layouts[] = { + 0, + AV_CH_FRONT_LEFT, + AV_CH_FRONT_RIGHT, + AV_CH_FRONT_CENTER, + AV_CH_LOW_FREQUENCY, + AV_CH_BACK_LEFT, + AV_CH_BACK_RIGHT, + AV_CH_FRONT_LEFT_OF_CENTER, + AV_CH_FRONT_RIGHT_OF_CENTER, + AV_CH_BACK_CENTER, + AV_CH_SIDE_LEFT, + AV_CH_SIDE_RIGHT, + AV_CH_TOP_CENTER, + AV_CH_TOP_FRONT_LEFT, + AV_CH_TOP_FRONT_CENTER, + AV_CH_TOP_FRONT_RIGHT, + AV_CH_TOP_BACK_LEFT, + AV_CH_TOP_BACK_CENTER, + AV_CH_TOP_BACK_RIGHT, +}; + static const uint16_t frame_duration_type_quants[] = { 3, 4, 6, 8, 4096, 8192, 16384, 512, 1024, 2048, }; @@ -54,22 +74,6 @@ static int tak_get_nb_samples(int sample_rate, enum TAKFrameSizeType type) return nb_samples; } -static int crc_init = 0; -#if CONFIG_SMALL -#define CRC_TABLE_SIZE 257 -#else -#define CRC_TABLE_SIZE 1024 -#endif -static AVCRC crc_24[CRC_TABLE_SIZE]; - -av_cold void ff_tak_init_crc(void) -{ - if (!crc_init) { - av_crc_init(crc_24, 0, 24, 0x864CFBU, sizeof(crc_24)); - crc_init = 1; - } -} - int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size) { uint32_t crc, CRC; @@ -78,41 +82,41 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size) return AVERROR_INVALIDDATA; buf_size -= 3; - CRC = av_bswap32(AV_RL24(buf + buf_size)) >> 8; - crc = av_crc(crc_24, 0xCE04B7U, buf, buf_size); + CRC = AV_RB24(buf + buf_size); + crc = av_crc(av_crc_get_table(AV_CRC_24_IEEE), 0xCE04B7U, buf, buf_size); if (CRC != crc) return AVERROR_INVALIDDATA; return 0; } -void avpriv_tak_parse_streaminfo(BitstreamContext *bc, TAKStreamInfo *s) +void ff_tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb) { uint64_t channel_mask = 0; int frame_type, i; - s->codec = bitstream_read(bc, TAK_ENCODER_CODEC_BITS); - bitstream_skip(bc, TAK_ENCODER_PROFILE_BITS); + s->codec = get_bits(gb, TAK_ENCODER_CODEC_BITS); + skip_bits(gb, TAK_ENCODER_PROFILE_BITS); - frame_type = bitstream_read(bc, TAK_SIZE_FRAME_DURATION_BITS); - s->samples = bitstream_read_63(bc, TAK_SIZE_SAMPLES_NUM_BITS); + frame_type = get_bits(gb, TAK_SIZE_FRAME_DURATION_BITS); + s->samples = get_bits64(gb, TAK_SIZE_SAMPLES_NUM_BITS); - s->data_type = bitstream_read(bc, TAK_FORMAT_DATA_TYPE_BITS); - s->sample_rate = bitstream_read(bc, TAK_FORMAT_SAMPLE_RATE_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 = bitstream_read(bc, TAK_FORMAT_BPS_BITS) + + s->bps = get_bits(gb, TAK_FORMAT_BPS_BITS) + TAK_BPS_MIN; - s->channels = bitstream_read(bc, TAK_FORMAT_CHANNEL_BITS) + + s->channels = get_bits(gb, TAK_FORMAT_CHANNEL_BITS) + TAK_CHANNELS_MIN; - if (bitstream_read_bit(bc)) { - bitstream_skip(bc, TAK_FORMAT_VALID_BITS); - if (bitstream_read_bit(bc)) { + if (get_bits1(gb)) { + skip_bits(gb, TAK_FORMAT_VALID_BITS); + if (get_bits1(gb)) { for (i = 0; i < s->channels; i++) { - int value = bitstream_read(bc, TAK_FORMAT_CH_LAYOUT_BITS); + int value = get_bits(gb, TAK_FORMAT_CH_LAYOUT_BITS); - if (value > 0 && value <= 18) - channel_mask |= 1 << (value - 1); + if (value < FF_ARRAY_ELEMS(tak_channel_layouts)) + channel_mask |= tak_channel_layouts[value]; } } } @@ -121,33 +125,49 @@ void avpriv_tak_parse_streaminfo(BitstreamContext *bc, TAKStreamInfo *s) s->frame_samples = tak_get_nb_samples(s->sample_rate, frame_type); } -int ff_tak_decode_frame_header(AVCodecContext *avctx, BitstreamContext *bc, +int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size) +{ + GetBitContext gb; + int ret = init_get_bits8(&gb, buf, size); + + if (ret < 0) + return AVERROR_INVALIDDATA; + + ff_tak_parse_streaminfo(s, &gb); + + return 0; +} + +int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, TAKStreamInfo *ti, int log_level_offset) { - if (bitstream_read(bc, 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"); return AVERROR_INVALIDDATA; } - ti->flags = bitstream_read(bc, TAK_FRAME_HEADER_FLAGS_BITS); - ti->frame_num = bitstream_read(bc, TAK_FRAME_HEADER_NO_BITS); + ti->flags = get_bits(gb, TAK_FRAME_HEADER_FLAGS_BITS); + ti->frame_num = get_bits(gb, TAK_FRAME_HEADER_NO_BITS); if (ti->flags & TAK_FRAME_FLAG_IS_LAST) { - ti->last_frame_samples = bitstream_read(bc, TAK_FRAME_HEADER_SAMPLE_COUNT_BITS) + 1; - bitstream_skip(bc, 2); + 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 (ti->flags & TAK_FRAME_FLAG_HAS_INFO) { - avpriv_tak_parse_streaminfo(bc, ti); + ff_tak_parse_streaminfo(ti, gb); - if (bitstream_read(bc, 6)) - bitstream_skip(bc, 25); - bitstream_align(bc); + if (get_bits(gb, 6)) + skip_bits(gb, 25); + align_get_bits(gb); } - bitstream_skip(bc, 24); + if (ti->flags & TAK_FRAME_FLAG_HAS_METADATA) + return AVERROR_INVALIDDATA; + + skip_bits(gb, 24); return 0; } |