country_availability_descriptor.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_COUNTRY_AVAILABILITY_DESCRIPTOR
  22. #define _UCSI_DVB_COUNTRY_AVAILABILITY_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_country_availability_descriptor structure.
  32. */
  33. struct dvb_country_availability_descriptor {
  34. struct descriptor d;
  35. EBIT2(uint8_t country_availability_flag : 1; ,
  36. uint8_t reserved : 7; );
  37. /* struct dvb_country_availability_entry countries[] */
  38. } __ucsi_packed;
  39. /**
  40. * An entry in the countries field of a dvb_country_availability_descriptor.
  41. */
  42. struct dvb_country_availability_entry {
  43. iso639country_t country_code;
  44. } __ucsi_packed;
  45. /**
  46. * Process a dvb_country_availability_descriptor.
  47. *
  48. * @param d Generic descriptor pointer.
  49. * @return dvb_country_availability_descriptor pointer, or NULL on error.
  50. */
  51. static inline struct dvb_country_availability_descriptor*
  52. dvb_country_availability_descriptor_codec(struct descriptor* d)
  53. {
  54. uint32_t len = d->len;
  55. if (len < (sizeof(struct dvb_country_availability_descriptor) - 2))
  56. return NULL;
  57. if ((len - 1) % sizeof(struct dvb_country_availability_entry))
  58. return NULL;
  59. return (struct dvb_country_availability_descriptor*) d;
  60. }
  61. /**
  62. * Iterator for the countries field of a dvb_country_availability_descriptor.
  63. *
  64. * @param d dvb_country_availability_descriptor pointer.
  65. * @param pos Variable containing a pointer to the current dvb_country_availability_entry.
  66. */
  67. #define dvb_country_availability_descriptor_countries_for_each(d, pos) \
  68. for ((pos) = dvb_country_availability_descriptor_countries_first(d); \
  69. (pos); \
  70. (pos) = dvb_country_availability_descriptor_countries_next(d, pos))
  71. /******************************** PRIVATE CODE ********************************/
  72. static inline struct dvb_country_availability_entry*
  73. dvb_country_availability_descriptor_countries_first(struct dvb_country_availability_descriptor *d)
  74. {
  75. if (d->d.len == 1)
  76. return NULL;
  77. return (struct dvb_country_availability_entry *)
  78. ((uint8_t*) d + sizeof(struct dvb_country_availability_descriptor));
  79. }
  80. static inline struct dvb_country_availability_entry*
  81. dvb_country_availability_descriptor_countries_next(struct dvb_country_availability_descriptor *d,
  82. struct dvb_country_availability_entry *pos)
  83. {
  84. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  85. uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_country_availability_entry);
  86. if (next >= end)
  87. return NULL;
  88. return (struct dvb_country_availability_entry *) next;
  89. }
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. #endif