cbs_mpeg2.h 6.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef AVCODEC_CBS_MPEG2_H
#define AVCODEC_CBS_MPEG2_H

#include <stddef.h>
#include <stdint.h>

25 26
#include "libavutil/buffer.h"

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

enum {
    MPEG2_START_PICTURE         = 0x00,
    MPEG2_START_SLICE_MIN       = 0x01,
    MPEG2_START_SLICE_MAX       = 0xaf,
    MPEG2_START_USER_DATA       = 0xb2,
    MPEG2_START_SEQUENCE_HEADER = 0xb3,
    MPEG2_START_SEQUENCE_ERROR  = 0xb4,
    MPEG2_START_EXTENSION       = 0xb5,
    MPEG2_START_SEQUENCE_END    = 0xb7,
    MPEG2_START_GROUP           = 0xb8,
};

#define MPEG2_START_IS_SLICE(type) \
    ((type) >= MPEG2_START_SLICE_MIN && \
     (type) <= MPEG2_START_SLICE_MAX)

enum {
    MPEG2_EXTENSION_SEQUENCE                  = 0x1,
    MPEG2_EXTENSION_SEQUENCE_DISPLAY          = 0x2,
    MPEG2_EXTENSION_QUANT_MATRIX              = 0x3,
    MPEG2_EXTENSION_COPYRIGHT                 = 0x4,
    MPEG2_EXTENSION_SEQUENCE_SCALABLE         = 0x5,
    MPEG2_EXTENSION_PICTURE_DISPLAY           = 0x7,
    MPEG2_EXTENSION_PICTURE_CODING            = 0x8,
    MPEG2_EXTENSION_PICTURE_SPATIAL_SCALABLE  = 0x9,
    MPEG2_EXTENSION_PICTURE_TEMPORAL_SCALABLE = 0xa,
54
    MPEG2_EXTENSION_CAMERA_PARAMETERS         = 0xb,
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    MPEG2_EXTENSION_ITU_T                     = 0xc,
};


typedef struct MPEG2RawSequenceHeader {
    uint8_t sequence_header_code;

    uint16_t horizontal_size_value;
    uint16_t vertical_size_value;
    uint8_t aspect_ratio_information;
    uint8_t frame_rate_code;
    uint32_t bit_rate_value;
    uint16_t vbv_buffer_size_value;
    uint8_t constrained_parameters_flag;

    uint8_t load_intra_quantiser_matrix;
    uint8_t intra_quantiser_matrix[64];
    uint8_t load_non_intra_quantiser_matrix;
    uint8_t non_intra_quantiser_matrix[64];
} MPEG2RawSequenceHeader;

typedef struct MPEG2RawUserData {
    uint8_t user_data_start_code;

    uint8_t *user_data;
    size_t user_data_length;
81
    AVBufferRef *user_data_ref;
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
} MPEG2RawUserData;

typedef struct MPEG2RawSequenceExtension {
    uint8_t profile_and_level_indication;
    uint8_t progressive_sequence;
    uint8_t chroma_format;
    uint8_t horizontal_size_extension;
    uint8_t vertical_size_extension;
    uint16_t bit_rate_extension;
    uint8_t vbv_buffer_size_extension;
    uint8_t low_delay;
    uint8_t frame_rate_extension_n;
    uint8_t frame_rate_extension_d;
} MPEG2RawSequenceExtension;

typedef struct MPEG2RawSequenceDisplayExtension {
    uint8_t video_format;

    uint8_t colour_description;
    uint8_t colour_primaries;
    uint8_t transfer_characteristics;
    uint8_t matrix_coefficients;

    uint16_t display_horizontal_size;
    uint16_t display_vertical_size;
} MPEG2RawSequenceDisplayExtension;

typedef struct MPEG2RawGroupOfPicturesHeader {
    uint8_t group_start_code;

    uint32_t time_code;
    uint8_t closed_gop;
    uint8_t broken_link;
} MPEG2RawGroupOfPicturesHeader;

117 118 119 120 121 122
typedef struct MPEG2RawExtraInformation {
    uint8_t     *extra_information;
    AVBufferRef *extra_information_ref;
    size_t       extra_information_length;
} MPEG2RawExtraInformation;

