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