2005-02-11 22:01:19 +00:00
|
|
|
/* GStreamer
|
2007-09-19 13:06:17 +00:00
|
|
|
* Copyright (C) <2007> Thijs Vermeir <thijsvermeir@gmail.com>
|
2006-11-17 03:15:40 +00:00
|
|
|
* Copyright (C) <2006> Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>
|
2005-02-11 22:01:19 +00:00
|
|
|
* Copyright (C) <2004> David A. Schleef <ds@schleef.org>
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2005-02-11 22:01:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
#include "gstrfbsrc.h"
|
|
|
|
|
2005-02-11 22:01:19 +00:00
|
|
|
#include <gst/video/video.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2008-11-06 22:54:39 +00:00
|
|
|
#ifdef HAVE_X11
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#endif
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2006-04-25 21:56:38 +00:00
|
|
|
enum
|
|
|
|
{
|
2015-04-27 09:55:13 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_HOST,
|
|
|
|
PROP_PORT,
|
|
|
|
PROP_VERSION,
|
|
|
|
PROP_PASSWORD,
|
|
|
|
PROP_OFFSET_X,
|
|
|
|
PROP_OFFSET_Y,
|
|
|
|
PROP_WIDTH,
|
|
|
|
PROP_HEIGHT,
|
|
|
|
PROP_INCREMENTAL,
|
|
|
|
PROP_USE_COPYRECT,
|
|
|
|
PROP_SHARED,
|
|
|
|
PROP_VIEWONLY
|
2006-04-25 21:56:38 +00:00
|
|
|
};
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rfbsrc_debug);
|
2008-11-05 22:25:25 +00:00
|
|
|
GST_DEBUG_CATEGORY (rfbdecoder_debug);
|
2006-11-17 03:15:40 +00:00
|
|
|
#define GST_CAT_DEFAULT rfbsrc_debug
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
static GstStaticPadTemplate gst_rfb_src_template =
|
2013-05-09 23:41:32 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2005-02-11 22:01:19 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2013-05-09 23:41:32 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("RGB")
|
|
|
|
"; " GST_VIDEO_CAPS_MAKE ("BGR")
|
|
|
|
"; " GST_VIDEO_CAPS_MAKE ("RGBx")
|
|
|
|
"; " GST_VIDEO_CAPS_MAKE ("BGRx")
|
|
|
|
"; " GST_VIDEO_CAPS_MAKE ("xRGB")
|
|
|
|
"; " GST_VIDEO_CAPS_MAKE ("xBGR")));
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2012-05-07 22:57:08 +00:00
|
|
|
static void gst_rfb_src_finalize (GObject * object);
|
2006-11-17 03:15:40 +00:00
|
|
|
static void gst_rfb_src_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rfb_src_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2016-04-05 19:31:49 +00:00
|
|
|
static gboolean gst_rfb_src_negotiate (GstBaseSrc * bsrc);
|
2006-11-17 03:15:40 +00:00
|
|
|
static gboolean gst_rfb_src_stop (GstBaseSrc * bsrc);
|
|
|
|
static gboolean gst_rfb_src_event (GstBaseSrc * bsrc, GstEvent * event);
|
2016-03-26 17:36:34 +00:00
|
|
|
static gboolean gst_rfb_src_unlock (GstBaseSrc * bsrc);
|
2016-04-06 01:07:32 +00:00
|
|
|
static gboolean gst_rfb_src_decide_allocation (GstBaseSrc * bsrc,
|
|
|
|
GstQuery * query);
|
|
|
|
static GstFlowReturn gst_rfb_src_fill (GstPushSrc * psrc, GstBuffer * outbuf);
|
2006-11-17 03:15:40 +00:00
|
|
|
|
2013-05-09 23:41:32 +00:00
|
|
|
#define gst_rfb_src_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstRfbSrc, gst_rfb_src, GST_TYPE_PUSH_SRC);
|
2005-02-11 22:01:19 +00:00
|
|
|
|
|
|
|
static void
|
2006-11-17 03:15:40 +00:00
|
|
|
gst_rfb_src_class_init (GstRfbSrcClass * klass)
|
2005-02-11 22:01:19 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2006-11-17 03:15:40 +00:00
|
|
|
GstBaseSrcClass *gstbasesrc_class;
|
2013-05-09 23:41:32 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2006-11-17 03:15:40 +00:00
|
|
|
GstPushSrcClass *gstpushsrc_class;
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2013-05-09 23:41:32 +00:00
|
|
|
|
2008-11-05 22:25:25 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (rfbsrc_debug, "rfbsrc", 0, "rfb src element");
|
|
|
|
GST_DEBUG_CATEGORY_INIT (rfbdecoder_debug, "rfbdecoder", 0, "rfb decoder");
|
|
|
|
|
2005-02-11 22:01:19 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
2006-11-17 03:15:40 +00:00
|
|
|
gstbasesrc_class = (GstBaseSrcClass *) klass;
|
|
|
|
gstpushsrc_class = (GstPushSrcClass *) klass;
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2012-05-07 22:57:08 +00:00
|
|
|
gobject_class->finalize = gst_rfb_src_finalize;
|
2006-11-17 03:15:40 +00:00
|
|
|
gobject_class->set_property = gst_rfb_src_set_property;
|
|
|
|
gobject_class->get_property = gst_rfb_src_get_property;
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_HOST,
|
2006-11-17 03:15:40 +00:00
|
|
|
g_param_spec_string ("host", "Host to connect to", "Host to connect to",
|
2010-10-19 10:43:14 +00:00
|
|
|
"127.0.0.1", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PORT,
|
2005-02-11 22:01:19 +00:00
|
|
|
g_param_spec_int ("port", "Port", "Port",
|
2010-10-19 10:43:14 +00:00
|
|
|
1, 65535, 5900, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_VERSION,
|
2007-09-17 21:12:17 +00:00
|
|
|
g_param_spec_string ("version", "RFB protocol version",
|
2010-10-19 10:43:14 +00:00
|
|
|
"RFB protocol version", "3.3",
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PASSWORD,
|
2007-09-19 13:06:17 +00:00
|
|
|
g_param_spec_string ("password", "Password for authentication",
|
2010-10-19 10:43:14 +00:00
|
|
|
"Password for authentication", "",
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_OFFSET_X,
|
2007-09-21 14:55:19 +00:00
|
|
|
g_param_spec_int ("offset-x", "x offset for screen scrapping",
|
2010-10-19 10:43:14 +00:00
|
|
|
"x offset for screen scrapping", 0, 65535, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_OFFSET_Y,
|
2007-09-21 14:55:19 +00:00
|
|
|
g_param_spec_int ("offset-y", "y offset for screen scrapping",
|
2010-10-19 10:43:14 +00:00
|
|
|
"y offset for screen scrapping", 0, 65535, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_WIDTH,
|
2007-09-21 14:55:19 +00:00
|
|
|
g_param_spec_int ("width", "width of screen", "width of screen", 0, 65535,
|
2010-10-19 10:43:14 +00:00
|
|
|
0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_HEIGHT,
|
2007-09-21 14:55:19 +00:00
|
|
|
g_param_spec_int ("height", "height of screen", "height of screen", 0,
|
2010-10-19 10:43:14 +00:00
|
|
|
65535, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_INCREMENTAL,
|
2007-09-27 14:52:58 +00:00
|
|
|
g_param_spec_boolean ("incremental", "Incremental updates",
|
2010-10-19 10:43:14 +00:00
|
|
|
"Incremental updates", TRUE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_USE_COPYRECT,
|
2007-11-29 13:32:11 +00:00
|
|
|
g_param_spec_boolean ("use-copyrect", "Use copyrect encoding",
|
2010-10-19 10:43:14 +00:00
|
|
|
"Use copyrect encoding", FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SHARED,
|
2008-07-08 14:28:08 +00:00
|
|
|
g_param_spec_boolean ("shared", "Share desktop with other clients",
|
2010-10-19 10:43:14 +00:00
|
|
|
"Share desktop with other clients", TRUE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-04-27 09:55:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_VIEWONLY,
|
2008-07-08 21:20:27 +00:00
|
|
|
g_param_spec_boolean ("view-only", "Only view the desktop",
|
2010-10-19 10:43:14 +00:00
|
|
|
"only view the desktop", FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2016-04-05 19:31:49 +00:00
|
|
|
|
|
|
|
gstbasesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_rfb_src_negotiate);
|
2006-11-17 03:15:40 +00:00
|
|
|
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_rfb_src_stop);
|
|
|
|
gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_rfb_src_event);
|
2016-03-26 17:36:34 +00:00
|
|
|
gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_rfb_src_unlock);
|
2016-04-06 01:07:32 +00:00
|
|
|
gstpushsrc_class->fill = GST_DEBUG_FUNCPTR (gst_rfb_src_fill);
|
|
|
|
gstbasesrc_class->decide_allocation =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rfb_src_decide_allocation);
|
2013-05-09 23:41:32 +00:00
|
|
|
|
|
|
|
gstelement_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_rfb_src_template);
|
2013-05-09 23:41:32 +00:00
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (gstelement_class, "Rfb source",
|
|
|
|
"Source/Video",
|
|
|
|
"Creates a rfb video stream",
|
|
|
|
"David A. Schleef <ds@schleef.org>, "
|
|
|
|
"Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>, "
|
|
|
|
"Thijs Vermeir <thijsvermeir@gmail.com>");
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
static void
|
2013-05-09 23:41:32 +00:00
|
|
|
gst_rfb_src_init (GstRfbSrc * src)
|
2005-02-11 22:01:19 +00:00
|
|
|
{
|
2006-11-17 03:15:40 +00:00
|
|
|
GstBaseSrc *bsrc = GST_BASE_SRC (src);
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
gst_pad_use_fixed_caps (GST_BASE_SRC_PAD (bsrc));
|
|
|
|
gst_base_src_set_live (bsrc, TRUE);
|
|
|
|
gst_base_src_set_format (bsrc, GST_FORMAT_TIME);
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
src->host = g_strdup ("127.0.0.1");
|
|
|
|
src->port = 5900;
|
2007-09-17 21:12:17 +00:00
|
|
|
src->version_major = 3;
|
|
|
|
src->version_minor = 3;
|
2007-09-19 13:06:17 +00:00
|
|
|
|
2007-09-27 14:52:58 +00:00
|
|
|
src->incremental_update = TRUE;
|
|
|
|
|
2008-07-08 21:20:27 +00:00
|
|
|
src->view_only = FALSE;
|
|
|
|
|
2007-09-19 13:06:17 +00:00
|
|
|
src->decoder = rfb_decoder_new ();
|
2006-11-17 03:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-07 22:57:08 +00:00
|
|
|
gst_rfb_src_finalize (GObject * object)
|
2006-11-17 03:15:40 +00:00
|
|
|
{
|
|
|
|
GstRfbSrc *src = GST_RFB_SRC (object);
|
|
|
|
|
|
|
|
g_free (src->host);
|
2016-04-06 01:07:32 +00:00
|
|
|
|
2008-02-12 05:19:05 +00:00
|
|
|
if (src->decoder) {
|
|
|
|
rfb_decoder_free (src->decoder);
|
|
|
|
src->decoder = NULL;
|
|
|
|
}
|
2006-11-17 03:15:40 +00:00
|
|
|
|
2012-05-07 22:57:08 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2006-11-17 03:15:40 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 21:12:17 +00:00
|
|
|
static void
|
|
|
|
gst_rfb_property_set_version (GstRfbSrc * src, gchar * value)
|
|
|
|
{
|
2008-02-22 05:33:59 +00:00
|
|
|
gchar *major;
|
|
|
|
gchar *minor;
|
|
|
|
|
2007-09-17 21:12:17 +00:00
|
|
|
g_return_if_fail (src != NULL);
|
|
|
|
g_return_if_fail (value != NULL);
|
|
|
|
|
2008-02-22 05:33:59 +00:00
|
|
|
major = g_strdup (value);
|
|
|
|
minor = g_strrstr (value, ".");
|
2007-09-17 21:12:17 +00:00
|
|
|
|
|
|
|
g_return_if_fail (minor != NULL);
|
|
|
|
|
|
|
|
*minor++ = 0;
|
|
|
|
|
|
|
|
g_return_if_fail (g_ascii_isdigit (*major) == TRUE);
|
|
|
|
g_return_if_fail (g_ascii_isdigit (*minor) == TRUE);
|
|
|
|
|
|
|
|
src->version_major = g_ascii_digit_value (*major);
|
|
|
|
src->version_minor = g_ascii_digit_value (*minor);
|
|
|
|
|
|
|
|
GST_DEBUG ("Version major : %d", src->version_major);
|
|
|
|
GST_DEBUG ("Version minor : %d", src->version_minor);
|
|
|
|
|
|
|
|
g_free (major);
|
|
|
|
g_free (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
gst_rfb_property_get_version (GstRfbSrc * src)
|
|
|
|
{
|
2008-11-05 22:25:25 +00:00
|
|
|
return g_strdup_printf ("%d.%d", src->version_major, src->version_minor);
|
2007-09-17 21:12:17 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
static void
|
|
|
|
gst_rfb_src_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRfbSrc *src = GST_RFB_SRC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_HOST:
|
2019-12-18 14:37:03 +00:00
|
|
|
src->host = g_value_dup_string (value);;
|
2005-02-11 22:01:19 +00:00
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_PORT:
|
2006-11-17 03:15:40 +00:00
|
|
|
src->port = g_value_get_int (value);
|
2005-02-11 22:01:19 +00:00
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_VERSION:
|
2019-12-18 14:37:03 +00:00
|
|
|
gst_rfb_property_set_version (src, g_value_dup_string (value));
|
2007-09-17 21:12:17 +00:00
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_PASSWORD:
|
2007-09-19 13:06:17 +00:00
|
|
|
g_free (src->decoder->password);
|
2019-12-18 14:37:03 +00:00
|
|
|
src->decoder->password = g_value_dup_string (value);
|
2007-09-19 13:06:17 +00:00
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_OFFSET_X:
|
2007-09-21 14:55:19 +00:00
|
|
|
src->decoder->offset_x = g_value_get_int (value);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_OFFSET_Y:
|
2007-09-21 14:55:19 +00:00
|
|
|
src->decoder->offset_y = g_value_get_int (value);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_WIDTH:
|
2007-09-21 14:55:19 +00:00
|
|
|
src->decoder->rect_width = g_value_get_int (value);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_HEIGHT:
|
2007-09-21 14:55:19 +00:00
|
|
|
src->decoder->rect_height = g_value_get_int (value);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_INCREMENTAL:
|
2007-09-27 14:52:58 +00:00
|
|
|
src->incremental_update = g_value_get_boolean (value);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_USE_COPYRECT:
|
2007-11-29 13:32:11 +00:00
|
|
|
src->decoder->use_copyrect = g_value_get_boolean (value);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_SHARED:
|
2008-07-08 14:28:08 +00:00
|
|
|
src->decoder->shared_flag = g_value_get_boolean (value);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_VIEWONLY:
|
2008-07-08 21:20:27 +00:00
|
|
|
src->view_only = g_value_get_boolean (value);
|
|
|
|
break;
|
2006-11-17 03:15:40 +00:00
|
|
|
default:
|
2005-02-11 22:01:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-17 03:15:40 +00:00
|
|
|
gst_rfb_src_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2005-02-11 22:01:19 +00:00
|
|
|
{
|
2006-11-17 03:15:40 +00:00
|
|
|
GstRfbSrc *src = GST_RFB_SRC (object);
|
2007-09-17 21:12:17 +00:00
|
|
|
gchar *version;
|
2006-11-17 03:15:40 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_HOST:
|
2006-11-17 03:15:40 +00:00
|
|
|
g_value_set_string (value, src->host);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_PORT:
|
2006-11-17 03:15:40 +00:00
|
|
|
g_value_set_int (value, src->port);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_VERSION:
|
2007-09-17 21:12:17 +00:00
|
|
|
version = gst_rfb_property_get_version (src);
|
|
|
|
g_value_set_string (value, version);
|
|
|
|
g_free (version);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_OFFSET_X:
|
2007-09-21 14:55:19 +00:00
|
|
|
g_value_set_int (value, src->decoder->offset_x);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_OFFSET_Y:
|
2007-09-21 14:55:19 +00:00
|
|
|
g_value_set_int (value, src->decoder->offset_y);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_WIDTH:
|
2007-09-21 14:55:19 +00:00
|
|
|
g_value_set_int (value, src->decoder->rect_width);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_HEIGHT:
|
2007-09-21 14:55:19 +00:00
|
|
|
g_value_set_int (value, src->decoder->rect_height);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_INCREMENTAL:
|
2007-09-27 14:52:58 +00:00
|
|
|
g_value_set_boolean (value, src->incremental_update);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_USE_COPYRECT:
|
2007-11-29 13:32:11 +00:00
|
|
|
g_value_set_boolean (value, src->decoder->use_copyrect);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_SHARED:
|
2008-07-08 14:28:08 +00:00
|
|
|
g_value_set_boolean (value, src->decoder->shared_flag);
|
|
|
|
break;
|
2015-04-27 09:55:13 +00:00
|
|
|
case PROP_VIEWONLY:
|
2008-07-08 21:20:27 +00:00
|
|
|
g_value_set_boolean (value, src->view_only);
|
|
|
|
break;
|
2006-11-17 03:15:40 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 01:07:32 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rfb_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
|
2013-05-09 23:41:32 +00:00
|
|
|
{
|
|
|
|
GstBufferPool *pool = NULL;
|
2016-04-06 01:07:32 +00:00
|
|
|
guint size, min = 1, max = 0;
|
2013-05-09 23:41:32 +00:00
|
|
|
GstStructure *config;
|
2016-04-06 01:07:32 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
GstVideoInfo info;
|
|
|
|
gboolean ret;
|
2013-05-09 23:41:32 +00:00
|
|
|
|
2016-04-06 01:07:32 +00:00
|
|
|
gst_query_parse_allocation (query, &caps, NULL);
|
2013-05-09 23:41:32 +00:00
|
|
|
|
2016-04-06 01:07:32 +00:00
|
|
|
if (!caps || !gst_video_info_from_caps (&info, caps))
|
|
|
|
return FALSE;
|
2013-05-09 23:41:32 +00:00
|
|
|
|
2016-04-06 01:40:58 +00:00
|
|
|
while (gst_query_get_n_allocation_pools (query) > 0) {
|
2013-05-09 23:41:32 +00:00
|
|
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
2016-04-06 01:07:32 +00:00
|
|
|
|
|
|
|
/* TODO We restrict to the exact size as we don't support strides or
|
|
|
|
* special padding */
|
|
|
|
if (size == info.size)
|
|
|
|
break;
|
|
|
|
|
2016-04-06 01:40:58 +00:00
|
|
|
gst_query_remove_nth_allocation_pool (query, 0);
|
2016-04-06 01:07:32 +00:00
|
|
|
gst_object_unref (pool);
|
|
|
|
pool = NULL;
|
2013-05-09 23:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pool == NULL) {
|
|
|
|
/* we did not get a pool, make one ourselves then */
|
|
|
|
pool = gst_video_buffer_pool_new ();
|
2016-04-06 01:07:32 +00:00
|
|
|
size = info.size;
|
2016-04-06 01:40:58 +00:00
|
|
|
min = 1;
|
|
|
|
max = 0;
|
2018-04-25 19:05:38 +00:00
|
|
|
|
|
|
|
if (gst_query_get_n_allocation_pools (query) > 0)
|
|
|
|
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
|
|
|
|
else
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, min, max);
|
2013-05-09 23:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, min, max);
|
|
|
|
|
2016-04-06 01:07:32 +00:00
|
|
|
ret = gst_buffer_pool_set_config (pool, config);
|
|
|
|
gst_object_unref (pool);
|
2013-05-09 23:41:32 +00:00
|
|
|
|
2016-04-06 01:07:32 +00:00
|
|
|
return ret;
|
2013-05-09 23:41:32 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
static gboolean
|
2016-04-05 19:31:49 +00:00
|
|
|
gst_rfb_src_negotiate (GstBaseSrc * bsrc)
|
2005-02-11 22:01:19 +00:00
|
|
|
{
|
2006-11-17 03:15:40 +00:00
|
|
|
GstRfbSrc *src = GST_RFB_SRC (bsrc);
|
|
|
|
RfbDecoder *decoder;
|
2005-02-11 22:01:19 +00:00
|
|
|
GstCaps *caps;
|
2013-05-09 23:41:32 +00:00
|
|
|
GstVideoInfo vinfo;
|
|
|
|
GstVideoFormat vformat;
|
2008-11-05 23:31:41 +00:00
|
|
|
guint32 red_mask, green_mask, blue_mask;
|
2014-05-02 12:20:58 +00:00
|
|
|
gchar *stream_id = NULL;
|
|
|
|
GstEvent *stream_start = NULL;
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2007-09-19 13:06:17 +00:00
|
|
|
decoder = src->decoder;
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2016-04-05 19:31:49 +00:00
|
|
|
if (decoder->inited)
|
|
|
|
return TRUE;
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "connecting to host %s on port %d",
|
|
|
|
src->host, src->port);
|
|
|
|
if (!rfb_decoder_connect_tcp (decoder, src->host, src->port)) {
|
2013-05-11 18:41:22 +00:00
|
|
|
if (decoder->error != NULL) {
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ,
|
|
|
|
("Could not connect to VNC server %s on port %d: %s", src->host,
|
|
|
|
src->port, decoder->error->message), (NULL));
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ,
|
|
|
|
("Could not connect to VNC server %s on port %d", src->host,
|
|
|
|
src->port), (NULL));
|
|
|
|
}
|
2006-11-17 03:15:40 +00:00
|
|
|
return FALSE;
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
while (!decoder->inited) {
|
2013-05-11 18:41:22 +00:00
|
|
|
if (!rfb_decoder_iterate (decoder)) {
|
|
|
|
if (decoder->error != NULL) {
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ,
|
|
|
|
("Failed to setup VNC connection to host %s on port %d: %s",
|
|
|
|
src->host, src->port, decoder->error->message), (NULL));
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ,
|
|
|
|
("Failed to setup VNC connection to host %s on port %d", src->host,
|
|
|
|
src->port), (NULL));
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-11-17 03:15:40 +00:00
|
|
|
}
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2014-05-02 12:20:58 +00:00
|
|
|
stream_id = gst_pad_create_stream_id_printf (GST_BASE_SRC_PAD (bsrc),
|
|
|
|
GST_ELEMENT (src), "%s:%d", src->host, src->port);
|
|
|
|
stream_start = gst_event_new_stream_start (stream_id);
|
|
|
|
g_free (stream_id);
|
|
|
|
gst_pad_push_event (GST_BASE_SRC_PAD (bsrc), stream_start);
|
|
|
|
|
2007-10-31 14:09:25 +00:00
|
|
|
decoder->rect_width =
|
|
|
|
(decoder->rect_width ? decoder->rect_width : decoder->width);
|
|
|
|
decoder->rect_height =
|
|
|
|
(decoder->rect_height ? decoder->rect_height : decoder->height);
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
decoder->decoder_private = src;
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2007-11-15 15:32:47 +00:00
|
|
|
/* calculate some many used values */
|
|
|
|
decoder->bytespp = decoder->bpp / 8;
|
|
|
|
decoder->line_size = decoder->rect_width * decoder->bytespp;
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "setting caps width to %d and height to %d",
|
2007-11-15 15:32:47 +00:00
|
|
|
decoder->rect_width, decoder->rect_height);
|
2006-11-17 03:15:40 +00:00
|
|
|
|
2008-11-05 23:31:41 +00:00
|
|
|
red_mask = decoder->red_max << decoder->red_shift;
|
|
|
|
green_mask = decoder->green_max << decoder->green_shift;
|
|
|
|
blue_mask = decoder->blue_max << decoder->blue_shift;
|
|
|
|
|
2013-05-09 23:41:32 +00:00
|
|
|
vformat = gst_video_format_from_masks (decoder->depth, decoder->bpp,
|
|
|
|
decoder->big_endian ? G_BIG_ENDIAN : G_LITTLE_ENDIAN,
|
|
|
|
red_mask, green_mask, blue_mask, 0);
|
|
|
|
|
|
|
|
gst_video_info_init (&vinfo);
|
|
|
|
|
|
|
|
gst_video_info_set_format (&vinfo, vformat, decoder->rect_width,
|
|
|
|
decoder->rect_height);
|
|
|
|
|
2016-04-06 01:07:32 +00:00
|
|
|
decoder->frame = g_malloc (vinfo.size);
|
|
|
|
if (decoder->use_copyrect)
|
|
|
|
decoder->prev_frame = g_malloc (vinfo.size);
|
|
|
|
|
2013-05-09 23:41:32 +00:00
|
|
|
caps = gst_video_info_to_caps (&vinfo);
|
2008-11-05 23:31:41 +00:00
|
|
|
|
2016-04-05 19:31:49 +00:00
|
|
|
gst_base_src_set_caps (bsrc, caps);
|
2013-05-09 23:41:32 +00:00
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
gst_caps_unref (caps);
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
return TRUE;
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rfb_src_stop (GstBaseSrc * bsrc)
|
2005-02-11 22:01:19 +00:00
|
|
|
{
|
2006-11-17 03:15:40 +00:00
|
|
|
GstRfbSrc *src = GST_RFB_SRC (bsrc);
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2016-03-24 22:14:17 +00:00
|
|
|
rfb_decoder_disconnect (src->decoder);
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2007-10-31 14:09:25 +00:00
|
|
|
if (src->decoder->frame) {
|
|
|
|
g_free (src->decoder->frame);
|
|
|
|
src->decoder->frame = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->decoder->prev_frame) {
|
|
|
|
g_free (src->decoder->prev_frame);
|
|
|
|
src->decoder->prev_frame = NULL;
|
2006-11-17 03:15:40 +00:00
|
|
|
}
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
return TRUE;
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
static GstFlowReturn
|
2016-04-06 01:07:32 +00:00
|
|
|
gst_rfb_src_fill (GstPushSrc * psrc, GstBuffer * outbuf)
|
2005-02-11 22:01:19 +00:00
|
|
|
{
|
2006-11-17 03:15:40 +00:00
|
|
|
GstRfbSrc *src = GST_RFB_SRC (psrc);
|
|
|
|
RfbDecoder *decoder = src->decoder;
|
2013-05-09 23:41:32 +00:00
|
|
|
GstMapInfo info;
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2007-09-27 14:52:58 +00:00
|
|
|
rfb_decoder_send_update_request (decoder, src->incremental_update,
|
2007-10-31 14:09:25 +00:00
|
|
|
decoder->offset_x, decoder->offset_y, decoder->rect_width,
|
|
|
|
decoder->rect_height);
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2007-10-31 14:09:25 +00:00
|
|
|
while (decoder->state != NULL) {
|
2013-05-11 18:41:22 +00:00
|
|
|
if (!rfb_decoder_iterate (decoder)) {
|
|
|
|
if (decoder->error != NULL) {
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ,
|
|
|
|
("Error on VNC connection to host %s on port %d: %s",
|
|
|
|
src->host, src->port, decoder->error->message), (NULL));
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ,
|
|
|
|
("Error on setup VNC connection to host %s on port %d", src->host,
|
|
|
|
src->port), (NULL));
|
|
|
|
}
|
2016-03-24 22:14:37 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2013-05-11 18:41:22 +00:00
|
|
|
}
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 01:07:32 +00:00
|
|
|
if (!gst_buffer_map (outbuf, &info, GST_MAP_WRITE)) {
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, WRITE,
|
|
|
|
("Could not map the output frame"), (NULL));
|
2006-11-17 03:15:40 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2013-05-09 23:41:32 +00:00
|
|
|
memcpy (info.data, decoder->frame, info.size);
|
|
|
|
|
2016-04-06 01:07:32 +00:00
|
|
|
GST_BUFFER_PTS (outbuf) =
|
2007-11-15 08:28:29 +00:00
|
|
|
gst_clock_get_time (GST_ELEMENT_CLOCK (src)) -
|
|
|
|
GST_ELEMENT_CAST (src)->base_time;
|
2006-11-17 03:15:40 +00:00
|
|
|
|
2016-04-06 01:07:32 +00:00
|
|
|
gst_buffer_unmap (outbuf, &info);
|
2013-05-09 23:41:32 +00:00
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
return GST_FLOW_OK;
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2006-11-17 03:15:40 +00:00
|
|
|
gst_rfb_src_event (GstBaseSrc * bsrc, GstEvent * event)
|
2005-02-11 22:01:19 +00:00
|
|
|
{
|
2006-11-17 03:15:40 +00:00
|
|
|
GstRfbSrc *src = GST_RFB_SRC (bsrc);
|
|
|
|
gdouble x, y;
|
|
|
|
gint button;
|
2013-05-09 23:41:32 +00:00
|
|
|
const GstStructure *structure;
|
2006-11-17 03:15:40 +00:00
|
|
|
const gchar *event_type;
|
2008-11-06 22:54:39 +00:00
|
|
|
gboolean key_event, key_press;
|
|
|
|
|
|
|
|
key_event = FALSE;
|
2005-02-11 22:01:19 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_NAVIGATION:
|
2008-07-08 21:20:27 +00:00
|
|
|
|
|
|
|
/* if in view_only mode ignore the navigation event */
|
|
|
|
if (src->view_only)
|
|
|
|
break;
|
|
|
|
|
2013-05-09 23:41:32 +00:00
|
|
|
structure = gst_event_get_structure (event);
|
2005-02-11 22:01:19 +00:00
|
|
|
event_type = gst_structure_get_string (structure, "event");
|
2008-11-06 22:54:39 +00:00
|
|
|
|
|
|
|
if (strcmp (event_type, "key-press") == 0) {
|
|
|
|
key_event = key_press = TRUE;
|
|
|
|
} else if (strcmp (event_type, "key-release") == 0) {
|
|
|
|
key_event = TRUE;
|
|
|
|
key_press = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key_event) {
|
|
|
|
#ifdef HAVE_X11
|
|
|
|
const gchar *key;
|
|
|
|
KeySym key_sym;
|
|
|
|
|
|
|
|
key = gst_structure_get_string (structure, "key");
|
|
|
|
key_sym = XStringToKeysym (key);
|
|
|
|
|
|
|
|
if (key_sym != NoSymbol)
|
|
|
|
rfb_decoder_send_key_event (src->decoder, key_sym, key_press);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-02-11 22:01:19 +00:00
|
|
|
gst_structure_get_double (structure, "pointer_x", &x);
|
|
|
|
gst_structure_get_double (structure, "pointer_y", &y);
|
2008-11-06 22:54:39 +00:00
|
|
|
gst_structure_get_int (structure, "button", &button);
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2007-11-15 15:32:47 +00:00
|
|
|
/* we need to take care of the offset's */
|
|
|
|
x += src->decoder->offset_x;
|
|
|
|
y += src->decoder->offset_y;
|
|
|
|
|
2008-11-06 22:54:39 +00:00
|
|
|
if (strcmp (event_type, "mouse-move") == 0) {
|
2006-11-17 03:15:40 +00:00
|
|
|
GST_LOG_OBJECT (src, "sending mouse-move event "
|
|
|
|
"button_mask=%d, x=%d, y=%d", src->button_mask, (gint) x, (gint) y);
|
|
|
|
rfb_decoder_send_pointer_event (src->decoder, src->button_mask,
|
|
|
|
(gint) x, (gint) y);
|
2005-02-11 22:01:19 +00:00
|
|
|
} else if (strcmp (event_type, "mouse-button-release") == 0) {
|
2008-11-06 22:54:39 +00:00
|
|
|
src->button_mask &= ~(1 << (button - 1));
|
2006-11-17 03:15:40 +00:00
|
|
|
GST_LOG_OBJECT (src, "sending mouse-button-release event "
|
|
|
|
"button_mask=%d, x=%d, y=%d", src->button_mask, (gint) x, (gint) y);
|
|
|
|
rfb_decoder_send_pointer_event (src->decoder, src->button_mask,
|
|
|
|
(gint) x, (gint) y);
|
2005-02-11 22:01:19 +00:00
|
|
|
} else if (strcmp (event_type, "mouse-button-press") == 0) {
|
2008-11-06 22:54:39 +00:00
|
|
|
src->button_mask |= (1 << (button - 1));
|
2006-11-17 03:15:40 +00:00
|
|
|
GST_LOG_OBJECT (src, "sending mouse-button-press event "
|
|
|
|
"button_mask=%d, x=%d, y=%d", src->button_mask, (gint) x, (gint) y);
|
|
|
|
rfb_decoder_send_pointer_event (src->decoder, src->button_mask,
|
|
|
|
(gint) x, (gint) y);
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-03-26 17:36:34 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rfb_src_unlock (GstBaseSrc * bsrc)
|
|
|
|
{
|
|
|
|
GstRfbSrc *src = GST_RFB_SRC (bsrc);
|
|
|
|
g_cancellable_cancel (src->decoder->cancellable);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-02-11 22:01:19 +00:00
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
return gst_element_register (plugin, "rfbsrc", GST_RANK_NONE,
|
2006-11-17 03:15:40 +00:00
|
|
|
GST_TYPE_RFB_SRC);
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 16:02:56 +00:00
|
|
|
rfbsrc,
|
2005-02-11 22:01:19 +00:00
|
|
|
"Connects to a VNC server and decodes RFB stream",
|
2006-04-01 10:09:11 +00:00
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|