pat_section.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_PAT_SECTION_H
  22. #define _UCSI_MPEG_PAT_SECTION_H 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/section.h>
  28. /**
  29. * mpeg_pat_section structure.
  30. */
  31. struct mpeg_pat_section {
  32. struct section_ext head; /* table_id_ext == transport_stream_id */
  33. /* struct mpeg_pat_program programs[] */
  34. } __ucsi_packed;
  35. /**
  36. * A program within an mpeg_pat_section.
  37. */
  38. struct mpeg_pat_program {
  39. uint16_t program_number;
  40. EBIT2(uint16_t reserved : 3; ,
  41. uint16_t pid :13; );
  42. } __ucsi_packed;
  43. /**
  44. * Process an mpeg_pat_section.
  45. *
  46. * @param section Pointer to the generic section_ext structure.
  47. * @return Pointer to the mpeg_pat_section structure, or NULL on error.
  48. */
  49. extern struct mpeg_pat_section *mpeg_pat_section_codec(struct section_ext *section);
  50. /**
  51. * Accessor for the transport_stream_id field of a PAT.
  52. *
  53. * @param pat PAT pointer.
  54. * @return The transport_stream_id.
  55. */
  56. static inline uint16_t mpeg_pat_section_transport_stream_id(struct mpeg_pat_section *pat)
  57. {
  58. return pat->head.table_id_ext;
  59. }
  60. /**
  61. * Conveience iterator for the programs field of an mpeg_pat_section.
  62. *
  63. * @param pat Pointer to the mpeg_pat_section structure.
  64. * @param pos Variable holding a pointer to the current mpeg_pat_program structure.
  65. */
  66. #define mpeg_pat_section_programs_for_each(pat, pos) \
  67. for ((pos) = mpeg_pat_section_programs_first(pat); \
  68. (pos); \
  69. (pos) = mpeg_pat_section_programs_next(pat, pos))
  70. /******************************** PRIVATE CODE ********************************/
  71. static inline struct mpeg_pat_program *
  72. mpeg_pat_section_programs_first(struct mpeg_pat_section * pat)
  73. {
  74. size_t pos = sizeof(struct mpeg_pat_section);
  75. if (pos >= section_ext_length(&pat->head))
  76. return NULL;
  77. return (struct mpeg_pat_program*)((uint8_t *) pat + pos);
  78. }
  79. static inline
  80. struct mpeg_pat_program *mpeg_pat_section_programs_next(struct mpeg_pat_section * pat,
  81. struct mpeg_pat_program * pos)
  82. {
  83. uint8_t *end = (uint8_t*) pat + section_ext_length(&pat->head);
  84. uint8_t *next= (uint8_t *) pos + sizeof(struct mpeg_pat_program);
  85. if (next >= end)
  86. return NULL;
  87. return (struct mpeg_pat_program *) next;
  88. }
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif