From b98012690960ac3b3b3edf288bd4ab8a3e8aa91d Mon Sep 17 00:00:00 2001 From: Thijs Vermeir Date: Mon, 17 Sep 2007 21:12:17 +0000 Subject: Added a new property for the rfb version Original commit message from CVS: Added a new property for the rfb version --- gst/librfb/gstrfbsrc.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ gst/librfb/gstrfbsrc.h | 5 +++++ gst/librfb/rfbdecoder.c | 51 +++++++++++++++++++++++++++++++++++++++---- gst/librfb/rfbdecoder.h | 4 ++-- 4 files changed, 112 insertions(+), 6 deletions(-) (limited to 'gst/librfb') diff --git a/gst/librfb/gstrfbsrc.c b/gst/librfb/gstrfbsrc.c index 66214f1a..b0fd6962 100644 --- a/gst/librfb/gstrfbsrc.c +++ b/gst/librfb/gstrfbsrc.c @@ -35,6 +35,7 @@ enum ARG_0, ARG_HOST, ARG_PORT, + ARG_VERSION, }; #define RGB332_R(x) ((((x)&0x07) * 0x124)>>3) @@ -116,6 +117,9 @@ gst_rfb_src_class_init (GstRfbSrcClass * klass) g_object_class_install_property (gobject_class, ARG_PORT, g_param_spec_int ("port", "Port", "Port", 1, 65535, 5900, G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, ARG_VERSION, + g_param_spec_string ("version", "RFB protocol version", + "RFB protocol version", "3.3", G_PARAM_READWRITE)); gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_rfb_src_start); gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_rfb_src_stop); @@ -136,6 +140,8 @@ gst_rfb_src_init (GstRfbSrc * src, GstRfbSrcClass * klass) src->host = g_strdup ("127.0.0.1"); src->port = 5900; + src->version_major = 3; + src->version_minor = 3; } static void @@ -148,6 +154,49 @@ gst_rfb_src_dispose (GObject * object) G_OBJECT_CLASS (parent_class)->dispose (object); } +static void +gst_rfb_property_set_version (GstRfbSrc * src, gchar * value) +{ + g_return_if_fail (src != NULL); + g_return_if_fail (value != NULL); + + gchar *major = g_strdup (value); + gchar *minor = g_strrstr (value, "."); + + 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) +{ + gchar *version = g_malloc (8); + gchar *major = g_strdup_printf ("%d", src->version_major); + gchar *minor = g_strdup_printf ("%d", src->version_minor); + + g_stpcpy (version, major); + g_strlcat (version, ".", 8); + g_strlcat (version, minor, 8); + + g_free (major); + g_free (minor); + + return version; +} + static void gst_rfb_src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) @@ -161,6 +210,9 @@ gst_rfb_src_set_property (GObject * object, guint prop_id, case ARG_PORT: src->port = g_value_get_int (value); break; + case ARG_VERSION: + gst_rfb_property_set_version (src, g_strdup (g_value_get_string (value))); + break; default: break; } @@ -171,6 +223,7 @@ gst_rfb_src_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { GstRfbSrc *src = GST_RFB_SRC (object); + gchar *version; switch (prop_id) { case ARG_HOST: @@ -179,6 +232,11 @@ gst_rfb_src_get_property (GObject * object, guint prop_id, case ARG_PORT: g_value_set_int (value, src->port); break; + case ARG_VERSION: + version = gst_rfb_property_get_version (src); + g_value_set_string (value, version); + g_free (version); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; diff --git a/gst/librfb/gstrfbsrc.h b/gst/librfb/gstrfbsrc.h index b908807a..57e6d338 100644 --- a/gst/librfb/gstrfbsrc.h +++ b/gst/librfb/gstrfbsrc.h @@ -60,6 +60,11 @@ struct _GstRfbSrc gboolean inter; guint button_mask; + + /* protocol version */ + guint version_major; + guint version_minor; + }; GType gst_rfb_src_get_type (void); diff --git a/gst/librfb/rfbdecoder.c b/gst/librfb/rfbdecoder.c index 5cacf092..490dd44c 100644 --- a/gst/librfb/rfbdecoder.c +++ b/gst/librfb/rfbdecoder.c @@ -2,7 +2,7 @@ #include "config.h" #endif -#include "rfbdecoder.h" +#include "gst/gst.h" #include #include @@ -20,6 +20,9 @@ #define RFB_SET_UINT16(ptr, val) (*(guint16 *)(ptr) = GUINT16_TO_BE (val)) #define RFB_SET_UINT8(ptr, val) (*(guint8 *)(ptr) = val) +GST_DEBUG_CATEGORY_STATIC (rfbdecoder_debug); +#define GST_CAT_DEFAULT rfbdecoder_debug + #if 0 struct _RfbSocketPrivate { @@ -109,17 +112,28 @@ rfb_decoder_connect_tcp (RfbDecoder * decoder, gchar * addr, guint port) return TRUE; } +/** + * rfb_decoder_iterate: + * @decoder: The rfb context + * + * Initializes the connection with the rfb server + * + * Returns: TRUE if initialization was succesfull, FALSE on fail. + */ gboolean rfb_decoder_iterate (RfbDecoder * decoder) { + GST_DEBUG_CATEGORY_INIT (rfbdecoder_debug, "rfbdecoder", 0, "Rfb source"); + g_return_val_if_fail (decoder != NULL, FALSE); g_return_val_if_fail (decoder->fd != -1, FALSE); if (decoder->state == NULL) { + GST_DEBUG ("First iteration: set state to -> wait for protocol version"); decoder->state = rfb_decoder_state_wait_for_protocol_version; } - // g_print ("iterating...\n"); + GST_DEBUG ("Executing next state in initialization"); return decoder->state (decoder); } @@ -185,6 +199,13 @@ rfb_decoder_send_pointer_event (RfbDecoder * decoder, rfb_decoder_send (decoder, data, 6); } +/** + * rfb_decoder_state_wait_for_protocol_version: + * + * Negotiate the rfb version used + * + * \TODO Support for versions 3.7 and 3.8 + */ static gboolean rfb_decoder_state_wait_for_protocol_version (RfbDecoder * decoder) { @@ -198,10 +219,32 @@ rfb_decoder_state_wait_for_protocol_version (RfbDecoder * decoder) data = buffer->data; - g_assert (memcmp (buffer->data, "RFB 003.00", 10) == 0); - // g_print ("\"%.11s\"\n", buffer->data); + g_return_val_if_fail (memcmp (buffer->data, "RFB 003.00", 10) == 0, FALSE); + g_return_val_if_fail (*(buffer->data + 11) == 0x0a, FALSE); + + GST_DEBUG ("\"%.11s\"", buffer->data); + *(buffer->data + 7) = 0x00; + *(buffer->data + 11) = 0x00; + decoder->protocol_major = atoi ((char *) (buffer->data + 4)); + decoder->protocol_minor = atoi ((char *) (buffer->data + 8)); + GST_DEBUG ("Major version : %d", decoder->protocol_major); + GST_DEBUG ("Minor version : %d", decoder->protocol_minor); rfb_buffer_free (buffer); + if (decoder->protocol_major != 3) { + GST_INFO + ("A major protocol version of %d is not supported, falling back to 3", + decoder->protocol_major); + decoder->protocol_major = 3; + } + switch (decoder->protocol_minor) { + case 3: + break; + default: + GST_INFO ("Minor version %d is not supported, using 3", + decoder->protocol_minor); + decoder->protocol_minor = 3; + } rfb_decoder_send (decoder, (guint8 *) "RFB 003.003\n", 12); decoder->state = rfb_decoder_state_wait_for_security; diff --git a/gst/librfb/rfbdecoder.h b/gst/librfb/rfbdecoder.h index 4163efe7..193e7995 100644 --- a/gst/librfb/rfbdecoder.h +++ b/gst/librfb/rfbdecoder.h @@ -31,8 +31,8 @@ struct _RfbDecoder /* readable properties */ gboolean inited; - gint protocol_major; - gint protocol_minor; + guint protocol_major; + guint protocol_minor; guint security_type; guint width; -- cgit v1.2.1