Move CODEC base classes into it's own library
[platform/upstream/gstreamer.git] / gst-libs / gst / codecs / gsth265picture.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_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
31 #include <gst/codecparsers/gsth265parser.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 typedef enum
54 {
55   GST_H265_PICTURE_FIELD_FRAME,
56   GST_H265_PICTURE_FILED_TOP_FIELD,
57   GST_H265_PICTURE_FIELD_BOTTOM_FIELD,
58 } GstH265PictureField;
59
60 struct _GstH265Picture
61 {
62   GstMiniObject parent;
63
64   GstH265SliceType type;
65
66   GstClockTime pts;
67
68   gint pic_order_cnt;
69   gint pic_order_cnt_msb;
70   gint pic_order_cnt_lsb;
71
72   guint32 pic_latency_cnt;      /* PicLatencyCount */
73
74   gboolean output_flag;
75   gboolean NoRaslOutputFlag;
76   gboolean NoOutputOfPriorPicsFlag;
77   gboolean RapPicFlag;           /* nalu type between 16 and 21 */
78   gboolean IntraPicFlag;         /* Intra pic (only Intra slices) */
79
80   gboolean ref;
81   gboolean long_term;
82   gboolean outputted;
83
84   GstH265PictureField field;
85
86   gpointer user_data;
87   GDestroyNotify notify;
88 };
89
90 GST_CODECS_API
91 GType gst_h265_picture_get_type (void);
92
93 GST_CODECS_API
94 GstH265Picture * gst_h265_picture_new (void);
95
96 static inline GstH265Picture *
97 gst_h265_picture_ref (GstH265Picture * picture)
98 {
99   return (GstH265Picture *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (picture));
100 }
101
102 static inline void
103 gst_h265_picture_unref (GstH265Picture * picture)
104 {
105   gst_mini_object_unref (GST_MINI_OBJECT_CAST (picture));
106 }
107
108 static inline gboolean
109 gst_h265_picture_replace (GstH265Picture ** old_picture,
110     GstH265Picture * new_picture)
111 {
112   return gst_mini_object_replace ((GstMiniObject **) old_picture,
113       (GstMiniObject *) new_picture);
114 }
115
116 static inline void
117 gst_h265_picture_clear (GstH265Picture ** picture)
118 {
119   if (picture && *picture) {
120     gst_h265_picture_unref (*picture);
121     *picture = NULL;
122   }
123 }
124
125 GST_CODECS_API
126 void gst_h265_picture_set_user_data (GstH265Picture * picture,
127                                      gpointer user_data,
128                                      GDestroyNotify notify);
129
130 GST_CODECS_API
131 gpointer gst_h265_picture_get_user_data (GstH265Picture * picture);
132
133 /*******************
134  * GstH265Dpb *
135  *******************/
136 typedef struct _GstH265Dpb GstH265Dpb;
137
138 GST_CODECS_API
139 GstH265Dpb * gst_h265_dpb_new (void);
140
141 GST_CODECS_API
142 void  gst_h265_dpb_set_max_num_pics (GstH265Dpb * dpb,
143                                      gint max_num_pics);
144
145 GST_CODECS_API
146 gint gst_h265_dpb_get_max_num_pics  (GstH265Dpb * dpb);
147
148 GST_CODECS_API
149 void  gst_h265_dpb_free             (GstH265Dpb * dpb);
150
151 GST_CODECS_API
152 void  gst_h265_dpb_clear            (GstH265Dpb * dpb);
153
154 GST_CODECS_API
155 void  gst_h265_dpb_add              (GstH265Dpb * dpb,
156                                      GstH265Picture * picture);
157
158 GST_CODECS_API
159 void  gst_h265_dpb_delete_unused    (GstH265Dpb * dpb);
160
161 GST_CODECS_API
162 void  gst_h265_dpb_delete_by_poc    (GstH265Dpb * dpb,
163                                      gint poc);
164
165 GST_CODECS_API
166 gint  gst_h265_dpb_num_ref_pictures (GstH265Dpb * dpb);
167
168 GST_CODECS_API
169 void  gst_h265_dpb_mark_all_non_ref (GstH265Dpb * dpb);
170
171 GST_CODECS_API
172 GstH265Picture * gst_h265_dpb_get_ref_by_poc       (GstH265Dpb * dpb,
173                                                     gint poc);
174
175 GST_CODECS_API
176 GstH265Picture * gst_h265_dpb_get_ref_by_poc_lsb   (GstH265Dpb * dpb,
177                                                     gint poc_lsb);
178
179 GST_CODECS_API
180 GstH265Picture * gst_h265_dpb_get_short_ref_by_poc (GstH265Dpb * dpb,
181                                                     gint poc);
182
183 GST_CODECS_API
184 GstH265Picture * gst_h265_dpb_get_long_ref_by_poc  (GstH265Dpb * dpb,
185                                                     gint poc);
186
187 GST_CODECS_API
188 void  gst_h265_dpb_get_pictures_not_outputted  (GstH265Dpb * dpb,
189                                                 GList ** out);
190
191 GST_CODECS_API
192 GArray * gst_h265_dpb_get_pictures_all         (GstH265Dpb * dpb);
193
194 GST_CODECS_API
195 gint  gst_h265_dpb_get_size   (GstH265Dpb * dpb);
196
197 GST_CODECS_API
198 gboolean gst_h265_dpb_is_full (GstH265Dpb * dpb);
199
200 G_END_DECLS
201
202 #endif /* __GST_H265_PICTURE_H__ */