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