使用 GStreamer 和 wxPanel 播放视频

Play Video with GStreamer and wxPanel

我正在学习 GStreamer 及其乐趣,但是我在将它与 wxWidgets 一起使用时遇到了障碍。无论我怎么努力,我都无法突破。那里的示例 GTK/Qt 仅对某些限制有帮助。这是当前代码(不起作用),下面是我收到的错误消息

wxGStreamer::wxGStreamer(wxWindow* parent, wxWindowID winid, const wxURI& location):wxPanel(parent, winid)
{
    SetBackgroundColour(*wxBLACK);

    /* Build the pipeline */
    wxString uri = location.BuildURI();
    wxPuts(uri);

    // prepare the pipeline
    GstElement *pipeline = gst_pipeline_new("xvoverlay");
    GstElement *src = gst_element_factory_make("videotestsrc", NULL);
    GstElement *sink = gst_element_factory_make("xvimagesink", NULL);
    gst_bin_add_many(GST_BIN(pipeline), src, sink, NULL);
    gst_element_link(src, sink);

    /* Set the URI to play */
    g_object_set (pipeline, "uri", "http://docs.gstreamer.com/media/sintel_trailer-480p.webm", NULL);

    GtkWidget* widget = GetHandle(); 
    guintptr video_window_handle = GDK_WINDOW_XID (gtk_widget_get_window (widget)); 
    gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(sink), video_window_handle); 

    // run the pipeline
    GstStateChangeReturn sret = gst_element_set_state(pipeline,
                                GST_STATE_PLAYING);

    if(sret == GST_STATE_CHANGE_FAILURE)
    {
        gst_element_set_state(pipeline, GST_STATE_NULL);
        gst_object_unref(pipeline);
    }

    gst_element_set_state(pipeline, GST_STATE_NULL);
    gst_object_unref(pipeline);
}

wxGStreamer 定义为

class  wxGStreamer : public wxPanel {............};

错误

即使您不想只使用它(为什么?),至少看看 wxMediaCtrl,它是在 Unix 下使用 GStreamer 实现的。

使用 gst_bus_set_sync_handler 添加同步处理程序,然后在该函数内使用 GstVideoOverlay 将视频传送到您的小部件。这是一个工作示例函数。

static GstBusSyncReply
bus_sync(GstBus* bus, GstMessage* message, gpointer user_data)
{
    CustomData* data = reinterpret_cast<CustomData*>(user_data);        

    if(!gst_is_video_overlay_prepare_window_handle_message(message))
        return GST_BUS_PASS;            
    else
    {
        if(data->xid!=NULL)
        {

            GstVideoOverlay *overlay;
            overlay = GST_VIDEO_OVERLAY(GST_MESSAGE_SRC(message));
            gst_video_overlay_set_window_handle(overlay, data->xid);
        }

        return GST_BUS_DROP;
    }
}