cbs_mpeg2.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVCODEC_CBS_MPEG2_H
  19. #define AVCODEC_CBS_MPEG2_H
  20. #include <stddef.h>
  21. #include <stdint.h>
  22. #include "libavutil/buffer.h"
  23. enum {
  24. MPEG2_START_PICTURE = 0x00,
  25. MPEG2_START_SLICE_MIN = 0x01,
  26. MPEG2_START_SLICE_MAX = 0xaf,
  27. MPEG2_START_USER_DATA = 0xb2,
  28. MPEG2_START_SEQUENCE_HEADER = 0xb3,
  29. MPEG2_START_SEQUENCE_ERROR = 0xb4,
  30. MPEG2_START_EXTENSION = 0xb5,
  31. MPEG2_START_SEQUENCE_END = 0xb7,
  32. MPEG2_START_GROUP = 0xb8,
  33. };
  34. #define MPEG2_START_IS_SLICE(type) \
  35. ((type) >= MPEG2_START_SLICE_MIN && \
  36. (type) <= MPEG2_START_SLICE_MAX)
  37. enum {
  38. MPEG2_EXTENSION_SEQUENCE = 0x1,
  39. MPEG2_EXTENSION_SEQUENCE_DISPLAY = 0x2,
  40. MPEG2_EXTENSION_QUANT_MATRIX = 0x3,
  41. MPEG2_EXTENSION_COPYRIGHT = 0x4,
  42. MPEG2_EXTENSION_SEQUENCE_SCALABLE = 0x5,
  43. MPEG2_EXTENSION_PICTURE_DISPLAY = 0x7,
  44. MPEG2_EXTENSION_PICTURE_CODING = 0x8,
  45. MPEG2_EXTENSION_PICTURE_SPATIAL_SCALABLE = 0x9,
  46. MPEG2_EXTENSION_PICTURE_TEMPORAL_SCALABLE = 0xa,
  47. MPEG2_EXTENSION_CAMERA_PARAMETERS = 0xb,
  48. MPEG2_EXTENSION_ITU_T = 0xc,
  49. };
  50. typedef struct MPEG2RawSequenceHeader {
  51. uint8_t sequence_header_code;
  52. uint16_t horizontal_size_value;
  53. uint16_t vertical_size_value;
  54. uint8_t aspect_ratio_information;
  55. uint8_t frame_rate_code;
  56. uint32_t bit_rate_value;
  57. uint16_t vbv_buffer_size_value;
  58. uint8_t constrained_parameters_flag;
  59. uint8_t load_intra_quantiser_matrix;
  60. uint8_t intra_quantiser_matrix[64];
  61. uint8_t load_non_intra_quantiser_matrix;
  62. uint8_t non_intra_quantiser_matrix[64];
  63. } MPEG2RawSequenceHeader;
  64. typedef struct MPEG2RawUserData {
  65. uint8_t user_data_start_code;
  66. uint8_t *user_data;
  67. size_t user_data_length;
  68. AVBufferRef *user_data_ref;
  69. } MPEG2RawUserData;
  70. typedef struct MPEG2RawSequenceExtension {
  71. uint8_t profile_and_level_indication;
  72. uint8_t progressive_sequence;
  73. uint8_t chroma_format;
  74. uint8_t horizontal_size_extension;
  75. uint8_t vertical_size_extension;
  76. uint16_t bit_rate_extension;
  77. uint8_t vbv_buffer_size_extension;
  78. uint8_t low_delay;
  79. uint8_t frame_rate_extension_n;
  80. uint8_t frame_rate_extension_d;
  81. } MPEG2RawSequenceExtension;
  82. typedef struct MPEG2RawSequenceDisplayExtension {
  83. uint8_t video_format;
  84. uint8_t colour_description;
  85. uint8_t colour_primaries;
  86. uint8_t transfer_characteristics;
  87. uint8_t matrix_coefficients;
  88. uint16_t display_horizontal_size;
  89. uint16_t display_vertical_size;
  90. } MPEG2RawSequenceDisplayExtension;
  91. typedef struct MPEG2RawGroupOfPicturesHeader {
  92. uint8_t group_start_code;
  93. uint32_t time_code;
  94. uint8_t closed_gop;
  95. uint8_t broken_link;
  96. } MPEG2RawGroupOfPicturesHeader;
  97. typedef struct MPEG2RawExtraInformation {
  98. uint8_t *extra_information;
  99. AVBufferRef *extra_information_ref;
  100. size_t extra_information_length;
  101. } MPEG2RawExtraInformation;
  102. typedef struct MPEG2RawPictureHeader {
  103. uint8_t picture_start_code;
  104. uint16_t temporal_reference;
  105. uint8_t picture_coding_type;
  106. uint16_t vbv_delay;
  107. uint8_t full_pel_forward_vector;
  108. uint8_t forward_f_code;
  109. uint8_t full_pel_backward_vector;
  110. uint8_t backward_f_code;
  111. MPEG2RawExtraInformation extra_information_picture;
  112. } MPEG2RawPictureHeader;
  113. typedef struct MPEG2RawPictureCodingExtension {
  114. uint8_t f_code[2][2];
  115. uint8_t intra_dc_precision;
  116. uint8_t picture_structure;
  117. uint8_t top_field_first;
  118. uint8_t frame_pred_frame_dct;
  119. uint8_t concealment_motion_vectors;
  120. uint8_t q_scale_type;
  121. uint8_t intra_vlc_format;
  122. uint8_t alternate_scan;
  123. uint8_t repeat_first_field;
  124. uint8_t chroma_420_type;
  125. uint8_t progressive_frame;
  126. uint8_t composite_display_flag;
  127. uint8_t v_axis;
  128. uint8_t field_sequence;
  129. uint8_t sub_carrier;
  130. uint8_t burst_amplitude;
  131. uint8_t sub_carrier_phase;
  132. } MPEG2RawPictureCodingExtension;
  133. typedef struct MPEG2RawQuantMatrixExtension {
  134. uint8_t load_intra_quantiser_matrix;
  135. uint8_t intra_quantiser_matrix[64];
  136. uint8_t load_non_intra_quantiser_matrix;
  137. uint8_t non_intra_quantiser_matrix[64];
  138. uint8_t load_chroma_intra_quantiser_matrix;
  139. uint8_t chroma_intra_quantiser_matrix[64];
  140. uint8_t load_chroma_non_intra_quantiser_matrix;
  141. uint8_t chroma_non_intra_quantiser_matrix[64];
  142. } MPEG2RawQuantMatrixExtension;
  143. typedef struct MPEG2RawPictureDisplayExtension {
  144. int16_t frame_centre_horizontal_offset[3];
  145. int16_t frame_centre_vertical_offset[3];
  146. } MPEG2RawPictureDisplayExtension;
  147. typedef struct MPEG2RawExtensionData {
  148. uint8_t extension_start_code;
  149. uint8_t extension_start_code_identifier;
  150. union {
  151. MPEG2RawSequenceExtension sequence;
  152. MPEG2RawSequenceDisplayExtension sequence_display;
  153. MPEG2RawQuantMatrixExtension quant_matrix;
  154. MPEG2RawPictureCodingExtension picture_coding;
  155. MPEG2RawPictureDisplayExtension picture_display;
  156. } data;
  157. } MPEG2RawExtensionData;
  158. typedef struct MPEG2RawSliceHeader {
  159. uint8_t slice_vertical_position;
  160. uint8_t slice_vertical_position_extension;
  161. uint8_t priority_breakpoint;
  162. uint8_t quantiser_scale_code;
  163. uint8_t slice_extension_flag;
  164. uint8_t intra_slice;
  165. uint8_t slice_picture_id_enable;
  166. uint8_t slice_picture_id;
  167. MPEG2RawExtraInformation extra_information_slice;
  168. } MPEG2RawSliceHeader;
  169. typedef struct MPEG2RawSlice {
  170. MPEG2RawSliceHeader header;
  171. uint8_t *data;
  172. size_t data_size;
  173. int data_bit_start;
  174. AVBufferRef *data_ref;
  175. } MPEG2RawSlice;
  176. typedef struct MPEG2RawSequenceEnd {
  177. uint8_t sequence_end_code;
  178. } MPEG2RawSequenceEnd;
  179. typedef struct CodedBitstreamMPEG2Context {
  180. // Elements stored in headers which are required for other decoding.
  181. uint16_t horizontal_size;
  182. uint16_t vertical_size;
  183. uint8_t scalable;
  184. uint8_t scalable_mode;
  185. uint8_t progressive_sequence;
  186. uint8_t number_of_frame_centre_offsets;
  187. } CodedBitstreamMPEG2Context;
  188. #endif /* AVCODEC_CBS_MPEG2_H */