short_event_descriptor.h 3.5 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_SHORT_EVENT_DESCRIPTOR
  22. #define _UCSI_DVB_SHORT_EVENT_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_short_event_descriptor structure.
  32. */
  33. struct dvb_short_event_descriptor {
  34. struct descriptor d;
  35. iso639lang_t language_code;
  36. uint8_t event_name_length;
  37. /* uint8_t event_name[] */
  38. /* struct dvb_short_event_descriptor_part2 part2 */
  39. } __ucsi_packed;
  40. /**
  41. * Second part of a dvb_short_event_descriptor, following the variable length
  42. * name field.
  43. */
  44. struct dvb_short_event_descriptor_part2 {
  45. uint8_t text_length;
  46. /* uint8_t text[] */
  47. } __ucsi_packed;
  48. /**
  49. * Process a dvb_short_event_descriptor.
  50. *
  51. * @param d Generic descriptor pointer.
  52. * @return dvb_short_event_descriptor pointer, or NULL on error.
  53. */
  54. static inline struct dvb_short_event_descriptor*
  55. dvb_short_event_descriptor_codec(struct descriptor* d)
  56. {
  57. struct dvb_short_event_descriptor *p =
  58. (struct dvb_short_event_descriptor*) d;
  59. struct dvb_short_event_descriptor_part2 *p2;
  60. uint32_t pos = sizeof(struct dvb_short_event_descriptor) - 2;
  61. uint32_t len = d->len;
  62. if (pos > len)
  63. return NULL;
  64. pos += p->event_name_length;
  65. if (pos > len)
  66. return NULL;
  67. p2 = (struct dvb_short_event_descriptor_part2*) ((uint8_t*) d + 2 + pos);
  68. pos += sizeof(struct dvb_short_event_descriptor_part2);
  69. if (pos > len)
  70. return NULL;
  71. pos += p2->text_length;
  72. if (pos != len)
  73. return NULL;
  74. return p;
  75. }
  76. /**
  77. * Accessor for name field in a dvb_short_event_descriptor.
  78. *
  79. * @param d dvb_short_event_descriptor pointer.
  80. * @return Pointer to name field.
  81. */
  82. static inline uint8_t *
  83. dvb_short_event_descriptor_event_name(struct dvb_short_event_descriptor *d)
  84. {
  85. return (uint8_t *) d + sizeof(struct dvb_short_event_descriptor);
  86. }
  87. /**
  88. * Accessor for second part of a dvb_short_event_descriptor.
  89. *
  90. * @param d dvb_short_event_descriptor pointer.
  91. * @return dvb_short_event_descriptor_part2 pointer.
  92. */
  93. static inline struct dvb_short_event_descriptor_part2 *
  94. dvb_short_event_descriptor_part2(struct dvb_short_event_descriptor *d)
  95. {
  96. return (struct dvb_short_event_descriptor_part2 *)
  97. ((uint8_t*) d + sizeof(struct dvb_short_event_descriptor) +
  98. d->event_name_length);
  99. }
  100. /**
  101. * Accessor for text field in a dvb_short_event_descriptor_part2.
  102. *
  103. * @param d dvb_short_event_descriptor_part2 pointer.
  104. * @return Pointer to text field.
  105. */
  106. static inline uint8_t *
  107. dvb_short_event_descriptor_text(struct dvb_short_event_descriptor_part2 *d)
  108. {
  109. return (uint8_t *) d + sizeof(struct dvb_short_event_descriptor_part2);
  110. }
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #endif