summaryrefslogtreecommitdiff
path: root/gst-libs/gst/codecs/gsth264picture.h
blob: bdf99b5b088b6c401d9dcf3b574b37a56f362ce2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/* GStreamer
 * Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __GST_H264_PICTURE_H__
#define __GST_H264_PICTURE_H__

#include <gst/codecs/codecs-prelude.h>
#include <gst/codecparsers/gsth264parser.h>
#include <gst/video/video.h>

G_BEGIN_DECLS

#define GST_TYPE_H264_PICTURE     (gst_h264_picture_get_type())
#define GST_IS_H264_PICTURE(obj)  (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_H264_PICTURE))
#define GST_H264_PICTURE(obj)     ((GstH264Picture *)obj)
#define GST_H264_PICTURE_CAST(obj) (GST_H264_PICTURE(obj))

typedef struct _GstH264Slice GstH264Slice;
typedef struct _GstH264Picture GstH264Picture;

/* As specified in A.3.1 h) and A.3.2 f) */
#define GST_H264_DPB_MAX_SIZE 16

/**
 * GST_H264_PICTURE_IS_REF:
 * @picture: a #GstH264Picture
 *
 * Check whether @picture is used for short-term or long-term reference
 *
 * Since: 1.20
 */
#define GST_H264_PICTURE_IS_REF(picture) \
    ((picture)->ref != GST_H264_PICTURE_REF_NONE)

/**
 * GST_H264_PICTURE_IS_SHORT_TERM_REF:
 * @picture: a #GstH264Picture
 *
 * Check whether @picture is used for short-term reference
 *
 * Since: 1.20
 */
#define GST_H264_PICTURE_IS_SHORT_TERM_REF(picture) \
    ((picture)->ref == GST_H264_PICTURE_REF_SHORT_TERM)

/**
 * GST_H264_PICTURE_IS_LONG_TERM_REF:
 * @picture: a #GstH264Picture
 *
 * Check whether @picture is used for long-term reference
 *
 * Since: 1.20
 */
#define GST_H264_PICTURE_IS_LONG_TERM_REF(picture) \
    ((picture)->ref == GST_H264_PICTURE_REF_LONG_TERM)

/**
 * GST_H264_PICTURE_IS_FRAME:
 * @picture: a #GstH264Picture
 *
 * Check whether @picture is a frame (not a field picture)
 *
 * Since: 1.20
 */
#define GST_H264_PICTURE_IS_FRAME(picture) \
    ((picture)->field == GST_H264_PICTURE_FIELD_FRAME)

struct _GstH264Slice
{
  GstH264SliceHdr header;

  /* parsed nal unit (doesn't take ownership of raw data) */
  GstH264NalUnit nalu;
};

typedef enum
{
  GST_H264_PICTURE_FIELD_FRAME,
  GST_H264_PICTURE_FIELD_TOP_FIELD,
  GST_H264_PICTURE_FIELD_BOTTOM_FIELD,
} GstH264PictureField;

/**
 * GstH264PictureReference:
 * @GST_H264_PICTURE_REF_NONE: Not used for reference picture
 * @GST_H264_PICTURE_REF_SHORT_TERM: Used for short-term reference picture
 * @GST_H264_PICTURE_REF_LONG_TERM: Used for long-term reference picture
 *
 * Since: 1.20
 */
typedef enum
{
  GST_H264_PICTURE_REF_NONE = 0,
  GST_H264_PICTURE_REF_SHORT_TERM,
  GST_H264_PICTURE_REF_LONG_TERM,
} GstH264PictureReference;

struct _GstH264Picture
{
  /*< private >*/
  GstMiniObject parent;

  GstH264SliceType type;

  /* From GstVideoCodecFrame */
  guint32 system_frame_number;

  guint8 pic_order_cnt_type;  /* SPS */
  gint32 top_field_order_cnt;
  gint32 bottom_field_order_cnt;

  gint pic_order_cnt;
  gint pic_order_cnt_msb;
  gint pic_order_cnt_lsb;
  gint delta_pic_order_cnt_bottom;
  gint delta_pic_order_cnt0;
  gint delta_pic_order_cnt1;

  gint pic_num;
  gint long_term_pic_num;
  gint frame_num;
  gint frame_num_offset;
  gint frame_num_wrap;
  gint long_term_frame_idx;

  gint nal_ref_idc;
  gboolean idr;
  gint idr_pic_id;
  GstH264PictureReference ref;
  gboolean needed_for_output;
  gboolean mem_mgmt_5;

  gboolean nonexisting;

  GstH264PictureField field;

  GstH264DecRefPicMarking dec_ref_pic_marking;

  /* For interlaced decoding */
  gboolean second_field;
  GstH264Picture * other_field;

  GstVideoBufferFlags buffer_flags;

