如何解决无法将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 举报,一经查实,本站将立刻删除。