1 /* GStreamer
2 * Copyright (C) 2020 Intel Corporation
3 * Author: He Junyan <junyan.he@intel.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #ifndef __GST_MPEG2_PICTURE_H__
22 #define __GST_MPEG2_PICTURE_H__
23
24 #include <gst/codecs/codecs-prelude.h>
25 #include <gst/codecparsers/gstmpegvideoparser.h>
26 #include <gst/video/video.h>
27
28 G_BEGIN_DECLS
29
30 /**
31 * GST_TYPE_MPEG2_PICTURE:
32 *
33 * Since: 1.20
34 */
35 #define GST_TYPE_MPEG2_PICTURE (gst_mpeg2_picture_get_type())
36 /**
37 * GST_IS_MPEG2_PICTURE:
38 *
39 * Since: 1.20
40 */
41 #define GST_IS_MPEG2_PICTURE(obj) (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_MPEG2_PICTURE))
42 /**
43 * GST_MPEG2_PICTURE:
44 *
45 * Since: 1.20
46 */
47 #define GST_MPEG2_PICTURE(obj) ((GstMpeg2Picture *)obj)
48
49 typedef struct _GstMpeg2Slice GstMpeg2Slice;
50 typedef struct _GstMpeg2Picture GstMpeg2Picture;
51
52 /**
53 * GstMpeg2Slice:
54 *
55 * Since: 1.20
56 */
57 struct _GstMpeg2Slice
58 {
59 /*< private >*/
60 GstMpegVideoQuantMatrixExt *quant_matrix; /* The parameter set */
61 GstMpegVideoPictureHdr *pic_hdr;
62 GstMpegVideoPictureExt *pic_ext;
63
64 GstMpegVideoSliceHdr header;
65
66 /* parsed video packet (doesn't take ownership of raw data) */
67 GstMpegVideoPacket packet;
68 /* offset of the start code for the slice */
69 guint sc_offset;
70 /* size, including the start code */
71 guint size;
72 };
73
74 /**
75 * GstMpeg2Picture:
76 *
77 * Since: 1.20
78 */
79 struct _GstMpeg2Picture
80 {
81 /*< private >*/
82 GstMiniObject parent;
83
84 /* From GstVideoCodecFrame */
85 guint32 system_frame_number;
86 gboolean needed_for_output;
87 /* For interlaced streams */
88 GstMpeg2Picture *first_field;
89
90 GstVideoBufferFlags buffer_flags;
91
92 gint pic_order_cnt;
93 gint tsn;
94 GstMpegVideoPictureStructure structure;
95 GstMpegVideoPictureType type;
96
97 gpointer user_data;
98 GDestroyNotify notify;
99 };
100
101 /**
102 * GST_MPEG2_PICTURE_IS_REF:
103 * @picture: a #GstMpeg2Picture
104 *
105 * Check whether @picture's type is I or P
106 *
107 * Since: 1.20
108 */
109 #define GST_MPEG2_PICTURE_IS_REF(picture) \
110 (((GstMpeg2Picture *) picture)->type == GST_MPEG_VIDEO_PICTURE_TYPE_I || \
111 ((GstMpeg2Picture *) picture)->type == GST_MPEG_VIDEO_PICTURE_TYPE_P)
112
113 GST_CODECS_API
114 GType gst_mpeg2_picture_get_type (void);
115
116 GST_CODECS_API
117 GstMpeg2Picture * gst_mpeg2_picture_new (void);
118
119 static inline GstMpeg2Picture *
gst_mpeg2_picture_ref(GstMpeg2Picture * picture)120 gst_mpeg2_picture_ref (GstMpeg2Picture * picture)
121 {
122 return (GstMpeg2Picture *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (picture));
123 }
124
125 static inline void
gst_mpeg2_picture_unref(GstMpeg2Picture * picture)126 gst_mpeg2_picture_unref (GstMpeg2Picture * picture)
127 {
128 gst_mini_object_unref (GST_MINI_OBJECT_CAST (picture));
129 }
130
131 static inline gboolean
gst_mpeg2_picture_replace(GstMpeg2Picture ** old_picture,GstMpeg2Picture * new_picture)132 gst_mpeg2_picture_replace (GstMpeg2Picture ** old_picture,
133 GstMpeg2Picture * new_picture)
134 {
135 return gst_mini_object_replace ((GstMiniObject **) old_picture,
136 (GstMiniObject *) new_picture);
137 }
138
139 static inline void
gst_mpeg2_picture_clear(GstMpeg2Picture ** picture)140 gst_mpeg2_picture_clear (GstMpeg2Picture ** picture)
141 {
142 if (picture && *picture) {
143 gst_mpeg2_picture_unref (*picture);
144 *picture = NULL;
145 }
146 }
147
148 GST_CODECS_API
149 void gst_mpeg2_picture_set_user_data (GstMpeg2Picture * picture,
150 gpointer user_data,
151 GDestroyNotify notify);
152
153 GST_CODECS_API
154 gpointer gst_mpeg2_picture_get_user_data (GstMpeg2Picture * picture);
155
156
157 /**
158 * GstMpeg2Dpb:
159 *
160 * Since: 1.20
161 */
162 typedef struct _GstMpeg2Dpb GstMpeg2Dpb;
163
164 GST_CODECS_API
165 GstMpeg2Dpb * gst_mpeg2_dpb_new (void);
166
167 GST_CODECS_API
168 void gst_mpeg2_dpb_free (GstMpeg2Dpb * dpb);
169
170 GST_CODECS_API
171 void gst_mpeg2_dpb_clear (GstMpeg2Dpb * dpb);
172
173 GST_CODECS_API
174 void gst_mpeg2_dpb_add (GstMpeg2Dpb * dpb,
175 GstMpeg2Picture * picture);
176 GST_CODECS_API
177 GstMpeg2Picture * gst_mpeg2_dpb_bump (GstMpeg2Dpb * dpb);
178
179 GST_CODECS_API
180 gboolean gst_mpeg2_dpb_need_bump (GstMpeg2Dpb * dpb);
181
182 GST_CODECS_API
183 void gst_mpeg2_dpb_get_neighbours (GstMpeg2Dpb * dpb,
184 GstMpeg2Picture * picture,
185 GstMpeg2Picture ** prev_picture_ptr,
186 GstMpeg2Picture ** next_picture_ptr);
187
188 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstMpeg2Picture, gst_mpeg2_picture_unref)
189
190 G_END_DECLS
191
192 #endif /* __GST_MPEG2_PICTURE_H__ */
193