]> git.sesse.net Git - ffmpeg/blob - libavcodec/h264_sei.h
lavf/segment: fix crash when failing to open segment list
[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     SEI_TYPE_BUFFERING_PERIOD       = 0,   ///< buffering period (H.264, D.1.1)
29     SEI_TYPE_PIC_TIMING             = 1,   ///< picture timing
30     SEI_TYPE_USER_DATA_REGISTERED   = 4,   ///< registered user data as specified by Rec. ITU-T T.35
31     SEI_TYPE_USER_DATA_UNREGISTERED = 5,   ///< unregistered user data
32     SEI_TYPE_RECOVERY_POINT         = 6,   ///< recovery point (frame # to decoder sync)
33     SEI_TYPE_FRAME_PACKING          = 45,  ///< frame packing arrangement
34     SEI_TYPE_DISPLAY_ORIENTATION    = 47,  ///< display orientation
35     SEI_TYPE_GREEN_METADATA         = 56   ///< GreenMPEG information
36 } SEI_Type;
37
38 /**
39  * pic_struct in picture timing SEI message
40  */
41 typedef enum {
42     SEI_PIC_STRUCT_FRAME             = 0, ///<  0: %frame
43     SEI_PIC_STRUCT_TOP_FIELD         = 1, ///<  1: top field
44     SEI_PIC_STRUCT_BOTTOM_FIELD      = 2, ///<  2: bottom field
45     SEI_PIC_STRUCT_TOP_BOTTOM        = 3, ///<  3: top field, bottom field, in that order
46     SEI_PIC_STRUCT_BOTTOM_TOP        = 4, ///<  4: bottom field, top field, in that order
47     SEI_PIC_STRUCT_TOP_BOTTOM_TOP    = 5, ///<  5: top field, bottom field, top field repeated, in that order
48     SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM = 6, ///<  6: bottom field, top field, bottom field repeated, in that order
49     SEI_PIC_STRUCT_FRAME_DOUBLING    = 7, ///<  7: %frame doubling
50     SEI_PIC_STRUCT_FRAME_TRIPLING    = 8  ///<  8: %frame tripling
51 } SEI_PicStructType;
52
53 /**
54  * frame_packing_arrangement types
55  */
56 typedef enum {
57     SEI_FPA_TYPE_CHECKERBOARD        = 0,
58     SEI_FPA_TYPE_INTERLEAVE_COLUMN   = 1,
59     SEI_FPA_TYPE_INTERLEAVE_ROW      = 2,
60     SEI_FPA_TYPE_SIDE_BY_SIDE        = 3,
61     SEI_FPA_TYPE_TOP_BOTTOM          = 4,
62     SEI_FPA_TYPE_INTERLEAVE_TEMPORAL = 5,
63     SEI_FPA_TYPE_2D                  = 6,
64 } SEI_FpaType;
65
66 typedef struct H264SEIPictureTiming {
67     SEI_PicStructType pic_struct;
68
69     /**
70      * Bit set of clock types for fields/frames in picture timing SEI message.
71      * For each found ct_type, appropriate bit is set (e.g., bit 1 for
72      * interlaced).
73      */
74     int ct_type;
75
76     /**
77      * dpb_output_delay in picture timing SEI message, see H.264 C.2.2
78      */
79     int dpb_output_delay;
80
81     /**
82      * cpb_removal_delay in picture timing SEI message, see H.264 C.1.2
83      */
84     int cpb_removal_delay;
85 } H264SEIPictureTiming;
86
87 typedef struct H264SEIAFD {
88     int present;
89     uint8_t active_format_description;
90 } H264SEIAFD;
91
92 typedef struct H264SEIA53Caption {
93     int a53_caption_size;
94     uint8_t *a53_caption;
95 } H264SEIA53Caption;
96
97 typedef struct H264SEIUnregistered {
98     int x264_build;
99 } H264SEIUnregistered;
100
101 typedef struct H264SEIRecoveryPoint {
102     /**
103      * recovery_frame_cnt
104      *
105      * Set to -1 if no recovery point SEI message found or to number of frames
106      * before playback synchronizes. Frames having recovery point are key
107      * frames.
108      */
109     int recovery_frame_cnt;
110 } H264SEIRecoveryPoint;
111
112 typedef struct H264SEIBufferingPeriod {
113     int present;   ///< Buffering period SEI flag
114     int initial_cpb_removal_delay[32];  ///< Initial timestamps for CPBs
115 } H264SEIBufferingPeriod;
116
117 typedef struct H264SEIFramePacking {
118     int present;
119     int frame_packing_arrangement_id;
120     int frame_packing_arrangement_cancel_flag;  ///< is previous arrangement canceled, -1 if never received
121     SEI_FpaType frame_packing_arrangement_type;
122     int frame_packing_arrangement_repetition_period;
123     int content_interpretation_type;
124     int quincunx_sampling_flag;
125 } H264SEIFramePacking;
126
127 typedef struct H264SEIDisplayOrientation {
128     int present;
129     int anticlockwise_rotation;
130     int hflip, vflip;
131 } H264SEIDisplayOrientation;
132
133 typedef struct H264SEIGreenMetaData {
134     uint8_t green_metadata_type;
135     uint8_t period_type;
136     uint16_t num_seconds;
137     uint16_t num_pictures;
138     uint8_t percent_non_zero_macroblocks;
139     uint8_t percent_intra_coded_macroblocks;
140     uint8_t percent_six_tap_filtering;
141     uint8_t percent_alpha_point_deblocking_instance;
142     uint8_t xsd_metric_type;
143     uint16_t xsd_metric_value;
144 } H264SEIGreenMetaData;
145
146 typedef struct H264SEIContext {
147     H264SEIPictureTiming picture_timing;
148     H264SEIAFD afd;
149     H264SEIA53Caption a53_caption;
150     H264SEIUnregistered unregistered;
151     H264SEIRecoveryPoint recovery_point;
152     H264SEIBufferingPeriod buffering_period;
153     H264SEIFramePacking frame_packing;
154     H264SEIDisplayOrientation display_orientation;
155     H264SEIGreenMetaData green_metadata;
156 } H264SEIContext;
157
158 struct H264ParamSets;
159
160 int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb,
161                        const struct H264ParamSets *ps, void *logctx);
162
163 /**
164  * Reset SEI values at the beginning of the frame.
165  */
166 void ff_h264_sei_uninit(H264SEIContext *h);
167
168 /**
169  * Get stereo_mode string from the h264 frame_packing_arrangement
170  */
171 const char *ff_h264_sei_stereo_mode(const H264SEIFramePacking *h);
172
173 #endif /* AVCODEC_H264_SEI_H */