x11: use frame copy functions

This commit is contained in:
Wim Taymans 2011-06-22 15:38:24 +02:00
parent 1d9deae5be
commit aa73f69f2d
4 changed files with 59 additions and 11 deletions

View file

@ -116,6 +116,7 @@
#include <gst/gstinfo.h>
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 */

View file

@ -38,6 +38,9 @@
#include <string.h>
#include <math.h>
/* Helper functions */
#include <gst/video/video.h>
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;

View file

@ -119,7 +119,6 @@
#include <gst/interfaces/colorbalance.h>
#include <gst/interfaces/propertyprobe.h>
/* Helper functions */
#include <gst/video/video.h>
#include <gst/video/gstmetavideo.h>
/* 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 */

View file

@ -42,6 +42,9 @@
#include <math.h>
#include <stdlib.h>
/* Helper functions */
#include <gst/video/video.h>
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;