赞
踩
GstPlayer::GstPlayer(QString url,QObject *parent) : QObject(parent),m_url(url) { s_obj = this; // 创建管道 data.gst_src = gst_element_factory_make("rtspsrc", "source"); if("H264" == App::encoding) data.gst_depay = gst_element_factory_make("rtph264depay","depay"); else data.gst_depay = gst_element_factory_make("rtph265depay","depay"); data.gst_queue = gst_element_factory_make("queue", "queue"); if("H264" == App::encoding) data.gst_parser = gst_element_factory_make("h264parse", "parse"); else data.gst_parser = gst_element_factory_make("h265parse", "parse"); data.gst_decoder = gst_element_factory_make("mppvideodec", "deodec"); data.gst_sink = gst_element_factory_make ("waylandsink","sink"); data.gst_pipeline = gst_pipeline_new ("new-pipeline"); if (!data.gst_pipeline || !data.gst_src || !data.gst_depay || !data.gst_queue || !data.gst_parser || !data.gst_decoder || !data.gst_sink) { emit signal_errorinfo("可视化初始化失败失败."); emit signal_stateinfo("可视化初始化失败失败."); return; } //设置每个元素的参数, 需要查看gst-inspect-1.0 rtspsrc g_object_set (G_OBJECT(data.gst_src), "location",m_url.toStdString().c_str(),NULL); g_object_set(G_OBJECT(data.gst_sink), "window-x", MIPI_WIDTH, NULL); g_object_set(G_OBJECT(data.gst_sink), "window-y", 0, NULL); int hdmiWidth = 1280; int hdmiHeight = 800; QStringList ra = App::resolutionratio.split('*'); if(2 == ra.count()) { hdmiWidth = ra.at(0).toInt(); hdmiHeight = ra.at(1).toInt(); } g_object_set(G_OBJECT(data.gst_sink), "window-width", hdmiWidth, NULL); g_object_set(G_OBJECT(data.gst_sink), "window-height", hdmiHeight, NULL); g_object_set(G_OBJECT(data.gst_sink), "fill-mode", 0, NULL); g_object_set(G_OBJECT(data.gst_sink), "sync", false, NULL); // 将多个插件连接起来 gst_bin_add_many(GST_BIN(data.gst_pipeline),data.gst_src,data.gst_depay,data.gst_queue,data.gst_parser,data.gst_decoder, data.gst_sink, NULL); //连接 if(gst_element_link_many(data.gst_depay,data.gst_queue,data.gst_parser,data.gst_decoder, data.gst_sink, NULL) == 0 ) { emit signal_errorinfo("可视化连接失败."); emit signal_stateinfo("可视化连接失败."); return; } //查看元素,以为rtspsrc的Availability为Sometimes,所以要动态绑定pad g_signal_connect (data.gst_src, "pad-added", G_CALLBACK (on_pad_added), &data); //绑定UI界面 //gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (data.gst_sink), this->winId()); //将管道的消息总线上的新消息的监视添加到默认的GLib主上下文,这是下面我们的GLib主循环附加到的主上下文 data.loop = g_main_loop_new (NULL, FALSE); data.bus = gst_pipeline_get_bus (GST_PIPELINE (data.gst_pipeline)); gst_bus_add_watch (data.bus, bus_callback, data.loop); gst_object_unref (data.bus); } GstPlayer::~GstPlayer() { g_main_loop_unref (data.loop); gst_object_unref (data.bus); gst_element_set_state (data.gst_pipeline, GST_STATE_NULL); gst_object_unref (data.gst_pipeline); } void GstPlayer::play() { GstStateChangeReturn ret = gst_element_set_state (data.gst_pipeline, GST_STATE_PLAYING); if (ret == GST_STATE_CHANGE_FAILURE) { emit signal_errorinfo("可视化播放失败."); emit signal_stateinfo("可视化播放失败."); gst_object_unref (data.gst_pipeline); return; } g_main_loop_run (data.loop); } void GstPlayer::replay() { stop(); QUIHelper::sleep(50); g_object_set (G_OBJECT(data.gst_src), "location",m_url.toStdString().c_str(),NULL); play(); } void GstPlayer::stop() { GstStateChangeReturn ret = gst_element_set_state (data.gst_pipeline, GST_STATE_NULL); if (ret == GST_STATE_CHANGE_FAILURE) { emit signal_errorinfo("可视化停止失败."); emit signal_stateinfo("可视化停止失败."); gst_object_unref (data.gst_pipeline); return; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。