| 178 | } |
| 179 | |
| 180 | void StreamThreadBase::readDataFromInputDevice(StreamClient &client) { |
| 181 | const input::SpDevice inputDevice = _stream.getInputDevice(); |
| 182 | size_t availableSize = (MAX_BUF - (_writeIndex - _readIndex)); |
| 183 | if (availableSize > MAX_BUF) { |
| 184 | availableSize %= MAX_BUF; |
| 185 | } |
| 186 | // SI_LOG_DEBUG("Stream: %d, PacketBuffer MAX %d W %d R %d S %d", _stream.getStreamID(), MAX_BUF, _writeIndex, _readIndex, availableSize); |
| 187 | if (inputDevice->isDataAvailable() && availableSize > 1) { |
| 188 | if (inputDevice->readFullTSPacket(_tsBuffer[_writeIndex])) { |
| 189 | #ifdef LIBDVBCSA |
| 190 | decrypt::dvbapi::SpClient decrypt = _stream.getDecryptDevice(); |
| 191 | if (decrypt != nullptr) { |
| 192 | decrypt->decrypt(_stream.getStreamID(), _tsBuffer[_writeIndex]); |
| 193 | } |
| 194 | #endif |
| 195 | // goto next, so inc write index |
| 196 | ++_writeIndex; |
| 197 | _writeIndex %= MAX_BUF; |
| 198 | |
| 199 | // reset next |
| 200 | _tsBuffer[_writeIndex].reset(); |
| 201 | } |
| 202 | } |
| 203 | // calculate interval |
| 204 | _t2 = std::chrono::steady_clock::now(); |
| 205 | const unsigned long interval = std::chrono::duration_cast<std::chrono::microseconds>(_t2 - _t1).count(); |
| 206 | if (interval > _sendInterval && _tsBuffer[_readIndex].isReadyToSend()) { |
| 207 | _t1 = _t2; |
| 208 | if (writeDataToOutputDevice(_tsBuffer[_readIndex], client)) { |
| 209 | // inc read index only when send is successful |
| 210 | ++_readIndex; |
| 211 | _readIndex %= MAX_BUF; |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | } // namespace output |
nothing calls this directly
no test coverage detected