无法将Gstreamer管道设置为暂停状态

问题描述

    #include <gst/gst.h>
#include <gst/audio/audio.h>
#include <string.h>
//gst - launch - 1.0 filesrc location = file.wav !wavparse !audioresample !
//audioconvert !audio / x - raw,format = S16BE,channels = 1,rate = 8000 !filesink location = file.pcm




int main(int argc,char* argv[]) {
    GstElement* filesrc,*wavparser,*audioresample,* audioconvert,* filesink,*pipeline;
    GstStateChangeReturn ret;
    GstPad* pad1,*pad2;
    GstBus* bus;

    /*Initialize GStreamer*/
        gst_init(&argc,&argv);
        filesrc = gst_element_factory_make("filesrc","filesrc");
        wavparser = gst_element_factory_make("wavparse","wavParser");
        audioresample = gst_element_factory_make("audioresample","audioresample");
        audioconvert = gst_element_factory_make("audioconvert","audioconvert");
        filesink = gst_element_factory_make("filesink","filesink");
        pipeline = gst_pipeline_new("new-pipe-line");

        if (!filesrc || !wavparser || !audioresample || !audioconvert || !filesink || !pipeline) {
            g_print("not all elements init");
        }
        g_print("All elements init.\n");
        //setup all elements
        g_object_set(G_OBJECT (filesrc),"location","file.wav",NULL);
        g_object_set(G_OBJECT (filesink),"file.pcm",NULL);


        // add and linking elements to pipeline
        gst_bin_add_many(GST_BIN(pipeline),filesrc,wavparser,audioresample,audioconvert,filesink,NULL);
        if (!gst_element_link_many(filesrc,NULL)) {
            g_print("Failed to add elements in pipeline.\n");
            gst_object_unref(pipeline);
            return -1;
        }
        //GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(pipeline),GST_DEBUG_GRAPH_SHOW_ALL,"tempa"); // for drawing graph
        ret = gst_element_set_state(pipeline,GST_STATE_READY);
        if (ret == GST_STATE_CHANGE_FAILURE) {
            g_printerr("Unable to set the pipeline to the ready state.\n");
            gst_object_unref(pipeline);
            return -1;
        }
        ret = gst_element_set_state(pipeline,GST_STATE_PAUSED);
        if (ret == GST_STATE_CHANGE_FAILURE) {
            g_printerr("Unable to set the pipeline to the paused state.\n");
            gst_object_unref(pipeline);
            return -1;
        }
        ret = gst_element_set_state(pipeline,GST_STATE_PLAYING);
        if (ret == GST_STATE_CHANGE_FAILURE) {
            g_printerr("Unable to set the pipeline to the playing state.\n");
            gst_object_unref(pipeline);
            return -1;
        }

        return 0;
}

代码中,我只是创建元素,将它们添加到管道中并进行链接。 尝试更改管道状态时,我无法更改状态以暂停。 我越来越无法将管道设置为暂停状态。 使用命令可以正常工作。 gst-launch-1.0 filesrc位置= file.wav!wavparse!audioresample! audioconvert!filesink位置= file.pcm

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)