明远智睿技术论坛

 找回密码
 立即注册
搜索
查看: 4428|回复: 4
打印 上一主题 下一主题

EK200用qt4.85调用gstreamer0.1开发组播播放视频

[复制链接]

16

主题

34

帖子

196

积分

注册会员

Rank: 2

积分
196
跳转到指定楼层
楼主
发表于 2017-10-14 18:23:14 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zp279 于 2017-10-14 18:28 编辑

Linux-3.0.35
开发板:EK200,使用P1的网口,不是USB扩展的
用qt4.85调用gstreamer0.1开发组播播放视频,视频不连续,很卡。
明远这边有UDP组播的demo吗?我的邮箱是 zp279@163.com
我们有项目快要上小批量了,时间很紧张,麻烦了!!!!
调试串口提示很多以下信息
Discont detected from 0:00:00.500000000 to 1:10:46.532788000
Discont detected from 0:00:00.500000000 to 1:10:46.556011000
Discont detected from 0:00:00.500000000 to 1:10:46.579233000
Discont detected from 0:00:00.500000000 to 1:10:46.602444000
Discont detected from 0:00:00.500000000 to 1:10:46.625666000
Discont detected from 0:00:00.500000000 to 1:10:46.648888000
Discont detected from 0:00:00.500000000 to 1:10:46.672111000
Discont detected from 0:00:00.500000000 to 1:10:46.695333000
Discont detected from 0:00:00.500000000 to 1:10:46.718544000
Discont detected from 0:00:00.500000000 to 1:10:46.741766000
Discont detected from 0:00:00.500000000 to 1:10:46.764988000
Discont detected from 0:00:00.500000000 to 1:10:46.788211000



主要代码
CQMedia::CQMedia(int winID,QWidget* win, DevType type,QObject* parent):
    CQGstBasic(winID,win,parent)
{
    if(type == ROOM||type == SUBVIDEO)
        qosMax = 20;
    else if(type == CAR)
        qosMax = 20;
    devType = type;
    silenceState = false;
    this->pipeline=gst_pipeline_new( "pipeline" );
    //构造各组件
    GstElement *udpsrc =  gst_element_factory_make("udpsrc","udpsrc");
    g_object_set(G_OBJECT(udpsrc),"do-timestamp",false,NULL);
    g_object_set(G_OBJECT(udpsrc),"timeout",(quint64)2000000,NULL);
    GstElement *queue0 = gst_element_factory_make("queue","queue0");
    g_object_set(G_OBJECT(queue0),"max-size-time",(guint64)0,NULL);
    GstElement *rtpmp2tdepay  =  gst_element_factory_make("rtpmp2tdepay","rtpmp2tdepay");

    GstElement *queue1 = gst_element_factory_make("queue","queue1");
    g_object_set(G_OBJECT(queue1),"max-size-time",(guint64)0,NULL);
    GstElement *aiurdemux = gst_element_factory_make("aiurdemux","aiurdemux");
    g_object_set(G_OBJECT(aiurdemux),"streaming_latency",(guint64)5000,NULL);
    GstElement *queue2 = gst_element_factory_make("queue","queue2");
    g_object_set(G_OBJECT(queue2),"max-size-time",(guint64)0,NULL);

    GstElement *v_dec = gst_element_factory_make("vpudec","v_dec");
    g_object_set(G_OBJECT(v_dec),"parser",false,"dbkenable",false,"profiling",false,
                 "framedrop",true,"min-latency",true,"fmt",(guint64)0,NULL);
    GstElement *v_sink  = gst_element_factory_make("mfw_v4lsink","v_sink");
    g_object_set(G_OBJECT(v_sink),"sync",true,"x11enable",true,NULL);

    GstElement *queue3 = gst_element_factory_make("queue","queue3");
    g_object_set(G_OBJECT(queue3),"max-size-time",(guint64)0,NULL);
    GstElement *a_dec = gst_element_factory_make("beepdec","a_dec");

    GstElement *a_conv = gst_element_factory_make("audioconvert","audioconvert");
    GstElement *capsfilter = gst_element_factory_make("capsfilter","capsfilter");
    GstCaps *a_caps = gst_caps_from_string("audio/x-raw-int, channels=2");
    g_object_set(G_OBJECT(capsfilter),"caps",a_caps,NULL);
    GstElement *audiovol = gst_element_factory_make("volume","audiovol");
    GstElement *a_sink = gst_element_factory_make("alsasink","a_sink");
    g_object_set(G_OBJECT(a_sink),"sync",true,NULL);
//串连组件

    gst_bin_add_many (GST_BIN (pipeline), udpsrc,queue0,rtpmp2tdepay,queue1,aiurdemux,
                      queue2,v_dec,queue3,a_dec,a_conv,capsfilter,audiovol,a_sink,v_sink,NULL);
    gst_element_link_many ( udpsrc,queue0,rtpmp2tdepay,queue1,aiurdemux,NULL);
    gst_element_link_many ( queue2,v_dec,v_sink,NULL);
    g_signal_connect (aiurdemux, "pad-added", G_CALLBACK (pad_added_handler),queue2);
    gst_element_link_many ( queue3,a_dec,a_conv,capsfilter,audiovol,a_sink,NULL);
    g_signal_connect (aiurdemux, "pad-added", G_CALLBACK (pad_added_handler), queue3);

    GstBus* bus=gst_pipeline_get_bus(GST_PIPELINE(pipeline));
    gst_bus_add_watch(bus,bus_callback,this);
    gst_object_unref(bus);
    gst_element_set_state(pipeline,GST_STATE_NULL);
    this->state=STOPPED;
}

