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 790999 - only vaapisink should query for app context
only vaapisink should query for app context
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer-vaapi
unspecified
Other All
: Normal normal
: 1.13.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-11-29 17:46 UTC by Víctor Manuel Jáquez Leal
Modified: 2017-12-06 21:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
videocontext: only vaapisink queries for app context (2.47 KB, patch)
2017-11-29 17:47 UTC, Víctor Manuel Jáquez Leal
none Details | Review
videocontext: only vaapisink queries for app context (3.89 KB, patch)
2017-11-30 13:35 UTC, Víctor Manuel Jáquez Leal
needs-work Details | Review
vaapivideocontext: possible memleak when no bus attached (1.13 KB, patch)
2017-12-01 22:11 UTC, Víctor Manuel Jáquez Leal
committed Details | Review
vaapivideocontext: log the name of GstVaapiDisplay (1.97 KB, patch)
2017-12-01 22:11 UTC, Víctor Manuel Jáquez Leal
committed Details | Review
vaapivideocontext: only vaapisink process app context (6.62 KB, patch)
2017-12-01 22:11 UTC, Víctor Manuel Jáquez Leal
committed Details | Review

Description Víctor Manuel Jáquez Leal 2017-11-29 17:46:57 UTC
Right now there are two contexts that are queried by GstVaapi:

the old gst.vaapi.Display which contains a GstVaapiDisplay object

and the new gst.vaapi.app.Display which contains a VADisplay opaque structure
and a native display object (right now X Display, but soon wl display).

The purpose of the last one is to applications to set their own VADisplay
when using vaapisink in overlay mode, since gstreamer-vaapi doesn't expose
a library for GstVaapiDisplay.

Currenty all gstreamer-vaapi elements query for both context types, though 
the first one is desgined to be shared among the pipeline, and the second
only make sense when vaapisink is used, and creates it's own GstVaapiDisplay
object (which most be shared among the pipeline afterwards).

I think there is a bug: only vaapisink should query for gst.vaapi.app.Display,
and the rest of vaapi elements for gst.vaapi.Display. Even more, when 
vaapisink creates its own GstVaapiDisplay from gst.vaapi.app.Display, it 
should be propagated (the GstVaapiDisplay context not the other one).
Comment 1 Víctor Manuel Jáquez Leal 2017-11-29 17:47:04 UTC
Created attachment 364635 [details] [review]
videocontext: only vaapisink queries for app context

