time_shifted_service_descriptor.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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_TIME_SHIFTED_SERVICE_DESCRIPTOR
  22. #define _UCSI_ATSC_TIME_SHIFTED_SERVICE_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. * atsc_time_shifted_service_descriptor structure.
  32. */
  33. struct atsc_time_shifted_service_descriptor {
  34. struct descriptor d;
  35. EBIT2(uint8_t reserved : 3; ,
  36. uint8_t number_of_services : 5; );
  37. /* struct atsc_time_shifted_service services[] */
  38. } __ucsi_packed;
  39. /**
  40. * An entry in the services field of an atsc_time_shifted_service_descriptor.
  41. */
  42. struct atsc_time_shifted_service {
  43. EBIT2(uint16_t reserved : 6; ,
  44. uint16_t time_shift :10; );
  45. EBIT3(uint32_t reserved2 : 4; ,
  46. uint32_t major_channel_number :10; ,
  47. uint32_t minor_channel_number :10; );
  48. } __ucsi_packed;
  49. /**
  50. * Process an atsc_time_shifted_service_descriptor.
  51. *
  52. * @param d Generic descriptor pointer.
  53. * @return atsc_time_shifted_service_descriptor pointer, or NULL on error.
  54. */
  55. static inline struct atsc_time_shifted_service_descriptor*
  56. atsc_time_shifted_service_descriptor_codec(struct descriptor* d)
  57. {
  58. struct atsc_time_shifted_service_descriptor *ret =
  59. (struct atsc_time_shifted_service_descriptor *) d;
  60. uint8_t *buf = (uint8_t*) d + 2;
  61. int pos = 0;
  62. int idx;
  63. if (d->len < 1)
  64. return NULL;
  65. pos++;
  66. for(idx = 0; idx < ret->number_of_services; idx++) {
  67. if (d->len < (pos + sizeof(struct atsc_time_shifted_service)))
  68. return NULL;
  69. bswap16(buf+pos);
  70. bswap24(buf+pos+2);
  71. pos += sizeof(struct atsc_time_shifted_service);
  72. }
  73. return (struct atsc_time_shifted_service_descriptor*) d;
  74. }
  75. /**
  76. * Iterator for services field of a atsc_time_shifted_service_descriptor.
  77. *
  78. * @param d atsc_time_shifted_service_descriptor pointer.
  79. * @param pos Variable holding a pointer to the current atsc_service_location_element.
  80. * @param idx Integer used to count which service we are in.
  81. */
  82. #define atsc_time_shifted_service_descriptor_services_for_each(d, pos, idx) \
  83. for ((pos) = atsc_time_shifted_service_descriptor_services_first(d), idx=0; \
  84. (pos); \
  85. (pos) = atsc_time_shifted_service_descriptor_services_next(d, pos, ++idx))
  86. /******************************** PRIVATE CODE ********************************/
  87. static inline struct atsc_time_shifted_service*
  88. atsc_time_shifted_service_descriptor_services_first(struct atsc_time_shifted_service_descriptor *d)
  89. {
  90. if (d->number_of_services == 0)
  91. return NULL;
  92. return (struct atsc_time_shifted_service *)
  93. ((uint8_t*) d + sizeof(struct atsc_time_shifted_service_descriptor));
  94. }
  95. static inline struct atsc_time_shifted_service*
  96. atsc_time_shifted_service_descriptor_services_next(struct atsc_time_shifted_service_descriptor *d,
  97. struct atsc_time_shifted_service *pos,
  98. int idx)
  99. {
  100. uint8_t *next = (uint8_t *) pos + sizeof(struct atsc_time_shifted_service);
  101. if (idx >= d->number_of_services)
  102. return NULL;
  103. return (struct atsc_time_shifted_service *) next;
  104. }
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. #endif