data_broadcast_descriptor.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_DATA_BROADCAST_DESCRIPTOR
  22. #define _UCSI_DVB_DATA_BROADCAST_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. * dvb_data_broadcast_descriptor structure.
  32. */
  33. struct dvb_data_broadcast_descriptor {
  34. struct descriptor d;
  35. uint16_t data_broadcast_id;
  36. uint8_t component_tag;
  37. uint8_t selector_length;
  38. /* uint8_t selector[] */
  39. /* struct dvb_data_broadcast_descriptor_part2 part2 */
  40. } __ucsi_packed;
  41. /**
  42. * Second part of a dvb_data_broadcast_descriptor following the variable length selector field.
  43. */
  44. struct dvb_data_broadcast_descriptor_part2 {
  45. iso639lang_t language_code;
  46. uint8_t text_length;
  47. /* uint8_t text[] */
  48. } __ucsi_packed;
  49. /**
  50. * Process a dvb_data_broadcast_descriptor.
  51. *
  52. * @param d Generic descriptor pointer.
  53. * @return dvb_data_broadcast_descriptor pointer, or NULL on error.
  54. */
  55. static inline struct dvb_data_broadcast_descriptor*
  56. dvb_data_broadcast_descriptor_codec(struct descriptor* d)
  57. {
  58. struct dvb_data_broadcast_descriptor *p =
  59. (struct dvb_data_broadcast_descriptor *) d;
  60. struct dvb_data_broadcast_descriptor_part2 *p2;
  61. uint8_t* buf = (uint8_t*) d + 2;
  62. uint32_t pos = sizeof(struct dvb_data_broadcast_descriptor) - 2;
  63. uint32_t len = d->len;
  64. if (pos > len)
  65. return NULL;
  66. bswap16(buf + 2);
  67. pos += p->selector_length;
  68. if (pos > len)
  69. return NULL;
  70. p2 = (struct dvb_data_broadcast_descriptor_part2*) (buf + 2 + pos);
  71. pos += sizeof(struct dvb_data_broadcast_descriptor_part2);
  72. if (pos > len)
  73. return NULL;
  74. pos += p2->text_length;
  75. if (pos != len)
  76. return NULL;
  77. return p;
  78. }
  79. /**
  80. * Accessor for the selector field of a dvb_data_broadcast_descriptor.
  81. *
  82. * @param d dvb_data_broadcast_descriptor pointer.
  83. * @return pointer to the field.
  84. */
  85. static inline uint8_t *
  86. dvb_data_broadcast_descriptor_selector(struct dvb_data_broadcast_descriptor *d)
  87. {
  88. return (uint8_t *) d + sizeof(struct dvb_data_broadcast_descriptor);
  89. }
  90. /**
  91. * Accessor for the second part of a dvb_data_broadcast_descriptor.
  92. *
  93. * @param d dvb_data_broadcast_descriptor pointer.
  94. * @return dvb_data_broadcast_descriptor_part2 pointer.
  95. */
  96. static inline struct dvb_data_broadcast_descriptor_part2 *
  97. dvb_data_broadcast_descriptor_part2(struct dvb_data_broadcast_descriptor *d)
  98. {
  99. return (struct dvb_data_broadcast_descriptor_part2*)
  100. ((uint8_t*) d + sizeof(struct dvb_data_broadcast_descriptor) +
  101. d->selector_length);
  102. }
  103. /**
  104. * Accessor for the text field in a dvb_data_broadcast_descriptor_part2.
  105. *
  106. * @param d dvb_data_broadcast_descriptor_part2 pointer.
  107. * @return pointer to the field.
  108. */
  109. static inline uint8_t *
  110. dvb_data_broadcast_descriptor_part2_text(struct dvb_data_broadcast_descriptor_part2 *d)
  111. {
  112. return (uint8_t *) d + sizeof(struct dvb_data_broadcast_descriptor_part2);
  113. }
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. #endif