service_descriptor.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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_SERVICE_DESCRIPTOR
  22. #define _UCSI_DVB_SERVICE_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 service_type.
  31. */
  32. enum {
  33. DVB_SERVICE_TYPE_DIGITAL_TV = 0x01,
  34. DVB_SERVICE_TYPE_DIGITAL_RADIO = 0x02,
  35. DVB_SERVICE_TYPE_TELETEXT = 0x03,
  36. DVB_SERVICE_TYPE_NVOD_REF = 0x04,
  37. DVB_SERVICE_TYPE_NVOD_TIMESHIFT = 0x05,
  38. DVB_SERVICE_TYPE_MOSAIC = 0x06,
  39. DVB_SERVICE_TYPE_PAL = 0x07,
  40. DVB_SERVICE_TYPE_SECAM = 0x08,
  41. DVB_SERVICE_TYPE_D_D2_MAC = 0x09,
  42. DVB_SERVICE_TYPE_FM_RADIO = 0x0a,
  43. DVB_SERVICE_TYPE_NTSC = 0x0b,
  44. DVB_SERVICE_TYPE_DATA_BCAST = 0x0c,
  45. DVB_SERVICE_TYPE_EN50221 = 0x0d,
  46. DVB_SERVICE_TYPE_RCS_MAP = 0x0e,
  47. DVB_SERVICE_TYPE_RCS_FLS = 0x0f,
  48. DVB_SERVICE_TYPE_MHP = 0x10,
  49. DVB_SERVICE_TYPE_MPEG2_HD_DIGITAL_TV = 0x11,
  50. DVB_SERVICE_TYPE_ADVANCED_CODEC_SD_DIGITAL_TV = 0x16,
  51. DVB_SERVICE_TYPE_ADVANCED_CODEC_SD_NVOD_TIMESHIFT = 0x17,
  52. DVB_SERVICE_TYPE_ADVANCED_CODEC_SD_NVOD_REF = 0x18,
  53. DVB_SERVICE_TYPE_ADVANCED_CODEC_HD_DIGITAL_TV = 0x19,
  54. DVB_SERVICE_TYPE_ADVANCED_CODEC_HD_NVOD_TIMESHIFT = 0x1a,
  55. DVB_SERVICE_TYPE_ADVANCED_CODEC_HD_NVOD_REF = 0x1b,
  56. };
  57. /**
  58. * dvb_service_descriptor structure.
  59. */
  60. struct dvb_service_descriptor {
  61. struct descriptor d;
  62. uint8_t service_type;
  63. uint8_t service_provider_name_length;
  64. /* uint8_t service_provider_name[] */
  65. /* struct dvb_service_descriptor_part2 part2 */
  66. } __ucsi_packed;
  67. /**
  68. * Second part of a dvb_service_descriptor following the variable length
  69. * service_provider_name field.
  70. */
  71. struct dvb_service_descriptor_part2 {
  72. uint8_t service_name_length;
  73. /* uint8_t service_name[] */
  74. } __ucsi_packed;
  75. /**
  76. * Process a dvb_service_descriptor.
  77. *
  78. * @param d Generic descriptor pointer.
  79. * @return dvb_service_descriptor pointer, or NULL on error.
  80. */
  81. static inline struct dvb_service_descriptor*
  82. dvb_service_descriptor_codec(struct descriptor* d)
  83. {
  84. struct dvb_service_descriptor *p =
  85. (struct dvb_service_descriptor *) d;
  86. struct dvb_service_descriptor_part2 *p2;
  87. uint32_t pos = sizeof(struct dvb_service_descriptor) - 2;
  88. uint32_t len = d->len;
  89. if (pos > len)
  90. return NULL;
  91. pos += p->service_provider_name_length;
  92. if (pos > len)
  93. return NULL;
  94. p2 = (struct dvb_service_descriptor_part2*) ((uint8_t*) d + 2 + pos);
  95. pos += sizeof(struct dvb_service_descriptor_part2);
  96. if (pos > len)
  97. return NULL;
  98. pos += p2->service_name_length;
  99. if (pos != len)
  100. return NULL;
  101. return p;
  102. }
  103. /**
  104. * Accessor for the service_provider_name field of a dvb_service_descriptor.
  105. *
  106. * @param d dvb_service_descriptor pointer.
  107. * @return Pointer to the service_provider_name field.
  108. */
  109. static inline uint8_t *
  110. dvb_service_descriptor_service_provider_name(struct dvb_service_descriptor *d)
  111. {
  112. return (uint8_t *) d + sizeof(struct dvb_service_descriptor);
  113. }
  114. /**
  115. * Accessor for the second part of a dvb_service_descriptor.
  116. *
  117. * @param d dvb_service_descriptor pointer.
  118. * @return dvb_service_descriptor_part2 pointer.
  119. */
  120. static inline struct dvb_service_descriptor_part2 *
  121. dvb_service_descriptor_part2(struct dvb_service_descriptor *d)
  122. {
  123. return (struct dvb_service_descriptor_part2 *)
  124. ((uint8_t*) d + sizeof(struct dvb_service_descriptor) +
  125. d->service_provider_name_length);
  126. }
  127. /**
  128. * Accessor for the service_name field of a dvb_service_descriptor_part2.
  129. *
  130. * @param d dvb_service_descriptor_part2 pointer.
  131. * @return Pointer to the service_name field.
  132. */
  133. static inline uint8_t *
  134. dvb_service_descriptor_service_name(struct dvb_service_descriptor_part2 *d)
  135. {
  136. return (uint8_t *) d + sizeof(struct dvb_service_descriptor_part2);
  137. }
  138. #ifdef __cplusplus
  139. }
  140. #endif
  141. #endif