Move files from gst-plugins-bad into the "subprojects/gst-plugins-bad/" subdir
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / d3dvideosink / d3dhelpers.h
1 /* GStreamer
2  * Copyright (C) 2012 Roland Krikava <info@bluedigits.com>
3  * Copyright (C) 2010-2011 David Hoyt <dhoyt@hoytsoft.org>
4  * Copyright (C) 2010 Andoni Morales <ylatuya@gmail.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 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  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 #ifndef _D3DHELPERS_H_
22 #define _D3DHELPERS_H_
23
24 #include <gst/gst.h>
25 #include <gst/video/video.h>
26
27 #include <windows.h>
28
29 #if defined(__MINGW32__)
30 # ifndef _OBJC_NO_COM_
31 #  if defined(__cplusplus) && !defined(CINTERFACE)
32 #   if defined(__GNUC__) &&  __GNUC__ < 3 && !defined(NOCOMATTRIBUTE)
33 #    define DECLARE_INTERFACE_IID_(i,b,d) _COM_interface __attribute__((com_interface)) i : public b
34 #   else
35 #    define DECLARE_INTERFACE_IID_(i,b,d) _COM_interface i : public b
36 #   endif
37 #  elif !defined(DECLARE_INTERFACE_IID_)
38 #   define DECLARE_INTERFACE_IID_(i,b,d) DECLARE_INTERFACE(i)
39 #  endif
40 # endif
41 # if !defined(__MSABI_LONG)
42 #  define __MSABI_LONG(x)  x ## l
43 # endif
44 #endif
45
46 #include <d3d9.h>
47
48 typedef struct _GstD3DVideoSink GstD3DVideoSink;
49 typedef struct _GstD3DVideoSinkClass GstD3DVideoSinkClass;
50
51 typedef struct _GstD3DDisplayDevice {
52   UINT                   adapter;
53   D3DFORMAT              format;
54   D3DTEXTUREFILTERTYPE   filter_type;
55   LPDIRECT3DDEVICE9      d3d_device;
56   D3DPRESENT_PARAMETERS  present_params;
57 } GstD3DDisplayDevice;
58
59 typedef struct _GstD3DDataClass {
60   guint                  refs;
61   LPDIRECT3D9            d3d;
62   GstD3DDisplayDevice    device;
63   GList                  *supported_formats;
64
65   /* Track individual sink instances */
66   GList *                sink_list;
67   gboolean               device_lost;
68
69   /* Window class for internal windows */
70   WNDCLASS               wnd_class;
71
72   /* Windows Message Handling */
73   GThread *              thread;
74   GMutex                 thread_start_mutex;
75   GCond                  thread_start_cond;
76   HWND                   hidden_window;
77   gboolean               thread_started;
78   gboolean               thread_error_exit;
79 } GstD3DDataClass;
80
81 typedef struct _GstD3DData {
82   /* Window Proc Stuff */
83   HWND                   external_window_handle;
84   HWND                   window_handle;
85   gboolean               window_is_internal;
86   WNDPROC                orig_wnd_proc;
87
88   /* Render Constructs */
89   LPDIRECT3DSWAPCHAIN9   swapchain;
90   LPDIRECT3DSURFACE9     surface;
91   D3DTEXTUREFILTERTYPE   filtertype;
92   D3DFORMAT              format;
93   GstVideoRectangle    * render_rect;
94   gboolean               renderable;
95   gboolean               device_lost;
96
97   /* list of GstD3DVideoSinkOverlay structs */
98   GList * overlay;
99   gboolean overlay_needs_resize;
100 } GstD3DData;
101
102 gboolean       d3d_class_init(GstD3DVideoSink * klass);
103 void           d3d_class_destroy(GstD3DVideoSink * klass);
104
105 gboolean       d3d_prepare_window(GstD3DVideoSink * sink);
106 gboolean       d3d_stop(GstD3DVideoSink * sink);
107 void           d3d_set_window_handle(GstD3DVideoSink * sink, guintptr window_id, gboolean internal);
108 void           d3d_set_render_rectangle(GstD3DVideoSink * sink);
109 void           d3d_expose_window(GstD3DVideoSink * sink);
110 GstFlowReturn  d3d_render_buffer(GstD3DVideoSink * sink, GstBuffer * buf);
111 GstCaps *      d3d_supported_caps(GstD3DVideoSink * sink);
112 gboolean       d3d_set_render_format(GstD3DVideoSink * sink);
113 gboolean       d3d_get_hwnd_window_size (HWND hwnd, gint * width, gint * height);
114
115 #define GST_TYPE_D3DSURFACE_BUFFER_POOL      (gst_d3dsurface_buffer_pool_get_type())
116 #define GST_IS_D3DSURFACE_BUFFER_POOL(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_D3DSURFACE_BUFFER_POOL))
117 #define GST_D3DSURFACE_BUFFER_POOL(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_D3DSURFACE_BUFFER_POOL, GstD3DSurfaceBufferPool))
118 #define GST_D3DSURFACE_BUFFER_POOL_CAST(obj) ((GstD3DSurfaceBufferPool*)(obj))
119
120 typedef struct _GstD3DSurfaceBufferPool {
121   GstVideoBufferPool parent;
122
123   GstD3DVideoSink *sink;
124   GstVideoInfo info;
125   gboolean add_metavideo;
126
127   GstAllocator *allocator;
128 } GstD3DSurfaceBufferPool;
129
130 typedef struct _GstD3DSurfaceBufferPoolClass {
131   GstVideoBufferPoolClass parent_class;
132 } GstD3DSurfaceBufferPoolClass;
133
134 GType gst_d3dsurface_meta_api_get_type (void);
135 #define GST_D3DSURFACE_META_API_TYPE  (gst_d3dsurface_meta_api_get_type())
136 const GstMetaInfo * gst_d3dsurface_meta_get_info (void);
137 #define GST_D3DSURFACE_META_INFO  (gst_d3dsurface_meta_get_info())
138
139 #define gst_buffer_get_d3dsurface_meta(b) ((GstD3DSurfaceMeta*)gst_buffer_get_meta((b),GST_D3DSURFACE_META_API_TYPE))
140
141 GType gst_d3dsurface_buffer_pool_get_type (void);
142 GstBufferPool * gst_d3dsurface_buffer_pool_new (GstD3DVideoSink * sink);
143
144 #endif /* _D3DHELPERS_H_ */