announcement_support_descriptor.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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_DVB_ANNOUNCEMENT_SUPPORT_DESCRIPTOR
  22. #define _UCSI_DVB_ANNOUNCEMENT_SUPPORT_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. /**
  30. * Possible values for announcement_support_indicator.
  31. */
  32. enum {
  33. DVB_ANNOUNCEMENT_SUPPORT_EMERGENCY = 0x01,
  34. DVB_ANNOUNCEMENT_SUPPORT_ROAD_TRAFFIC_FLASH = 0x02,
  35. DVB_ANNOUNCEMENT_SUPPORT_PUBLIC_TRANSPORT_FLASH = 0x04,
  36. DVB_ANNOUNCEMENT_SUPPORT_WARNING_MESSAGE = 0x08,
  37. DVB_ANNOUNCEMENT_SUPPORT_NEWS_FLASH = 0x10,
  38. DVB_ANNOUNCEMENT_SUPPORT_WEATHER_FLASH = 0x20,
  39. DVB_ANNOUNCEMENT_SUPPORT_EVENT_ANNOUNCEMENT = 0x40,
  40. DVB_ANNOUNCEMENT_SUPPORT_PERSONAL_CALL = 0x80,
  41. };
  42. /**
  43. * Possible values for announcement_type.
  44. */
  45. enum {
  46. DVB_ANNOUNCEMENT_TYPE_EMERGENCY = 0x00,
  47. DVB_ANNOUNCEMENT_TYPE_ROAD_TRAFFIC_FLASH = 0x01,
  48. DVB_ANNOUNCEMENT_TYPE_PUBLIC_TRANSPORT_FLASH = 0x02,
  49. DVB_ANNOUNCEMENT_TYPE_WARNING_MESSAGE = 0x03,
  50. DVB_ANNOUNCEMENT_TYPE_NEWS_FLASH = 0x04,
  51. DVB_ANNOUNCEMENT_TYPE_WEATHER_FLASH = 0x05,
  52. DVB_ANNOUNCEMENT_TYPE_EVENT_ANNOUNCEMENT = 0x06,
  53. DVB_ANNOUNCEMENT_TYPE_PERSONAL_CALL = 0x07,
  54. };
  55. /**
  56. * Possible values for reference_type.
  57. */
  58. enum {
  59. DVB_REFERENCE_TYPE_AUDIO = 0x00,
  60. DVB_REFERENCE_TYPE_OTHER_AUDIO = 0x01,
  61. DVB_REFERENCE_TYPE_OTHER_SERVICE = 0x02,
  62. DVB_REFERENCE_TYPE_OTHER_TS = 0x03,
  63. };
  64. /**
  65. * dvb_announcement_support_descriptor structure.
  66. */
  67. struct dvb_announcement_support_descriptor {
  68. struct descriptor d;
  69. uint16_t announcement_support_indicator;
  70. /* struct dvb_announcement_support_entry entries[] */
  71. } __ucsi_packed;
  72. /**
  73. * An entry in the entries field of a dvb_announcement_support_descriptor.
  74. */
  75. struct dvb_announcement_support_entry {
  76. EBIT3(uint8_t announcement_type : 4; ,
  77. uint8_t reserved : 1; ,
  78. uint8_t reference_type : 3; );
  79. /* Only if reference_type == 1, 2 or 3:
  80. * struct dvb_announcement_support_reference reference */
  81. } __ucsi_packed;
  82. /**
  83. * The optional reference field only present in a dvb_announcement_support_descriptor if
  84. * its reference_type field is 1,2 or 3.
  85. */
  86. struct dvb_announcement_support_reference {
  87. uint16_t original_network_id;
  88. uint16_t transport_stream_id;
  89. uint16_t service_id;
  90. uint8_t component_tag;
  91. } __ucsi_packed;
  92. /**
  93. * Process a dvb_announcement_support_descriptor.
  94. *
  95. * @param d Generic descriptor pointer.
  96. * @return dvb_announcement_support_descriptor pointer, or NULL on error.
  97. */
  98. static inline struct dvb_announcement_support_descriptor*
  99. dvb_announcement_support_descriptor_codec(struct descriptor* d)
  100. {
  101. uint32_t pos = 0;
  102. uint8_t* buf = (uint8_t*) d + 2;
  103. uint32_t len = d->len;
  104. if (len < (sizeof(struct dvb_announcement_support_descriptor) - 2))
  105. return NULL;
  106. bswap16(buf+pos);
  107. pos += 2;
  108. while(pos < len) {
  109. struct dvb_announcement_support_entry *e =
  110. (struct dvb_announcement_support_entry*) (buf+pos);
  111. pos += sizeof(struct dvb_announcement_support_entry);
  112. if (pos > len)
  113. return NULL;
  114. if ((e->reference_type == 1) ||
  115. (e->reference_type == 2) ||
  116. (e->reference_type == 3)) {
  117. if ((pos + sizeof(struct dvb_announcement_support_reference)) > len)
  118. return NULL;
  119. bswap16(buf+pos);
  120. bswap16(buf+pos+2);
  121. bswap16(buf+pos+4);
  122. pos += sizeof(struct dvb_announcement_support_reference);
  123. }
  124. }
  125. return (struct dvb_announcement_support_descriptor*) d;
  126. }
  127. /**
  128. * Iterator for the entries field of a dvb_announcement_support_descriptor.
  129. *
  130. * @param d dvb_announcement_support_descriptor pointer.
  131. * @param pod Variable holding a pointer to the current dvb_announcement_support_entry.
  132. */
  133. #define dvb_announcement_support_descriptor_entries_for_each(d, pos) \
  134. for ((pos) = dvb_announcement_support_descriptor_entries_first(d); \
  135. (pos); \
  136. (pos) = dvb_announcement_support_descriptor_entries_next(d, pos))
  137. /**
  138. * Accessor for the reference field of a dvb_announcement_support_entry if present.
  139. *
  140. * @param entry dvb_announcement_support_entry pointer.
  141. * @return dvb_announcement_support_reference pointer, or NULL on error.
  142. */
  143. static inline struct dvb_announcement_support_reference*
  144. dvb_announcement_support_entry_reference(struct dvb_announcement_support_entry* entry)
  145. {
  146. if ((entry->reference_type != 0x01) &&
  147. (entry->reference_type != 0x02) &&
  148. (entry->reference_type != 0x03))
  149. return NULL;
  150. return (struct dvb_announcement_support_reference*)
  151. ((uint8_t*) entry + sizeof(struct dvb_announcement_support_entry));
  152. }
  153. /******************************** PRIVATE CODE ********************************/
  154. static inline struct dvb_announcement_support_entry*
  155. dvb_announcement_support_descriptor_entries_first(struct dvb_announcement_support_descriptor *d)
  156. {
  157. if (d->d.len == 2)
  158. return NULL;
  159. return (struct dvb_announcement_support_entry *)
  160. ((uint8_t*) d + sizeof(struct dvb_announcement_support_descriptor));
  161. }
  162. static inline struct dvb_announcement_support_entry*
  163. dvb_announcement_support_descriptor_entries_next(struct dvb_announcement_support_descriptor *d,
  164. struct dvb_announcement_support_entry *pos)
  165. {
  166. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  167. uint8_t* next = (uint8_t*) pos + sizeof(struct dvb_announcement_support_entry);
  168. struct dvb_announcement_support_reference* reference =
  169. dvb_announcement_support_entry_reference(pos);
  170. if (reference)
  171. next += sizeof(struct dvb_announcement_support_reference);
  172. if (next >= end)
  173. return NULL;
  174. return (struct dvb_announcement_support_entry *) next;
  175. }
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179. #endif