当前位置:   article > 正文

飞凌嵌入式 gstreamer播放rtsp_嵌入式板卡gstreamer 可以播放网络上的视频吗

嵌入式板卡gstreamer 可以播放网络上的视频吗
  1. 开发环境:
    飞凌RK3568 Gstreamer 网络摄像头(rtsp)
  2. 主要代码
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;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115

完整代码

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/862839
推荐阅读
相关标签
  

闽ICP备14008679号