123 124 125 126 127 128 129 130 131 132 133 134
typedef struct MPEG2RawPictureHeader {
    uint8_t picture_start_code;

    uint16_t temporal_reference;
    uint8_t picture_coding_type;
    uint16_t vbv_delay;

    uint8_t full_pel_forward_vector;
    uint8_t forward_f_code;
    uint8_t full_pel_backward_vector;
    uint8_t backward_f_code;

135
    MPEG2RawExtraInformation extra_information_picture;
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
} MPEG2RawPictureHeader;

typedef struct MPEG2RawPictureCodingExtension {
    uint8_t f_code[2][2];

    uint8_t intra_dc_precision;
    uint8_t picture_structure;
    uint8_t top_field_first;
    uint8_t frame_pred_frame_dct;
    uint8_t concealment_motion_vectors;
    uint8_t q_scale_type;
    uint8_t intra_vlc_format;
    uint8_t alternate_scan;
    uint8_t repeat_first_field;
    uint8_t chroma_420_type;
    uint8_t progressive_frame;

    uint8_t composite_display_flag;
    uint8_t v_axis;
    uint8_t field_sequence;
    uint8_t sub_carrier;
    uint8_t burst_amplitude;
    uint8_t sub_carrier_phase;
} MPEG2RawPictureCodingExtension;

typedef struct MPEG2RawQuantMatrixExtension {
    uint8_t load_intra_quantiser_matrix;
    uint8_t intra_quantiser_matrix[64];
    uint8_t load_non_intra_quantiser_matrix;
    uint8_t non_intra_quantiser_matrix[64];
    uint8_t load_chroma_intra_quantiser_matrix;
    uint8_t chroma_intra_quantiser_matrix[64];
    uint8_t load_chroma_non_intra_quantiser_matrix;
    uint8_t chroma_non_intra_quantiser_matrix[64];
} MPEG2RawQuantMatrixExtension;

typedef struct MPEG2RawPictureDisplayExtension {
173 174
    int16_t frame_centre_horizontal_offset[3];
    int16_t frame_centre_vertical_offset[3];
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
} MPEG2RawPictureDisplayExtension;

typedef struct MPEG2RawExtensionData {
    uint8_t extension_start_code;
    uint8_t extension_start_code_identifier;

    union {
        MPEG2RawSequenceExtension sequence;
        MPEG2RawSequenceDisplayExtension sequence_display;
        MPEG2RawQuantMatrixExtension quant_matrix;
        MPEG2RawPictureCodingExtension picture_coding;
        MPEG2RawPictureDisplayExtension picture_display;
    } data;
} MPEG2RawExtensionData;

typedef struct MPEG2RawSliceHeader {
    uint8_t slice_vertical_position;

    uint8_t slice_vertical_position_extension;
    uint8_t priority_breakpoint;

    uint8_t quantiser_scale_code;

    uint8_t slice_extension_flag;
    uint8_t intra_slice;
    uint8_t slice_picture_id_enable;
    uint8_t slice_picture_id;

203
    MPEG2RawExtraInformation extra_information_slice;
204 205 206 207 208 209 210 211
} MPEG2RawSliceHeader;

typedef struct MPEG2RawSlice {
    MPEG2RawSliceHeader header;

    uint8_t *data;
    size_t   data_size;
    int      data_bit_start;
212
    AVBufferRef *data_ref;
213 214
} MPEG2RawSlice;

215 216 217 218
typedef struct MPEG2RawSequenceEnd {
    uint8_t sequence_end_code;
} MPEG2RawSequenceEnd;

219 220 221 222 223 224 225 226 227 228 229 230 231

typedef struct CodedBitstreamMPEG2Context {
    // Elements stored in headers which are required for other decoding.
    uint16_t horizontal_size;
    uint16_t vertical_size;
    uint8_t scalable;
    uint8_t scalable_mode;
    uint8_t progressive_sequence;
    uint8_t number_of_frame_centre_offsets;
} CodedBitstreamMPEG2Context;


#endif /* AVCODEC_CBS_MPEG2_H */