• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <gst/codecparsers/gsth264parser.h>
25 #include <gst/video/video.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 /* As specified in A.3.1 h) and A.3.2 f) */
38 #define GST_H264_DPB_MAX_SIZE 16
39 
40 /**
41  * GST_H264_PICTURE_IS_REF:
42  * @picture: a #GstH264Picture
43  *
44  * Check whether @picture is used for short-term or long-term reference
45  *
46  * Since: 1.20
47  */
48 #define GST_H264_PICTURE_IS_REF(picture) \
49     ((picture)->ref != GST_H264_PICTURE_REF_NONE)
50 
51 /**
52  * GST_H264_PICTURE_IS_SHORT_TERM_REF:
53  * @picture: a #GstH264Picture
54  *
55  * Check whether @picture is used for short-term reference
56  *
57  * Since: 1.20
58  */
59 #define GST_H264_PICTURE_IS_SHORT_TERM_REF(picture) \
60     ((picture)->ref == GST_H264_PICTURE_REF_SHORT_TERM)
61 
62 /**
63  * GST_H264_PICTURE_IS_LONG_TERM_REF:
64  * @picture: a #GstH264Picture
65  *
66  * Check whether @picture is used for long-term reference
67  *
68  * Since: 1.20
69  */
70 #define GST_H264_PICTURE_IS_LONG_TERM_REF(picture) \
71     ((picture)->ref == GST_H264_PICTURE_REF_LONG_TERM)
72 
73 /**
74  * GST_H264_PICTURE_IS_FRAME:
75  * @picture: a #GstH264Picture
76  *
77  * Check whether @picture is a frame (not a field picture)
78  *
79  * Since: 1.20
80  */
81 #define GST_H264_PICTURE_IS_FRAME(picture) \
82     ((picture)->field == GST_H264_PICTURE_FIELD_FRAME)
83 
84 struct _GstH264Slice
85 {
86   GstH264SliceHdr header;
87 
88   /* parsed nal unit (doesn't take ownership of raw data) */
89   GstH264NalUnit nalu;
90 };
91 
92 typedef enum
93 {
94   GST_H264_PICTURE_FIELD_FRAME,
95   GST_H264_PICTURE_FIELD_TOP_FIELD,
96   GST_H264_PICTURE_FIELD_BOTTOM_FIELD,
97 } GstH264PictureField;
98 
99 /**
100  * GstH264PictureReference:
101  * @GST_H264_PICTURE_REF_NONE: Not used for reference picture
102  * @GST_H264_PICTURE_REF_SHORT_TERM: Used for short-term reference picture
103  * @GST_H264_PICTURE_REF_LONG_TERM: Used for long-term reference picture
104  *
105  * Since: 1.20
106  */
107 typedef enum
108 {
109   GST_H264_PICTURE_REF_NONE = 0,
110   GST_H264_PICTURE_REF_SHORT_TERM,
111   GST_H264_PICTURE_REF_LONG_TERM,
112 } GstH264PictureReference;
113 
114 struct _GstH264Picture
115 {
116   /*< private >*/
117   GstMiniObject parent;
118 
119   GstH264SliceType type;
120 
121   /* From GstVideoCodecFrame */
122   guint32 system_frame_number;
123 
124   guint8 pic_order_cnt_type;  /* SPS */
125   gint32 top_field_order_cnt;
126   gint32 bottom_field_order_cnt;
127 
128   gint pic_order_cnt;
129   gint pic_order_cnt_msb;
130   gint pic_order_cnt_lsb;
131   gint delta_pic_order_cnt_bottom;
132   gint delta_pic_order_cnt0;
133   gint delta_pic_order_cnt1;
134 
135   gint pic_num;
136   gint long_term_pic_num;
137   gint frame_num;
138   gint frame_num_offset;
139   gint frame_num_wrap;
140   gint long_term_frame_idx;
141 
142   gint nal_ref_idc;
143   gboolean idr;
144   gint idr_pic_id;
145   GstH264PictureReference ref;
146   /* Whether a reference picture. */
147   gboolean ref_pic;
148   gboolean needed_for_output;
149   gboolean mem_mgmt_5;
150 
151   gboolean nonexisting;
152 
153   GstH264PictureField field;
154 
155   GstH264DecRefPicMarking dec_ref_pic_marking;
156 
157   /* For interlaced decoding */
158   gboolean second_field;
159   GstH264Picture * other_field;
160 
161   GstVideoBufferFlags buffer_flags;
162 
163   gpointer user_data;
164   GDestroyNotify notify;
165 };
166 
167 /**
168  * GstH264DpbBumpMode:
169  * @GST_H264_DPB_BUMP_NORMAL_LATENCY: No latency requirement for DBP bumping.
170  * @GST_H264_DPB_BUMP_LOW_LATENCY: Low-latency requirement for DBP bumping.
171  * @GST_H264_DPB_BUMP_VERY_LOW_LATENCY: Very low-latency requirement for DBP bumping.
172  *
173  * Since: 1.20
174  */
175 typedef enum
176 {
177   GST_H264_DPB_BUMP_NORMAL_LATENCY,
178   GST_H264_DPB_BUMP_LOW_LATENCY,
179   GST_H264_DPB_BUMP_VERY_LOW_LATENCY
180 } GstH264DpbBumpMode;
181 
182 GST_CODECS_API
183 GType gst_h264_picture_get_type (void);
184 
185 GST_CODECS_API
186 GstH264Picture * gst_h264_picture_new (void);
187 
188 static inline GstH264Picture *
gst_h264_picture_ref(GstH264Picture * picture)189 gst_h264_picture_ref (GstH264Picture * picture)
190 {
191   return (GstH264Picture *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (picture));
192 }
193 
194 static inline void
gst_h264_picture_unref(GstH264Picture * picture)195 gst_h264_picture_unref (GstH264Picture * picture)
196 {
197   gst_mini_object_unref (GST_MINI_OBJECT_CAST (picture));
198 }
199 
200 static inline gboolean
gst_h264_picture_replace(GstH264Picture ** old_picture,GstH264Picture * new_picture)201 gst_h264_picture_replace (GstH264Picture ** old_picture,
202     GstH264Picture * new_picture)
203 {
204   return gst_mini_object_replace ((GstMiniObject **) old_picture,
205       (GstMiniObject *) new_picture);
206 }
207 
208 static inline void
gst_h264_picture_clear(GstH264Picture ** picture)209 gst_h264_picture_clear (GstH264Picture ** picture)
210 {
211   if (picture && *picture) {
212     gst_h264_picture_unref (*picture);
213     *picture = NULL;
214   }
215 }
216 
217 GST_CODECS_API
218 void gst_h264_picture_set_user_data (GstH264Picture * picture,
219                                      gpointer user_data,
220                                      GDestroyNotify notify);
221 
222 GST_CODECS_API
223 gpointer gst_h264_picture_get_user_data (GstH264Picture * picture);
224 
225 /*******************
226  * GstH264Dpb *
227  *******************/
228 typedef struct _GstH264Dpb GstH264Dpb;
229 
230 GST_CODECS_API
231 GstH264Dpb * gst_h264_dpb_new (void);
232 
233 GST_CODECS_API
234 void  gst_h264_dpb_set_max_num_frames (GstH264Dpb * dpb,
235                                        gint max_num_frames);
236 
237 GST_CODECS_API
238 gint gst_h264_dpb_get_max_num_frames  (GstH264Dpb * dpb);
239 
240 GST_CODECS_API
241 void gst_h264_dpb_set_interlaced      (GstH264Dpb * dpb,
242                                        gboolean interlaced);
243 
244 GST_CODECS_API
245 void gst_h264_dpb_set_max_num_reorder_frames (GstH264Dpb * dpb,
246                                               guint32 max_num_reorder_frames);
247 
248 GST_CODECS_API
249 gboolean gst_h264_dpb_get_interlaced  (GstH264Dpb * dpb);
250 
251 GST_CODECS_API
252 void  gst_h264_dpb_free             (GstH264Dpb * dpb);
253 
254 GST_CODECS_API
255 void  gst_h264_dpb_clear            (GstH264Dpb * dpb);
256 
257 GST_CODECS_API
258 void  gst_h264_dpb_add              (GstH264Dpb * dpb,
259                                      GstH264Picture * picture);
260 
261 GST_CODECS_API
262 void  gst_h264_dpb_delete_unused    (GstH264Dpb * dpb);
263 
264 GST_CODECS_API
265 gint  gst_h264_dpb_num_ref_frames (GstH264Dpb * dpb);
266 
267 GST_CODECS_API
268 void  gst_h264_dpb_mark_all_non_ref (GstH264Dpb * dpb);
269 
270 GST_CODECS_API
271 GstH264Picture * gst_h264_dpb_get_short_ref_by_pic_num (GstH264Dpb * dpb,
272                                                         gint pic_num);
273 
274 GST_CODECS_API
275 GstH264Picture * gst_h264_dpb_get_long_ref_by_long_term_pic_num (GstH264Dpb * dpb,
276                                                                  gint long_term_pic_num);
277 
278 GST_CODECS_API
279 GstH264Picture * gst_h264_dpb_get_lowest_frame_num_short_ref (GstH264Dpb * dpb);
280 
281 GST_CODECS_API
282 void  gst_h264_dpb_get_pictures_short_term_ref (GstH264Dpb * dpb,
283                                                 gboolean include_non_existing,
284                                                 gboolean include_second_field,
285                                                 GArray * out);
286 
287 GST_CODECS_API
288 void  gst_h264_dpb_get_pictures_long_term_ref  (GstH264Dpb * dpb,
289                                                 gboolean include_second_field,
290                                                 GArray * out);
291 
292 GST_CODECS_API
293 GArray * gst_h264_dpb_get_pictures_all         (GstH264Dpb * dpb);
294 
295 GST_CODECS_API
296 GstH264Picture * gst_h264_dpb_get_picture      (GstH264Dpb * dpb,
297                                                 guint32 system_frame_number);
298 
299 GST_CODECS_API
300 gint  gst_h264_dpb_get_size   (GstH264Dpb * dpb);
301 
302 GST_CODECS_API
303 gboolean gst_h264_dpb_has_empty_frame_buffer   (GstH264Dpb * dpb);
304 
305 GST_CODECS_API
306 gboolean gst_h264_dpb_needs_bump (GstH264Dpb * dpb,
307                                   GstH264Picture * to_insert,
308                                   GstH264DpbBumpMode latency_mode);
309 
310 GST_CODECS_API
311 GstH264Picture * gst_h264_dpb_bump (GstH264Dpb * dpb,
312                                     gboolean drain);
313 
314 GST_CODECS_API
315 void gst_h264_dpb_set_last_output (GstH264Dpb * dpb,
316                                    GstH264Picture * picture);
317 
318 GST_CODECS_API
319 gboolean         gst_h264_dpb_perform_memory_management_control_operation (GstH264Dpb * dpb,
320                                                                            GstH264RefPicMarking *ref_pic_marking,
321                                                                            GstH264Picture * picture);
322 
323 /* Internal methods */
324 void  gst_h264_picture_set_reference (GstH264Picture * picture,
325                                       GstH264PictureReference reference,
326                                       gboolean other_field);
327 
328 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstH264Picture, gst_h264_picture_unref)
329 
330 G_END_DECLS
331 
332 #endif /* __GST_H264_PICTURE_H__ */
333