video_stream_descriptor.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_VIDEO_STREAM_DESCRIPTOR
  22. #define _UCSI_MPEG_VIDEO_STREAM_DESCRIPTOR 1
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #include <libucsi/descriptor.h>
  28. #include <libucsi/endianops.h>
  29. /**
  30. * The mpeg_video_stream_descriptor structure
  31. */
  32. struct mpeg_video_stream_descriptor {
  33. struct descriptor d;
  34. EBIT5(uint8_t multiple_frame_rate_flag : 1; ,
  35. uint8_t frame_rate_code : 4; ,
  36. uint8_t mpeg_1_only_flag : 1; ,
  37. uint8_t constrained_parameter_flag : 1; ,
  38. uint8_t still_picture_flag : 1; );
  39. /* if (mpeg_1_only_flag == 0) struct mpeg_video_stream_extra extra */
  40. } __ucsi_packed;
  41. /**
  42. * The mpeg_video_stream_extra - only present in non-MPEG1-only streams.
  43. */
  44. struct mpeg_video_stream_extra {
  45. uint8_t profile_and_level_indication;
  46. EBIT3(uint8_t chroma_format : 2; ,
  47. uint8_t frame_rate_extension : 1; ,
  48. uint8_t reserved : 5; );
  49. } __ucsi_packed;
  50. /**
  51. * Process an mpeg_video_stream_descriptor structure.
  52. *
  53. * @param d Pointer to the generic descriptor structure.
  54. * @return Pointer to the mpeg_video_stream_descriptor, or NULL on error.
  55. */
  56. static inline struct mpeg_video_stream_descriptor*
  57. mpeg_video_stream_descriptor_codec(struct descriptor* d)
  58. {
  59. struct mpeg_video_stream_descriptor* vsd =
  60. (struct mpeg_video_stream_descriptor*) d;
  61. if (d->len < (sizeof(struct mpeg_video_stream_descriptor) - 2))
  62. return NULL;
  63. if (!vsd->mpeg_1_only_flag) {
  64. if (d->len != (sizeof(struct mpeg_video_stream_descriptor) +
  65. sizeof(struct mpeg_video_stream_extra) - 2))
  66. return NULL;
  67. }
  68. return (struct mpeg_video_stream_descriptor*) d;
  69. }
  70. /**
  71. * Get a pointer to the mpeg_video_stream_extra structure.
  72. *
  73. * @param d Pointer to the mpeg_video_stream_descriptor structure.
  74. * @return Pointer to the mpeg_video_stream_extra structure, or NULL on error.
  75. */
  76. static inline struct mpeg_video_stream_extra*
  77. mpeg_video_stream_descriptor_extra(struct mpeg_video_stream_descriptor* d)
  78. {
  79. if (d->mpeg_1_only_flag != 0)
  80. return NULL;
  81. return (struct mpeg_video_stream_extra*)
  82. ((uint8_t*) d + sizeof(struct mpeg_video_stream_descriptor));
  83. }
  84. #ifdef __cplusplus
  85. }
  86. #endif
  87. #endif