You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.3KB

  1. /*
  2. * RAW DTS demuxer
  3. * Copyright (c) 2008 Benjamin Larsson
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavcodec/bytestream.h"
  22. #include "libavcodec/dca_syncwords.h"
  23. #include "avformat.h"
  24. #include "rawdec.h"
  25. static int dts_probe(AVProbeData *p)
  26. {
  27. const uint8_t *buf, *bufp;
  28. uint32_t state = -1;
  29. int markers[3] = {0};
  30. int sum, max;
  31. buf = p->buf;
  32. for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
  33. bufp = buf;
  34. state = (state << 16) | bytestream_get_be16(&bufp);
  35. /* regular bitstream */
  36. if (state == DCA_SYNCWORD_CORE_BE || state == DCA_SYNCWORD_CORE_LE)
  37. markers[0]++;
  38. /* 14 bits big-endian bitstream */
  39. if (state == DCA_SYNCWORD_CORE_14B_BE)
  40. if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
  41. markers[1]++;
  42. /* 14 bits little-endian bitstream */
  43. if (state == DCA_SYNCWORD_CORE_14B_LE)
  44. if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
  45. markers[2]++;
  46. }
  47. sum = markers[0] + markers[1] + markers[2];
  48. max = markers[1] > markers[0];
  49. max = markers[2] > markers[max] ? 2 : max;
  50. if (markers[max] > 3 && p->buf_size / markers[max] < 32*1024 &&
  51. markers[max] * 4 > sum * 3)
  52. return AVPROBE_SCORE_EXTENSION + 1;
  53. return 0;
  54. }
  55. AVInputFormat ff_dts_demuxer = {
  56. .name = "dts",
  57. .long_name = NULL_IF_CONFIG_SMALL("raw DTS"),
  58. .read_probe = dts_probe,
  59. .read_header = ff_raw_audio_read_header,
  60. .read_packet = ff_raw_read_partial_packet,
  61. .flags = AVFMT_GENERIC_INDEX,
  62. .extensions = "dts",
  63. .raw_codec_id = AV_CODEC_ID_DTS,
  64. };