From 7254a6752808830d5fc133e5362da6c47f3f84ff Mon Sep 17 00:00:00 2001 From: Frank Schmirler Date: Thu, 2 Dec 2010 09:43:13 +0100 Subject: Snapshot 2009-06-11 --- remux/extern.c | 42 ++++++++++++++++++++++++++++++------------ remux/extern.h | 2 -- remux/ts2ps.h | 4 ++++ remux/tsremux.c | 3 ++- remux/tsremux.h | 4 ++++ 5 files changed, 40 insertions(+), 15 deletions(-) (limited to 'remux') diff --git a/remux/extern.c b/remux/extern.c index e137c4a..c5f35de 100644 --- a/remux/extern.c +++ b/remux/extern.c @@ -1,4 +1,5 @@ #include "remux/extern.h" +#include "server/server.h" #include "server/streamer.h" #include #include @@ -6,8 +7,6 @@ #include #include -const char *g_ExternRemux = "/root/externremux.sh"; - class cTSExt: public cThread { private: cRingBufferLinear *m_ResultBuffer; @@ -28,7 +27,7 @@ public: cTSExt::cTSExt(cRingBufferLinear *ResultBuffer, std::string Parameter): m_ResultBuffer(ResultBuffer), m_Active(false), - m_Process(0), + m_Process(-1), m_Inpipe(0), m_Outpipe(0) { @@ -67,9 +66,13 @@ cTSExt::cTSExt(cRingBufferLinear *ResultBuffer, std::string Parameter): for (int i = STDERR_FILENO + 1; i < MaxPossibleFileDescriptors; i++) close(i); //close all dup'ed filedescriptors - std::string cmd = std::string(g_ExternRemux) + " " + Parameter; - execl("/bin/sh", "sh", "-c", cmd.c_str(), NULL); - _exit(-1); + std::string cmd = std::string(opt_remux) + " " + Parameter; + if (execl("/bin/sh", "sh", "-c", cmd.c_str(), NULL) == -1) { + esyslog("streamdev-server: externremux script '%s' execution failed: %m", cmd.c_str()); + _exit(-1); + } + // should never be reached + _exit(0); } close(inpipe[0]); @@ -84,16 +87,31 @@ cTSExt::~cTSExt() m_Active = false; Cancel(3); if (m_Process > 0) { + // close pipes close(m_Outpipe); close(m_Inpipe); - kill(m_Process, SIGTERM); - for (int i = 0; waitpid(m_Process, NULL, WNOHANG) == 0; i++) { - if (i == 20) { - esyslog("streamdev-server: externremux process won't stop - killing it"); - kill(m_Process, SIGKILL); + // signal and wait for termination + if (kill(m_Process, SIGINT) < 0) { + esyslog("streamdev-server: externremux SIGINT failed: %m"); + } + else { + int i = 0; + int retval; + while ((retval = waitpid(m_Process, NULL, WNOHANG)) == 0) { + + if ((++i % 20) == 0) { + esyslog("streamdev-server: externremux process won't stop - killing it"); + kill(m_Process, SIGKILL); + } + cCondWait::SleepMs(100); } - cCondWait::SleepMs(100); + + if (retval < 0) + esyslog("streamdev-server: externremux process waitpid failed: %m"); + else + Dprintf("streamdev-server: externremux child (%d) exited as expected\n", m_Process); } + m_Process = -1; } } diff --git a/remux/extern.h b/remux/extern.h index 7a44852..aa6acf7 100644 --- a/remux/extern.h +++ b/remux/extern.h @@ -5,8 +5,6 @@ #include #include -extern const char *g_ExternRemux; - class cTSExt; class cExternRemux: public cTSRemux { diff --git a/remux/ts2ps.h b/remux/ts2ps.h index 334215a..f31e025 100644 --- a/remux/ts2ps.h +++ b/remux/ts2ps.h @@ -5,6 +5,10 @@ #include #include +#ifndef MAXTRACKS +#define MAXTRACKS 64 +#endif + class cTS2PS; class cTS2PSRemux: public cTSRemux { diff --git a/remux/tsremux.c b/remux/tsremux.c index 6be5245..c73c2fe 100644 --- a/remux/tsremux.c +++ b/remux/tsremux.c @@ -1,6 +1,7 @@ #include "remux/tsremux.h" -#define SC_PICTURE 0x00 // "picture header" +#define SC_PICTURE 0x00 // "picture header" +#define PID_MASK_HI 0x1F void cTSRemux::SetBrokenLink(uchar *Data, int Length) { diff --git a/remux/tsremux.h b/remux/tsremux.h index f7e4e09..a7fe481 100644 --- a/remux/tsremux.h +++ b/remux/tsremux.h @@ -4,6 +4,10 @@ #include "libdvbmpeg/transform.h" #include +#ifndef NO_PICTURE +#define NO_PICTURE 0 +#endif + #define RESULTBUFFERSIZE KILOBYTE(256) class cTSRemux { -- cgit v1.2.3