gstreamer pipeline添加 caps 于插件之间

前端之家收集整理的这篇文章主要介绍了gstreamer pipeline添加 caps 于插件之间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

注:如果插件没有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 stream\n");
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: %s\n",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: %s\n",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 playback\n");
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
return 0;
}

原文链接:https://www.f2er.com/javaschema/282863.html

猜你在找的设计模式相关文章