diff options
author | Christian Gmeiner <christian.gmeiner@gmail.com> | 2009-05-07 08:10:47 +0200 |
---|---|---|
committer | Christian Gmeiner <christian.gmeiner@gmail.com> | 2009-05-07 08:10:47 +0200 |
commit | 8c416bb8e605f9e7dff8fa6b93927c73b317da11 (patch) | |
tree | 779f92a53578e32d9c97195a8635022fb7e43bed /dxr3syncbuffer.c | |
parent | 3b2a6d0a0d1b44e9bca084ea33921fd1a83cdd2d (diff) | |
download | vdr-plugin-dxr3-8c416bb8e605f9e7dff8fa6b93927c73b317da11.tar.gz vdr-plugin-dxr3-8c416bb8e605f9e7dff8fa6b93927c73b317da11.tar.bz2 |
changed style of source
Diffstat (limited to 'dxr3syncbuffer.c')
-rw-r--r-- | dxr3syncbuffer.c | 216 |
1 files changed, 97 insertions, 119 deletions
diff --git a/dxr3syncbuffer.c b/dxr3syncbuffer.c index d51e530..7712e6c 100644 --- a/dxr3syncbuffer.c +++ b/dxr3syncbuffer.c @@ -45,9 +45,8 @@ cFixedLengthFrame::cFixedLengthFrame() : // ================================== cFixedLengthFrame::~cFixedLengthFrame() { - if (m_pData) - { - delete[] m_pData; + if (m_pData) { + delete[] m_pData; } } @@ -59,10 +58,9 @@ void cFixedLengthFrame::Init(uint32_t lenght) m_pData = new uint8_t[lenght]; // allocation ok? - if (!m_pData) - { - esyslog("dxr3: fatal: unable to allocate memory for new frame"); - exit(1); + if (!m_pData) { + esyslog("dxr3: fatal: unable to allocate memory for new frame"); + exit(1); } } @@ -70,11 +68,10 @@ void cFixedLengthFrame::Init(uint32_t lenght) void cFixedLengthFrame::CopyFrame(const uint8_t* pStart, int length, uint32_t pts, eFrameType type) { - if (length > m_length) - { - delete[] m_pData; - m_pData = new uint8_t[length]; - m_length = length; + if (length > m_length) { + delete[] m_pData; + m_pData = new uint8_t[length]; + m_length = length; } m_type = type; m_count = length; @@ -115,16 +112,14 @@ cDxr3SyncBuffer::cDxr3SyncBuffer(int frameCount, int frameLength, m_pBuffer = new cFixedLengthFrame[frameCount]; // got we a valid m_pBuffer? - if (!m_pBuffer) - { - esyslog("dxr3: fatal: unable to allocate memory for new frame"); - exit(1); + if (!m_pBuffer) { + esyslog("dxr3: fatal: unable to allocate memory for new frame"); + exit(1); } // init our new m_pBuffer; - for (int i = 0; i < frameCount; i++) - { - m_pBuffer[i].Init(frameLength); + for (int i = 0; i < frameCount; i++) { + m_pBuffer[i].Init(frameLength); } // set some default values @@ -143,9 +138,8 @@ cDxr3SyncBuffer::cDxr3SyncBuffer(int frameCount, int frameLength, // ================================== cDxr3SyncBuffer::~cDxr3SyncBuffer() { - if (m_pBuffer) - { - delete[] m_pBuffer; + if (m_pBuffer) { + delete[] m_pBuffer; } } @@ -167,33 +161,30 @@ bool cDxr3SyncBuffer::Poll(int TimeoutMs) struct timeval tv_start, tv; m_bPollSync = true; gettimeofday(&tv_start, NULL); - if (m_demuxMode == DXR3_DEMUX_REPLAY_MODE) - { - if (Available() >= Size() - (Size()*BUFFER_LIMIT/100)) - { - m_bPollSync = true; - while ((Available() >= Size() - (Size()*BUFFER_LIMIT_2)/100) && - ((m_dxr3Device.GetSysClock() - currTime) < - ((uint32_t)TimeoutMs * (uint32_t)45))) - { - int d_s, d_us, ms; - m_bPutBlock = true; - EnableGet(); - WaitForPut(); - gettimeofday(&tv, NULL); - d_s = tv.tv_sec - tv_start.tv_sec; - d_us = tv.tv_usec - tv_start.tv_usec; - ms = d_s * 1000 + d_us / 1000; - if (ms > TimeoutMs * 2) { - esyslog("dxr3: sync: secondary timeout"); - break; - } - } - if (Available() >= Size() - (Size()*BUFFER_LIMIT_2)/100) - { - retVal = false; - } - } + if (m_demuxMode == DXR3_DEMUX_REPLAY_MODE) { + if (Available() >= Size() - (Size()*BUFFER_LIMIT/100)) { + m_bPollSync = true; + while ((Available() >= Size() - (Size()*BUFFER_LIMIT_2)/100) && + ((m_dxr3Device.GetSysClock() - currTime) < + ((uint32_t)TimeoutMs * (uint32_t)45))) + { + int d_s, d_us, ms; + m_bPutBlock = true; + EnableGet(); + WaitForPut(); + gettimeofday(&tv, NULL); + d_s = tv.tv_sec - tv_start.tv_sec; + d_us = tv.tv_usec - tv_start.tv_usec; + ms = d_s * 1000 + d_us / 1000; + if (ms > TimeoutMs * 2) { + esyslog("dxr3: sync: secondary timeout"); + break; + } + } + if (Available() >= Size() - (Size()*BUFFER_LIMIT_2)/100) { + retVal = false; + } + } } return retVal; @@ -206,51 +197,47 @@ cFixedLengthFrame* cDxr3SyncBuffer::Push(const uint8_t* pStart, int length, uint struct timeval tv_start, tv; gettimeofday(&tv_start, NULL); - switch (m_demuxMode) - { + switch (m_demuxMode) { case DXR3_DEMUX_TRICK_MODE: - break; + break; case DXR3_DEMUX_TV_MODE: case DXR3_DEMUX_REPLAY_MODE: default: - while ((Available() >= Size() - (Size()*10)/100)) - { - int d_s, d_us, ms; - m_bPutBlock = true; - EnableGet(); - WaitForPut(); - gettimeofday(&tv, NULL); - d_s = tv.tv_sec - tv_start.tv_sec; - d_us = tv.tv_usec - tv_start.tv_usec; - ms = d_s * 1000 + d_us / 1000; - if (ms > 2000) { - esyslog("dxr3: sync: push timeout"); - return NULL; - } - } - - lastIndex = m_nextFree; - m_pBuffer[m_nextFree].CopyFrame(pStart, length, pts, type); - m_pBuffer[m_nextFree].SetChannelCount(UNKNOWN_CHANNEL_COUNT); - m_pBuffer[m_nextFree].SetSampleRate(UNKNOWN_DATA_RATE); - m_pBuffer[m_nextFree].SetAspectRatio(UNKNOWN_ASPECT_RATIO); - m_nextFree++; - m_count++; - m_nextFree %= Size(); - - if (m_nextFree == m_next) - { - esyslog("dxr3: sync: push buffer overrun"); - Clear(); // XXX This is only a workaround until a sufficient control algorithm is implemented - throw(SYNC_BUFFER_OVERRUN); - } - if (m_bStartReceiver) - { - EnableGet(); - } - break; + while ((Available() >= Size() - (Size()*10)/100)) { + int d_s, d_us, ms; + m_bPutBlock = true; + EnableGet(); + WaitForPut(); + gettimeofday(&tv, NULL); + d_s = tv.tv_sec - tv_start.tv_sec; + d_us = tv.tv_usec - tv_start.tv_usec; + ms = d_s * 1000 + d_us / 1000; + if (ms > 2000) { + esyslog("dxr3: sync: push timeout"); + return NULL; + } + } + + lastIndex = m_nextFree; + m_pBuffer[m_nextFree].CopyFrame(pStart, length, pts, type); + m_pBuffer[m_nextFree].SetChannelCount(UNKNOWN_CHANNEL_COUNT); + m_pBuffer[m_nextFree].SetSampleRate(UNKNOWN_DATA_RATE); + m_pBuffer[m_nextFree].SetAspectRatio(UNKNOWN_ASPECT_RATIO); + m_nextFree++; + m_count++; + m_nextFree %= Size(); + + if (m_nextFree == m_next) { + esyslog("dxr3: sync: push buffer overrun"); + Clear(); // XXX This is only a workaround until a sufficient control algorithm is implemented + throw(SYNC_BUFFER_OVERRUN); + } + if (m_bStartReceiver) { + EnableGet(); + } + break; } return &m_pBuffer[lastIndex]; @@ -275,23 +262,18 @@ cFixedLengthFrame* cDxr3SyncBuffer::Get(void) { cFixedLengthFrame* pRet = 0; - if (!m_bStopped) - { - while ((!Available() || !m_bStartReceiver) && !m_bStopped) - { - m_bGetBlock = true; - ReceiverStopped(); - WaitForGet(); - } - - if (m_nextFree != m_next) - { - pRet = &m_pBuffer[m_next]; - } - } - else - { - WaitForGet(); + if (!m_bStopped) { + while ((!Available() || !m_bStartReceiver) && !m_bStopped) { + m_bGetBlock = true; + ReceiverStopped(); + WaitForGet(); + } + + if (m_nextFree != m_next) { + pRet = &m_pBuffer[m_next]; + } + } else { + WaitForGet(); } return pRet; @@ -305,10 +287,9 @@ void cDxr3SyncBuffer::Clear(void) m_count = 0; m_bStartReceiver = false; m_bPollSync = false; - if (m_bPutBlock) - { - EnablePut(); - m_bPutBlock = false; + if (m_bPutBlock) { + EnablePut(); + m_bPutBlock = false; } } @@ -317,17 +298,15 @@ void cDxr3SyncBuffer::Start(void) { m_bStartReceiver = true; m_bStopped = false; - if (Available()) - { - EnableGet(); + if (Available()) { + EnableGet(); } } // ================================== void cDxr3SyncBuffer::WakeUp(void) { - if (m_bStartReceiver == true) - { + if (m_bStartReceiver == true) { EnableGet(); } } @@ -335,11 +314,10 @@ void cDxr3SyncBuffer::WakeUp(void) // ================================== void cDxr3SyncBuffer::WaitForReceiverStopped(void) { - if (!m_bGetBlock) - { - receiverStoppedMutex.Lock(); - receiverStopped.Wait(receiverStoppedMutex); - receiverStoppedMutex.Unlock(); + if (!m_bGetBlock) { + receiverStoppedMutex.Lock(); + receiverStopped.Wait(receiverStoppedMutex); + receiverStoppedMutex.Unlock(); } } |