Unified · Split
| @@ -23,6 +23,8 @@ · 22 unmodified lines | ||
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | 25 | #include "dca.h" |
| 26 | +#include "dcadata.h" | |
| 27 | +#include "dca_exss.h" | |
| 26 | 28 | #include "dca_syncwords.h" |
| 27 | 29 | #include "get_bits.h" |
| 28 | 30 | #include "parser.h" |
| @@ -32,6 +34,8 @@ typedef struct DCAParseContext { · 3 unmodified lines | ||
| 32 | 34 | uint32_t lastmarker; |
| 33 | 35 | int size; |
| 34 | 36 | int framesize; |
| 37 | + DCAExssParser exss; | |
| 38 | + unsigned int sr_code; | |
| 35 | 39 | } DCAParseContext; |
| 36 | 40 | |
| 37 | 41 | #define IS_CORE_MARKER(state) \ |
| @@ -177,11 +181,12 @@ static av_cold int dca_parse_init(AVCodecParserContext *s) · 139 unmodified lines | ||
| 177 | 181 | DCAParseContext *pc1 = s->priv_data; |
| 178 | 182 | |
| 179 | 183 | pc1->lastmarker = 0; |
| 184 | + pc1->sr_code = -1; | |
| 180 | 185 | return 0; |
| 181 | 186 | } |
| 182 | 187 | |
| 183 | −static int dca_parse_params(const uint8_t *buf, int buf_size, int *duration, | |
| 184 | − int *sample_rate) | |
| 188 | +static int dca_parse_params(DCAParseContext *pc1, const uint8_t *buf, | |
| 189 | + int buf_size, int *duration, int *sample_rate) | |
| 185 | 190 | { |
| 186 | 191 | GetBitContext gb; |
| 187 | 192 | uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 }; |
| @@ -190,6 +195,63 @@ static int dca_parse_params(const uint8_t *buf, int buf_size, int *duration, · 2 unmodified lines | ||
| 190 | 195 | if (buf_size < 12) |
| 191 | 196 | return AVERROR_INVALIDDATA; |
| 192 | 197 | |
| 198 | + if (AV_RB32(buf) == DCA_SYNCWORD_SUBSTREAM) { | |
| 199 | + DCAExssAsset *asset = &pc1->exss.assets[0]; | |
| 200 | + | |
| 201 | + if ((ret = ff_dca_exss_parse(&pc1->exss, buf, buf_size)) < 0) | |
| 202 | + return ret; | |
| 203 | + | |
| 204 | + if (asset->extension_mask & DCA_EXSS_LBR) { | |
| 205 | + if ((ret = init_get_bits8(&gb, buf + asset->lbr_offset, asset->lbr_size)) < 0) | |
| 206 | + return ret; | |
| 207 | + | |
| 208 | + if (get_bits_long(&gb, 32) != DCA_SYNCWORD_LBR) | |
| 209 | + return AVERROR_INVALIDDATA; | |
| 210 | + | |
| 211 | + switch (get_bits(&gb, 8)) { | |
| 212 | + case 2: | |
| 213 | + pc1->sr_code = get_bits(&gb, 8); | |
| 214 | + case 1: | |
| 215 | + break; | |
| 216 | + default: | |
| 217 | + return AVERROR_INVALIDDATA; | |
| 218 | + } | |
| 219 | + | |
| 220 | + if (pc1->sr_code >= FF_ARRAY_ELEMS(ff_dca_sampling_freqs)) | |
| 221 | + return AVERROR_INVALIDDATA; | |
| 222 | + | |
| 223 | + *sample_rate = ff_dca_sampling_freqs[pc1->sr_code]; | |
| 224 | + *duration = 1024 << ff_dca_freq_ranges[pc1->sr_code]; | |
| 225 | + return 0; | |
| 226 | + } | |
| 227 | + | |
| 228 | + if (asset->extension_mask & DCA_EXSS_XLL) { | |
| 229 | + int nsamples_log2; | |
| 230 | + | |
| 231 | + if ((ret = init_get_bits8(&gb, buf + asset->xll_offset, asset->xll_size)) < 0) | |
| 232 | + return ret; | |
| 233 | + | |
| 234 | + if (get_bits_long(&gb, 32) != DCA_SYNCWORD_XLL) | |
| 235 | + return AVERROR_INVALIDDATA; | |
| 236 | + | |
| 237 | + if (get_bits(&gb, 4)) | |
| 238 | + return AVERROR_INVALIDDATA; | |
| 239 | + | |
| 240 | + skip_bits(&gb, 8); | |
| 241 | + skip_bits_long(&gb, get_bits(&gb, 5) + 1); | |
| 242 | + skip_bits(&gb, 4); | |
| 243 | + nsamples_log2 = get_bits(&gb, 4) + get_bits(&gb, 4); | |
| 244 | + if (nsamples_log2 > 24) | |
| 245 | + return AVERROR_INVALIDDATA; | |
| 246 | + | |
| 247 | + *sample_rate = asset->max_sample_rate; | |
| 248 | + *duration = (1 + (*sample_rate > 96000)) << nsamples_log2; | |
| 249 | + return 0; | |
| 250 | + } | |
| 251 | + | |
| 252 | + return AVERROR_INVALIDDATA; | |
| 253 | + } | |
| 254 | + | |
| 193 | 255 | if ((ret = avpriv_dca_convert_bitstream(buf, 12, hdr, 12)) < 0) |
| 194 | 256 | return ret; |
| 195 | 257 | |
| @@ -230,7 +292,7 @@ static int dca_parse(AVCodecParserContext *s, AVCodecContext *avctx, · 34 unmodified lines | ||
| 230 | 292 | } |
| 231 | 293 | |
| 232 | 294 | /* read the duration and sample rate from the frame header */ |
| 233 | − if (!dca_parse_params(buf, buf_size, &duration, &sample_rate)) { | |
| 295 | + if (!dca_parse_params(pc1, buf, buf_size, &duration, &sample_rate)) { | |
| 234 | 296 | if (!avctx->sample_rate) |
| 235 | 297 | avctx->sample_rate = sample_rate; |
| 236 | 298 | s->duration = av_rescale(duration, avctx->sample_rate, sample_rate); |