Hello, I'm trying to integrate gstreamer into my application with appsrc/appsink, so this my first step in that direction. The goal of this code is to just input random noise into appsource to be played on the speakers. The code is the following, followed by the runtime errors.
-------------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> #include <gst/gst.h> #include <gst/app/gstappsrc.h> #include <gst/app/gstappbuffer.h> #include <pthread.h> /*gcc -Wall $(pkg-config --cflags --libs gstreamer-0.10) -pthread -lgstapp-0.10 src.c -o src*/ const gchar *audio_caps ="audio/x-raw-int,rate=11000,channels=1"; typedef struct { GMainLoop *loop; GstElement *pipeline; GstElement *source; guint source_id; guint num_frame; } AppData; int main (int argc, char *argv[]) { AppData *app = NULL; gchar *string = NULL; GstBus *bus = NULL; GstElement *appsrc = NULL; srand ( time(NULL) ); gst_init (&argc, &argv); app = g_new0 (AppData, 1); app->loop = g_main_loop_new (NULL, FALSE); string = g_strdup_printf ("appsrc -v name=source caps=\"%s\" ! audioconvert ! audioresample ! osssink",audio_caps); app->pipeline = gst_parse_launch (string, NULL); g_free (string); if (app->pipeline == NULL) { g_print ("Bad pipeline\n"); return -1; } appsrc = gst_bin_get_by_name (GST_BIN (app->pipeline), "source"); app->source = appsrc; /* add watch for messages */ bus = gst_element_get_bus (app->pipeline); gst_object_unref (bus); GstBuffer *buffer; buffer=gst_buffer_new_and_alloc(5000); int i; for (i=0; i<5000;i++) buffer->data[i]=rand()%10000; gst_app_src_push_buffer(GST_APP_SRC (app->source),buffer); gst_app_src_end_of_stream (GST_APP_SRC (app->source)); /* go to playing and wait in a mainloop */ gst_element_set_state (app->pipeline, GST_STATE_PLAYING); g_main_loop_run(app->loop); gst_element_set_state (app->pipeline, GST_STATE_NULL); /* Cleaning up */ gst_object_unref (app->source); gst_object_unref (app->pipeline); g_main_loop_unref (app->loop); g_free (app); return 0; } ------------------------------------------------------------------------------------------- wildcat@ubuntu:~/Desktop$ gcc -Wall -pthread -lgstapp-0.10 $(pkg-config --cflags --libs gstreamer-0.10) srcdemo.c -o srcdemo;./srcdemo ** (srcdemo:2845): CRITICAL **: gst_app_src_push_buffer_full: assertion `GST_IS_APP_SRC (appsrc)' failed ** (srcdemo:2845): CRITICAL **: gst_app_src_end_of_stream: assertion `GST_IS_APP_SRC (appsrc)' failed ------------------------------------------------------------------------------------------- These messages only come up when I use the verbose option, and it still continues to run with no sound. Are there any glaring problems? (Also, are my audio caps sufficient?) As far as the buffer_full issues, the error remains if I create a buffer of size 50 or 50,000. Also, if my code needs ripped apart, my application needs to run alongside the gstreamer (in its own thread) and needs to input/output data at its own pace; so I can't use gstreamer's callback functions to input data when gstreamer needs it, but instead would prefer to have appsink/source block itself while waiting for data. Thanks so much, and any general pointers about my program/goals will be appreciated too. |
Free forum by Nabble | Edit this page |