Commit 72a9a7e9 authored by foo86's avatar foo86 Committed by James Almer

avcodec/dca_exss: prepare to be called from parser context

Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent 24fcb233
...@@ -128,6 +128,7 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset) ...@@ -128,6 +128,7 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset)
// Number of speaker remapping sets // Number of speaker remapping sets
if ((spkr_remap_nsets = get_bits(&s->gb, 3)) && !spkr_mask_nbits) { if ((spkr_remap_nsets = get_bits(&s->gb, 3)) && !spkr_mask_nbits) {
if (s->avctx)
av_log(s->avctx, AV_LOG_ERROR, "Speaker mask disabled yet there are remapping sets\n"); av_log(s->avctx, AV_LOG_ERROR, "Speaker mask disabled yet there are remapping sets\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -213,6 +214,7 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset) ...@@ -213,6 +214,7 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset)
for (i = 0; i < s->nmixoutconfigs; i++) { for (i = 0; i < s->nmixoutconfigs; i++) {
if (!s->nmixoutchs[i]) { if (!s->nmixoutchs[i]) {
if (s->avctx)
av_log(s->avctx, AV_LOG_ERROR, "Invalid speaker layout mask for mixing configuration\n"); av_log(s->avctx, AV_LOG_ERROR, "Invalid speaker layout mask for mixing configuration\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -310,6 +312,7 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset) ...@@ -310,6 +312,7 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset)
// Reserved // Reserved
// Zero pad // Zero pad
if (ff_dca_seek_bits(&s->gb, descr_pos + descr_size * 8)) { if (ff_dca_seek_bits(&s->gb, descr_pos + descr_size * 8)) {
if (s->avctx)
av_log(s->avctx, AV_LOG_ERROR, "Read past end of EXSS asset descriptor\n"); av_log(s->avctx, AV_LOG_ERROR, "Read past end of EXSS asset descriptor\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -373,7 +376,7 @@ static int set_exss_offsets(DCAExssAsset *asset) ...@@ -373,7 +376,7 @@ static int set_exss_offsets(DCAExssAsset *asset)
return 0; return 0;
} }
int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size) int ff_dca_exss_parse(DCAExssParser *s, const uint8_t *data, int size)
{ {
int i, ret, offset, wide_hdr, header_size; int i, ret, offset, wide_hdr, header_size;
...@@ -396,7 +399,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size) ...@@ -396,7 +399,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
header_size = get_bits(&s->gb, 8 + 4 * wide_hdr) + 1; header_size = get_bits(&s->gb, 8 + 4 * wide_hdr) + 1;
// Check CRC // Check CRC
if (ff_dca_check_crc(s->avctx, &s->gb, 32 + 8, header_size * 8)) { if (s->avctx && ff_dca_check_crc(s->avctx, &s->gb, 32 + 8, header_size * 8)) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid EXSS header checksum\n"); av_log(s->avctx, AV_LOG_ERROR, "Invalid EXSS header checksum\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -406,6 +409,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size) ...@@ -406,6 +409,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
// Number of bytes of extension substream // Number of bytes of extension substream
s->exss_size = get_bits(&s->gb, s->exss_size_nbits) + 1; s->exss_size = get_bits(&s->gb, s->exss_size_nbits) + 1;
if (s->exss_size > size) { if (s->exss_size > size) {
if (s->avctx)
av_log(s->avctx, AV_LOG_ERROR, "Packet too short for EXSS frame\n"); av_log(s->avctx, AV_LOG_ERROR, "Packet too short for EXSS frame\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -428,6 +432,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size) ...@@ -428,6 +432,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
// Number of defined audio presentations // Number of defined audio presentations
s->npresents = get_bits(&s->gb, 3) + 1; s->npresents = get_bits(&s->gb, 3) + 1;
if (s->npresents > 1) { if (s->npresents > 1) {
if (s->avctx)
avpriv_request_sample(s->avctx, "%d audio presentations", s->npresents); avpriv_request_sample(s->avctx, "%d audio presentations", s->npresents);
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
} }
...@@ -435,6 +440,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size) ...@@ -435,6 +440,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
// Number of audio assets in extension substream // Number of audio assets in extension substream
s->nassets = get_bits(&s->gb, 3) + 1; s->nassets = get_bits(&s->gb, 3) + 1;
if (s->nassets > 1) { if (s->nassets > 1) {
if (s->avctx)
avpriv_request_sample(s->avctx, "%d audio assets", s->nassets); avpriv_request_sample(s->avctx, "%d audio assets", s->nassets);
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
} }
...@@ -476,6 +482,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size) ...@@ -476,6 +482,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
s->assets[i].asset_size = get_bits(&s->gb, s->exss_size_nbits) + 1; s->assets[i].asset_size = get_bits(&s->gb, s->exss_size_nbits) + 1;
offset += s->assets[i].asset_size; offset += s->assets[i].asset_size;
if (offset > s->exss_size) { if (offset > s->exss_size) {
if (s->avctx)
av_log(s->avctx, AV_LOG_ERROR, "EXSS asset out of bounds\n"); av_log(s->avctx, AV_LOG_ERROR, "EXSS asset out of bounds\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -486,6 +493,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size) ...@@ -486,6 +493,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
if ((ret = parse_descriptor(s, &s->assets[i])) < 0) if ((ret = parse_descriptor(s, &s->assets[i])) < 0)
return ret; return ret;
if ((ret = set_exss_offsets(&s->assets[i])) < 0) { if ((ret = set_exss_offsets(&s->assets[i])) < 0) {
if (s->avctx)
av_log(s->avctx, AV_LOG_ERROR, "Invalid extension size in EXSS asset descriptor\n"); av_log(s->avctx, AV_LOG_ERROR, "Invalid extension size in EXSS asset descriptor\n");
return ret; return ret;
} }
...@@ -498,6 +506,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size) ...@@ -498,6 +506,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
// Byte align // Byte align
// CRC16 of extension substream header // CRC16 of extension substream header
if (ff_dca_seek_bits(&s->gb, header_size * 8)) { if (ff_dca_seek_bits(&s->gb, header_size * 8)) {
if (s->avctx)
av_log(s->avctx, AV_LOG_ERROR, "Read past end of EXSS header\n"); av_log(s->avctx, AV_LOG_ERROR, "Read past end of EXSS header\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
......
...@@ -87,6 +87,6 @@ typedef struct DCAExssParser { ...@@ -87,6 +87,6 @@ typedef struct DCAExssParser {
DCAExssAsset assets[1]; ///< Audio asset descriptors DCAExssAsset assets[1]; ///< Audio asset descriptors
} DCAExssParser; } DCAExssParser;
int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size); int ff_dca_exss_parse(DCAExssParser *s, const uint8_t *data, int size);
#endif #endif
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