App context is made for applications that will provide, via
GstContext, the VA display and the native display to use by the
pipeline, when are using vaapisink as overlay. There ir no use case
for encoders, decoders, neither for the postprocessor.
Comment 2 Nicolas Dufresne (ndufresne) 2017-11-29 23:22:17 UTC
Just a question, if the decoder get created and activated before the display sink, will it manage to use the right dsiplay ?
Comment 3 Víctor Manuel Jáquez Leal 2017-11-30 08:33:05 UTC
(In reply to Nicolas Dufresne (stormer) from comment #2)
> Just a question, if the decoder get created and activated before the display
> sink, will it manage to use the right dsiplay ?

They will create the GstVaapiDisplay as usual, by creating a new VADisplay and trying to detect the native window and platform, and creating a new native display.

Still, this is a good question, because with this patch, the vaapisink doesn't query upstream for an already created GstVaapiDisplay. Thanks!
Comment 4 Víctor Manuel Jáquez Leal 2017-11-30 13:35:59 UTC
Created attachment 364675 [details] [review]
videocontext: only vaapisink queries for app context

App context is made for applications that will provide, via
GstContext, the VA display and the native display to use by the
pipeline, when are using vaapisink as overlay. There ir no use case
for encoders, decoders, neither for the postprocessor.

In the case of the vaapisink, it will query for gst.vaapi.Display to
upstream first, and if there is no reply, a gst.vaapi.app.Display
context will be posted as a bus message to the application. If
replied, a GstVaapiDisplay object is instantiated given the context
info, otherwise a GstVaapiDisplay is created with the normal
algorithm to guess the graphics platform. Either way, the
instantiated GstVaapiDisplay is propagated among the pipeline.
Comment 5 Víctor Manuel Jáquez Leal 2017-12-01 13:11:12 UTC
Review of attachment 364675 [details] [review]:

::: gst/vaapi/gstvaapipluginutil.c
@@ +283,3 @@
+      if (GST_IS_VIDEO_SINK (element)) {
+        /* Propagate if display was created from application */
+        gst_vaapi_video_context_propagate (element, plugin->display);

This is wrong. If the sink find a GstVaapiDisplay in upstream, it will propagate it again, which is not intended.
Comment 6 Víctor Manuel Jáquez Leal 2017-12-01 22:11:22 UTC
Created attachment 364791 [details] [review]
vaapivideocontext: possible memleak when no bus attached
Comment 7 Víctor Manuel Jáquez Leal 2017-12-01 22:11:32 UTC
Created attachment 364792 [details] [review]
vaapivideocontext: log the name of GstVaapiDisplay
Comment 8 Víctor Manuel Jáquez Leal 2017-12-01 22:11:39 UTC
Created attachment 364793 [details] [review]
vaapivideocontext: only vaapisink process app context

gst.vaapi.app.Display context is made for applications that will
provide the VA display and the native display to used by the
pipeline, when are using vaapisink as overlay. There are no use
case for encoders, decoders, neither for the postprocessor.

In the case of the vaapisink, it shall query for gst.vaapi.Display
upstream first, and then, if there is no reply,
gst.vaapi.app.Display context will be posted in the bus for the
application. If the application replies, a GstVaapiDisplay object
is instantiated given the context info, otherwise a
GstVaapiDisplay is created with the normal algorithm to guess the
graphics platform. Either way, the instantiated GstVaapiDisplay
is propagated among the pipeline and the have-message bus message.

Also only vaapisink will process the gst.vaapi.app.Display, if
and only if, it doesn't have a display already set. This is
caused because if vaapisink is in a bin (playsink, for example)
the need-context is posted twice, leading to an error state.
Comment 9 Nicolas Dufresne (ndufresne) 2017-12-06 19:04:39 UTC
Review of attachment 364791 [details] [review]:

Lgtm.
Comment 10 Nicolas Dufresne (ndufresne) 2017-12-06 19:05:16 UTC
Review of attachment 364792 [details] [review]:

Lgtm.
Comment 11 Nicolas Dufresne (ndufresne) 2017-12-06 19:09:05 UTC
Review of attachment 364793 [details] [review]:

Looks good, no more comments.
Comment 12 Víctor Manuel Jáquez Leal 2017-12-06 19:36:07 UTC
Attachment 364791 [details] pushed as 0438a3e - vaapivideocontext: possible memleak when no bus attached
Attachment 364792 [details] pushed as 466c839 - vaapivideocontext: log the name of GstVaapiDisplay
Attachment 364793 [details] pushed as 8f5933c - vaapivideocontext: only vaapisink process app context
Comment 13 Víctor Manuel Jáquez Leal 2017-12-06 19:37:10 UTC
Thanks for the review!
Comment 14 Tim-Philipp Müller 2017-12-06 20:08:07 UTC
Comment on attachment 364791 [details] [review]
vaapivideocontext: possible memleak when no bus attached

>+  if (!gst_element_post_message (element, msg)) {
>     GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element, "No bus attached");
>+    gst_message_unref (msg);
>+  }

This doesn't look right to me.

gst_element_post_message() takes ownership of the message. It should take ownership in all cases.
Comment 15 Nicolas Dufresne (ndufresne) 2017-12-06 21:13:07 UTC
Thanks for spotting, fixed:

commit b0d41c5db8c29b3df2a5b23d3da55141d701b992 (HEAD -> master)
Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Date:   Wed Dec 6 16:11:46 2017 -0500

    videoconvert: gst_element_post_message() is transfer full on msg
    
    For this reson we need not to unref the message, even if it failed.

commit f9a57ccece4552a609b4660d2d3152611f52e0de
Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Date:   Wed Dec 6 16:11:25 2017 -0500

    Revert "vaapivideocontext: possible memleak when no bus attached"
    
    This reverts commit 0438a3e62660e64ed390b6bb83bfb560b91664aa.