gpt4 book ai didi

c - 从 appsink 解析数据时出现内部数据流错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:50:30 29 4
gpt4 key购买 nike

我正在使用 gstreamer 1.0 编写一个 C 应用程序

我正在将 alsa 音频源录制到 appsink 中,以便解析数据并稍后显示图表。

create_loop() 函数在初始化 gst_init 后在 main 中调用

我遇到的问题是两次收到 sample 后我收到错误内部数据流错误。

new sample
buffer size 1280
new sample
buffer size 1280
debug: gstbasesrc.c(2865): gst_base_src_loop (): /GstPipeline:audio-player/GstAlsaSrc:alsasrc0:
streaming task paused, reason custom-error (-335484816)
Error: Internal data flow error.
Returned, stopping playback
Deleting pipeline

当我多次运行它时,有时它可以正常工作,但大多数时候它会在 2 次迭代后停止。我什至尝试使用 audiotestsrc 而不是 alsasrc,但我遇到了同样的问题。

这是代码:

#include <gst/gst.h>
#include <glib.h>
#include <gst/app/gstappsink.h>

static gboolean
bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{

GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {

case GST_MESSAGE_EOS:
g_print ("End of stream\n");
g_main_loop_quit (loop);
break;

case GST_MESSAGE_ERROR: {
gchar *debug;
GError *error;

gst_message_parse_error (msg, &error, &debug);
g_print("debug: %s\n",debug);
g_free (debug);

g_printerr ("Error: %s\n", error->message);
g_error_free (error);

g_main_loop_quit (loop);
break;
}
default:
break;
}

return TRUE;
}

void new_sample(GstElement *sink, gpointer *data) {
g_print("new sample\n");
GstSample *sample = gst_app_sink_pull_sample(GST_APP_SINK(sink));
if (sample != NULL) {
GstBuffer *buffer = gst_sample_get_buffer(sample);
GstMapInfo map;
if (buffer != NULL) {
gst_buffer_map(buffer, &map, GST_MAP_READ);
g_print("buffer size %zu\n",map.size);
gst_buffer_unmap(buffer, &map);
gst_sample_unref(sample);

}
}

}


void create_loop()
{
GMainLoop *loop;

GstElement *pipeline, *source, *sink;
GstBus *bus;
guint bus_watch_id;

loop = g_main_loop_new (NULL, FALSE);



pipeline = gst_pipeline_new ("audio-player");
source = gst_element_factory_make ("alsasrc", NULL);
sink = gst_element_factory_make ("appsink", NULL);

gst_app_sink_set_emit_signals(GST_APP_SINK(sink),TRUE);
g_signal_connect(sink, "new-sample", G_CALLBACK(new_sample),NULL);

if (!pipeline || !source || !sink) {
g_printerr ("One element could not be created. Exiting.\n");
return;
}

g_object_set (G_OBJECT(source),"device","hw:3,0",NULL);

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

gst_bin_add_many (GST_BIN (pipeline),
source, sink, NULL);

gst_element_link (source, sink);
gst_element_set_state (pipeline, GST_STATE_PLAYING);

g_print ("Running...\n");
g_main_loop_run (loop);

g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);

g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
g_source_remove (bus_watch_id);
g_main_loop_unref (loop);

}

知道为什么会这样吗?

最佳答案

new-event的回调函数,应该返回一个GstFlowReturn类型,值为GST_FLOW_OK

这意味着:

函数定义为:

GstFlowReturn new_sample(GstElement *sink, gpointer *data) {
...

结束于:

return GST_FLOW_OK;

关于c - 从 appsink 解析数据时出现内部数据流错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22646749/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com