caption_service_descriptor.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_ATSC_CAPTION_SERVICE_DESCRIPTOR
  22. #define _UCSI_ATSC_CAPTION_SERVICE_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. * atsc_caption_service_descriptor structure.
  32. */
  33. struct atsc_caption_service_descriptor {
  34. struct descriptor d;
  35. EBIT2(uint8_t reserved : 3; ,
  36. uint8_t number_of_services : 5; );
  37. /* struct atsc_caption_service_entry entries[] */
  38. } __ucsi_packed;
  39. /**
  40. * An entry in the entries field of a atsc_caption_service_descriptor.
  41. */
  42. struct atsc_caption_service_entry {
  43. iso639lang_t language_code;
  44. EBIT3(uint8_t digital_cc : 1; ,
  45. uint8_t reserved : 1; ,
  46. uint8_t value : 6; );
  47. EBIT3(uint16_t easy_reader : 1; ,
  48. uint16_t wide_aspect_ratio : 1; ,
  49. uint16_t reserved1 :14; );
  50. } __ucsi_packed;
  51. /**
  52. * Process an atsc_caption_service_descriptor.
  53. *
  54. * @param d Generic descriptor pointer.
  55. * @return atsc_caption_service_descriptor pointer, or NULL on error.
  56. */
  57. static inline struct atsc_caption_service_descriptor*
  58. atsc_caption_service_descriptor_codec(struct descriptor* d)
  59. {
  60. struct atsc_caption_service_descriptor *ret =
  61. (struct atsc_caption_service_descriptor *) d;
  62. uint8_t *buf = (uint8_t*) d + 2;
  63. int pos = 0;
  64. int idx;
  65. if (d->len < 1)
  66. return NULL;
  67. pos++;
  68. for(idx = 0; idx < ret->number_of_services; idx++) {
  69. if (d->len < (pos + sizeof(struct atsc_caption_service_entry)))
  70. return NULL;
  71. bswap16(buf+pos+4);
  72. pos += sizeof(struct atsc_caption_service_entry);
  73. }
  74. return (struct atsc_caption_service_descriptor*) d;
  75. }
  76. /**
  77. * Iterator for entries field of a atsc_caption_service_descriptor.
  78. *
  79. * @param d atsc_caption_service_descriptor pointer.
  80. * @param pos Variable holding a pointer to the current atsc_caption_service_entry.
  81. * @param idx Field iterator integer.
  82. */
  83. #define atsc_caption_service_descriptor_entries_for_each(d, pos, idx) \
  84. for ((pos) = atsc_caption_service_descriptor_entries_first(d), idx=0; \
  85. (pos); \
  86. (pos) = atsc_caption_service_descriptor_entries_next(d, pos, ++idx))
  87. /******************************** PRIVATE CODE ********************************/
  88. static inline struct atsc_caption_service_entry*
  89. atsc_caption_service_descriptor_entries_first(struct atsc_caption_service_descriptor *d)
  90. {
  91. if (d->number_of_services == 0)
  92. return NULL;
  93. return (struct atsc_caption_service_entry *)
  94. ((uint8_t*) d + sizeof(struct atsc_caption_service_descriptor));
  95. }
  96. static inline struct atsc_caption_service_entry*
  97. atsc_caption_service_descriptor_entries_next(struct atsc_caption_service_descriptor *d,
  98. struct atsc_caption_service_entry *pos,
  99. int idx)
  100. {
  101. if (idx >= d->number_of_services)
  102. return NULL;
  103. return (struct atsc_caption_service_entry *)
  104. ((uint8_t *) pos + sizeof(struct atsc_caption_service_entry));
  105. }
  106. #ifdef __cplusplus
  107. }
  108. #endif
  109. #endif