RTSP server doesn't stop when watchdog is triggered.
Nikita Pawar via gstreamer-devel <[email protected]>
| Newsgroups | gmane.comp.video.gstreamer.devel |
|---|---|
| Message-ID | <CAEE3G1jLjznOJmvWEKP-131KOdx5_JMpXNx0C4-1ec4a086wCQ@mail.gmail.com> |
Hi, I am new to this. Please help me to solve this problem. We have a script that is an rtsp_server. This script on the running stream is being provided and it keeps in running state even if there is no media flowing through it. I want the scripts to exit once there is no-media in the pipeline and once the watchdog is triggered the script should get excited. Please revert back as soon as possible. Thankyou in advance Attaching script along with this email.
test-launch1.c
(text/x-csrc, 4.4 KB)
#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
#include <gst/rtsp-server/rtsp-media-factory.h>
#define DEFAULT_RTSP_PORT "8554"
#define DEFAULT_DISABLE_RTCP FALSE
static char *port = (char *) DEFAULT_RTSP_PORT;
GstElement *pipeline_bin;
struct Data {
GstRTSPServer *server;
GMainLoop *loop;
};
// Override function
GstElement *custom_create_element(GstRTSPMediaFactory *factory, const GstRTSPUrl *url)
{
return pipeline_bin;
}
// Override class
GstRTSPMediaFactory *custom_pipeline_factory()
{
GstRTSPMediaFactory *factory = gst_rtsp_media_factory_new();
GstRTSPMediaFactoryClass *klass = GST_RTSP_MEDIA_FACTORY_GET_CLASS(factory);
klass->create_element = custom_create_element;
return factory;
}
void on_error_signal(GstBus *bus_, GstMessage *msg_, gpointer loop_)
{
g_print ("Got %s message from %s on bus\n", GST_MESSAGE_TYPE_NAME(msg_), GST_MESSAGE_SRC_NAME(msg_));
//g_main_loop_quit ((GMainLoop *)loop_);
}
void on_eos_signal(GstBus *bus_, GstMessage *msg_, gpointer loop_)
{
g_print ("Got %s message on bus\n", GST_MESSAGE_TYPE_NAME(msg_));
//g_main_loop_quit ((GMainLoop *)loop_);
}
static gboolean
handle_message_callback (GstRTSPMedia * self,
GstMessage * message,
gpointer data)
{
struct Data *user_data = (struct Data *)data;
if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_EOS){
g_print("RECEIVED EOS!\n");
return TRUE;
}
else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
g_print("RECEIVED ERROR!\n");
g_main_loop_quit ((GMainLoop *) (user_data->loop));
//return TRUE;
}
return TRUE; // Return TRUE to indicate successful message handling
}
void media_configure(GstRTSPMediaFactory* factory,
GstRTSPMedia* media,
gpointer data)
{
g_signal_connect(media, "handle-message", G_CALLBACK(handle_message_callback), &data);
}
int
main (int argc, char *argv[])
{
struct Data data;
GstRTSPMediaFactory *factory;
GstRTSPMountPoints *mounts;
gst_init (&argc, &argv);
/* create the main loop */
data.loop = g_main_loop_new (NULL, FALSE);
/* create a server instance */
data.server = gst_rtsp_server_new ();
g_object_set (data.server, "service", port, NULL);
/* mount the path */
mounts = gst_rtsp_server_get_mount_points (data.server);
//pipeline = gst_pipeline_new ("media-pipeline");
GstBin pipeline;
/* create launch pipeline */
// const gchar *launchline = "( videotestsrc num-buffers=-1 is-live=true pattern=ball animation-mode=frames ! video/x-raw,width=1920,height=1080 ! x264enc ! h264parse ! rtph264pay name=pay
// 0 config-interval=1 )";
const gchar *launchline = "( udpsrc port=8989 ! watchdog timeout=5000 ! video/x-raw,width=1920,height=1080 ! openh264enc ! h264parse ! rtph264pay name=pay0 config-interval=1 )";
GError *error = NULL;
//pipeline_bin = gst_parse_launch_full(launchline, NULL, GST_PARSE_FLAG_PLACE_IN_BIN, &error);
pipeline_bin = gst_parse_launch(launchline, &error);
if (pipeline_bin == NULL)
g_critical ("could not parse launch syntax (%s): %s", launchline,
(error ? error->message : "unknown reason"));
if (error)
g_error_free (error);
/* create media factory */
factory = gst_rtsp_media_factory_new(); //custom_pipeline_factory();
g_signal_connect(factory, "media-configure", G_CALLBACK(media_configure), &data);
//gst_rtsp_media_factory_set_shared (factory, TRUE);
gst_rtsp_media_factory_set_launch(factory,launchline);
gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
g_object_unref (mounts);
/* Add bus watch */
//GstBus *bus = gst_element_get_bus(pipeline_bin);
//msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Free resources */
//if (msg != NULL)
// gst_message_unref (msg);
//gst_object_unref (bus);
//gst_bus_add_signal_watch(bus);
//g_signal_connect(bus, "message::error", G_CALLBACK(on_error_signal), data.loop);
//g_signal_connect(bus, "message::eos", G_CALLBACK(on_eos_signal), data.loop);
//gst_object_unref(bus);
/* attach the server to the default maincontext */
guint id;
if ((id = gst_rtsp_server_attach (data.server, g_main_loop_get_context(data.loop))) == 0)
{
g_print ("failed to attach the server\n");
return -1;
}
else {
g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port);
}
g_main_loop_run (data.loop);
g_object_unref(data.server);
g_print("Exitting...\n");
return 0;
}