Add initial infrastructure for video processing.
[platform/upstream/gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapidisplay_priv.h
1 /*
2  *  gstvaapidisplay_priv.h - Base VA display (private definitions)
3  *
4  *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5  *  Copyright (C) 2011-2012 Intel Corporation
6  *
7  *  This library is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU Lesser General Public License
9  *  as published by the Free Software Foundation; either version 2.1
10  *  of the License, or (at your option) any later version.
11  *
12  *  This library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public
18  *  License along with this library; if not, write to the Free
19  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  *  Boston, MA 02110-1301 USA
21  */
22
23 #ifndef GST_VAAPI_DISPLAY_PRIV_H
24 #define GST_VAAPI_DISPLAY_PRIV_H
25
26 #include <gst/vaapi/gstvaapidisplay.h>
27 #include <gst/vaapi/gstvaapidisplaycache.h>
28 #include "gstvaapiminiobject.h"
29
30 G_BEGIN_DECLS
31
32 #define GST_VAAPI_DISPLAY_CAST(display) \
33     ((GstVaapiDisplay *)(display))
34
35 #define GST_VAAPI_DISPLAY_GET_PRIVATE(display) \
36     (&GST_VAAPI_DISPLAY_CAST(display)->priv)
37
38 #define GST_VAAPI_DISPLAY_CLASS(klass) \
39     ((GstVaapiDisplayClass *)(klass))
40
41 #define GST_VAAPI_IS_DISPLAY_CLASS(klass) \
42     ((klass) != NULL)
43
44 #define GST_VAAPI_DISPLAY_GET_CLASS(obj) \
45     GST_VAAPI_DISPLAY_CLASS(GST_VAAPI_MINI_OBJECT_GET_CLASS(obj))
46
47 typedef struct _GstVaapiDisplayPrivate          GstVaapiDisplayPrivate;
48 typedef struct _GstVaapiDisplayClass            GstVaapiDisplayClass;
49 typedef enum _GstVaapiDisplayInitType           GstVaapiDisplayInitType;
50
51 typedef void     (*GstVaapiDisplayInitFunc)    (GstVaapiDisplay *display);
52 typedef gboolean (*GstVaapiDisplayBindFunc)    (GstVaapiDisplay *display,
53     gpointer native_dpy);
54 typedef gboolean (*GstVaapiDisplayOpenFunc)    (GstVaapiDisplay *display,
55     const gchar *name);
56 typedef void     (*GstVaapiDisplayCloseFunc)   (GstVaapiDisplay *display);
57 typedef void     (*GstVaapiDisplayLockFunc)    (GstVaapiDisplay *display);
58 typedef void     (*GstVaapiDisplayUnlockFunc)  (GstVaapiDisplay *display);
59 typedef void     (*GstVaapiDisplaySyncFunc)    (GstVaapiDisplay *display);
60 typedef void     (*GstVaapiDisplayFlushFunc)   (GstVaapiDisplay *display);
61 typedef gboolean (*GstVaapiDisplayGetInfoFunc) (GstVaapiDisplay *display,
62     GstVaapiDisplayInfo *info);
63 typedef void     (*GstVaapiDisplayGetSizeFunc) (GstVaapiDisplay *display,
64     guint *pwidth, guint *pheight);
65 typedef void     (*GstVaapiDisplayGetSizeMFunc)(GstVaapiDisplay *display,
66     guint *pwidth, guint *pheight);
67
68 /**
69  * GST_VAAPI_DISPLAY_VADISPLAY:
70  * @display_: a #GstVaapiDisplay
71  *
72  * Macro that evaluates to the #VADisplay of @display.
73  * This is an internal macro that does not do any run-time type check.
74  */
75 #undef  GST_VAAPI_DISPLAY_VADISPLAY
76 #define GST_VAAPI_DISPLAY_VADISPLAY(display_) \
77     GST_VAAPI_DISPLAY_GET_PRIVATE(display_)->display
78
79 /**
80  * GST_VAAPI_DISPLAY_LOCK:
81  * @display: a #GstVaapiDisplay
82  *
83  * Locks @display
84  */
85 #undef  GST_VAAPI_DISPLAY_LOCK
86 #define GST_VAAPI_DISPLAY_LOCK(display) \
87     gst_vaapi_display_lock(GST_VAAPI_DISPLAY_CAST(display))
88
89 /**
90  * GST_VAAPI_DISPLAY_UNLOCK:
91  * @display: a #GstVaapiDisplay
92  *
93  * Unlocks @display
94  */
95 #undef  GST_VAAPI_DISPLAY_UNLOCK
96 #define GST_VAAPI_DISPLAY_UNLOCK(display) \
97     gst_vaapi_display_unlock(GST_VAAPI_DISPLAY_CAST(display))
98
99 /**
100  * GST_VAAPI_DISPLAY_TYPE:
101  * @display: a #GstVaapiDisplay
102  *
103  * Returns the @display type
104  */
105 #undef  GST_VAAPI_DISPLAY_TYPE
106 #define GST_VAAPI_DISPLAY_TYPE(display) \
107     GST_VAAPI_DISPLAY_GET_PRIVATE(display)->display_type
108
109 /**
110  * GST_VAAPI_DISPLAY_TYPES:
111  * @display: a #GstVaapiDisplay
112  *
113  * Returns compatible @display types as a set of flags
114  */
115 #undef  GST_VAAPI_DISPLAY_TYPES
116 #define GST_VAAPI_DISPLAY_TYPES(display) \
117     gst_vaapi_display_get_display_types(GST_VAAPI_DISPLAY_CAST(display))
118
119 /**
120  * GST_VAAPI_DISPLAY_HAS_VPP:
121  * @display: a @GstVaapiDisplay
122  *
123  * Returns whether the @display supports video processing (VA/VPP)
124  */
125 #undef  GST_VAAPI_DISPLAY_HAS_VPP
126 #define GST_VAAPI_DISPLAY_HAS_VPP(display) \
127     (GST_VAAPI_DISPLAY_GET_PRIVATE(display)->has_vpp)
128
129 struct _GstVaapiDisplayPrivate {
130     GstVaapiDisplay    *parent;
131     GRecMutex           mutex;
132     GstVaapiDisplayType display_type;
133     VADisplay           display;
134     guint               width;
135     guint               height;
136     guint               width_mm;
137     guint               height_mm;
138     guint               par_n;
139     guint               par_d;
140     GArray             *decoders;
141     GArray             *encoders;
142     GArray             *image_formats;
143     GArray             *subpicture_formats;
144     GArray             *properties;
145     guint               use_foreign_display     : 1;
146     guint               has_vpp                 : 1;
147 };
148
149 /**
150  * GstVaapiDisplay:
151  *
152  * Base class for VA displays.
153  */
154 struct _GstVaapiDisplay {
155     /*< private >*/
156     GstVaapiMiniObject parent_instance;
157
158     GstVaapiDisplayPrivate priv;
159 };
160
161 /**
162  * GstVaapiDisplayClass:
163  * @open_display: virtual function to open a display
164  * @close_display: virtual function to close a display
165  * @lock: (optional) virtual function to lock a display
166  * @unlock: (optional) virtual function to unlock a display
167  * @sync: (optional) virtual function to sync a display
168  * @flush: (optional) virtual function to flush pending requests of a display
169  * @get_display: virtual function to retrieve the #GstVaapiDisplayInfo
170  * @get_size: virtual function to retrieve the display dimensions, in pixels
171  * @get_size_mm: virtual function to retrieve the display dimensions, in millimeters
172  *
173  * Base class for VA displays.
174  */
175 struct _GstVaapiDisplayClass {
176     /*< private >*/
177     GstVaapiMiniObjectClass parent_class;
178
179     /*< protected >*/
180     guint                       display_types;
181
182     /*< public >*/
183     GstVaapiDisplayInitFunc     init;
184     GstVaapiDisplayBindFunc     bind_display;
185     GstVaapiDisplayOpenFunc     open_display;
186     GstVaapiDisplayCloseFunc    close_display;
187     GstVaapiDisplayLockFunc     lock;
188     GstVaapiDisplayUnlockFunc   unlock;
189     GstVaapiDisplaySyncFunc     sync;
190     GstVaapiDisplayFlushFunc    flush;
191     GstVaapiDisplayGetInfoFunc  get_display;
192     GstVaapiDisplayGetSizeFunc  get_size;
193     GstVaapiDisplayGetSizeMFunc get_size_mm;
194 };
195
196 /* Initialization types */
197 enum _GstVaapiDisplayInitType {
198     GST_VAAPI_DISPLAY_INIT_FROM_DISPLAY_NAME = 1,
199     GST_VAAPI_DISPLAY_INIT_FROM_NATIVE_DISPLAY,
200     GST_VAAPI_DISPLAY_INIT_FROM_VA_DISPLAY
201 };
202
203 void
204 gst_vaapi_display_class_init(GstVaapiDisplayClass *klass);
205
206 GstVaapiDisplay *
207 gst_vaapi_display_new(const GstVaapiDisplayClass *klass,
208     GstVaapiDisplayInitType init_type, gpointer init_value);
209
210 GstVaapiDisplayCache *
211 gst_vaapi_display_get_cache(void);
212
213 static inline guint
214 gst_vaapi_display_get_display_types(GstVaapiDisplay *display)
215 {
216     const GstVaapiDisplayClass * const dpy_class =
217         GST_VAAPI_DISPLAY_GET_CLASS(display);
218
219     return dpy_class->display_types;
220 }
221
222 /* Inline reference counting for core libgstvaapi library */
223 #ifdef GST_VAAPI_CORE
224 #define gst_vaapi_display_ref_internal(display) \
225     ((gpointer)gst_vaapi_mini_object_ref(GST_VAAPI_MINI_OBJECT(display)))
226
227 #define gst_vaapi_display_unref_internal(display) \
228     gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(display))
229
230 #define gst_vaapi_display_replace_internal(old_display_ptr, new_display) \
231     gst_vaapi_mini_object_replace((GstVaapiMiniObject **)(old_display_ptr), \
232         GST_VAAPI_MINI_OBJECT(new_display))
233
234 #undef  gst_vaapi_display_ref
235 #define gst_vaapi_display_ref(display) \
236     gst_vaapi_display_ref_internal((display))
237
238 #undef  gst_vaapi_display_unref
239 #define gst_vaapi_display_unref(display) \
240     gst_vaapi_display_unref_internal((display))
241
242 #undef  gst_vaapi_display_replace
243 #define gst_vaapi_display_replace(old_display_ptr, new_display) \
244     gst_vaapi_display_replace_internal((old_display_ptr), (new_display))
245 #endif
246
247 G_END_DECLS
248
249 #endif /* GST_VAAPI_DISPLAY_PRIV_H */