subtitling_descriptor.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_SUBTITLING_DESCRIPTOR
  22. #define _UCSI_DVB_SUBTITLING_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_subtitling_descriptor structure.
  32. */
  33. struct dvb_subtitling_descriptor {
  34. struct descriptor d;
  35. /* struct dvb_subtitling_entry subtitles[] */
  36. } __ucsi_packed;
  37. /**
  38. * An entry in the subtitles field of the a dvb_subtitling_descriptor.
  39. */
  40. struct dvb_subtitling_entry {
  41. iso639lang_t language_code;
  42. uint8_t subtitling_type;
  43. uint16_t composition_page_id;
  44. uint16_t ancillary_page_id;
  45. } __ucsi_packed;
  46. /**
  47. * Process a dvb_subtitling_descriptor.
  48. *
  49. * @param d Generic descriptor.
  50. * @return dvb_subtitling_descriptor pointer, or NULL on error.
  51. */
  52. static inline struct dvb_subtitling_descriptor*
  53. dvb_subtitling_descriptor_codec(struct descriptor* d)
  54. {
  55. uint32_t pos = 0;
  56. uint8_t* ptr = (uint8_t*) d + 2;
  57. uint32_t len = d->len;
  58. if (len % sizeof(struct dvb_subtitling_entry))
  59. return NULL;
  60. while(pos < len) {
  61. bswap16(ptr+pos+4);
  62. bswap16(ptr+pos+6);
  63. pos += sizeof(struct dvb_subtitling_entry);
  64. }
  65. return (struct dvb_subtitling_descriptor*) d;
  66. }
  67. /**
  68. * Iterator for subtitles field in dvb_subtitling_descriptor.
  69. *
  70. * @param d dvb_subtitling_descriptor pointer.
  71. * @param pos Variable containing a pointer to current dvb_subtitling_entry.
  72. */
  73. #define dvb_subtitling_descriptor_subtitles_for_each(d, pos) \
  74. for ((pos) = dvb_subtitling_descriptor_subtitles_first(d); \
  75. (pos); \
  76. (pos) = dvb_subtitling_descriptor_subtitles_next(d, pos))
  77. /******************************** PRIVATE CODE ********************************/
  78. static inline struct dvb_subtitling_entry*
  79. dvb_subtitling_descriptor_subtitles_first(struct dvb_subtitling_descriptor *d)
  80. {
  81. if (d->d.len == 0)
  82. return NULL;
  83. return (struct dvb_subtitling_entry *)
  84. ((uint8_t*) d + sizeof(struct dvb_subtitling_descriptor));
  85. }
  86. static inline struct dvb_subtitling_entry*
  87. dvb_subtitling_descriptor_subtitles_next(struct dvb_subtitling_descriptor *d,
  88. struct dvb_subtitling_entry *pos)
  89. {
  90. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  91. uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_subtitling_entry);
  92. if (next >= end)
  93. return NULL;
  94. return (struct dvb_subtitling_entry *) next;
  95. }
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif