首页 > 解决方案 > Gtk/Gstreamer 应用程序在第一帧冻结

问题描述

我正在尝试制作一个通过 gtk 绘图区域流式传输视频的应用程序。我目前正在尝试运行的管道是 videotestsrc !ximagesink。我的问题是,当我尝试运行我的程序时,它显示 videotestsrc,但仅显示为静止图像。这与通过终端运行“gst-launch-1.0 videotestsrc!ximagesink”不同,右下角的静态移动。

关于我做错了什么的任何想法?

int main(int argc, char* argv[])
{
        Gst::init(argc, argv);
        auto app = Gtk::Application::create(argc, argv, "gtkmm.video.sunshine.test");
        Program_Window window;
        return app->run(window);
}

    
class Program_Window : public Gtk::Window
{
    
public:
        Program_Window();
        virtual ~Program_Window();

protected:
        Gtk::DrawingArea* display;
        Glib::RefPtr<Gst::Pipeline> playbin;
        gulong window_handler;
        GstVideoOverlay* overlay;
        void on_display_realize();
};


Program_Window::Program_Window()
{

        //initialize variables
        display = new Gtk::DrawingArea();
        window_handler = 0;

        //connect realize callback
        display->signal_realize().connect( sigc::mem_fun( *this, &Program_Window::on_display_realize ));

        //create playbin
        playbin = Gst::PlayBin::create("playbin");

        //prepare elements for the pipeline
        Glib::RefPtr<Gst::Element> source = Gst::ElementFactory::create_element("videotestsrc", "src");
        Glib::RefPtr<Gst::Element> sink = Gst::ElementFactory::create_element("ximagesink", "sink");

        //add elements to the pipeline
        playbin->add(source)->add(sink);

        //link elements
        source->link(sink);

        //prep video overlay interface
        overlay = (GstVideoOverlay*) sink->gobj();

        //add drawing area to main window
        add(*display);
        show_all_children();
}


void Program_Window::on_display_realize()
{
    
            //acquire an xwindow pointer to our draw area   
            window_handler = GDK_WINDOW_XID( display->get_window()->gobj() );
    
            //give xwindow pointer to our pipeline via video overlay interface
            gst_video_overlay_set_window_handle(overlay, window_handler);
    
            //start video
            playbin->set_state(Gst::STATE_PLAYING);
}

标签: gtkgstreamer

解决方案


解决它。无论出于何种原因,该程序不喜欢我使用 playbin 的方式。将其更改为正常的 Gst::pipeline 有效。

    //create playbin                             //in the above code
    //playbin = Gst::PlayBin::create("playbin"); //change this
    playbin = Gst::Pipeline::create("pipeline"); //to this

推荐阅读