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.

95 lines
2.9KB

  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(const 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. int nsubframes = 0;
  31. for (buf = p->buf; buf + 8 <= end; buf++) {
  32. if (AV_RB32(buf + 4) == sync) {
  33. frames++;
  34. if (last_buf + size == buf) {
  35. valid += 1 + nsubframes / 8;
  36. }
  37. nsubframes = 0;
  38. last_buf = buf;
  39. size = (AV_RB16(buf) & 0xfff) * 2;
  40. } else if (buf - last_buf == size) {
  41. nsubframes++;
  42. size += (AV_RB16(buf) & 0xfff) * 2;
  43. }
  44. }
  45. if (valid >= 100)
  46. return AVPROBE_SCORE_MAX;
  47. return 0;
  48. }
  49. #if CONFIG_MLP_DEMUXER
  50. static int mlp_probe(const AVProbeData *p)
  51. {
  52. return mlp_thd_probe(p, 0xf8726fbb);
  53. }
  54. FF_RAW_DEMUXER_CLASS(mlp)
  55. AVInputFormat ff_mlp_demuxer = {
  56. .name = "mlp",
  57. .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
  58. .read_probe = mlp_probe,
  59. .read_header = ff_raw_audio_read_header,
  60. .read_packet = ff_raw_read_partial_packet,
  61. .flags = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
  62. .extensions = "mlp",
  63. .raw_codec_id = AV_CODEC_ID_MLP,
  64. .priv_data_size = sizeof(FFRawDemuxerContext),
  65. .priv_class = &mlp_demuxer_class,
  66. };
  67. #endif
  68. #if CONFIG_TRUEHD_DEMUXER
  69. static int thd_probe(const AVProbeData *p)
  70. {
  71. return mlp_thd_probe(p, 0xf8726fba);
  72. }
  73. FF_RAW_DEMUXER_CLASS(truehd)
  74. AVInputFormat ff_truehd_demuxer = {
  75. .name = "truehd",
  76. .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
  77. .read_probe = thd_probe,
  78. .read_header = ff_raw_audio_read_header,
  79. .read_packet = ff_raw_read_partial_packet,
  80. .flags = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
  81. .extensions = "thd",
  82. .raw_codec_id = AV_CODEC_ID_TRUEHD,
  83. .priv_data_size = sizeof(FFRawDemuxerContext),
  84. .priv_class = &truehd_demuxer_class,
  85. };
  86. #endif