  gpointer user_data;
  GDestroyNotify notify;
};

GST_CODECS_API
GType gst_h264_picture_get_type (void);

GST_CODECS_API
GstH264Picture * gst_h264_picture_new (void);

static inline GstH264Picture *
gst_h264_picture_ref (GstH264Picture * picture)
{
  return (GstH264Picture *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (picture));
}

static inline void
gst_h264_picture_unref (GstH264Picture * picture)
{
  gst_mini_object_unref (GST_MINI_OBJECT_CAST (picture));
}

static inline gboolean
gst_h264_picture_replace (GstH264Picture ** old_picture,
    GstH264Picture * new_picture)
{
  return gst_mini_object_replace ((GstMiniObject **) old_picture,
      (GstMiniObject *) new_picture);
}

static inline void
gst_h264_picture_clear (GstH264Picture ** picture)
{
  if (picture && *picture) {
    gst_h264_picture_unref (*picture);
    *picture = NULL;
  }
}

GST_CODECS_API
void gst_h264_picture_set_user_data (GstH264Picture * picture,
                                     gpointer user_data,
                                     GDestroyNotify notify);

GST_CODECS_API
gpointer gst_h264_picture_get_user_data (GstH264Picture * picture);

/*******************
 * GstH264Dpb *
 *******************/
typedef struct _GstH264Dpb GstH264Dpb;

GST_CODECS_API
GstH264Dpb * gst_h264_dpb_new (void);

GST_CODECS_API
void  gst_h264_dpb_set_max_num_frames (GstH264Dpb * dpb,
                                       gint max_num_frames);

GST_CODECS_API
gint gst_h264_dpb_get_max_num_frames  (GstH264Dpb * dpb);

GST_CODECS_API
void gst_h264_dpb_set_interlaced      (GstH264Dpb * dpb,
                                       gboolean interlaced);

GST_CODECS_API
gboolean gst_h264_dpb_get_interlaced  (GstH264Dpb * dpb);

GST_CODECS_API
void  gst_h264_dpb_free             (GstH264Dpb * dpb);

GST_CODECS_API
void  gst_h264_dpb_clear            (GstH264Dpb * dpb);

GST_CODECS_API
void  gst_h264_dpb_add              (GstH264Dpb * dpb,
                                     GstH264Picture * picture);

GST_CODECS_API
void  gst_h264_dpb_delete_unused    (GstH264Dpb * dpb);

GST_CODECS_API
gint  gst_h264_dpb_num_ref_frames (GstH264Dpb * dpb);

GST_CODECS_API
void  gst_h264_dpb_mark_all_non_ref (GstH264Dpb * dpb);

GST_CODECS_API
GstH264Picture * gst_h264_dpb_get_short_ref_by_pic_num (GstH264Dpb * dpb,
                                                        gint pic_num);

GST_CODECS_API
GstH264Picture * gst_h264_dpb_get_long_ref_by_long_term_pic_num (GstH264Dpb * dpb,
                                                                 gint long_term_pic_num);

GST_CODECS_API
GstH264Picture * gst_h264_dpb_get_lowest_frame_num_short_ref (GstH264Dpb * dpb);

GST_CODECS_API
void  gst_h264_dpb_get_pictures_short_term_ref (GstH264Dpb * dpb,
                                                gboolean include_non_existing,
                                                gboolean include_second_field,
                                                GArray * out);

GST_CODECS_API
void  gst_h264_dpb_get_pictures_long_term_ref  (GstH264Dpb * dpb,
                                                gboolean include_second_field,
                                                GArray * out);

GST_CODECS_API
GArray * gst_h264_dpb_get_pictures_all         (GstH264Dpb * dpb);

GST_CODECS_API
GstH264Picture * gst_h264_dpb_get_picture      (GstH264Dpb * dpb,
                                                guint32 system_frame_number);

GST_CODECS_API
gint  gst_h264_dpb_get_size   (GstH264Dpb * dpb);

GST_CODECS_API
gboolean gst_h264_dpb_needs_bump (GstH264Dpb * dpb,
                                  guint32 max_num_reorder_frames,
                                  gboolean low_latency);

GST_CODECS_API
GstH264Picture * gst_h264_dpb_bump (GstH264Dpb * dpb,
                                    gboolean drain);

GST_CODECS_API
gboolean         gst_h264_dpb_perform_memory_management_control_operation (GstH264Dpb * dpb,
                                                                           GstH264RefPicMarking *ref_pic_marking,
                                                                           GstH264Picture * picture);

/* Internal methods */
void  gst_h264_picture_set_reference (GstH264Picture * picture,
                                      GstH264PictureReference reference,
                                      gboolean other_field);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstH264Picture, gst_h264_picture_unref)

G_END_DECLS

#endif /* __GST_H264_PICTURE_H__ */