[Spice-devel] [spice v2] gstreamer-encoder: Return the average frame size as a 32 bit int
Francois Gouget
fgouget at codeweavers.com
Tue May 21 00:30:19 UTC 2019
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 at codeweavers.com>
---
In get_min_playback_delay() I opted for the cast approach as this makes
what happens clearer. I deemed the assignment (uint32_t) unnecessary
though.
server/gstreamer-encoder.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/server/gstreamer-encoder.c b/server/gstreamer-encoder.c
index 0ff1201a9..0101b36fa 100644
--- a/server/gstreamer-encoder.c
+++ b/server/gstreamer-encoder.c
@@ -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);
--
2.20.1
More information about the Spice-devel
mailing list