rnt_rnt_scan_descriptor.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_RNT_RNT_SCAN_DESCRIPTOR
  22. #define _UCSI_DVB_RNT_RNT_SCAN_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_rnt_rnt_scan_descriptor structure.
  32. */
  33. struct dvb_rnt_rnt_scan_descriptor {
  34. struct descriptor d;
  35. /* struct dvb_rnt_rnt_scan_entry entries[] */
  36. } __ucsi_packed;
  37. /**
  38. * An entry in the entries field of a dvb_rnt_rnt_scan_descriptor.
  39. */
  40. struct dvb_rnt_rnt_scan_entry {
  41. uint16_t transport_stream_id;
  42. uint16_t original_network_id;
  43. uint8_t scan_weighting;
  44. } __ucsi_packed;
  45. /**
  46. * Process a dvb_rnt_rnt_scan_descriptor.
  47. *
  48. * @param d Generic descriptor.
  49. * @return dvb_rnt_rnt_scan_descriptor pointer, or NULL on error.
  50. */
  51. static inline struct dvb_rnt_rnt_scan_descriptor*
  52. dvb_rnt_rnt_scan_descriptor_codec(struct descriptor* d)
  53. {
  54. uint8_t *buf = (uint8_t*) d;
  55. uint32_t len = d->len +2;
  56. uint32_t pos = 2;
  57. if ((len-2) % sizeof(struct dvb_rnt_rnt_scan_entry))
  58. return NULL;
  59. while(pos < len) {
  60. bswap16(buf+pos);
  61. bswap16(buf+pos+2);
  62. pos += sizeof(struct dvb_rnt_rnt_scan_entry);
  63. }
  64. return (struct dvb_rnt_rnt_scan_descriptor*) d;
  65. }
  66. /**
  67. * Iterator for entries field of a dvb_rnt_rnt_scan_descriptor.
  68. *
  69. * @param d dvb_rnt_rnt_scan_descriptor pointer.
  70. * @param pos Variable holding a pointer to the current dvb_rnt_rnt_scan_entry.
  71. */
  72. #define dvb_rnt_rnt_scan_descriptor_entries_for_each(d, pos) \
  73. for ((pos) = dvb_rnt_rnt_scan_descriptor_entries_first(d); \
  74. (pos); \
  75. (pos) = dvb_rnt_rnt_scan_descriptor_entries_next(d, pos))
  76. /******************************** PRIVATE CODE ********************************/
  77. static inline struct dvb_rnt_rnt_scan_entry*
  78. dvb_rnt_rnt_scan_descriptor_entries_first(struct dvb_rnt_rnt_scan_descriptor *d)
  79. {
  80. if (d->d.len == 0)
  81. return NULL;
  82. return (struct dvb_rnt_rnt_scan_entry *)
  83. ((uint8_t*) d + sizeof(struct dvb_rnt_rnt_scan_descriptor));
  84. }
  85. static inline struct dvb_rnt_rnt_scan_entry*
  86. dvb_rnt_rnt_scan_descriptor_entries_next(struct dvb_rnt_rnt_scan_descriptor *d,
  87. struct dvb_rnt_rnt_scan_entry *pos)
  88. {
  89. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  90. uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_rnt_rnt_scan_entry);
  91. if (next >= end)
  92. return NULL;
  93. return (struct dvb_rnt_rnt_scan_entry *) next;
  94. }
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif