service_availability_descriptor.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_SERVICE_AVAILABILITY_DESCRIPTOR
  22. #define _UCSI_DVB_SERVICE_AVAILABILITY_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. /**
  30. * dvb_service_availability_descriptor structure.
  31. */
  32. struct dvb_service_availability_descriptor {
  33. struct descriptor d;
  34. EBIT2(uint8_t availability_flag : 1; ,
  35. uint8_t reserved : 7; );
  36. /* uint16_t cell_ids[] */
  37. } __ucsi_packed;
  38. /**
  39. * Process a dvb_service_availability_descriptor.
  40. *
  41. * @param d Pointer to a generic descriptor structure.
  42. * @return dvb_service_availability_descriptor pointer, or NULL on error.
  43. */
  44. static inline struct dvb_service_availability_descriptor*
  45. dvb_service_availability_descriptor_codec(struct descriptor* d)
  46. {
  47. uint32_t pos = 0;
  48. uint8_t* buf = (uint8_t*) d + 2;
  49. uint32_t len = d->len;
  50. pos += sizeof(struct dvb_service_availability_descriptor) - 2;
  51. if ((len - pos) % 2)
  52. return NULL;
  53. while(pos < len) {
  54. bswap16(buf+pos);
  55. pos += 2;
  56. }
  57. return (struct dvb_service_availability_descriptor*) d;
  58. }
  59. /**
  60. * Accessor for the cell_ids field of a dvb_service_availability_descriptor.
  61. *
  62. * @param d dvb_service_availability_descriptor pointer.
  63. * @return Pointer to the field.
  64. */
  65. static inline uint16_t *
  66. dvb_service_availability_descriptor_cell_ids(struct dvb_service_availability_descriptor *d)
  67. {
  68. return (uint16_t *) ((uint8_t *) d + sizeof(struct dvb_service_availability_descriptor));
  69. }
  70. /**
  71. * Determine the number of entries in the cell_ids field of a dvb_service_availability_descriptor.
  72. *
  73. * @param d dvb_service_availability_descriptor pointer.
  74. * @return The number of entries.
  75. */
  76. static inline int
  77. dvb_service_availability_descriptor_cell_ids_count(struct dvb_service_availability_descriptor *d)
  78. {
  79. return (d->d.len - 1) >> 1;
  80. }
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif