After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 740419 - decoders don't report latency
decoders don't report latency
Status: RESOLVED FIXED
Product: gstreamer-vaapi
Classification: Other
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: gstreamer-vaapi maintainer(s)
gstreamer-vaapi maintainer(s)
Depends on:
Blocks: 743569 749640
 
 
Reported: 2014-11-20 11:46 UTC by Jan Schmidt
Modified: 2015-06-01 16:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
vaapidecode: calculate decoding latency (2.04 KB, patch)
2015-05-21 17:39 UTC, Víctor Manuel Jáquez Leal
committed Details | Review

Description Jan Schmidt 2014-11-20 11:46:03 UTC
None of the gst-vaapi decoder implementations appear to set any min/max decoder latency, causing problems in live playback scenarios.

Is there a way to get that info from the vaapi implementation?

Decoders should call gst_video_decoder_set_latency() to configure the latency, and the base class will use it to answer latency queries.
Comment 1 Gwenole Beauchesne 2014-11-26 13:47:49 UTC
I think we could safely assume realtime performance for the HW decoder side, once submitted to the HW.

However, for parsing/preparation purposes we'd need at least 1 frame latency in general, with perfectly known unit boundaries (NALU, AU), and up to 2 frames when we need to wait for the second frame start to determine the first frame is complete, i.e. scan for start code + check that this is the start of the next frame actually.

WDYT? Or do I misunderstand the expected concepts?
Comment 2 Gwenole Beauchesne 2014-11-26 13:50:22 UTC
(In reply to comment #0)
> None of the gst-vaapi decoder implementations appear to set any min/max decoder
> latency, causing problems in live playback scenarios.
> 
> Is there a way to get that info from the vaapi implementation?
> 
> Decoders should call gst_video_decoder_set_latency() to configure the latency,
> and the base class will use it to answer latency queries.

For some codecs, there is a VA API to determine the number of MBs that can be processed per second. However, to be honest, this is mostly unimplemented right now (VA driver wise), and that API is not even mainlined yet IIRC. It's in the "staging" branch for now.
Comment 3 Jan Schmidt 2014-11-27 10:21:20 UTC
Assuming realtime decode performance is almost certainly acceptable. Your understanding is correct - see http://cgit.freedesktop.org/gstreamer/gst-plugins-ugly/tree/ext/mpeg2dec/gstmpeg2dec.c#n772 for example.
Comment 4 Víctor Manuel Jáquez Leal 2015-05-21 17:39:09 UTC
Created attachment 303774 [details] [review]
vaapidecode: calculate decoding latency

This is a naïve approach to the calculation of the VA-API decoding latency. It
takes into consideration when the frame-rate has some insane value.
Comment 5 Jan Schmidt 2015-05-25 04:57:38 UTC
Seems OK :)
Comment 6 Víctor Manuel Jáquez Leal 2015-06-01 13:55:21 UTC
(In reply to Jan Schmidt from comment #5)
> Seems OK :)

There's something that worries me is that

GstClockTime latency = gst_util_uint64_scale (2, fps_d, fps_n);

Always returns 0. It that value useful as latency (no latency)? 

But if we do 

GstClockTime latency = gst_util_uint64_scale (2 * GST_SECOND, fps_d, fps_n);

We usually get a positive number that, for me, makes sense, since, if I understand correctly, the decoder will produce the first frame after the duration of two frames.

#include <gst/gst.h>

void
tururu (gint fps_n, gint fps_d)
{
	GstClockTime l1, l2;

	l1 = gst_util_uint64_scale (2, fps_d, fps_n);
	l2 = gst_util_uint64_scale (2 * GST_SECOND, fps_d, fps_n);

	g_print ("l1 = %ld / l2 = %ld\n", l1, l2);

}

int
main (int argc, char **argv)
{
	tururu (24, 1);
	tururu (5000000, 208333);
	tururu (24000, 1001);
	return 0;
}
Comment 7 Jan Schmidt 2015-06-01 14:24:20 UTC
Oops - I should have checked the logic more carefully. Yes, you need to multiply by GST_SECOND

So, in the case where packet boundaries are known, the latency can be set to
 
GstClockTime latency = gst_util_uint64_scale (GST_SECOND, fps_d, fps_n);

and when the decoder needs to collect a ref frame and then a 2nd frame to find the end-of-packet boundary, it needs to be 

GstClockTime latency = gst_util_uint64_scale (2 * GST_SECOND, fps_d, fps_n);

but it's OK to use the larger value for both - it'll just add a fraction of a second to playback delay in live streaming.
Comment 8 Víctor Manuel Jáquez Leal 2015-06-01 16:31:09 UTC
(In reply to Jan Schmidt from comment #7)
> Oops - I should have checked the logic more carefully. Yes, you need to
> multiply by GST_SECOND

I said it because you don't multiply in gstmpeg2dec ;)

http://cgit.freedesktop.org/gstreamer/gst-plugins-ugly/tree/ext/mpeg2dec/gstmpeg2dec.c#n821

> 
> So, in the case where packet boundaries are known, the latency can be set to
>  
> GstClockTime latency = gst_util_uint64_scale (GST_SECOND, fps_d, fps_n);
> 
> and when the decoder needs to collect a ref frame and then a 2nd frame to
> find the end-of-packet boundary, it needs to be 
> 
> GstClockTime latency = gst_util_uint64_scale (2 * GST_SECOND, fps_d, fps_n);
> 
> but it's OK to use the larger value for both - it'll just add a fraction of
> a second to playback delay in live streaming.

Thanks again!
Comment 9 Víctor Manuel Jáquez Leal 2015-06-01 16:43:10 UTC
Attachment 303774 [details] pushed as 26cedfa - vaapidecode: calculate decoding latency