fmc_descriptor.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_FMC_DESCRIPTOR
  22. #define _UCSI_MPEG_FMC_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. /**
  30. * mpeg_fmc_descriptor structure.
  31. */
  32. struct mpeg_fmc_descriptor {
  33. struct descriptor d;
  34. /* struct mpeg_flex_mux muxes[] */
  35. } __ucsi_packed;
  36. /**
  37. * An entry in the muxes field of an mpeg_fmc_descriptor structure.
  38. */
  39. struct mpeg_flex_mux {
  40. uint16_t es_id;
  41. uint8_t flex_mux_channel;
  42. } __ucsi_packed;
  43. /**
  44. * Process an mpeg_fmc_descriptor structure.
  45. *
  46. * @param d Generic descriptor structure.
  47. * @return Pointer to an mpeg_fmc_descriptor structure, or NULL on error.
  48. */
  49. static inline struct mpeg_fmc_descriptor*
  50. mpeg_fmc_descriptor_codec(struct descriptor* d)
  51. {
  52. uint8_t* buf = (uint8_t*) d + 2;
  53. int pos = 0;
  54. int len = d->len;
  55. if (len % sizeof(struct mpeg_flex_mux))
  56. return NULL;
  57. while(pos < len) {
  58. bswap16(buf+pos);
  59. pos += sizeof(struct mpeg_flex_mux);
  60. }
  61. return (struct mpeg_fmc_descriptor*) d;
  62. }
  63. /**
  64. * Convenience iterator for the muxes field of an mpeg_fmc_descriptor structure.
  65. *
  66. * @param d Generic descriptor structure.
  67. * @param pos Variable holding a pointer to the the current entry within the muxes field.
  68. */
  69. #define mpeg_fmc_descriptor_muxes_for_each(d, pos) \
  70. for ((pos) = mpeg_fmc_descriptor_muxes_first(d); \
  71. (pos); \
  72. (pos) = mpeg_fmc_descriptor_muxes_next(d, pos))
  73. /******************************** PRIVATE CODE ********************************/
  74. static inline struct mpeg_flex_mux*
  75. mpeg_fmc_descriptor_muxes_first(struct mpeg_fmc_descriptor *d)
  76. {
  77. if (d->d.len < sizeof(struct mpeg_flex_mux))
  78. return NULL;
  79. return (struct mpeg_flex_mux *)
  80. ((uint8_t*) d + sizeof(struct mpeg_fmc_descriptor));
  81. }
  82. static inline struct mpeg_flex_mux*
  83. mpeg_fmc_descriptor_muxes_next(struct mpeg_fmc_descriptor *d,
  84. struct mpeg_flex_mux *pos)
  85. {
  86. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  87. uint8_t *next = (uint8_t *) pos + sizeof(struct mpeg_flex_mux);
  88. if (next >= end)
  89. return NULL;
  90. return (struct mpeg_flex_mux *) next;
  91. }
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif