From 51f4f1c7e37920d026dc8fb502fb4eef77c7c936 Mon Sep 17 00:00:00 2001 From: phintuka Date: Fri, 15 Dec 2006 16:35:31 +0000 Subject: Support raw PES streams (used with HTTP) --- tools/backgroundwriter.c | 20 +++++++++++++++----- tools/backgroundwriter.h | 8 ++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/tools/backgroundwriter.c b/tools/backgroundwriter.c index 6dae8e99..0602ed7c 100644 --- a/tools/backgroundwriter.c +++ b/tools/backgroundwriter.c @@ -4,7 +4,7 @@ * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * - * $Id: backgroundwriter.c,v 1.2 2006-06-11 10:19:50 phintuka Exp $ + * $Id: backgroundwriter.c,v 1.3 2006-12-15 16:35:31 phintuka Exp $ * */ @@ -23,12 +23,13 @@ #define MAX_OVERFLOWS_BEFORE_DISCONNECT 500 // ~ 1 second -cBackgroundWriter::cBackgroundWriter(int fd, int Size) +cBackgroundWriter::cBackgroundWriter(int fd, int Size, bool Raw) : m_RingBuffer(Size, sizeof(stream_tcp_header_t)) { m_fd = fd; m_RingBuffer.SetTimeouts(0, 100); m_Active = true; + m_Raw = Raw; m_PutPos = 0; m_DiscardStart = 0; @@ -36,7 +37,8 @@ cBackgroundWriter::cBackgroundWriter(int fd, int Size) m_BufferOverflows = 0; - LOGDBG("cBackgroundWriter initialized (buffer %d kb)", Size/1024); + LOGDBG("cBackgroundWriter%s initialized (buffer %d kb)", + Raw?"(RAW)":"", Size/1024); Start(); } @@ -62,7 +64,7 @@ void cBackgroundWriter::Action(void) if(Poller.Poll(100)) { - int Count = 0; + int Count = 0, n; uchar *Data = m_RingBuffer.Get(Count); if(Data && Count > 0) { @@ -125,7 +127,12 @@ void cBackgroundWriter::Action(void) #endif errno = 0; - int n = write(m_fd, Data, Count); + if(!m_Raw) + n = write(m_fd, Data, Count); + else + n = write(m_fd, + Data + sizeof(stream_tcp_header_t), + Count - sizeof(stream_tcp_header_t)); if(n == 0) { LOGERR("cBackgroundWriter: Client disconnected data stream ?"); @@ -144,6 +151,9 @@ void cBackgroundWriter::Action(void) } } + if(m_Raw) + n += sizeof(stream_tcp_header_t); + GetPos += n; m_RingBuffer.Del(n); } diff --git a/tools/backgroundwriter.h b/tools/backgroundwriter.h index d49ee133..ea69de67 100644 --- a/tools/backgroundwriter.h +++ b/tools/backgroundwriter.h @@ -4,7 +4,7 @@ * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * - * $Id: backgroundwriter.h,v 1.2 2006-06-11 10:19:50 phintuka Exp $ + * $Id: backgroundwriter.h,v 1.3 2006-12-15 16:35:31 phintuka Exp $ * */ @@ -23,7 +23,8 @@ class cBackgroundWriter : public cThread { cRingBufferLinear m_RingBuffer; volatile bool m_Active; - int m_fd; + bool m_Raw; /* stream without stream_tcp_header_t */ + int m_fd; uint64_t m_PutPos; uint64_t m_DiscardStart; @@ -38,7 +39,7 @@ class cBackgroundWriter : public cThread { const uchar *Data, int DataCount); public: - cBackgroundWriter(int fd, int Size = KILOBYTE(512)); + cBackgroundWriter(int fd, int Size = KILOBYTE(512), bool Raw = false); virtual ~cBackgroundWriter() ; // Return largest possible Put size @@ -56,7 +57,6 @@ class cBackgroundWriter : public cThread { // Drop all data (only complete frames) from buffer void Clear(void); - //bool Poll(int TimeoutMs); bool Flush(int TimeoutMs); }; -- cgit v1.2.3