s2_satellite_delivery_descriptor.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_S2_SATELLITE_DELIVERY_DESCRIPTOR
  22. #define _UCSI_DVB_S2_SATELLITE_DELIVERY_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. /**
  30. * dvb_s2_satellite_delivery_descriptor structure.
  31. */
  32. struct dvb_s2_satellite_delivery_descriptor {
  33. struct descriptor d;
  34. EBIT4(uint8_t scrambling_sequence_selector : 1; ,
  35. uint8_t multiple_input_stream : 1; ,
  36. uint8_t backwards_compatability : 1; ,
  37. uint8_t reserved : 5; );
  38. /* uint32_t scrambling_sequence_index if scrambling_sequence_selector = 1 */
  39. /* uint8_t input_stream_id if multiple_input_stream = 1 */
  40. } __ucsi_packed;
  41. /**
  42. * Process a dvb_s2_satellite_delivery_descriptor.
  43. *
  44. * @param d Pointer to a generic descriptor structure.
  45. * @return dvb_s2_satellite_delivery_descriptor pointer, or NULL on error.
  46. */
  47. static inline struct dvb_s2_satellite_delivery_descriptor*
  48. dvb_s2_satellite_delivery_descriptor_codec(struct descriptor* d)
  49. {
  50. struct dvb_s2_satellite_delivery_descriptor *s2 =
  51. (struct dvb_s2_satellite_delivery_descriptor*) d;
  52. if (d->len < (sizeof(struct dvb_s2_satellite_delivery_descriptor) - 2))
  53. return NULL;
  54. int len = sizeof(struct dvb_s2_satellite_delivery_descriptor);
  55. if (s2->scrambling_sequence_selector) {
  56. len += 3;
  57. }
  58. if (s2->multiple_input_stream) {
  59. len += 1;
  60. }
  61. if (d->len < len)
  62. return NULL;
  63. return s2;
  64. }
  65. /**
  66. * Accessor for the scrambling_sequence_index field of a dvb_s2_satellite_delivery_descriptor.
  67. *
  68. * @param s2 dvb_s2_satellite_delivery_descriptor pointer.
  69. * @return The scrambling_sequence_index.
  70. */
  71. static inline uint32_t dvb_s2_satellite_delivery_descriptor_scrambling_sequence_index(struct dvb_s2_satellite_delivery_descriptor *s2)
  72. {
  73. uint8_t *tmp = (uint8_t*) s2;
  74. if (s2->scrambling_sequence_selector) {
  75. return ((tmp[4] & 0x03) << 16) | (tmp[5] << 8) | tmp[6];
  76. }
  77. return 0;
  78. }
  79. /**
  80. * Accessor for the input_stream_id field of a dvb_s2_satellite_delivery_descriptor.
  81. *
  82. * @param s2 dvb_s2_satellite_delivery_descriptor pointer.
  83. * @return The input_stream_id.
  84. */
  85. static inline uint8_t dvb_s2_satellite_delivery_descriptor_input_stream_id(struct dvb_s2_satellite_delivery_descriptor *s2)
  86. {
  87. uint8_t *tmp = (uint8_t*) s2;
  88. if (!s2->multiple_input_stream)
  89. return 0;
  90. int off = 3;
  91. if (s2->scrambling_sequence_selector) {
  92. off += 3;
  93. }
  94. return tmp[off];
  95. }
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif