Padding before the first sync word can be very large for DTS-in-WAV streams. There is no reason to include this padding in parsed packet.
Unified · Split
| @@ -33,6 +33,7 @@ typedef struct DCAParseContext { · 32 unmodified lines | ||
| 33 | 33 | uint32_t lastmarker; |
| 34 | 34 | int size; |
| 35 | 35 | int framesize; |
| 36 | + unsigned int startpos; | |
| 36 | 37 | DCAExssParser exss; |
| 37 | 38 | unsigned int sr_code; |
| 38 | 39 | } DCAParseContext; |
| @@ -75,20 +76,27 @@ static int dca_find_frame_end(DCAParseContext *pc1, const uint8_t *buf, · 36 unmodified lines | ||
| 75 | 76 | |
| 76 | 77 | i = 0; |
| 77 | 78 | if (!start_found) { |
| 78 | − for (i = 0; i < buf_size; i++) { | |
| 79 | + for (; i < buf_size; i++) { | |
| 80 | + size++; | |
| 79 | 81 | state = (state << 8) | buf[i]; |
| 80 | − if (IS_MARKER(state)) { | |
| 81 | − if (!pc1->lastmarker || | |
| 82 | − pc1->lastmarker == CORE_MARKER(state) || | |
| 83 | − pc1->lastmarker == DCA_SYNCWORD_SUBSTREAM) { | |
| 84 | − start_found = 1; | |
| 85 | − if (IS_EXSS_MARKER(state)) | |
| 86 | − pc1->lastmarker = EXSS_MARKER(state); | |
| 87 | − else | |
| 88 | − pc1->lastmarker = CORE_MARKER(state); | |
| 89 | − i++; | |
| 90 | − break; | |
| 91 | − } | |
| 82 | + | |
| 83 | + if (IS_MARKER(state) && | |
| 84 | + (!pc1->lastmarker || | |
| 85 | + pc1->lastmarker == CORE_MARKER(state) || | |
| 86 | + pc1->lastmarker == DCA_SYNCWORD_SUBSTREAM)) { | |
| 87 | + if (!pc1->lastmarker) | |
| 88 | + pc1->startpos = IS_EXSS_MARKER(state) ? size - 4 : size - 6; | |
| 89 | + | |
| 90 | + if (IS_EXSS_MARKER(state)) | |
| 91 | + pc1->lastmarker = EXSS_MARKER(state); | |
| 92 | + else | |
| 93 | + pc1->lastmarker = CORE_MARKER(state); | |
| 94 | + | |
| 95 | + start_found = 1; | |
| 96 | + size = 0; | |
| 97 | + | |
| 98 | + i++; | |
| 99 | + break; | |
| 92 | 100 | } |
| 93 | 101 | } |
| 94 | 102 | } |
| @@ -284,6 +292,13 @@ static int dca_parse(AVCodecParserContext *s, AVCodecContext *avctx, · 189 unmodified lines | ||
| 284 | 292 | *poutbuf_size = 0; |
| 285 | 293 | return buf_size; |
| 286 | 294 | } |
| 295 | + | |
| 296 | + /* skip initial padding */ | |
| 297 | + if (buf_size > pc1->startpos) { | |
| 298 | + buf += pc1->startpos; | |
| 299 | + buf_size -= pc1->startpos; | |
| 300 | + } | |
| 301 | + pc1->startpos = 0; | |
| 287 | 302 | } |
| 288 | 303 | |
| 289 | 304 | /* read the duration and sample rate from the frame header */ |