From aa73f69f2d464046f391de787dc4841f2bb9f50d Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 22 Jun 2011 15:38:24 +0200 Subject: [PATCH] x11: use frame copy functions --- sys/ximage/ximagesink.c | 32 +++++++++++++++++++++++++++----- sys/ximage/ximagesink.h | 5 +++++ sys/xvimage/xvimagesink.c | 28 ++++++++++++++++++++++------ sys/xvimage/xvimagesink.h | 5 +++++ 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/sys/ximage/ximagesink.c b/sys/ximage/ximagesink.c index d66ebcf..a4c47e4 100644 --- a/sys/ximage/ximagesink.c +++ b/sys/ximage/ximagesink.c @@ -116,6 +116,7 @@ #include GST_DEBUG_CATEGORY_EXTERN (gst_debug_ximagesink); +GST_DEBUG_CATEGORY_EXTERN (GST_CAT_PERFORMANCE); #define GST_CAT_DEFAULT gst_debug_ximagesink typedef struct @@ -1122,6 +1123,9 @@ gst_ximagesink_setcaps (GstBaseSink * bsink, GstCaps * caps) ximagesink->xwindow = gst_ximagesink_xwindow_new (ximagesink, GST_VIDEO_SINK_WIDTH (ximagesink), GST_VIDEO_SINK_HEIGHT (ximagesink)); } + + ximagesink->info = info; + /* Remember to draw borders for next frame */ ximagesink->draw_border = TRUE; @@ -1287,8 +1291,7 @@ gst_ximagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf) to_put = buf; res = GST_FLOW_OK; } else { - guint8 *data; - gsize size; + GstVideoFrame src, dest; /* Else we have to copy the data into our private image, */ /* if we have one... */ @@ -1309,9 +1312,21 @@ gst_ximagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf) if (gst_buffer_get_size (to_put) < gst_buffer_get_size (buf)) goto wrong_size; - data = gst_buffer_map (to_put, &size, NULL, GST_MAP_WRITE); - gst_buffer_extract (buf, 0, data, size); - gst_buffer_unmap (to_put, data, size); + GST_CAT_LOG_OBJECT (GST_CAT_PERFORMANCE, ximagesink, + "slow copy into bufferpool buffer %p", to_put); + + if (!gst_video_frame_map (&src, &ximagesink->info, buf, GST_MAP_READ)) + goto invalid_buffer; + + if (!gst_video_frame_map (&dest, &ximagesink->info, to_put, GST_MAP_WRITE)) { + gst_video_frame_unmap (&src); + goto invalid_buffer; + } + + gst_video_frame_copy (&dest, &src); + + gst_video_frame_unmap (&dest); + gst_video_frame_unmap (&src); } if (!gst_ximagesink_ximage_put (ximagesink, to_put)) @@ -1347,6 +1362,13 @@ wrong_size: res = GST_FLOW_ERROR; goto done; } +invalid_buffer: + { + /* No Window available to put our image into */ + GST_WARNING_OBJECT (ximagesink, "could map image"); + res = GST_FLOW_OK; + goto done; + } no_window: { /* No Window available to put our image into */ diff --git a/sys/ximage/ximagesink.h b/sys/ximage/ximagesink.h index 7974a3f..0cdd896 100644 --- a/sys/ximage/ximagesink.h +++ b/sys/ximage/ximagesink.h @@ -38,6 +38,9 @@ #include #include +/* Helper functions */ +#include + G_BEGIN_DECLS #define GST_TYPE_XIMAGESINK \ (gst_ximagesink_get_type()) @@ -171,6 +174,8 @@ struct _GstXImageSink GThread *event_thread; gboolean running; + GstVideoInfo info; + /* Framerate numerator and denominator */ gint fps_n; gint fps_d; diff --git a/sys/xvimage/xvimagesink.c b/sys/xvimage/xvimagesink.c index 9109e61..1106422 100644 --- a/sys/xvimage/xvimagesink.c +++ b/sys/xvimage/xvimagesink.c @@ -119,7 +119,6 @@ #include #include /* Helper functions */ -#include #include /* Object header */ @@ -1656,6 +1655,8 @@ gst_xvimagesink_setcaps (GstBaseSink * bsink, GstCaps * caps) GST_VIDEO_SINK_HEIGHT (xvimagesink)); } + xvimagesink->info = info; + /* After a resize, we want to redraw the borders in case the new frame size * doesn't cover the same area */ xvimagesink->redraw_border = TRUE; @@ -1828,8 +1829,7 @@ gst_xvimagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf) to_put = buf; res = GST_FLOW_OK; } else { - guint8 *data; - gsize size; + GstVideoFrame src, dest; /* Else we have to copy the data into our private image, */ /* if we have one... */ @@ -1853,9 +1853,18 @@ gst_xvimagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf) GST_CAT_LOG_OBJECT (GST_CAT_PERFORMANCE, xvimagesink, "slow copy into bufferpool buffer %p", to_put); - data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); - gst_buffer_fill (to_put, 0, data, size); - gst_buffer_unmap (buf, data, size); + if (!gst_video_frame_map (&src, &xvimagesink->info, buf, GST_MAP_READ)) + goto invalid_buffer; + + if (!gst_video_frame_map (&dest, &xvimagesink->info, to_put, GST_MAP_WRITE)) { + gst_video_frame_unmap (&src); + goto invalid_buffer; + } + + gst_video_frame_copy (&dest, &src); + + gst_video_frame_unmap (&dest); + gst_video_frame_unmap (&src); } if (!gst_xvimagesink_xvimage_put (xvimagesink, to_put)) @@ -1891,6 +1900,13 @@ wrong_size: res = GST_FLOW_ERROR; goto done; } +invalid_buffer: + { + /* No Window available to put our image into */ + GST_WARNING_OBJECT (xvimagesink, "could map image"); + res = GST_FLOW_OK; + goto done; + } no_window: { /* No Window available to put our image into */ diff --git a/sys/xvimage/xvimagesink.h b/sys/xvimage/xvimagesink.h index 4531cf3..1a21b01 100644 --- a/sys/xvimage/xvimagesink.h +++ b/sys/xvimage/xvimagesink.h @@ -42,6 +42,9 @@ #include #include +/* Helper functions */ +#include + G_BEGIN_DECLS #define GST_TYPE_XVIMAGESINK \ (gst_xvimagesink_get_type()) @@ -213,6 +216,8 @@ struct _GstXvImageSink GThread *event_thread; gboolean running; + GstVideoInfo info; + /* Framerate numerator and denominator */ gint fps_n; gint fps_d; -- 2.7.4