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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
{
|
|
|
|
ARG_0,
|
2006-11-17 03:15:40 +00:00
|
|
|
ARG_HOST,
|
2006-04-25 21:56:38 +00:00
|
|
|
ARG_PORT,
|
2007-09-17 21:12:17 +00:00
|
|
|
ARG_VERSION,
|
2007-09-19 13:06:17 +00:00
|
|
|
ARG_PASSWORD,
|
2007-09-21 14:55:19 +00:00
|
|
|
ARG_OFFSET_X,
|
|
|
|
ARG_OFFSET_Y,
|
|
|
|
ARG_WIDTH,
|
|
|
|
ARG_HEIGHT,
|
2007-09-27 14:52:58 +00:00
|
|
|
ARG_INCREMENTAL,
|
2008-07-08 14:28:08 +00:00
|
|
|
ARG_USE_COPYRECT,
|
2008-07-08 21:20:27 +00:00
|
|
|
ARG_SHARED,
|
|
|
|
ARG_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 =
|
2006-04-25 21:56:38 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
2005-02-11 22:01:19 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-raw-rgb, "
|
2007-09-20 18:30:35 +00:00
|
|
|
"bpp = (int) [1, 255], "
|
|
|
|
"depth = (int) [1, 255], "
|
|
|
|
"endianness = (int) [1234, 4321], "
|
2008-11-05 23:31:41 +00:00
|
|
|
"red_mask = (int) [min, max], "
|
|
|
|
"green_mask = (int) [min, max], "
|
|
|
|
"blue_mask = (int) [min, max], "
|
2006-11-17 03:15:40 +00:00
|
|
|
"width = (int) [ 16, 4096 ], "
|
2007-09-21 10:27:02 +00:00
|
|
|
"height = (int) [ 16, 4096 ], " "framerate = (fraction) 0/1")
|
2005-02-11 22:01:19 +00:00
|
|
|
);
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
static void gst_rfb_src_dispose (GObject * object);
|
|
|
|
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);
|
|
|
|
|
|
|
|
static gboolean gst_rfb_src_start (GstBaseSrc * bsrc);
|
|
|
|
static gboolean gst_rfb_src_stop (GstBaseSrc * bsrc);
|
|
|
|
static gboolean gst_rfb_src_event (GstBaseSrc * bsrc, GstEvent * event);
|
|
|
|
static GstFlowReturn gst_rfb_src_create (GstPushSrc * psrc,
|
|
|
|
GstBuffer ** outbuf);
|
|
|
|
|
2008-11-05 22:25:25 +00:00
|
|
|
GST_BOILERPLATE (GstRfbSrc, gst_rfb_src, GstPushSrc, 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_base_init (gpointer g_class)
|
2005-02-11 22:01:19 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2006-11-17 03:15:40 +00:00
|
|
|
gst_static_pad_template_get (&gst_rfb_src_template));
|
|
|
|
|
2010-03-18 16:30:26 +00:00
|
|
|
gst_element_class_set_details_simple (element_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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
GstPushSrcClass *gstpushsrc_class;
|
2005-02-11 22:01:19 +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
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
gobject_class->dispose = gst_rfb_src_dispose;
|
|
|
|
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
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_HOST,
|
|
|
|
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));
|
2005-02-11 22:01:19 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_PORT,
|
|
|
|
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));
|
2007-09-17 21:12:17 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_VERSION,
|
|
|
|
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));
|
2007-09-19 13:06:17 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_PASSWORD,
|
|
|
|
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));
|
2007-09-21 14:55:19 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_OFFSET_X,
|
|
|
|
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));
|
2007-09-21 14:55:19 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_OFFSET_Y,
|
|
|
|
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));
|
2007-09-21 14:55:19 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_WIDTH,
|
|
|
|
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));
|
2007-09-21 14:55:19 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_HEIGHT,
|
|
|
|
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));
|
2007-09-27 14:52:58 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_INCREMENTAL,
|
|
|
|
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));
|
2007-11-29 13:32:11 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_USE_COPYRECT,
|
|
|
|
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));
|
2008-07-08 14:28:08 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_SHARED,
|
|
|
|
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));
|
2008-07-08 21:20:27 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_VIEWONLY,
|
|
|
|
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));
|
2006-11-17 03:15:40 +00:00
|
|
|
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_rfb_src_start);
|
|
|
|
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_rfb_src_stop);
|
|
|
|
gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_rfb_src_event);
|
|
|
|
gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_rfb_src_create);
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
static void
|
|
|
|
gst_rfb_src_init (GstRfbSrc * src, GstRfbSrcClass * klass)
|
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
|
|
|
|
gst_rfb_src_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GstRfbSrc *src = GST_RFB_SRC (object);
|
|
|
|
|
|
|
|
g_free (src->host);
|
2008-02-12 05:19:05 +00:00
|
|
|
if (src->decoder) {
|
|
|
|
rfb_decoder_free (src->decoder);
|
|
|
|
g_free (src->decoder);
|
|
|
|
src->decoder = NULL;
|
|
|
|
}
|
2006-11-17 03:15:40 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
case ARG_HOST:
|
|
|
|
src->host = g_strdup (g_value_get_string (value));
|
2005-02-11 22:01:19 +00:00
|
|
|
break;
|
2006-11-17 03:15:40 +00:00
|
|
|
case ARG_PORT:
|
|
|
|
src->port = g_value_get_int (value);
|
2005-02-11 22:01:19 +00:00
|
|
|
break;
|
2007-09-17 21:12:17 +00:00
|
|
|
case ARG_VERSION:
|
|
|
|
gst_rfb_property_set_version (src, g_strdup (g_value_get_string (value)));
|
|
|
|
break;
|
2007-09-19 13:06:17 +00:00
|
|
|
case ARG_PASSWORD:
|
|
|
|
g_free (src->decoder->password);
|
|
|
|
src->decoder->password = g_strdup (g_value_get_string (value));
|
|
|
|
break;
|
2007-09-21 14:55:19 +00:00
|
|
|
case ARG_OFFSET_X:
|
|
|
|
src->decoder->offset_x = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case ARG_OFFSET_Y:
|
|
|
|
src->decoder->offset_y = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case ARG_WIDTH:
|
|
|
|
src->decoder->rect_width = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case ARG_HEIGHT:
|
|
|
|
src->decoder->rect_height = g_value_get_int (value);
|
|
|
|
break;
|
2007-09-27 14:52:58 +00:00
|
|
|
case ARG_INCREMENTAL:
|
|
|
|
src->incremental_update = g_value_get_boolean (value);
|
|
|
|
break;
|
2007-11-29 13:32:11 +00:00
|
|
|
case ARG_USE_COPYRECT:
|
|
|
|
src->decoder->use_copyrect = g_value_get_boolean (value);
|
|
|
|
break;
|
2008-07-08 14:28:08 +00:00
|
|
|
case ARG_SHARED:
|
|
|
|
src->decoder->shared_flag = g_value_get_boolean (value);
|
|
|
|
break;
|
2008-07-08 21:20:27 +00:00
|
|
|
case ARG_VIEWONLY:
|
|
|
|
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) {
|
|
|
|
case ARG_HOST:
|
|
|
|
g_value_set_string (value, src->host);
|
|
|
|
break;
|
|
|
|
case ARG_PORT:
|
|
|
|
g_value_set_int (value, src->port);
|
|
|
|
break;
|
2007-09-17 21:12:17 +00:00
|
|
|
case ARG_VERSION:
|
|
|
|
version = gst_rfb_property_get_version (src);
|
|
|
|
g_value_set_string (value, version);
|
|
|
|
g_free (version);
|
|
|
|
break;
|
2007-09-21 14:55:19 +00:00
|
|
|
case ARG_OFFSET_X:
|
|
|
|
g_value_set_int (value, src->decoder->offset_x);
|
|
|
|
break;
|
|
|
|
case ARG_OFFSET_Y:
|
|
|
|
g_value_set_int (value, src->decoder->offset_y);
|
|
|
|
break;
|
|
|
|
case ARG_WIDTH:
|
|
|
|
g_value_set_int (value, src->decoder->rect_width);
|
|
|
|
break;
|
|
|
|
case ARG_HEIGHT:
|
|
|
|
g_value_set_int (value, src->decoder->rect_height);
|
|
|
|
break;
|
2007-09-27 14:52:58 +00:00
|
|
|
case ARG_INCREMENTAL:
|
|
|
|
g_value_set_boolean (value, src->incremental_update);
|
|
|
|
break;
|
2007-11-29 13:32:11 +00:00
|
|
|
case ARG_USE_COPYRECT:
|
|
|
|
g_value_set_boolean (value, src->decoder->use_copyrect);
|
|
|
|
break;
|
2008-07-08 14:28:08 +00:00
|
|
|
case ARG_SHARED:
|
|
|
|
g_value_set_boolean (value, src->decoder->shared_flag);
|
|
|
|
break;
|
2008-07-08 21:20:27 +00:00
|
|
|
case ARG_VIEWONLY:
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rfb_src_start (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;
|
2008-11-05 23:31:41 +00:00
|
|
|
guint32 red_mask, green_mask, blue_mask;
|
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
|
|
|
|
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)) {
|
2008-11-05 22:25:25 +00:00
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
|
2006-11-17 03:15:40 +00:00
|
|
|
("Could not connect to host %s on port %d", src->host, src->port));
|
|
|
|
rfb_decoder_free (decoder);
|
|
|
|
return FALSE;
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
while (!decoder->inited) {
|
|
|
|
rfb_decoder_iterate (decoder);
|
|
|
|
}
|
2005-02-11 22:01:19 +00:00
|
|
|
|
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
|
|
|
g_object_set (bsrc, "blocksize",
|
2007-09-20 20:40:05 +00:00
|
|
|
src->decoder->width * src->decoder->height * (decoder->bpp / 8), NULL);
|
2005-02-11 22:01:19 +00:00
|
|
|
|
2007-10-31 14:09:25 +00:00
|
|
|
decoder->frame = g_malloc (bsrc->blocksize);
|
2007-11-29 13:32:11 +00:00
|
|
|
if (decoder->use_copyrect) {
|
|
|
|
decoder->prev_frame = g_malloc (bsrc->blocksize);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
caps =
|
|
|
|
gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (bsrc)));
|
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;
|
|
|
|
|
|
|
|
gst_caps_set_simple (caps, "width", G_TYPE_INT, decoder->rect_width,
|
|
|
|
"height", G_TYPE_INT, decoder->rect_height,
|
|
|
|
"bpp", G_TYPE_INT, decoder->bpp,
|
|
|
|
"depth", G_TYPE_INT, decoder->depth,
|
|
|
|
"endianness", G_TYPE_INT, G_BIG_ENDIAN,
|
|
|
|
"red_mask", G_TYPE_INT, GST_READ_UINT32_BE (&red_mask),
|
|
|
|
"green_mask", G_TYPE_INT, GST_READ_UINT32_BE (&green_mask),
|
|
|
|
"blue_mask", G_TYPE_INT, GST_READ_UINT32_BE (&blue_mask), NULL);
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
gst_pad_set_caps (GST_BASE_SRC_PAD (bsrc), caps);
|
|
|
|
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
|
|
|
|
2007-09-26 16:44:42 +00:00
|
|
|
src->decoder->fd = -1;
|
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
|
|
|
|
gst_rfb_src_create (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;
|
|
|
|
gulong newsize;
|
|
|
|
GstFlowReturn ret;
|
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) {
|
2006-11-17 03:15:40 +00:00
|
|
|
rfb_decoder_iterate (decoder);
|
2005-02-11 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
newsize = GST_BASE_SRC (psrc)->blocksize;
|
|
|
|
|
|
|
|
/* Create the buffer. */
|
|
|
|
ret = gst_pad_alloc_buffer (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
|
|
|
|
GST_BUFFER_OFFSET_NONE, newsize,
|
|
|
|
GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (ret != GST_FLOW_OK)) {
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-10-31 14:09:25 +00:00
|
|
|
memcpy (GST_BUFFER_DATA (*outbuf), decoder->frame, newsize);
|
2006-11-17 03:15:40 +00:00
|
|
|
GST_BUFFER_SIZE (*outbuf) = newsize;
|
2007-11-15 08:28:29 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (*outbuf) =
|
|
|
|
gst_clock_get_time (GST_ELEMENT_CLOCK (src)) -
|
|
|
|
GST_ELEMENT_CAST (src)->base_time;
|
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;
|
2005-02-11 22:01:19 +00:00
|
|
|
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;
|
|
|
|
|
2006-11-17 03:15:40 +00:00
|
|
|
structure = event->structure;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|