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.

86 lines
2.6KB

  1. /*
  2. * MLP and TrueHD demuxer
  3. * Copyright (c) 2001 Fabrice Bellard
  4. * Copyright (c) 2005 Alex Beregszaszi
  5. * Copyright (c) 2015 Carl Eugen Hoyos
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include "avformat.h"
  24. #include "rawdec.h"
  25. #include "libavutil/intreadwrite.h"
  26. static int av_always_inline mlp_thd_probe(AVProbeData *p, uint32_t sync)
  27. {
  28. const uint8_t *buf, *last_buf = p->buf, *end = p->buf + p->buf_size;
  29. int frames = 0, valid = 0, size = 0;
  30. for (buf = p->buf; buf + 8 <= end; buf++) {
  31. if (AV_RB32(buf + 4) == sync) {
  32. frames++;
  33. if (last_buf + size == buf) {
  34. valid++;
  35. }
  36. last_buf = buf;
  37. size = (AV_RB16(buf) & 0xfff) * 2;
  38. } else if (buf - last_buf == size) {
  39. size += (AV_RB16(buf) & 0xfff) * 2;
  40. }
  41. }
  42. if (valid >= 100)
  43. return AVPROBE_SCORE_MAX;
  44. return 0;
  45. }
  46. #if CONFIG_MLP_DEMUXER
  47. static int mlp_probe(AVProbeData *p)
  48. {
  49. return mlp_thd_probe(p, 0xf8726fbb);
  50. }
  51. AVInputFormat ff_mlp_demuxer = {
  52. .name = "mlp",
  53. .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
  54. .read_probe = mlp_probe,
  55. .read_header = ff_raw_audio_read_header,
  56. .read_packet = ff_raw_read_partial_packet,
  57. .flags = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
  58. .extensions = "mlp",
  59. .raw_codec_id = AV_CODEC_ID_MLP,
  60. };
  61. #endif
  62. #if CONFIG_TRUEHD_DEMUXER
  63. static int thd_probe(AVProbeData *p)
  64. {
  65. return mlp_thd_probe(p, 0xf8726fba);
  66. }
  67. AVInputFormat ff_truehd_demuxer = {
  68. .name = "truehd",
  69. .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
  70. .read_probe = thd_probe,
  71. .read_header = ff_raw_audio_read_header,
  72. .read_packet = ff_raw_read_partial_packet,
  73. .flags = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
  74. .extensions = "thd",
  75. .raw_codec_id = AV_CODEC_ID_TRUEHD,
  76. };
  77. #endif