local_time_offset_descriptor.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_LOCAL_TIME_OFFSET_DESCRIPTOR
  22. #define _UCSI_DVB_LOCAL_TIME_OFFSET_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. #include <libucsi/dvb/types.h>
  31. /**
  32. * dvb_local_time_offset_descriptor parameter.
  33. */
  34. struct dvb_local_time_offset_descriptor {
  35. struct descriptor d;
  36. /* struct dvb_local_time_offset offsets[] */
  37. } __ucsi_packed;
  38. /**
  39. * Entry in the offsets field of dvb_local_time_offset_descriptor.
  40. */
  41. struct dvb_local_time_offset {
  42. iso639country_t country_code;
  43. EBIT3(uint8_t country_region_id : 6; ,
  44. uint8_t reserved : 1; ,
  45. uint8_t local_time_offset_polarity : 1; );
  46. dvbhhmm_t local_time_offset;
  47. dvbdate_t time_of_change;
  48. dvbhhmm_t next_time_offset;
  49. } __ucsi_packed;
  50. /**
  51. * Process a dvb_local_time_offset_descriptor.
  52. *
  53. * @param d Generic descriptor pointer.
  54. * @return dvb_local_time_offset_descriptor pointer, or NULL on error.
  55. */
  56. static inline struct dvb_local_time_offset_descriptor*
  57. dvb_local_time_offset_descriptor_codec(struct descriptor* d)
  58. {
  59. uint32_t len = d->len;
  60. uint32_t pos = 0;
  61. if (len % sizeof(struct dvb_local_time_offset))
  62. return NULL;
  63. while(pos < len) {
  64. pos += sizeof(struct dvb_local_time_offset);
  65. }
  66. return (struct dvb_local_time_offset_descriptor*) d;
  67. }
  68. /**
  69. * Iterator for the offsets field of a dvb_local_time_offset_descriptor.
  70. *
  71. * @param d dvb_local_time_offset_descriptor pointer.
  72. * @param pos Variable containing a pointer to the current dvb_local_time_offset.
  73. */
  74. #define dvb_local_time_offset_descriptor_offsets_for_each(d, pos) \
  75. for ((pos) = dvb_local_time_offset_descriptor_offsets_first(d); \
  76. (pos); \
  77. (pos) = dvb_local_time_offset_descriptor_offsets_next(d, pos))
  78. /******************************** PRIVATE CODE ********************************/
  79. static inline struct dvb_local_time_offset*
  80. dvb_local_time_offset_descriptor_offsets_first(struct dvb_local_time_offset_descriptor *d)
  81. {
  82. if (d->d.len == 0)
  83. return NULL;
  84. return (struct dvb_local_time_offset *)
  85. ((uint8_t*) d + sizeof(struct dvb_local_time_offset_descriptor));
  86. }
  87. static inline struct dvb_local_time_offset*
  88. dvb_local_time_offset_descriptor_offsets_next(struct dvb_local_time_offset_descriptor *d,
  89. struct dvb_local_time_offset *pos)
  90. {
  91. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  92. uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_local_time_offset);
  93. if (next >= end)
  94. return NULL;
  95. return (struct dvb_local_time_offset *) next;
  96. }
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #endif