mlp_parse.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2007 Ian Caulfield
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_MLP_PARSE_H
  21. #define AVCODEC_MLP_PARSE_H
  22. #include "get_bits.h"
  23. typedef struct MLPHeaderInfo
  24. {
  25. int stream_type; ///< 0xBB for MLP, 0xBA for TrueHD
  26. int header_size; ///< Size of the major sync header, in bytes
  27. int group1_bits; ///< The bit depth of the first substream
  28. int group2_bits; ///< Bit depth of the second substream (MLP only)
  29. int group1_samplerate; ///< Sample rate of first substream
  30. int group2_samplerate; ///< Sample rate of second substream (MLP only)
  31. int channel_arrangement;
  32. int channel_modifier_thd_stream0; ///< Channel modifier for substream 0 of TrueHD streams ("2-channel presentation")
  33. int channel_modifier_thd_stream1; ///< Channel modifier for substream 1 of TrueHD streams ("6-channel presentation")
  34. int channel_modifier_thd_stream2; ///< Channel modifier for substream 2 of TrueHD streams ("8-channel presentation")
  35. int channels_mlp; ///< Channel count for MLP streams
  36. int channels_thd_stream1; ///< Channel count for substream 1 of TrueHD streams ("6-channel presentation")
  37. int channels_thd_stream2; ///< Channel count for substream 2 of TrueHD streams ("8-channel presentation")
  38. uint64_t channel_layout_mlp; ///< Channel layout for MLP streams
  39. uint64_t channel_layout_thd_stream1; ///< Channel layout for substream 1 of TrueHD streams ("6-channel presentation")
  40. uint64_t channel_layout_thd_stream2; ///< Channel layout for substream 2 of TrueHD streams ("8-channel presentation")
  41. int access_unit_size; ///< Number of samples per coded frame
  42. int access_unit_size_pow2; ///< Next power of two above number of samples per frame
  43. int is_vbr; ///< Stream is VBR instead of CBR
  44. int peak_bitrate; ///< Peak bitrate for VBR, actual bitrate (==peak) for CBR
  45. int num_substreams; ///< Number of substreams within stream
  46. } MLPHeaderInfo;
  47. static const uint8_t thd_chancount[13] = {
  48. // LR C LFE LRs LRvh LRc LRrs Cs Ts LRsd LRw Cvh LFE2
  49. 2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1
  50. };
  51. static const uint64_t thd_layout[13] = {
  52. AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT, // LR
  53. AV_CH_FRONT_CENTER, // C
  54. AV_CH_LOW_FREQUENCY, // LFE
  55. AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, // LRs
  56. AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT, // LRvh
  57. AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER, // LRc
  58. AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, // LRrs
  59. AV_CH_BACK_CENTER, // Cs
  60. AV_CH_TOP_CENTER, // Ts
  61. AV_CH_SURROUND_DIRECT_LEFT|AV_CH_SURROUND_DIRECT_RIGHT, // LRsd
  62. AV_CH_WIDE_LEFT|AV_CH_WIDE_RIGHT, // LRw
  63. AV_CH_TOP_FRONT_CENTER, // Cvh
  64. AV_CH_LOW_FREQUENCY_2, // LFE2
  65. };
  66. static inline int mlp_samplerate(int in)
  67. {
  68. if (in == 0xF)
  69. return 0;
  70. return (in & 8 ? 44100 : 48000) << (in & 7) ;
  71. }
  72. static inline int truehd_channels(int chanmap)
  73. {
  74. int channels = 0, i;
  75. for (i = 0; i < 13; i++)
  76. channels += thd_chancount[i] * ((chanmap >> i) & 1);
  77. return channels;
  78. }
  79. static inline uint64_t truehd_layout(int chanmap)
  80. {
  81. int i;
  82. uint64_t layout = 0;
  83. for (i = 0; i < 13; i++)
  84. layout |= thd_layout[i] * ((chanmap >> i) & 1);
  85. return layout;
  86. }
  87. int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb);
  88. #endif /* AVCODEC_MLP_PARSE_H */