• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
4  * Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.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., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef __GST_D3D11_WINDOW_H__
23 #define __GST_D3D11_WINDOW_H__
24 
25 #include <gst/gst.h>
26 #include <gst/video/video.h>
27 #include <gst/d3d11/gstd3d11.h>
28 #include "gstd3d11converter.h"
29 #include "gstd3d11overlaycompositor.h"
30 #include "gstd3d11videoprocessor.h"
31 #include "gstd3d11pluginutils.h"
32 
33 G_BEGIN_DECLS
34 
35 #define GST_TYPE_D3D11_WINDOW             (gst_d3d11_window_get_type())
36 #define GST_D3D11_WINDOW(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_D3D11_WINDOW, GstD3D11Window))
37 #define GST_D3D11_WINDOW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_D3D11_WINDOW, GstD3D11WindowClass))
38 #define GST_IS_D3D11_WINDOW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_D3D11_WINDOW))
39 #define GST_IS_D3D11_WINDOW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_D3D11_WINDOW))
40 #define GST_D3D11_WINDOW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_D3D11_WINDOW, GstD3D11WindowClass))
41 #define GST_D3D11_WINDOW_TOGGLE_MODE_GET_TYPE (gst_d3d11_window_fullscreen_toggle_mode_type())
42 
43 typedef struct _GstD3D11Window        GstD3D11Window;
44 typedef struct _GstD3D11WindowClass   GstD3D11WindowClass;
45 
46 #define GST_D3D11_WINDOW_FLOW_CLOSED GST_FLOW_CUSTOM_ERROR
47 
48 typedef enum
49 {
50   GST_D3D11_WINDOW_FULLSCREEN_TOGGLE_MODE_NONE = 0,
51   GST_D3D11_WINDOW_FULLSCREEN_TOGGLE_MODE_ALT_ENTER = (1 << 1),
52   GST_D3D11_WINDOW_FULLSCREEN_TOGGLE_MODE_PROPERTY = (1 << 2),
53 } GstD3D11WindowFullscreenToggleMode;
54 
55 GType gst_d3d11_window_fullscreen_toggle_mode_type (void);
56 
57 typedef enum
58 {
59   GST_D3D11_WINDOW_NATIVE_TYPE_NONE = 0,
60   GST_D3D11_WINDOW_NATIVE_TYPE_HWND,
61   GST_D3D11_WINDOW_NATIVE_TYPE_CORE_WINDOW,
62   GST_D3D11_WINDOW_NATIVE_TYPE_SWAP_CHAIN_PANEL,
63 } GstD3D11WindowNativeType;
64 
65 typedef struct
66 {
67   HANDLE shared_handle;
68   guint texture_misc_flags;
69   guint64 acquire_key;
70   guint64 release_key;
71 
72   ID3D11Texture2D *texture;
73   IDXGIKeyedMutex *keyed_mutex;
74   ID3D11VideoProcessorOutputView *pov;
75   ID3D11RenderTargetView *rtv;
76 
77   ID3D11VideoProcessorOutputView *fallback_pov;
78   ID3D11RenderTargetView *fallback_rtv;
79 } GstD3D11WindowSharedHandleData;
80 
81 struct _GstD3D11Window
82 {
83   GstObject parent;
84 
85   /*< protected >*/
86   gboolean initialized;
87   GstD3D11Device *device;
88   guintptr external_handle;
89 
90   /* properties */
91   gboolean force_aspect_ratio;
92   gboolean enable_navigation_events;
93   GstD3D11WindowFullscreenToggleMode fullscreen_toggle_mode;
94   gboolean requested_fullscreen;
95   gboolean fullscreen;
96   gboolean render_stats;
97 
98   GstVideoInfo info;
99   GstVideoInfo render_info;
100   GstD3D11VideoProcessor *processor;
101   GstD3D11Converter *converter;
102   GstD3D11OverlayCompositor *compositor;
103 
104   gboolean processor_in_use;
105 
106   /* calculated rect with aspect ratio and window area */
107   RECT render_rect;
108 
109   /* input resolution */
110   RECT input_rect;
111 
112   /* requested rect via gst_d3d11_window_render */
113   GstVideoRectangle rect;
114 
115   guint surface_width;
116   guint surface_height;
117 
118   IDXGISwapChain *swap_chain;
119   ID3D11RenderTargetView *rtv;
120   ID3D11VideoProcessorOutputView *pov;
121   DXGI_FORMAT dxgi_format;
122 
123   GstBuffer *cached_buffer;
124   gboolean first_present;
125   gboolean allow_tearing;
126 };
127 
128 struct _GstD3D11WindowClass
129 {
130   GstObjectClass object_class;
131 
132   void          (*show)                   (GstD3D11Window * window);
133 
134   void          (*update_swap_chain)      (GstD3D11Window * window);
135 
136   void          (*change_fullscreen_mode) (GstD3D11Window * window);
137 
138   gboolean      (*create_swap_chain)      (GstD3D11Window * window,
139                                            DXGI_FORMAT format,
140                                            guint width,
141                                            guint height,
142                                            guint swapchain_flags,
143                                            IDXGISwapChain ** swap_chain);
144 
145   GstFlowReturn (*present)                (GstD3D11Window * window,
146                                            guint present_flags);
147 
148   gboolean      (*unlock)                 (GstD3D11Window * window);
149 
150   gboolean      (*unlock_stop)            (GstD3D11Window * window);
151 
152   void          (*on_resize)              (GstD3D11Window * window,
153                                            guint width,
154                                            guint height);
155 
156   gboolean      (*prepare)                (GstD3D11Window * window,
157                                            guint display_width,
158                                            guint display_height,
159                                            GstCaps * caps,
160                                            gboolean * video_processor_available,
161                                            GError ** error);
162 
163   void          (*unprepare)              (GstD3D11Window * window);
164 
165   gboolean      (*open_shared_handle)     (GstD3D11Window * window,
166                                            GstD3D11WindowSharedHandleData * data);
167 
168   gboolean      (*release_shared_handle)  (GstD3D11Window * window,
169                                            GstD3D11WindowSharedHandleData * data);
170 
171   void          (*set_render_rectangle)   (GstD3D11Window * window,
172                                            const GstVideoRectangle * rect);
173 
174   void          (*set_title)              (GstD3D11Window * window,
175                                            const gchar *title);
176 };
177 
178 GType         gst_d3d11_window_get_type             (void);
179 
180 void          gst_d3d11_window_show                 (GstD3D11Window * window);
181 
182 void          gst_d3d11_window_set_render_rectangle (GstD3D11Window * window,
183                                                      const GstVideoRectangle * rect);
184 
185 void          gst_d3d11_window_set_title            (GstD3D11Window * window,
186                                                      const gchar *title);
187 
188 gboolean      gst_d3d11_window_prepare              (GstD3D11Window * window,
189                                                      guint display_width,
190                                                      guint display_height,
191                                                      GstCaps * caps,
192                                                      gboolean * video_processor_available,
193                                                      GError ** error);
194 
195 GstFlowReturn gst_d3d11_window_render               (GstD3D11Window * window,
196                                                      GstBuffer * buffer);
197 
198 GstFlowReturn gst_d3d11_window_render_on_shared_handle (GstD3D11Window * window,
199                                                         GstBuffer * buffer,
200                                                         HANDLE shared_handle,
201                                                         guint texture_misc_flags,
202                                                         guint64 acquire_key,
203                                                         guint64 release_key);
204 
205 gboolean      gst_d3d11_window_unlock               (GstD3D11Window * window);
206 
207 gboolean      gst_d3d11_window_unlock_stop          (GstD3D11Window * window);
208 
209 void          gst_d3d11_window_unprepare            (GstD3D11Window * window);
210 
211 void          gst_d3d11_window_on_key_event         (GstD3D11Window * window,
212                                                      const gchar * event,
213                                                      const gchar * key);
214 
215 void          gst_d3d11_window_on_mouse_event       (GstD3D11Window * window,
216                                                      const gchar * event,
217                                                      gint button,
218                                                      gdouble x,
219                                                      gdouble y);
220 
221 /* utils */
222 GstD3D11WindowNativeType gst_d3d11_window_get_native_type_from_handle (guintptr handle);
223 
224 const gchar *            gst_d3d11_window_get_native_type_to_string   (GstD3D11WindowNativeType type);
225 
226 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstD3D11Window, gst_object_unref)
227 
228 G_END_DECLS
229 
230 #endif /* __GST_D3D11_WINDOW_H__ */
231