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_H265_PICTURE_H__
21 #define __GST_H265_PICTURE_H__
22
23 #ifndef GST_USE_UNSTABLE_API
24 #warning "The CODECs library is unstable API and may change in future."
25 #warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
26 #endif
27
28 #include <gst/gst.h>
29 #include <gst/codecs/codecs-prelude.h>
30 #include <gst/codecparsers/gsth265parser.h>
31 #include <gst/video/video.h>
32
33 G_BEGIN_DECLS
34
35 #define GST_TYPE_H265_PICTURE (gst_h265_picture_get_type())
36 #define GST_IS_H265_PICTURE(obj) (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_H265_PICTURE))
37 #define GST_H265_PICTURE(obj) ((GstH265Picture *)obj)
38 #define GST_H265_PICTURE_CAST(obj) (GST_H265_PICTURE(obj))
39
40 typedef struct _GstH265Slice GstH265Slice;
41 typedef struct _GstH265Picture GstH265Picture;
42
43 #define GST_H265_DPB_MAX_SIZE 16
44
45 struct _GstH265Slice
46 {
47 GstH265SliceHdr header;
48
49 /* parsed nal unit (doesn't take ownership of raw data) */
50 GstH265NalUnit nalu;
51 };
52
53 struct _GstH265Picture
54 {
55 /*< private >*/
56 GstMiniObject parent;
57
58 GstH265SliceType type;
59
60 GstClockTime pts;
61 /* From GstVideoCodecFrame */
62 guint32 system_frame_number;
63
64 gint pic_order_cnt;
65 gint pic_order_cnt_msb;
66 gint pic_order_cnt_lsb;
67
68 guint32 pic_latency_cnt; /* PicLatencyCount */
69
70 gboolean output_flag;
71 gboolean NoRaslOutputFlag;
72 gboolean NoOutputOfPriorPicsFlag;
73 gboolean RapPicFlag; /* nalu type between 16 and 21 */
74 gboolean IntraPicFlag; /* Intra pic (only Intra slices) */
75
76 gboolean ref;
77 gboolean long_term;
78 gboolean needed_for_output;
79
80 /* from picture timing SEI */
81 GstH265SEIPicStructType pic_struct;
82 guint8 source_scan_type;
83 guint8 duplicate_flag;
84
85 GstVideoBufferFlags buffer_flags;
86
87 gpointer user_data;
88 GDestroyNotify notify;
89 };
90
91 GST_CODECS_API
92 GType gst_h265_picture_get_type (void);
93
94 GST_CODECS_API
95 GstH265Picture * gst_h265_picture_new (void);
96
97 static inline GstH265Picture *
gst_h265_picture_ref(GstH265Picture * picture)98 gst_h265_picture_ref (GstH265Picture * picture)
99 {
100 return (GstH265Picture *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (picture));
101 }
102
103 static inline void
gst_h265_picture_unref(GstH265Picture * picture)104 gst_h265_picture_unref (GstH265Picture * picture)
105 {
106 gst_mini_object_unref (GST_MINI_OBJECT_CAST (picture));
107 }
108
109 static inline gboolean
gst_h265_picture_replace(GstH265Picture ** old_picture,GstH265Picture * new_picture)110 gst_h265_picture_replace (GstH265Picture ** old_picture,
111 GstH265Picture * new_picture)
112 {
113 return gst_mini_object_replace ((GstMiniObject **) old_picture,
114 (GstMiniObject *) new_picture);
115 }
116
117 static inline void
gst_h265_picture_clear(GstH265Picture ** picture)118 gst_h265_picture_clear (GstH265Picture ** picture)
119 {
120 if (picture && *picture) {
121 gst_h265_picture_unref (*picture);
122 *picture = NULL;
123 }
124 }
125
126 GST_CODECS_API
127 void gst_h265_picture_set_user_data (GstH265Picture * picture,
128 gpointer user_data,
129 GDestroyNotify notify);
130
131 GST_CODECS_API
132 gpointer gst_h265_picture_get_user_data (GstH265Picture * picture);
133
134 /*******************
135 * GstH265Dpb *
136 *******************/
137 typedef struct _GstH265Dpb GstH265Dpb;
138
139 GST_CODECS_API
140 GstH265Dpb * gst_h265_dpb_new (void);
141
142 GST_CODECS_API
143 void gst_h265_dpb_set_max_num_pics (GstH265Dpb * dpb,
144 gint max_num_pics);
145
146 GST_CODECS_API
147 gint gst_h265_dpb_get_max_num_pics (GstH265Dpb * dpb);
148
149 GST_CODECS_API
150 void gst_h265_dpb_free (GstH265Dpb * dpb);
151
152 GST_CODECS_API
153 void gst_h265_dpb_clear (GstH265Dpb * dpb);
154
155 GST_CODECS_API
156 void gst_h265_dpb_add (GstH265Dpb * dpb,
157 GstH265Picture * picture);
158
159 GST_CODECS_API
160 void gst_h265_dpb_delete_unused (GstH265Dpb * dpb);
161
162 GST_CODECS_API
163 gint gst_h265_dpb_num_ref_pictures (GstH265Dpb * dpb);
164
165 GST_CODECS_API
166 void gst_h265_dpb_mark_all_non_ref (GstH265Dpb * dpb);
167
168 GST_CODECS_API
169 GstH265Picture * gst_h265_dpb_get_ref_by_poc (GstH265Dpb * dpb,
170 gint poc);
171
172 GST_CODECS_API
173 GstH265Picture * gst_h265_dpb_get_ref_by_poc_lsb (GstH265Dpb * dpb,
174 gint poc_lsb);
175
176 GST_CODECS_API
177 GstH265Picture * gst_h265_dpb_get_short_ref_by_poc (GstH265Dpb * dpb,
178 gint poc);
179
180 GST_CODECS_API
181 GstH265Picture * gst_h265_dpb_get_long_ref_by_poc (GstH265Dpb * dpb,
182 gint poc);
183
184 GST_CODECS_API
185 GArray * gst_h265_dpb_get_pictures_all (GstH265Dpb * dpb);
186
187 GST_CODECS_API
188 GstH265Picture * gst_h265_dpb_get_picture (GstH265Dpb * dpb,
189 guint32 system_frame_number);
190
191 GST_CODECS_API
192 gint gst_h265_dpb_get_size (GstH265Dpb * dpb);
193
194 GST_CODECS_API
195 gboolean gst_h265_dpb_needs_bump (GstH265Dpb * dpb,
196 guint max_num_reorder_pics,
197 guint max_latency_increase,
198 guint max_dec_pic_buffering);
199
200 GST_CODECS_API
201 GstH265Picture * gst_h265_dpb_bump (GstH265Dpb * dpb,
202 gboolean drain);
203
204 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstH265Picture, gst_h265_picture_unref)
205
206 G_END_DECLS
207
208 #endif /* __GST_H265_PICTURE_H__ */
209