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.

230 lines
6.6KB

  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. #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_CAMAERA_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 MPEG2RawPictureHeader {
  98. uint8_t picture_start_code;
  99. uint16_t temporal_reference;
  100. uint8_t picture_coding_type;
  101. uint16_t vbv_delay;
  102. uint8_t full_pel_forward_vector;
  103. uint8_t forward_f_code;
  104. uint8_t full_pel_backward_vector;
  105. uint8_t backward_f_code;
  106. uint8_t extra_bit_picture;
  107. } MPEG2RawPictureHeader;
  108. typedef struct MPEG2RawPictureCodingExtension {
  109. uint8_t f_code[2][2];
  110. uint8_t intra_dc_precision;
  111. uint8_t picture_structure;
  112. uint8_t top_field_first;
  113. uint8_t frame_pred_frame_dct;
  114. uint8_t concealment_motion_vectors;
  115. uint8_t q_scale_type;
  116. uint8_t intra_vlc_format;
  117. uint8_t alternate_scan;
  118. uint8_t repeat_first_field;
  119. uint8_t chroma_420_type;
  120. uint8_t progressive_frame;
  121. uint8_t composite_display_flag;
  122. uint8_t v_axis;
  123. uint8_t field_sequence;
  124. uint8_t sub_carrier;
  125. uint8_t burst_amplitude;
  126. uint8_t sub_carrier_phase;
  127. } MPEG2RawPictureCodingExtension;
  128. typedef struct MPEG2RawQuantMatrixExtension {
  129. uint8_t load_intra_quantiser_matrix;
  130. uint8_t intra_quantiser_matrix[64];
  131. uint8_t load_non_intra_quantiser_matrix;
  132. uint8_t non_intra_quantiser_matrix[64];
  133. uint8_t load_chroma_intra_quantiser_matrix;
  134. uint8_t chroma_intra_quantiser_matrix[64];
  135. uint8_t load_chroma_non_intra_quantiser_matrix;
  136. uint8_t chroma_non_intra_quantiser_matrix[64];
  137. } MPEG2RawQuantMatrixExtension;
  138. typedef struct MPEG2RawPictureDisplayExtension {
  139. uint16_t frame_centre_horizontal_offset[3];
  140. uint16_t frame_centre_vertical_offset[3];
  141. } MPEG2RawPictureDisplayExtension;
  142. typedef struct MPEG2RawExtensionData {
  143. uint8_t extension_start_code;
  144. uint8_t extension_start_code_identifier;
  145. union {
  146. MPEG2RawSequenceExtension sequence;
  147. MPEG2RawSequenceDisplayExtension sequence_display;
  148. MPEG2RawQuantMatrixExtension quant_matrix;
  149. MPEG2RawPictureCodingExtension picture_coding;
  150. MPEG2RawPictureDisplayExtension picture_display;
  151. } data;
  152. } MPEG2RawExtensionData;
  153. typedef struct MPEG2RawSliceHeader {
  154. uint8_t slice_vertical_position;
  155. uint8_t slice_vertical_position_extension;
  156. uint8_t priority_breakpoint;
  157. uint8_t quantiser_scale_code;
  158. uint8_t slice_extension_flag;
  159. uint8_t intra_slice;
  160. uint8_t slice_picture_id_enable;
  161. uint8_t slice_picture_id;
  162. uint8_t extra_bit_slice;
  163. size_t extra_information_length;
  164. uint8_t *extra_information;
  165. AVBufferRef *extra_information_ref;
  166. } MPEG2RawSliceHeader;
  167. typedef struct MPEG2RawSlice {
  168. MPEG2RawSliceHeader header;
  169. uint8_t *data;
  170. size_t data_size;
  171. int data_bit_start;
  172. AVBufferRef *data_ref;
  173. } MPEG2RawSlice;
  174. typedef struct CodedBitstreamMPEG2Context {
  175. // Elements stored in headers which are required for other decoding.
  176. uint16_t horizontal_size;
  177. uint16_t vertical_size;
  178. uint8_t scalable;
  179. uint8_t scalable_mode;
  180. uint8_t progressive_sequence;
  181. uint8_t number_of_frame_centre_offsets;
  182. // Write buffer.
  183. uint8_t *write_buffer;
  184. size_t write_buffer_size;
  185. } CodedBitstreamMPEG2Context;
  186. #endif /* AVCODEC_CBS_MPEG2_H */