diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c index f828de2f88..9031c18210 100644 --- a/libavcodec/dolby_e.c +++ b/libavcodec/dolby_e.c @@ -25,7 +25,6 @@ #include "internal.h" #include "get_bits.h" -#include "put_bits.h" #include "dolby_e.h" #include "kbdwin.h" #include "fft.h" @@ -626,42 +625,6 @@ static int parse_key(DBEContext *s) return 0; } -static int convert_input(DBEContext *s, int nb_words, int key) -{ - const uint8_t *src = s->input; - uint8_t *dst = s->buffer; - PutBitContext pb; - int i; - - av_assert0(nb_words <= 1024u); - - if (nb_words > s->input_size) { - av_log(s->avctx, AV_LOG_ERROR, "Packet too short\n"); - return AVERROR_INVALIDDATA; - } - - switch (s->word_bits) { - case 16: - for (i = 0; i < nb_words; i++, src += 2, dst += 2) - AV_WB16(dst, AV_RB16(src) ^ key); - break; - case 20: - init_put_bits(&pb, s->buffer, sizeof(s->buffer)); - for (i = 0; i < nb_words; i++, src += 3) - put_bits(&pb, 20, AV_RB24(src) >> 4 ^ key); - flush_put_bits(&pb); - break; - case 24: - for (i = 0; i < nb_words; i++, src += 3, dst += 3) - AV_WB24(dst, AV_RB24(src) ^ key); - break; - default: - av_assert0(0); - } - - return init_get_bits(&s->gb, s->buffer, nb_words * s->word_bits); -} - static int parse_metadata_ext(DBEDecodeContext *s1) { DBEContext *s = &s1->dectx; @@ -992,7 +955,8 @@ static int parse_audio(DBEDecodeContext *s1, int start, int end, int seg_id) s1->channels[seg_id][ch].nb_groups = 0; continue; } - if ((ret = convert_input(s, s->metadata.ch_size[ch], key)) < 0) + ret = ff_dolby_e_convert_input(s, s->metadata.ch_size[ch], key); + if (ret < 0) return ret; if ((ret = parse_channel(s1, ch, seg_id)) < 0) { if (s1->avctx->err_recognition & AV_EF_EXPLODE) diff --git a/libavcodec/dolby_e.h b/libavcodec/dolby_e.h index 0838a1d3ea..32471bce80 100644 --- a/libavcodec/dolby_e.h +++ b/libavcodec/dolby_e.h @@ -84,6 +84,13 @@ typedef struct DBEContext { static const uint16_t sample_rate_tab[16] = { 0, 42965, 43008, 44800, 53706, 53760 }; + +/** + * Use the provided key to transform the input into data (put into s->buffer) + * suitable for further processing and initialize s->gb to read said data. + */ +int ff_dolby_e_convert_input(DBEContext *s, int nb_words, int key); + /** * Initialize DBEContext and parse Dolby E metadata. * Set word_bits/word_bytes, input, input_size, key_present diff --git a/libavcodec/dolby_e_parse.c b/libavcodec/dolby_e_parse.c index 33ec3d7f09..00b5536020 100644 --- a/libavcodec/dolby_e_parse.c +++ b/libavcodec/dolby_e_parse.c @@ -53,7 +53,7 @@ static int parse_key(DBEContext *s) return 0; } -static int convert_input(DBEContext *s, int nb_words, int key) +int ff_dolby_e_convert_input(DBEContext *s, int nb_words, int key) { const uint8_t *src = s->input; uint8_t *dst = s->buffer; @@ -63,6 +63,8 @@ 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"); return AVERROR_INVALIDDATA; } @@ -116,7 +118,7 @@ int ff_dolby_e_parse_header(DBEContext *s, const uint8_t *buf, int buf_size) if ((key = parse_key(s)) < 0) return key; - if ((ret = convert_input(s, 1, key)) < 0) + if ((ret = ff_dolby_e_convert_input(s, 1, key)) < 0) return ret; skip_bits(&s->gb, 4); @@ -127,7 +129,7 @@ int ff_dolby_e_parse_header(DBEContext *s, const uint8_t *buf, int buf_size) return AVERROR_INVALIDDATA; } - if ((ret = convert_input(s, mtd_size, key)) < 0) + if ((ret = ff_dolby_e_convert_input(s, mtd_size, key)) < 0) return ret; skip_bits(&s->gb, 14);