frequency_list_descriptor.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_FREQUENCY_LIST_DESCRIPTOR
  22. #define _UCSI_DVB_FREQUENCY_LIST_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. /**
  30. * Possible values for coding_type.
  31. */
  32. enum {
  33. DVB_CODING_TYPE_SATELLITE = 0x01,
  34. DVB_CODING_TYPE_CABLE = 0x02,
  35. DVB_CODING_TYPE_TERRESTRIAL = 0x03,
  36. };
  37. /**
  38. * dvb_frequency_list_descriptor structure.
  39. */
  40. struct dvb_frequency_list_descriptor {
  41. struct descriptor d;
  42. EBIT2(uint8_t reserved : 6; ,
  43. uint8_t coding_type : 2; );
  44. /* uint32_t centre_frequencies [] */
  45. } __ucsi_packed;
  46. /**
  47. * Process a dvb_frequency_list_descriptor.
  48. *
  49. * @param d Pointer to a generic descriptor structure.
  50. * @return dvb_frequency_list_descriptor pointer, or NULL on error.
  51. */
  52. static inline struct dvb_frequency_list_descriptor*
  53. dvb_frequency_list_descriptor_codec(struct descriptor* d)
  54. {
  55. uint32_t pos = 0;
  56. uint8_t* buf = (uint8_t*) d + 2;
  57. uint32_t len = d->len;
  58. pos += sizeof(struct dvb_frequency_list_descriptor) - 2;
  59. if ((len - pos) % 4)
  60. return NULL;
  61. while(pos < len) {
  62. bswap32(buf+pos);
  63. pos += 4;
  64. }
  65. return (struct dvb_frequency_list_descriptor*) d;
  66. }
  67. /**
  68. * Accessor for the centre_frequencies field of a dvb_frequency_list_descriptor.
  69. *
  70. * @param d dvb_frequency_list_descriptor pointer.
  71. * @return Pointer to the field.
  72. */
  73. static inline uint32_t *
  74. dvb_frequency_list_descriptor_centre_frequencies(struct dvb_frequency_list_descriptor *d)
  75. {
  76. return (uint32_t *) ((uint8_t *) d + sizeof(struct dvb_frequency_list_descriptor));
  77. }
  78. /**
  79. * Determine the number of entries in the centre_frequencies field of a dvb_frequency_list_descriptor.
  80. *
  81. * @param d dvb_frequency_list_descriptor pointer.
  82. * @return The number of entries.
  83. */
  84. static inline int
  85. dvb_frequency_list_descriptor_centre_frequencies_count(struct dvb_frequency_list_descriptor *d)
  86. {
  87. return (d->d.len - 1) >> 2;
  88. }
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif