cat_section.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_MPEG_CAT_SECTION_H
  22. #define _UCSI_MPEG_CAT_SECTION_H 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/section.h>
  28. /**
  29. * mpeg_cat_section structure.
  30. */
  31. struct mpeg_cat_section {
  32. struct section_ext head;
  33. /* struct descriptor descriptors[] */
  34. } __ucsi_packed;
  35. /**
  36. * Process an mpeg_cat_section.
  37. *
  38. * @param section The generic section_ext structure.
  39. * @return Pointer to an mpeg_cat_section structure, or NULL on error.
  40. */
  41. extern struct mpeg_cat_section *mpeg_cat_section_codec(struct section_ext *section);
  42. /**
  43. * Convenience iterator for descriptors field of an mpeg_cat_section.
  44. *
  45. * @param cat The mpeg_cat_section pointer.
  46. * @param pos Variable holding a pointer to the current descriptor.
  47. */
  48. #define mpeg_cat_section_descriptors_for_each(cat, pos) \
  49. for ((pos) = mpeg_cat_section_descriptors_first(cat); \
  50. (pos); \
  51. (pos) = mpeg_cat_section_descriptors_next(cat, pos))
  52. /******************************** PRIVATE CODE ********************************/
  53. static inline struct descriptor *
  54. mpeg_cat_section_descriptors_first(struct mpeg_cat_section *cat)
  55. {
  56. size_t pos = sizeof(struct mpeg_cat_section);
  57. if (pos >= section_ext_length(&cat->head))
  58. return NULL;
  59. return (struct descriptor*)((uint8_t *) cat + pos);
  60. }
  61. static inline struct descriptor *
  62. mpeg_cat_section_descriptors_next(struct mpeg_cat_section *cat,
  63. struct descriptor* pos)
  64. {
  65. return next_descriptor((uint8_t *) cat + sizeof(struct mpeg_cat_section),
  66. section_ext_length(&cat->head) - sizeof(struct mpeg_cat_section),
  67. pos);
  68. }
  69. #ifdef __cplusplus
  70. }
  71. #endif
  72. #endif