Commit Graph

556 Commits

Author SHA1 Message Date
Alon Levy
9c192980e8 server/red_worker: remove more direct access to RedChannelClient.rcc 2011-08-23 18:01:51 +03:00
Yonit Halperin
d42575feab server/red_worker.c: make dictionary and cache different per client
There is no inter-client shared dictionary and cache yet.

At this point the display channel can be used by multiple clients.

You can still crash on lack of Drawables or CursorItems due to the slower
clients pipe growing uncontrollably.
2011-08-23 18:01:28 +03:00
Alon Levy
a32e90257e server/red_worker: multiple client support - base split
This patch compiles but breaks spice.

Split both display and cursor channels to a client part and channel part.

Introduce DisplayChannelClient, CursorChannelClient, CommonChannelClient.
don't disconnect channel on client disconnect.
Move all caches to the ChannelClient's.

Remove reference counting of the channel.

No new functionality introduced.

NOTE: Introduces a crash in disconnections, a regression, resulting from
incorrect thread access, that is fixed in the patch titled:
"server: registering RedChannel in reds, instead of Channel"
2011-08-23 18:01:04 +03:00
Alon Levy
406751888e server/red_worker: cleanup 2011-08-23 18:00:41 +03:00
Alon Levy
eded227f4c server/smartcard: support multiple clients
each client supplying a smartcard channel gets it's own smartcard. If
there are not enough smartcards provided by the server (read: qemu)
then it will be as though there are none.

currently disabled - later patches that enable smartcard don't make
this channel available to any but the first client.
2011-08-23 18:00:19 +03:00
Alon Levy
9aa62c4baa server/red_tunnel_worker: trivial multi client support
s/TunnelChannel/TunnelChannelClient/

That's about it.  this is probably the wrong way to do it. Not tested
at all. What do we want, a separate interface per client? same interface
for all clients? probably the later. This doesn't do that. Not tested,
so probably doesn't even work.

changes red_channel_pipe_item_is_linked to red_channel_client_pipe_item_is_linked,
since tunnel channel is the only user, must be done in patch to not break compilation.
2011-08-23 17:59:55 +03:00
Alon Levy
82524cec13 server/inputs_channel: support multiple clients
from server events are broadcast - leds change. The rest is client
to server, so it is just passed on.
2011-08-23 17:59:34 +03:00
Alon Levy
9cece23ba3 server/main_channel: support multiple clients
The main channel deals with connecting new clients, announcing mouse mode
changes, and the agent channel. The implementation is currently done without
any changes to the protocol, so everything has to be either broadcast or
to a specific client.

 channels list - specific client
 mouse mode - broadcast
 agent - broadcast
 notify - broadcast (should have two modes, and use the appropriate)

Notable TODOs:
 * migration testing
 * agent tokens are wrongly sent (or did I fix that? check)
2011-08-23 17:59:09 +03:00
Alon Levy
0f0bdb190b server/red_channel: introduce pipes functions
Introduce functions to add (via producer method) the same item to multiple
pipes, all for the same channel.

Note: Right now there is only a single channel, but the next patches will do the
per-channel breakdown to channel and channel_client before actually introducing
a ring in RedChannel, this makes it easier to make smaller changes - the
channel->rcc link will exist until removed in the ring introducing patch.
2011-08-23 17:58:46 +03:00
Alon Levy
03cf66383c server/red_channel: ignore error if already shutdown
on red_channel_peer_on_incoming_error, if we are already shutdown, do not
call the channel's error handler. Since the channel has been shutdown, we
assume this is a second or later error, and handling has already occured.
2011-08-23 17:58:24 +03:00
Alon Levy
4e304ff40f server/main_channel: move connection_id from reds
Expose additional api to find a client given a connection_id. The connection_id
is first set when the first channel connects, which is the main channel.
It could also be kept in the RedClient instead, not sure.

