Commit Graph

2034 Commits

Author SHA1 Message Date
Francois Gouget
2db59fef3a streaming: Let the video encoder manage the compressed buffer
This way the video encoder is not forced to use malloc()/free().
This also allows more flexibility in how the video encoder manages the
buffer which allows for a zero-copy implementation in both video
encoders.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
6dc0dadf8d streaming: Add VP8 support to the GStreamer video encoder
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Pavel Grunt
ce6113d838 replay: Add an option to change video codec 2016-06-14 17:04:40 +02:00
Francois Gouget
497fcbb0a3 streaming: Let the administrator pick the video encoder and codec
The Spice server administrator can specify the encoder and codec
preferences to optimize for CPU or bandwidth usage. Preferences are
described in a semi-colon separated list of encoder:codec pairs.
The server has a default preference list which can explicitly be
selected by specifying 'auto'.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
f4414af48c streaming: Check the client video codec capabilities
The server picks a codec supported by the client based on the following
new client capabilities:
 * SPICE_DISPLAY_CAP_MULTI_CODEC which denotes a recent client that
   supports multiple codecs. This capability is needed to not have to
   hardcode that MJPEG is supported. This makes it possible to write
   clients that don't support MJPEG.
 * SPICE_DISPLAY_CAP_CODEC_XXX, where XXX is a supported codec. Note
   that for now the server only supports the MJPEG codec.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
a697bd971b streaming: Add a GStreamer 1.0 MJPEG video encoder and use it by default
This introduces a pared down GStreamer-based video encoder to serve as
the basis for later enhancements.
In this form the new encoder supports both regular and sized streams
but lacks any rate control. It should still work fine if bandwidth is
sufficient such as on LANs.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
1b69198c4e streaming: Remove the width/height encode_frame() parameters
encode_frame() needs the QXL_DRAW_COPY operation's SpiceCopy.src_area
field anyway, so the width and height parameters were redundant.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
032cb0ce85 mjpeg: Use src_area as the authoritative source for the frame dimensions
Video frames correspond to QXL_DRAW_COPY operations where the frame area
is defined by the SpiceCopy.src_area field.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
618255168e streaming: Simplify is_next_stream_frame()
After the removal of Drawable::sized_stream, we no longer need to detect
if the stream changes size in is_next_stream_frame() so it can return a
boolean rather than a value from an enum.
2016-06-14 17:04:40 +02:00
Francois Gouget
47509b1e6e streaming: Remove unused detach_stream() argument
After the removal of Drawable::sized_stream, the last argument to
detach_stream() is no longer used.
2016-06-14 17:04:40 +02:00
Francois Gouget
42a5794845 streaming: Remove the Drawable.sized_stream field
Only red_marshall_stream_data() needs to know whether to send the frame
using a SpiceMsgDisplayStreamDataSized or a regular StreamData message.
So check whether we have a sized frame there and simplify the rest of
the code.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
28f2e425c4 streaming: Rework red_marshall_stream_data a bit
This code just refactors the function without doing any functional
changes. The actual changes will be in the next commit, and this will
make the next commit much more obvious.
2016-06-14 17:04:40 +02:00
Francois Gouget
709c9d71f1 streaming: Better check for sized frames
Usually the RedDrawable bbox dimensions match the src_area dimensions
so that checking that the bbox matches the stream's original dest_area
should be enough to determine if sized stream support is needed to
send the frame.
But making the bbox different could be used to have the scaling be
performed on the client side. So it's better not to assume the bbox and
src_area have the same dimensions.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Frediano Ziglio
81f3d44ee7 Move image_encoders_compress_glz to dcc-encoders.c
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-14 15:07:31 +01:00
Frediano Ziglio
cb8e832c87 Make dcc_compress_image_glz independent to DisplayChannelClient
Also rename to image_encoders_compress_glz

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-14 15:07:31 +01:00
Frediano Ziglio
108d11f4aa Move others glz fields to dcc-encoders
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-14 15:07:31 +01:00
Frediano Ziglio
41231aa4f8 Change dcc_encoders_init to take ImageEncoders instead of DisplayChannelClient
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-14 15:07:29 +01:00
Frediano Ziglio
b46984ed30 Move some glz fields to ImageEncoders
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-14 15:07:28 +01:00
Frediano Ziglio
86b702a7d0 Add a structure to hold ImageEncoders shared data
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-14 15:07:23 +01:00
snir sheriber
903c91cd30 LZ4 compression is now available at the Spicevmc channel
Compressed message type is CompressedData which contains compression
type (1 byte) followed by the uncompressed data size (4 bytes - exists
only if data was compressed) followed by the compressed data

If SPICE_USBREDIR_CAP_DATA_COMPRESS_LZ4 capability is available &&
data_size > COMPRESS_THRESHOLD && !AF_LOCAL data will be sent
compressed otherwise data will be sent uncompressed (also if
compression has failed)

Update the required protocol to 0.12.12

