codecs: vp9: Drop frames on non-keyframe format change
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / gst-libs / gst / codecs / gstvp9decoder.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_VP9_DECODER_H__
21 #define __GST_VP9_DECODER_H__
22
23 #include <gst/codecs/codecs-prelude.h>
24
25 #include <gst/video/video.h>
26 #include <gst/codecs/gstvp9picture.h>
27
28 G_BEGIN_DECLS
29
30 #define GST_TYPE_VP9_DECODER            (gst_vp9_decoder_get_type())
31 #define GST_VP9_DECODER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VP9_DECODER,GstVp9Decoder))
32 #define GST_VP9_DECODER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VP9_DECODER,GstVp9DecoderClass))
33 #define GST_VP9_DECODER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_VP9_DECODER,GstVp9DecoderClass))
34 #define GST_IS_VP9_DECODER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VP9_DECODER))
35 #define GST_IS_VP9_DECODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VP9_DECODER))
36 #define GST_VP9_DECODER_CAST(obj)       ((GstVP9Decoder*)obj)
37
38 typedef struct _GstVp9Decoder GstVp9Decoder;
39 typedef struct _GstVp9DecoderClass GstVp9DecoderClass;
40 typedef struct _GstVp9DecoderPrivate GstVp9DecoderPrivate;
41
42 /**
43  * GstVp9Decoder:
44  *
45  * The opaque #GstVp9Decoder data structure.
46  */
47 struct _GstVp9Decoder
48 {
49   /*< private >*/
50   GstVideoDecoder parent;
51
52   /*< protected >*/
53   GstVideoCodecState * input_state;
54   gboolean parse_compressed_headers;
55
56   /*< private >*/
57   GstVp9DecoderPrivate *priv;
58   gpointer padding[GST_PADDING_LARGE];
59 };
60
61 /**
62  * GstVp9DecoderClass:
63  */
64 struct _GstVp9DecoderClass
65 {
66   GstVideoDecoderClass parent_class;
67
68   /**
69    * GstVp9DecoderClass::new_sequence:
70    *
71    * Notifies subclass of video sequence update such as resolution, bitdepth,
72    * profile.
73    *
74    * Since: 1.18
75    */
76   GstFlowReturn   (*new_sequence)      (GstVp9Decoder * decoder,
77                                         const GstVp9FrameHeader *frame_hdr);
78
79   /**
80    * GstVp9DecoderClass::new_picture:
81    * @decoder: a #GstVp9Decoder
82    * @frame: (transfer none): a #GstVideoCodecFrame
83    * @picture: (transfer none): a #GstVp9Picture
84    *
85    * Optional. Called whenever new #GstVp9Picture is created.
86    * Subclass can set implementation specific user data on the #GstVp9Picture
87    * via gst_vp9_picture_set_user_data()
88    *
89    * Since: 1.18
90    */
91   GstFlowReturn   (*new_picture)       (GstVp9Decoder * decoder,
92                                         GstVideoCodecFrame * frame,
93                                         GstVp9Picture * picture);
94
95   /**
96    * GstVp9DecoderClass::duplicate_picture:
97    * @decoder: a #GstVp9Decoder
98    * @frame: (transfer none): a #GstVideoCodecFrame
99    * @picture: (transfer none): a #GstVp9Picture to be duplicated
100    *
101    * Optional. Called to duplicate @picture when show_existing_frame flag is set
102    * in the parsed vp9 frame header. Returned #GstVp9Picture from this method
103    * should hold already decoded picture data corresponding to the @picture,
104    * since the returned #GstVp9Picture from this method will be passed to
105    * the output_picture method immediately without additional decoding process.
106    *
107    * If this method is not implemented by subclass, baseclass will drop
108    * current #GstVideoCodecFrame without additional processing for the current
109    * frame.
110    *
111    * Returns: (transfer full): a #GstVp9Picture or %NULL if failed to duplicate
112    * @picture.
113    *
114    * Since: 1.18
115    */
116   GstVp9Picture * (*duplicate_picture) (GstVp9Decoder * decoder,
117                                         GstVideoCodecFrame * frame,
118                                         GstVp9Picture * picture);
119
120   /**
121    * GstVp9DecoderClass::start_picture:
122    * @decoder: a #GstVp9Decoder
123    * @picture: (transfer none): a #GstVp9Picture
124    *
125    * Optional. Called to notify subclass to prepare decoding process for
126    * @picture
127    *
128    * Since: 1.18
129    */
130   GstFlowReturn   (*start_picture)     (GstVp9Decoder * decoder,
131                                         GstVp9Picture * picture);
132
133   /**
134    * GstVp9DecoderClass::decode_picture:
135    * @decoder: a #GstVp9Decoder
136    * @picture: (transfer none): a #GstVp9Picture to decoder
137    * @dpb: (transfer none): a #GstVp9Dpb
138    *
139    * Called to notify decoding for subclass to decoder given @picture with
140    * given @dpb
141    *
142    * Since: 1.18
143    */
144   GstFlowReturn   (*decode_picture)    (GstVp9Decoder * decoder,
145                                         GstVp9Picture * picture,
146                                         GstVp9Dpb * dpb);
147
148   /**
149    * GstVp9DecoderClass::end_picture:
150    * @decoder: a #GstVp9Decoder
151    * @picture: (transfer none): a #GstVp9Picture
152    *
153    * Optional. Called per one #GstVp9Picture to notify subclass to finish
154    * decoding process for the #GstVp9Picture
155    *
156    * Since: 1.18
157    */
158   GstFlowReturn   (*end_picture)       (GstVp9Decoder * decoder,
159                                         GstVp9Picture * picture);
160
161   /**
162    * GstVp9DecoderClass::output_picture:
163    * @decoder: a #GstVp9Decoder
164    * @frame: (transfer full): a #GstVideoCodecFrame
165    * @picture: (transfer full): a #GstVp9Picture
166    *
167    * Called to notify @picture is ready to be outputted.
168    *
169    * Since: 1.18
170    */
171   GstFlowReturn   (*output_picture)    (GstVp9Decoder * decoder,
172                                         GstVideoCodecFrame * frame,
173                                         GstVp9Picture * picture);
174
175   /**
176    * GstVp9DecoderClass::get_preferred_output_delay:
177    * @decoder: a #GstVp9Decoder
178    * @is_live: whether upstream is live or not
179    *
180    * Optional. Retrieve the preferred output delay from child classes.
181    * controls how many frames to delay when calling
182    * GstVp9DecoderClass::output_picture
183    *
184    * Returns: the number of perferred delayed output frame
185    *
186    * Since: 1.20
187    */
188   guint           (*get_preferred_output_delay)   (GstVp9Decoder * decoder,
189                                                    gboolean is_live);
190
191   /*< private >*/
192   gpointer padding[GST_PADDING_LARGE];
193 };
194
195 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVp9Decoder, gst_object_unref)
196
197 GST_CODECS_API
198 GType gst_vp9_decoder_get_type (void);
199
200 GST_CODECS_API
201 void gst_vp9_decoder_set_non_keyframe_format_change_support (GstVp9Decoder * decoder,
202                                                              gboolean support);
203
204 G_END_DECLS
205
206 #endif /* __GST_VP9_DECODER_H__ */