gstreamer stop streaming on silence
I have two terminals open on my ubuntu machine. The idea is to speak into the microphone and then play it back over the speaker. On the first terminal I set up a gstreamer speaker with the command:
gst-launch-0.10 pulsesrc ! audioconvert ! audio/x-raw-int,channels=1,depth=16,width=16,rate=22000 ! rtpL16pay ! udpsink host=localhost port=5000
the listener on the other terminal i use this command
gst-launch-0.10 -v udpsrc port=5000 ! "application/x-rtp,media=(string)audio, clock-rate=(int)22000, width=16, height=16, encoding-name=(string)L16, encoding-params=(string)1, channels=(int)1, channel-positions=(int)1, payload=(int)96" ! rtpL16depay ! audioconvert ! alsasink sync=false
What i want to now do is start the code, and automatically stop the stream when there is no sound for about 2 second. How should i go about doing this?
Udpsrc has a property called "timeout", by setting this property the element will post a message on the pipeline bus in case no package is received in a specific lapse of time. Your receiving pipeline should look something like this:
gst-launch-0.10 -v udpsrc port=5000 timeout=2000 ! "application/x-rtp,media=(string)audio, clock-rate=(int)22000, width=16, height=16, encoding-name=(string)L16, encoding-params=(string)1, channels=(int)1, channel-positions=(int)1, payload=(int)96" ! rtpL16depay ! audioconvert ! alsasink sync=false
The bus callback then should look something like this:
gboolean
bus_callback (GstBus * bus, GstMessage * message, gpointer data)
{
GError *error;
gchar *parsed_txt;
const GstStructure *st = gst_message_get_structure (message);
const gchar *typename = GST_MESSAGE_TYPE_NAME (message);
const gchar *srcname = GST_MESSAGE_SRC_NAME (message);
GST_LOG ("New %s message from %s: %s", typename, srcname,
st ? gst_structure_get_name(st) : "(null)");
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_INFO:
gst_message_parse_info (message, &error, &parsed_txt);
g_print ("%sn", parsed_txt);
g_free (parsed_txt);
g_error_free (error);
break;
case GST_MESSAGE_ERROR:
gst_message_parse_error (message, &error, &parsed_txt);
GST_ERROR ("%s (%s)", error->message,
parsed_txt ? parsed_txt : "no debug info");
if (parsed_txt)
g_free (parsed_txt);
GST_DEBUG ("No error handling callback registered");
break;
case GST_MESSAGE_ELEMENT:
/* We don't care for messages other than timeouts */
if (!gst_structure_has_name (st, "GstUDPSrcTimeout"))
break;
GST_WARNING ("Timeout received from udpsrc");
gst_element_set_state(GST_ELEMENT (pipeline),GST_STATE_NULL));
break;
default:
break;
}
Good Luck!
链接地址: http://www.djcxy.com/p/43996.html上一篇: 在android手机中使用gstreamer流式传输网络内容
下一篇: gstreamer停止沉默流媒体