1 /* GStreamer
2  * Copyright (C) 2007 Haakon Sporsheim <hakon.sporsheim@tandberg.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 /**
21  * SECTION:element-gdiscreencapsrc
22  * @title: gdiscreencapsrc
23  *
24  * This element uses GDI to capture the desktop or a portion of it.
25  * The default is capturing the whole desktop, but #GstGDIScreenCapSrc:x,
26  * #GstGDIScreenCapSrc:y, #GstGDIScreenCapSrc:width and
27  * #GstGDIScreenCapSrc:height can be used to select a particular region.
28  * Use #GstGDIScreenCapSrc:monitor for changing which monitor to capture
29  * from.
30  *
31  * Set #GstGDIScreenCapSrc:cursor to TRUE to include the mouse cursor.
32  *
33  * ## Example pipelines
34  * |[
35  * gst-launch-1.0 gdiscreencapsrc ! videoconvert ! dshowvideosink
36  * ]| Capture the desktop and display it.
37  * |[
38  * gst-launch-1.0 gdiscreencapsrc x=100 y=100 width=320 height=240 cursor=TRUE
39  * ! videoconvert ! dshowvideosink
40  * ]| Capture a portion of the desktop, including the mouse cursor, and
41  * display it.
42  *
43  */
44 
45 #ifdef HAVE_CONFIG_H
46 #include "config.h"
47 #endif
48 
49 #include "gstgdiscreencapsrc.h"
50 #include <gst/video/video.h>
51 
52 GST_DEBUG_CATEGORY_STATIC (gdiscreencapsrc_debug);
53 
54 static GstStaticPadTemplate src_template =
55 GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
56     GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("BGR")));
57 
58 #define gst_gdiscreencapsrc_parent_class parent_class
59 G_DEFINE_TYPE (GstGDIScreenCapSrc, gst_gdiscreencapsrc, GST_TYPE_PUSH_SRC);
60 
61 enum
62 {
63   PROP_0,
64   PROP_MONITOR,
65   PROP_SHOW_CURSOR,
66   PROP_X_POS,
67   PROP_Y_POS,
68   PROP_WIDTH,
69   PROP_HEIGHT
70 };
71 
72 /* Fwd. decl. */
73 static void gst_gdiscreencapsrc_dispose (GObject * object);
74 static void gst_gdiscreencapsrc_set_property (GObject * object, guint prop_id,
75     const GValue * value, GParamSpec * pspec);
76 static void gst_gdiscreencapsrc_get_property (GObject * object, guint prop_id,
77     GValue * value, GParamSpec * pspec);
78 
79 static GstCaps *gst_gdiscreencapsrc_fixate (GstBaseSrc * bsrc, GstCaps * caps);
80 static gboolean gst_gdiscreencapsrc_set_caps (GstBaseSrc * bsrc,
81     GstCaps * caps);
82 static GstCaps *gst_gdiscreencapsrc_get_caps (GstBaseSrc * bsrc,
83     GstCaps * filter);
84 static gboolean gst_gdiscreencapsrc_start (GstBaseSrc * bsrc);
85 static gboolean gst_gdiscreencapsrc_unlock (GstBaseSrc * bsrc);
86 
87 static GstFlowReturn gst_gdiscreencapsrc_create (GstPushSrc * src,
88     GstBuffer ** buf);
89 
90 static gboolean gst_gdiscreencapsrc_screen_capture (GstGDIScreenCapSrc * src,
91     GstBuffer * buf);
92 
93 /* Implementation. */
94 static void
gst_gdiscreencapsrc_class_init(GstGDIScreenCapSrcClass * klass)95 gst_gdiscreencapsrc_class_init (GstGDIScreenCapSrcClass * klass)
96 {
97   GObjectClass *go_class;
98   GstElementClass *e_class;
99   GstBaseSrcClass *bs_class;
100   GstPushSrcClass *ps_class;
101 
102   go_class = (GObjectClass *) klass;
103   e_class = (GstElementClass *) klass;
104   bs_class = (GstBaseSrcClass *) klass;
105   ps_class = (GstPushSrcClass *) klass;
106 
107   go_class->dispose = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_dispose);
108   go_class->set_property = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_set_property);
109   go_class->get_property = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_get_property);
110 
111   bs_class->get_caps = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_get_caps);
112   bs_class->set_caps = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_set_caps);
113   bs_class->start = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_start);
114   bs_class->unlock = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_unlock);
115   bs_class->fixate = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_fixate);
116 
117   ps_class->create = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_create);
118 
119   g_object_class_install_property (go_class, PROP_MONITOR,
120       g_param_spec_int ("monitor",
121           "Monitor", "Which monitor to use (0 = 1st monitor and default)",
122           0, G_MAXINT, 0, G_PARAM_READWRITE));
123 
124   g_object_class_install_property (go_class, PROP_SHOW_CURSOR,
125       g_param_spec_boolean ("cursor", "Show mouse cursor",
126           "Whether to show mouse cursor (default off)",
127           FALSE, G_PARAM_READWRITE));
128 
129   g_object_class_install_property (go_class, PROP_X_POS,
130       g_param_spec_int ("x", "X",
131           "Horizontal coordinate of top left corner for the screen capture "
132           "area", 0, G_MAXINT, 0, G_PARAM_READWRITE));
133   g_object_class_install_property (go_class, PROP_Y_POS,
134       g_param_spec_int ("y", "Y",
135           "Vertical coordinate of top left corner for the screen capture "
136           "area", 0, G_MAXINT, 0, G_PARAM_READWRITE));
137 
138   g_object_class_install_property (go_class, PROP_WIDTH,
139       g_param_spec_int ("width", "Width",
140           "Width of screen capture area (0 = maximum)",
141           0, G_MAXINT, 0, G_PARAM_READWRITE));
142   g_object_class_install_property (go_class, PROP_HEIGHT,
143       g_param_spec_int ("height", "Height",
144           "Height of screen capture area (0 = maximum)",
145           0, G_MAXINT, 0, G_PARAM_READWRITE));
146 
147   gst_element_class_add_static_pad_template (e_class, &src_template);
148   gst_element_class_set_static_metadata (e_class,
149       "GDI screen capture source", "Source/Video", "Captures screen",
150       "Haakon Sporsheim <hakon.sporsheim@tandberg.com>");
151 
152   GST_DEBUG_CATEGORY_INIT (gdiscreencapsrc_debug,
153       "gdiscreencapsrc", 0, "GDI screen capture source");
154 }
155 
156 static void
gst_gdiscreencapsrc_init(GstGDIScreenCapSrc * src)157 gst_gdiscreencapsrc_init (GstGDIScreenCapSrc * src)
158 {
159   /* Set src element inital values... */
160   src->dibMem = NULL;
161   src->hBitmap = (HBITMAP) INVALID_HANDLE_VALUE;
162   src->memDC = (HDC) INVALID_HANDLE_VALUE;
163   src->capture_x = 0;
164   src->capture_y = 0;
165   src->capture_w = 0;
166   src->capture_h = 0;
167 
168   src->monitor = 0;
169   src->show_cursor = FALSE;
170 
171   gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
172   gst_base_src_set_live (GST_BASE_SRC (src), TRUE);
173 }
174 
175 static void
gst_gdiscreencapsrc_dispose(GObject * object)176 gst_gdiscreencapsrc_dispose (GObject * object)
177 {
178   GstGDIScreenCapSrc *src = GST_GDISCREENCAPSRC (object);
179 
180   if (src->hBitmap != INVALID_HANDLE_VALUE)
181     DeleteObject (src->hBitmap);
182 
183   if (src->memDC != INVALID_HANDLE_VALUE)
184     DeleteDC (src->memDC);
185 
186   src->hBitmap = (HBITMAP) INVALID_HANDLE_VALUE;
187   src->memDC = (HDC) INVALID_HANDLE_VALUE;
188   src->dibMem = NULL;
189 
190   G_OBJECT_CLASS (parent_class)->dispose (object);
191 }
192 
193 static void
gst_gdiscreencapsrc_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)194 gst_gdiscreencapsrc_set_property (GObject * object, guint prop_id,
195     const GValue * value, GParamSpec * pspec)
196 {
197   GstGDIScreenCapSrc *src = GST_GDISCREENCAPSRC (object);
198 
199   switch (prop_id) {
200     case PROP_MONITOR:
201       if (g_value_get_int (value) >= GetSystemMetrics (SM_CMONITORS)) {
202         G_OBJECT_WARN_INVALID_PSPEC (object, "Monitor", prop_id, pspec);
203         break;
204       }
205       src->monitor = g_value_get_int (value);
206       break;
207     case PROP_SHOW_CURSOR:
208       src->show_cursor = g_value_get_boolean (value);
209       break;
210     case PROP_X_POS:
211       src->capture_x = g_value_get_int (value);
212       break;
213     case PROP_Y_POS:
214       src->capture_y = g_value_get_int (value);
215       break;
216     case PROP_WIDTH:
217       src->capture_w = g_value_get_int (value);
218       break;
219     case PROP_HEIGHT:
220       src->capture_h = g_value_get_int (value);
221       break;
222     default:
223       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
224       break;
225   };
226 }
227 
228 static void
gst_gdiscreencapsrc_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)229 gst_gdiscreencapsrc_get_property (GObject * object, guint prop_id,
230     GValue * value, GParamSpec * pspec)
231 {
232   GstGDIScreenCapSrc *src = GST_GDISCREENCAPSRC (object);
233 
234   switch (prop_id) {
235     case PROP_MONITOR:
236       g_value_set_int (value, src->monitor);
237       break;
238     case PROP_SHOW_CURSOR:
239       g_value_set_boolean (value, src->show_cursor);
240       break;
241     case PROP_X_POS:
242       g_value_set_int (value, src->capture_x);
243       break;
244     case PROP_Y_POS:
245       g_value_set_int (value, src->capture_y);
246       break;
247     case PROP_WIDTH:
248       g_value_set_int (value, src->capture_w);
249       break;
250     case PROP_HEIGHT:
251       g_value_set_int (value, src->capture_h);
252       break;
253     default:
254       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
255       break;
256   };
257 }
258 
259 static GstCaps *
gst_gdiscreencapsrc_fixate(GstBaseSrc * bsrc,GstCaps * caps)260 gst_gdiscreencapsrc_fixate (GstBaseSrc * bsrc, GstCaps * caps)
261 {
262   GstStructure *structure;
263 
264   caps = gst_caps_make_writable (caps);
265 
266   structure = gst_caps_get_structure (caps, 0);
267 
268   gst_structure_fixate_field_nearest_int (structure, "width", 640);
269   gst_structure_fixate_field_nearest_int (structure, "height", 480);
270   gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
271 
272   caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
273 
274   return caps;
275 }
276 
277 static gboolean
gst_gdiscreencapsrc_set_caps(GstBaseSrc * bsrc,GstCaps * caps)278 gst_gdiscreencapsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
279 {
280   GstGDIScreenCapSrc *src = GST_GDISCREENCAPSRC (bsrc);
281   HWND capture;
282   HDC device;
283   GstStructure *structure;
284   const GValue *framerate;
285 
286   structure = gst_caps_get_structure (caps, 0);
287 
288   src->src_rect = src->screen_rect;
289   if (src->capture_w && src->capture_h) {
290     src->src_rect.left += src->capture_x;
291     src->src_rect.top += src->capture_y;
292     src->src_rect.right = src->src_rect.left + src->capture_w;
293     src->src_rect.bottom = src->src_rect.top + src->capture_h;
294   }
295 
296   framerate = gst_structure_get_value (structure, "framerate");
297   if (framerate) {
298     src->rate_numerator = gst_value_get_fraction_numerator (framerate);
299     src->rate_denominator = gst_value_get_fraction_denominator (framerate);
300   }
301 
302   src->info.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
303   src->info.bmiHeader.biWidth = src->src_rect.right - src->src_rect.left;
304   src->info.bmiHeader.biHeight = src->src_rect.top - src->src_rect.bottom;
305   src->info.bmiHeader.biPlanes = 1;
306   src->info.bmiHeader.biBitCount = 24;
307   src->info.bmiHeader.biCompression = BI_RGB;
308   src->info.bmiHeader.biSizeImage = 0;
309   src->info.bmiHeader.biXPelsPerMeter = 0;
310   src->info.bmiHeader.biYPelsPerMeter = 0;
311   src->info.bmiHeader.biClrUsed = 0;
312   src->info.bmiHeader.biClrImportant = 0;
313 
314   /* Cleanup first */
315   if (src->hBitmap != INVALID_HANDLE_VALUE)
316     DeleteObject (src->hBitmap);
317 
318   if (src->memDC != INVALID_HANDLE_VALUE)
319     DeleteDC (src->memDC);
320 
321   /* Allocate */
322   capture = GetDesktopWindow ();
323   device = GetDC (capture);
324   src->hBitmap = CreateDIBSection (device, &(src->info), DIB_RGB_COLORS,
325       (void **) &(src->dibMem), 0, 0);
326   src->memDC = CreateCompatibleDC (device);
327   SelectObject (src->memDC, src->hBitmap);
328   ReleaseDC (capture, device);
329 
330   GST_DEBUG_OBJECT (src, "size %dx%d, %d/%d fps",
331       (gint) src->info.bmiHeader.biWidth,
332       (gint) (-src->info.bmiHeader.biHeight),
333       src->rate_numerator, src->rate_denominator);
334 
335   return TRUE;
336 }
337 
338 static GstCaps *
gst_gdiscreencapsrc_get_caps(GstBaseSrc * bsrc,GstCaps * filter)339 gst_gdiscreencapsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
340 {
341   GstGDIScreenCapSrc *src = GST_GDISCREENCAPSRC (bsrc);
342   RECT rect_dst;
343   GstCaps *caps;
344 
345   src->screen_rect = rect_dst = gst_win32_get_monitor_rect (src->monitor);
346 
347   if (src->capture_w && src->capture_h &&
348       src->capture_x + src->capture_w < rect_dst.right - rect_dst.left &&
349       src->capture_y + src->capture_h < rect_dst.bottom - rect_dst.top) {
350     rect_dst.left = src->capture_x;
351     rect_dst.top = src->capture_y;
352     rect_dst.right = src->capture_x + src->capture_w;
353     rect_dst.bottom = src->capture_y + src->capture_h;
354   } else {
355     /* Default values. */
356     src->capture_x = src->capture_y = 0;
357     src->capture_w = src->capture_h = 0;
358   }
359 
360   GST_DEBUG ("width = %d, height=%d",
361       (gint) (rect_dst.right - rect_dst.left),
362       (gint) (rect_dst.bottom - rect_dst.top));
363 
364   caps = gst_caps_new_simple ("video/x-raw",
365       "format", G_TYPE_STRING, "BGR",
366       "width", G_TYPE_INT, rect_dst.right - rect_dst.left,
367       "height", G_TYPE_INT, rect_dst.bottom - rect_dst.top,
368       "framerate", GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1,
369       "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL);
370 
371   if (filter) {
372     GstCaps *tmp =
373         gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
374     gst_caps_unref (caps);
375     caps = tmp;
376   }
377 
378   return caps;
379 }
380 
381 static gboolean
gst_gdiscreencapsrc_start(GstBaseSrc * bsrc)382 gst_gdiscreencapsrc_start (GstBaseSrc * bsrc)
383 {
384   GstGDIScreenCapSrc *src = GST_GDISCREENCAPSRC (bsrc);
385 
386   src->frame_number = -1;
387 
388   return TRUE;
389 }
390 
391 static gboolean
gst_gdiscreencapsrc_unlock(GstBaseSrc * bsrc)392 gst_gdiscreencapsrc_unlock (GstBaseSrc * bsrc)
393 {
394   GstGDIScreenCapSrc *src = GST_GDISCREENCAPSRC (bsrc);
395 
396   GST_OBJECT_LOCK (src);
397   if (src->clock_id) {
398     GST_DEBUG_OBJECT (src, "Waking up waiting clock");
399     gst_clock_id_unschedule (src->clock_id);
400   }
401   GST_OBJECT_UNLOCK (src);
402 
403   return TRUE;
404 }
405 
406 static GstFlowReturn
gst_gdiscreencapsrc_create(GstPushSrc * push_src,GstBuffer ** buf)407 gst_gdiscreencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
408 {
409   GstGDIScreenCapSrc *src = GST_GDISCREENCAPSRC (push_src);
410   GstBuffer *new_buf;
411   gint new_buf_size;
412   GstClock *clock;
413   GstClockTime buf_time, buf_dur;
414   guint64 frame_number;
415 
416   if (G_UNLIKELY (!src->info.bmiHeader.biWidth ||
417           !src->info.bmiHeader.biHeight)) {
418     GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL),
419         ("format wasn't negotiated before create function"));
420     return GST_FLOW_NOT_NEGOTIATED;
421   }
422 
423   new_buf_size = GST_ROUND_UP_4 (src->info.bmiHeader.biWidth * 3) *
424       (-src->info.bmiHeader.biHeight);
425 
426   GST_LOG_OBJECT (src,
427       "creating buffer of %d bytes with %dx%d image",
428       new_buf_size, (gint) src->info.bmiHeader.biWidth,
429       (gint) (-src->info.bmiHeader.biHeight));
430 
431   new_buf = gst_buffer_new_and_alloc (new_buf_size);
432 
433   clock = gst_element_get_clock (GST_ELEMENT (src));
434   if (clock != NULL) {
435     GstClockTime time, base_time;
436 
437     /* Calculate sync time. */
438 
439     time = gst_clock_get_time (clock);
440     base_time = gst_element_get_base_time (GST_ELEMENT (src));
441     buf_time = time - base_time;
442 
443     if (src->rate_numerator) {
444       frame_number = gst_util_uint64_scale (buf_time,
445           src->rate_numerator, GST_SECOND * src->rate_denominator);
446     } else {
447       frame_number = -1;
448     }
449   } else {
450     buf_time = GST_CLOCK_TIME_NONE;
451     frame_number = -1;
452   }
453 
454   if (frame_number != -1 && frame_number == src->frame_number) {
455     GstClockID id;
456     GstClockReturn ret;
457 
458     /* Need to wait for the next frame */
459     frame_number += 1;
460 
461     /* Figure out what the next frame time is */
462     buf_time = gst_util_uint64_scale (frame_number,
463         src->rate_denominator * GST_SECOND, src->rate_numerator);
464 
465     id = gst_clock_new_single_shot_id (clock,
466         buf_time + gst_element_get_base_time (GST_ELEMENT (src)));
467     GST_OBJECT_LOCK (src);
468     src->clock_id = id;
469     GST_OBJECT_UNLOCK (src);
470 
471     GST_DEBUG_OBJECT (src, "Waiting for next frame time %" G_GUINT64_FORMAT,
472         buf_time);
473     ret = gst_clock_id_wait (id, NULL);
474     GST_OBJECT_LOCK (src);
475 
476     gst_clock_id_unref (id);
477     src->clock_id = NULL;
478     if (ret == GST_CLOCK_UNSCHEDULED) {
479       /* Got woken up by the unlock function */
480       GST_OBJECT_UNLOCK (src);
481       return GST_FLOW_FLUSHING;
482     }
483     GST_OBJECT_UNLOCK (src);
484 
485     /* Duration is a complete 1/fps frame duration */
486     buf_dur =
487         gst_util_uint64_scale_int (GST_SECOND, src->rate_denominator,
488         src->rate_numerator);
489   } else if (frame_number != -1) {
490     GstClockTime next_buf_time;
491 
492     GST_DEBUG_OBJECT (src, "No need to wait for next frame time %"
493         G_GUINT64_FORMAT " next frame = %" G_GINT64_FORMAT " prev = %"
494         G_GINT64_FORMAT, buf_time, frame_number, src->frame_number);
495     next_buf_time = gst_util_uint64_scale (frame_number + 1,
496         src->rate_denominator * GST_SECOND, src->rate_numerator);
497     /* Frame duration is from now until the next expected capture time */
498     buf_dur = next_buf_time - buf_time;
499   } else {
500     buf_dur = GST_CLOCK_TIME_NONE;
501   }
502   src->frame_number = frame_number;
503 
504   GST_BUFFER_TIMESTAMP (new_buf) = buf_time;
505   GST_BUFFER_DURATION (new_buf) = buf_dur;
506 
507   /* Do screen capture and put it into buffer... */
508   gst_gdiscreencapsrc_screen_capture (src, new_buf);
509 
510   gst_object_unref (clock);
511 
512   *buf = new_buf;
513   return GST_FLOW_OK;
514 }
515 
516 static gboolean
gst_gdiscreencapsrc_screen_capture(GstGDIScreenCapSrc * src,GstBuffer * buf)517 gst_gdiscreencapsrc_screen_capture (GstGDIScreenCapSrc * src, GstBuffer * buf)
518 {
519   HWND capture;
520   HDC winDC;
521   gint height, width;
522   GstMapInfo map;
523 
524   if (G_UNLIKELY (!src->hBitmap || !src->dibMem))
525     return FALSE;
526 
527   width = src->info.bmiHeader.biWidth;
528   height = -src->info.bmiHeader.biHeight;
529 
530   /* Capture screen */
531   capture = GetDesktopWindow ();
532   winDC = GetWindowDC (capture);
533 
534   BitBlt (src->memDC, 0, 0, width, height,
535       winDC, src->src_rect.left, src->src_rect.top, SRCCOPY);
536 
537   ReleaseDC (capture, winDC);
538 
539   /* Capture mouse cursor */
540   if (src->show_cursor) {
541     CURSORINFO ci;
542 
543     ci.cbSize = sizeof (CURSORINFO);
544     GetCursorInfo (&ci);
545     if (ci.flags & CURSOR_SHOWING) {
546       ICONINFO ii;
547 
548       GetIconInfo (ci.hCursor, &ii);
549 
550       DrawIconEx (src->memDC,
551           ci.ptScreenPos.x - src->src_rect.left - ii.xHotspot,
552           ci.ptScreenPos.y - src->src_rect.top - ii.yHotspot, ci.hCursor, 0, 0,
553           0, NULL, DI_DEFAULTSIZE | DI_NORMAL | DI_COMPAT);
554 
555       DeleteObject (ii.hbmColor);
556       DeleteObject (ii.hbmMask);
557     }
558   }
559 
560   /* Copy DC bits to GST buffer */
561   gst_buffer_map (buf, &map, GST_MAP_WRITE);
562   memcpy (map.data, src->dibMem, map.size);
563   gst_buffer_unmap (buf, &map);
564 
565   return TRUE;
566 }
567