You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

225 lines
6.5KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav 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. * Libav 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 Libav; 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. enum {
  23. MPEG2_START_PICTURE = 0x00,
  24. MPEG2_START_SLICE_MIN = 0x01,
  25. MPEG2_START_SLICE_MAX = 0xaf,
  26. MPEG2_START_USER_DATA = 0xb2,
  27. MPEG2_START_SEQUENCE_HEADER = 0xb3,
  28. MPEG2_START_SEQUENCE_ERROR = 0xb4,
  29. MPEG2_START_EXTENSION = 0xb5,
  30. MPEG2_START_SEQUENCE_END = 0xb7,
  31. MPEG2_START_GROUP = 0xb8,
  32. };
  33. #define MPEG2_START_IS_SLICE(type) \
  34. ((type) >= MPEG2_START_SLICE_MIN && \
  35. (type) <= MPEG2_START_SLICE_MAX)
  36. enum {
  37. MPEG2_EXTENSION_SEQUENCE = 0x1,
  38. MPEG2_EXTENSION_SEQUENCE_DISPLAY = 0x2,
  39. MPEG2_EXTENSION_QUANT_MATRIX = 0x3,
  40. MPEG2_EXTENSION_COPYRIGHT = 0x4,
  41. MPEG2_EXTENSION_SEQUENCE_SCALABLE = 0x5,
  42. MPEG2_EXTENSION_PICTURE_DISPLAY = 0x7,
  43. MPEG2_EXTENSION_PICTURE_CODING = 0x8,
  44. MPEG2_EXTENSION_PICTURE_SPATIAL_SCALABLE = 0x9,
  45. MPEG2_EXTENSION_PICTURE_TEMPORAL_SCALABLE = 0xa,
  46. MPEG2_EXTENSION_CAMAERA_PARAMETERS = 0xb,
  47. MPEG2_EXTENSION_ITU_T = 0xc,
  48. };
  49. typedef struct MPEG2RawSequenceHeader {
  50. uint8_t sequence_header_code;
  51. uint16_t horizontal_size_value;
  52. uint16_t vertical_size_value;
  53. uint8_t aspect_ratio_information;
  54. uint8_t frame_rate_code;
  55. uint32_t bit_rate_value;
  56. uint16_t vbv_buffer_size_value;
  57. uint8_t constrained_parameters_flag;
  58. uint8_t load_intra_quantiser_matrix;
  59. uint8_t intra_quantiser_matrix[64];
  60. uint8_t load_non_intra_quantiser_matrix;
  61. uint8_t non_intra_quantiser_matrix[64];
  62. } MPEG2RawSequenceHeader;
  63. typedef struct MPEG2RawUserData {
  64. uint8_t user_data_start_code;
  65. uint8_t *user_data;
  66. size_t user_data_length;
  67. } MPEG2RawUserData;
  68. typedef struct MPEG2RawSequenceExtension {
  69. uint8_t profile_and_level_indication;
  70. uint8_t progressive_sequence;
  71. uint8_t chroma_format;
  72. uint8_t horizontal_size_extension;
  73. uint8_t vertical_size_extension;
  74. uint16_t bit_rate_extension;
  75. uint8_t vbv_buffer_size_extension;
  76. uint8_t low_delay;
  77. uint8_t frame_rate_extension_n;
  78. uint8_t frame_rate_extension_d;
  79. } MPEG2RawSequenceExtension;
  80. typedef struct MPEG2RawSequenceDisplayExtension {
  81. uint8_t video_format;
  82. uint8_t colour_description;
  83. uint8_t colour_primaries;
  84. uint8_t transfer_characteristics;
  85. uint8_t matrix_coefficients;
  86. uint16_t display_horizontal_size;
  87. uint16_t display_vertical_size;
  88. } MPEG2RawSequenceDisplayExtension;
  89. typedef struct MPEG2RawGroupOfPicturesHeader {
  90. uint8_t group_start_code;
  91. uint32_t time_code;
  92. uint8_t closed_gop;
  93. uint8_t broken_link;
  94. } MPEG2RawGroupOfPicturesHeader;
  95. typedef struct MPEG2RawPictureHeader {
  96. uint8_t picture_start_code;
  97. uint16_t temporal_reference;
  98. uint8_t picture_coding_type;
  99. uint16_t vbv_delay;
  100. uint8_t full_pel_forward_vector;
  101. uint8_t forward_f_code;
  102. uint8_t full_pel_backward_vector;
  103. uint8_t backward_f_code;
  104. uint8_t extra_bit_picture;
  105. } MPEG2RawPictureHeader;
  106. typedef struct MPEG2RawPictureCodingExtension {
  107. uint8_t f_code[2][2];
  108. uint8_t intra_dc_precision;
  109. uint8_t picture_structure;
  110. uint8_t top_field_first;
  111. uint8_t frame_pred_frame_dct;
  112. uint8_t concealment_motion_vectors;
  113. uint8_t q_scale_type;
  114. uint8_t intra_vlc_format;
  115. uint8_t alternate_scan;
  116. uint8_t repeat_first_field;
  117. uint8_t chroma_420_type;
  118. uint8_t progressive_frame;
  119. uint8_t composite_display_flag;
  120. uint8_t v_axis;
  121. uint8_t field_sequence;
  122. uint8_t sub_carrier;
  123. uint8_t burst_amplitude;
  124. uint8_t sub_carrier_phase;
  125. } MPEG2RawPictureCodingExtension;
  126. typedef struct MPEG2RawQuantMatrixExtension {
  127. uint8_t load_intra_quantiser_matrix;
  128. uint8_t intra_quantiser_matrix[64];
  129. uint8_t load_non_intra_quantiser_matrix;
  130. uint8_t non_intra_quantiser_matrix[64];
  131. uint8_t load_chroma_intra_quantiser_matrix;
  132. uint8_t chroma_intra_quantiser_matrix[64];
  133. uint8_t load_chroma_non_intra_quantiser_matrix;
  134. uint8_t chroma_non_intra_quantiser_matrix[64];
  135. } MPEG2RawQuantMatrixExtension;
  136. typedef struct MPEG2RawPictureDisplayExtension {
  137. uint16_t frame_centre_horizontal_offset[3];
  138. uint16_t frame_centre_vertical_offset[3];
  139. } MPEG2RawPictureDisplayExtension;
  140. typedef struct MPEG2RawExtensionData {
  141. uint8_t extension_start_code;
  142. uint8_t extension_start_code_identifier;
  143. union {
  144. MPEG2RawSequenceExtension sequence;
  145. MPEG2RawSequenceDisplayExtension sequence_display;
  146. MPEG2RawQuantMatrixExtension quant_matrix;
  147. MPEG2RawPictureCodingExtension picture_coding;
  148. MPEG2RawPictureDisplayExtension picture_display;
  149. } data;
  150. } MPEG2RawExtensionData;
  151. typedef struct MPEG2RawSliceHeader {
  152. uint8_t slice_vertical_position;
  153. uint8_t slice_vertical_position_extension;
  154. uint8_t priority_breakpoint;
  155. uint8_t quantiser_scale_code;
  156. uint8_t slice_extension_flag;
  157. uint8_t intra_slice;
  158. uint8_t slice_picture_id_enable;
  159. uint8_t slice_picture_id;
  160. uint8_t extra_bit_slice;
  161. size_t extra_information_length;
  162. uint8_t *extra_information;
  163. } MPEG2RawSliceHeader;
  164. typedef struct MPEG2RawSlice {
  165. MPEG2RawSliceHeader header;
  166. uint8_t *data;
  167. size_t data_size;
  168. int data_bit_start;
  169. } MPEG2RawSlice;
  170. typedef struct CodedBitstreamMPEG2Context {
  171. // Elements stored in headers which are required for other decoding.
  172. uint16_t horizontal_size;
  173. uint16_t vertical_size;
  174. uint8_t scalable;
  175. uint8_t scalable_mode;
  176. uint8_t progressive_sequence;
  177. uint8_t number_of_frame_centre_offsets;
  178. // Write buffer.
  179. uint8_t *write_buffer;
  180. size_t write_buffer_size;
  181. } CodedBitstreamMPEG2Context;
  182. #endif /* AVCODEC_CBS_MPEG2_H */