bool CQMedia::loadURL(const QString& url)
{
    qDebug("CQMedia::loadURL");
    QString tmp = url;
    tmp.remove(0,6);
    QString ip = tmp.split(QChar(':'))[0];
    int port = tmp.split(QChar(':'))[1].toInt();
    this->url = url;

    GstElement *udpsrc =  gst_bin_get_by_name(GST_BIN(pipeline),"udpsrc");
    GstCaps *caps = gst_caps_new_simple("application/x-rtp",NULL);
    QString uri = url;

    g_object_set(G_OBJECT(udpsrc),"uri",uri.toUtf8().data(),"caps",caps,NULL);
    gst_object_unref(udpsrc);
    return true;

}

void CQMedia::setVolume(double _volume)
{
    volume=_volume;
    if(silenceState)
        return;
    GstElement *vol = gst_bin_get_by_name((GstBin *)pipeline,"audiovol");
    if(vol != NULL)
        g_object_set(vol,"volume",lineFun(volume),NULL);
}
double CQMedia::getVolume()
{
    return this->volume;
}

void CQMedia::setSilence(bool toggle)
{
    if(toggle)
    {
        GstElement *vol = gst_bin_get_by_name((GstBin *)pipeline,"audiovol");
        if(vol != NULL)
            g_object_set(vol,"volume",0.0,NULL);
    }
    else
    {
        GstElement *vol = gst_bin_get_by_name((GstBin *)pipeline,"audiovol");
        if(vol != NULL)
            g_object_set(vol,"volume",lineFun(volume),NULL);
    }
    silenceState = toggle;
}

