| 115 | } |
| 116 | |
| 117 | BOOL CircleBuffer::readBuffer(void* pDestBuffer, const unsigned int _iBytesToRead, unsigned int* pbBytesRead, int& audioTime) |
| 118 | { |
| 119 | unsigned int iBytesToRead = _iBytesToRead; |
| 120 | unsigned int iBytesRead = 0; |
| 121 | DWORD dwWaitResult; |
| 122 | BOOL bComplete = FALSE; |
| 123 | |
| 124 | while (iBytesToRead > 0 && bComplete == FALSE) |
| 125 | { |
| 126 | dwWaitResult = WaitForSingleObject(this->m_evtDataAvailable, this->wait_timeout); |
| 127 | if (dwWaitResult == WAIT_TIMEOUT) |
| 128 | { |
| 129 | *pbBytesRead = iBytesRead; |
| 130 | return FALSE; |
| 131 | } |
| 132 | |
| 133 | EnterCriticalSection(&this->m_csCircleBuffer); |
| 134 | |
| 135 | bool bPopTimeStamp = false; |
| 136 | if (this->m_iInternalReadCursor > this->m_iInternalWriteCursor) |
| 137 | { |
| 138 | unsigned int iChunkSize = this->m_iBufferSize - this->m_iInternalReadCursor; |
| 139 | if (iChunkSize > iBytesToRead) |
| 140 | iChunkSize = iBytesToRead; |
| 141 | |
| 142 | memcpy((BYTE*)pDestBuffer + iBytesRead, this->m_pBuffer + this->m_iInternalReadCursor, iChunkSize); |
| 143 | |
| 144 | iBytesRead += iChunkSize; |
| 145 | iBytesToRead -= iChunkSize; |
| 146 | |
| 147 | this->m_iInternalReadCursor += iChunkSize; |
| 148 | if (this->m_iInternalReadCursor >= this->m_iBufferSize) |
| 149 | this->m_iInternalReadCursor -= this->m_iBufferSize; |
| 150 | bPopTimeStamp = true; |
| 151 | } |
| 152 | |
| 153 | if (iBytesToRead && this->m_iInternalReadCursor < this->m_iInternalWriteCursor) |
| 154 | { |
| 155 | unsigned int iChunkSize = this->m_iInternalWriteCursor - this->m_iInternalReadCursor; |
| 156 | if (iChunkSize > iBytesToRead) |
| 157 | iChunkSize = iBytesToRead; |
| 158 | |
| 159 | memcpy((BYTE*)pDestBuffer + iBytesRead, |
| 160 | this->m_pBuffer + this->m_iInternalReadCursor, |
| 161 | iChunkSize); |
| 162 | |
| 163 | iBytesRead += iChunkSize; |
| 164 | iBytesToRead -= iChunkSize; |
| 165 | this->m_iInternalReadCursor += iChunkSize; |
| 166 | bPopTimeStamp = true; |
| 167 | } |
| 168 | |
| 169 | if(bPopTimeStamp && !audioTimeQueue.empty()) { |
| 170 | audioTime = audioTimeQueue.front();//audio timestamp |
| 171 | audioTimeQueue.pop(); |
| 172 | } |
| 173 | |
| 174 | if (this->m_iInternalReadCursor == this->m_iInternalWriteCursor) |
no test coverage detected