webrtc: Don't crash in ICE gathering
[platform/upstream/gstreamer.git] / gst-libs / gst / codecs / gsth264picture.h
1 /* GStreamer
2  * Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef __GST_H264_PICTURE_H__
21 #define __GST_H264_PICTURE_H__
22
23 #include <gst/codecs/codecs-prelude.h>
24
25 #include <gst/codecparsers/gsth264parser.h>
26
27 G_BEGIN_DECLS
28
29 #define GST_TYPE_H264_PICTURE     (gst_h264_picture_get_type())
30 #define GST_IS_H264_PICTURE(obj)  (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_H264_PICTURE))
31 #define GST_H264_PICTURE(obj)     ((GstH264Picture *)obj)
32 #define GST_H264_PICTURE_CAST(obj) (GST_H264_PICTURE(obj))
33
34 typedef struct _GstH264Slice GstH264Slice;
35 typedef struct _GstH264Picture GstH264Picture;
36
37 #define GST_H264_DPB_MAX_SIZE 32
38
39 struct _GstH264Slice
40 {
41   GstH264SliceHdr header;
42
43   /* parsed nal unit (doesn't take ownership of raw data) */
44   GstH264NalUnit nalu;
45 };
46
47 typedef enum
48 {
49   GST_H264_PICTURE_FIELD_FRAME,
50   GST_H264_PICTURE_FILED_TOP_FIELD,
51   GST_H264_PICTURE_FIELD_BOTTOM_FIELD,
52 } GstH264PictureField;
53
54 struct _GstH264Picture
55 {
56   GstMiniObject parent;
57
58   GstH264SliceType type;
59
60   GstClockTime pts;
61
62   guint8 pic_order_cnt_type;  /* SPS */
63   gint32 top_field_order_cnt;
64   gint32 bottom_field_order_cnt;
65
66   gint pic_order_cnt;
67   gint pic_order_cnt_msb;
68   gint pic_order_cnt_lsb;
69   gint delta_pic_order_cnt_bottom;
70   gint delta_pic_order_cnt0;
71   gint delta_pic_order_cnt1;
72
73   gint pic_num;
74   gint long_term_pic_num;
75   gint frame_num;
76   gint frame_num_offset;
77   gint frame_num_wrap;
78   gint long_term_frame_idx;
79
80   gint nal_ref_idc;
81   gboolean idr;
82   gint idr_pic_id;
83   gboolean ref;
84   gboolean long_term;
85   gboolean outputted;
86   gboolean mem_mgmt_5;
87
88   gboolean nonexisting;
89
90   GstH264PictureField field;
91
92   GstH264DecRefPicMarking dec_ref_pic_marking;
93
94   gpointer user_data;
95   GDestroyNotify notify;
96 };
97
98 GST_CODECS_API
99 GType gst_h264_picture_get_type (void);
100
101 GST_CODECS_API
102 GstH264Picture * gst_h264_picture_new (void);
103
104 static inline GstH264Picture *
105 gst_h264_picture_ref (GstH264Picture * picture)
106 {
107   return (GstH264Picture *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (picture));
108 }
109
110 static inline void
111 gst_h264_picture_unref (GstH264Picture * picture)
112 {
113   gst_mini_object_unref (GST_MINI_OBJECT_CAST (picture));
114 }
115
116 static inline gboolean
117 gst_h264_picture_replace (GstH264Picture ** old_picture,
118     GstH264Picture * new_picture)
119 {
120   return gst_mini_object_replace ((GstMiniObject **) old_picture,
121       (GstMiniObject *) new_picture);
122 }
123
124 static inline void
125 gst_h264_picture_clear (GstH264Picture ** picture)
126 {
127   if (picture && *picture) {
128     gst_h264_picture_unref (*picture);
129     *picture = NULL;
130   }
131 }
132
133 GST_CODECS_API
134 void gst_h264_picture_set_user_data (GstH264Picture * picture,
135                                      gpointer user_data,
136                                      GDestroyNotify notify);
137
138 GST_CODECS_API
139 gpointer gst_h264_picture_get_user_data (GstH264Picture * picture);
140
141 /*******************
142  * GstH264Dpb *
143  *******************/
144 typedef struct _GstH264Dpb GstH264Dpb;
145
146 GST_CODECS_API
147 GstH264Dpb * gst_h264_dpb_new (void);
148
149 GST_CODECS_API
150 void  gst_h264_dpb_set_max_num_pics (GstH264Dpb * dpb,
151                                      gint max_num_pics);
152
153 GST_CODECS_API
154 gint gst_h264_dpb_get_max_num_pics  (GstH264Dpb * dpb);
155
156 GST_CODECS_API
157 void  gst_h264_dpb_free             (GstH264Dpb * dpb);
158
159 GST_CODECS_API
160 void  gst_h264_dpb_clear            (GstH264Dpb * dpb);
161
162 GST_CODECS_API
163 void  gst_h264_dpb_add              (GstH264Dpb * dpb,
164                                      GstH264Picture * picture);
165
166 GST_CODECS_API
167 void  gst_h264_dpb_delete_unused    (GstH264Dpb * dpb);
168
169 GST_CODECS_API
170 void  gst_h264_dpb_delete_by_poc    (GstH264Dpb * dpb,
171                                      gint poc);
172
173 GST_CODECS_API
174 gint  gst_h264_dpb_num_ref_pictures (GstH264Dpb * dpb);
175
176 GST_CODECS_API
177 void  gst_h264_dpb_mark_all_non_ref (GstH264Dpb * dpb);
178
179 GST_CODECS_API
180 GstH264Picture * gst_h264_dpb_get_short_ref_by_pic_num (GstH264Dpb * dpb,
181                                                         gint pic_num);
182
183 GST_CODECS_API
184 GstH264Picture * gst_h264_dpb_get_long_ref_by_pic_num  (GstH264Dpb * dpb,
185                                                         gint pic_num);
186
187 GST_CODECS_API
188 GstH264Picture * gst_h264_dpb_get_lowest_frame_num_short_ref (GstH264Dpb * dpb);
189
190 GST_CODECS_API
191 void  gst_h264_dpb_get_pictures_not_outputted  (GstH264Dpb * dpb,
192                                                 GList ** out);
193
194 GST_CODECS_API
195 void  gst_h264_dpb_get_pictures_short_term_ref (GstH264Dpb * dpb,
196                                                 GList ** out);
197
198 GST_CODECS_API
199 void  gst_h264_dpb_get_pictures_long_term_ref  (GstH264Dpb * dpb,
200                                                 GList ** out);
201
202 GST_CODECS_API
203 GArray * gst_h264_dpb_get_pictures_all         (GstH264Dpb * dpb);
204
205 GST_CODECS_API
206 gint  gst_h264_dpb_get_size   (GstH264Dpb * dpb);
207
208 GST_CODECS_API
209 gboolean gst_h264_dpb_is_full (GstH264Dpb * dpb);
210
211 G_END_DECLS
212
213 #endif /* __GST_H264_PICTURE_H__ */