带有输出选择器的 Gstreamer 应用程序无法正常工作

Gtreamer application with output-selector not working

我写了一个程序来测试输出选择器。
我使用的管道是

                                    --> 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;
}

但是我听不到任何声音。 我也试过把它换到其他垫子上,但还是没有声音。

但是当我尝试从垃圾箱中取出 alsasink1 或 alsasink 时,它的工作正常,切换也在发生,我可以在一个垫子上听到声音。

我使用下面的命令来编译程序

gcc test.c -o test -Wall `pkg-config --cflags --libs gstreamer-0.10`

任何帮助都将非常有用,在此先感谢。

只需在将管道设置为 运行 状态之前添加以下行

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 被用作源时,将 "async" 设置为 FALSE 就足够了。但是如果源是 alsasrc 那么 "async" 和 "sync" 都需要设置为 FALSE.