void CQMedia::_updateDecoder()
{
    GstElement *videodecoder = gst_bin_get_by_name((GstBin*)pipeline,"v_dec");
    GstStateChangeReturn ret=gst_element_set_state(videodecoder,GST_STATE_NULL);
    if(GST_STATE_CHANGE_SUCCESS==ret)
    {
        qDebug("set videodecoder to null SUCCESS!!");
        if(gst_bin_remove(GST_BIN(pipeline),videodecoder))
        {
            qDebug("remove videodecoder success!!");
            int refCount = GST_OBJECT_REFCOUNT_VALUE(videodecoder);
            for(int i = 0;i < refCount; i++)
                gst_object_unref(videodecoder);
            videodecoder =  gst_element_factory_make("vpudec","v_dec");
            g_object_set(G_OBJECT(videodecoder),"parser",false,"dbkenable",false,"profiling",false,
                         "framedrop",true,"min-latency",true,"fmt",(guint64)0,NULL);
            GstElement *queue2 = gst_bin_get_by_name((GstBin*)pipeline,"queue2");
            GstElement *v_sink = gst_bin_get_by_name((GstBin*)pipeline,"v_sink");
            gst_bin_add_many (GST_BIN (pipeline),videodecoder,NULL);
            if(gst_element_link_many ( queue2,videodecoder,v_sink,NULL))
            {
                qDebug("link videodecoder  SUCCESS!!");
            }
            else
            {
                qDebug("link videodecoder  FAILED!!");
            }
            gst_object_unref(queue2);
            gst_object_unref(v_sink);
        }
        else
        {
            qDebug("remove videodecoder failed!!");
        }
    }
    else
    {
        qDebug("set videodecoder to null FAILED!! 456");
    }
}
void CQMedia::_updateDemux()
{
    GstElement *aiurdemux = gst_bin_get_by_name((GstBin*)pipeline,"aiurdemux");
    if (aiurdemux==NULL)
        qDebug("-------111-------ERROR:aiurdemux==NULL");
    GstStateChangeReturn ret=gst_element_set_state(aiurdemux,GST_STATE_NULL);
    if(GST_STATE_CHANGE_SUCCESS==ret)
    {
        qDebug("set aiurdemux to null SUCCESS!!");
        if(gst_bin_remove(GST_BIN(pipeline),aiurdemux))
        {
            qDebug("remove aiurdemux success!!");
            if (aiurdemux == NULL)
                qDebug("-------222-------ERROR:aiurdemux==NULL");
            sleep(1);
            gst_object_unref(aiurdemux);
            aiurdemux =  gst_element_factory_make("aiurdemux","aiurdemux");
            if(devType == ROOM || devType == SUBVIDEO)
                g_object_set(G_OBJECT(aiurdemux),"streaming_latency",(guint64)3000,NULL);
            else
                g_object_set(G_OBJECT(aiurdemux),"streaming_latency",(guint64)3000,NULL);

            GstElement *queue1 = gst_bin_get_by_name((GstBin*)pipeline,"queue1");
            GstElement *queue2 = gst_bin_get_by_name((GstBin*)pipeline,"queue2");
            GstElement *queue3 = gst_bin_get_by_name((GstBin*)pipeline,"queue3");
            qDebug("queue3 is %p",queue3);
            gst_bin_add_many (GST_BIN (pipeline),aiurdemux,NULL);
            if(gst_element_link ( queue1,aiurdemux))
            {
                qDebug("link aiurdemux  SUCCESS!!");
            }
            else
            {
                qDebug("link aiurdemux  FAILED!!");
            }
            g_signal_connect (aiurdemux, "pad-added", G_CALLBACK (pad_added_handler), queue2);
            g_signal_connect (aiurdemux, "pad-added", G_CALLBACK (pad_added_handler), queue3);

            qDebug("queue %d , %d ,%d!!",queue1,queue2,queue3);
            gst_object_unref(queue1);
            gst_object_unref(queue2);
            gst_object_unref(queue3);
        }
        else
        {
            qDebug("remove aiurdemux failed!!");
        }
    }
    else
    {
        qDebug("set aiurdemux to null FAILED!!");
    }
}




回复

使用道具 举报

16

主题

34

帖子

196

积分

注册会员

Rank: 2

积分
196
沙发
 楼主| 发表于 2017-10-14 18:24:53 | 只看该作者
本帖最后由 zp279 于 2017-10-14 18:26 编辑

我的邮箱是 zp279@163.com
回复 支持 反对

使用道具 举报

36

主题

745

帖子

2872

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2872
板凳
发表于 2017-10-16 09:10:58 | 只看该作者
zp279 发表于 2017-10-14 18:24
我的邮箱是 zp279@163.com

是网络视频流播放吗
回复 支持 反对

使用道具 举报

16

主题

34

帖子

196

积分

注册会员

Rank: 2

积分
196
地板
 楼主| 发表于 2017-10-16 09:39:12 | 只看该作者
软件01 发表于 2017-10-16 09:10
是网络视频流播放吗

是网络视频流,server组播.ts文件,EK200接收播放udp://225.0.0.1:2001
回复 支持 反对

使用道具 举报

36

主题

745

帖子

2872

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2872
5#
发表于 2017-10-17 09:13:29 | 只看该作者
zp279 发表于 2017-10-16 09:39
是网络视频流,server组播.ts文件,EK200接收播放udp://225.0.0.1:2001

网络视频流,我们测试过rtsp的,应该没什么问题的,但是没测UDP的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|明远智睿  

GMT+8, 2024-11-23 18:36 , Processed in 0.065452 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表