History

avcodec/dca_parser: set duration for core-less streams

foo86 committed 10 years ago

Commit cb55c5b1 parent 72a9a7e1 file · +65 −3Browse files

Showing the changes to libavcodec/dca_parser.c (1 of 1 file). Show all

Unified · Split

libavcodec/dca_parser.c+65−3
@@ -23,6 +23,8 @@ · 22 unmodified lines
2323 */
2424
2525 #include "dca.h"
26+#include "dcadata.h"
27+#include "dca_exss.h"
2628 #include "dca_syncwords.h"
2729 #include "get_bits.h"
2830 #include "parser.h"
@@ -32,6 +34,8 @@ typedef struct DCAParseContext { · 3 unmodified lines
3234 uint32_t lastmarker;
3335 int size;
3436 int framesize;
37+ DCAExssParser exss;
38+ unsigned int sr_code;
3539 } DCAParseContext;
3640
3741 #define IS_CORE_MARKER(state) \
@@ -177,11 +181,12 @@ static av_cold int dca_parse_init(AVCodecParserContext *s) · 139 unmodified lines
177181 DCAParseContext *pc1 = s->priv_data;
178182
179183 pc1->lastmarker = 0;
184+ pc1->sr_code = -1;
180185 return 0;
181186 }
182187
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)
185190 {
186191 GetBitContext gb;
187192 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
190195 if (buf_size < 12)
191196 return AVERROR_INVALIDDATA;
192197
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+
193255 if ((ret = avpriv_dca_convert_bitstream(buf, 12, hdr, 12)) < 0)
194256 return ret;
195257
@@ -230,7 +292,7 @@ static int dca_parse(AVCodecParserContext *s, AVCodecContext *avctx, · 34 unmodified lines
230292 }
231293
232294 /* 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)) {
234296 if (!avctx->sample_rate)
235297 avctx->sample_rate = sample_rate;
236298 s->duration = av_rescale(duration, avctx->sample_rate, sample_rate);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t