Signed-off-by: Snir Sheriber <ssheribe@redhat.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-13 23:12:59 +01:00
Frediano Ziglio
6e29efadbc Remove unused DCC_TO_WORKER macro
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-10 13:36:00 +01:00
Frediano Ziglio
9c5a8d5bce More encapsulation for dcc_encoders_free
Encoders function should not use DisplayChannelClient

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-10 09:15:24 +01:00
Frediano Ziglio
c2bc754559 Encapsulate zlib information in ImageEncoders structure
This change is less clean the other similar patches as zlib and
glz require more steps.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-10 09:15:17 +01:00
Frediano Ziglio
21a90ae986 Move image_encoders_compress_lz4 to dcc-encoders.c
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 22:50:12 +01:00
Frediano Ziglio
aa10a2ca2a Prepare to move dcc_compress_image_lz4 to ImageEncoders
Remove all DisplayChannel(Client) dependencies.
Rename function.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 22:50:10 +01:00
Frediano Ziglio
6d70d15d64 Encapsulate lz4 information in ImageEncoders structure
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 22:50:02 +01:00
Frediano Ziglio
25c0b204c4 Move image_encoders_compress_jpeg to dcc-encoders.c
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 22:32:50 +01:00
Frediano Ziglio
9d92a2edc8 Prepare to move dcc_compress_image_jpeg to ImageEncoders
Remove all DisplayChannel(Client) dependencies.
Rename function.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 22:32:48 +01:00
Frediano Ziglio
7b6cb37cc0 Encapsulate jpeg information in ImageEncoders structure
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 22:32:26 +01:00
Frediano Ziglio
cff7950aa3 Move image_encoders_compress_lz to dcc-encoders.c
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 22:11:30 +01:00
Frediano Ziglio
c5caf0dddd Prepare to move dcc_compress_image_lz to ImageEncoders
Remove all DisplayChannel(Client) dependencies.
Rename function.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 22:11:27 +01:00
Frediano Ziglio
a25182f060 Encapsulate lz information in ImageEncoders structure
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 22:11:20 +01:00
Frediano Ziglio
fa0a579a65 Move image_encoders_compress_quic to dcc-encoders.c
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 21:14:43 +01:00
Frediano Ziglio
645b8af35b Prepare to move dcc_compress_image_quic to ImageEncoders
Remove all DisplayChannel(Client) dependencies.
Rename function.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 21:12:43 +01:00
Frediano Ziglio
d7fb16c80e Encapsulate quic information in a new ImageEncoders structure
Start putting all encoding code into dcc-encoders.c.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-09 21:12:34 +01:00
Frediano Ziglio
2d34002e59 Move marshalling code from dcc-encoders to dcc-send
No reasons why dcc-encoders should know about marshalling.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-09 06:55:43 +01:00
Frediano Ziglio
fa4eb13f7b Add compress_buf_free function
dcc-encoders should be in change of allocate and free the structure
don't put internal assumptions (which functions are used for memory
management) in different files.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-09 06:55:40 +01:00
Frediano Ziglio
aed25d8407 record: Use spice_get_monotonic_time_ns instead of stat_now(CLOCK_MONOTONIC)
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-08 15:27:55 +01:00
Frediano Ziglio
cf4b289f29 record: Use proper type for timestamp
Use red_time_t to make sure timestamp has the right precision even
on 32 bit systems.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-08 15:27:48 +01:00
Frediano Ziglio
69628ea137 improve primary surface parameter checks
Primary surface, as additional surfaces, can be used to access
host memory from the guest using invalid parameters.

The removed warning is not enough to prevent all cases. Also a warning
is not enough to stop an escalation to happen.
The red_validate_surface do different checks to make sure surface
request is valid and not cause possible buffer/integer overflows:
- format is valid;
- width is not large to cause overflow compared to stride;
- stride is not -2^31 (a number which negate is still <0);
- stride * height does not overflow.

This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1312980.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-08 09:59:54 +01:00
Frediano Ziglio
790d8f3e53 factor out red_validate_surface function to validate surface parameters
Make possible to reuse it outside red-parse-qxl.c.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-08 09:59:31 +01:00
Frediano Ziglio
a051a4d884 Move dcc glz field initialization into dcc_new
There is no reason to initialize these fields in two different places.
Note that an usage between dcc_new and the function where these
field were initialised would have resulted in a crash.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-07 23:09:45 +01:00
Frediano Ziglio
ddd3b286ad record: Make red_record_cursor_cmd static
This function is never used outside this compile unit.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-07 22:43:48 +01:00
Frediano Ziglio
2b58c60bb1 replay: Handle cursor commands
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-07 22:43:30 +01:00
Victor Toso
9df00ebdc8 char-device: fix mismatch of client tokens
As the tokens counter were not being reset you could enter in a
situation where client thinks it has more tokens then server which
would eventually lead to client's disconnection from 0c5eca97f1
onwards (before it was crashing).

It is easy to check the above situation if you track the amount of
tokens you have in the client and simply kill and restart the agent
while doing some file transfer: the client could reach more then 13
tokens which should not really be possible.

Based on patch from Frediano Ziglio <fziglio@redhat.com>

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-07 18:06:31 +01:00
Frediano Ziglio
b46fcbb3ab replay: Load cursor commands
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-06 09:29:12 +01:00
Frediano Ziglio
52f9850be8 worker: Record cursor commands
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-06 09:29:12 +01:00
Frediano Ziglio
3f4ba5e5f5 record: Support cursor commands
Use red_record_cursor_cmd to be able to record cursor commands.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-06 09:28:39 +01:00
Frediano Ziglio
18c99e008f avoid integer underflow under 32 bit architectures
The segment_size computation on 32 bit can lead to big numbers which
can lead to negative offset. Let'ss avoid to underrun the buffer,
as it's not checked.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Fabiano Fidêncio <fidencio@redhat.com>
2016-06-06 08:58:52 +01:00
Frediano Ziglio
3dd93a1f5f fix integer overflows in red_get_path
Use 64 bit arithmetic to avoid overflows.
The multiplication between count and a constant can overflow.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Fabiano Fidêncio <fidencio@redhat.com>
2016-06-05 09:44:42 +01:00