1 /* GStreamer
2 * Copyright (C) 2020 He Junyan <junyan.he@intel.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 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include "gstav1picture.h"
25
26 GST_DEBUG_CATEGORY_EXTERN (gst_av1_decoder_debug);
27 #define GST_CAT_DEFAULT gst_av1_decoder_debug
28
29 GST_DEFINE_MINI_OBJECT_TYPE (GstAV1Picture, gst_av1_picture);
30
31 static void
_gst_av1_picture_free(GstAV1Picture * picture)32 _gst_av1_picture_free (GstAV1Picture * picture)
33 {
34 GST_TRACE ("Free picture %p", picture);
35
36 if (picture->notify)
37 picture->notify (picture->user_data);
38
39 g_free (picture);
40 }
41
42 /**
43 * gst_av1_picture_new:
44 *
45 * Create new #GstAV1Picture
46 *
47 * Returns: a new #GstAV1Picture
48 *
49 * Since: 1.20
50 */
51 GstAV1Picture *
gst_av1_picture_new(void)52 gst_av1_picture_new (void)
53 {
54 GstAV1Picture *pic;
55
56 pic = g_new0 (GstAV1Picture, 1);
57
58 gst_mini_object_init (GST_MINI_OBJECT_CAST (pic), 0,
59 GST_TYPE_AV1_PICTURE, NULL, NULL,
60 (GstMiniObjectFreeFunction) _gst_av1_picture_free);
61
62 GST_TRACE ("New picture %p", pic);
63
64 return pic;
65 }
66
67 /**
68 * gst_av1_picture_set_user_data:
69 * @picture: a #GstAV1Picture
70 * @user_data: private data
71 * @notify: (closure user_data): a #GDestroyNotify
72 *
73 * Sets @user_data on the picture and the #GDestroyNotify that will be called when
74 * the picture is freed.
75 *
76 * If a @user_data was previously set, then the previous set @notify will be called
77 * before the @user_data is replaced.
78 *
79 * Since: 1.20
80 */
81 void
gst_av1_picture_set_user_data(GstAV1Picture * picture,gpointer user_data,GDestroyNotify notify)82 gst_av1_picture_set_user_data (GstAV1Picture * picture, gpointer user_data,
83 GDestroyNotify notify)
84 {
85 g_return_if_fail (GST_IS_AV1_PICTURE (picture));
86
87 if (picture->notify)
88 picture->notify (picture->user_data);
89
90 picture->user_data = user_data;
91 picture->notify = notify;
92 }
93
94 /**
95 * gst_av1_picture_get_user_data:
96 * @picture: a #GstAV1Picture
97 *
98 * Gets private data set on the picture via
99 * gst_av1_picture_set_user_data() previously.
100 *
101 * Returns: (transfer none): The previously set user_data
102 *
103 * Since: 1.20
104 */
105 gpointer
gst_av1_picture_get_user_data(GstAV1Picture * picture)106 gst_av1_picture_get_user_data (GstAV1Picture * picture)
107 {
108 return picture->user_data;
109 }
110
111 /**
112 * gst_av1_dpb_new: (skip)
113 *
114 * Create new #GstAV1Dpb
115 *
116 * Returns: a new #GstAV1Dpb
117 *
118 * Since: 1.20
119 */
120 GstAV1Dpb *
gst_av1_dpb_new(void)121 gst_av1_dpb_new (void)
122 {
123 GstAV1Dpb *dpb;
124
125 dpb = g_new0 (GstAV1Dpb, 1);
126
127 return dpb;
128 }
129
130 /**
131 * gst_av1_dpb_free:
132 * @dpb: a #GstAV1Dpb to free
133 *
134 * Free the @dpb
135 *
136 * Since: 1.20
137 */
138 void
gst_av1_dpb_free(GstAV1Dpb * dpb)139 gst_av1_dpb_free (GstAV1Dpb * dpb)
140 {
141 g_return_if_fail (dpb != NULL);
142
143 gst_av1_dpb_clear (dpb);
144 g_free (dpb);
145 }
146
147 /**
148 * gst_av1_dpb_clear:
149 * @dpb: a #GstAV1Dpb
150 *
151 * Clear all stored #GstAV1Picture
152 *
153 * Since: 1.20
154 */
155 void
gst_av1_dpb_clear(GstAV1Dpb * dpb)156 gst_av1_dpb_clear (GstAV1Dpb * dpb)
157 {
158 gint i;
159
160 g_return_if_fail (dpb != NULL);
161
162 for (i = 0; i < GST_AV1_NUM_REF_FRAMES; i++)
163 gst_av1_picture_clear (&dpb->pic_list[i]);
164 }
165
166 /**
167 * gst_av1_dpb_add:
168 * @dpb: a #GstAV1Dpb
169 * @picture: (transfer full): a #GstAV1Picture
170 *
171 * Store the @picture
172 *
173 * Since: 1.20
174 */
175 void
gst_av1_dpb_add(GstAV1Dpb * dpb,GstAV1Picture * picture)176 gst_av1_dpb_add (GstAV1Dpb * dpb, GstAV1Picture * picture)
177 {
178 GstAV1FrameHeaderOBU *fh;
179 guint i;
180
181 g_return_if_fail (dpb != NULL);
182 g_return_if_fail (GST_IS_AV1_PICTURE (picture));
183
184 fh = &picture->frame_hdr;
185
186 for (i = 0; i < GST_AV1_NUM_REF_FRAMES; i++) {
187 if ((fh->refresh_frame_flags >> i) & 1) {
188 GST_TRACE ("reference frame %p to ref slot:%d", picture, i);
189 gst_av1_picture_replace (&dpb->pic_list[i], picture);
190 }
191 }
192
193 gst_av1_picture_unref (picture);
194 }
195