ait_application_descriptor.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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_AIT_APPLICATION_DESCRIPTOR
  22. #define _UCSI_DVB_AIT_APPLICATION_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 the visibility field.
  31. */
  32. enum {
  33. AVB_AIT_APPLICATION_VISIBILITY_HIDDEN = 0x00,
  34. AVB_AIT_APPLICATION_VISIBILITY_APPSONLY = 0x01,
  35. AVB_AIT_APPLICATION_VISIBILITY_VISIBLE = 0x03,
  36. };
  37. /**
  38. * dvb_ait_application_descriptor structure.
  39. */
  40. struct dvb_ait_application_descriptor {
  41. struct descriptor d;
  42. uint8_t application_profiles_length;
  43. /* struct dvb_ait_application_profile profiles [] */
  44. /* struct dvb_ait_application_descriptor_part2 part2 */
  45. } __ucsi_packed;
  46. /**
  47. * An entry in the profiles field of a dvb_ait_application_descriptor.
  48. */
  49. struct dvb_ait_application_profile {
  50. uint16_t application_profile;
  51. uint8_t version_major;
  52. uint8_t version_minor;
  53. uint8_t version_micro;
  54. } __ucsi_packed;
  55. /**
  56. * Second part of a dvb_ait_application_descriptor structure.
  57. */
  58. struct dvb_ait_application_descriptor_part2 {
  59. EBIT3(uint8_t service_bound_flag : 1; ,
  60. uint8_t visibility : 2; ,
  61. uint8_t reserved : 5; );
  62. uint8_t application_priority;
  63. /* uint8_t transport_protocol_label[] */
  64. } __ucsi_packed;
  65. /**
  66. * Process a dvb_ait_application_descriptor.
  67. *
  68. * @param d Generic descriptor pointer.
  69. * @return dvb_ait_application_descriptor pointer, or NULL on error.
  70. */
  71. static inline struct dvb_ait_application_descriptor*
  72. dvb_ait_application_descriptor_codec(struct descriptor* d)
  73. {
  74. uint32_t pos = 0;
  75. uint32_t pos2 = 0;
  76. uint32_t len = d->len + 2;
  77. uint8_t* buf = (uint8_t*) d;
  78. struct dvb_ait_application_descriptor *ret =
  79. (struct dvb_ait_application_descriptor*) d;
  80. if (len < sizeof(struct dvb_ait_application_descriptor))
  81. return NULL;
  82. if (len < (sizeof(struct dvb_ait_application_descriptor) + ret->application_profiles_length))
  83. return NULL;
  84. if (ret->application_profiles_length % sizeof(struct dvb_ait_application_profile))
  85. return NULL;
  86. pos += sizeof(struct dvb_ait_application_descriptor);
  87. pos2 = 0;
  88. while(pos2 < ret->application_profiles_length) {
  89. bswap16(buf + pos + pos2);
  90. pos2 += sizeof(struct dvb_ait_application_descriptor);
  91. }
  92. pos += pos2;
  93. if (len < (pos + sizeof(struct dvb_ait_application_descriptor_part2)))
  94. return NULL;
  95. return ret;
  96. }
  97. /**
  98. * Iterator for the profiles field of a dvb_ait_application_descriptor.
  99. *
  100. * @param d dvb_ait_application_descriptor pointer.
  101. * @param pos Variable containing a pointer to the current dvb_ait_application_profile.
  102. */
  103. #define dvb_ait_application_descriptor_profiles_for_each(d, pos) \
  104. for ((pos) = dvb_ait_application_descriptor_profiles_first(d); \
  105. (pos); \
  106. (pos) = dvb_ait_application_descriptor_profiles_next(d, pos))
  107. /**
  108. * Accessor for the part2 field of a dvb_ait_application_descriptor.
  109. *
  110. * @param d dvb_ait_application_descriptor pointer.
  111. * @return dvb_ait_application_descriptor_part2 pointer.
  112. */
  113. static inline struct dvb_ait_application_descriptor_part2*
  114. dvb_ait_application_descriptor_part2(struct dvb_ait_application_descriptor* d)
  115. {
  116. return (struct dvb_ait_application_descriptor_part2*)
  117. ((uint8_t*) d +
  118. sizeof(struct dvb_ait_application_descriptor) +
  119. d->application_profiles_length);
  120. }
  121. /**
  122. * Accessor for the transport_protocol_label field of a dvb_ait_application_descriptor_part2.
  123. *
  124. * @param d dvb_ait_application_descriptor_part2 pointer.
  125. * @return Pointer to the field.
  126. */
  127. static inline uint8_t*
  128. dvb_ait_application_descriptor_part2_transport_protocol_label(struct dvb_ait_application_descriptor_part2* d)
  129. {
  130. return (uint8_t*) d +
  131. sizeof(struct dvb_ait_application_descriptor_part2);
  132. }
  133. /**
  134. * Calculate the number of bytes in the transport_protocol_label field of a dvb_ait_application_descriptor_part2.
  135. *
  136. * @param d dvb_ait_application_descriptor pointer.
  137. * @param part2 dvb_ait_application_descriptor_part2 pointer.
  138. * @return Number of bytes.
  139. */
  140. static inline int
  141. dvb_ait_application_descriptor_part2_transport_protocol_label_length(struct dvb_ait_application_descriptor *d,
  142. struct dvb_ait_application_descriptor_part2* part2)
  143. {
  144. uint8_t *ptr = (uint8_t*) part2 + sizeof(struct dvb_ait_application_descriptor_part2);
  145. uint8_t *end = (uint8_t*) d + d->d.len + 2;
  146. return (int) (end - ptr);
  147. }
  148. /******************************** PRIVATE CODE ********************************/
  149. static inline struct dvb_ait_application_profile*
  150. dvb_ait_application_descriptor_profiles_first(struct dvb_ait_application_descriptor *d)
  151. {
  152. if (d->application_profiles_length == 0)
  153. return NULL;
  154. return (struct dvb_ait_application_profile *)
  155. ((uint8_t*) d + sizeof(struct dvb_ait_application_descriptor));
  156. }
  157. static inline struct dvb_ait_application_profile*
  158. dvb_ait_application_descriptor_profiles_next(struct dvb_ait_application_descriptor *d,
  159. struct dvb_ait_application_profile *pos)
  160. {
  161. uint8_t *end = (uint8_t*) d +
  162. sizeof(struct dvb_ait_application_descriptor) +
  163. d->application_profiles_length;
  164. uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_ait_application_profile);
  165. if (next >= end)
  166. return NULL;
  167. return (struct dvb_ait_application_profile *) next;
  168. }
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif