service_location_descriptor.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_SERVICE_LOCATION_DESCRIPTOR
  22. #define _UCSI_ATSC_SERVICE_LOCATION_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. enum atsc_stream_types {
  31. ATSC_STREAM_TYPE_VIDEO = 0x02,
  32. ATSC_STREAM_TYPE_AUDIO = 0x81,
  33. };
  34. /**
  35. * atsc_service_location_descriptor structure.
  36. */
  37. struct atsc_service_location_descriptor {
  38. struct descriptor d;
  39. EBIT2(uint16_t reserved : 3; ,
  40. uint16_t PCR_PID :13; );
  41. uint8_t number_elements;
  42. /* struct atsc_service_location_element elements[] */
  43. } __ucsi_packed;
  44. /**
  45. * An entry in the elements field of an atsc_service_location_descriptor.
  46. */
  47. struct atsc_caption_service_location_element {
  48. uint8_t stream_type;
  49. EBIT2(uint16_t reserved : 3; ,
  50. uint16_t elementary_PID :13; );
  51. iso639lang_t language_code;
  52. } __ucsi_packed;
  53. /**
  54. * Process an atsc_service_location_descriptor.
  55. *
  56. * @param d Generic descriptor pointer.
  57. * @return atsc_service_location_descriptor pointer, or NULL on error.
  58. */
  59. static inline struct atsc_service_location_descriptor*
  60. atsc_service_location_descriptor_codec(struct descriptor* d)
  61. {
  62. struct atsc_service_location_descriptor *ret =
  63. (struct atsc_service_location_descriptor *) d;
  64. uint8_t *buf = (uint8_t*) d + 2;
  65. int pos = 0;
  66. int idx;
  67. if (d->len < 3)
  68. return NULL;
  69. bswap16(buf + pos);
  70. pos+=3;
  71. for(idx = 0; idx < ret->number_elements; idx++) {
  72. if (d->len < (pos + sizeof(struct atsc_caption_service_entry)))
  73. return NULL;
  74. bswap16(buf+pos+1);
  75. pos += sizeof(struct atsc_caption_service_entry);
  76. }
  77. return (struct atsc_service_location_descriptor*) d;
  78. }
  79. /**
  80. * Iterator for elements field of a atsc_service_location_descriptor.
  81. *
  82. * @param d atsc_service_location_descriptor pointer.
  83. * @param pos Variable holding a pointer to the current atsc_service_location_element.
  84. * @param idx Integer used to count which dimension we are in.
  85. */
  86. #define atsc_service_location_descriptor_elements_for_each(d, pos, idx) \
  87. for ((pos) = atsc_service_location_descriptor_elements_first(d), idx=0; \
  88. (pos); \
  89. (pos) = atsc_service_location_descriptor_elements_next(d, pos, ++idx))
  90. /******************************** PRIVATE CODE ********************************/
  91. static inline struct atsc_caption_service_location_element*
  92. atsc_service_location_descriptor_elements_first(struct atsc_service_location_descriptor *d)
  93. {
  94. if (d->number_elements == 0)
  95. return NULL;
  96. return (struct atsc_caption_service_location_element *)
  97. ((uint8_t*) d + sizeof(struct atsc_service_location_descriptor));
  98. }
  99. static inline struct atsc_caption_service_location_element*
  100. atsc_service_location_descriptor_elements_next(struct atsc_service_location_descriptor *d,
  101. struct atsc_caption_service_location_element *pos,
  102. int idx)
  103. {
  104. uint8_t *next = (uint8_t *) pos + sizeof(struct atsc_caption_service_location_element);
  105. if (idx >= d->number_elements)
  106. return NULL;
  107. return (struct atsc_caption_service_location_element *) next;
  108. }
  109. #ifdef __cplusplus
  110. }
  111. #endif
  112. #endif