xref: /third_party/ffmpeg/libavcodec/h264_sei.h (revision cabdff1a)
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
19#ifndef AVCODEC_H264_SEI_H
20#define AVCODEC_H264_SEI_H
21
22#include "get_bits.h"
23#include "h264_ps.h"
24#include "sei.h"
25
26
27/**
28 * pic_struct in picture timing SEI message
29 */
30typedef enum {
31    H264_SEI_PIC_STRUCT_FRAME             = 0, ///<  0: %frame
32    H264_SEI_PIC_STRUCT_TOP_FIELD         = 1, ///<  1: top field
33    H264_SEI_PIC_STRUCT_BOTTOM_FIELD      = 2, ///<  2: bottom field
34    H264_SEI_PIC_STRUCT_TOP_BOTTOM        = 3, ///<  3: top field, bottom field, in that order
35    H264_SEI_PIC_STRUCT_BOTTOM_TOP        = 4, ///<  4: bottom field, top field, in that order
36    H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP    = 5, ///<  5: top field, bottom field, top field repeated, in that order
37    H264_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM = 6, ///<  6: bottom field, top field, bottom field repeated, in that order
38    H264_SEI_PIC_STRUCT_FRAME_DOUBLING    = 7, ///<  7: %frame doubling
39    H264_SEI_PIC_STRUCT_FRAME_TRIPLING    = 8  ///<  8: %frame tripling
40} H264_SEI_PicStructType;
41
42/**
43 * frame_packing_arrangement types
44 */
45typedef enum {
46    H264_SEI_FPA_TYPE_CHECKERBOARD        = 0,
47    H264_SEI_FPA_TYPE_INTERLEAVE_COLUMN   = 1,
48    H264_SEI_FPA_TYPE_INTERLEAVE_ROW      = 2,
49    H264_SEI_FPA_TYPE_SIDE_BY_SIDE        = 3,
50    H264_SEI_FPA_TYPE_TOP_BOTTOM          = 4,
51    H264_SEI_FPA_TYPE_INTERLEAVE_TEMPORAL = 5,
52    H264_SEI_FPA_TYPE_2D                  = 6,
53} H264_SEI_FpaType;
54
55typedef struct H264SEITimeCode {
56    /* When not continuously receiving full timecodes, we have to reference
57       the previous timecode received */
58    int full;
59    int frame;
60    int seconds;
61    int minutes;
62    int hours;
63    int dropframe;
64} H264SEITimeCode;
65
66typedef struct H264SEIPictureTiming {
67    // maximum size of pic_timing according to the spec should be 274 bits
68    uint8_t payload[40];
69    int     payload_size_bits;
70
71    int present;
72    H264_SEI_PicStructType pic_struct;
73
74    /**
75     * Bit set of clock types for fields/frames in picture timing SEI message.
76     * For each found ct_type, appropriate bit is set (e.g., bit 1 for
77     * interlaced).
78     */
79    int ct_type;
80
81    /**
82     * dpb_output_delay in picture timing SEI message, see H.264 C.2.2
83     */
84    int dpb_output_delay;
85
86    /**
87     * cpb_removal_delay in picture timing SEI message, see H.264 C.1.2
88     */
89    int cpb_removal_delay;
90
91    /**
92     * Maximum three timecodes in a pic_timing SEI.
93     */
94    H264SEITimeCode timecode[3];
95
96    /**
97     * Number of timecode in use
98     */
99    int timecode_cnt;
100} H264SEIPictureTiming;
101
102typedef struct H264SEIAFD {
103    int present;
104    uint8_t active_format_description;
105} H264SEIAFD;
106
107typedef struct H264SEIA53Caption {
108    AVBufferRef *buf_ref;
109} H264SEIA53Caption;
110
111typedef struct H264SEIUnregistered {
112    int x264_build;
113    AVBufferRef **buf_ref;
114    int nb_buf_ref;
115} H264SEIUnregistered;
116
117typedef struct H264SEIRecoveryPoint {
118    /**
119     * recovery_frame_cnt
120     *
121     * Set to -1 if no recovery point SEI message found or to number of frames
122     * before playback synchronizes. Frames having recovery point are key
123     * frames.
124     */
125    int recovery_frame_cnt;
126} H264SEIRecoveryPoint;
127
128typedef struct H264SEIBufferingPeriod {
129    int present;   ///< Buffering period SEI flag
130    int initial_cpb_removal_delay[32];  ///< Initial timestamps for CPBs
131} H264SEIBufferingPeriod;
132
133typedef struct H264SEIFramePacking {
134    int present;
135    int arrangement_id;
136    int arrangement_cancel_flag;  ///< is previous arrangement canceled, -1 if never received
137    H264_SEI_FpaType arrangement_type;
138    int arrangement_repetition_period;
139    int content_interpretation_type;
140    int quincunx_sampling_flag;
141    int current_frame_is_frame0_flag;
142} H264SEIFramePacking;
143
144typedef struct H264SEIDisplayOrientation {
145    int present;
146    int anticlockwise_rotation;
147    int hflip, vflip;
148} H264SEIDisplayOrientation;
149
150typedef struct H264SEIGreenMetaData {
151    uint8_t green_metadata_type;
152    uint8_t period_type;
153    uint16_t num_seconds;
154    uint16_t num_pictures;
155    uint8_t percent_non_zero_macroblocks;
156    uint8_t percent_intra_coded_macroblocks;
157    uint8_t percent_six_tap_filtering;
158    uint8_t percent_alpha_point_deblocking_instance;
159    uint8_t xsd_metric_type;
160    uint16_t xsd_metric_value;
161} H264SEIGreenMetaData;
162
163typedef struct H264SEIAlternativeTransfer {
164    int present;
165    int preferred_transfer_characteristics;
166} H264SEIAlternativeTransfer;
167
168typedef struct H264SEIFilmGrainCharacteristics {
169    int present;
170    int model_id;
171    int separate_colour_description_present_flag;
172    int bit_depth_luma;
173    int bit_depth_chroma;
174    int full_range;
175    int color_primaries;
176    int transfer_characteristics;
177    int matrix_coeffs;
178    int blending_mode_id;
179    int log2_scale_factor;
180    int comp_model_present_flag[3];
181    uint16_t num_intensity_intervals[3];
182    uint8_t num_model_values[3];
183    uint8_t intensity_interval_lower_bound[3][256];
184    uint8_t intensity_interval_upper_bound[3][256];
185    int16_t comp_model_value[3][256][6];
186    int repetition_period;
187} H264SEIFilmGrainCharacteristics;
188
189typedef struct H264SEIContext {
190    H264SEIPictureTiming picture_timing;
191    H264SEIAFD afd;
192    H264SEIA53Caption a53_caption;
193    H264SEIUnregistered unregistered;
194    H264SEIRecoveryPoint recovery_point;
195    H264SEIBufferingPeriod buffering_period;
196    H264SEIFramePacking frame_packing;
197    H264SEIDisplayOrientation display_orientation;
198    H264SEIGreenMetaData green_metadata;
199    H264SEIAlternativeTransfer alternative_transfer;
200    H264SEIFilmGrainCharacteristics film_grain_characteristics;
201} H264SEIContext;
202
203struct H264ParamSets;
204
205int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb,
206                       const struct H264ParamSets *ps, void *logctx);
207
208/**
209 * Reset SEI values at the beginning of the frame.
210 */
211void ff_h264_sei_uninit(H264SEIContext *h);
212
213/**
214 * Get stereo_mode string from the h264 frame_packing_arrangement
215 */
216const char *ff_h264_sei_stereo_mode(const H264SEIFramePacking *h);
217
218/**
219 * Parse the contents of a picture timing message given an active SPS.
220 */
221int ff_h264_sei_process_picture_timing(H264SEIPictureTiming *h, const SPS *sps,
222                                       void *logctx);
223
224#endif /* AVCODEC_H264_SEI_H */
225