]> git.sesse.net Git - ffmpeg/blob - libavcodec/h264_sei.h
Merge commit 'ea8ae27a5e112d06fd5625f640e40849e6313f0c'
[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
24 /**
25  * SEI message types
26  */
27 typedef enum {
28     H264_SEI_TYPE_BUFFERING_PERIOD       = 0,   ///< buffering period (H.264, D.1.1)
29     H264_SEI_TYPE_PIC_TIMING             = 1,   ///< picture timing
30     H264_SEI_TYPE_PAN_SCAN_RECT          = 2,   ///< pan-scan rectangle
31     H264_SEI_TYPE_FILLER_PAYLOAD         = 3,   ///< filler data
32     H264_SEI_TYPE_USER_DATA_REGISTERED   = 4,   ///< registered user data as specified by Rec. ITU-T T.35
33     H264_SEI_TYPE_USER_DATA_UNREGISTERED = 5,   ///< unregistered user data
34     H264_SEI_TYPE_RECOVERY_POINT         = 6,   ///< recovery point (frame # to decoder sync)
35     H264_SEI_TYPE_FRAME_PACKING          = 45,  ///< frame packing arrangement
36     H264_SEI_TYPE_DISPLAY_ORIENTATION    = 47,  ///< display orientation
37     H264_SEI_TYPE_GREEN_METADATA         = 56,  ///< GreenMPEG information
38     H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME = 137,  ///< mastering display properties
39     H264_SEI_TYPE_ALTERNATIVE_TRANSFER   = 147, ///< alternative transfer
40 } H264_SEI_Type;
41
42 /**
43  * pic_struct in picture timing SEI message
44  */
45 typedef enum {
46     H264_SEI_PIC_STRUCT_FRAME             = 0, ///<  0: %frame
47     H264_SEI_PIC_STRUCT_TOP_FIELD         = 1, ///<  1: top field
48     H264_SEI_PIC_STRUCT_BOTTOM_FIELD      = 2, ///<  2: bottom field
49     H264_SEI_PIC_STRUCT_TOP_BOTTOM        = 3, ///<  3: top field, bottom field, in that order
50     H264_SEI_PIC_STRUCT_BOTTOM_TOP        = 4, ///<  4: bottom field, top field, in that order
51     H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP    = 5, ///<  5: top field, bottom field, top field repeated, in that order
52     H264_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM = 6, ///<  6: bottom field, top field, bottom field repeated, in that order
53     H264_SEI_PIC_STRUCT_FRAME_DOUBLING    = 7, ///<  7: %frame doubling
54     H264_SEI_PIC_STRUCT_FRAME_TRIPLING    = 8  ///<  8: %frame tripling
55 } H264_SEI_PicStructType;
56
57 /**
58  * frame_packing_arrangement types
59  */
60 typedef enum {
61     H264_SEI_FPA_TYPE_CHECKERBOARD        = 0,
62     H264_SEI_FPA_TYPE_INTERLEAVE_COLUMN   = 1,
63     H264_SEI_FPA_TYPE_INTERLEAVE_ROW      = 2,
64     H264_SEI_FPA_TYPE_SIDE_BY_SIDE        = 3,
65     H264_SEI_FPA_TYPE_TOP_BOTTOM          = 4,
66     H264_SEI_FPA_TYPE_INTERLEAVE_TEMPORAL = 5,
67     H264_SEI_FPA_TYPE_2D                  = 6,
68 } H264_SEI_FpaType;
69
70 typedef struct H264SEIPictureTiming {
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 } H264SEIPictureTiming;
91
92 typedef struct H264SEIAFD {
93     int present;
94     uint8_t active_format_description;
95 } H264SEIAFD;
96
97 typedef struct H264SEIA53Caption {
98     AVBufferRef *buf_ref;
99 } H264SEIA53Caption;
100
101 typedef struct H264SEIUnregistered {
102     int x264_build;
103 } H264SEIUnregistered;
104
105 typedef struct H264SEIRecoveryPoint {
106     /**
107      * recovery_frame_cnt
108      *
109      * Set to -1 if no recovery point SEI message found or to number of frames
110      * before playback synchronizes. Frames having recovery point are key
111      * frames.
112      */
113     int recovery_frame_cnt;
114 } H264SEIRecoveryPoint;
115
116 typedef struct H264SEIBufferingPeriod {
117     int present;   ///< Buffering period SEI flag
118     int initial_cpb_removal_delay[32];  ///< Initial timestamps for CPBs
119 } H264SEIBufferingPeriod;
120
121 typedef struct H264SEIFramePacking {
122     int present;
123     int arrangement_id;
124     int arrangement_cancel_flag;  ///< is previous arrangement canceled, -1 if never received
125     H264_SEI_FpaType arrangement_type;
126     int arrangement_repetition_period;
127     int content_interpretation_type;
128     int quincunx_sampling_flag;
129     int current_frame_is_frame0_flag;
130 } H264SEIFramePacking;
131
132 typedef struct H264SEIDisplayOrientation {
133     int present;
134     int anticlockwise_rotation;
135     int hflip, vflip;
136 } H264SEIDisplayOrientation;
137
138 typedef struct H264SEIGreenMetaData {
139     uint8_t green_metadata_type;
140     uint8_t period_type;
141     uint16_t num_seconds;
142     uint16_t num_pictures;
143     uint8_t percent_non_zero_macroblocks;
144     uint8_t percent_intra_coded_macroblocks;
145     uint8_t percent_six_tap_filtering;
146     uint8_t percent_alpha_point_deblocking_instance;
147     uint8_t xsd_metric_type;
148     uint16_t xsd_metric_value;
149 } H264SEIGreenMetaData;
150
151 typedef struct H264SEIAlternativeTransfer {
152     int present;
153     int preferred_transfer_characteristics;
154 } H264SEIAlternativeTransfer;
155
156 typedef struct H264SEIContext {
157     H264SEIPictureTiming picture_timing;
158     H264SEIAFD afd;
159     H264SEIA53Caption a53_caption;
160     H264SEIUnregistered unregistered;
161     H264SEIRecoveryPoint recovery_point;
162     H264SEIBufferingPeriod buffering_period;
163     H264SEIFramePacking frame_packing;
164     H264SEIDisplayOrientation display_orientation;
165     H264SEIGreenMetaData green_metadata;
166     H264SEIAlternativeTransfer alternative_transfer;
167 } H264SEIContext;
168
169 struct H264ParamSets;
170
171 int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb,
172                        const struct H264ParamSets *ps, void *logctx);
173
174 /**
175  * Reset SEI values at the beginning of the frame.
176  */
177 void ff_h264_sei_uninit(H264SEIContext *h);
178
179 /**
180  * Get stereo_mode string from the h264 frame_packing_arrangement
181  */
182 const char *ff_h264_sei_stereo_mode(const H264SEIFramePacking *h);
183
184 #endif /* AVCODEC_H264_SEI_H */