GstElement
*
pipeline,
*
fakesrc1,
*
udpsink1,
*
fakesrc2,
*
udpsink2;
static
gboolean on_timeout(gpointer data)
{
g_message(
"
ENTERING TIMEOUT PART START...
"
);
fakesrc2
=
gst_element_factory_make(
"
fakesrc
"
, NULL);
g_object_set (G_OBJECT(fakesrc2),
"
filltype
"
,
3
, NULL);
g_object_set (G_OBJECT(fakesrc2),
"
num-buffers
"
,
5
, NULL);
gchar
*
rtpuri
=
g_strdup_printf (
"
udp://202.119.24.12:5000
"
);
udpsink2
=
gst_element_make_from_uri (GST_URI_SINK, rtpuri, NULL);
g_free (rtpuri);
//
Add and link
//
gst_bin_add_many(GST_BIN(pipeline), fakesrc2, udpsink2, NULL);
gst_element_link(fakesrc2, udpsink2);
gst_element_set_state(fakesrc2, GST_STATE_PLAYING);
gst_element_set_state(udpsink2, GST_STATE_PLAYING);
GstState cur, pending;
gst_element_get_state(fakesrc2,
&
cur,
&
pending, GST_CLOCK_TIME_NONE);
g_message(
"
fakesrc2 cur state is %d, pending state is %d
"
, cur, pending);
gst_element_get_state(udpsink2,
&
cur,
&
pending, GST_CLOCK_TIME_NONE);
g_message(
"
udpsink2 cur state is %d, pending state is %d
"
, cur, pending);
g_message(
"
ENTERING TIMEOUT PART END...
"
);
return
FALSE;
}
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_print(
"
The message's owner is: %s\n
"
, GST_OBJECT_NAME(GST_MESSAGE_SRC(msg)));
//
g_main_loop_quit(loop);
break
;
case
GST_MESSAGE_ERROR: {
gchar
*
debug;
GError
*
err;
gst_message_parse_error(msg,
&
err,
&
debug);
g_print(
"
Error debug info: %s\n
"
, debug);
g_free(debug);
g_print(
"
Error: %s\n
"
, err
->
message);
g_error_free(err);
g_main_loop_quit(loop);
break
;
}
case
GST_MESSAGE_NEW_CLOCK: {
GstClock
*
newclock;
gst_message_parse_new_clock(msg,
&
newclock);
g_message(
"
Got new clock, clock name is %s
"
, GST_OBJECT_NAME(GST_OBJECT(newclock)));
break
;
}
case
GST_MESSAGE_ASYNC_START: {
g_message(
"
Got ASYNC_START message.
"
);
break
;
}
case
GST_MESSAGE_ASYNC_DONE: {
g_message(
"
Got ASYNC_DONE message.
"
);
break
;
}
default
:
break
;
}
return
TRUE;
}
int
main(
int
argc,
char
*
argv[])
{
GMainLoop
*
loop;
GstBus
*
bus;
gst_init(
&
argc,
&
argv);
loop
=
g_main_loop_new(NULL, FALSE);
//
create elements
pipeline
=
gst_element_factory_make(
"
pipeline
"
,
"
pipeline
"
);
fakesrc1
=
gst_element_factory_make(
"
fakesrc
"
, NULL);
g_object_set (G_OBJECT(fakesrc1),
"
filltype
"
,
3
, NULL);
g_object_set (G_OBJECT(fakesrc1),
"
num-buffers
"
,
5
, NULL);
gchar
*
rtpuri
=
g_strdup_printf (
"
udp://202.119.24.12:5000
"
);
udpsink1
=
gst_element_make_from_uri (GST_URI_SINK, rtpuri, NULL);
g_free (rtpuri);
if
(
!
pipeline
||
!
fakesrc1
||
!
udpsink1) {
g_print(
"
Elements could not be created!\n
"
);
return
-
1
;
}
bus
=
gst_pipeline_get_bus(GST_PIPELINE(pipeline));
gst_bus_add_watch(bus, bus_call, loop);
gst_object_unref(bus);
//
Add and link
gst_bin_add_many(GST_BIN(pipeline), fakesrc1, udpsink1, NULL);
gst_element_link(fakesrc1, udpsink1);
//
now play
g_print(
"
Setting to PLAYING\n
"
);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
g_print(
"
Running\n
"
);
//
add timeout callback
g_timeout_add(
4000
, (GSourceFunc)on_timeout, NULL);
g_main_loop_run(loop);
//
clean up
g_print(
"
Returned, stopping playback\n
"
);
gst_element_set_state(pipeline, GST_STATE_NULL);
g_print(
"
Deleting pipeline\n
"
);
gst_object_unref(GST_OBJECT(pipeline));
return
0
;
}