This reduces the direct access to the struct in preparation for GObjectification --- server/Makefile.am | 3 ++ server/common-graphics-channel-client-private.h | 29 ++++++++++++ server/common-graphics-channel-client.c | 60 +++++++++++++++++++++++++ server/common-graphics-channel-client.h | 42 +++++++++++++++++ server/cursor-channel.c | 3 +- server/dcc-private.h | 1 + server/dcc.c | 2 +- server/display-channel.c | 5 ++- server/display-channel.h | 1 - server/red-record-qxl.c | 1 - server/red-worker.c | 34 ++------------ server/red-worker.h | 18 +------- server/stream.c | 4 +- 13 files changed, 148 insertions(+), 55 deletions(-) create mode 100644 server/common-graphics-channel-client-private.h create mode 100644 server/common-graphics-channel-client.c create mode 100644 server/common-graphics-channel-client.h diff --git a/server/Makefile.am b/server/Makefile.am index 5f098cb..ed6c875 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -71,6 +71,9 @@ libserver_la_SOURCES = \ cache-item.h \ char-device.c \ char-device.h \ + common-graphics-channel-client.c \ + common-graphics-channel-client.h \ + common-graphics-channel-client-private.h \ demarshallers.h \ event-loop.c \ glz-encoder.c \ diff --git a/server/common-graphics-channel-client-private.h b/server/common-graphics-channel-client-private.h new file mode 100644 index 0000000..8a9ef76 --- /dev/null +++ b/server/common-graphics-channel-client-private.h @@ -0,0 +1,29 @@ +/* + Copyright (C) 2009-2015 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef COMMON_GRAPHICS_CHANNEL_CLIENT_PRIVATE_H +#define COMMON_GRAPHICS_CHANNEL_CLIENT_PRIVATE_H + +#include "common-graphics-channel-client.h" +#include "red-channel.h" + +struct CommonGraphicsChannelClient { + RedChannelClient base; + + int is_low_bandwidth; +}; + +#endif /* COMMON_GRAPHICS_CHANNEL_CLIENT_PRIVATE_H */ diff --git a/server/common-graphics-channel-client.c b/server/common-graphics-channel-client.c new file mode 100644 index 0000000..1de4fe2 --- /dev/null +++ b/server/common-graphics-channel-client.c @@ -0,0 +1,60 @@ +/* + Copyright (C) 2009-2015 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "common-graphics-channel-client-private.h" +#include "dcc.h" + +void common_graphics_channel_client_set_low_bandwidth(CommonGraphicsChannelClient *self, + gboolean low_bandwidth) +{ + self->is_low_bandwidth = low_bandwidth; +} + +gboolean common_graphics_channel_client_is_low_bandwidth(CommonGraphicsChannelClient *self) +{ + return self->is_low_bandwidth; +} + +CommonGraphicsChannelClient *common_graphics_channel_client_new(CommonGraphicsChannel *common, + int size, + RedClient *client, + RedsStream *stream, + int mig_target, + int monitor_latency, + uint32_t *common_caps, + int num_common_caps, + uint32_t *caps, + int num_caps) +{ + RedChannelClient *rcc = + red_channel_client_create(size, RED_CHANNEL(common), client, stream, monitor_latency, + num_common_caps, common_caps, num_caps, caps); + if (!rcc) { + return NULL; + } + CommonGraphicsChannelClient *common_cc = (CommonGraphicsChannelClient*)rcc; + common->during_target_migrate = mig_target; + + // TODO: move wide/narrow ack setting to red_channel. + red_channel_client_ack_set_client_window(rcc, + common_cc->is_low_bandwidth ? + WIDE_CLIENT_ACK_WINDOW : NARROW_CLIENT_ACK_WINDOW); + return common_cc; +} diff --git a/server/common-graphics-channel-client.h b/server/common-graphics-channel-client.h new file mode 100644 index 0000000..fedd1a1 --- /dev/null +++ b/server/common-graphics-channel-client.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2009-2015 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef COMMON_GRAPHICS_CHANNEL_CLIENT_H +#define COMMON_GRAPHICS_CHANNEL_CLIENT_H + +#include "red-common.h" + +typedef struct CommonGraphicsChannelClient CommonGraphicsChannelClient; +typedef struct CommonGraphicsChannel CommonGraphicsChannel; +typedef struct RedClient RedClient; +typedef struct RedsStream RedsStream; + +void common_graphics_channel_client_set_low_bandwidth(CommonGraphicsChannelClient *self, + gboolean low_bandwidth); +gboolean common_graphics_channel_client_is_low_bandwidth(CommonGraphicsChannelClient *self); + +CommonGraphicsChannelClient *common_graphics_channel_client_new(CommonGraphicsChannel *common, + int size, + RedClient *client, + RedsStream *stream, + int mig_target, + int monitor_latency, + uint32_t *common_caps, + int num_common_caps, + uint32_t *caps, + int num_caps); + +#endif /* COMMON_GRAPHICS_CHANNEL_CLIENT_H */ diff --git a/server/cursor-channel.c b/server/cursor-channel.c index c4304cc..ae4b408 100644 --- a/server/cursor-channel.c +++ b/server/cursor-channel.c @@ -21,6 +21,7 @@ #include <glib.h> #include "common/generated_server_marshallers.h" +#include "common-graphics-channel-client-private.h" #include "cursor-channel.h" #include "cache-item.h" @@ -462,7 +463,7 @@ CursorChannelClient* cursor_channel_client_new(CursorChannel *cursor, RedClient spice_return_val_if_fail(!num_caps || caps, NULL); CursorChannelClient *ccc = - (CursorChannelClient*)common_graphics_channel_new_client(&cursor->common, + (CursorChannelClient*)common_graphics_channel_client_new(&cursor->common, sizeof(CursorChannelClient), client, stream, mig_target, diff --git a/server/dcc-private.h b/server/dcc-private.h index 6f6bbf9..85c5a33 100644 --- a/server/dcc-private.h +++ b/server/dcc-private.h @@ -19,6 +19,7 @@ #define DCC_PRIVATE_H_ #include "cache-item.h" +#include "common-graphics-channel-client-private.h" #include "dcc.h" #include "dcc-encoders.h" #include "stream.h" diff --git a/server/dcc.c b/server/dcc.c index 9669b95..6e24317 100644 --- a/server/dcc.c +++ b/server/dcc.c @@ -364,7 +364,7 @@ DisplayChannelClient *dcc_new(DisplayChannel *display, { DisplayChannelClient *dcc; - dcc = (DisplayChannelClient*)common_graphics_channel_new_client( + dcc = (DisplayChannelClient*)common_graphics_channel_client_new( COMMON_GRAPHICS_CHANNEL(display), sizeof(DisplayChannelClient), client, stream, mig_target, TRUE, common_caps, num_common_caps, diff --git a/server/display-channel.c b/server/display-channel.c index 5df1ab8..d086ab1 100644 --- a/server/display-channel.c +++ b/server/display-channel.c @@ -2131,14 +2131,15 @@ void display_channel_process_surface_cmd(DisplayChannel *display, RedSurfaceCmd void display_channel_update_compression(DisplayChannel *display, DisplayChannelClient *dcc) { + gboolean is_low_bw = common_graphics_channel_client_is_low_bandwidth((CommonGraphicsChannelClient*)dcc); if (dcc_get_jpeg_state(dcc) == SPICE_WAN_COMPRESSION_AUTO) { - display->enable_jpeg = ((CommonGraphicsChannelClient*)dcc)->is_low_bandwidth; + display->enable_jpeg = is_low_bw; } else { display->enable_jpeg = (dcc_get_jpeg_state(dcc) == SPICE_WAN_COMPRESSION_ALWAYS); } if (dcc_get_zlib_glz_state(dcc) == SPICE_WAN_COMPRESSION_AUTO) { - display->enable_zlib_glz_wrap = ((CommonGraphicsChannelClient*)dcc)->is_low_bandwidth; + display->enable_zlib_glz_wrap = is_low_bw; } else { display->enable_zlib_glz_wrap = (dcc_get_zlib_glz_state(dcc) == SPICE_WAN_COMPRESSION_ALWAYS); } diff --git a/server/display-channel.h b/server/display-channel.h index d87b222..cb0a1e3 100644 --- a/server/display-channel.h +++ b/server/display-channel.h @@ -21,7 +21,6 @@ #include <setjmp.h> #include "common/rect.h" -#include "red-worker.h" #include "reds-stream.h" #include "cache-item.h" #include "pixmap-cache.h" diff --git a/server/red-record-qxl.c b/server/red-record-qxl.c index 9c9dd62..2791903 100644 --- a/server/red-record-qxl.c +++ b/server/red-record-qxl.c @@ -21,7 +21,6 @@ #include <stdbool.h> #include <inttypes.h> -#include "red-worker.h" #include "red-common.h" #include "memslot.h" #include "red-parse-qxl.h" diff --git a/server/red-worker.c b/server/red-worker.c index 5b6bc7b..46fbc4d 100644 --- a/server/red-worker.c +++ b/server/red-worker.c @@ -404,6 +404,7 @@ static int common_channel_config_socket(RedChannelClient *rcc) CommonGraphicsChannelClient *ccc = COMMON_GRAPHICS_CHANNEL_CLIENT(rcc); int flags; int delay_val; + gboolean low_bw; if ((flags = fcntl(stream->socket, F_GETFL)) == -1) { spice_warning("accept failed, %s", strerror(errno)); @@ -416,8 +417,9 @@ static int common_channel_config_socket(RedChannelClient *rcc) } // TODO - this should be dynamic, not one time at channel creation - ccc->is_low_bandwidth = main_channel_client_is_low_bandwidth(mcc); - delay_val = ccc->is_low_bandwidth ? 0 : 1; + low_bw = main_channel_client_is_low_bandwidth(mcc); + common_graphics_channel_client_set_low_bandwidth(ccc, low_bw); + delay_val = low_bw ? 0 : 1; /* FIXME: Using Nagle's Algorithm can lead to apparent delays, depending * on the delayed ack timeout on the other side. * Instead of using Nagle's, we need to implement message buffering on @@ -433,34 +435,6 @@ static int common_channel_config_socket(RedChannelClient *rcc) return TRUE; } -CommonGraphicsChannelClient *common_graphics_channel_new_client(CommonGraphicsChannel *common, - int size, - RedClient *client, - RedsStream *stream, - int mig_target, - int monitor_latency, - uint32_t *common_caps, - int num_common_caps, - uint32_t *caps, - int num_caps) -{ - RedChannelClient *rcc = - red_channel_client_create(size, &common->base, client, stream, monitor_latency, - num_common_caps, common_caps, num_caps, caps); - if (!rcc) { - return NULL; - } - CommonGraphicsChannelClient *common_cc = (CommonGraphicsChannelClient*)rcc; - common->during_target_migrate = mig_target; - - // TODO: move wide/narrow ack setting to red_channel. - red_channel_client_ack_set_client_window(rcc, - common_cc->is_low_bandwidth ? - WIDE_CLIENT_ACK_WINDOW : NARROW_CLIENT_ACK_WINDOW); - return common_cc; -} - - CommonGraphicsChannel *red_worker_new_channel(RedWorker *worker, int size, const char *name, uint32_t channel_type, int migration_flags, diff --git a/server/red-worker.h b/server/red-worker.h index 63be8b5..5afc4e0 100644 --- a/server/red-worker.h +++ b/server/red-worker.h @@ -19,17 +19,12 @@ #define _H_REDWORKER #include "red-common.h" +#include "common-graphics-channel-client.h" #include "red-qxl.h" #include "red-parse-qxl.h" typedef struct RedWorker RedWorker; -typedef struct CommonGraphicsChannelClient { - RedChannelClient base; - - int is_low_bandwidth; -} CommonGraphicsChannelClient; - #define COMMON_GRAPHICS_CHANNEL_CLIENT(Client) ((CommonGraphicsChannelClient*)(Client)) #define COMMON_CLIENT_TIMEOUT (NSEC_PER_SEC * 30) @@ -100,15 +95,4 @@ CommonGraphicsChannel *red_worker_new_channel(RedWorker *worker, int size, ChannelCbs *channel_cbs, channel_handle_parsed_proc handle_parsed); -CommonGraphicsChannelClient *common_graphics_channel_new_client(CommonGraphicsChannel *common, - int size, - RedClient *client, - RedsStream *stream, - int mig_target, - int monitor_latency, - uint32_t *common_caps, - int num_common_caps, - uint32_t *caps, - int num_caps); - #endif diff --git a/server/stream.c b/server/stream.c index 131e347..ee3c0b0 100644 --- a/server/stream.c +++ b/server/stream.c @@ -341,7 +341,7 @@ static void before_reattach_stream(DisplayChannel *display, agent = dcc_get_stream_agent(dcc, index); if (!dcc_use_mjpeg_encoder_rate_control(dcc) && - !((CommonGraphicsChannelClient*)dcc)->is_low_bandwidth) { + !common_graphics_channel_client_is_low_bandwidth((CommonGraphicsChannelClient*)dcc)) { continue; } @@ -640,7 +640,7 @@ static uint64_t get_initial_bit_rate(DisplayChannelClient *dcc, Stream *stream) * If the network info is not initialized due to another reason, * the low_bandwidth flag is FALSE. */ - bit_rate = ((CommonGraphicsChannelClient*)dcc)->is_low_bandwidth ? + bit_rate = common_graphics_channel_client_is_low_bandwidth((CommonGraphicsChannelClient*)dcc) ? RED_STREAM_DEFAULT_LOW_START_BIT_RATE : RED_STREAM_DEFAULT_HIGH_START_BIT_RATE; } -- 2.4.11 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel