我写了一个测试输出选择器的程序 我使用的管道是
--> alsasink
audiotestsrc --> output-selector --|
--> alsasink
以下是代码
#include <gst/gst.h>
#include <glib.h>
int main(int argc, char*argv[]){
GstElement *pipeline, *alsasrc, *outputsel, *alsasink, *alsasink1;
GstPad *sink_pad1, *sink_pad2, *output_sel_pad1, *output_sel_pad2;
setenv("GST_DEBUG","*:3", 1);
//Gstreamer Initialization
gst_init(&argc, &argv);
//Setting up pipeline and elements
pipeline = gst_pipeline_new ("output selector tester");
alsasrc = gst_element_factory_make ("audiotestsrc", "alsa source");
alsasink1 = gst_element_factory_make ("alsasink", "fake sink");
alsasink = gst_element_factory_make ("alsasink", "alsa sink");
outputsel = gst_element_factory_make ("output-selector","output");
gst_bin_add_many (GST_BIN(pipeline), alsasrc, outputsel, alsasink1, alsasink, NULL);
if(!gst_element_link (alsasrc, outputsel)){
printf("Error linking");
return -1;
}
//Input Selector pad settings
output_sel_pad1 = gst_element_get_request_pad (outputsel, "src%d");
output_sel_pad2 = gst_element_get_request_pad (outputsel, "src%d");
sink_pad1 = gst_element_get_static_pad (alsasink, "sink");
sink_pad2 = gst_element_get_static_pad (alsasink1, "sink");
if(gst_pad_link (output_sel_pad1, sink_pad1) != GST_PAD_LINK_OK){
printf("Error linking");
return -1;
}
if(gst_pad_link (output_sel_pad2, sink_pad2) != GST_PAD_LINK_OK){
printf("Error linking");
return -1;
}
gst_element_set_state (pipeline, GST_STATE_NULL);
g_object_set (G_OBJECT (outputsel), "pad-negotiation-mode", 2, NULL);
g_object_set (G_OBJECT (outputsel), "resend-latest", TRUE, NULL);
g_object_set (G_OBJECT(outputsel), "active-pad", output_sel_pad2, NULL);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
getchar();
gst_object_unref (pipeline);
return 0;
}
但我听不到任何声音。 我尝试将它切换到其他垫也没有声音。
但是当我尝试从bin中移除alsasink1或alsasink时,它的工作,切换也发生了,我可以在一个打击垫上听到声音。
我使用下面的命令编译程序
gcc test.c -o test -Wall `pkg-config --cflags --libs gstreamer-0.10`
任何帮助都会非常棒,并提前感谢。
答案 0 :(得分:0)
在将管道设置为运行状态
之前,只需添加以下行g_object_set(G_OBJECT(alsasink1), "async", FALSE, NULL);
g_object_set(G_OBJECT(alsasink), "async", FALSE, NULL);
g_object_set(G_OBJECT(alsasink1), "sync", FALSE, NULL);
g_object_set(G_OBJECT(alsasink), "sync", FALSE, NULL);
问题解决了。
当audiotestsrc用作源时,设置&#34; async&#34;假的就足够了。但是如果source是alsasrc那么&#34; async&#34;和&#34;同步&#34;需要设置为FALSE。