w3c / mediacapture-extensions

Extensions to Media Capture and Streams by the WebRTC Working Group
https://w3c.github.io/mediacapture-extensions/
Other
19 stars 14 forks source link

[Audio Stats] Add average, min and max latency #128

Closed henbos closed 7 months ago

henbos commented 8 months ago

As previously discussed in meetings, an app wants to know average latency over an interval that the app decides on, but as @padenot pointed out, for these averages not to hide extremes, we should also have min and max.

During our meeting the proposal that I believe everyone would be happy with is exposing min/max/avg since the last time track.stats.resetLatency() was called (feel free to have opinions about attribute and method names we did not decide anything).

henbos commented 8 months ago

Shall I create a PR for...? @padenot @jan-ivar

interface MediaStreamTrackAudioStats {
    ...

    // Added in https://github.com/w3c/mediacapture-extensions/pull/124
    readonly attribute DOMHighResTimeStamp? latency;

    // New PR:

    readonly attribute DOMHighResTimeStamp? averageLatency;
    readonly attribute DOMHighResTimeStamp? minLatency;
    readonly attribute DOMHighResTimeStamp? maxLatency;

    // Resets min/max/average so that the next time `track.stats´ is called these values represent the
    // min/max/average since `resetLatency()` was called.
    void resetLatency();
};

Nullable because if we've just reset the latencies we don't have any latency measure to min/max/avg over.

jan-ivar commented 8 months ago

Do we need nullable? Why not just set averageLatency = minLatency = maxLatency = latency at that point?

henbos commented 8 months ago

That would work, except that latency is not known until the first time that a measurement is made. So if you just called getUserMedia I don't think you necessarily know what the latency is yet. Unless you think the user agent could have some sensible default there

henbos commented 8 months ago

We could default it to 0 just to avoid nullables, the app could still check if deliveredFrames > 0 for this edge case

henbos commented 7 months ago

I think we can remove nullable, when it is reset min/max/avg = current latency. Since we removed nullable from current latency.