comparison raw.c @ 5182:34ec401808a8 libavformat

Make DTS probe more robust against false positives (as e.g. probetest shows). In particular check that the detected markers clearly indicate a specific DTS format (a wild mixture of e.g. little- and big-endian markers is unlikely to be a valid DTS file) and ensure the markers appear with sufficient frequency.
author reimar
date Mon, 14 Sep 2009 20:28:10 +0000
parents cd0985411145
children 3f35ada98286
comparison
equal deleted inserted replaced
5181:c900e8690782 5182:34ec401808a8
508 #define DCA_MARKER_RAW_LE 0xFE7F0180 508 #define DCA_MARKER_RAW_LE 0xFE7F0180
509 static int dts_probe(AVProbeData *p) 509 static int dts_probe(AVProbeData *p)
510 { 510 {
511 const uint8_t *buf, *bufp; 511 const uint8_t *buf, *bufp;
512 uint32_t state = -1; 512 uint32_t state = -1;
513 int markers[3] = {0};
514 int sum, max;
513 515
514 buf = p->buf; 516 buf = p->buf;
515 517
516 for(; buf < (p->buf+p->buf_size)-2; buf+=2) { 518 for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
517 bufp = buf; 519 bufp = buf;
518 state = (state << 16) | bytestream_get_be16(&bufp); 520 state = (state << 16) | bytestream_get_be16(&bufp);
519 521
520 /* regular bitstream */ 522 /* regular bitstream */
521 if (state == DCA_MARKER_RAW_BE || state == DCA_MARKER_RAW_LE) 523 if (state == DCA_MARKER_RAW_BE || state == DCA_MARKER_RAW_LE)
522 return AVPROBE_SCORE_MAX/2+1; 524 markers[0]++;
523 525
524 /* 14 bits big-endian bitstream */ 526 /* 14 bits big-endian bitstream */
525 if (state == DCA_MARKER_14B_BE) 527 if (state == DCA_MARKER_14B_BE)
526 if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0) 528 if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
527 return AVPROBE_SCORE_MAX/2+1; 529 markers[1]++;
528 530
529 /* 14 bits little-endian bitstream */ 531 /* 14 bits little-endian bitstream */
530 if (state == DCA_MARKER_14B_LE) 532 if (state == DCA_MARKER_14B_LE)
531 if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007) 533 if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
532 return AVPROBE_SCORE_MAX/2+1; 534 markers[2]++;
533 } 535 }
536 sum = markers[0] + markers[1] + markers[2];
537 max = markers[1] > markers[0];
538 max = markers[2] > markers[max] ? 2 : max;
539 if (markers[max] > 3 && p->buf_size / markers[max] < 32*1024 &&
540 markers[max] * 4 > sum * 3)
541 return AVPROBE_SCORE_MAX/2+1;
534 542
535 return 0; 543 return 0;
536 } 544 }
537 #endif 545 #endif
538 546