teletext_descriptor.h 3.2 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_TELETEXT_DESCRIPTOR
  22. #define _UCSI_DVB_TELETEXT_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. * Possible values for the type field.
  32. */
  33. enum {
  34. DVB_TELETEXT_TYPE_INITIAL = 0x01,
  35. DVB_TELETEXT_TYPE_SUBTITLE = 0x02,
  36. DVB_TELETEXT_TYPE_ADDITIONAL = 0x03,
  37. DVB_TELETEXT_TYPE_SCHEDULE = 0x04,
  38. DVB_TELETEXT_TYPE_SUBTITLE_HEARING_IMPAIRED= 0x05,
  39. };
  40. /**
  41. * dvb_teletext_descriptor structure.
  42. */
  43. struct dvb_teletext_descriptor {
  44. struct descriptor d;
  45. /* struct dvb_teletext_entry entries[] */
  46. } __ucsi_packed;
  47. /**
  48. * An entry in the entries field of a dvb_teletext_descriptor.
  49. */
  50. struct dvb_teletext_entry {
  51. iso639lang_t language_code;
  52. EBIT2(uint8_t type : 5; ,
  53. uint8_t magazine_number: 3; );
  54. uint8_t page_number;
  55. } __ucsi_packed;
  56. /**
  57. * Process a dvb_teletext_descriptor.
  58. *
  59. * @param d Generic descriptor.
  60. * @return dvb_teletext_descriptor pointer, or NULL on error.
  61. */
  62. static inline struct dvb_teletext_descriptor*
  63. dvb_teletext_descriptor_codec(struct descriptor* d)
  64. {
  65. if (d->len % sizeof(struct dvb_teletext_entry))
  66. return NULL;
  67. return (struct dvb_teletext_descriptor*) d;
  68. }
  69. /**
  70. * Iterator for entries field of a dvb_teletext_descriptor.
  71. *
  72. * @param d dvb_teletext_descriptor pointer.
  73. * @param pos Variable holding a pointer to the current dvb_teletext_entry.
  74. */
  75. #define dvb_teletext_descriptor_entries_for_each(d, pos) \
  76. for ((pos) = dvb_teletext_descriptor_entries_first(d); \
  77. (pos); \
  78. (pos) = dvb_teletext_descriptor_entries_next(d, pos))
  79. /******************************** PRIVATE CODE ********************************/
  80. static inline struct dvb_teletext_entry*
  81. dvb_teletext_descriptor_entries_first(struct dvb_teletext_descriptor *d)
  82. {
  83. if (d->d.len == 0)
  84. return NULL;
  85. return (struct dvb_teletext_entry *)
  86. ((uint8_t*) d + sizeof(struct dvb_teletext_descriptor));
  87. }
  88. static inline struct dvb_teletext_entry*
  89. dvb_teletext_descriptor_entries_next(struct dvb_teletext_descriptor *d,
  90. struct dvb_teletext_entry *pos)
  91. {
  92. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  93. uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_teletext_entry);
  94. if (next >= end)
  95. return NULL;
  96. return (struct dvb_teletext_entry *) next;
  97. }
  98. #ifdef __cplusplus
  99. }
  100. #endif
  101. #endif