• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) <2005> Julien Moutte <julien@moutte.net>
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 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #ifdef HAVE_XSHM
25 #include <sys/types.h>
26 #include <sys/ipc.h>
27 #include <sys/shm.h>
28 #endif /* HAVE_XSHM */
29 
30 #include <X11/Xlib.h>
31 #include <X11/Xutil.h>
32 
33 #ifdef HAVE_XSHM
34 #include <X11/extensions/XShm.h>
35 #endif /* HAVE_XSHM */
36 
37 #include <string.h>
38 #include <math.h>
39 
40 /* Object header */
41 #include "xvimageallocator.h"
42 
43 /* Debugging category */
44 #include <gst/gstinfo.h>
45 
46 /* Helper functions */
47 #include <gst/video/video.h>
48 
49 
50 GST_DEBUG_CATEGORY_STATIC (gst_debug_xvimageallocator);
51 #define GST_CAT_DEFAULT gst_debug_xvimageallocator
52 
53 struct _GstXvImageMemory
54 {
55   GstMemory parent;
56 
57   gint im_format;
58   GstVideoInfo info;
59   GstVideoRectangle crop;
60 
61   XvImage *xvimage;
62 
63 #ifdef HAVE_XSHM
64   XShmSegmentInfo SHMInfo;
65 #endif                          /* HAVE_XSHM */
66 };
67 
68 
69 struct _GstXvImageAllocator
70 {
71   GstAllocator parent;
72 
73   GstXvContext *context;
74 };
75 
76 struct _GstXvImageAllocatorClass
77 {
78   GstAllocatorClass parent_class;
79 };
80 
81 gboolean
gst_xvimage_memory_is_from_context(GstMemory * mem,GstXvContext * context)82 gst_xvimage_memory_is_from_context (GstMemory * mem, GstXvContext * context)
83 {
84   GstXvImageAllocator *alloc;
85 
86   if (!GST_IS_XVIMAGE_ALLOCATOR (mem->allocator))
87     return FALSE;
88 
89   alloc = GST_XVIMAGE_ALLOCATOR_CAST (mem->allocator);
90 
91   if (alloc->context != context)
92     return FALSE;
93 
94   return TRUE;
95 }
96 
97 gint
gst_xvimage_memory_get_format(GstXvImageMemory * xvmem)98 gst_xvimage_memory_get_format (GstXvImageMemory * xvmem)
99 {
100   g_return_val_if_fail (xvmem != NULL, FALSE);
101 
102   return xvmem->im_format;
103 }
104 
105 XvImage *
gst_xvimage_memory_get_xvimage(GstXvImageMemory * xvmem)106 gst_xvimage_memory_get_xvimage (GstXvImageMemory * xvmem)
107 {
108   g_return_val_if_fail (xvmem != NULL, FALSE);
109 
110   return xvmem->xvimage;
111 }
112 
113 gboolean
gst_xvimage_memory_get_crop(GstXvImageMemory * xvmem,GstVideoRectangle * crop)114 gst_xvimage_memory_get_crop (GstXvImageMemory * xvmem, GstVideoRectangle * crop)
115 {
116   g_return_val_if_fail (xvmem != NULL, FALSE);
117 
118   if (crop)
119     *crop = xvmem->crop;
120 
121   return TRUE;
122 }
123 
124 
125 /* X11 stuff */
126 static gboolean error_caught = FALSE;
127 
128 static int
gst_xvimage_handle_xerror(Display * display,XErrorEvent * xevent)129 gst_xvimage_handle_xerror (Display * display, XErrorEvent * xevent)
130 {
131   char error_msg[1024];
132 
133   XGetErrorText (display, xevent->error_code, error_msg, 1024);
134   GST_DEBUG ("xvimage triggered an XError. error: %s", error_msg);
135   error_caught = TRUE;
136   return 0;
137 }
138 
139 static GstMemory *
gst_xvimage_allocator_dummy_alloc(GstAllocator * allocator,gsize size,GstAllocationParams * params)140 gst_xvimage_allocator_dummy_alloc (GstAllocator * allocator, gsize size,
141     GstAllocationParams * params)
142 {
143   return NULL;
144 }
145 
146 static void
gst_xvimage_allocator_free(GstAllocator * allocator,GstMemory * gmem)147 gst_xvimage_allocator_free (GstAllocator * allocator, GstMemory * gmem)
148 {
149   GstXvImageMemory *mem = (GstXvImageMemory *) gmem;
150   GstXvImageAllocator *alloc = (GstXvImageAllocator *) allocator;
151   GstXvContext *context;
152 
153   if (gmem->parent)
154     goto sub_mem;
155 
156   context = alloc->context;
157 
158   GST_DEBUG_OBJECT (allocator, "free memory %p", mem);
159 
160   g_mutex_lock (&context->lock);
161 
162 #ifdef HAVE_XSHM
163   if (context->use_xshm) {
164     if (mem->SHMInfo.shmaddr != ((void *) -1)) {
165       GST_DEBUG_OBJECT (allocator, "XServer ShmDetaching from 0x%x id 0x%lx",
166           mem->SHMInfo.shmid, mem->SHMInfo.shmseg);
167       XShmDetach (context->disp, &mem->SHMInfo);
168       XSync (context->disp, FALSE);
169       shmdt (mem->SHMInfo.shmaddr);
170       mem->SHMInfo.shmaddr = (void *) -1;
171     }
172     if (mem->xvimage)
173       XFree (mem->xvimage);
174   } else
175 #endif /* HAVE_XSHM */
176   {
177     if (mem->xvimage) {
178       g_free (mem->xvimage->data);
179       XFree (mem->xvimage);
180     }
181   }
182 
183   XSync (context->disp, FALSE);
184 
185   g_mutex_unlock (&context->lock);
186 
187 sub_mem:
188   g_slice_free (GstXvImageMemory, mem);
189 }
190 
191 static gpointer
gst_xvimage_memory_map(GstXvImageMemory * mem,gsize maxsize,GstMapFlags flags)192 gst_xvimage_memory_map (GstXvImageMemory * mem, gsize maxsize,
193     GstMapFlags flags)
194 {
195   return mem->xvimage->data + mem->parent.offset;
196 }
197 
198 static gboolean
gst_xvimage_memory_unmap(GstXvImageMemory * mem)199 gst_xvimage_memory_unmap (GstXvImageMemory * mem)
200 {
201   return TRUE;
202 }
203 
204 static GstXvImageMemory *
gst_xvimage_memory_share(GstXvImageMemory * mem,gssize offset,gsize size)205 gst_xvimage_memory_share (GstXvImageMemory * mem, gssize offset, gsize size)
206 {
207   GstXvImageMemory *sub;
208   GstMemory *parent;
209 
210   /* We can only share the complete memory */
211   if (offset != 0)
212     return NULL;
213   if (size != -1 && size != mem->xvimage->data_size)
214     return NULL;
215 
216   GST_DEBUG ("share memory %p", mem);
217 
218   /* find the real parent */
219   if ((parent = mem->parent.parent) == NULL)
220     parent = (GstMemory *) mem;
221 
222   if (size == -1)
223     size = mem->parent.size - offset;
224 
225   /* the shared memory is always readonly */
226   sub = g_slice_new (GstXvImageMemory);
227 
228   gst_memory_init (GST_MEMORY_CAST (sub), GST_MINI_OBJECT_FLAGS (parent) |
229       GST_MINI_OBJECT_FLAG_LOCK_READONLY, mem->parent.allocator,
230       &mem->parent, mem->parent.maxsize, mem->parent.align,
231       mem->parent.offset + offset, size);
232 
233   sub->info = mem->info;
234   sub->im_format = mem->im_format;
235   sub->crop = mem->crop;
236   sub->xvimage = mem->xvimage;
237 #ifdef HAVE_XSHM
238   sub->SHMInfo = mem->SHMInfo;
239 #endif
240 
241   return sub;
242 }
243 
244 static GstXvImageMemory *
gst_xvimage_memory_copy(GstMemory * gmem,gssize offset,gsize size)245 gst_xvimage_memory_copy (GstMemory * gmem, gssize offset, gsize size)
246 {
247   GstXvImageMemory *mem, *copy;
248 
249   mem = (GstXvImageMemory *) gmem;
250 
251   /* We can only copy the complete memory */
252   if (offset != 0)
253     return NULL;
254   if (size != -1 && size != mem->xvimage->data_size)
255     return NULL;
256 
257   GST_DEBUG ("copy memory %p", mem);
258 
259   copy = (GstXvImageMemory *)
260       gst_xvimage_allocator_alloc (GST_XVIMAGE_ALLOCATOR_CAST (gmem->allocator),
261       mem->im_format, &mem->info, mem->xvimage->width,
262       mem->xvimage->height, &mem->crop, NULL);
263 
264   memcpy (copy->xvimage->data + copy->parent.offset,
265       mem->xvimage->data + mem->parent.offset, mem->xvimage->data_size);
266 
267   return copy;
268 }
269 
270 #define gst_xvimage_allocator_parent_class parent_class
271 G_DEFINE_TYPE (GstXvImageAllocator, gst_xvimage_allocator, GST_TYPE_ALLOCATOR);
272 
273 static void gst_xvimage_allocator_finalize (GObject * object);
274 
275 #define GST_XVIMAGE_ALLOCATOR_NAME "xvimage"
276 
277 static void
gst_xvimage_allocator_class_init(GstXvImageAllocatorClass * klass)278 gst_xvimage_allocator_class_init (GstXvImageAllocatorClass * klass)
279 {
280   GObjectClass *gobject_class;
281   GstAllocatorClass *allocator_class;
282 
283   gobject_class = (GObjectClass *) klass;
284   allocator_class = (GstAllocatorClass *) klass;
285 
286   gobject_class->finalize = gst_xvimage_allocator_finalize;
287 
288   allocator_class->alloc = gst_xvimage_allocator_dummy_alloc;
289   allocator_class->free = gst_xvimage_allocator_free;
290 
291   GST_DEBUG_CATEGORY_INIT (gst_debug_xvimageallocator, "xvimageallocator", 0,
292       "xvimageallocator object");
293 }
294 
295 static void
gst_xvimage_allocator_init(GstXvImageAllocator * allocator)296 gst_xvimage_allocator_init (GstXvImageAllocator * allocator)
297 {
298   GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator);
299 
300   alloc->mem_type = GST_XVIMAGE_ALLOCATOR_NAME;
301   alloc->mem_map = (GstMemoryMapFunction) gst_xvimage_memory_map;
302   alloc->mem_unmap = (GstMemoryUnmapFunction) gst_xvimage_memory_unmap;
303   alloc->mem_share = (GstMemoryShareFunction) gst_xvimage_memory_share;
304   alloc->mem_copy = (GstMemoryShareFunction) gst_xvimage_memory_copy;
305   /* fallback is_span */
306 
307   GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC);
308 }
309 
310 static void
gst_xvimage_allocator_finalize(GObject * object)311 gst_xvimage_allocator_finalize (GObject * object)
312 {
313   GstXvImageAllocator *alloc = GST_XVIMAGE_ALLOCATOR (object);
314 
315   GST_DEBUG_OBJECT (object, "finalize");
316 
317   gst_xvcontext_unref (alloc->context);
318 
319   G_OBJECT_CLASS (parent_class)->finalize (object);
320 }
321 
322 GstXvImageAllocator *
gst_xvimage_allocator_new(GstXvContext * context)323 gst_xvimage_allocator_new (GstXvContext * context)
324 {
325   GstXvImageAllocator *alloc;
326 
327   g_return_val_if_fail (GST_IS_XVCONTEXT (context), NULL);
328 
329   alloc = g_object_new (GST_TYPE_XVIMAGE_ALLOCATOR, NULL);
330   alloc->context = gst_xvcontext_ref (context);
331   gst_object_ref_sink (alloc);
332 
333   return alloc;
334 }
335 
336 GstXvContext *
gst_xvimage_allocator_peek_context(GstXvImageAllocator * allocator)337 gst_xvimage_allocator_peek_context (GstXvImageAllocator * allocator)
338 {
339   g_return_val_if_fail (GST_IS_XVIMAGE_ALLOCATOR (allocator), NULL);
340 
341   return allocator->context;
342 }
343 
344 GstMemory *
gst_xvimage_allocator_alloc(GstXvImageAllocator * allocator,gint im_format,const GstVideoInfo * info,gint padded_width,gint padded_height,const GstVideoRectangle * crop,GError ** error)345 gst_xvimage_allocator_alloc (GstXvImageAllocator * allocator, gint im_format,
346     const GstVideoInfo * info, gint padded_width, gint padded_height,
347     const GstVideoRectangle * crop, GError ** error)
348 {
349   int (*handler) (Display *, XErrorEvent *);
350   gboolean success = FALSE;
351   GstXvContext *context;
352   gint align, offset;
353   GstXvImageMemory *mem;
354 #ifdef HAVE_XSHM
355   gint expected_size = 0;
356 #endif
357 
358   context = allocator->context;
359 
360   mem = g_slice_new (GstXvImageMemory);
361 
362   mem->im_format = im_format;
363   mem->info = *info;
364 #ifdef HAVE_XSHM
365   mem->SHMInfo.shmaddr = ((void *) -1);
366   mem->SHMInfo.shmid = -1;
367 #endif
368   mem->crop = *crop;
369 
370   GST_DEBUG_OBJECT (allocator, "creating image %p (%dx%d) cropped %dx%d-%dx%d",
371       mem, padded_width, padded_height, crop->x, crop->y, crop->w, crop->h);
372 
373   g_mutex_lock (&context->lock);
374 
375   /* Setting an error handler to catch failure */
376   error_caught = FALSE;
377   handler = XSetErrorHandler (gst_xvimage_handle_xerror);
378 
379 #ifdef HAVE_XSHM
380   if (context->use_xshm) {
381 
382     mem->xvimage = XvShmCreateImage (context->disp,
383         context->xv_port_id, im_format, NULL, padded_width, padded_height,
384         &mem->SHMInfo);
385     if (!mem->xvimage || error_caught) {
386       g_mutex_unlock (&context->lock);
387 
388       /* Reset error flag */
389       error_caught = FALSE;
390 
391       /* Push a warning */
392       GST_WARNING_OBJECT (allocator,
393           "could not XShmCreateImage a %dx%d image", padded_width,
394           padded_height);
395 
396       /* Retry without XShm */
397       context->use_xshm = FALSE;
398 
399       /* Hold X mutex again to try without XShm */
400       g_mutex_lock (&context->lock);
401       goto no_xshm;
402     }
403 
404     /* we have to use the returned data_size for our shm size */
405     GST_LOG_OBJECT (allocator, "XShm image size is %d",
406         mem->xvimage->data_size);
407 
408     /* calculate the expected size.  This is only for sanity checking the
409      * number we get from X. */
410     if (GST_VIDEO_FORMAT_INFO_IS_YUV (info->finfo)) {
411       switch (GST_VIDEO_FORMAT_INFO_FORMAT (info->finfo)) {
412         case GST_VIDEO_FORMAT_I420:
413         case GST_VIDEO_FORMAT_YV12:
414         {
415           gint pitches[3];
416           gint offsets[3];
417           guint plane;
418 
419           offsets[0] = 0;
420           pitches[0] = GST_ROUND_UP_4 (padded_width);
421           offsets[1] = offsets[0] + pitches[0] * GST_ROUND_UP_2 (padded_height);
422           pitches[1] = GST_ROUND_UP_8 (padded_width) / 2;
423           offsets[2] =
424               offsets[1] + pitches[1] * GST_ROUND_UP_2 (padded_height) / 2;
425           pitches[2] = GST_ROUND_UP_8 (pitches[0]) / 2;
426 
427           expected_size =
428               offsets[2] + pitches[2] * GST_ROUND_UP_2 (padded_height) / 2;
429 
430           for (plane = 0; plane < mem->xvimage->num_planes; plane++) {
431             GST_DEBUG_OBJECT (allocator,
432                 "Plane %u has a expected pitch of %d bytes, " "offset of %d",
433                 plane, pitches[plane], offsets[plane]);
434           }
435           break;
436         }
437         case GST_VIDEO_FORMAT_YUY2:
438         case GST_VIDEO_FORMAT_UYVY:
439           expected_size = padded_height * GST_ROUND_UP_4 (padded_width * 2);
440           break;
441         default:
442           break;
443       }
444     } else if (GST_VIDEO_FORMAT_INFO_IS_RGB (info->finfo) &&
445         GST_VIDEO_FORMAT_INFO_N_PLANES (info->finfo) == 1) {
446       expected_size = padded_height * GST_ROUND_UP_4 (padded_width *
447           GST_VIDEO_FORMAT_INFO_PSTRIDE (info->finfo, 0));
448     }
449     if (expected_size != 0 && mem->xvimage->data_size < expected_size)
450       goto unexpected_size;
451 
452     /* Be verbose about our XvImage stride */
453     {
454       guint plane;
455 
456       for (plane = 0; plane < mem->xvimage->num_planes; plane++) {
457         GST_DEBUG_OBJECT (allocator, "Plane %u has a pitch of %d bytes, "
458             "offset of %d", plane, mem->xvimage->pitches[plane],
459             mem->xvimage->offsets[plane]);
460       }
461     }
462 
463     /* get shared memory */
464     align = 0;
465     mem->SHMInfo.shmid =
466         shmget (IPC_PRIVATE, mem->xvimage->data_size, IPC_CREAT | 0777);
467     if (mem->SHMInfo.shmid == -1)
468       goto shmget_failed;
469 
470     /* attach */
471     mem->SHMInfo.shmaddr = shmat (mem->SHMInfo.shmid, NULL, 0);
472     if (mem->SHMInfo.shmaddr == ((void *) -1))
473       goto shmat_failed;
474 
475     /* now we can set up the image data */
476     mem->xvimage->data = mem->SHMInfo.shmaddr;
477     mem->SHMInfo.readOnly = FALSE;
478 
479     if (XShmAttach (context->disp, &mem->SHMInfo) == 0)
480       goto xattach_failed;
481 
482     XSync (context->disp, FALSE);
483 
484     /* Delete the shared memory segment as soon as we everyone is attached.
485      * This way, it will be deleted as soon as we detach later, and not
486      * leaked if we crash. */
487     shmctl (mem->SHMInfo.shmid, IPC_RMID, NULL);
488 
489     GST_DEBUG_OBJECT (allocator, "XServer ShmAttached to 0x%x, id 0x%lx",
490         mem->SHMInfo.shmid, mem->SHMInfo.shmseg);
491   } else
492   no_xshm:
493 #endif /* HAVE_XSHM */
494   {
495     mem->xvimage = XvCreateImage (context->disp,
496         context->xv_port_id, im_format, NULL, padded_width, padded_height);
497     if (!mem->xvimage || error_caught)
498       goto create_failed;
499 
500     /* we have to use the returned data_size for our image size */
501     align = 15;                 /* g_malloc aligns to 8, we need 16 */
502     mem->xvimage->data = g_malloc (mem->xvimage->data_size + align);
503 
504     XSync (context->disp, FALSE);
505   }
506 
507   if ((offset = ((guintptr) mem->xvimage->data & align)))
508     offset = (align + 1) - offset;
509 
510   GST_DEBUG_OBJECT (allocator, "memory %p, align %d, offset %d",
511       mem->xvimage->data, align, offset);
512 
513   /* Reset error handler */
514   error_caught = FALSE;
515   XSetErrorHandler (handler);
516 
517   gst_memory_init (GST_MEMORY_CAST (mem), 0,
518       GST_ALLOCATOR_CAST (allocator), NULL, mem->xvimage->data_size + align,
519       align, offset, mem->xvimage->data_size);
520 
521   g_mutex_unlock (&context->lock);
522 
523   success = TRUE;
524 
525 beach:
526   if (!success) {
527     g_slice_free (GstXvImageMemory, mem);
528     mem = NULL;
529   }
530 
531   return GST_MEMORY_CAST (mem);
532 
533   /* ERRORS */
534 create_failed:
535   {
536     g_mutex_unlock (&context->lock);
537     /* Reset error handler */
538     error_caught = FALSE;
539     XSetErrorHandler (handler);
540     /* Push an error */
541     g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_WRITE,
542         "could not XvShmCreateImage a %dx%d image", padded_width,
543         padded_height);
544     goto beach;
545   }
546 #ifdef HAVE_XSHM
547 unexpected_size:
548   {
549     g_mutex_unlock (&context->lock);
550     g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_WRITE,
551         "unexpected XShm image size (got %d, expected %d)",
552         mem->xvimage->data_size, expected_size);
553     goto beach;
554   }
555 shmget_failed:
556   {
557     g_mutex_unlock (&context->lock);
558     g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_WRITE,
559         "could not get shared memory of %d bytes", mem->xvimage->data_size);
560     goto beach;
561   }
562 shmat_failed:
563   {
564     g_mutex_unlock (&context->lock);
565     g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_WRITE,
566         "Failed to shmat: %s", g_strerror (errno));
567     /* Clean up the shared memory segment */
568     shmctl (mem->SHMInfo.shmid, IPC_RMID, NULL);
569     goto beach;
570   }
571 xattach_failed:
572   {
573     /* Clean up the shared memory segment */
574     shmctl (mem->SHMInfo.shmid, IPC_RMID, NULL);
575     g_mutex_unlock (&context->lock);
576 
577     g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_WRITE,
578         "Failed to XShmAttach");
579     goto beach;
580   }
581 #endif
582 }
583 
584 /* We are called with the x_lock taken */
585 static void
gst_xwindow_draw_borders(GstXWindow * window,GstVideoRectangle * rect)586 gst_xwindow_draw_borders (GstXWindow * window, GstVideoRectangle * rect)
587 {
588   gint t1, t2;
589   GstXvContext *context;
590 
591   g_return_if_fail (window != NULL);
592   g_return_if_fail (rect != NULL);
593 
594   context = window->context;
595 
596   XSetForeground (context->disp, window->gc, context->black);
597 
598   /* Left border */
599   if (rect->x > window->render_rect.x) {
600     XFillRectangle (context->disp, window->win, window->gc,
601         window->render_rect.x, window->render_rect.y,
602         rect->x - window->render_rect.x, window->render_rect.h);
603   }
604 
605   /* Right border */
606   t1 = rect->x + rect->w;
607   t2 = window->render_rect.x + window->render_rect.w;
608   if (t1 < t2) {
609     XFillRectangle (context->disp, window->win, window->gc,
610         t1, window->render_rect.y, t2 - t1, window->render_rect.h);
611   }
612 
613   /* Top border */
614   if (rect->y > window->render_rect.y) {
615     XFillRectangle (context->disp, window->win, window->gc,
616         window->render_rect.x, window->render_rect.y,
617         window->render_rect.w, rect->y - window->render_rect.y);
618   }
619 
620   /* Bottom border */
621   t1 = rect->y + rect->h;
622   t2 = window->render_rect.y + window->render_rect.h;
623   if (t1 < t2) {
624     XFillRectangle (context->disp, window->win, window->gc,
625         window->render_rect.x, t1, window->render_rect.w, t2 - t1);
626   }
627 }
628 
629 void
gst_xvimage_memory_render(GstXvImageMemory * mem,GstVideoRectangle * src_crop,GstXWindow * window,GstVideoRectangle * dst_crop,gboolean draw_border)630 gst_xvimage_memory_render (GstXvImageMemory * mem, GstVideoRectangle * src_crop,
631     GstXWindow * window, GstVideoRectangle * dst_crop, gboolean draw_border)
632 {
633   GstXvContext *context;
634   XvImage *xvimage;
635 
636   context = window->context;
637 
638   g_mutex_lock (&context->lock);
639   xvimage = gst_xvimage_memory_get_xvimage (mem);
640 
641   if (draw_border) {
642     gst_xwindow_draw_borders (window, dst_crop);
643   }
644 #ifdef HAVE_XSHM
645   if (context->use_xshm) {
646     GST_LOG ("XvShmPutImage with image %dx%d and window %dx%d, from xvimage %p",
647         src_crop->w, src_crop->h, window->render_rect.w, window->render_rect.h,
648         mem);
649 
650     XvShmPutImage (context->disp,
651         context->xv_port_id,
652         window->win,
653         window->gc, xvimage,
654         src_crop->x, src_crop->y, src_crop->w, src_crop->h,
655         dst_crop->x, dst_crop->y, dst_crop->w, dst_crop->h, FALSE);
656   } else
657 #endif /* HAVE_XSHM */
658   {
659     XvPutImage (context->disp,
660         context->xv_port_id,
661         window->win,
662         window->gc, xvimage,
663         src_crop->x, src_crop->y, src_crop->w, src_crop->h,
664         dst_crop->x, dst_crop->y, dst_crop->w, dst_crop->h);
665   }
666   XSync (context->disp, FALSE);
667 
668   g_mutex_unlock (&context->lock);
669 }
670