iso_639_language_descriptor.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * section and descriptor parser
  3. *
  4. * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
  5. * Copyright (C) 2005 Andrew de Quincey (adq_dvb@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_MPEG_ISO_639_LANGUAGE_DESCRIPTOR
  22. #define _UCSI_MPEG_ISO_639_LANGUAGE_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. #include <libucsi/types.h>
  30. /**
  31. * Possible values for audio_type.
  32. */
  33. enum {
  34. MPEG_AUDIO_TYPE_CLEAN_EFFECTS = 0x01,
  35. MPEG_AUDIO_TYPE_HEARING_IMPAIRED = 0x02,
  36. MPEG_AUDIO_TYPE_VISUAL_IMPAIRED_COMMENTARY = 0x03,
  37. };
  38. /**
  39. * mpeg_iso_639_language_descriptor structure.
  40. */
  41. struct mpeg_iso_639_language_descriptor {
  42. struct descriptor d;
  43. /* struct mpeg_iso_639_language_code languages[] */
  44. } __ucsi_packed;
  45. /**
  46. * An entry in the mpeg_iso_639_language_descriptor languages field.
  47. */
  48. struct mpeg_iso_639_language_code {
  49. iso639lang_t language_code;
  50. uint8_t audio_type;
  51. } __ucsi_packed;
  52. /**
  53. * Process an mpeg_iso_639_language_descriptor.
  54. *
  55. * @param d Generic descriptor structure.
  56. * @return Pointer to an mpeg_iso_639_language_descriptor structure, or NULL
  57. * on error.
  58. */
  59. static inline struct mpeg_iso_639_language_descriptor*
  60. mpeg_iso_639_language_descriptor_codec(struct descriptor* d)
  61. {
  62. if (d->len % sizeof(struct mpeg_iso_639_language_code))
  63. return NULL;
  64. return (struct mpeg_iso_639_language_descriptor*) d;
  65. }
  66. /**
  67. * Convenience iterator for the languages field of an mpeg_iso_639_language_descriptor
  68. *
  69. * @param d Pointer to the mpeg_iso_639_language_descriptor structure.
  70. * @param pos Variable holding a pointer to the current entry.
  71. */
  72. #define mpeg_iso_639_language_descriptor_languages_for_each(_d, _pos) \
  73. for ((_pos) = mpeg_iso_639_language_descriptor_languages_first(_d); \
  74. (_pos); \
  75. (_pos) = mpeg_iso_639_language_descriptor_languages_next(_d, _pos))
  76. /******************************** PRIVATE CODE ********************************/
  77. static inline struct mpeg_iso_639_language_code*
  78. mpeg_iso_639_language_descriptor_languages_first(struct mpeg_iso_639_language_descriptor *d)
  79. {
  80. if (d->d.len < sizeof(struct mpeg_iso_639_language_code))
  81. return NULL;
  82. return (struct mpeg_iso_639_language_code *)
  83. ((uint8_t*) d + sizeof(struct mpeg_iso_639_language_descriptor));
  84. }
  85. static inline struct mpeg_iso_639_language_code*
  86. mpeg_iso_639_language_descriptor_languages_next(struct mpeg_iso_639_language_descriptor *d,
  87. struct mpeg_iso_639_language_code *pos)
  88. {
  89. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  90. uint8_t *next = (uint8_t *) pos + sizeof(struct mpeg_iso_639_language_code);
  91. if (next >= end)
  92. return NULL;
  93. return (struct mpeg_iso_639_language_code *) next;
  94. }
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif