The StreamInfo message contains the guest (xrandr) output ID of the monitor that is being streamed. We store the guest_output_id in the monitors_guest_output_id hash table for a later use. Signed-off-by: Lukáš Hrázký <lhrazky@xxxxxxxxxx> --- server/red-stream-device.c | 40 +++++++++++++++++++++++++++++-- server/stream-channel.c | 11 +++++++++ server/stream-channel.h | 1 + server/tests/test-stream-device.c | 4 ++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/server/red-stream-device.c b/server/red-stream-device.c index fb036b93..4e85703b 100644 --- a/server/red-stream-device.c +++ b/server/red-stream-device.c @@ -34,6 +34,7 @@ struct StreamDevice { uint8_t hdr_pos; union { StreamMsgFormat format; + StreamMsgInfo info; StreamMsgCapabilities capabilities; StreamMsgCursorSet cursor_set; StreamMsgCursorMove cursor_move; @@ -64,8 +65,8 @@ static void char_device_set_state(RedCharDevice *char_dev, int state); typedef bool StreamMsgHandler(StreamDevice *dev, SpiceCharDeviceInstance *sin) SPICE_GNUC_WARN_UNUSED_RESULT; -static StreamMsgHandler handle_msg_format, handle_msg_data, handle_msg_cursor_set, - handle_msg_cursor_move, handle_msg_capabilities; +static StreamMsgHandler handle_msg_format, handle_msg_info, + handle_msg_data, handle_msg_cursor_set, handle_msg_cursor_move, handle_msg_capabilities; static bool handle_msg_invalid(StreamDevice *dev, SpiceCharDeviceInstance *sin, const char *error_msg) SPICE_GNUC_WARN_UNUSED_RESULT; @@ -166,6 +167,13 @@ stream_device_partial_read(StreamDevice *dev, SpiceCharDeviceInstance *sin) case STREAM_TYPE_CAPABILITIES: handled = handle_msg_capabilities(dev, sin); break; + case STREAM_TYPE_INFO: + if (dev->hdr.size != sizeof(StreamMsgInfo)) { + handled = handle_msg_invalid(dev, sin, "Wrong size for StreamMsgInfo"); + } else { + handled = handle_msg_info(dev, sin); + } + break; default: handled = handle_msg_invalid(dev, sin, "Invalid message type"); break; @@ -271,6 +279,34 @@ handle_msg_format(StreamDevice *dev, SpiceCharDeviceInstance *sin) return true; } +static bool +handle_msg_info(StreamDevice *dev, SpiceCharDeviceInstance *sin) +{ + SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin); + + if (spice_extra_checks) { + spice_assert(dev->hdr_pos >= sizeof(StreamDevHeader)); + spice_assert(dev->hdr.type == STREAM_TYPE_INFO); + } + + int n = sif->read(sin, dev->msg->buf + dev->msg_pos, sizeof(StreamMsgInfo) - dev->msg_pos); + if (n < 0) { + return handle_msg_invalid(dev, sin, NULL); + } + + dev->msg_pos += n; + + if (dev->msg_pos < sizeof(StreamMsgInfo)) { + return false; + } + + dev->msg->info.guest_output_id = GUINT32_FROM_LE(dev->msg->info.guest_output_id); + + stream_channel_handle_stream_info(dev->stream_channel, &dev->msg->info); + + return true; +} + static bool handle_msg_capabilities(StreamDevice *dev, SpiceCharDeviceInstance *sin) { diff --git a/server/stream-channel.c b/server/stream-channel.c index 2521d4dd..c9ebe6be 100644 --- a/server/stream-channel.c +++ b/server/stream-channel.c @@ -514,6 +514,17 @@ stream_channel_change_format(StreamChannel *channel, const StreamMsgFormat *fmt) red_channel_pipes_add_type(red_channel, RED_PIPE_ITEM_TYPE_STREAM_ACTIVATE_REPORT); } +void +stream_channel_handle_stream_info(StreamChannel *channel, const StreamMsgInfo *info) +{ + RedsState *reds = red_channel_get_server(RED_CHANNEL(channel)); + + uint32_t channel_id; + g_object_get(channel, "id", &channel_id, NULL); + + reds_store_monitor_guest_output_id(reds, channel_id, 0 /*monitor_id*/, info->guest_output_id); +} + static inline void stream_channel_update_queue_stat(StreamChannel *channel, int32_t num_diff, int32_t size_diff) diff --git a/server/stream-channel.h b/server/stream-channel.h index e8bec80b..83c73012 100644 --- a/server/stream-channel.h +++ b/server/stream-channel.h @@ -60,6 +60,7 @@ struct StreamMsgStartStop; void stream_channel_change_format(StreamChannel *channel, const struct StreamMsgFormat *fmt); +void stream_channel_handle_stream_info(StreamChannel *channel, const struct StreamMsgInfo *info); void stream_channel_send_data(StreamChannel *channel, const void *data, size_t size, uint32_t mm_time); diff --git a/server/tests/test-stream-device.c b/server/tests/test-stream-device.c index f1707d2f..26fdb8d4 100644 --- a/server/tests/test-stream-device.c +++ b/server/tests/test-stream-device.c @@ -203,6 +203,10 @@ void stream_channel_change_format(StreamChannel *channel, { } +void stream_channel_handle_stream_info(StreamChannel *channel, const StreamMsgInfo *info) +{ +} + void stream_channel_send_data(StreamChannel *channel, const void *data, size_t size, uint32_t mm_time) -- 2.18.0 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel