Commit Graph

44 Commits

Author SHA1 Message Date
Frediano Ziglio
454e521b17 reuse red_get_monotonic_time function
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2015-11-23 11:07:33 +00:00
Francois Gouget
f2c8609985 server: Hide the MJPEG encoder internals from red_worker.c
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2015-10-30 15:35:47 +01:00
Francois Gouget
3708bf9cf0 server: Move the MJPEG encoder functions to mjpeg_encoder.c
Note that this requires some adjustments to the encode_frame()
parameters to avoid red_worker-specific types.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2015-10-30 15:35:47 +01:00
Francois Gouget
fd451860df server: Move mjpeg_encoder_new() to the end of mjpeg_encoder.c
This also allows getting rid of a couple of forward definitions.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2015-10-30 15:35:47 +01:00
Frediano Ziglio
90a08ebae8 remove small leak in MJPEG code
cinfo.dest is allocated in spice_jpeg_mem_dest but never freed.
Note that jpeg_destroy_compress does not free this field as is
supposed to be a buffer provided by jpeg caller.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-23 12:10:23 +01:00
Christophe Fergeau
31eb8eeecb syntax-check: Don't use tabs for indentation 2015-10-19 14:25:36 +02:00
Victor Toso
bdeef8b292 mjpeg and jpeg encoder: fix alignment warnings
As the input line could be uint8_t*, uint16_t* or uint32_t*, changing
the default from uint8_t* to void* seems the correct choice to deal with
upcasting warnings.

Regarding chunks->data allocation, I quote Frediano explantion:
"Lines came from spice_bitmap_get_line. This function assume that bitmap
data is split among chunks each containing some lines
(always full lines). If chunk->data is allocated using malloc or similar
SHOULD (not 100% sure) be 4 bytes aligned so in our cases
(8, 16, 24 or 32 bit images) should be aligned enough.

All the casts unfortunately came from the fact we compute based on
pixel bytes to make it generic so we use uint8_t*."

and

"Looking at code looks like these chunks came from the virtual machine.
So the question is... why should the virtual machine give use some
not-pixel align data?
I would put a large comment to state that we assume VM send aligned
data, would be stupid for the VM to not align it!"

clang output:
jpeg_encoder.c:109:26: error: cast from 'uint8_t *'
(aka 'unsigned char *') to 'uint16_t *' (aka 'unsigned short *')
increases required alignment from 1 to 2 [-Werror,-Wcast-align]
  uint16_t *src_line = (uint16_t *)line;
                       ^~~~~~~~~~~~~~~~

jpeg_encoder.c:144:26: error: cast from 'uint8_t *'
(aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *')
increases required alignment from 1 to 4 [-Werror,-Wcast-align]
  uint32_t *src_line = (uint32_t *)line;
                       ^~~~~~~~~~~~~~~~

mjpeg_encoder.c:260:23: error: cast from 'uint8_t *'
(aka 'unsigned char *') to 'uint16_t *' (aka 'unsigned short *')
increases required alignment from 1 to 2 [-Werror,-Wcast-align]
  uint16_t pixel = *(uint16_t *)src;
                    ^~~~~~~~~~~~~~~
2015-08-20 11:22:59 +01:00
Francois Gouget
aa22138d05 server: Remove the rate_control_is_active field from MJpegEncoder.
It is redundant with the corresponding callbacks.
2015-06-29 18:04:12 +02:00
Francois Gouget
f017d7a421 mjpeg: Convert rate control checks to asserts in encoder
The checks would lead the reader to think these functions can be called
when bit rate control is off when in fact they are only called when it
is active.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
2015-06-22 19:47:58 +02:00
Jonathon Jongsma
284cca2a5e Fix assert in mjpeg_encoder_adjust_params_to_bit_rate()
If mjpeg_encoder_reset_quality() is called with the same quality as currently
set, it will not reset last_enc_size but not reset num_recent_enc_frames,
violating some assumptions in _adjust_params_to_bit_rate(). To avoid aborting
the server, simply return early from this function.

Resolves: rhbz#1086820
2014-05-30 13:45:02 -05:00
소병철
3cb746329e Use PRI macros in printf to keep compatibility between 32/64bit system
gcc's some integer type definitions are different between 32/64bit system.
This causes platform dependency problem with printf function. However,
we can avoid this problem by using PRI macros that supports platform
independent printf.
2014-05-15 14:45:58 +02:00
Christophe Fergeau
67be56ad8a mjpeg: Don't warn on unsupported image formats
When trying to start mjpeg compression mode, mjpeg_encoder_start_frame()
tests the image format as its only able to compress 24/32bpp images. On
images with lower bit depths, we return MJPEG_ENCODER_FRAME_UNSUPPORTED to
indicate this is not a format we can compress. However, this return goes
with a spice_warning("unsupported format"). As the rest of the code can
cope with this unsupported format by not doing mjpeg compression, it's
nicer to downgrade this spice_warning() to spice_debug().

This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1070028
2014-03-13 17:13:27 +01:00
Yonit Halperin
648117544f red_worker: improve stream stats readability and ease of parsing
also added start/end-bit-rate and avg-quality to the final stream stats.
2013-06-24 15:23:34 -04:00
Yonit Halperin
a9f1a4b75d mjpeg_encoder: add mjpeg_encoder_get_stats 2013-06-24 15:23:34 -04:00
Yonit Halperin
1d760551ec collect and print video stream statistics 2013-04-22 16:30:55 -04:00
Yonit Halperin
4c79f325e2 server/red_worker.c: use the bit rate of old streams as a start point for new streams
mjpeg_encoder modify the initial bit we supply it, according to the
client feedback. If it reaches a bit rate which is higher than the
initial one, we use the higher bit rate as the new bit rate estimation.
2013-04-22 16:30:55 -04:00
Yonit Halperin
622d7159c2 mjpeg_encoder: add stream warmup time, in which we avoid server and client drops
The stream starts after lossless frames were sent to the client,
and without rate control (except for pipe congestion). Thus, on the beginning
of the stream, we might observe frame drops on the client and server side which
are not necessarily related to mis-estimation of the bit rate, and we would
like to wait till the stream stabilizes.
2013-04-22 16:30:53 -04:00
Yonit Halperin
ff1bde1d81 mjpeg_encoder: keep the average observed fps similar to the defined fps
The actual frames distribution does not necessarily fit the
condition "at least one frame every (1000/rate_contorl->fps)
milliseconds".
For keeping the average frame rate close to the defined fps, we
periodically measure the current average fps, and modify
rate_control->adjusted_fps accordingly. Then, we use
(1000/rate_control->adjusted_fps) as the interval between the
frames.
2013-04-22 16:30:53 -04:00
Yonit Halperin
6f883d0eb5 mjpeg_encoder: move the control over frame drops to mjpeg_encoder 2013-04-22 16:30:53 -04:00
Yonit Halperin
44ce87b55a mjpeg_encoder: update the client with estimations for the required playback latency
The required client playback latency is assessed based on the current
estimation of the bit rate, the network latency, and the encoding size
of the frames. When the playback delay that is reported by the client
seems too small, or when the stream parameters change, we send the
client an updated playback latency estimation.
2013-04-22 16:30:53 -04:00
Yonit Halperin
3bbde4b3a6 mjpeg_encoder: modify stream bit rate based on server side pipe congestion
Downgrading stream bit rate when the input frame rate in the server
exceeds the output frame rate, and frames are being dropped from the
output pipe.
2013-04-22 16:30:53 -04:00
Yonit Halperin
b490635130 mjpeg_encoder: adjust the stream bit rate based on periodic client feedback
mjpeg_encoder can receive periodic reports about the playback status on
the client side. Then, mjpeg_encoder analyses the report and can
increase or decrease the stream bit rate, depending on the report.
When the bit rate is changed, the quality and frame rate of the stream
are re-evaluated.
2013-04-22 16:30:51 -04:00
Yonit Halperin
2025494af5 mjpeg_encoder: re-configure stream parameters when the frame's encoding size changes
If the encoding size seems to get smaller/bigger, re-evaluate the
stream quality and frame rate.
2013-04-22 11:45:59 -04:00
Yonit Halperin
f68b539d70 mjpeg_encoder: configure mjpeg quality and frame rate according to a given bit rate
Previously, the mjpeg quality was always 70. The frame rate was
tuned according to the frames' congestion in the pipe.
This patch sets the quality and frame rate according to
a given bit rate and the size of the first encoded frames.

The following patches will introduce an adaptive video streaming, in which
the bit rate, the quality, and the frame rate, change in response to
different parameters.

Patches that make red_worker adopt this feature will also follow.
2013-04-22 11:45:59 -04:00
Yonit Halperin
d0a57ac22b server/mjpeg_encoder: realloc encoder->row, when a wider frame is given
Fix crashes when there are sized wider frames in the stream, and we are
linked with libjpeg.

Related : rhbz#813826
Resolves: rhbz#820669
2012-05-16 08:55:11 +03:00
Yonit Halperin
c211774422 server/mjpeg_encoder: fix wrong size assigned to dest_len
It should have been the allocated size and not the occupied one.
This led to a lot of unnecessary allocations and deallocations.
2012-05-10 14:06:59 +03:00
Yonit Halperin
fecc1e3d4d server/mjpeg_encoder: Fix memory leak for the inital output buffer given for each frame 2012-05-10 14:01:04 +03:00
Yonit Halperin
318dce4abb server/red_worker.c/video: add support for frames of different sizes
rhbz #813826

When playing a youtube video on Windows guest, the driver sometimes(**) sends
images which contain the video frames, but also other parts of the
screen (e.g., the youtube process bar). In order to prevent glitches, we send these
images as part of the stream, using SPICE_MSG_DISPLAY_STREAM_DATA_SIZED.

(**) It happens regularly with the you tube html5 player. With flash,
it occurs when moving the cursor in the player area.
2012-05-03 13:07:01 +03:00
Marc-André Lureau
b34fd7432d Use the spice-common logging functions
It will abort by default for critical level messages. That behaviour
can be tuned at runtime.
2012-03-25 19:00:00 +02:00
Daniel P. Berrange
faf0947ebb Remove useless if() before free()
The free() function allows NULL to be passed in, so any
code which puts a if() before free() is wasting time
2012-01-13 18:11:58 +02:00
Alon Levy
2548cd713d server/mjpeg_encoder: use size_t * consistently
fix another 64 bit-ism. unsigned long != size_t in general.
2011-11-10 16:29:19 +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
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
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
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
e17767e892 add missing static 2011-05-03 14:44:11 +02:00
Christophe Fergeau
78c1465ed3 add #include <config.h> to all source files
When using config.h, it must be the very first include in all source
files since it contains #define that may change the compilation process
(eg libc structure layout changes when it's used to enable large file
support on 32 bit x86 archs). This commit adds it at the beginning
of all .c and .cpp files
2011-05-03 14:44:10 +02:00
Alexander Larsson
c97116aeb9 Relicense everything from GPL to LGPL 2.1+ 2010-04-13 22:22:15 +02:00
Alexander Larsson
288a9ad03f Use fast DCT method for better jpeg compression performance 2010-04-12 20:54:35 +02:00
Alexander Larsson
de4306af33 Initialize _kill_mark so we don't get spurious valgrind warnings 2010-04-08 17:09:32 +02:00