diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2009-09-13 02:09:45 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2009-09-13 02:09:45 +0800 |
commit | 5b446132bfb821106ce32a90539fc58e7475dbdb (patch) | |
tree | e7eb7f14febd6505cfc6aa9234889bad361e440a | |
parent | be659670cd160b0e8eb4fe604b38be3ad2c47c7f (diff) |
sopcastsrc: rename log category to sopcastsrc and make sure sp-sc get killed
-rw-r--r-- | src/gstscsrc.c | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/gstscsrc.c b/src/gstscsrc.c index 0817cf9..61f7f6a 100644 --- a/src/gstscsrc.c +++ b/src/gstscsrc.c @@ -43,8 +43,8 @@ #include <gst/base/gsttypefindhelper.h> #include "gstscsrc.h" -GST_DEBUG_CATEGORY_STATIC (scsrc_debug); -#define GST_CAT_DEFAULT scsrc_debug +GST_DEBUG_CATEGORY_STATIC (sopcastsrc_debug); +#define GST_CAT_DEFAULT sopcastsrc_debug static const GstElementDetails gst_sopcast_src_details = GST_ELEMENT_DETAILS ("Sopcast stream source", @@ -109,7 +109,7 @@ _do_init (GType type) g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info); - GST_DEBUG_CATEGORY_INIT (scsrc_debug, "scsrc", 0, + GST_DEBUG_CATEGORY_INIT (sopcastsrc_debug, "sopcastsrc", 0, "SCtream src"); } @@ -162,7 +162,7 @@ gst_sopcast_src_class_init (GstSopcastSrcClass * klass) gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_sopcast_src_create); gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_sopcast_src_change_state); - GST_DEBUG_CATEGORY_INIT (scsrc_debug, "scsrc", 0, + GST_DEBUG_CATEGORY_INIT (sopcastsrc_debug, "sopcastsrc", 0, "SCtream Source"); } @@ -302,8 +302,8 @@ gst_sopcast_src_send_first_request (GstSopcastSrc *src) if (n < 4) continue; if (reply[n] == '\n' && !strncmp (&reply[n - 3], "\r\n\r\n", 4)) { - reply[n + 1] = '\0'; - GST_DEBUG_OBJECT (src, "Server replied: %*s length: %d", n, reply, n); + reply[n - 3] = '\0'; + GST_DEBUG_OBJECT (src, "Server replied: %s", reply); return TRUE; } } @@ -395,7 +395,12 @@ failed: static gboolean gst_sopcast_src_helper_is_running (GstSopcastSrc *src) { - if (kill (src->helper_pid, 0) == 0) + int ret; + + do { + ret = kill (src->helper_pid, 0); + } while (ret < 0 && errno == EINTR); + if (ret == 0) return TRUE; GST_ERROR_OBJECT (src, "helper is not running."); @@ -645,7 +650,7 @@ gst_sopcast_src_spawn_helper (GstSopcastSrc * src) } static void -gst_sopcast_src_subproc_main (GstSopcastSrc * src, int sock) +gst_sopcast_src_subproc_main (GstSopcastSrc * src, pid_t ppid, int sock) { fd_set rfs; fd_set efs; @@ -663,6 +668,13 @@ gst_sopcast_src_subproc_main (GstSopcastSrc * src, int sock) signal (SIGHUP, SIG_IGN); signal (SIGINT, SIG_IGN); while (1) { + int error; + + if (getppid () != ppid) { + GST_DEBUG_OBJECT (src, "ppid changed %d -> %d", ppid, getppid ()); + break; + } + if (!gst_sopcast_src_helper_is_running (src)) break; @@ -676,12 +688,16 @@ gst_sopcast_src_subproc_main (GstSopcastSrc * src, int sock) tv.tv_sec = 1; tv.tv_usec = 0; ret = select (sock + 1, &rfs, NULL, &efs, &tv); + error = errno; + GST_LOG_OBJECT (src, "select () = %d", ret); if (ret == 0) continue; + if (ret < 0 && error == EINTR) + continue; break; } - + GST_DEBUG_OBJECT (src, "killing sp-sc(%d)", src->helper_pid); kill (src->helper_pid, SIGINT); kill (src->helper_pid, SIGTERM); kill (src->helper_pid, SIGKILL); @@ -694,7 +710,7 @@ gst_sopcast_src_subproc_main (GstSopcastSrc * src, int sock) static gboolean gst_sopcast_src_spawn_sopcast (GstSopcastSrc * src) { - pid_t pid; + pid_t ppid, pid; int ret; int fds[2]; @@ -702,10 +718,11 @@ gst_sopcast_src_spawn_sopcast (GstSopcastSrc * src) if (ret < 0) return FALSE; + ppid = getpid (); pid = fork (); if (pid == 0) { /* fds[0] will be closed later */ - gst_sopcast_src_subproc_main (src, fds[1]); + gst_sopcast_src_subproc_main (src, ppid, fds[1]); } else if (pid > 0) { close (fds[1]); src->heatebeat_fd = fds[0]; @@ -760,6 +777,8 @@ gst_sopcast_src_stop (GstBaseSrc * bsrc) close (src->heatebeat_fd); src->heatebeat_fd = -1; + g_usleep (500000); + GST_DEBUG_OBJECT (src, "killing helper %d", src->helper_pid); kill (src->helper_pid, SIGINT); kill (src->helper_pid, SIGTERM); |