TODO:
 multiple todo's added for multiclient handling. I don't remember why
 I wrote them exactly, and besides if I did any migration tests. So: TODO.
2011-08-23 17:58:01 +03:00
Alon Levy
d65b08e12d server/main_channel: move ping here from reds.
cleanup only. Note that the ping function is half used since the opt parameter
stopped being called with anything but NULL, should be returned at some point,
specifically when we drop the 250kbyte ping on start and do a continuous check
for latency and bandwidth.

See:
 81945d897 - server: add new vd interface QTerm2Interface, Yaniv Kamay
  introducing the usage of ping with a non NULL opt
 3f7ea8e7a - zap qterm interfaces, Gerd Hoffman
  removing it
2011-08-23 17:57:37 +03:00
Alon Levy
5bcdf37997 server/main_channel: move latency and bitrate to channel client
They were globals before. This introduces api for other channels
to query the low bandwidth status. The queries themselves are still done
from the wrong context (channel and not channel client) but that's because
the decoupling of channel and channel client will be done in the following
patches.

Note that snd_worker.c got two copied function declarations that belong to
main_channel.h but can't be easily dragged into snd_worker.c since it still
uses it's own RedChannel struct.
2011-08-23 17:57:13 +03:00
Alon Levy
614df17193 server/reds: add concept of secondary channels
Secondary channels are those that don't support multiple clients. The
support added in this patch just doesn't let the second or more connected
client receive the unsupported channels in the channels list sent by the
server to the client. This doesn't handle the situation where:

client A connects (gets all channels)
client B connects (gets supported multiple client channels)
client A disconnects (Suboptimal 1: B doesn't get new channels at this point)
client C connects (Suboptimal 2: C doesn't get the full list of channels, but
the partial one)

Specifically the channels that only support a single client are:
 sound (both playback and record channels)
 smartcard
 tunnel
2011-08-23 17:56:46 +03:00
Alon Levy
448ed75bd6 server: Add RedClient
That means RedClient tracks a ring of channels. Right now there will be only
a single client because of the disconnection mechanism - whenever a new
client comes we disconnect all existing clients. But this patch adds already
a ring of clients to reds.c (stored in RedServer).

There is a known problem handling many connections and disconnections at the
same time, trigerrable easily by the following script:

export NEW_DISPLAY=:3.0

Xephyr $NEW_DISPLAY -noreset &
for ((i = 0 ; i < 5; ++i)); do
    for ((j = 0 ; j < 10; ++j)); do
        DISPLAY=$NEW_DISPLAY c_win7x86_qxl_tests &
    done
    sleep 2;
done

I fixed a few of the problems resulting from this in the same patch. This
required already introducing a few other changes:
 * make sure all removal of channels happens in the main thread, for that
 two additional dispatcher calls are added to remove a specific channel
 client (RED_WORKER_MESSAGE_CURSOR_DISCONNECT_CLIENT and
 RED_WORKER_MESSAGE_DISPLAY_DISCONNECT_CLIENT).
 * change some asserts in input channel.
 * make main channel disconnect not recursive
 * introduce disconnect call back to red_channel_create_parser

The remaining abort is from a double free in the main channel, still can't
find it (doesn't happen when running under valgrind - probably due to the
slowness resulting from that), but is easy to see when running under gdb.
2011-08-23 17:56:44 +03:00
Alon Levy
22084c4703 server/main_channel+reds: make main_channel_init return MainChannelClient
This makes it easier to introduce RedClient in the next patch.
2011-08-23 17:46:30 +03:00
Alon Levy
2550e825ec server/red_worker: release PIPE_ITEM_TYPE_VERB in display channel
We send a SPICE_MSG_DISPLAY_MARK verb.
2011-08-23 17:46:07 +03:00
Alon Levy
9ae19999d2 server/red_client: clear pipe on disconnect 2011-08-23 17:45:45 +03:00
Alon Levy
cd2c87da3e server/red_channel: workaround for fast client disconnect bug (TODO - real fix) 2011-08-23 17:45:24 +03:00
Alon Levy
6be2c77dd9 server/main_channel: use MainChannel in sig
use MainChannel* instead of Channel* for a many functions in main_channel.h
(affects main_channel.c and reds.c).

some one liner fixes are hidden in here too.
2011-08-23 17:44:58 +03:00
Alon Levy
09ae4700d2 server: move pipe from RedChannel to RedChannelClient
Another cleanup patch, no change to behavior (still one client, and it
disconnects previous client if any).

The implementation for multiple client is straightforward: the pipe
remains per (channel,client) pair, so it needs to move from the RedChannel
that to RedChannelClient. Implementation using a single pipe with multiple
consumers (to reflect different latencies) doesn't fit well with pipe rewriting
that is used by the display channel. Additionally this approach is much simpler
to verify. Lastly it doesn't add considerable overhead (but see the display
channel changes in a later patch for a real place to rethink).

