<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 18 October 2013 08:30, Pekka Paalanen <span dir="ltr"><<a href="mailto:ppaalanen@gmail.com" target="_blank">ppaalanen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><div>
<br>
On Thu, 17 Oct 2013 21:34:02 +0100<br>
James Courtier-Dutton <<a href="mailto:james.dutton@gmail.com" target="_blank">james.dutton@gmail.com</a>> wrote:<br>
<br>
> The key point I was trying to make is that the media player needs to be<br>
> able to predict when frames will be displayed.<br>
<br>
</div>Yes, the *player* needs to be able to predict, and we aim to give it the<br>
historical information to do exactly that.<br></blockquote><div>Yes, the "player" needs <br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><br>
> All its prediction calculations will be based on a fixed scanout rate.<br>
<br>
</div>Why only fixed scanout rate? Why can't you dynamically adapt to the<br>
latency between requested and realized presentation time, over time?<br></blockquote><div><br></div><div>Conceptually, the player is not requesting a presentation time. It can't. The scanout does not change to match the player.<br>
</div><div>The player predicts that a particular frame scanout will happen at time X, and the player then decides what it wants displayed for that scanout.<br></div><div>So what we need is:<br></div><div>1) Predictable scanout times. <- We can get this from the historical callback timestamps as you mentioned.<br>
</div><div>2) A Deterministic way to ensure that the frame the player wants to appear at a particular scanout does actually appear then.<br></div><div>It is this second point that I am not sure we have yet.<br></div><div>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
There are lots of ways to predict based on past measurements and<br>
taking account uncertainty, Kalman filter is the first one to come<br>
my mind, but I guess there are better methods for meeting a<br>
deadline/cycle kind of scenarios.<br></blockquote><div>Agreed.<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>I don't think drivers predict anything, do they? Right now, drivers<br></div>
only tell you what happened (the presentation timestamp), if even that.<br>
AFAIK, most popular drivers do not currently even have queues. You can<br>
schedule *one* page flip at a time, and you cannot even cancel that<br>
later if you wanted to, from what I've heard.<br></blockquote><div>The current situation is not ideal, so players can only achieve best effort.<br></div><div>But when you can get deterministic frame display, the player can do a much better job.<br>
</div><div>I difference is noticeable to the person watching. The artifact that is most noticeable is jitter, caused by missing a scanout or the wrong frame appearing on the wrong scanout.<br><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
In the future I'm hoping we would have drivers where you could actually<br>
queue buffers for hardware overlays, so the buffer queue does not need<br>
to live completely in the userspace on the mercy of scheduling hickups<br>
and system load. But even then I can't imagine drivers doing any<br>
predictions, they would just try to meet requested presentation times.<br>
If drivers predict, they will do it internally only to make sure the<br>
requested presentation time is realized. *How* it is realized is a good<br>
question (never show before the requested time? or make sure is on<br>
screen at the requested time? or...)<br></blockquote><div>For low power applications, like smart phones with a separate APU and GPU, there is a possibility to send say 10 frames from the APU to the GPU. The APU can then sleep for 10 frames, while the GPU outputs the frames at all the correct scanouts. The APU then wakes up to gather the next 10 frames.<br>
</div><div>So, in this scenario, the API between the APU and GPU would need to be able request the previous 10 frame scanout times stamps, because an individual frame callback would not work because the APU was sleeping.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
The compositor is similar to drivers in my opinion. If it tries to<br>
predict something, it will only do that to be able to meet the<br>
requested presentation times. Who knows, maybe predictions in the<br>
compositor and drivers would actually make prediction in the clients<br>
worse by introducing more variables.<br>
<br>
In any case, I do not see the compositor being responsible for<br>
predicting times for clients' buffers. In my view, it is clients'<br>
resposibility to predict in any way they want, based on hard facts of<br>
the past given by the compositor and drivers. The client (player) is the<br>
only one knowing everything relevant, like the original video frame rate<br>
and audio position, and whether it wants to prefer showing frames early,<br>
late, when to skip, etc. <br></blockquote><div>If you are mentioning the compositor, a nice feature would be to be able to send the video stream to the compositor, then also an overlay to be mixed with the video stream just before display. Both the video stream and the overlay need a way to make sure they are displayed at the correct scanout.<br>
</div><div>There is also a need for another overlay to not need to be deterministic.<br></div><div>E.g. 1 Video stream. One overlay stream for subtitles. <- need to be in sync for eg. karaoke.<br></div><div>second overlay for non-deterministic item such as menus, program guide overlay on video etc.<br>
</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
If you are concerned about video start, where you do not yet have<br>
measurements available to predict from, then yeah, all you have is the<br>
current monitor framerate. But after the first frame has been<br>
presented, you get the first presentation timestamp, which should allow<br>
you to adapt to the phase of the scanout cycle. Right?<br></blockquote><div>So long as there has not been a frame rate change recently, historical data should be available.<br></div><div>If you are changing the frame rate at the very start of the video, you can normally wait a few frames before starting the video, allowing the display to settle.<br>
<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
And of course repeat that "coarse calibration" every time scanout rate<br>
(monitor refresh rate) changes.<br>
<br>
While the presentation loop is running, you could theoretically adjust<br>
the gap between requested and realized presentation timestamps. If the<br>
gap gets too small and the frames start to miss their intended scanout<br>
cycle, you see it in the realized timestamps, and can back off. It is a<br>
trial and error, but I'm hoping it will take only a few frames in the<br>
beginning to reach a steady state and lock the gap length, after which<br>
the predictor in the player should be in sync.<br></blockquote><div>In ALSA (Linux sound) there is a concept of "delay".<br></div><div>This is a measure of "If I submit the sound sample now, when will it be played?" I.e. It will be played in 20ms. The returned value depends on the amount of sound samples already queued, but not yet "SoundOut".<br>
</div><div>For Video, this would be "If I submit a frame now, which scanout will it be displayed on?". Can we get an answer for this question through some API?<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><br>
> Also, If buffer2 has T=200. What is the 200 being compared to in order to<br>
> decide to display the buffer or not?<br>
> This will not be the timestamp on the presentation callback will it?<br>
<br>
</div>Yes, it will, if you mean clock domains. There needs to be a way to have<br>
all timestamps related to frames in the same clock domain, of course. An<br>
idea we also already discussed but didn't mention yet, is the<br>
compositor to tell clients which clock domain it uses for all frame<br>
timing purposes. Then clients can ask the current time directly from<br>
the kernel if they need it, and relate it to the audio clock.<br></blockquote><div>Will the graphics card have its own clock, being used for scanout clocking.<br></div><div>Can this be read by the user? Can it use that clock to timestamp the presented frames?<br>
</div><div>One of the problems with PCs is that the graphics card has its own clock, the sound card has its own clock, and the kernel has its own clock.<br></div><div>The software then has to somehow match them all up.<br>
</div><div>Embedded systems are generally better and can use the same hardware based clocking for graphics card and sound card and kernel clock.<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
It is a good question, what does the requested presentation time<br>
actually mean. Should the system guarantee, that the frame is already<br>
on screen at that time, or that it is not shown before that time?<br>
Luckily, the realized presentation time can be defined exactly, e.g.<br>
the time when the hardware starts to scan out the new image. The<br>
realized time is the one that matters, and the specific meaning of<br>
requested time is not so important, since a client can adapt. No?<br></blockquote><div>The client can adapt so long as it known which clock domain each of the timestamps are in.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><br>
> There is also the matter of clock sync. Is T=100 referenced to the system<br>
> monotonic clock or some other clock.<br>
> Video and Audio sync is not achieved by comparing Video and Audio time<br>
> stamps.<br>
> You have a global system monotonic clock, and sync Video to the system<br>
> clock, and sync Audio to the system clock.<br>
> A good side effect of this is that Audio and Video are then in sync.<br>
> The advantage of this syncing to the system monotonic clock is that you can<br>
> then run Video and Audio in separate thread, different CPUs, whenever, but<br>
> they will always be in sync.<br>
<br>
</div>Some GStreamer people have told me that they actually prefer to use the<br>
audio clock as the master clock, and infer everything else from that.<br>
Anyway, yes, clock domains are important.<br></blockquote><div>This method is not always best. Some sound cards are very bad at providing an audio clock.<br></div><div>xine provides several different sync/clock methods so the user can select the best one for their hardware.<br>
<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I would like to know if I have understood something wrong in this whole<br>
video thing.<br></blockquote><div>I think how wayland can help provide the "deterministic" angle is not yet clear to me. <br></div></div><br></div></div>