2 * Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
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.
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.
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.
20 #ifndef __GST_H264_PICTURE_H__
21 #define __GST_H264_PICTURE_H__
23 #include <gst/codecs/codecs-prelude.h>
24 #include <gst/codecparsers/gsth264parser.h>
25 #include <gst/video/video.h>
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))
34 typedef struct _GstH264Slice GstH264Slice;
35 typedef struct _GstH264Picture GstH264Picture;
37 /* As specified in A.3.1 h) and A.3.2 f) */
38 #define GST_H264_DPB_MAX_SIZE 16
41 * GST_H264_PICTURE_IS_REF:
42 * @picture: a #GstH264Picture
44 * Check whether @picture is used for short-term or long-term reference
48 #define GST_H264_PICTURE_IS_REF(picture) \
49 ((picture)->ref != GST_H264_PICTURE_REF_NONE)
52 * GST_H264_PICTURE_IS_SHORT_TERM_REF:
53 * @picture: a #GstH264Picture
55 * Check whether @picture is used for short-term reference
59 #define GST_H264_PICTURE_IS_SHORT_TERM_REF(picture) \
60 ((picture)->ref == GST_H264_PICTURE_REF_SHORT_TERM)
63 * GST_H264_PICTURE_IS_LONG_TERM_REF:
64 * @picture: a #GstH264Picture
66 * Check whether @picture is used for long-term reference
70 #define GST_H264_PICTURE_IS_LONG_TERM_REF(picture) \
71 ((picture)->ref == GST_H264_PICTURE_REF_LONG_TERM)
74 * GST_H264_PICTURE_IS_FRAME:
75 * @picture: a #GstH264Picture
77 * Check whether @picture is a frame (not a field picture)
81 #define GST_H264_PICTURE_IS_FRAME(picture) \
82 ((picture)->field == GST_H264_PICTURE_FIELD_FRAME)
86 GstH264SliceHdr header;
88 /* parsed nal unit (doesn't take ownership of raw data) */
94 GST_H264_PICTURE_FIELD_FRAME,
95 GST_H264_PICTURE_FIELD_TOP_FIELD,
96 GST_H264_PICTURE_FIELD_BOTTOM_FIELD,
97 } GstH264PictureField;
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
109 GST_H264_PICTURE_REF_NONE = 0,
110 GST_H264_PICTURE_REF_SHORT_TERM,
111 GST_H264_PICTURE_REF_LONG_TERM,
112 } GstH264PictureReference;
114 struct _GstH264Picture
117 GstMiniObject parent;
119 GstH264SliceType type;
121 /* From GstVideoCodecFrame */
122 guint32 system_frame_number;
124 guint8 pic_order_cnt_type; /* SPS */
125 gint32 top_field_order_cnt;
126 gint32 bottom_field_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;
136 gint long_term_pic_num;
138 gint frame_num_offset;
140 gint long_term_frame_idx;
145 gboolean field_pic_flag;
146 GstH264PictureReference ref;
147 /* Whether a reference picture. */
149 gboolean needed_for_output;
152 gboolean nonexisting;
154 GstH264PictureField field;
156 GstH264DecRefPicMarking dec_ref_pic_marking;
158 /* For interlaced decoding */
159 gboolean second_field;
160 GstH264Picture * other_field;
162 GstVideoBufferFlags buffer_flags;
164 /* decoder input state if this picture is discont point */
165 GstVideoCodecState *discont_state;
168 GDestroyNotify notify;
172 * GstH264DpbBumpMode:
173 * @GST_H264_DPB_BUMP_NORMAL_LATENCY: No latency requirement for DBP bumping.
174 * @GST_H264_DPB_BUMP_LOW_LATENCY: Low-latency requirement for DBP bumping.
175 * @GST_H264_DPB_BUMP_VERY_LOW_LATENCY: Very low-latency requirement for DBP bumping.
181 GST_H264_DPB_BUMP_NORMAL_LATENCY,
182 GST_H264_DPB_BUMP_LOW_LATENCY,
183 GST_H264_DPB_BUMP_VERY_LOW_LATENCY
184 } GstH264DpbBumpMode;
187 GType gst_h264_picture_get_type (void);
190 GstH264Picture * gst_h264_picture_new (void);
192 static inline GstH264Picture *
193 gst_h264_picture_ref (GstH264Picture * picture)
195 return (GstH264Picture *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (picture));
199 gst_h264_picture_unref (GstH264Picture * picture)
201 gst_mini_object_unref (GST_MINI_OBJECT_CAST (picture));
204 static inline gboolean
205 gst_h264_picture_replace (GstH264Picture ** old_picture,
206 GstH264Picture * new_picture)
208 return gst_mini_object_replace ((GstMiniObject **) old_picture,
209 (GstMiniObject *) new_picture);
213 gst_clear_h264_picture (GstH264Picture ** picture)
215 if (picture && *picture) {
216 gst_h264_picture_unref (*picture);
222 void gst_h264_picture_set_user_data (GstH264Picture * picture,
224 GDestroyNotify notify);
227 gpointer gst_h264_picture_get_user_data (GstH264Picture * picture);
232 typedef struct _GstH264Dpb GstH264Dpb;
235 GstH264Dpb * gst_h264_dpb_new (void);
238 void gst_h264_dpb_set_max_num_frames (GstH264Dpb * dpb,
239 gint max_num_frames);
242 gint gst_h264_dpb_get_max_num_frames (GstH264Dpb * dpb);
245 void gst_h264_dpb_set_interlaced (GstH264Dpb * dpb,
246 gboolean interlaced);
249 void gst_h264_dpb_set_max_num_reorder_frames (GstH264Dpb * dpb,
250 guint32 max_num_reorder_frames);
253 gboolean gst_h264_dpb_get_interlaced (GstH264Dpb * dpb);
256 void gst_h264_dpb_free (GstH264Dpb * dpb);
259 void gst_h264_dpb_clear (GstH264Dpb * dpb);
262 void gst_h264_dpb_add (GstH264Dpb * dpb,
263 GstH264Picture * picture);
266 void gst_h264_dpb_delete_unused (GstH264Dpb * dpb);
269 gint gst_h264_dpb_num_ref_frames (GstH264Dpb * dpb);
272 void gst_h264_dpb_mark_all_non_ref (GstH264Dpb * dpb);
275 GstH264Picture * gst_h264_dpb_get_short_ref_by_pic_num (GstH264Dpb * dpb,
279 GstH264Picture * gst_h264_dpb_get_long_ref_by_long_term_pic_num (GstH264Dpb * dpb,
280 gint long_term_pic_num);
283 GstH264Picture * gst_h264_dpb_get_lowest_frame_num_short_ref (GstH264Dpb * dpb);
286 void gst_h264_dpb_get_pictures_short_term_ref (GstH264Dpb * dpb,
287 gboolean include_non_existing,
288 gboolean include_second_field,
292 void gst_h264_dpb_get_pictures_long_term_ref (GstH264Dpb * dpb,
293 gboolean include_second_field,
297 GArray * gst_h264_dpb_get_pictures_all (GstH264Dpb * dpb);
300 GstH264Picture * gst_h264_dpb_get_picture (GstH264Dpb * dpb,
301 guint32 system_frame_number);
304 gint gst_h264_dpb_get_size (GstH264Dpb * dpb);
307 gboolean gst_h264_dpb_has_empty_frame_buffer (GstH264Dpb * dpb);
310 gboolean gst_h264_dpb_needs_bump (GstH264Dpb * dpb,
311 GstH264Picture * to_insert,
312 GstH264DpbBumpMode latency_mode);
315 GstH264Picture * gst_h264_dpb_bump (GstH264Dpb * dpb,
319 void gst_h264_dpb_set_last_output (GstH264Dpb * dpb,
320 GstH264Picture * picture);
323 gboolean gst_h264_dpb_perform_memory_management_control_operation (GstH264Dpb * dpb,
324 GstH264RefPicMarking *ref_pic_marking,
325 GstH264Picture * picture);
327 /* Internal methods */
328 void gst_h264_picture_set_reference (GstH264Picture * picture,
329 GstH264PictureReference reference,
330 gboolean other_field);
332 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstH264Picture, gst_h264_picture_unref)
336 #endif /* __GST_H264_PICTURE_H__ */