content_descriptor.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_CONTENT_DESCRIPTOR
  22. #define _UCSI_DVB_CONTENT_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. // FIXME: the nibbles
  30. /**
  31. * dvb_content_descriptor structure.
  32. */
  33. struct dvb_content_descriptor {
  34. struct descriptor d;
  35. /* struct dvb_content_nibble nibbles[] */
  36. } __ucsi_packed;
  37. /**
  38. * An entry in the nibbles field of a dvb_content_descriptor.
  39. */
  40. struct dvb_content_nibble {
  41. EBIT2(uint8_t content_nibble_level_1 : 4; ,
  42. uint8_t content_nibble_level_2 : 4; );
  43. EBIT2(uint8_t user_nibble_1 : 4; ,
  44. uint8_t user_nibble_2 : 4; );
  45. } __ucsi_packed;
  46. /**
  47. * Process a dvb_content_descriptor.
  48. *
  49. * @param d Generic descriptor pointer.
  50. * @return dvb_content_descriptor pointer, or NULL on error.
  51. */
  52. static inline struct dvb_content_descriptor*
  53. dvb_content_descriptor_codec(struct descriptor* d)
  54. {
  55. if (d->len % sizeof(struct dvb_content_nibble))
  56. return NULL;
  57. return (struct dvb_content_descriptor*) d;
  58. }
  59. /**
  60. * Iterator for the nibbles field of a dvb_content_descriptor.
  61. *
  62. * @param d dvb_content_descriptor pointer.
  63. * @param pos Variable containing a pointer to the current dvb_content_nibble.
  64. */
  65. #define dvb_content_descriptor_nibbles_for_each(d, pos) \
  66. for ((pos) = dvb_content_descriptor_nibbles_first(d); \
  67. (pos); \
  68. (pos) = dvb_content_descriptor_nibbles_next(d, pos))
  69. /******************************** PRIVATE CODE ********************************/
  70. static inline struct dvb_content_nibble*
  71. dvb_content_descriptor_nibbles_first(struct dvb_content_descriptor *d)
  72. {
  73. if (d->d.len == 0)
  74. return NULL;
  75. return (struct dvb_content_nibble *)
  76. ((uint8_t*) d + sizeof(struct dvb_content_descriptor));
  77. }
  78. static inline struct dvb_content_nibble*
  79. dvb_content_descriptor_nibbles_next(struct dvb_content_descriptor *d,
  80. struct dvb_content_nibble *pos)
  81. {
  82. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  83. uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_content_nibble);
  84. if (next >= end)
  85. return NULL;
  86. return (struct dvb_content_nibble *) next;
  87. }
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif