Add bus watches

parent 7b2ce2d2
......@@ -35,6 +35,12 @@ typedef struct {
// get this from gst-rfc3551.h
#define CAPS "application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)G722,payload=(int)9"
/* TODO:
* watch the gstreamer busses
* remove previously linked pads (if any) in the "pad-added" handler
* construct the capabilities string from programmatically
*/
static GMainLoop *loop;
/* rtpbin adds a pad once the payload is verified */
......@@ -42,6 +48,8 @@ static void
pad_added_cb (GstElement *rtpbin, GstPad *srcpad, GstElement *depayloader)
{
GstPad *sinkpad;
/* there might still be another rtp src bin linked to the depayloader */
GstPad *other_srcpad;
g_debug ("pad added: %s", GST_PAD_NAME (srcpad));
......@@ -67,11 +75,46 @@ pad_removed_cb (GstElement *rtpbin, GstPad *srcpad, GstElement *depayloader)
gst_object_unref (sinkpad);
}
static gboolean
bus_cb (GstBus *bus, GstMessage *message, gpointer data)
{
g_autoptr (GError) error = NULL;
g_autofree gchar *msg;
RtpData *rtpdata = data;
g_debug ("Got %s message", GST_MESSAGE_TYPE_NAME (message));
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error (message, &error, &msg);
g_error ("Error: %s", msg);
break;
case GST_MESSAGE_WARNING:
gst_message_parse_warning (message, &error, &msg);
g_warning ("Warning: %s", msg);
break;
case GST_MESSAGE_EOS:
g_debug ("Received end of stream");
g_main_loop_quit (loop);
break;
default:
g_debug ("Unhandled message type");
}
/* keep watching for messages on the bus */
return TRUE;
}
int
main (int argc, char **argv)
{
RtpData data;
GstBus *bus;
GstBus *bus_send;
GstBus *bus_recv;
guint bus_watch_send, bus_watch_recv;
GstCodec *codec = NULL;
GstPad *srcpad, *sinkpad;
GstCaps *caps;
......@@ -111,6 +154,12 @@ main (int argc, char **argv)
data.send_pipeline = gst_pipeline_new ("rtp-send-pipeline");
data.recv_pipeline = gst_pipeline_new ("rtp-recv-pipeline");
/* get the busses and establish watches */
bus_send = gst_pipeline_get_bus (GST_PIPELINE (data.send_pipeline));
bus_recv = gst_pipeline_get_bus (GST_PIPELINE (data.recv_pipeline));
bus_watch_send = gst_bus_add_watch (bus_send, bus_cb, &data);
bus_watch_recv = gst_bus_add_watch (bus_recv, bus_cb, &data);
if (!data.send_pipeline || !data.recv_pipeline ||
!data.audiosink || !data.audiosrc || !data.send_rtpbin || !data.recv_rtpbin ||
!data.decoder || !data.encoder || !data.depayloader || !data.payloader ||
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment