aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/dolby_e.c
diff options
context:
space:
mode:
authorNicolas Gaullier <nicolas.gaullier@cji.paris>2021-01-25 13:11:37 +0100
committerPaul B Mahol <onemda@gmail.com>2021-01-25 13:19:48 +0100
commitc7016e35a624a75bb5b82bee932ddfe28d013b3f (patch)
treed150896f1723e2119044a2fd4f91e5fab6a90477 /libavcodec/dolby_e.c
parent0bf18db26aa277d11c4ae5ecb6dd7b8fad188add (diff)
downloadffmpeg-c7016e35a624a75bb5b82bee932ddfe28d013b3f.tar.gz
avcodec/dolby_e: Split decoder/parser files
Diffstat (limited to 'libavcodec/dolby_e.c')
-rw-r--r--libavcodec/dolby_e.c149
1 files changed, 6 insertions, 143 deletions
diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
index 6bb817ec5c..74388f43d1 100644
--- a/libavcodec/dolby_e.c
+++ b/libavcodec/dolby_e.c
@@ -28,13 +28,14 @@
#include "put_bits.h"
#include "parser.h"
#include "dolby_e.h"
+#include "dolby_edec.h"
+#include "dolby_e_parser_internal.h"
#include "fft.h"
static int skip_input(DBEContext *s, int nb_words)
{
if (nb_words > s->input_size) {
- if (s->avctx)
- av_log(s->avctx, AV_LOG_ERROR, "Packet too short\n");
+ av_log(s->avctx, AV_LOG_ERROR, "Packet too short\n");
return AVERROR_INVALIDDATA;
}
@@ -65,8 +66,7 @@ static int convert_input(DBEContext *s, int nb_words, int key)
av_assert0(nb_words <= 1024u);
if (nb_words > s->input_size) {
- if (s->avctx)
- av_log(s->avctx, AV_LOG_ERROR, "Packet too short\n");
+ av_log(s->avctx, AV_LOG_ERROR, "Packet too short\n");
return AVERROR_INVALIDDATA;
}
@@ -92,69 +92,6 @@ static int convert_input(DBEContext *s, int nb_words, int key)
return init_get_bits(&s->gb, s->buffer, nb_words * s->word_bits);
}
-static int parse_metadata(DBEContext *s, DolbyEHeaderInfo *hdr)
-{
- int i, ret, key, mtd_size;
-
- if ((key = parse_key(s)) < 0)
- return key;
- if ((ret = convert_input(s, 1, key)) < 0)
- return ret;
-
- skip_bits(&s->gb, 4);
- mtd_size = get_bits(&s->gb, 10);
- if (!mtd_size) {
- if (s->avctx)
- av_log(s->avctx, AV_LOG_ERROR, "Invalid metadata size\n");
- return AVERROR_INVALIDDATA;
- }
-
- if ((ret = convert_input(s, mtd_size, key)) < 0)
- return ret;
-
- skip_bits(&s->gb, 14);
- hdr->prog_conf = get_bits(&s->gb, 6);
- if (hdr->prog_conf > MAX_PROG_CONF) {
- if (s->avctx)
- av_log(s->avctx, AV_LOG_ERROR, "Invalid program configuration\n");
- return AVERROR_INVALIDDATA;
- }
-
- hdr->nb_channels = nb_channels_tab[hdr->prog_conf];
- hdr->nb_programs = nb_programs_tab[hdr->prog_conf];
-
- hdr->fr_code = get_bits(&s->gb, 4);
- hdr->fr_code_orig = get_bits(&s->gb, 4);
- if (!sample_rate_tab[hdr->fr_code] ||
- !sample_rate_tab[hdr->fr_code_orig]) {
- if (s->avctx)
- av_log(s->avctx, AV_LOG_ERROR, "Invalid frame rate code\n");
- return AVERROR_INVALIDDATA;
- }
-
- skip_bits_long(&s->gb, 88);
- for (i = 0; i < hdr->nb_channels; i++)
- hdr->ch_size[i] = get_bits(&s->gb, 10);
- hdr->mtd_ext_size = get_bits(&s->gb, 8);
- hdr->meter_size = get_bits(&s->gb, 8);
-
- skip_bits_long(&s->gb, 10 * hdr->nb_programs);
- for (i = 0; i < hdr->nb_channels; i++) {
- hdr->rev_id[i] = get_bits(&s->gb, 4);
- skip_bits1(&s->gb);
- hdr->begin_gain[i] = get_bits(&s->gb, 10);
- hdr->end_gain[i] = get_bits(&s->gb, 10);
- }
-
- if (get_bits_left(&s->gb) < 0) {
- if (s->avctx)
- av_log(s->avctx, AV_LOG_ERROR, "Read past end of metadata\n");
- return AVERROR_INVALIDDATA;
- }
-
- return skip_input(s, mtd_size + 1);
-}
-
static int parse_metadata_ext(DBEDecodeContext *s1)
{
DBEContext *s = &s1->dectx;
@@ -603,73 +540,6 @@ static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
return 0;
}
-static int dolby_e_sync(DBEContext *s, const uint8_t *buf, int buf_size)
-{
- int hdr;
-
- if (buf_size < 3)
- return AVERROR_INVALIDDATA;
-
- hdr = AV_RB24(buf);
- if ((hdr & 0xfffffe) == 0x7888e) {
- s->word_bits = 24;
- } else if ((hdr & 0xffffe0) == 0x788e0) {
- s->word_bits = 20;
- } else if ((hdr & 0xfffe00) == 0x78e00) {
- s->word_bits = 16;
- } else {
- if (s->avctx)
- av_log(s->avctx, AV_LOG_ERROR, "Invalid frame header\n");
- return AVERROR_INVALIDDATA;
- }
-
- s->word_bytes = s->word_bits + 7 >> 3;
- s->input = buf + s->word_bytes;
- s->input_size = buf_size / s->word_bytes - 1;
- s->key_present = hdr >> 24 - s->word_bits & 1;
-
- return 0;
-}
-
-static int dolby_e_parse(AVCodecParserContext *s2, AVCodecContext *avctx,
- const uint8_t **poutbuf, int *poutbuf_size,
- const uint8_t *buf, int buf_size)
-{
- DBEParseContext *s1 = s2->priv_data;
- DBEContext *s = &s1->dectx;
- int ret;
-
- if ((ret = dolby_e_sync(s, buf, buf_size)) < 0)
- goto end;
-
- if ((ret = parse_metadata(s, &s1->metadata)) < 0)
- goto end;
-
- s2->duration = FRAME_SAMPLES;
- switch (s1->metadata.nb_channels) {
- case 4:
- avctx->channel_layout = AV_CH_LAYOUT_4POINT0;
- break;
- case 6:
- avctx->channel_layout = AV_CH_LAYOUT_5POINT1;
- break;
- case 8:
- avctx->channel_layout = AV_CH_LAYOUT_7POINT1;
- break;
- }
-
- avctx->channels = s1->metadata.nb_channels;
- avctx->sample_rate = sample_rate_tab[s1->metadata.fr_code];
- avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
-
-end:
- /* always return the full packet. this parser isn't doing any splitting or
- combining, only packet analysis */
- *poutbuf = buf;
- *poutbuf_size = buf_size;
- return buf_size;
-}
-
static int dolby_e_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{
@@ -677,10 +547,10 @@ static int dolby_e_decode_frame(AVCodecContext *avctx, void *data,
DBEContext *s = &s1->dectx;
int i, j, ret;
- if ((ret = dolby_e_sync(s, avpkt->data, avpkt->size)) < 0)
+ if ((ret = ff_dolby_e_parse_init(s, avpkt->data, avpkt->size)) < 0)
return ret;
- if ((ret = parse_metadata(s, &s1->metadata)) < 0)
+ if ((ret = ff_dolby_e_parse_header(s, &s1->metadata)) < 0)
return ret;
if (s1->metadata.nb_programs > 1 && !s1->metadata.multi_prog_warned) {
@@ -853,13 +723,6 @@ static av_cold int dolby_e_init(AVCodecContext *avctx)
return 0;
}
-AVCodecParser ff_dolby_e_parser = {
- .codec_ids = { AV_CODEC_ID_DOLBY_E },
- .priv_data_size = sizeof(DBEParseContext),
- .parser_parse = dolby_e_parse,
- .parser_close = ff_parse_close,
-};
-
AVCodec ff_dolby_e_decoder = {
.name = "dolby_e",
.long_name = NULL_IF_CONFIG_SMALL("Dolby E"),