<div dir="ltr"><span style="color:rgb(13,13,13);font-family:Söhne,ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,Ubuntu,Cantarell,"Noto Sans",sans-serif,"Helvetica Neue",Arial,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"">I forgot to mention that handling window operations in Wayland is a bit different from X11</span>.there is a c example for wayland gtk in the gstreamer repo, but I can not find it now.<br>here is my python code, shall be easy convert to C++<div><br></div><div><div style="color:rgb(214,214,221);background-color:rgb(24,24,24);font-family:"Droid Sans Mono","monospace",monospace;font-size:16px;line-height:22px;white-space:pre"><div><div style="line-height:22px"><div></div><div><span style="color:rgb(148,193,250)">libgdk</span> = <span style="color:rgb(209,209,209)">ctypes</span>.<span style="color:rgb(235,200,141)">CDLL</span>(<span style="color:rgb(235,200,141)">find_library</span>(<span style="color:rgb(227,148,220)">"libgdk-3"</span>))</div><div><div style="line-height:22px"><div><span style="color:rgb(148,193,250)">libgst</span> = <span style="color:rgb(209,209,209)">ctypes</span>.<span style="color:rgb(235,200,141)">CDLL</span>(<span style="color:rgb(235,200,141)">find_library</span>(<span style="color:rgb(227,148,220)">"libgstreamer-1.0"</span>))</div><div><br></div></div></div></div></div><div><span style="color:rgb(130,210,206)">def</span> <span style="color:rgb(239,176,128);font-weight:bold">get_wayland_window_handle</span>(<span style="font-style:italic">widget</span>):</div><div>    <span style="color:rgb(131,214,197);font-style:italic">return</span> <span style="color:rgb(148,193,250)">libgdk</span>.<span style="color:rgb(170,160,250)">gdk_wayland_window_get_wl_surface</span>(<span style="color:rgb(130,210,206)">hash</span>(<span style="font-style:italic">widget</span>.<span style="color:rgb(170,160,250)">get_window</span>()))</div><br><br><div><span style="color:rgb(130,210,206)">def</span> <span style="color:rgb(239,176,128);font-weight:bold">get_default_wayland_display_context</span>():</div><div>    <span style="color:rgb(148,193,250)">wl_display</span> = <span style="color:rgb(148,193,250)">libgdk</span>.<span style="color:rgb(170,160,250)">gdk_wayland_display_get_wl_display</span>(</div><div>        <span style="color:rgb(130,210,206)">hash</span>(Gdk.Display.<span style="color:rgb(170,160,250)">get_default</span>())</div><div>    )</div><div>    <span style="color:rgb(148,193,250)">context</span> = Gst.Context.<span style="color:rgb(170,160,250)">new</span>(<span style="color:rgb(227,148,220)">"GstWaylandDisplayHandleContextType"</span>, <span style="color:rgb(130,210,206)">True</span>)</div><div>    <span style="color:rgb(148,193,250)">structure</span> = <span style="color:rgb(148,193,250)">libgst</span>.<span style="color:rgb(170,160,250)">gst_context_writable_structure</span>(<span style="color:rgb(130,210,206)">hash</span>(<span style="color:rgb(148,193,250)">context</span>))</div><div>    <span style="color:rgb(148,193,250)">libgst</span>.<span style="color:rgb(170,160,250)">gst_structure_set</span>(</div><div>        <span style="color:rgb(148,193,250)">structure</span>,</div><div>        <span style="color:rgb(209,209,209)">ctypes</span>.<span style="color:rgb(235,200,141)">c_char_p</span>(<span style="color:rgb(227,148,220)">"display"</span>.<span style="color:rgb(235,200,141)">encode</span>()),</div><div>        <span style="color:rgb(130,210,206)">hash</span>(GObject.TYPE_POINTER),</div><div>        <span style="color:rgb(148,193,250)">wl_display</span>,</div><div>        <span style="color:rgb(235,200,141)">0</span>,</div><div>    )</div><div>    <span style="color:rgb(131,214,197);font-style:italic">return</span> <span style="color:rgb(148,193,250)">context</span></div><div><span style="color:rgb(148,193,250)"><br></span></div><div><div style="line-height:22px"><div><span style="color:rgb(130,210,206)">def</span> <span style="color:rgb(239,176,128);font-weight:bold">set_window</span>(<span style="color:rgb(204,124,138);font-style:italic">self</span>):</div><div>        <span style="color:rgb(131,214,197);font-style:italic">if</span> <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">window</span> <span style="color:rgb(131,214,197)">is</span> <span style="color:rgb(131,214,197)">not</span> <span style="color:rgb(130,210,206)">None</span>:</div><div>            <span style="color:rgb(109,109,109);font-style:italic"># window already set, when refresh/update, do not create new window</span></div><div>            <span style="color:rgb(131,214,197);font-style:italic">return</span></div><div>        <span style="color:rgb(148,193,250)">window</span> = Gtk.<span style="color:rgb(170,160,250)">Window</span>()</div><div>        <span style="color:rgb(148,193,250)">window</span>.<span style="color:rgb(170,160,250)">set_title</span>(<span style="color:rgb(227,148,220)">"Video Streaming"</span>)</div><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">window</span> = <span style="color:rgb(148,193,250)">window</span></div><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">window</span>.<span style="color:rgb(170,160,250)">connect</span>(<span style="color:rgb(227,148,220)">"destroy"</span>, Gtk.main_quit, <span style="color:rgb(227,148,220)">"WM destroy"</span>)</div><div>        <span style="color:rgb(148,193,250)">window</span>.<span style="color:rgb(170,160,250)">set_default_size</span>(<span style="color:rgb(235,200,141)">1200</span>, <span style="color:rgb(235,200,141)">800</span>)</div><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">window</span>.<span style="color:rgb(170,160,250)">show_all</span>()</div><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">window</span>.<span style="color:rgb(170,160,250)">fullscreen</span>()</div></div></div><div><span style="color:rgb(148,193,250)"><br></span></div><div><div style="line-height:22px"><div><span style="color:rgb(130,210,206)">def</span> <span style="color:rgb(239,176,128);font-weight:bold">set_stream</span>(<span style="color:rgb(204,124,138);font-style:italic">self</span>, <span style="font-style:italic">url</span>):</div><div>        <span style="color:rgb(148,193,250)">command</span> = <span style="color:rgb(130,210,206)">f</span><span style="color:rgb(227,148,220)">"rtspsrc name=rtspsrc location=</span><span style="color:rgb(248,199,98)">{</span><span style="font-style:italic">url</span><span style="color:rgb(248,199,98)">}</span><span style="color:rgb(227,148,220)"> protocols=tcp latency=10 max-rtcp-rtp-time-diff=10 ! errorignore ! rtph265depay name=depay ! h265parse ! avdec_h265 name=avdec ! videoconvert ! video/x-raw, format=RGBA ! waylandsink name=sink"</span></div><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">logger</span>.<span style="color:rgb(235,200,141)">info</span>(<span style="color:rgb(130,210,206)">f</span><span style="color:rgb(227,148,220)">"command </span><span style="color:rgb(248,199,98)">{</span><span style="color:rgb(148,193,250)">command</span><span style="color:rgb(248,199,98)">}</span><span style="color:rgb(227,148,220)">"</span>)</div><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">pipeline</span> = Gst.<span style="color:rgb(170,160,250)">parse_launch</span>(<span style="color:rgb(148,193,250)">command</span>)</div><br><div>        <span style="color:rgb(148,193,250)">bus</span> = <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">pipeline</span>.<span style="color:rgb(170,160,250)">get_bus</span>()</div><div>        <span style="color:rgb(148,193,250)">bus</span>.<span style="color:rgb(170,160,250)">add_signal_watch</span>()</div><div>        <span style="color:rgb(148,193,250)">bus</span>.<span style="color:rgb(170,160,250)">connect</span>(<span style="color:rgb(227,148,220)">"message"</span>, <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(235,200,141)">on_message</span>)</div><br><div>        <span style="color:rgb(131,214,197);font-style:italic">if</span> <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">drawing_area</span> <span style="color:rgb(131,214,197)">is</span> <span style="color:rgb(131,214,197)">not</span> <span style="color:rgb(130,210,206)">None</span>:</div><div>            <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">window</span>.<span style="color:rgb(170,160,250)">remove</span>(<span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">drawing_area</span>)</div><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">drawing_area</span> = Gtk.<span style="color:rgb(170,160,250)">DrawingArea</span>()</div><div>        <span style="color:rgb(109,109,109);font-style:italic"># set background color</span></div><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">drawing_area</span>.<span style="color:rgb(170,160,250)">modify_bg</span>(</div><div>            Gtk.StateType.NORMAL, Gdk.<span style="color:rgb(170,160,250)">color_parse</span>(<span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">background_color_str</span>)</div><div>        )</div><br><div>        <span style="color:rgb(148,193,250)">glsink</span> = <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">pipeline</span>.<span style="color:rgb(170,160,250)">get_by_name</span>(<span style="color:rgb(227,148,220)">"sink"</span>)</div><br><div>        <span style="color:rgb(109,109,109);font-style:italic"># Wayland display context wrapped as a GStreamer context.</span></div><div>        <span style="color:rgb(148,193,250)">wl_display</span> = <span style="color:rgb(235,200,141)">get_default_wayland_display_context</span>()</div><div>        <span style="color:rgb(148,193,250)">glsink</span>.<span style="color:rgb(170,160,250)">set_context</span>(<span style="color:rgb(148,193,250)">wl_display</span>)</div><br><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">window</span>.<span style="color:rgb(170,160,250)">connect</span>(<span style="color:rgb(227,148,220)">"delete-event"</span>, Gtk.main_quit)</div><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">window</span>.<span style="color:rgb(170,160,250)">add</span>(<span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">drawing_area</span>)</div><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">drawing_area</span>.<span style="color:rgb(170,160,250)">realize</span>()</div><br><div>        <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">window</span>.<span style="color:rgb(170,160,250)">show_all</span>()</div><br><div>        <span style="color:rgb(148,193,250)">bus</span>.<span style="color:rgb(170,160,250)">enable_sync_message_emission</span>()</div><div>        <span style="color:rgb(148,193,250)">bus</span>.<span style="color:rgb(170,160,250)">connect</span>(<span style="color:rgb(227,148,220)">"sync-message"</span>, <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(235,200,141)">on_sync_message</span>)</div><div><br></div><div><div style="line-height:22px"><div><span style="color:rgb(130,210,206)">def</span> <span style="color:rgb(239,176,128);font-weight:bold">on_sync_message</span>(<span style="color:rgb(204,124,138);font-style:italic">self</span>, <span style="font-style:italic">bus</span>: Gst.Bus, <span style="font-style:italic">message</span>: Gst.Message):</div><div>        <span style="color:rgb(131,214,197);font-style:italic">if</span> <span style="font-style:italic">message</span>.<span style="color:rgb(170,160,250)">get_structure</span>() <span style="color:rgb(131,214,197)">is</span> <span style="color:rgb(130,210,206)">None</span>:</div><div>            <span style="color:rgb(131,214,197);font-style:italic">return</span> <span style="color:rgb(235,200,141)">1</span></div><br><div>        <span style="color:rgb(131,214,197);font-style:italic">if</span> <span style="font-style:italic">message</span>.<span style="color:rgb(170,160,250)">get_structure</span>().<span style="color:rgb(170,160,250)">get_name</span>() == <span style="color:rgb(227,148,220)">"prepare-window-handle"</span>:</div><div>            <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">logger</span>.<span style="color:rgb(235,200,141)">info</span>(<span style="color:rgb(130,210,206)">f</span><span style="color:rgb(227,148,220)">"[on_sync_message] </span><span style="color:rgb(248,199,98)">{</span><span style="font-style:italic">message</span>.<span style="color:rgb(170,160,250)">get_structure</span>().<span style="color:rgb(170,160,250)">get_name</span>()<span style="color:rgb(248,199,98)">}</span><span style="color:rgb(227,148,220)">"</span>)</div><div>            <span style="color:rgb(148,193,250)">sink</span> = <span style="font-style:italic">message</span>.src</div><div>            <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">logger</span>.<span style="color:rgb(235,200,141)">info</span>(<span style="color:rgb(130,210,206)">f</span><span style="color:rgb(227,148,220)">"[on_sync_message] sink: </span><span style="color:rgb(248,199,98)">{</span><span style="color:rgb(148,193,250)">sink</span><span style="color:rgb(248,199,98)">}</span><span style="color:rgb(227,148,220)">"</span>)</div><br><div>            <span style="color:rgb(109,109,109);font-style:italic"># Wayland window handle.</span></div><div>            <span style="color:rgb(148,193,250)">wl_handle</span> = <span style="color:rgb(235,200,141)">get_wayland_window_handle</span>(<span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">drawing_area</span>)</div><div>            <span style="color:rgb(148,193,250)">sink</span>.<span style="color:rgb(170,160,250)">set_window_handle</span>(<span style="color:rgb(148,193,250)">wl_handle</span>)</div><br><div>            <span style="color:rgb(148,193,250)">allocation</span> = <span style="color:rgb(204,124,138);font-style:italic">self</span>.<span style="color:rgb(170,155,245)">drawing_area</span>.<span style="color:rgb(170,160,250)">get_allocation</span>()</div><div>            <span style="color:rgb(148,193,250)">sink</span>.<span style="color:rgb(170,160,250)">set_render_rectangle</span>(</div><div>                <span style="color:rgb(148,193,250)">allocation</span>.x, <span style="color:rgb(148,193,250)">allocation</span>.y, <span style="color:rgb(148,193,250)">allocation</span>.width, <span style="color:rgb(148,193,250)">allocation</span>.height</div><div>            )</div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 29 Apr 2024 at 12:15, Gregoire Gentil <<a href="mailto:gregoire@gentil.com">gregoire@gentil.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Thanks for helping. Still not working.<br>
<br>
I have replaced glimagesink by waylandsink. If I don't call <br>
"gst_video_overlay_set_window_handle", the video appears in the back. So <br>
at least, waylandsink is working. But note that the video is appearing <br>
without being part of any window at all.<br>
<br>
If I call "gst_video_overlay_set_window_handle", the video doesn't <br>
appear and doesn't play. I also receive the following message:<br>
<br>
waylandsink cannot use an externally-supplied surface without an <br>
externally-supplied display handle. Consider providing a display handle <br>
from your application with GstContext<br>
<br>
Am I missing another API call?<br>
<br>
Grégoire<br>
<br>
<br>
On 4/28/24 20:28, Max Weng wrote:<br>
> I understand your situation better now. :) I've noticed that the video <br>
> indeed appears in a separate window with other sinks as well. It seems <br>
> that in my experience, only |waylandsink|consistently integrates <br>
> directly into the GTK window without issues.<br>
> <br>
> On Mon, 29 Apr 2024 at 10:51, Gregoire Gentil <<a href="mailto:gregoire@gentil.com" target="_blank">gregoire@gentil.com</a> <br>
> <mailto:<a href="mailto:gregoire@gentil.com" target="_blank">gregoire@gentil.com</a>>> wrote:<br>
> <br>
>     I could have been more precise: the glimageslink pipeline does work and<br>
>     the video appears in a separated window if I don't link it to the<br>
>     window<br>
>     with the code mentioned below. What I want to do is to insert the video<br>
>     inside the gtk window.<br>
> <br>
>     Also glimagesink has the unique advantage to work on both wayland and<br>
>     non-wayland systems,<br>
> <br>
>     Grégoire<br>
> <br>
> <br>
> <br>
> <br>
>     On 4/28/24 19:12, Max Weng wrote:<br>
>      > try use waylandsink?<br>
>      ><br>
>      > this work for me "rtspsrc name=rtspsrc location={url} protocols=tcp<br>
>      > latency=10 max-rtcp-rtp-time-diff=10 ! errorignore ! rtph265depay<br>
>      > name=depay ! h265parse ! avdec_h265 name=avdec ! videoconvert !<br>
>      > video/x-raw, format=RGBA ! waylandsink name=sink"<br>
>      ><br>
>      > On Mon, 29 Apr 2024 at 06:18, Gregoire Gentil via gstreamer-devel<br>
>      > <<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a><br>
>     <mailto:<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a>><br>
>      > <mailto:<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a><br>
>     <mailto:<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a>>>> wrote:<br>
>      ><br>
>      >     Hello,<br>
>      ><br>
>      >     I had an application with a gtk+-3.0 window and a pipeline "... !<br>
>      >     imagesink". The video is rendered inside the gtk window.<br>
>      ><br>
>      >     I was doing:<br>
>      >     static void realize_cb(GtkWidget *widget, CustomData *data) {<br>
>      >     GdkWindow *window = gtk_widget_get_window(widget);<br>
>      >     data->window_handle = GDK_WINDOW_XID(window);<br>
>      ><br>
>      >     and then:<br>
>      ><br>
>      >     static GstBusSyncReply bus_sync_handler(GstBus * bus,<br>
>     GstMessage *<br>
>      >     message, CustomData *data) {<br>
>      >   <br>
>       gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(data->video_sink),<br>
>      >     data->window_handle);<br>
>      ><br>
>      >     Everything was working fine. I want now to support wayland<br>
>     system.<br>
>      ><br>
>      >     Pipeline becomes: "... ! glimagesink".<br>
>      ><br>
>      >     in the realize_cb function, I have now:<br>
>      >     GdkWindow *window = gtk_widget_get_window(widget);<br>
>      >     data->window_handle =<br>
>      >     (guintptr)gdk_wayland_window_get_wl_surface(window);<br>
>      ><br>
>      ><br>
>      >     At run-time, I'm getting hundreds of:<br>
>      >     "GStreamer-GL-CRITICAL **: 14:06:48.263: Failed to flush Wayland<br>
>      >     connection"<br>
>      ><br>
>      >     What am I doing wrong? Many thanks in advance for any hint,<br>
>      ><br>
>      >     Grégoire<br>
>      ><br>
> <br>
</blockquote></div>