multilingual_component_descriptor.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_MULTILINGUAL_COMPONENT_DESCRIPTOR
  22. #define _UCSI_DVB_MULTILINGUAL_COMPONENT_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_multilingual_component_descriptor structure.
  32. */
  33. struct dvb_multilingual_component_descriptor {
  34. struct descriptor d;
  35. uint8_t component_tag;
  36. /* struct dvb_multilingual_component components[] */
  37. } __ucsi_packed;
  38. /**
  39. * An entry in the components field of a dvb_multilingual_component_descriptor.
  40. */
  41. struct dvb_multilingual_component {
  42. iso639lang_t language_code;
  43. uint8_t text_description_length;
  44. /* uint8_t text_char[] */
  45. } __ucsi_packed;
  46. /**
  47. * Process a dvb_multilingual_component_descriptor.
  48. *
  49. * @param d Generic descriptor pointer.
  50. * @return dvb_multilingual_component_descriptor pointer, or NULL on error.
  51. */
  52. static inline struct dvb_multilingual_component_descriptor*
  53. dvb_multilingual_component_descriptor_codec(struct descriptor* d)
  54. {
  55. uint8_t* buf = (uint8_t*) d + 2;
  56. uint32_t pos = sizeof(struct dvb_multilingual_component_descriptor) - 2;
  57. uint32_t len = d->len;
  58. if (pos > len)
  59. return NULL;
  60. while(pos < len) {
  61. struct dvb_multilingual_component *e =
  62. (struct dvb_multilingual_component*) (buf+pos);
  63. pos += sizeof(struct dvb_multilingual_component);
  64. if (pos > len)
  65. return NULL;
  66. pos += e->text_description_length;
  67. if (pos > len)
  68. return NULL;
  69. }
  70. return (struct dvb_multilingual_component_descriptor*) d;
  71. }
  72. /**
  73. * Iterator for entries in the components field of a dvb_multilingual_component_descriptor.
  74. *
  75. * @param d Generic descriptor pointer.
  76. * @param pos Variable containing a pointer to the current dvb_multilingual_component.
  77. */
  78. #define dvb_multilingual_component_descriptor_components_for_each(d, pos) \
  79. for ((pos) = dvb_multilingual_component_descriptor_components_first(d); \
  80. (pos); \
  81. (pos) = dvb_multilingual_component_descriptor_components_next(d, pos))
  82. /**
  83. * Accessor for the text_char field in a dvb_multilingual_component.
  84. *
  85. * @param e dvb_multilingual_component pointer.
  86. * @return Pointer to the field.
  87. */
  88. static inline uint8_t *
  89. dvb_multilingual_component_text_char(struct dvb_multilingual_component *e)
  90. {
  91. return (uint8_t *) e + sizeof(struct dvb_multilingual_component);
  92. }
  93. /******************************** PRIVATE CODE ********************************/
  94. static inline struct dvb_multilingual_component*
  95. dvb_multilingual_component_descriptor_components_first(struct dvb_multilingual_component_descriptor *d)
  96. {
  97. if (d->d.len == 1)
  98. return NULL;
  99. return (struct dvb_multilingual_component *)
  100. ((uint8_t*) d + sizeof(struct dvb_multilingual_component_descriptor));
  101. }
  102. static inline struct dvb_multilingual_component*
  103. dvb_multilingual_component_descriptor_components_next(struct dvb_multilingual_component_descriptor *d,
  104. struct dvb_multilingual_component *pos)
  105. {
  106. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  107. uint8_t *next = (uint8_t *) pos +
  108. sizeof(struct dvb_multilingual_component) +
  109. pos->text_description_length;
  110. if (next >= end)
  111. return NULL;
  112. return (struct dvb_multilingual_component *) next;
  113. }
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. #endif