Commit Graph

2082 Commits

Author SHA1 Message Date
Pavel Grunt
a68c821164 Fix -Werror=format with DEBUG_ENCODE
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-07-01 14:00:37 +02:00
Pavel Grunt
3a06113ce4 Do not force computing streaming statistic
Let user to define STREAM_STATS to enable them

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-07-01 14:00:32 +02:00
Pavel Grunt
fb1b30a0e5 Fix compiling with defined DEBUG_DISPATCHER
setup_dummy_signal_handler was used before declared

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-07-01 13:59:36 +02:00
Frediano Ziglio
3b2fd86e8a Constify spice_server_char_device_recognized_subtypes
Users should not change the list of supported subtypes.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-29 08:09:03 +01:00
Frediano Ziglio
c70b2067a9 Constify event_loop_core
Was used as write variable only for testing.
Avoid usage of not constant globals.
Making globals constants avoid future race condition
usages.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-29 08:08:54 +01:00
Frediano Ziglio
6f388ef65a Protect globals servers variable with a mutex
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-22 16:48:12 +01:00
Frediano Ziglio
2896e2eed9 Make video_encoder_procs constant
This is not going to be modified.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-22 15:45:30 +01:00
Frediano Ziglio
356f819e50 Initialise OpenSSL just once
Avoid multiple initializations of this library.
Also initialize using thread safe code to avoid possible race
conditions.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-06-22 15:36:25 +01:00
Frediano Ziglio
e0a0ede078 Make spice_server_char_device_recognized_subtypes_list static
Not used outside the compile unit.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-22 15:30:58 +01:00
Frediano Ziglio
770b7c8e25 Make servers global static
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-22 08:03:02 +01:00
Frediano Ziglio
48cb6a295b Use proper types in compress_send_data_t
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-20 21:51:06 +01:00
Frediano Ziglio
67981ff7f6 Make RedGlzDrawable typedef private
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-17 20:59:19 +01:00
Frediano Ziglio
0434e66a37 Destroy pthread structures
Current Linux pthread implementation should use futex so there should
be no leak but calling destroy avoid possible future leaks.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-17 20:59:19 +01:00
Frediano Ziglio
e6ed1840a1 Rename dcc-encoders.[ch] to image-encoders.[ch]
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-17 15:28:30 +01:00
Frediano Ziglio
a27eb96811 Reduce header dependency
Avoid dependencies from RedChannel stuff.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-17 10:57:07 +01:00
Frediano Ziglio
e281703af8 Remove dependency from dcc-encoders to Drawable
Encoding image requires a RedDrawable (where the data is stored) and
a Ring where to store information to free Glz structures.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-17 10:57:05 +01:00
Frediano Ziglio
a5eae2a0e9 Use new GlzImageRetention instead of accessing Drawable internals
Remove some coupling, we mainly need to store a list of RedGlzDrawables.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-17 10:57:00 +01:00
Frediano Ziglio
0628ce6228 Make GlzSharedDictionary structure private in dcc-encoders.c
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-16 21:03:31 +01:00
Frediano Ziglio
141bcd1eec Do not access ImageEncoders internal to lock/unlock glz encoding
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-16 21:03:22 +01:00
Frediano Ziglio
cc26a9a91e Better encapsulation for image_encoders_compress_glz call
Do not access too much encoders data.
Slightly different as now if glz is frozen lz compression is used.
Glz is frozen only during migration.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-16 21:03:05 +01:00
Frediano Ziglio
2d1c724301 Rename encoder_globals to encoder_shared_data
Was missing due to a mistake.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-16 21:02:54 +01:00
Frediano Ziglio
fa4d204819 Remove unused free_compress_bufs field from DisplayChannel
RedCompressBuf are no longer pooled.
The usage was removed in 92d9b782bd.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-16 15:46:16 +01:00
Eduardo Lima (Etrunko)
d7fb7b0b36 Move lz4-encoder.[ch] to conditional block in Makefile.am
Let's follow the 'standard' for optional components. This commit also
drops (now) unecessary #ifdef USE_LZ4 from lz4-encode.c, as the decision
to build this file is now made in Makefile.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-16 11:16:01 -03:00
Frediano Ziglio
7b4322ce0f Make video-encoder.h self independent
gpointer definition was not included causing the header to fails to
compile if included first.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-16 14:14:04 +01:00
Eduardo Lima (Etrunko)
77c062f0c0 Fix set but not used variable warning
Introduced by commit 903c91cd30, this
variable is used only for LZ4 code. Move the declaration to the proper
block of code.

