Gtreamer与Qt无法回送音频

时间:2012-01-07 22:57:41

标签: qt gstreamer

我可以播放单拍音频。但是,没有调用注册回调函数,它负责在流结束时循环返回。

下面是在Class中封装GStreame函数的代码片段。代码中显示的最后一个函数是类外的回调函数。

从调试输出我开始知道永远不会调用回调函数。你能指导我让音频循环工作吗?

//constructor
Sound::Sound(QObject *parent) : QObject(parent)
{
    gst_init(NULL,NULL);
    pipeline = gst_element_factory_make("playbin2", NULL);
    bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
    ...
}

//destructor
Sound::~Sound(){
    gst_object_unref(bus);
    gst_object_unref (pipeline);
}

void Sound::playSound(QString name,bool stopBeforePlay){
       ...
       gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
}


void Sound::setLoop(bool isLoop){
   if(isLoop){
       qDebug("Setting Call back for loop");
       loopSet = true;
       callBackID = gst_bus_add_watch (bus, loopCallback, pipeline);
   }else if(loopSet){
       qDebug("Unsetting Call back for loop");
       g_source_remove(callBackID);
   }
}


// A call back function outside the class.
gboolean loopCallback(GstBus *bus, GstMessage *msg, gpointer data){
     qDebug("In callback\n");
     GstElement *play = GST_ELEMENT(data);
     switch (GST_MESSAGE_TYPE(msg))
     {
        case GST_MESSAGE_EOS:
            if (!gst_element_seek(play,
                        1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
                        GST_SEEK_TYPE_SET, 0,
                        GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
                qDebug("Seek failed!\n");
            }
            break;
        default:
            break;
    }
    return TRUE;
}

0 个答案:

没有答案