[Spice-devel] [spice v6] server: Provide a framerate estimate based on the initial frames

Francois Gouget fgouget at codeweavers.com
Thu Dec 10 03:16:19 PST 2015


On Thu, 10 Dec 2015, Victor Toso wrote:
[...]
> > > +    drawable->creation_time = drawable->first_frame_time =red_get_monotonic_time();
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
> need extra space!

Yes. I fixed it locally but I'm hesitant to resubmit just for that.
In the worst case it will be fixed with the rename to 
spice_get_monotonic_ns().


[...]
> > > +    /* Provide an fps estimate the video encoder can use when initializing
> > > +     * based on the frames that lead to the creation of the stream. Round to
> > > +     * the nearest integer, for instance 24 for 23.976.
> > > +     */
> > > +    uint64_t duration = drawable->creation_time - drawable->first_frame_time;
> > > +    if (duration > (uint64_t)drawable->frames_count * 1000 * 1000 * 1000 / MAX_FPS) {
> > > +        stream->input_fps = ((uint64_t)drawable->frames_count * 1000 * 1000 * 1000 + duration / 2) / duration;
> 
> Why + (duration/2) ? This would be the same as [ x/2 + 1/2 ] so I'm
> guessing it is for the rounding, right?

Yes, it's to round to the nearest integer.
The general principle is that if your division truncates, then 
round_to_nearest( ((double)x) / n ) = (x + n/2) / n

I'll also note that this is a case where we want the most accurate 
estimate of the fps so round to nearest makes sense.

-- 
Francois Gouget <fgouget at codeweavers.com>


More information about the Spice-devel mailing list