Build log:

spicevmc.c: In function 'handle_compressed_msg':
spicevmc.c:346:14: error: variable 'decompressed' set but not used [-Werror=unused-but-set-variable]
     uint8_t *decompressed;
                   ^

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-16 08:29:39 -03:00
Eduardo Lima (Etrunko)
33b45af275 Fix build for systems without LZ4 dependency installed
This was introduced by commit 903c91cd30.
To fix it, we simply protect the try_compress_lz4 function with proper
ifdef guards.

Build log:

spicevmc.c: In function 'try_compress_lz4':
spicevmc.c:143:5: error: implicit declaration of function 'LZ4_compress_default' [-Werror=implicit-function-declaration]
     compressed_data_count = LZ4_compress_default((char*)&msg_item->buf,
     ^
spicevmc.c:143:5: error: nested extern declaration of 'LZ4_compress_default' [-Werror=nested-externs]

spicevmc.c: At top level:
spicevmc.c:124:24: error: 'try_compress_lz4' defined but not used [-Werror=unused-function]
 static RedVmcPipeItem* try_compress_lz4(SpiceVmcState *state, int n, RedVmcPipeItem *msg_item)
                        ^

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-16 08:29:20 -03:00
Frediano Ziglio
e3419b0e12 Remove message_buf from EncoderData
This buffer was just written and then used, no reason to store into
a more persistent structure.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-15 23:17:43 +01:00
Frediano Ziglio
a46045a141 Make red_glz_drawable_free() static
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-15 15:12:34 +01:00
Frediano Ziglio
e92afe539b Encapsulate some data in dcc-encoders
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-15 15:12:20 +01:00
Pavel Grunt
58ed103636 Fix missing prototypes
Signed-off-by: Pavel Grunt <pgrunt@redhat.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-15 15:02:42 +01:00
Pavel Grunt
6a131e2cd1 Remove unused reds_expects_link_id
Not needed since f683815ad5

Signed-off-by: Pavel Grunt <pgrunt@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-15 14:47:44 +01:00
Jonathon Jongsma
6bfeb5501c Rename image_encoders_free_glz_drawable()
Rename this function to red_glz_drawable_free() and remove the
ImageEncoders argument since the RedGlzDrawable already holds a pointer
to the ImageEncoders structure

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-15 09:31:38 +01:00
Jonathon Jongsma
a6314d1782 Rename image_encoders_free_glz_drawable_instance()
Rename this function to glz_drawable_instance_item_free() and remove the
ImageEncoders argument since the RedGlzDrawable already holds a pointer
to the ImageEncoders structure.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-15 09:20:40 +01:00
Frediano Ziglio
afbad7231e Make image_encoders_freeze_glz() static
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-15 09:05:47 +01:00
Frediano Ziglio
b61c1ce030 Encapsulate code to save glz state
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-15 08:43:45 +01:00
Frediano Ziglio
49e2899ea8 Change RedGlzDrawable::drawable from pointer to boolean
The field was used just as a flag.
This has the advantage to make clear to not use the pointer as we don't
have ownership.
Also makes the structure a bit smaller.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-15 08:33:37 +01:00
Frediano Ziglio
9939496a93 Better encoders encapsulation
Avoid to access some fields from dcc.c

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-15 08:22:21 +01:00
Frediano Ziglio
49273f2011 Encapsulate dcc_release_glz
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-15 08:18:07 +01:00
Francois Gouget
0503cd3d61 streaming: Add support for GStreamer 0.10
configure will use GStreamer 1.0 if present and fall back to
GStreamer 0.10 otherwise.
ffenc_mjpeg takes its bitrate as a long so extend set_gstenc_bitrate().

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
b64b9e5657 streaming: Dynamically adjust the GStreamer encoder bitrate if possible
This is faster and lets the encoder leverage past bitrate shaping
history to attain the target faster.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
fc68e2e5ba streaming: Respect the GStreamer encoder's valid bit rate range
GObject returns an error instead of clamping if given an out of range
property value.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
c6f6471eb8 streaming: Give up after a while if GStreamer cannot handle the video
This typically happens when sending very small frames (less than
16 pixels in one dimension) to the x264enc encoder.
This avoids repeatedly wasting time rebuilding the pipeline.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
ef6d6b063d streaming: Adjust the frame rate based on the GStreamer encoding time
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
669d7090ca streaming: Adjust the GStreamer encoder bit rate to the network
The video encoder uses the client reports and/or notifications of
server frame drops as its feedback mechanisms. In particular it keeps
track of the maximum video margin and reduces the bit rate whenever the
margin goes below certain thresholds or decreases too sharply.
It uses these to figure out the lowest bit rate that causes negative
feedback, and the highest bit rate that allows a return to positive
feedbacks. It then works to narrow this range and settles on the lower
end once the spread has gone below a given threshold.
All the while it monitors the effective bit rate to ensure the target
bit rate does not grow significantly beyond what the GStreamer encoder
will produce: this avoids target bit rate 'bubbles' which would
invariably be followed by a bit rate crash with accompanying frame loss.
As soon as the network feedback indicates a significant degradation the
bit rate is lowered to minimize the risk of frame loss and/or long
freezes.
It also relies on the existing shaping of the GStreamer output bit rate
to minimize the pipeline reconfigurations.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
4f04c9ac79 streaming: Shape the bit rate of the GStreamer codecs output
The GStreamer codecs don't follow the specified bit rate very closely:
they can decide to exceed it for ten seconds or more if they consider
the scene deserves it. Such long bursts are enough to cause network
congestion, resulting in many lost frames which cause significant
display corruption.
So the GStreamer video encoder now uses a short 300ms virtual buffer
to shape the compressed video output and ensure we don't exceed the
target bit rate for any significant length of time.
It could instead rely on the network feedback (when available) to lower
the bit rate. However frequent GStreamer bit rate changes lower the
overall compression level and also result in a lower average bit rate,
both of which result in lower video quality.
The GStreamer video encoder also keeps track of the encoded frame size
so it can gather statistics and call update_client_playback_delay()
with accurate information and also annotate the client report debug
traces with the corresponding bit rate information.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
a21ec4e251 streaming: Add h264 support to the GStreamer video encoder
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
49036e6aae streaming: Avoid copying the input frame in the GStreamer encoder
Note that we can only avoid copies for the first 1 Mpixels or so.
That's because Spice splits larger frames into more chunks than we can
fit GstMemory fragments in a GStreamer buffer. So if there are more
pixels we will avoid copies for the first 3840 KB and copy the rest.
Furthermore, while in practice the GStreamer encoder will only modify
the RedDrawable refcount during the encode_frame(), in theory the
refcount could be decremented from the GStreamer thread after
encode_frame() returns.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
Francois Gouget
a6795d1971 streaming: Handle and recover from GStreamer encoding errors
If an error occurs for whatever reason (e.g. codec not supporting odd
frame sizes), the GStreamer pipeline will drop the current buffer,
causing the encoder to be stuck waiting for the sample. So this patch
tracks error notifications and ensures we don't wait for a sample if
none will come.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2016-06-14 17:04:40 +02:00
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