summaryrefslogtreecommitdiff
path: root/sys/d3d11/gstd3d11window.h
blob: 257f23bb433b0a51756997e04aa162794513cbfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * GStreamer
 * Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
 * Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __GST_D3D11_WINDOW_H__
#define __GST_D3D11_WINDOW_H__

#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/d3d11/gstd3d11.h>
#include "gstd3d11converter.h"
#include "gstd3d11overlaycompositor.h"
#include "gstd3d11videoprocessor.h"
#include "gstd3d11pluginutils.h"

G_BEGIN_DECLS

#define GST_TYPE_D3D11_WINDOW             (gst_d3d11_window_get_type())
#define GST_D3D11_WINDOW(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_D3D11_WINDOW, GstD3D11Window))
#define GST_D3D11_WINDOW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_D3D11_WINDOW, GstD3D11WindowClass))
#define GST_IS_D3D11_WINDOW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_D3D11_WINDOW))
#define GST_IS_D3D11_WINDOW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_D3D11_WINDOW))
#define GST_D3D11_WINDOW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_D3D11_WINDOW, GstD3D11WindowClass))
#define GST_D3D11_WINDOW_TOGGLE_MODE_GET_TYPE (gst_d3d11_window_fullscreen_toggle_mode_type())

typedef struct _GstD3D11Window        GstD3D11Window;
typedef struct _GstD3D11WindowClass   GstD3D11WindowClass;

#define GST_D3D11_WINDOW_FLOW_CLOSED GST_FLOW_CUSTOM_ERROR

typedef enum
{
  GST_D3D11_WINDOW_FULLSCREEN_TOGGLE_MODE_NONE = 0,
  GST_D3D11_WINDOW_FULLSCREEN_TOGGLE_MODE_ALT_ENTER = (1 << 1),
  GST_D3D11_WINDOW_FULLSCREEN_TOGGLE_MODE_PROPERTY = (1 << 2),
} GstD3D11WindowFullscreenToggleMode;

GType gst_d3d11_window_fullscreen_toggle_mode_type (void);

typedef enum
{
  GST_D3D11_WINDOW_NATIVE_TYPE_NONE = 0,
  GST_D3D11_WINDOW_NATIVE_TYPE_HWND,
  GST_D3D11_WINDOW_NATIVE_TYPE_CORE_WINDOW,
  GST_D3D11_WINDOW_NATIVE_TYPE_SWAP_CHAIN_PANEL,
} GstD3D11WindowNativeType;

typedef struct
{
  HANDLE shared_handle;
  guint texture_misc_flags;
  guint64 acquire_key;
  guint64 release_key;

  ID3D11Texture2D *texture;
  IDXGIKeyedMutex *keyed_mutex;
  ID3D11VideoProcessorOutputView *pov;
  ID3D11RenderTargetView *rtv;

  ID3D11VideoProcessorOutputView *fallback_pov;
  ID3D11RenderTargetView *fallback_rtv;
} GstD3D11WindowSharedHandleData;

struct _GstD3D11Window
{
  GstObject parent;

  /*< protected >*/
  gboolean initialized;
  GstD3D11Device *device;
  guintptr external_handle;

  /* properties */
  gboolean force_aspect_ratio;
  gboolean enable_navigation_events;
  GstD3D11WindowFullscreenToggleMode fullscreen_toggle_mode;
  gboolean requested_fullscreen;
  gboolean fullscreen;
  gboolean render_stats;

  GstVideoInfo info;
  GstVideoInfo render_info;
  GstD3D11VideoProcessor *processor;
  GstD3D11Converter *converter;
  GstD3D11OverlayCompositor *compositor;

  gboolean processor_in_use;

  /* calculated rect with aspect ratio and window area */
  RECT render_rect;

  /* input resolution */
  RECT input_rect;

  /* requested rect via gst_d3d11_window_render */
  GstVideoRectangle rect;

  guint surface_width;
  guint surface_height;

  IDXGISwapChain *swap_chain;
  ID3D11RenderTargetView *rtv;
  ID3D11VideoProcessorOutputView *pov;
  DXGI_FORMAT dxgi_format;

  GstBuffer *cached_buffer;
  gboolean first_present;
  gboolean allow_tearing;
};

struct _GstD3D11WindowClass
{
  GstObjectClass object_class;

  void          (*show)                   (GstD3D11Window * window);

  void          (*update_swap_chain)      (GstD3D11Window * window);

  void          (*change_fullscreen_mode) (GstD3D11Window * window);

  gboolean      (*create_swap_chain)      (GstD3D11Window * window,
                                           DXGI_FORMAT format,
                                           guint width,
                                           guint height,
                                           guint swapchain_flags,
                                           IDXGISwapChain ** swap_chain);

  GstFlowReturn (*present)                (GstD3D11Window * window,
                                           guint present_flags);

  gboolean      (*unlock)                 (GstD3D11Window * window);

  gboolean      (*unlock_stop)            (GstD3D11Window * window);

  void          (*on_resize)              (GstD3D11Window * window,
                                           guint width,
                                           guint height);

  gboolean      (*prepare)                (GstD3D11Window * window,
                                           guint display_width,
                                           guint display_height,
                                           GstCaps * caps,
                                           gboolean * video_processor_available,
                                           GError ** error);

  void          (*unprepare)              (GstD3D11Window * window);

  gboolean      (*open_shared_handle)     (GstD3D11Window * window,
                                           GstD3D11WindowSharedHandleData * data);

  gboolean      (*release_shared_handle)  (GstD3D11Window * window,
                                           GstD3D11WindowSharedHandleData * data);

  void          (*set_render_rectangle)   (GstD3D11Window * window,
                                           const GstVideoRectangle * rect);
};

GType         gst_d3d11_window_get_type             (void);

void          gst_d3d11_window_show                 (GstD3D11Window * window);

void          gst_d3d11_window_set_render_rectangle (GstD3D11Window * window,
                                                     const GstVideoRectangle * rect);

gboolean      gst_d3d11_window_prepare              (GstD3D11Window * window,
                                                     guint display_width,
                                                     guint display_height,
                                                     GstCaps * caps,
                                                     gboolean * video_processor_available,
                                                     GError ** error);

GstFlowReturn gst_d3d11_window_render               (GstD3D11Window * window,
                                                     GstBuffer * buffer);

GstFlowReturn gst_d3d11_window_render_on_shared_handle (GstD3D11Window * window,
                                                        GstBuffer * buffer,
                                                        HANDLE shared_handle,
                                                        guint texture_misc_flags,
                                                        guint64 acquire_key,
                                                        guint64 release_key);

gboolean      gst_d3d11_window_unlock               (GstD3D11Window * window);

gboolean      gst_d3d11_window_unlock_stop          (GstD3D11Window * window);

void          gst_d3d11_window_unprepare            (GstD3D11Window * window);

void          gst_d3d11_window_on_key_event         (GstD3D11Window * window,
                                                     const gchar * event,
                                                     const gchar * key);

void          gst_d3d11_window_on_mouse_event       (GstD3D11Window * window,
                                                     const gchar * event,
                                                     gint button,
                                                     gdouble x,
                                                     gdouble y);

/* utils */
GstD3D11WindowNativeType gst_d3d11_window_get_native_type_from_handle (guintptr handle);

const gchar *            gst_d3d11_window_get_native_type_to_string   (GstD3D11WindowNativeType type);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstD3D11Window, gst_object_unref)

G_END_DECLS

#endif /* __GST_D3D11_WINDOW_H__ */