parental_rating_descriptor.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_PARENTAL_RATING_DESCRIPTOR
  22. #define _UCSI_DVB_PARENTAL_RATING_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. * Defined values for the rating field.
  32. */
  33. enum {
  34. DVB_PARENTAL_RATING_MIN_3YEARS = 0x01,
  35. DVB_PARENTAL_RATING_MIN_4YEARS = 0x02,
  36. DVB_PARENTAL_RATING_MIN_5YEARS = 0x03,
  37. DVB_PARENTAL_RATING_MIN_6YEARS = 0x04,
  38. DVB_PARENTAL_RATING_MIN_7YEARS = 0x05,
  39. DVB_PARENTAL_RATING_MIN_8YEARS = 0x06,
  40. DVB_PARENTAL_RATING_MIN_9YEARS = 0x07,
  41. DVB_PARENTAL_RATING_MIN_10YEARS = 0x08,
  42. DVB_PARENTAL_RATING_MIN_11YEARS = 0x09,
  43. DVB_PARENTAL_RATING_MIN_12YEARS = 0x0a,
  44. DVB_PARENTAL_RATING_MIN_13YEARS = 0x0b,
  45. DVB_PARENTAL_RATING_MIN_14YEARS = 0x0c,
  46. DVB_PARENTAL_RATING_MIN_15YEARS = 0x0d,
  47. DVB_PARENTAL_RATING_MIN_16YEARS = 0x0e,
  48. DVB_PARENTAL_RATING_MIN_17YEARS = 0x0f,
  49. };
  50. /**
  51. * dvb_parental_rating_descriptor structure.
  52. */
  53. struct dvb_parental_rating_descriptor {
  54. struct descriptor d;
  55. /* struct dvb_parental_rating ratings[] */
  56. } __ucsi_packed;
  57. /**
  58. * An entry in the ratings field of a dvb_parental_rating_descriptor.
  59. */
  60. struct dvb_parental_rating {
  61. iso639country_t country_code;
  62. uint8_t rating;
  63. } __ucsi_packed;
  64. /**
  65. * Process a dvb_parental_rating_descriptor.
  66. *
  67. * @param d Generic descriptor structure pointer.
  68. * @return dvb_parental_rating_descriptor pointer, or NULL on error.
  69. */
  70. static inline struct dvb_parental_rating_descriptor*
  71. dvb_parental_rating_descriptor_codec(struct descriptor* d)
  72. {
  73. if (d->len % sizeof(struct dvb_parental_rating))
  74. return NULL;
  75. return (struct dvb_parental_rating_descriptor*) d;
  76. }
  77. /**
  78. * Iterator for entries in the ratings field of a dvb_parental_rating_descriptor.
  79. *
  80. * @param d dvb_parental_rating_descriptor pointer.
  81. * @param pos Variable containing a pointer to the current dvb_parental_rating.
  82. */
  83. #define dvb_parental_rating_descriptor_ratings_for_each(d, pos) \
  84. for ((pos) = dvb_parental_rating_descriptor_ratings_first(d); \
  85. (pos); \
  86. (pos) = dvb_parental_rating_descriptor_ratings_next(d, pos))
  87. /******************************** PRIVATE CODE ********************************/
  88. static inline struct dvb_parental_rating*
  89. dvb_parental_rating_descriptor_ratings_first(struct dvb_parental_rating_descriptor *d)
  90. {
  91. if (d->d.len == 0)
  92. return NULL;
  93. return (struct dvb_parental_rating *)
  94. ((uint8_t*) d + sizeof(struct dvb_parental_rating_descriptor));
  95. }
  96. static inline struct dvb_parental_rating*
  97. dvb_parental_rating_descriptor_ratings_next(struct dvb_parental_rating_descriptor *d,
  98. struct dvb_parental_rating *pos)
  99. {
  100. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  101. uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_parental_rating);
  102. if (next >= end)
  103. return NULL;
  104. return (struct dvb_parental_rating *) next;
  105. }
  106. #ifdef __cplusplus
  107. }
  108. #endif
  109. #endif