Now RED_CHANNEL_CLIENT is a function call so avoid to call multiple time for the same conversion in the same functions. This speed up and reduce code and also reduce source line length. Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- server/dcc.c | 40 +++++++++++++++++++++--------------- server/main-channel-client.c | 49 +++++++++++++++++++++++++------------------- server/main-channel.c | 2 +- server/smartcard.c | 8 +++++--- server/stream.c | 9 +++++--- 5 files changed, 63 insertions(+), 45 deletions(-) diff --git a/server/dcc.c b/server/dcc.c index 17f9300..f5f797c 100644 --- a/server/dcc.c +++ b/server/dcc.c @@ -545,9 +545,10 @@ static int display_channel_client_wait_for_init(DisplayChannelClient *dcc) { dcc->priv->expect_init = TRUE; uint64_t end_time = spice_get_monotonic_time_ns() + COMMON_CLIENT_TIMEOUT; + RedChannelClient *rcc = RED_CHANNEL_CLIENT(dcc); for (;;) { - red_channel_client_receive(RED_CHANNEL_CLIENT(dcc)); - if (!red_channel_client_is_connected(RED_CHANNEL_CLIENT(dcc))) { + red_channel_client_receive(rcc); + if (!red_channel_client_is_connected(rcc)) { break; } if (dcc->priv->pixmap_cache && dcc->priv->encoders.glz_dict) { @@ -561,7 +562,7 @@ static int display_channel_client_wait_for_init(DisplayChannelClient *dcc) } if (spice_get_monotonic_time_ns() > end_time) { spice_warning("timeout"); - red_channel_client_disconnect(RED_CHANNEL_CLIENT(dcc)); + red_channel_client_disconnect(rcc); break; } usleep(DISPLAY_CLIENT_RETRY_INTERVAL); @@ -574,7 +575,7 @@ void dcc_start(DisplayChannelClient *dcc) DisplayChannel *display = DCC_TO_DC(dcc); RedChannelClient *rcc = RED_CHANNEL_CLIENT(dcc); - red_channel_client_push_set_ack(RED_CHANNEL_CLIENT(dcc)); + red_channel_client_push_set_ack(rcc); if (red_channel_client_is_waiting_for_migrate_data(rcc)) return; @@ -582,7 +583,7 @@ void dcc_start(DisplayChannelClient *dcc) if (!display_channel_client_wait_for_init(dcc)) return; - red_channel_client_ack_zero_messages_window(RED_CHANNEL_CLIENT(dcc)); + red_channel_client_ack_zero_messages_window(rcc); if (display->priv->surfaces[0].context.canvas) { display_channel_current_flush(display, 0); red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_INVAL_PALETTE_CACHE); @@ -672,21 +673,23 @@ void dcc_push_monitors_config(DisplayChannelClient *dcc) DisplayChannel *dc = DCC_TO_DC(dcc); MonitorsConfig *monitors_config = dc->priv->monitors_config; RedMonitorsConfigItem *mci; + RedChannelClient *rcc; if (monitors_config == NULL) { spice_warning("monitors_config is NULL"); return; } - if (!red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(dcc), + rcc = RED_CHANNEL_CLIENT(dcc); + if (!red_channel_client_test_remote_cap(rcc, SPICE_DISPLAY_CAP_MONITORS_CONFIG)) { return; } - mci = red_monitors_config_item_new(red_channel_client_get_channel(RED_CHANNEL_CLIENT(dcc)), + mci = red_monitors_config_item_new(red_channel_client_get_channel(rcc), monitors_config); - red_channel_client_pipe_add(RED_CHANNEL_CLIENT(dcc), &mci->pipe_item); - red_channel_client_push(RED_CHANNEL_CLIENT(dcc)); + red_channel_client_pipe_add(rcc, &mci->pipe_item); + red_channel_client_push(rcc); } static RedSurfaceDestroyItem *red_surface_destroy_item_new(RedChannel *channel, @@ -960,16 +963,16 @@ int dcc_pixmap_cache_unlocked_add(DisplayChannelClient *dcc, uint64_t id, NewCacheItem *item; uint64_t serial; int key; + RedChannelClient *rcc = RED_CHANNEL_CLIENT(dcc); spice_assert(size > 0); item = spice_new(NewCacheItem, 1); - serial = red_channel_client_get_message_serial(RED_CHANNEL_CLIENT(dcc)); + serial = red_channel_client_get_message_serial(rcc); if (cache->generation != dcc->priv->pixmap_cache_generation) { if (!dcc->priv->pending_pixmaps_sync) { - red_channel_client_pipe_add_type( - RED_CHANNEL_CLIENT(dcc), RED_PIPE_ITEM_TYPE_PIXMAP_SYNC); + red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_PIXMAP_SYNC); dcc->priv->pending_pixmaps_sync = TRUE; } free(item); @@ -1203,6 +1206,7 @@ int dcc_handle_migrate_data(DisplayChannelClient *dcc, uint32_t size, void *mess SpiceMigrateDataDisplay *migrate_data = (SpiceMigrateDataDisplay *)(header + 1); uint8_t *surfaces; int i; + RedChannelClient *rcc; spice_return_val_if_fail( size >= (sizeof(*migrate_data) + sizeof(SpiceMigrateDataHeader)), FALSE); @@ -1210,11 +1214,13 @@ int dcc_handle_migrate_data(DisplayChannelClient *dcc, uint32_t size, void *mess migration_protocol_validate_header(header, SPICE_MIGRATE_DATA_DISPLAY_MAGIC, SPICE_MIGRATE_DATA_DISPLAY_VERSION), FALSE); + rcc = RED_CHANNEL_CLIENT(dcc); + /* size is set to -1 in order to keep the cache frozen until the original * channel client that froze the cache on the src size receives the migrate * data and unfreezes the cache by setting its size > 0 and by triggering * pixmap_cache_reset */ - dcc->priv->pixmap_cache = pixmap_cache_get(red_channel_client_get_client(RED_CHANNEL_CLIENT(dcc)), + dcc->priv->pixmap_cache = pixmap_cache_get(red_channel_client_get_client(rcc), migrate_data->pixmap_cache_id, -1); spice_return_val_if_fail(dcc->priv->pixmap_cache, FALSE); @@ -1229,7 +1235,7 @@ int dcc_handle_migrate_data(DisplayChannelClient *dcc, uint32_t size, void *mess /* activating the cache. The cache will start to be active after * pixmap_cache_reset is called, when handling RED_PIPE_ITEM_TYPE_PIXMAP_RESET */ dcc->priv->pixmap_cache->size = migrate_data->pixmap_cache_size; - red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(dcc), RED_PIPE_ITEM_TYPE_PIXMAP_RESET); + red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_PIXMAP_RESET); } if (dcc_handle_migrate_glz_dictionary(dcc, migrate_data)) { @@ -1241,7 +1247,7 @@ int dcc_handle_migrate_data(DisplayChannelClient *dcc, uint32_t size, void *mess dcc->is_low_bandwidth = migrate_data->low_bandwidth_setting; if (migrate_data->low_bandwidth_setting) { - red_channel_client_ack_set_client_window(RED_CHANNEL_CLIENT(dcc), WIDE_CLIENT_ACK_WINDOW); + red_channel_client_ack_set_client_window(rcc, WIDE_CLIENT_ACK_WINDOW); if (dcc->priv->jpeg_state == SPICE_WAN_COMPRESSION_AUTO) { display->priv->enable_jpeg = TRUE; } @@ -1257,9 +1263,9 @@ int dcc_handle_migrate_data(DisplayChannelClient *dcc, uint32_t size, void *mess spice_return_val_if_fail(surfaces_restored, FALSE); - red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(dcc), RED_PIPE_ITEM_TYPE_INVAL_PALETTE_CACHE); + red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_INVAL_PALETTE_CACHE); /* enable sending messages */ - red_channel_client_ack_zero_messages_window(RED_CHANNEL_CLIENT(dcc)); + red_channel_client_ack_zero_messages_window(rcc); return TRUE; } diff --git a/server/main-channel-client.c b/server/main-channel-client.c index 7304586..5c9859d 100644 --- a/server/main-channel-client.c +++ b/server/main-channel-client.c @@ -369,13 +369,14 @@ static RedPipeItem *main_name_item_new(const char *name) void main_channel_client_push_name(MainChannelClient *mcc, const char *name) { RedPipeItem *item; + RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc); - if (!red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(mcc), - SPICE_MAIN_CAP_NAME_AND_UUID)) + if (!red_channel_client_test_remote_cap(rcc, SPICE_MAIN_CAP_NAME_AND_UUID)) { return; + } item = main_name_item_new(name); - red_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(mcc), item); + red_channel_client_pipe_add_push(rcc, item); } static RedPipeItem *main_uuid_item_new(const uint8_t uuid[16]) @@ -391,13 +392,14 @@ static RedPipeItem *main_uuid_item_new(const uint8_t uuid[16]) void main_channel_client_push_uuid(MainChannelClient *mcc, const uint8_t uuid[16]) { RedPipeItem *item; + RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc); - if (!red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(mcc), - SPICE_MAIN_CAP_NAME_AND_UUID)) + if (!red_channel_client_test_remote_cap(rcc, SPICE_MAIN_CAP_NAME_AND_UUID)) { return; + } item = main_uuid_item_new(uuid); - red_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(mcc), item); + red_channel_client_pipe_add_push(rcc, item); } void main_channel_client_push_notify(MainChannelClient *mcc, const char *msg) @@ -433,10 +435,11 @@ void main_channel_client_handle_migrate_connected(MainChannelClient *mcc, int success, int seamless) { - RedClient *client = red_channel_client_get_client(RED_CHANNEL_CLIENT(mcc)); + RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc); + RedClient *client = red_channel_client_get_client(rcc); spice_printerr("client %p connected: %d seamless %d", client, success, seamless); if (mcc->priv->mig_wait_connect) { - RedChannel *channel = red_channel_client_get_channel(RED_CHANNEL_CLIENT(mcc)); + RedChannel *channel = red_channel_client_get_channel(rcc); MainChannel *main_channel = MAIN_CHANNEL(channel); mcc->priv->mig_wait_connect = FALSE; @@ -445,7 +448,7 @@ void main_channel_client_handle_migrate_connected(MainChannelClient *mcc, } else { if (success) { spice_printerr("client %p MIGRATE_CANCEL", client); - red_channel_client_pipe_add_empty_msg(RED_CHANNEL_CLIENT(mcc), + red_channel_client_pipe_add_empty_msg(rcc, SPICE_MSG_MAIN_MIGRATE_CANCEL); } } @@ -454,13 +457,14 @@ void main_channel_client_handle_migrate_connected(MainChannelClient *mcc, void main_channel_client_handle_migrate_dst_do_seamless(MainChannelClient *mcc, uint32_t src_version) { - RedChannel *channel = red_channel_client_get_channel(RED_CHANNEL_CLIENT(mcc)); + RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc); + RedChannel *channel = red_channel_client_get_channel(rcc); if (reds_on_migrate_dst_set_seamless(red_channel_get_server(channel), mcc, src_version)) { mcc->priv->seamless_mig_dst = TRUE; - red_channel_client_pipe_add_empty_msg(RED_CHANNEL_CLIENT(mcc), + red_channel_client_pipe_add_empty_msg(rcc, SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_ACK); } else { - red_channel_client_pipe_add_empty_msg(RED_CHANNEL_CLIENT(mcc), + red_channel_client_pipe_add_empty_msg(rcc, SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_NACK); } } @@ -499,7 +503,7 @@ void main_channel_client_handle_pong(MainChannelClient *mcc, SpiceMsgPing *ping, "bandwidth", mcc->priv->latency, roundtrip); mcc->priv->latency = 0; mcc->priv->net_test_stage = NET_TEST_STAGE_INVALID; - red_channel_client_start_connectivity_monitoring(RED_CHANNEL_CLIENT(mcc), + red_channel_client_start_connectivity_monitoring(rcc, CLIENT_CONNECTIVITY_TIMEOUT); break; } @@ -511,7 +515,7 @@ void main_channel_client_handle_pong(MainChannelClient *mcc, SpiceMsgPing *ping, mcc->priv->bitrate_per_sec, (double)mcc->priv->bitrate_per_sec / 1024 / 1024, main_channel_client_is_low_bandwidth(mcc) ? " LOW BANDWIDTH" : ""); - red_channel_client_start_connectivity_monitoring(RED_CHANNEL_CLIENT(mcc), + red_channel_client_start_connectivity_monitoring(rcc, CLIENT_CONNECTIVITY_TIMEOUT); break; default: @@ -525,12 +529,13 @@ void main_channel_client_handle_pong(MainChannelClient *mcc, SpiceMsgPing *ping, void main_channel_client_handle_migrate_end(MainChannelClient *mcc) { - RedClient *client = red_channel_client_get_client(RED_CHANNEL_CLIENT(mcc)); + RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc); + RedClient *client = red_channel_client_get_client(rcc); if (!red_client_during_migrate_at_target(client)) { spice_printerr("unexpected SPICE_MSGC_MIGRATE_END"); return; } - if (!red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(mcc), + if (!red_channel_client_test_remote_cap(rcc, SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE)) { spice_printerr("unexpected SPICE_MSGC_MIGRATE_END, " "client does not support semi-seamless migration"); @@ -552,14 +557,15 @@ void main_channel_client_migrate_cancel_wait(MainChannelClient *mcc) void main_channel_client_migrate_dst_complete(MainChannelClient *mcc) { + RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc); if (mcc->priv->mig_wait_prev_complete) { if (mcc->priv->mig_wait_prev_try_seamless) { - RedChannel *channel = red_channel_client_get_channel(RED_CHANNEL_CLIENT(mcc)); + RedChannel *channel = red_channel_client_get_channel(rcc); spice_assert(red_channel_get_n_clients(channel) == 1); - red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(mcc), + red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_BEGIN_SEAMLESS); } else { - red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(mcc), + red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_BEGIN); } mcc->priv->mig_wait_connect = TRUE; @@ -624,9 +630,10 @@ static void do_ping_client(MainChannelClient *mcc, static void ping_timer_cb(void *opaque) { MainChannelClient *mcc = opaque; - RedChannel *channel = red_channel_client_get_channel(RED_CHANNEL_CLIENT(mcc)); + RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc); + RedChannel *channel = red_channel_client_get_channel(rcc); - if (!red_channel_client_is_connected(RED_CHANNEL_CLIENT(mcc))) { + if (!red_channel_client_is_connected(rcc)) { spice_printerr("not connected to peer, ping off"); reds_core_timer_cancel(red_channel_get_server(channel), mcc->priv->ping_timer); diff --git a/server/main-channel.c b/server/main-channel.c index c7a67a9..ea24c22 100644 --- a/server/main-channel.c +++ b/server/main-channel.c @@ -87,7 +87,7 @@ static void main_channel_push_channels(MainChannelClient *mcc) "during migration"); return; } - red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(mcc), RED_PIPE_ITEM_TYPE_MAIN_CHANNELS_LIST); + red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_MAIN_CHANNELS_LIST); } void main_channel_push_mouse_mode(MainChannel *main_chan, int current_mode, diff --git a/server/smartcard.c b/server/smartcard.c index 29e4849..3461ac2 100644 --- a/server/smartcard.c +++ b/server/smartcard.c @@ -338,23 +338,25 @@ void smartcard_char_device_attach_client(SpiceCharDeviceInstance *char_device, { RedCharDeviceSmartcard *dev = red_char_device_opaque_get(char_device->st); int client_added; + RedChannelClient *rcc; spice_assert(!smartcard_channel_client_get_char_device(scc) && !dev->priv->scc); dev->priv->scc = scc; smartcard_channel_client_set_char_device(scc, dev); + rcc = RED_CHANNEL_CLIENT(scc); client_added = red_char_device_client_add(RED_CHAR_DEVICE(dev), - red_channel_client_get_client(RED_CHANNEL_CLIENT(scc)), + red_channel_client_get_client(rcc), FALSE, /* no flow control yet */ 0, /* send queue size */ ~0, ~0, red_channel_client_is_waiting_for_migrate_data( - RED_CHANNEL_CLIENT(scc))); + rcc)); if (!client_added) { spice_warning("failed"); dev->priv->scc = NULL; smartcard_channel_client_set_char_device(scc, NULL); - red_channel_client_disconnect(RED_CHANNEL_CLIENT(scc)); + red_channel_client_disconnect(rcc); } } diff --git a/server/stream.c b/server/stream.c index e5cad96..6892afe 100644 --- a/server/stream.c +++ b/server/stream.c @@ -764,9 +764,12 @@ static VideoEncoder* dcc_create_video_encoder(DisplayChannelClient *dcc, void dcc_create_stream(DisplayChannelClient *dcc, Stream *stream) { StreamAgent *agent = dcc_get_stream_agent(dcc, display_channel_get_stream_id(DCC_TO_DC(dcc), stream)); + RedChannelClient *rcc; spice_return_if_fail(region_is_empty(&agent->vis_region)); + rcc = RED_CHANNEL_CLIENT(dcc); + if (stream->current) { agent->frames = 1; region_clone(&agent->vis_region, &stream->current->tree_item.base.rgn); @@ -792,16 +795,16 @@ void dcc_create_stream(DisplayChannelClient *dcc, Stream *stream) } else { agent->video_encoder = dcc_create_video_encoder(dcc, 0, NULL); } - red_channel_client_pipe_add(RED_CHANNEL_CLIENT(dcc), stream_create_item_new(agent)); + red_channel_client_pipe_add(rcc, stream_create_item_new(agent)); - if (red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(dcc), SPICE_DISPLAY_CAP_STREAM_REPORT)) { + if (red_channel_client_test_remote_cap(rcc, SPICE_DISPLAY_CAP_STREAM_REPORT)) { RedStreamActivateReportItem *report_pipe_item = spice_malloc0(sizeof(*report_pipe_item)); agent->report_id = rand(); red_pipe_item_init(&report_pipe_item->pipe_item, RED_PIPE_ITEM_TYPE_STREAM_ACTIVATE_REPORT); report_pipe_item->stream_id = display_channel_get_stream_id(DCC_TO_DC(dcc), stream); - red_channel_client_pipe_add(RED_CHANNEL_CLIENT(dcc), &report_pipe_item->pipe_item); + red_channel_client_pipe_add(rcc, &report_pipe_item->pipe_item); } #ifdef STREAM_STATS memset(&agent->stats, 0, sizeof(StreamStats)); -- 2.7.4 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel