gstreamer-encoder: Return the average frame size as a 32 bit int

It makes no sense to expect average frame sizes anywhere close to 2GB.
But then make sure to avoid arithmetic overflows.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
Francois Gouget 2019-05-21 02:30:19 +02:00 committed by Frediano Ziglio
parent cfe98800a0
commit ba4bcd5174

View File

@ -396,7 +396,7 @@ static uint64_t get_average_encoding_time(SpiceGstEncoder *encoder)
return encoder->stat_duration_sum / count;
}
static uint64_t get_average_frame_size(SpiceGstEncoder *encoder)
static uint32_t get_average_frame_size(SpiceGstEncoder *encoder)
{
uint32_t count = encoder->history_last +
(encoder->history_last < encoder->stat_first ? SPICE_GST_HISTORY_SIZE : 0) -
@ -520,8 +520,8 @@ static uint32_t get_min_playback_delay(SpiceGstEncoder *encoder)
* an I frame) and an average frame. This also takes into account the
* frames dropped by the encoder bit rate control.
*/
uint64_t size = get_maximum_frame_size(encoder) + get_average_frame_size(encoder);
uint32_t send_time = MSEC_PER_SEC * size * 8 / encoder->bit_rate;
uint32_t size = get_maximum_frame_size(encoder) + get_average_frame_size(encoder);
uint32_t send_time = ((uint64_t)MSEC_PER_SEC * 8) * size / encoder->bit_rate;
/* Also factor in the network latency with a margin for jitter. */
uint32_t net_latency = get_network_latency(encoder) * (1.0 + SPICE_GST_LATENCY_MARGIN);