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