- use cThread::Running()/Active() instead of private members

- replaced the last usleep by cCondWait
thanks to Rolf Ahrenberg (#383)
Modified Files:
 Tag: v0_4
	CONTRIBUTORS HISTORY server/server.c server/server.h
	server/streamer.c server/streamer.h server/suspend.c
	server/suspend.h
This commit is contained in:
schmirl 2008-10-22 11:59:35 +00:00
parent 5c24a13075
commit 84f994384a
8 changed files with 36 additions and 55 deletions

View File

@ -26,6 +26,7 @@ Rolf Ahrenberg
for making it possible to pass parameters to externremux.sh for making it possible to pass parameters to externremux.sh
for removing pre VDR 1.4 legacy code for removing pre VDR 1.4 legacy code
for fixing output format of some debug messages for fixing output format of some debug messages
for replacing private members by cThread::Running()/Active()
Rantanen Teemu Rantanen Teemu
for providing vdr-incompletesections.diff for providing vdr-incompletesections.diff

View File

@ -1,6 +1,8 @@
VDR Plugin 'streamdev' Revision History eDR Plugin 'streamdev' Revision History
--------------------------------------- ---------------------------------------
- use cThread::Running()/Active() instead of private members (thanks to
Rolf Ahrenberg)
- fixed output format of some debug messages (thanks to Rolf Ahrenberg) - fixed output format of some debug messages (thanks to Rolf Ahrenberg)
- added HTTP authentication - added HTTP authentication
- added preprocessor directive for ancient gcc - added preprocessor directive for ancient gcc

View File

@ -1,5 +1,5 @@
/* /*
* $Id: server.c,v 1.5.2.2 2008/10/14 11:05:59 schmirl Exp $ * $Id: server.c,v 1.5.2.3 2008/10/22 11:59:37 schmirl Exp $
*/ */
#include "server/server.h" #include "server/server.h"
@ -21,8 +21,7 @@ cList<cServerComponent> cStreamdevServer::m_Servers;
cList<cServerConnection> cStreamdevServer::m_Clients; cList<cServerConnection> cStreamdevServer::m_Clients;
cStreamdevServer::cStreamdevServer(void): cStreamdevServer::cStreamdevServer(void):
cThread("streamdev server"), cThread("streamdev server")
m_Active(false)
{ {
Start(); Start();
} }
@ -49,10 +48,8 @@ void cStreamdevServer::Destruct(void)
void cStreamdevServer::Stop(void) void cStreamdevServer::Stop(void)
{ {
if (m_Active) { if (Running())
m_Active = false;
Cancel(3); Cancel(3);
}
} }
void cStreamdevServer::Register(cServerComponent *Server) void cStreamdevServer::Register(cServerComponent *Server)
@ -62,8 +59,6 @@ void cStreamdevServer::Register(cServerComponent *Server)
void cStreamdevServer::Action(void) void cStreamdevServer::Action(void)
{ {
m_Active = true;
/* Initialize Server components, deleting those that failed */ /* Initialize Server components, deleting those that failed */
for (cServerComponent *c = m_Servers.First(); c;) { for (cServerComponent *c = m_Servers.First(); c;) {
cServerComponent *next = m_Servers.Next(c); cServerComponent *next = m_Servers.Next(c);
@ -74,11 +69,15 @@ void cStreamdevServer::Action(void)
if (m_Servers.Count() == 0) { if (m_Servers.Count() == 0) {
esyslog("ERROR: no streamdev server activated, exiting"); esyslog("ERROR: no streamdev server activated, exiting");
m_Active = false; #if VDRVERSNUM > 10403
Cancel(-1);
#else
return;
#endif
} }
cTBSelect select; cTBSelect select;
while (m_Active) { while (Running()) {
select.Clear(); select.Clear();
/* Ask all Server components to register to the selector */ /* Ask all Server components to register to the selector */
@ -104,9 +103,9 @@ void cStreamdevServer::Action(void)
sel = 0; sel = 0;
} }
} }
} while (sel < 0 && errno == ETIMEDOUT && m_Active); } while (sel < 0 && errno == ETIMEDOUT && Running());
if (!m_Active) if (!Running())
break; break;
if (sel < 0) { if (sel < 0) {
esyslog("fatal error, server exiting: %m"); esyslog("fatal error, server exiting: %m");
@ -166,6 +165,4 @@ void cStreamdevServer::Action(void)
c->Destruct(); c->Destruct();
m_Servers.Del(c); m_Servers.Del(c);
} }
m_Active = false;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: server.h,v 1.3.2.2 2008/10/14 11:05:59 schmirl Exp $ * $Id: server.h,v 1.3.2.3 2008/10/22 11:59:37 schmirl Exp $
*/ */
#ifndef VDR_STREAMDEV_SERVER_H #ifndef VDR_STREAMDEV_SERVER_H
@ -18,8 +18,6 @@ extern char *opt_remux;
class cStreamdevServer: public cThread { class cStreamdevServer: public cThread {
private: private:
bool m_Active;
static cStreamdevServer *m_Instance; static cStreamdevServer *m_Instance;
static cList<cServerComponent> m_Servers; static cList<cServerComponent> m_Servers;
static cList<cServerConnection> m_Clients; static cList<cServerConnection> m_Clients;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: streamer.c,v 1.16 2007/09/21 11:45:53 schmirl Exp $ * $Id: streamer.c,v 1.16.2.1 2008/10/22 11:59:37 schmirl Exp $
*/ */
#include <vdr/ringbuffer.h> #include <vdr/ringbuffer.h>
@ -20,16 +20,15 @@ cStreamdevWriter::cStreamdevWriter(cTBSocket *Socket,
cStreamdevStreamer *Streamer): cStreamdevStreamer *Streamer):
cThread("streamdev-writer"), cThread("streamdev-writer"),
m_Streamer(Streamer), m_Streamer(Streamer),
m_Socket(Socket), m_Socket(Socket)
m_Active(false)
{ {
} }
cStreamdevWriter::~cStreamdevWriter() cStreamdevWriter::~cStreamdevWriter()
{ {
Dprintf("destructing writer\n"); Dprintf("destructing writer\n");
m_Active = false; if (Running())
Cancel(3); Cancel(3);
} }
void cStreamdevWriter::Action(void) void cStreamdevWriter::Action(void)
@ -39,11 +38,10 @@ void cStreamdevWriter::Action(void)
int max = 0; int max = 0;
uchar *block = NULL; uchar *block = NULL;
int count, offset = 0; int count, offset = 0;
m_Active = true;
sel.Clear(); sel.Clear();
sel.Add(*m_Socket, true); sel.Add(*m_Socket, true);
while (m_Active) { while (Running()) {
if (block == NULL) { if (block == NULL) {
block = m_Streamer->Get(count); block = m_Streamer->Get(count);
offset = 0; offset = 0;
@ -73,7 +71,6 @@ void cStreamdevWriter::Action(void)
} }
} }
} }
m_Active = false;
Dprintf("Max. Transmit Blocksize was: %d\n", max); Dprintf("Max. Transmit Blocksize was: %d\n", max);
} }
@ -81,7 +78,6 @@ void cStreamdevWriter::Action(void)
cStreamdevStreamer::cStreamdevStreamer(const char *Name): cStreamdevStreamer::cStreamdevStreamer(const char *Name):
cThread(Name), cThread(Name),
m_Active(false),
m_Running(false), m_Running(false),
m_Writer(NULL), m_Writer(NULL),
m_RingBuffer(new cRingBufferLinear(STREAMERBUFSIZE, TS_SIZE * 2, m_RingBuffer(new cRingBufferLinear(STREAMERBUFSIZE, TS_SIZE * 2,
@ -109,7 +105,7 @@ void cStreamdevStreamer::Start(cTBSocket *Socket)
void cStreamdevStreamer::Activate(bool On) void cStreamdevStreamer::Activate(bool On)
{ {
if (On && !m_Active) { if (On && !Active()) {
Dprintf("activate streamer\n"); Dprintf("activate streamer\n");
m_Writer->Start(); m_Writer->Start();
cThread::Start(); cThread::Start();
@ -118,9 +114,8 @@ void cStreamdevStreamer::Activate(bool On)
void cStreamdevStreamer::Stop(void) void cStreamdevStreamer::Stop(void)
{ {
if (m_Active) { if (Running()) {
Dprintf("stopping streamer\n"); Dprintf("stopping streamer\n");
m_Active = false;
Cancel(3); Cancel(3);
} }
if (m_Running) { if (m_Running) {
@ -132,8 +127,7 @@ void cStreamdevStreamer::Stop(void)
void cStreamdevStreamer::Action(void) void cStreamdevStreamer::Action(void)
{ {
m_Active = true; while (Running()) {
while (m_Active) {
int got; int got;
uchar *block = m_RingBuffer->Get(got); uchar *block = m_RingBuffer->Get(got);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: streamer.h,v 1.8 2007/04/02 10:32:34 schmirl Exp $ * $Id: streamer.h,v 1.8.2.1 2008/10/22 11:59:37 schmirl Exp $
*/ */
#ifndef VDR_STREAMDEV_STREAMER_H #ifndef VDR_STREAMDEV_STREAMER_H
@ -21,7 +21,6 @@ class cStreamdevWriter: public cThread {
private: private:
cStreamdevStreamer *m_Streamer; cStreamdevStreamer *m_Streamer;
cTBSocket *m_Socket; cTBSocket *m_Socket;
bool m_Active;
protected: protected:
virtual void Action(void); virtual void Action(void);
@ -29,15 +28,12 @@ protected:
public: public:
cStreamdevWriter(cTBSocket *Socket, cStreamdevStreamer *Streamer); cStreamdevWriter(cTBSocket *Socket, cStreamdevStreamer *Streamer);
virtual ~cStreamdevWriter(); virtual ~cStreamdevWriter();
bool IsActive(void) const { return m_Active; }
}; };
// --- cStreamdevStreamer ----------------------------------------------------- // --- cStreamdevStreamer -----------------------------------------------------
class cStreamdevStreamer: public cThread { class cStreamdevStreamer: public cThread {
private: private:
bool m_Active;
bool m_Running; bool m_Running;
cStreamdevWriter *m_Writer; cStreamdevWriter *m_Writer;
cRingBufferLinear *m_RingBuffer; cRingBufferLinear *m_RingBuffer;
@ -54,7 +50,7 @@ public:
virtual void Start(cTBSocket *Socket); virtual void Start(cTBSocket *Socket);
virtual void Stop(void); virtual void Stop(void);
bool Abort(void) const; bool Abort(void);
void Activate(bool On); void Activate(bool On);
int Receive(uchar *Data, int Length) { return m_RingBuffer->Put(Data, Length); } int Receive(uchar *Data, int Length) { return m_RingBuffer->Put(Data, Length); }
@ -68,9 +64,9 @@ public:
virtual void Attach(void) {} virtual void Attach(void) {}
}; };
inline bool cStreamdevStreamer::Abort(void) const inline bool cStreamdevStreamer::Abort(void)
{ {
return m_Active && !m_Writer->IsActive(); return Active() && !m_Writer->Active();
} }
#endif // VDR_STREAMDEV_STREAMER_H #endif // VDR_STREAMDEV_STREAMER_H

View File

@ -1,5 +1,5 @@
/* /*
* $Id: suspend.c,v 1.2 2008/04/07 14:27:31 schmirl Exp $ * $Id: suspend.c,v 1.2.2.1 2008/10/22 11:59:37 schmirl Exp $
*/ */
#include "server/suspend.h" #include "server/suspend.h"
@ -12,6 +12,7 @@ cSuspendLive::cSuspendLive(void)
} }
cSuspendLive::~cSuspendLive() { cSuspendLive::~cSuspendLive() {
Stop();
Detach(); Detach();
} }
@ -24,17 +25,14 @@ void cSuspendLive::Activate(bool On) {
} }
void cSuspendLive::Stop(void) { void cSuspendLive::Stop(void) {
if (m_Active) { if (Running())
m_Active = false;
Cancel(3); Cancel(3);
}
} }
void cSuspendLive::Action(void) { void cSuspendLive::Action(void) {
m_Active = true; while (Running()) {
while (m_Active) {
DeviceStillPicture(suspend_mpg, sizeof(suspend_mpg)); DeviceStillPicture(suspend_mpg, sizeof(suspend_mpg));
usleep(100000); cCondWait::SleepMs(100);
} }
} }
@ -51,7 +49,7 @@ cSuspendCtl::~cSuspendCtl() {
} }
eOSState cSuspendCtl::ProcessKey(eKeys Key) { eOSState cSuspendCtl::ProcessKey(eKeys Key) {
if (!m_Suspend->IsActive() || Key == kBack) { if (!m_Suspend->Active() || Key == kBack) {
DELETENULL(m_Suspend); DELETENULL(m_Suspend);
return osEnd; return osEnd;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: suspend.h,v 1.1 2004/12/30 22:44:26 lordjaxom Exp $ * $Id: suspend.h,v 1.1.1.1.2.1 2008/10/22 11:59:37 schmirl Exp $
*/ */
#ifndef VDR_STREAMDEV_SUSPEND_H #ifndef VDR_STREAMDEV_SUSPEND_H
@ -7,10 +7,7 @@
#include <vdr/player.h> #include <vdr/player.h>
class cSuspendLive: public cPlayer, cThread { class cSuspendLive: public cPlayer, public cThread {
private:
bool m_Active;
protected: protected:
virtual void Activate(bool On); virtual void Activate(bool On);
virtual void Action(void); virtual void Action(void);
@ -20,8 +17,6 @@ protected:
public: public:
cSuspendLive(void); cSuspendLive(void);
virtual ~cSuspendLive(); virtual ~cSuspendLive();
bool IsActive(void) const { return m_Active; }
}; };
class cSuspendCtl: public cControl { class cSuspendCtl: public cControl {