Debian Codegraph @

sys/d3dvideosink/d3dvideosink.c

raw symbols SCIP
1 /* GStreamer
2 * Copyright (C) 2012 Roland Krikava <[email protected]>
3 * Copyright (C) 2010-2011 David Hoyt <[email protected]>
4 * Copyright (C) 2010 Andoni Morales <[email protected]>
5 * Copyright (C) 2012 Sebastian Dröge <[email protected]>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 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 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "d3dvideosink.h"
27 #include "gstd3d9overlay.h"
28
29 #define ELEMENT_NAME "d3dvideosink"
30
31 enum
32 {
33 PROP_0,
34 PROP_FORCE_ASPECT_RATIO,
35 PROP_CREATE_RENDER_WINDOW,
36 PROP_STREAM_STOP_ON_CLOSE,
37 PROP_ENABLE_NAVIGATION_EVENTS,
38 PROP_LAST
39 };
40
41 #define DEFAULT_FORCE_ASPECT_RATIO TRUE
42 #define DEFAULT_CREATE_RENDER_WINDOW TRUE
43 #define DEFAULT_STREAM_STOP_ON_CLOSE TRUE
44 #define DEFAULT_ENABLE_NAVIGATION_EVENTS TRUE
45
46 #define GST_D3D9_VIDEO_FORMATS \
47 "{ I420, YV12, UYVY, YUY2, NV12, BGRx, RGBx, BGRA, RGBA, BGR, RGB16, RGB15 }"
48 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
49 GST_PAD_SINK,
50 GST_PAD_ALWAYS,
51 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_D3D9_VIDEO_FORMATS) ";"
52 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY
53 ", " GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION,
54 GST_D3D9_VIDEO_FORMATS)));
55
56 GST_DEBUG_CATEGORY (gst_d3dvideosink_debug);
57 #define GST_CAT_DEFAULT gst_d3dvideosink_debug
58
59 /* FWD DECLS */
60 /* GstXOverlay Interface */
61 static void
62 gst_d3dvideosink_video_overlay_interface_init (GstVideoOverlayInterface *
63 iface);
64 static void gst_d3dvideosink_set_window_handle (GstVideoOverlay * overlay,
65 guintptr window_id);
66 static void gst_d3dvideosink_set_render_rectangle (GstVideoOverlay * overlay,
67 gint x, gint y, gint width, gint height);
68 static void gst_d3dvideosink_expose (GstVideoOverlay * overlay);
69 /* GstNavigation Interface */
70 static void gst_d3dvideosink_navigation_interface_init (GstNavigationInterface *
71 iface);
72 static void gst_d3dvideosink_navigation_send_event (GstNavigation * navigation,
73 GstEvent * event);
74 /* GObject */
75 static void gst_d3dvideosink_set_property (GObject * object, guint prop_id,
76 const GValue * value, GParamSpec * pspec);
77 static void gst_d3dvideosink_get_property (GObject * object, guint prop_id,
78 GValue * value, GParamSpec * pspec);
79 static void gst_d3dvideosink_finalize (GObject * gobject);
80 /* GstBaseSink */
81 static GstCaps *gst_d3dvideosink_get_caps (GstBaseSink * basesink,
82 GstCaps * filter);
83 static gboolean gst_d3dvideosink_set_caps (GstBaseSink * bsink, GstCaps * caps);
84 static gboolean gst_d3dvideosink_start (GstBaseSink * sink);
85 static gboolean gst_d3dvideosink_stop (GstBaseSink * sink);
86 static GstFlowReturn gst_d3dvideosink_prepare (GstBaseSink * bsink,
87 GstBuffer * buf);
88 static gboolean gst_d3dvideosink_propose_allocation (GstBaseSink * bsink,
89 GstQuery * query);
90 /* GstVideoSink */
91 static GstFlowReturn gst_d3dvideosink_show_frame (GstVideoSink * vsink,
92 GstBuffer * buffer);
93
94 #define _do_init \
95 G_IMPLEMENT_INTERFACE (GST_TYPE_NAVIGATION, gst_d3dvideosink_navigation_interface_init); \
96 G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_OVERLAY, gst_d3dvideosink_video_overlay_interface_init); \
97 GST_DEBUG_CATEGORY_INIT (gst_d3dvideosink_debug, ELEMENT_NAME, 0, "Direct3D Video");
98
99 G_DEFINE_TYPE_WITH_CODE (GstD3DVideoSink, gst_d3dvideosink, GST_TYPE_VIDEO_SINK,
100 _do_init);
101
102 static void
103 gst_d3dvideosink_class_init (GstD3DVideoSinkClass * klass)
104 {
105 GObjectClass *gobject_class;
106 GstElementClass *gstelement_class;
107 GstVideoSinkClass *gstvideosink_class;
108 GstBaseSinkClass *gstbasesink_class;
109
110 gobject_class = (GObjectClass *) klass;
111 gstelement_class = (GstElementClass *) klass;
112 gstvideosink_class = (GstVideoSinkClass *) klass;
113 gstbasesink_class = (GstBaseSinkClass *) klass;
114
115 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_d3dvideosink_finalize);
116 gobject_class->set_property =
117 GST_DEBUG_FUNCPTR (gst_d3dvideosink_set_property);
118 gobject_class->get_property =
119 GST_DEBUG_FUNCPTR (gst_d3dvideosink_get_property);
120
121 gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_d3dvideosink_get_caps);
122 gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_d3dvideosink_set_caps);
123 gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_d3dvideosink_start);
124 gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_d3dvideosink_stop);
125 gstbasesink_class->prepare = GST_DEBUG_FUNCPTR (gst_d3dvideosink_prepare);
126 gstbasesink_class->propose_allocation =
127 GST_DEBUG_FUNCPTR (gst_d3dvideosink_propose_allocation);
128
129 gstvideosink_class->show_frame =
130 GST_DEBUG_FUNCPTR (gst_d3dvideosink_show_frame);
131
132 /* Add properties */
133 g_object_class_install_property (G_OBJECT_CLASS (klass),
134 PROP_FORCE_ASPECT_RATIO, g_param_spec_boolean ("force-aspect-ratio",
135 "Force aspect ratio",
136 "When enabled, scaling will respect original aspect ratio",
137 DEFAULT_FORCE_ASPECT_RATIO,
138 (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
139 g_object_class_install_property (G_OBJECT_CLASS (klass),
140 PROP_CREATE_RENDER_WINDOW, g_param_spec_boolean ("create-render-window",
141 "Create render window",
142 "If no window ID is given, a new render window is created",
143 DEFAULT_CREATE_RENDER_WINDOW,
144 (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
145 g_object_class_install_property (G_OBJECT_CLASS (klass),
146 PROP_STREAM_STOP_ON_CLOSE, g_param_spec_boolean ("stream-stop-on-close",
147 "Stop streaming on window close",
148 "If the render window is closed stop stream",
149 DEFAULT_STREAM_STOP_ON_CLOSE,
150 (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
151 g_object_class_install_property (G_OBJECT_CLASS (klass),
152 PROP_ENABLE_NAVIGATION_EVENTS,
153 g_param_spec_boolean ("enable-navigation-events",
154 "Enable navigation events",
155 "When enabled, navigation events are sent upstream",
156 DEFAULT_ENABLE_NAVIGATION_EVENTS,
157 (GParamFlags) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
158
159 gst_element_class_set_static_metadata (gstelement_class,
160 "Direct3D9 video sink", "Sink/Video",
161 "Display data using a Direct3D9 video renderer",
162 "David Hoyt <[email protected]>, Roland Krikava <[email protected]>");
163
164 gst_element_class_add_static_pad_template (gstelement_class, &sink_template);
165
166 g_rec_mutex_init (&klass->lock);
167 }
168
169 static void
170 gst_d3dvideosink_init (GstD3DVideoSink * sink)
171 {
172 GST_DEBUG_OBJECT (sink, " ");
173
174 /* Init Properties */
175 sink->force_aspect_ratio = DEFAULT_FORCE_ASPECT_RATIO;
176 sink->create_internal_window = DEFAULT_CREATE_RENDER_WINDOW;
177 sink->stream_stop_on_close = DEFAULT_STREAM_STOP_ON_CLOSE;
178 sink->enable_navigation_events = DEFAULT_ENABLE_NAVIGATION_EVENTS;
179 sink->d3d.overlay_needs_resize = FALSE;
180 g_queue_init (&sink->d3d.overlays);
181 g_rec_mutex_init (&sink->lock);
182 }
183
184 /* GObject Functions */
185
186 static void
187 gst_d3dvideosink_finalize (GObject * gobject)
188 {
189 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (gobject);
190
191 GST_DEBUG_OBJECT (sink, " ");
192
193 gst_object_replace ((GstObject **) & sink->pool, NULL);
194 gst_object_replace ((GstObject **) & sink->fallback_pool, NULL);
195
196 gst_caps_replace (&sink->supported_caps, NULL);
197
198 g_rec_mutex_clear (&sink->lock);
199
200 G_OBJECT_CLASS (gst_d3dvideosink_parent_class)->finalize (gobject);
201 }
202
203 static void
204 gst_d3dvideosink_set_property (GObject * object, guint prop_id,
205 const GValue * value, GParamSpec * pspec)
206 {
207 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (object);
208
209 switch (prop_id) {
210 case PROP_FORCE_ASPECT_RATIO:
211 sink->force_aspect_ratio = g_value_get_boolean (value);
212 break;
213 case PROP_CREATE_RENDER_WINDOW:
214 sink->create_internal_window = g_value_get_boolean (value);
215 break;
216 case PROP_STREAM_STOP_ON_CLOSE:
217 sink->stream_stop_on_close = g_value_get_boolean (value);
218 break;
219 case PROP_ENABLE_NAVIGATION_EVENTS:
220 sink->enable_navigation_events = g_value_get_boolean (value);
221 break;
222 default:
223 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
224 break;
225 }
226 }
227
228 static void
229 gst_d3dvideosink_get_property (GObject * object, guint prop_id, GValue * value,
230 GParamSpec * pspec)
231 {
232 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (object);
233
234 switch (prop_id) {
235 case PROP_FORCE_ASPECT_RATIO:
236 g_value_set_boolean (value, sink->force_aspect_ratio);
237 break;
238 case PROP_CREATE_RENDER_WINDOW:
239 g_value_set_boolean (value, sink->create_internal_window);
240 break;
241 case PROP_STREAM_STOP_ON_CLOSE:
242 g_value_set_boolean (value, sink->stream_stop_on_close);
243 break;
244 case PROP_ENABLE_NAVIGATION_EVENTS:
245 g_value_set_boolean (value, sink->enable_navigation_events);
246 break;
247 default:
248 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
249 break;
250 }
251 }
252
253 /* GstBaseSinkClass Functions */
254
255 static GstCaps *
256 gst_d3dvideosink_get_caps (GstBaseSink * basesink, GstCaps * filter)
257 {
258 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (basesink);
259 GstCaps *caps;
260
261 caps = d3d_supported_caps (sink);
262 if (!caps)
263 caps = gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD (sink));
264
265 if (caps && filter) {
266 GstCaps *isect;
267 isect = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
268 gst_caps_unref (caps);
269 caps = isect;
270 }
271
272 return caps;
273 }
274
275 static gboolean
276 gst_d3dvideosink_set_caps (GstBaseSink * bsink, GstCaps * caps)
277 {
278 GstD3DVideoSink *sink;
279 GstCaps *sink_caps;
280 gint video_width, video_height;
281 gint video_par_n, video_par_d; /* video's PAR */
282 gint display_par_n = 1, display_par_d = 1; /* display's PAR */
283 guint num, den;
284 GstBufferPool *newpool, *oldpool;
285 GstBufferPool *newfbpool, *oldfbpool;
286 GstStructure *config;
287
288 GST_DEBUG_OBJECT (bsink, "Caps: %" GST_PTR_FORMAT, caps);
289 sink = GST_D3DVIDEOSINK (bsink);
290
291 sink_caps = d3d_supported_caps (sink);
292
293 if (!gst_caps_can_intersect (sink_caps, caps))
294 goto incompatible_caps;
295 gst_caps_replace (&sink_caps, NULL);
296
297 memset (&sink->info, 0, sizeof (GstVideoInfo));
298 if (!gst_video_info_from_caps (&sink->info, caps))
299 goto invalid_format;
300
301 sink->format = sink->info.finfo->format;
302 video_width = sink->info.width;
303 video_height = sink->info.height;
304 video_par_n = sink->info.par_n;
305 video_par_d = sink->info.par_d;
306
307 GST_DEBUG_OBJECT (bsink, "Set Caps Format: %s",
308 gst_video_format_to_string (sink->format));
309
310 /* get aspect ratio from caps if it's present, and
311 * convert video width and height to a display width and height
312 * using wd / hd = wv / hv * PARv / PARd */
313
314 /* TODO: Get display PAR */
315
316 if (!gst_video_calculate_display_ratio (&num, &den, video_width,
317 video_height, video_par_n, video_par_d, display_par_n, display_par_d))
318 goto no_disp_ratio;
319
320 GST_DEBUG_OBJECT (sink,
321 "video width/height: %dx%d, calculated display ratio: %d/%d format: %u",
322 video_width, video_height, num, den, sink->format);
323
324 /* now find a width x height that respects this display ratio.
325 * prefer those that have one of w/h the same as the incoming video
326 * using wd / hd = num / den
327 */
328
329 /* start with same height, because of interlaced video
330 * check hd / den is an integer scale factor, and scale wd with the PAR
331 */
332 if (video_height % den == 0) {
333 GST_DEBUG_OBJECT (sink, "keeping video height");
334 GST_VIDEO_SINK_WIDTH (sink) = (guint)
335 gst_util_uint64_scale_int (video_height, num, den);
336 GST_VIDEO_SINK_HEIGHT (sink) = video_height;
337 } else if (video_width % num == 0) {
338 GST_DEBUG_OBJECT (sink, "keeping video width");
339 GST_VIDEO_SINK_WIDTH (sink) = video_width;
340 GST_VIDEO_SINK_HEIGHT (sink) = (guint)
341 gst_util_uint64_scale_int (video_width, den, num);
342 } else {
343 GST_DEBUG_OBJECT (sink, "approximating while keeping video height");
344 GST_VIDEO_SINK_WIDTH (sink) = (guint)
345 gst_util_uint64_scale_int (video_height, num, den);
346 GST_VIDEO_SINK_HEIGHT (sink) = video_height;
347 }
348 GST_DEBUG_OBJECT (sink, "scaling to %dx%d",
349 GST_VIDEO_SINK_WIDTH (sink), GST_VIDEO_SINK_HEIGHT (sink));
350
351 if (GST_VIDEO_SINK_WIDTH (sink) <= 0 || GST_VIDEO_SINK_HEIGHT (sink) <= 0)
352 goto no_display_size;
353
354 memset (&sink->crop_rect, 0, sizeof (sink->crop_rect));
355 sink->crop_rect.w = sink->info.width;
356 sink->crop_rect.h = sink->info.height;
357
358 sink->width = video_width;
359 sink->height = video_height;
360
361 GST_DEBUG_OBJECT (bsink, "Selected caps: %" GST_PTR_FORMAT, caps);
362
363 if (!d3d_set_render_format (sink))
364 goto incompatible_caps;
365
366 /* Create a window (or start using an application-supplied one, then connect the graph */
367 d3d_prepare_window (sink);
368
369 newpool = gst_d3dsurface_buffer_pool_new (sink);
370 config = gst_buffer_pool_get_config (newpool);
371 /* we need at least 2 buffer because we hold on to the last one */
372 gst_buffer_pool_config_set_params (config, caps, sink->info.size, 2, 0);
373 if (!gst_buffer_pool_set_config (newpool, config)) {
374 gst_object_unref (newpool);
375 GST_ERROR_OBJECT (sink, "Failed to set buffer pool configuration");
376 return FALSE;
377 }
378
379 newfbpool = gst_d3dsurface_buffer_pool_new (sink);
380 config = gst_buffer_pool_get_config (newfbpool);
381 /* we need at least 2 buffer because we hold on to the last one */
382 gst_buffer_pool_config_set_params (config, caps, sink->info.size, 2, 0);
383 /* Fallback pool must use videometa */
384 gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
385 if (!gst_buffer_pool_set_config (newfbpool, config)) {
386 gst_object_unref (newfbpool);
387 GST_ERROR_OBJECT (sink, "Failed to set buffer pool configuration");
388 return FALSE;
389 }
390
391 GST_OBJECT_LOCK (sink);
392 oldpool = sink->pool;
393 sink->pool = newpool;
394 oldfbpool = sink->fallback_pool;
395 sink->fallback_pool = newfbpool;
396 GST_OBJECT_UNLOCK (sink);
397
398 if (oldpool)
399 gst_object_unref (oldpool);
400 if (oldfbpool) {
401 gst_buffer_pool_set_active (oldfbpool, FALSE);
402 gst_object_unref (oldfbpool);
403 }
404
405 return TRUE;
406 /* ERRORS */
407 incompatible_caps:
408 {
409 GST_ERROR_OBJECT (sink, "caps incompatible");
410 gst_caps_unref (sink_caps);
411 return FALSE;
412 }
413 invalid_format:
414 {
415 GST_DEBUG_OBJECT (sink,
416 "Could not locate image format from caps %" GST_PTR_FORMAT, caps);
417 return FALSE;
418 }
419 no_disp_ratio:
420 {
421 GST_ELEMENT_ERROR (sink, CORE, NEGOTIATION, (NULL),
422 ("Error calculating the output display ratio of the video."));
423 return FALSE;
424 }
425 no_display_size:
426 {
427 GST_ELEMENT_ERROR (sink, CORE, NEGOTIATION, (NULL),
428 ("Error calculating the output display ratio of the video."));
429 return FALSE;
430 }
431 }
432
433 static gboolean
434 gst_d3dvideosink_start (GstBaseSink * bsink)
435 {
436 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (bsink);
437
438 GST_DEBUG_OBJECT (bsink, "Start() called");
439
440 return d3d_class_init (sink);
441 }
442
443 static gboolean
444 gst_d3dvideosink_stop (GstBaseSink * bsink)
445 {
446 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (bsink);
447 GstD3DVideoSinkClass *klass = GST_D3DVIDEOSINK_GET_CLASS (sink);
448
449 GST_DEBUG_OBJECT (bsink, "Stop() called");
450 LOCK_CLASS (sink, klass);
451 d3d_stop (sink);
452 d3d_class_destroy (sink);
453 UNLOCK_CLASS (sink, klass);
454
455 return TRUE;
456 }
457
458 static GstFlowReturn
459 gst_d3dvideosink_prepare (GstBaseSink * bsink, GstBuffer * buf)
460 {
461 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (bsink);
462 GstFlowReturn ret = GST_FLOW_OK;
463
464 GST_TRACE ("preparing buffer:%p", buf);
465
466 if (GST_VIDEO_SINK_WIDTH (sink) < 1 || GST_VIDEO_SINK_HEIGHT (sink) < 1) {
467 return GST_FLOW_NOT_NEGOTIATED;
468 }
469
470 GST_OBJECT_LOCK (sink);
471 ret = gst_d3d9_overlay_prepare (sink, buf);
472 GST_OBJECT_UNLOCK (sink);
473 return ret;
474 }
475
476 static gboolean
477 gst_d3dvideosink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
478 {
479 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (bsink);
480 GstBufferPool *pool;
481 GstStructure *config;
482 GstCaps *caps;
483 guint size;
484 gboolean need_pool;
485 GstStructure *allocation_meta = NULL;
486
487 gst_query_parse_allocation (query, &caps, &need_pool);
488 if (!caps) {
489 GST_DEBUG_OBJECT (sink, "no caps specified");
490 return FALSE;
491 }
492 #ifdef DISABLE_BUFFER_POOL
493 return TRUE;
494 #endif
495
496 /* FIXME re-using buffer pool breaks renegotiation */
497 GST_OBJECT_LOCK (sink);
498 pool = sink->pool ? gst_object_ref (sink->pool) : NULL;
499 GST_OBJECT_UNLOCK (sink);
500
501 if (pool) {
502 GstCaps *pcaps;
503
504 /* we had a pool, check caps */
505 GST_DEBUG_OBJECT (sink, "check existing pool caps");
506 config = gst_buffer_pool_get_config (pool);
507 gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
508
509 if (!gst_caps_is_equal (caps, pcaps)) {
510 GST_DEBUG_OBJECT (sink, "pool has different caps");
511 /* different caps, we can't use this pool */
512 gst_object_unref (pool);
513 pool = NULL;
514 }
515 gst_structure_free (config);
516 } else {
517 GstVideoInfo info;
518
519 if (!gst_video_info_from_caps (&info, caps)) {
520 GST_ERROR_OBJECT (sink, "allocation query has invalid caps %"
521 GST_PTR_FORMAT, caps);
522 return FALSE;
523 }
524
525 /* the normal size of a frame */
526 size = info.size;
527 }
528
529 if (pool == NULL && need_pool) {
530 GST_DEBUG_OBJECT (sink, "create new pool");
531 pool = gst_d3dsurface_buffer_pool_new (sink);
532
533 config = gst_buffer_pool_get_config (pool);
534 /* we need at least 2 buffer because we hold on to the last one */
535 gst_buffer_pool_config_set_params (config, caps, size, 2, 0);
536 if (!gst_buffer_pool_set_config (pool, config)) {
537 gst_object_unref (pool);
538 GST_ERROR_OBJECT (sink, "failed to set pool configuration");
539 return FALSE;
540 }
541 }
542
543 /* we need at least 2 buffer because we hold on to the last one */
544 gst_query_add_allocation_pool (query, pool, size, 2, 0);
545 if (pool)
546 gst_object_unref (pool);
547
548 if (sink->width != 0 && sink->height != 0) {
549 allocation_meta =
550 gst_structure_new ("GstVideoOverlayCompositionMeta",
551 "width", G_TYPE_UINT, sink->width,
552 "height", G_TYPE_UINT, sink->height, NULL);
553 GST_DEBUG ("sending allocation query with size %dx%d",
554 sink->width, sink->height);
555 }
556 gst_query_add_allocation_meta (query,
557 GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE, allocation_meta);
558 if (allocation_meta)
559 gst_structure_free (allocation_meta);
560
561 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
562 gst_query_add_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, NULL);
563
564 return TRUE;
565 }
566
567 /* PUBLIC FUNCTIONS */
568
569 /* Interface Registrations */
570
571 static void
572 gst_d3dvideosink_video_overlay_interface_init (GstVideoOverlayInterface * iface)
573 {
574 iface->set_window_handle = gst_d3dvideosink_set_window_handle;
575 iface->set_render_rectangle = gst_d3dvideosink_set_render_rectangle;
576 iface->expose = gst_d3dvideosink_expose;
577 }
578
579 static void
580 gst_d3dvideosink_navigation_interface_init (GstNavigationInterface * iface)
581 {
582 iface->send_event_simple = gst_d3dvideosink_navigation_send_event;
583 }
584
585 /* Video Render Code */
586
587 static void
588 gst_d3dvideosink_set_window_handle (GstVideoOverlay * overlay,
589 guintptr window_id)
590 {
591 d3d_set_window_handle (GST_D3DVIDEOSINK (overlay), window_id, FALSE);
592 }
593
594 static void
595 gst_d3dvideosink_set_render_rectangle (GstVideoOverlay * overlay, gint x,
596 gint y, gint width, gint height)
597 {
598 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (overlay);
599 sink->render_rect.x = x;
600 sink->render_rect.y = y;
601 sink->render_rect.w = width;
602 sink->render_rect.h = height;
603 d3d_set_render_rectangle (sink);
604 }
605
606 static void
607 gst_d3dvideosink_expose (GstVideoOverlay * overlay)
608 {
609 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (overlay);
610 d3d_expose_window (sink);
611 }
612
613 static GstFlowReturn
614 gst_d3dvideosink_show_frame (GstVideoSink * vsink, GstBuffer * buffer)
615 {
616 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (vsink);
617 return d3d_render_buffer (sink, buffer);
618 }
619
620 /* Video Navigation Events */
621
622 static void
623 gst_d3dvideosink_navigation_send_event (GstNavigation * navigation,
624 GstEvent * event)
625 {
626 GstD3DVideoSink *sink = GST_D3DVIDEOSINK (navigation);
627
628 GstPad *pad;
629 if ((pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (sink)))) {
630 if (!gst_pad_send_event (pad, gst_event_ref (event))) {
631 /* If upstream didn't handle the event we'll post a message with it
632 * for the application in case it wants to do something with it */
633 gst_element_post_message (GST_ELEMENT_CAST (sink),
634 gst_navigation_message_new_event (GST_OBJECT_CAST (sink), event));
635 }
636 gst_event_unref (event);
637 gst_object_unref (pad);
638 }
639 }
640
641 /* PRIVATE FUNCTIONS */
642
643
644 /* Plugin entry point */
645 static gboolean
646 plugin_init (GstPlugin * plugin)
647 {
648 if (!gst_element_register (plugin, ELEMENT_NAME,
649 GST_RANK_SECONDARY, GST_TYPE_D3DVIDEOSINK))
650 return FALSE;
651
652 return TRUE;
653 }
654
655 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
656 GST_VERSION_MINOR,
657 d3d,
658 "Direct3D plugin",
659 plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)