This patch is just technical, changing signatures to reflect the first
argument (oop style) so red_channel becomes red_channel_client. Some places
may seem odd but they should be fixed with later comits where the channels
grow to support multiple clients.

Sound (playback/record) channels are the only ones not touched - this is
consistent with previous patches, since they have been left out of the
RedChannel refactoring.  That is left as future work. (note that they don't use
a pipe, which was the reason for not refactoring).
2011-08-23 17:44:54 +03:00
Alon Levy
b6cf68604f server/red_worker: introduce {display,cursor}_is_connected
Instead of checking for worker->{display,cursor}_channel directly.
2011-08-23 17:42:48 +03:00
Alon Levy
7e8e13593e server/red_channel (all): introduce RedChannelClient
This commit adds a RedChannelClient that now owns the stream connection,
but still doesn't own the pipe. There is only a single RCC per RC
right now (and RC still means RedChannel, RedClient will be introduced
later). All internal api changes are in server/red_channel.h, hence
the need to update all channels. red_worker.c is affected the most because
it makes use of direct access to some of RedChannel still.

API changes:

 1. red_channel_client_create added.
  rec_channel_create -> (red_channel_create, red_channel_client_create)
 2. two way connection: rcc->channel, channel->rcc (later channel will
  hold a list, and there will be a RedClient to hold the list of channels
  per client)
 3. seperation of channel disconnect and channel_client_disconnect

TODO:
 usbredir added untested.
2011-08-23 17:42:36 +03:00
Alon Levy
75b6a305ff server/red_worker: drop red_pipe_add_tail, use red_channel_pipe_add_tail
The only difference between them being that the later also does a push.
I don't believe that to be a problem, but if it does I can always introduce
a push'less version.
2011-08-23 17:01:14 +03:00
Alon Levy
8fbc41b717 server/red_channel: renames to use _proc postfix consistently
rename types - we use _proc suffix mostly to indicate function pointer types,
use it for some function pointers that were missing it.

