AnsweredAssumed Answered

imx8mq gstreamer waylandsink display with qt5 widget

Question asked by yuanzhi wang on Jun 11, 2020
Latest reply on Jun 17, 2020 by yuanzhi wang

I want to play video with greamer's waylandsink and qt5 widget, but  waylandsink cann't render to th qt5 widget,it didn't  work. thank you.

this is the my code:

 

the main.cpp

 

GstBusSyncReply PlayerWindow::bus_sync_handler (GstBus * bus, GstMessage * message, gpointer user_data)
{
PlayerWindow *d = (PlayerWindow *)user_data;
if (gst_is_wayland_display_handle_need_context_message (message)) {
GstContext *context;
struct wl_display *display_handle;


display_handle = (struct wl_display*) QGuiApplication::platformNativeInterface()->nativeResourceForWindow("display", NULL);

 

context = gst_wayland_display_handle_context_new (display_handle);
gst_element_set_context (GST_ELEMENT (GST_MESSAGE_SRC (message)), context);

goto drop;
} else if (gst_is_video_overlay_prepare_window_handle_message (message)) {


struct wl_surface *surface = static_cast<struct wl_surface *>(QGuiApplication::platformNativeInterface()->nativeResourceForWindow("surface", d->windowHandle()));
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message)),(guintptr) surface);
gst_video_overlay_set_render_rectangle(
GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message)),
0, 80,
1920, 1080);
goto drop;
}

return GST_BUS_PASS;

drop:
gst_message_unref (message);
return GST_BUS_DROP;
}

 

 

int main(int argc, char *argv[])

{

gst_init (&argc, &argv);
QApplication app(argc, argv);
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit ()));

GstElement *pipeline = gst_parse_launch ("playbin uri=file:///run/media/mmcblk0p1/stream_chn0.h265", NULL);

 

PlayerWindow *window = new PlayerWindow(pipeline);
GstElement *vsink = gst_element_factory_make ("waylandsink", "vsink"); // waylandsink glimagesink
g_object_set(GST_OBJECT(pipeline), "video-sink", vsink, NULL);
QApplication::sync();
window->resize(1920, 1080);

// connect to interesting signals
GstBus *bus = gst_element_get_bus(pipeline);
gst_bus_add_watch(bus, &PlayerWindow::postGstMessage, window);
gst_bus_set_sync_handler (bus, &PlayerWindow::bus_sync_handler, window, NULL);
gst_object_unref(bus);

GstStateChangeReturn sret = gst_element_set_state (pipeline, GST_STATE_PLAYING);

window->show();
int ret = app.exec()

}

Outcomes