Add or remove elements to (from) a tee dynamically
trinitonadam
trinitonadam at gmail.com
Wed Dec 23 15:21:58 PST 2015
I want to write an app that listening to the sound of the webcam and, if
necessary, to record sound.
The following example is the chain of elements:
/ [ queue | audioconvert | audioresample | alsasink ]
(*listen branch*)
alsasrc | tee
\ [ queue | level | encodebin | filesink ]
(*record branch*)
For this I wrote the following functions:
GstElement *src;
GstElement *tee;
GstElement *play_queue;
GstElement *audioconvert;
GstElement *audioresample;
GstElement *encoder;
GstElement *filesink;
GstElement *record_queue;
GstElement *alsasink;
GstElement *bin;
GstElement *level;
GstElement *encodebin;
GstElement *pipeline;
GstBus *bus;
gboolean bus_call(GstBus *bus, GstMessage *message, gpointer data)
{
switch (GST_MESSAGE_TYPE (message))
case GST_MESSAGE_ERROR:
break;
case GST_MESSAGE_EOS:
break;
default:
break;
return TRUE;
}
void cleanup()
{
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
}
gboolean start_playback(void)
{
pipeline = gst_pipeline_new("pipeline");
src = gst_element_factory_make("alsasrc", NULL);
tee = gst_element_factory_make("tee", NULL);
play_queue = gst_element_factory_make("queue", NULL);
audioconvert = gst_element_factory_make("audioconvert", NULL);
audioresample = gst_element_factory_make("audioresample", NULL);
sink = gst_element_factory_make("alsasink", NULL);
if (!src || !tee || !play_queue || audioresample || audioconvert || !sink)
return FALSE;
bin = gst_bin_new("bin");
g_object_set (src, "device", "hw:1", NULL);
gst_bin_add_many(GST_BIN(bin), src, tee, play_queue, audioconvert,
audioresample, sink, NULL);
gst_bin_add(GST_BIN(pipeline), bin);
gst_element_link(src, tee);
gst_element_link(tee, play_queue);
gst_element_link(queue, audioconvert);
gst_element_link(audioconvert, audioresample);
gst_element_link(audioresample, sink);
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, NULL);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
gst_object_unref(bus);
return 0;
}
gboolean start_recording(gchar *location)
{
GTimeVal time;
gchar *filename;
encoder = gst_element_factory_make("flacenc", NULL);
filesink = gst_element_factory_make("filesink", NULL);
record_queue = gst_element_factory_make("queue", NULL);
if (!encoder || !record_queue || !filesink)
return FALSE;
g_get_current_time(&time);
filename = g_strdup_printf("%s/%s.flac", location,
g_time_val_to_iso8601(&time));
g_object_set(filesink, "location", filename, NULL);
g_free(filename);
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_bin_add_many(GST_BIN(bin), encoder, filesink, record_queue, NULL);
gst_element_link(tee, record_queue);
gst_element_link(record_queue, encoder);
gst_element_link(encoder, filesink);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
return TRUE;
}
void stop_recording(void)
{
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_element_unlink(encoder, filesink);
gst_element_unlink(record_queue, encoder);
gst_element_unlink(tee, queue);
gst_bin_remove_many(GST_BIN(bin), encoder ,filesink, record_queue, NULL);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
}
I want to improve this functions.
I need to dynamically changing the pipeline to listen or (and) record sound
from webcam (add or remove elements to/from a tee dynamically) with same
like functions:
*start_payback
stop_payback
start_recording
stop_recording*
--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Add-or-remove-elements-to-from-a-tee-dynamically-tp4675008.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list