注:如果插件没有caps属性,则需使用link_alsa_element_with_filter将caps置于两插件之间来实现。
转自:http://e2e.ti.com/support/embedded/linux/f/354/p/569574/2087961
#include <glib.h> #include <stdio.h> #include <string.h> #include <string> #include <pthread.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <fcntl.h> #include <sys/mman.h> #include <sys/ioctl.h>
#include <gst/gst.h> static gboolean link_alsa_element_with_filter (GstElement *element1,GstElement *element2) { /* CAPS to be linked: * audio/x-raw-int,signed=true,width=32,depth=32,format=S32LE,rate=96000,channels=4 * */ gboolean link_ok; GstCaps *caps; caps = gst_caps_new_simple ("audio/x-raw-int", "endianness",G_TYPE_INT,1234,255);">"signed",G_TYPE_BOOLEAN,TRUE,255);">"width",16,255);">"depth",255);">"channels",2,255);">"rate",44100,255);">NULL); link_ok = gst_element_link_filtered (element1,element2,caps); gst_caps_unref (caps); if (!link_ok) { g_warning ("Failed to link element1 and element2!(source->queue)"); } return link_ok; 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 streamn"); g_main_loop_quit (loop); break; case GST_MESSAGE_ERROR: { gchar *debug; GError *error; gst_message_parse_error (msg,&error,&debug); g_free (debug); g_printerr ("Error: %sn",error->message); g_error_free (error); default: return TRUE; /* Main function for audio pipeline initialization and looping streaming process */ gint main (gint argc,gchar **argv) { GMainLoop *loop; GstElement *pipeline; GstElement *source; GstElement *queues; GstElement *sink; GstBus *bus; // guint bus_watch_id; // gboolean ret; /* Initialisation */ gst_init (&argc,&argv); loop = g_main_loop_new (NULL,FALSE); /* Creategstreamerelements: */ pipeline = gst_pipeline_new ("audio_stream"); source = gst_element_factory_make ("alsasrc","audio_source"); g_return_val_if_fail (source,-1); g_object_set (G_OBJECT (source),"device","plughw:0,0",NULL); queues = gst_element_factory_make ("queue","queues"); g_return_val_if_fail (queues,255);">sink = gst_element_factory_make ("alsasink","audio_sink"); g_return_val_if_fail (sink,255);">//g_object_set (G_OBJECT (sink),255);">/* Add a message handler */ bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); gst_bus_add_watch (bus,bus_call,loop); gst_object_unref (bus); /* Add elements to the bin before linking them. */ gst_bin_add (GST_BIN (pipeline),source);
/* Link the pipeline */ link_alsa_element_with_filter (source,255);">gst_element_link_pads (queues,"src",sink,"sink"); /* Set the pipeline to "playing" state */ g_print ("Playing: %sn",argv[1]); gst_element_set_state (pipeline,GST_STATE_PLAYING); /* Iterate */ g_print ("Running...n"); g_main_loop_run (loop); /* Out of the main loop,clean up nicely */ g_print ("Returned,stopping playbackn"); g_print ("Deleting pipelinen"); gst_object_unref (GST_OBJECT (pipeline)); return 0; } (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|