Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gstreamer:不能同时收听alsasrc的音频+录音?_C_Gstreamer_Alsa - Fatal编程技术网

Gstreamer:不能同时收听alsasrc的音频+录音?

Gstreamer:不能同时收听alsasrc的音频+录音?,c,gstreamer,alsa,C,Gstreamer,Alsa,我正在编写一个C应用程序,它使用gstreamer从电视调谐器录制音频 我有一个电视调谐器卡,它有一个类似hw:1,0的声卡。 当应用程序开始使用ALSA API时,默认情况下,音频源作为播放源访问 我想编写一个函数,使用GStreamer后端从这个源录制声音 我的下一个问题似乎涉及到一个小的比赛条件,涉及我的hw:1,0已经在使用中,需要能够记录一些东西 我能做些什么来让它工作 更新:播放声音不使用GStreamer API,如果alsa和libv4l2util可用,它将使用alsa函数自动启

我正在编写一个C应用程序,它使用gstreamer从电视调谐器录制音频

我有一个电视调谐器卡,它有一个类似hw:1,0的声卡。 当应用程序开始使用ALSA API时,默认情况下,音频源作为播放源访问

我想编写一个函数,使用GStreamer后端从这个源录制声音

我的下一个问题似乎涉及到一个小的比赛条件,涉及我的hw:1,0已经在使用中,需要能够记录一些东西

我能做些什么来让它工作

更新:播放声音不使用GStreamer API,如果alsa和libv4l2util可用,它将使用alsa函数自动启动V4L2设备hw:1.0和音频输出设备hw:0.0之间的音频流

我尝试停止ALSA流并使用Gstreamer元素:

int main (int argc, char *argv[])
{
    GstCaps *filter;

    GMainLoop *loop;
    GstBus *bus;

    GstElement *pipeline, *audiosource, *audiosink, *audioresample, *audiobin, *audiotee, *encodebin, *filesink, *savebin;

    GstEncodingProfile *profile;

    gst_init (&argc, &argv);
    loop = g_main_loop_new (NULL, FALSE);

    pipeline = gst_pipeline_new("pipeline");
    audiosource = gst_element_factory_make("alsasrc", NULL);
    audiosink = gst_element_factory_make("alsasink", NULL);
    audioresample = gst_element_factory_make("audioresample", NULL);
    audiotee = gst_element_factory_make("tee", NULL);
    encodebin = gst_element_factory_make("encodebin", NULL);
    filesink = gst_element_factory_make("filesink", NULL);

    audiobin = gst_bin_new ("abin");
    savebin = gst_bin_new ("sbin");

    profile = gst_get_encoding_profile(my.settings.profile);

    if (!pipeline || !audiosource || !audiosink || !audioresample || !audiobin)
            return -1;

    g_object_set(G_OBJECT(audiosource), "device", "hw:1,0", NULL);
    g_object_set(G_OBJECT(filesink), "location", "save.ogg", NULL);
    g_object_set(encodebin, "profile", profile, NULL);
    gst_encoding_profile_unref(profile);

    g_object_set(G_OBJECT(audiobin), "async-handling", TRUE, NULL);
    g_object_set(G_OBJECT(savebin), "async-handling", TRUE, NULL);


    bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
    gst_bus_add_watch (bus, bus_call, loop);
    gst_object_unref (bus);

    gst_bin_add_many (GST_BIN (audiobin), audiosource, audioresample, audiotee, audiosink, NULL);
    gst_bin_add_many (GST_BIN (savebin), encodebin, filesink, NULL);
    gst_bin_add_many (GST_BIN (pipeline), audiobin, savebin, NULL);

    filter = gst_caps_new_simple("audio/x-raw", "rate", G_TYPE_INT, 32000, NULL);
    if (!gst_element_link_filtered(audiosource, audioresample, filter))
            return -1;

    if (!gst_element_link_many(audioresample, audiotee, audiosink, NULL))
            return -1;

    gst_element_set_state (pipeline, GST_STATE_PLAYING);

    g_main_loop_run (loop);

    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (GST_OBJECT (pipeline));

    return 0;
}

现在我可以听到声音,录制开始,但创建的录制文件不包含任何数据。

在更新的问题中,我可以看到encodebin已添加到管道中,但未链接到音频T形三通,这将是您的问题。在您当前的代码中,使用无用的audiobin和savebin,我希望您在尝试这样做时也会遇到错误,沿着错误的元素层次结构。去掉这两个箱子,它应该可以工作。

这肯定不是完整的代码,这些元素甚至没有链接并添加到管道中,而且我看不到实际播放声音的元素。。请用实际代码更新您的问题。