diff options
-rw-r--r-- | tools/udp_pes_scheduler.c | 45 | ||||
-rw-r--r-- | tools/udp_pes_scheduler.h | 4 |
2 files changed, 36 insertions, 13 deletions
diff --git a/tools/udp_pes_scheduler.c b/tools/udp_pes_scheduler.c index c697c5de..0de6997e 100644 --- a/tools/udp_pes_scheduler.c +++ b/tools/udp_pes_scheduler.c @@ -4,7 +4,7 @@ * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * - * $Id: udp_pes_scheduler.c,v 1.45 2009-07-02 04:37:50 phintuka Exp $ + * $Id: udp_pes_scheduler.c,v 1.46 2009-07-02 10:38:29 phintuka Exp $ * */ @@ -83,7 +83,6 @@ typedef enum { eScrFromVideo } ScrSource_t; -static inline int pts_to_ms(int64_t pts) { return int(pts)/90; } cUdpScheduler::cUdpScheduler() { @@ -450,6 +449,37 @@ bool cUdpScheduler::Queue(uint64_t StreamPos, const uchar *Data, int Length) return true; } +void cUdpScheduler::QueuePadding(void) +{ + cMutexLock ml(&m_Lock); + + if (m_Handles[0] < 0) + return; + + if (m_QueuePending > 2) + return; + + QueuePaddingInternal(); + + m_Cond.Broadcast(); +} + +void cUdpScheduler::QueuePaddingInternal(void) +{ + static unsigned const char Padding[] = {0x00,0x00,0x01,0xBE,0x00,0x02,0xff,0xff}; + + int PrevSeq = (m_QueueNextSeq + UDP_BUFFER_SIZE - 1) & UDP_BUFFER_MASK; + stream_rtp_header_impl_t *Frame = m_BackLog->Get(PrevSeq); + if (Frame) { + int PrevLen = m_BackLog->PayloadSize(PrevSeq); + uint64_t Pos = ntohll(Frame->hdr_ext.pos) + PrevLen - 8; + m_BackLog->MakeFrame(Pos, Padding, 8); + } else + m_BackLog->MakeFrame(0, Padding, 8); + + m_QueuePending++; +} + int cUdpScheduler::CalcElapsedVtime(int64_t pts, bool Audio) { int64_t diff = 0; @@ -732,16 +762,7 @@ void cUdpScheduler::Action(void) // Still nothing... // Send padding frame once in 100ms so clients can detect // possible missing frames and server shutdown - static unsigned char padding[] = {0x00,0x00,0x01,0xBE,0x00,0x02,0xff,0xff}; - int prevseq = (m_QueueNextSeq + UDP_BUFFER_SIZE - 1) & UDP_BUFFER_MASK; - stream_rtp_header_impl_t *frame = m_BackLog->Get(prevseq); - if(frame) { - int prevlen = m_BackLog->PayloadSize(prevseq); - uint64_t pos = ntohll(frame->hdr_ext.pos) + prevlen - 8; - m_BackLog->MakeFrame(pos, padding, 8); - } else - m_BackLog->MakeFrame(0, padding, 8); - m_QueuePending++; + QueuePaddingInternal(); } continue; // to check Running() } diff --git a/tools/udp_pes_scheduler.h b/tools/udp_pes_scheduler.h index 44b1a276..a889f728 100644 --- a/tools/udp_pes_scheduler.h +++ b/tools/udp_pes_scheduler.h @@ -4,7 +4,7 @@ * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * - * $Id: udp_pes_scheduler.h,v 1.19 2009-07-01 09:24:13 phintuka Exp $ + * $Id: udp_pes_scheduler.h,v 1.20 2009-07-02 10:38:29 phintuka Exp $ * */ @@ -41,6 +41,7 @@ class cUdpScheduler : public cThread bool Clients(void) { return m_Handles[0] >= 0; } int Poll(int TimeoutMs, bool Master); bool Queue(uint64_t StreamPos, const uchar *Data, int Length); + void QueuePadding(void); void ReSend(int fd, uint64_t Pos, int Seq1, int Seq2); void Clear(void); @@ -89,6 +90,7 @@ class cUdpScheduler : public cThread int CalcElapsedVtime(int64_t pts, bool Audio); void Schedule(const uchar *Data, int Length); void Scheduler_Sleep(int ms); + void QueuePaddingInternal(void); // RTP |