s/channel_handle_migrate_flush_mark/channel_handle_migrate_flush_mark_proc/
s/channel_handle_migrate_data_get_serial/channel_handle_migrate_data_get_serial_proc/
s/channel_handle_migrate_data/channel_handle_migrate_data_proc/
2011-08-23 17:01:14 +03:00
Alon Levy
f124b87a40 server/red_worker: explicitly include unistd and errno 2011-08-23 17:01:14 +03:00
Alon Levy
2bddc6e33c server/tests/test_playback: correctly use spice_server_playback_get_buffer
and spice_server_playback_put_samples. The former retrieves a buffer from a free
list with spice_server_playback_get_buffer, and should be used once via
spice_server_playback_put_samples. The tester previously reused the same buffer
a number of times.
2011-08-23 17:01:14 +03:00
Alon Levy
b88f233633 server/tests/basic_event_loop: multiple fixes
reuse common/ring.h
ignore SIGPIPE
fix handling of removed watches
2011-08-23 17:01:14 +03:00
Yonit Halperin
06c2e22fd9 server/red_worker.c: fix - locking the wrong mutex when releasing glz dict 2011-08-23 17:01:14 +03:00
Alon Levy
5c99a6da4f server/tests/test_display_base: fix compile 2011-08-23 17:01:14 +03:00
Alon Levy
70a5360e1c server/reds.h: explicitly include config.h 2011-08-23 17:01:14 +03:00
Hans de Goede
c5a291f454 server: Add a usbredir channel 2011-08-10 22:42:40 +02:00
Christophe Fergeau
3582adb989 mjpeg: add missing SPICE_BITMAP_FMT_RGBA
I forgot to handle SPICE_BITMAP_FMT_RGBA when mapping from
spice image formats to libjpeg-turbo colorspaces.
2011-08-02 11:13:49 +02:00
Christophe Fergeau
4b15555fbd mjpeg: fix libjpeg assertion
After the changes to add libjpeg-turbo support to spice-server mjpeg
compression code, it's relatively easy to hit an assertion from
libjpeg in spice-server about "too few scanlines transferred" when
the mjpeg streaming code triggers. This assertion brings down qemu,
which is bad :)

This is because when we first initialize the mjpeg encoder, we do:

stream_width = SPICE_ALIGN(src_rect->right - src_rect->left, 2);
stream_height = SPICE_ALIGN(src_rect->bottom - src_rect->top, 2);

stream->mjpeg_encoder = mjpeg_encoder_new(stream_width, stream_height);

and then when we iterate over the image scanlines to feed them to
libjpeg, we do:

const int image_height = src->bottom - src->top;
const int image_width = src->right - src->left;

for (i = 0; i < image_height; i++) {
    mjpeg_encoder_encode_scanline(...);
}
mjpeg_encoder_end_frame(...);

When stream_height is odd, the mjpeg_encoder will be created with
an height that is 1 more than the number of lines we encode. Then
libjpeg asserts when we tell it we're done with the compression
while it's still waiting for one more scanline.

Looking through git history, this rounding seems to be an artifact
from when we were using ffmpeg for the mjpeg encoding. Since
spicec and spicy (the latter needs a few fixes) can handle streams
with odd height/width, the best way to solve this issue is to stop
rounding up the height and width of the streams we create. This
even saves some bandwidth :)
2011-08-01 11:01:04 +02:00
Alon Levy
f0f44e2630 server/red_dispatcher: fix wrong resolution set for tablet
when changing resolutions due to the new async code paths the surface
creation command was kept by reference, and later, when the red_worker
signaled completion by calling async_complete the mouse mode was updated
using the reference. This caused the wrong values to be read resulting in wrong
resolutions set and a non working mouse pointer. Fix this by keeping a copy of
the surface creation command instead of a reference.

No bz. Found in testing.
2011-07-31 17:47:07 +03:00
Hans de Goede
608713b9ac Bump version in server/spice,h to 0.9.1
It is a bit early to bump, since a 0.9.1 release is not happening yet,
but this allows me to test if the vdagent SpiceCharInterface state callback
fixes are present or not in qemu code, and thus disabling the ugly vdagent
specific workaround from spice-qemu-char.c when compiling against a new
enough spice-server.
2011-07-26 14:16:07 +02:00
Hans de Goede
37a24a888f server: Don't call vdagent chardev state callback on client (dis)connect
See this long mail for the rationale for this:
http://lists.freedesktop.org/archives/spice-devel/2011-July/004837.html
2011-07-25 12:21:46 +02:00
Alon Levy
b371824269 server/smartcard: fix smartcard_channel_send_error
It was sending the wrong data, the memory right after the VCSMsgHeader
which was actually not where the data was.

Fixed by having the header and data (VSCError, 4 bytes of the error code)
embedded in the ErrorItem pipe item.
2011-07-22 22:36:12 +03:00
Christophe Fergeau
47684d2885 mjpeg: rename jpeg_mem_dest
jpeg_mem_dest is a public symbol in libjpeg8 so using it with
no prefix will cause symbol clashes. Rename it to spice_jpeg_mem_dest.
2011-07-22 16:53:56 +02:00
Christophe Fergeau
c12bafbc53 mjpeg_encoder: allocate "row" on demand
It's not used when we use jpeg-turbo colorspaces, so it's better
to allocate it when we know we'll need it rather than always
allocating it even if it won't be used.
2011-07-22 16:53:56 +02:00
Christophe Fergeau
3a433912e9 mjpeg_encoder: remove unused functions
After the refactoring to optionally use libjpeg-turbo, some
of the functions that mjpeg-encoder used to provide are now no
longer used. This commit removes them.
2011-07-22 16:53:56 +02:00
Christophe Fergeau
ad55230a2d mjpeg_encoder: use libjpeg-turbo extra colorspaces
When libjpeg-turbo is available, we can use the BGR and BGRX
colorspaces that it provides to avoid extra conversions of the
data we want to compress to mjpeg
2011-07-22 16:53:56 +02:00
Christophe Fergeau
b0cd4f4883 red_worker: use new mjpeg_encoder_encode_scanline API
The main point is to move the pixel conversion code into
the MjpegEncoder class to be able to make use libjpeg-turbo
additional pixel formats without the reds_worker code noticing.
2011-07-22 16:53:56 +02:00
Christophe Fergeau
d4305e16ad mjpeg_encoder: add mjpeg_encoder_get_bytes_per_pixel
Returns the number of bytes per pixel corresponding to the input
data format.
2011-07-22 16:53:56 +02:00
Christophe Fergeau
4275095ff9 mjpeg_encoder: add mjpeg_encoder_encode_scanline
This API is meant to allow us to move the pixel format conversion
into MjpegEncoder. This will allow us to be able to use the
additional pixel formats from libjpeg-turbo when available.
2011-07-22 16:53:56 +02:00
Christophe Fergeau
cacca4dce6 red_worker: simplify red_rgb_to_24bpp prototype
It takes a lot of arguments, "id" is unused, "frame" and
"frame_size" can be obtained from the "stream" argument, so
can get rid of 3 arguments to make things more readable.
2011-07-22 16:53:56 +02:00
Christophe Fergeau
1d808d31f4 mjpeg_encoder: rework output buffer allocation
When encoding a frame, red_worker passes an allocated buffer to
libjpeg where it should encode the frame. When it fails, a new
bigger buffer is allocated and the encoding is restarted from
scratch. However, it's possible to use libjpeg to realloc this
buffer if it gets too small during the encoding process. Make use
of this feature, especially since it will make it easier to encore
one line at a time instead of a full frame in subsequent commits.
2011-07-22 16:53:56 +02:00
Christophe Fergeau
22743bee9f red_worker: factor pixel conversion code
When encoding to mjpeg, the on screen data have to be converted
to 24bpp RGB since that's the format that libjpeg expects. Factor
as much code as possible for the 3 formats we handle.
2011-07-22 16:53:56 +02:00
Christophe Fergeau
e0e8d091ff fix make distcheck 2011-07-22 10:24:30 +02:00
Hans de Goede
765948d449 server: make sure we clear vdagent and update mouse mode on agent disconnect
The check this patch removes causes us to not set vdagent to NULL, nor
update the mouse mode when the guest agent disconnects when no client is
attached. Which leads to a non working mouse, and on agent reconnect a
"spice_server_char_device_add_interface: vdagent already attached" message
instead of a successful re-add of the agent interface .

hansg: Note this is commit 443994ba from the 0.8 branch, which I did
not forward port back then because it seemed unnecessary on master, but it
turns out that the (wrong) check was just hidden in another place on master.
2011-07-21 14:59:26 +02:00