encoder: fix subclassing process.
[vaapi:gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapiencoder_priv.h
1 /*
2  *  gstvaapiencoder_priv.h - VA encoder abstraction (private definitions)
3  *
4  *  Copyright (C) 2013 Intel Corporation
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public License
8  *  as published by the Free Software Foundation; either version 2.1
9  *  of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free
18  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301 USA
20  */
21
22 #ifndef GST_VAAPI_ENCODER_PRIV_H
23 #define GST_VAAPI_ENCODER_PRIV_H
24
25 #include <gst/vaapi/gstvaapiencoder.h>
26 #include <gst/vaapi/gstvaapiencoder_objects.h>
27 #include <gst/vaapi/gstvaapicontext.h>
28 #include <gst/vaapi/gstvaapivideopool.h>
29 #include <gst/video/gstvideoutils.h>
30
31 G_BEGIN_DECLS
32
33 #define GST_VAAPI_ENCODER_CLASS(klass) \
34     ((GstVaapiEncoderClass *)(klass))
35
36 #define GST_IS_VAAPI_ENCODER_CLASS(klass) \
37     ((klass) != NULL)
38
39 #define GST_VAAPI_ENCODER_GET_CLASS(obj) \
40     GST_VAAPI_ENCODER_CLASS(GST_VAAPI_MINI_OBJECT_GET_CLASS(obj))
41
42 /* Get GstVaapiDisplay* */
43 #define GST_VAAPI_ENCODER_DISPLAY(encoder) \
44     (GST_VAAPI_ENCODER_CAST(encoder)->display)
45
46 /* Get VADisplay */
47 #define GST_VAAPI_ENCODER_VA_DISPLAY(encoder) \
48     (GST_VAAPI_ENCODER_CAST(encoder)->va_display)
49
50 /* Get GstVaapiContext* */
51 #define GST_VAAPI_ENCODER_CONTEXT(encoder) \
52     (GST_VAAPI_ENCODER_CAST(encoder)->context)
53
54 /* Get VAContext */
55 #define GST_VAAPI_ENCODER_VA_CONTEXT(encoder) \
56     (GST_VAAPI_ENCODER_CAST(encoder)->va_context)
57
58 #define GST_VAAPI_ENCODER_VIDEO_INFO(encoder) (GST_VAAPI_ENCODER_CAST(encoder)->video_info)
59 #define GST_VAAPI_ENCODER_CAPS(encoder)       (GST_VAAPI_ENCODER_CAST(encoder)->caps)
60 #define GST_VAAPI_ENCODER_WIDTH(encoder)      (GST_VAAPI_ENCODER_CAST(encoder)->video_info.width)
61 #define GST_VAAPI_ENCODER_HEIGHT(encoder)     (GST_VAAPI_ENCODER_CAST(encoder)->video_info.height)
62 #define GST_VAAPI_ENCODER_FPS_N(encoder)      (GST_VAAPI_ENCODER_CAST(encoder)->video_info.fps_n)
63 #define GST_VAAPI_ENCODER_FPS_D(encoder)      (GST_VAAPI_ENCODER_CAST(encoder)->video_info.fps_d)
64 #define GST_VAAPI_ENCODER_RATE_CONTROL(encoder)   \
65     (GST_VAAPI_ENCODER_CAST(encoder)->rate_control)
66
67 #define GST_VAAPI_ENCODER_LOG_ERROR(...)   GST_ERROR( __VA_ARGS__)
68 #define GST_VAAPI_ENCODER_LOG_WARNING(...) GST_WARNING( __VA_ARGS__)
69 #define GST_VAAPI_ENCODER_LOG_DEBUG(...)   GST_DEBUG( __VA_ARGS__)
70 #define GST_VAAPI_ENCODER_LOG_INFO(...)    GST_INFO( __VA_ARGS__)
71
72 #define GST_VAAPI_ENCODER_CHECK_STATUS(exp, err_num, err_reason, ...)   \
73   if (!(exp)) {                                                         \
74     ret = err_num;                                                      \
75     GST_VAAPI_ENCODER_LOG_ERROR(err_reason, ## __VA_ARGS__);            \
76     goto end;                                                           \
77   }
78
79 typedef struct _GstVaapiEncoderClass GstVaapiEncoderClass;
80
81 struct _GstVaapiEncoder
82 {
83   /*< private > */
84   GstVaapiMiniObject parent_instance;
85
86   GstVaapiDisplay *display;
87   GstVaapiContext *context;
88   GstCaps *caps;
89
90   VADisplay va_display;
91   VAContextID va_context;
92   GstVideoInfo video_info;
93   GstVaapiRateControl rate_control;
94
95   GMutex lock;
96   GCond surface_free;
97   GCond codedbuf_free;
98   guint codedbuf_size;
99   GstVaapiVideoPool *codedbuf_pool;
100
101   /* queue for sync */
102   GQueue sync_pictures;
103   GCond sync_ready;
104 };
105
106 struct _GstVaapiEncoderClass
107 {
108   GstVaapiMiniObjectClass parent_class;
109
110   gboolean              (*init)         (GstVaapiEncoder * encoder);
111   void                  (*finalize)     (GstVaapiEncoder * encoder);
112
113   GstCaps *             (*set_format)   (GstVaapiEncoder * encoder,
114                                          GstVideoCodecState * in_state,
115                                          GstCaps * ref_caps);
116
117   gboolean              (*get_context_info) (GstVaapiEncoder * encoder,
118                                              GstVaapiContextInfo * info);
119
120   GstVaapiEncoderStatus (*reordering)   (GstVaapiEncoder * encoder,
121                                          GstVideoCodecFrame * in,
122                                          gboolean flush,
123                                          GstVaapiEncPicture ** out);
124   GstVaapiEncoderStatus (*encode)       (GstVaapiEncoder * encoder,
125                                          GstVaapiEncPicture * picture,
126                                          GstVaapiCodedBufferProxy * codedbuf);
127
128   GstVaapiEncoderStatus (*flush)        (GstVaapiEncoder * encoder);
129
130   /* get_codec_data can be NULL */
131   GstVaapiEncoderStatus (*get_codec_data) (GstVaapiEncoder * encoder,
132                                            GstBuffer ** codec_data);
133 };
134
135 #define GST_VAAPI_ENCODER_CLASS_HOOK(codec, func) \
136   .func = G_PASTE (G_PASTE (G_PASTE (gst_vaapi_encoder_,codec),_), func)
137
138 #define GST_VAAPI_ENCODER_CLASS_INIT_BASE(CODEC)                \
139   .parent_class = {                                             \
140     .size = sizeof (G_PASTE (GstVaapiEncoder, CODEC)),          \
141     .finalize = (GDestroyNotify) gst_vaapi_encoder_finalize     \
142   }
143
144 #define GST_VAAPI_ENCODER_CLASS_INIT(CODEC, codec)              \
145   GST_VAAPI_ENCODER_CLASS_INIT_BASE (CODEC),                    \
146     GST_VAAPI_ENCODER_CLASS_HOOK (codec, init),                 \
147     GST_VAAPI_ENCODER_CLASS_HOOK (codec, finalize),             \
148     GST_VAAPI_ENCODER_CLASS_HOOK (codec, set_format),           \
149     GST_VAAPI_ENCODER_CLASS_HOOK (codec, get_context_info),     \
150     GST_VAAPI_ENCODER_CLASS_HOOK (codec, reordering),           \
151     GST_VAAPI_ENCODER_CLASS_HOOK (codec, encode),               \
152     GST_VAAPI_ENCODER_CLASS_HOOK (codec, flush)
153
154 G_GNUC_INTERNAL
155 GstVaapiEncoder *
156 gst_vaapi_encoder_new (const GstVaapiEncoderClass * klass,
157     GstVaapiDisplay * display);
158
159 G_GNUC_INTERNAL
160 void
161 gst_vaapi_encoder_finalize (GstVaapiEncoder * encoder);
162
163 GstVaapiSurfaceProxy *
164 gst_vaapi_encoder_create_surface (GstVaapiEncoder *
165     encoder);
166
167 void
168 gst_vaapi_encoder_release_surface (GstVaapiEncoder * encoder,
169     GstVaapiSurfaceProxy * surface);
170
171 G_END_DECLS
172
173 #endif /* GST_VAAPI_ENCODER_PRIV_H */