ac3_descriptor.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * section and descriptor parser
  3. *
  4. * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
  5. * Copyright (C) 2005 Andrew de Quincey (adq_atsc@lidskialf.net)
  6. *
  7. * This library 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. * This library 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 this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  20. */
  21. #ifndef _UCSI_ATSC_AC3_DESCRIPTOR
  22. #define _UCSI_ATSC_AC3_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. enum atsc_ac3_channels {
  30. ATSC_AC3_CHANNELS_1_PLUS_1 = 0x0,
  31. ATSC_AC3_CHANNELS_1_0 = 0x1,
  32. ATSC_AC3_CHANNELS_2_0 = 0x2,
  33. ATSC_AC3_CHANNELS_3_0 = 0x3,
  34. ATSC_AC3_CHANNELS_2_1 = 0x4,
  35. ATSC_AC3_CHANNELS_3_1 = 0x5,
  36. ATSC_AC3_CHANNELS_2_2 = 0x6,
  37. ATSC_AC3_CHANNELS_3_2 = 0x7,
  38. ATSC_AC3_CHANNELS_1 = 0x8,
  39. ATSC_AC3_CHANNELS_LTEQ_2 = 0x9,
  40. ATSC_AC3_CHANNELS_LTEQ_3 = 0xa,
  41. ATSC_AC3_CHANNELS_LTEQ_4 = 0xb,
  42. ATSC_AC3_CHANNELS_LTEQ_5 = 0xc,
  43. ATSC_AC3_CHANNELS_LTEQ_6 = 0xd,
  44. };
  45. /**
  46. * atsc_ac3_descriptor structure.
  47. */
  48. struct atsc_ac3_descriptor {
  49. struct descriptor d;
  50. EBIT2(uint8_t sample_rate_code : 3; ,
  51. uint8_t bsid : 5; );
  52. EBIT2(uint8_t bit_rate_code : 6; ,
  53. uint8_t surround_mode : 2; );
  54. EBIT3(uint8_t bsmod : 3; ,
  55. uint8_t num_channels : 4; ,
  56. uint8_t full_svc : 1; );
  57. /* uint8_t additional_info[] */
  58. } __ucsi_packed;
  59. /**
  60. * Process an atsc_ac3_descriptor.
  61. *
  62. * @param d Generic descriptor structure.
  63. * @return atsc_ac3_descriptor pointer, or NULL on error.
  64. */
  65. static inline struct atsc_ac3_descriptor*
  66. atsc_ac3_descriptor_codec(struct descriptor* d)
  67. {
  68. int pos = 0;
  69. if (d->len < (pos+4))
  70. return NULL;
  71. pos += 4;
  72. return (struct atsc_ac3_descriptor*) d;
  73. }
  74. /**
  75. * Retrieve pointer to additional_info field of a atsc_ac3_descriptor.
  76. *
  77. * @param d atsc_ac3_descriptor pointer.
  78. * @return Pointer to additional_info field.
  79. */
  80. static inline uint8_t *atsc_ac3_descriptor_additional_info(struct atsc_ac3_descriptor *d)
  81. {
  82. int pos = sizeof(struct atsc_ac3_descriptor);
  83. return ((uint8_t *) d) + pos;
  84. }
  85. /**
  86. * Determine length of additional_info field of a atsc_ac3_descriptor.
  87. *
  88. * @param d atsc_ac3_descriptor pointer.
  89. * @return Length of field in bytes.
  90. */
  91. static inline int atsc_ac3_descriptor_additional_info_length(struct atsc_ac3_descriptor* d)
  92. {
  93. return d->d.len - 3;
  94. }
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif