Commit 56410655 authored by Andrew de Quincey's avatar Andrew de Quincey

This change moves the precaching from InitWork() to DoWork() in tsstreamer.

The caching can take a while to finish on certain sources and I don't think
it should force the rest of vls to wait for it.

Also, with the MPEX MPEG2 encoder card (spits out a TS stream): If it gets no
video signal, it outputs no TS packets until it gets one. This causes VLS to
hang when starting this input until a video feed is plugged in.
parent 2d1863f9
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* start, stop, suspend and resume operations. * start, stop, suspend and resume operations.
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2003 VideoLAN * (c)1999-2003 VideoLAN
* $Id: normaltrickplay.cpp,v 1.12 2003/08/14 15:22:35 adq Exp $ * $Id: normaltrickplay.cpp,v 1.13 2003/08/14 17:20:36 adq Exp $
* *
* Authors: Jean-Paul Saman <jpsaman@wxs.nl> * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
* *
...@@ -100,19 +100,19 @@ void C_NormalTrickPlay::HandlePacket(C_TsPacket* pPacket) ...@@ -100,19 +100,19 @@ void C_NormalTrickPlay::HandlePacket(C_TsPacket* pPacket)
void C_NormalTrickPlay::DoWork() void C_NormalTrickPlay::DoWork()
{ {
C_TsPacket * pPacket;
int iRc = NO_ERR;
// printf("C_NormalTrickPlay::DoWork()\n");
// Initialize the condition in the new thread. // Initialize the condition in the new thread.
m_cResumeCond.Protect(); m_cResumeCond.Protect();
// log it
C_String strPgrmName = m_pBroadcast->GetProgram()->GetName(); C_String strPgrmName = m_pBroadcast->GetProgram()->GetName();
LogDbg(m_hLog, "Starting to read program \"" + strPgrmName + "\""); LogDbg(m_hLog, "Starting to read program \"" + strPgrmName + "\"");
int iRc = NO_ERR;
C_Fifo<C_TsPacket> * pPackets = new C_Fifo<C_TsPacket>(700);
C_TsPacket * pPacket;
// the main loop
unsigned int prefillCount = 0;
while(!m_bStop && !iRc) while(!m_bStop && !iRc)
{ {
...@@ -150,24 +150,34 @@ void C_NormalTrickPlay::DoWork() ...@@ -150,24 +150,34 @@ void C_NormalTrickPlay::DoWork()
} }
} }
iRc = m_pConverter->GetNextTsPackets(pPackets); iRc = m_pConverter->GetNextTsPackets(m_pPackets);
int iVectorSize = pPackets->Size(); int iVectorSize = m_pPackets->Size();
if ((iRc == NO_ERR) && (!m_bStop)) if ((iRc == NO_ERR) && (!m_bStop))
{ {
for(int i = 0; i < iVectorSize; i++) for(int i = 0; i < iVectorSize; i++)
{ {
pPacket = pPackets->Pop(); pPacket = m_pPackets->Pop();
ASSERT(pPacket); ASSERT(pPacket);
if (prefillCount >= m_iInitFill) {
HandlePacket(pPacket); HandlePacket(pPacket);
} else {
if (!m_pHandler->HandlePrefillPacket(pPacket)) {
HandlePacket(pPacket);
m_pHandler->PrefillComplete();
prefillCount = m_iInitFill+1; // make sure we don't do any more prefilling
} else if (++prefillCount >= m_iInitFill) {
m_pHandler->PrefillComplete();
}
}
} }
} }
else else
{ {
for(int i = 0; i < iVectorSize; i++) for(int i = 0; i < iVectorSize; i++)
{ {
pPacket = pPackets->Pop(); pPacket = m_pPackets->Pop();
ASSERT(pPacket); ASSERT(pPacket);
if (pPacket->RefCount()>0) if (pPacket->RefCount()>0)
m_pTsProvider->ReleasePacket(pPacket); m_pTsProvider->ReleasePacket(pPacket);
...@@ -185,6 +195,9 @@ void C_NormalTrickPlay::DoWork() ...@@ -185,6 +195,9 @@ void C_NormalTrickPlay::DoWork()
m_pEventHandler->HandleEvent(cEvent); m_pEventHandler->HandleEvent(cEvent);
} }
m_pHandler->PrefillComplete();
delete m_pPackets;
m_cResumeCond.Release(); m_cResumeCond.Release();
LogDbg(m_hLog, "Converter stopped for program " + strPgrmName); LogDbg(m_hLog, "Converter stopped for program " + strPgrmName);
} }
...@@ -211,24 +224,8 @@ void C_NormalTrickPlay::InitWork() ...@@ -211,24 +224,8 @@ void C_NormalTrickPlay::InitWork()
int iRc = NO_ERR; int iRc = NO_ERR;
int iVectorSize = 0; int iVectorSize = 0;
C_Fifo<C_TsPacket> * pPackets = new C_Fifo<C_TsPacket>(700); m_pPackets = new C_Fifo<C_TsPacket>(700);
C_TsPacket * pPacket; m_pHandler->PrefillStart();
for(unsigned int ui = 0; ui < m_iInitFill; ui += iVectorSize)
{
iRc = m_pConverter->GetNextTsPackets(pPackets);
if (iRc != NO_ERR)
throw E_Exception(GEN_ERR, "Normal TrickPlay failed to start");
iVectorSize = pPackets->Size();
for(int i = 0; i < iVectorSize; i++)
{
pPacket = pPackets->Pop();
ASSERT(pPacket);
HandlePacket(pPacket);
}
}
} }
void C_NormalTrickPlay::CleanWork() void C_NormalTrickPlay::CleanWork()
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* normaltrickplay.h: Header file for the normal trickplay implementation * normaltrickplay.h: Header file for the normal trickplay implementation
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2003 VideoLAN * (c)1999-2003 VideoLAN
* $Id: normaltrickplay.h,v 1.3 2003/08/05 19:01:15 tooney Exp $ * $Id: normaltrickplay.h,v 1.4 2003/08/14 17:20:36 adq Exp $
* *
* Authors: Jean-Paul Saman <jpsaman@wxs.nl> * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
* *
...@@ -52,6 +52,9 @@ class C_NormalTrickPlay : public C_TrickPlay ...@@ -52,6 +52,9 @@ class C_NormalTrickPlay : public C_TrickPlay
virtual void DoWork(); virtual void DoWork();
virtual void StopWork(); virtual void StopWork();
virtual void CleanWork(); virtual void CleanWork();
private:
C_Fifo<C_TsPacket>* m_pPackets;
}; };
// Declaration and implementation of C_TrickPlayModule // Declaration and implementation of C_TrickPlayModule
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* dvbpsi.h: common tools to use the libdvbpsi * dvbpsi.h: common tools to use the libdvbpsi
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2002 VideoLAN * (c)1999-2002 VideoLAN
* $Id: dvbpsi.h,v 1.3 2003/08/14 15:22:35 adq Exp $ * $Id: dvbpsi.h,v 1.4 2003/08/14 17:20:36 adq Exp $
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* *
...@@ -138,8 +138,10 @@ public: ...@@ -138,8 +138,10 @@ public:
void Detach(); void Detach();
virtual bool HandlePacket(C_TsPacket* pPacket); virtual bool HandlePacket(C_TsPacket* pPacket);
virtual void Shutdown() {}; virtual bool HandlePrefillPacket(C_TsPacket* pPacket) { return false; }
virtual void Shutdown() {}
virtual void PrefillStart() {}
virtual void PrefillComplete() {}
private: private:
static void Callback(C_DvbPsiPatDecoder *pThis, dvbpsi_pat_t* p_new_pat); static void Callback(C_DvbPsiPatDecoder *pThis, dvbpsi_pat_t* p_new_pat);
...@@ -229,7 +231,10 @@ public: ...@@ -229,7 +231,10 @@ public:
void Detach(); void Detach();
virtual bool HandlePacket(C_TsPacket* pPacket); virtual bool HandlePacket(C_TsPacket* pPacket);
virtual bool HandlePrefillPacket(C_TsPacket* pPacket) { return false; }
virtual void Shutdown() {} virtual void Shutdown() {}
virtual void PrefillStart() {}
virtual void PrefillComplete() {}
private: private:
static void Callback(C_DvbPsiPmtDecoder *pThis, dvbpsi_pmt_t* p_new_pmt); static void Callback(C_DvbPsiPmtDecoder *pThis, dvbpsi_pmt_t* p_new_pmt);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ts.h: TsPacket class definition * ts.h: TsPacket class definition
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN * (c)1999-2001 VideoLAN
* $Id: ts.h,v 1.11 2003/08/14 15:22:35 adq Exp $ * $Id: ts.h,v 1.12 2003/08/14 17:20:36 adq Exp $
* *
* Authors: Benoit Steiner <benny@via.ecp.fr> * Authors: Benoit Steiner <benny@via.ecp.fr>
* Jean-Paul Saman <jpsaman@wxs.n> * Jean-Paul Saman <jpsaman@wxs.n>
...@@ -100,7 +100,11 @@ class I_TsPacketHandler ...@@ -100,7 +100,11 @@ class I_TsPacketHandler
{ {
public: public:
virtual bool HandlePacket(C_TsPacket* pPacket) = 0; virtual bool HandlePacket(C_TsPacket* pPacket) = 0;
virtual bool HandlePrefillPacket(C_TsPacket* pPacket) = 0;
virtual void Shutdown() = 0; virtual void Shutdown() = 0;
virtual void PrefillStart() = 0;
virtual void PrefillComplete() = 0;
bool operator == (const I_TsPacketHandler& cHandler) const bool operator == (const I_TsPacketHandler& cHandler) const
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* tsdemux.h: TS demultiplexer * tsdemux.h: TS demultiplexer
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2002 VideoLAN * (c)1999-2002 VideoLAN
* $Id: tsdemux.h,v 1.2 2003/08/14 15:22:35 adq Exp $ * $Id: tsdemux.h,v 1.3 2003/08/14 17:20:36 adq Exp $
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* *
...@@ -65,7 +65,10 @@ public: ...@@ -65,7 +65,10 @@ public:
void UnLock(); void UnLock();
virtual bool HandlePacket(C_TsPacket* pPacket); virtual bool HandlePacket(C_TsPacket* pPacket);
virtual void Shutdown() {}; virtual bool HandlePrefillPacket(C_TsPacket* pPacket) { return false; }
virtual void Shutdown() {}
virtual void PrefillStart() {}
virtual void PrefillComplete() {}
protected: protected:
// Selection hooks // Selection hooks
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* tsmux.h: TS multiplexer * tsmux.h: TS multiplexer
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2002 VideoLAN * (c)1999-2002 VideoLAN
* $Id: tsmux.h,v 1.3 2003/08/14 15:22:35 adq Exp $ * $Id: tsmux.h,v 1.4 2003/08/14 17:20:36 adq Exp $
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* *
...@@ -85,7 +85,10 @@ public: ...@@ -85,7 +85,10 @@ public:
void DetachProgram(u16 iPmtPid); void DetachProgram(u16 iPmtPid);
virtual bool HandlePacket(C_TsPacket* pPacket); virtual bool HandlePacket(C_TsPacket* pPacket);
virtual void Shutdown() {}; virtual bool HandlePrefillPacket(C_TsPacket* pPacket) { return false; }
virtual void Shutdown() {}
virtual void PrefillStart() {}
virtual void PrefillComplete() {}
protected: protected:
// PMT PID -> PMT decoder // PMT PID -> PMT decoder
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* buffer.cpp: Buffers management * buffer.cpp: Buffers management
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN * (c)1999-2001 VideoLAN
* $Id: buffer.cpp,v 1.10 2003/08/14 15:22:35 adq Exp $ * $Id: buffer.cpp,v 1.11 2003/08/14 17:20:36 adq Exp $
* *
* Authors: Benoit Steiner <benny@via.ecp.fr> * Authors: Benoit Steiner <benny@via.ecp.fr>
* *
...@@ -72,11 +72,11 @@ C_SyncFifo::~C_SyncFifo() ...@@ -72,11 +72,11 @@ C_SyncFifo::~C_SyncFifo()
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool C_SyncFifo::HandlePacket(C_TsPacket* pPacket) bool C_SyncFifo::HandlePacket(C_TsPacket* pPacket)
{ {
int iRc;
ASSERT(pPacket); ASSERT(pPacket);
// Push the data (wait for a pop if the fifo is full) // Push the data (wait for a pop if the fifo is full)
// wait for a pop without blocking the thread permanently // wait for a pop without blocking the thread permanently
int iRc;
while(((iRc = m_cNotFullSignal.TryWait()) == -1) && (!m_bShutdown)) while(((iRc = m_cNotFullSignal.TryWait()) == -1) && (!m_bShutdown))
{ {
#ifdef WIN32 #ifdef WIN32
...@@ -105,6 +105,45 @@ bool C_SyncFifo::HandlePacket(C_TsPacket* pPacket) ...@@ -105,6 +105,45 @@ bool C_SyncFifo::HandlePacket(C_TsPacket* pPacket)
return true; return true;
} }
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
bool C_SyncFifo::HandlePrefillPacket(C_TsPacket* pPacket)
{
int iRc;
ASSERT(pPacket);
// see if there is any space left (don't block though)
if (m_cNotFullSignal.TryWait() == -1) return false;
// add on the packet
iRc = m_cFifo.Push(pPacket);
ASSERT(!iRc);
// Warn the waiting threads if any that they have data to pop
iRc = m_cNotEmptySignal.Post();
ASSERT(!iRc);
return true;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void C_SyncFifo::PrefillStart() {
m_cPrefilling.Protect();
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void C_SyncFifo::PrefillComplete() {
m_cPrefilling.Release();
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -119,6 +158,8 @@ void C_SyncFifo::Shutdown() ...@@ -119,6 +158,8 @@ void C_SyncFifo::Shutdown()
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
C_TsPacket* C_SyncFifo::Pop() C_TsPacket* C_SyncFifo::Pop()
{ {
m_cPrefilling.Protect();
// Pop the data (wait for them if the fifo is empty) // Pop the data (wait for them if the fifo is empty)
int iRc; int iRc;
while( (iRc = m_cNotEmptySignal.TryWait()) == -1) while( (iRc = m_cNotEmptySignal.TryWait()) == -1)
...@@ -145,6 +186,8 @@ C_TsPacket* C_SyncFifo::Pop() ...@@ -145,6 +186,8 @@ C_TsPacket* C_SyncFifo::Pop()
iRc = m_cNotFullSignal.Post(); iRc = m_cNotFullSignal.Post();
ASSERT(!iRc); ASSERT(!iRc);
m_cPrefilling.Release();
return pPacket; return pPacket;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* buffer.h: Buffer classes definitions * buffer.h: Buffer classes definitions
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* (c)1999-2001 VideoLAN * (c)1999-2001 VideoLAN
* $Id: buffer.h,v 1.6 2003/08/14 15:22:35 adq Exp $ * $Id: buffer.h,v 1.7 2003/08/14 17:20:36 adq Exp $
* *
* Authors: Benoit Steiner <benny@via.ecp.fr> * Authors: Benoit Steiner <benny@via.ecp.fr>
* *
...@@ -46,6 +46,9 @@ class C_SyncFifo : public I_TsPacketHandler ...@@ -46,6 +46,9 @@ class C_SyncFifo : public I_TsPacketHandler
{ return m_cFifo.Size(); } { return m_cFifo.Size(); }
virtual bool HandlePacket(C_TsPacket* pPacket); virtual bool HandlePacket(C_TsPacket* pPacket);
virtual bool HandlePrefillPacket(C_TsPacket* pPacket);
virtual void PrefillStart();
virtual void PrefillComplete();
virtual void Shutdown(); virtual void Shutdown();
C_TsPacket* Pop(); C_TsPacket* Pop();
C_TsPacket* Peek(unsigned int uiIndex); C_TsPacket* Peek(unsigned int uiIndex);
...@@ -54,6 +57,7 @@ class C_SyncFifo : public I_TsPacketHandler ...@@ -54,6 +57,7 @@ class C_SyncFifo : public I_TsPacketHandler
// Thread synchro objects // Thread synchro objects
C_Semaphore m_cNotEmptySignal; C_Semaphore m_cNotEmptySignal;
C_Semaphore m_cNotFullSignal; C_Semaphore m_cNotFullSignal;
C_Condition m_cPrefilling;
// Fifo // Fifo
C_Fifo<C_TsPacket> m_cFifo; C_Fifo<C_TsPacket> m_cFifo;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment