qint64 CNetworkConnection::peek(char *data, qint64 maxlen) { qint64 nBytes = qMin((qint64)GetInputBuffer()->size(), maxlen); memcpy(data, GetInputBuffer()->constData(), nBytes); return nBytes; }
int JackPortAudioDriver::Read() { for (int i = 0; i < fCaptureChannels; i++) { memcpy(GetInputBuffer(i), fInputBuffer[i], sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize); } return 0; }
QByteArray CNetworkConnection::read(qint64 maxlen) { QByteArray oResult; qint64 nToRead = qMin<qint64>(GetInputBuffer()->size(), maxlen); oResult.resize(nToRead); readData(oResult.data(), nToRead); return oResult; }
QByteArray CNetworkConnection::Read(qint64 nMaxSize) { QByteArray baRet; baRet.resize(qMin<qint64>(nMaxSize, GetInputBuffer()->size())); readData(baRet.data(), baRet.size()); return baRet; }
void CG2Node::OnRead() { if( !Network.m_pSection.tryLock(50) ) { emit readyRead(); // it is a queued connection, lets requeue the missed signal return; } //qDebug() << "CG2Node::OnRead"; if( m_nState == nsHandshaking ) { if( peek(bytesAvailable()).indexOf("\r\n\r\n") != -1 ) { if( m_bInitiated ) { ParseOutgoingHandshake(); } else { ParseIncomingHandshake(); } } } else if ( m_nState == nsConnected ) { G2Packet* pPacket = 0; try { while( (pPacket = G2Packet::ReadBuffer(GetInputBuffer())) ) { m_tLastPacketIn = time(0); m_nPacketsIn++; OnPacket(pPacket); pPacket->Release(); } } catch(...) { if( pPacket ) { qDebug() << pPacket->ToHex() << "\n" << pPacket->ToASCII(); pPacket->Release(); } qDebug() << "Packet error - " << m_oAddress.toString().toAscii(); m_nState = nsClosing; emit NodeStateChanged(); deleteLater(); } } Network.m_pSection.unlock(); }
bool CGraphmatFile :: LoadFileToGraphan (const string& CommandLine) { try { m_SourceFileName = CommandLine.c_str(); m_GraFileName = MakeFName (m_SourceFileName,"gra"); m_XmlMacSynName = MakeFName (m_SourceFileName,"xml"); m_SaveTxtName = MakeFName (m_SourceFileName,"tds"); if (IsHtmlFile(m_SourceFileName)) { HTML Convert(m_SourceFileName); string Text = Convert.getText(); if (!InitInputBuffer(Text)) { m_LastError = Format("Cannot init inpur buffer for %i bytes", Text.length()); return false; } if (m_bSaveHtmlFileToTdsFile) WriteVector(m_SaveTxtName, GetInputBuffer()); } else { if (access(m_SourceFileName.c_str(), 04) != 0) return false; string Text; LoadFileToString(m_SourceFileName, Text); if (!InitInputBuffer(Text)) { m_LastError = Format("Cannot init inpur buffer for %i bytes", Text.length()); return false; }; }; return GraphmatMain (); } catch (CExpc& C) { m_LastError = C.m_ErrorCode; return false; } catch (...) { m_LastError = "general exception"; return false; }; };
nsresult MediaCodecDataDecoder::QueueSample(const MediaRawData* aSample) { MOZ_ASSERT(aSample); AutoLocalJNIFrame frame(jni::GetEnvForThread(), 1); // We have a sample, try to feed it to the decoder. int32_t inputIndex = -1; nsresult res = mDecoder->DequeueInputBuffer(kDecoderTimeout, &inputIndex); if (NS_FAILED(res)) { return res; } if (inputIndex < 0) { // There is no valid input buffer available. return NS_ERROR_FAILURE; } jni::Object::LocalRef buffer(frame.GetEnv()); res = GetInputBuffer(frame.GetEnv(), inputIndex, &buffer); if (NS_FAILED(res)) { return res; } void* directBuffer = frame.GetEnv()->GetDirectBufferAddress(buffer.Get()); MOZ_ASSERT(frame.GetEnv()->GetDirectBufferCapacity(buffer.Get()) >= aSample->Size(), "Decoder buffer is not large enough for sample"); PodCopy(static_cast<uint8_t*>(directBuffer), aSample->Data(), aSample->Size()); CryptoInfo::LocalRef cryptoInfo = GetCryptoInfoFromSample(aSample); if (cryptoInfo) { res = mDecoder->QueueSecureInputBuffer(inputIndex, 0, cryptoInfo, aSample->mTime, 0); } else { res = mDecoder->QueueInputBuffer(inputIndex, 0, aSample->Size(), aSample->mTime, 0); } if (NS_FAILED(res)) { return res; } mDurations.push_back(TimeUnit::FromMicroseconds(aSample->mDuration)); return NS_OK; }
int JackLoopbackDriver::ProcessReadAsync() { int res = 0; // Loopback copy for (int i = 0; i < fCaptureChannels; i++) { memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize); } // Resume connected clients in the graph if (ResumeRefNum() < 0) { jack_error("JackLoopbackDriver::ProcessReadAsync - ResumeRefNum error"); res = -1; } return res; }
int JackProxyDriver::Read() { // take the time at the beginning of the cycle JackDriver::CycleTakeBeginTime(); int i; void *from, *to; size_t buflen = sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize; for (i = 0; i < fCaptureChannels; i++) { if (fUpstreamPlaybackPortConnected[i]) { from = jack_port_get_buffer(fUpstreamPlaybackPorts[i], fEngineControl->fBufferSize); to = GetInputBuffer(i); memcpy(to, from, buflen); } } return 0; }
void CChatSessionG2::OnRead() { if( m_nState == csHandshaking ) { if(Peek(bytesAvailable()).indexOf("\r\n\r\n") != -1) { if(m_bInitiated) { ParseOutgoingHandshake(); } else { //ParseIncomingHandshake(); } } } else if( m_nState == csConnected || m_nState == csActive ) { G2Packet* pPacket = 0; try { while((pPacket = G2Packet::ReadBuffer(GetInputBuffer()))) { OnPacket(pPacket); pPacket->Release(); } } catch(...) { if(pPacket) { pPacket->Release(); } emit systemMessage("Received corrupted G2 packet, connection lost."); CNetworkConnection::Close(); } m_bReadyReadSent = false; } }
int JackWinMMEDriver::Read() { size_t size; for (int chan = 0; chan < fCaptureChannels; chan++) { if (fGraphManager->GetConnectionsNum(fCapturePortList[chan]) > 0) { JackMidiBuffer* midi_buffer = GetInputBuffer(chan); if (jack_ringbuffer_read_space (fRingBuffer[chan]) == 0) { // Reset buffer midi_buffer->Reset(midi_buffer->nframes); } else { while ((size = jack_ringbuffer_read_space (fRingBuffer[chan])) > 0) { //jack_info("jack_ringbuffer_read_space %d", size); int ev_count = 0; jack_ringbuffer_read(fRingBuffer[chan], (char*)&ev_count, sizeof(int)); if (ev_count > 0) { for (int j = 0; j < ev_count; j++) { unsigned int event_len = 3; // Read event actual data jack_midi_data_t* dest = midi_buffer->ReserveEvent(0, event_len); jack_ringbuffer_read(fRingBuffer[chan], (char*)dest, event_len); } } } } } else { //jack_info("Consume ring buffer"); jack_ringbuffer_read_advance(fRingBuffer[chan], jack_ringbuffer_read_space(fRingBuffer[chan])); } } return 0; }
bool CGraphmatFile :: GraphmatMain () { m_LastError = ""; if (0x500000 < GetInputBuffer().size()) { m_LastError = "File is to large, it cannot be more than 5 MB"; return false; }; InitTokenBuffer(); { // NUMBER of all UNITS which were read from INPUT file size_t CurrOutBufOffset = 0; // we should process all bytes except the last terminating null size_t InputBufferSize = GetInputBuffer().size()-1; for (size_t InputOffset = 0; InputOffset < InputBufferSize ; ) { CGraLine NewLine; NewLine.SetToken(GetUnitBufferStart() + CurrOutBufOffset); DWORD PageNumber; InputOffset = NewLine.ReadWord(InputOffset,this, PageNumber); // ignore single spaces in order to save memory if ( !NewLine.IsSingleSpaceToDelete() ) { AddUnit(NewLine); CurrOutBufOffset += NewLine.GetTokenLength(); if (NewLine.IsPageBreak() ) SetPageNumber(GetUnits().size() - 1,PageNumber); } else { assert (!GetUnits().empty()); GetUnit(GetUnits().size() -1).SetSingleSpaceAfter(); }; } } // больше TBuf не нужен, так что освобождаем память ClearInputBuffer(); for (size_t i=1; i< GetUnits().size(); i++) InitNonContextDescriptors(GetUnit(i)); if (m_bOnlyNonContextDescriptors) return true; BuildUnitBufferUpper(); InitContextDescriptors (0,GetUnits().size()); MacSynHierarchy(); if (m_bSentBreaker) if (!DealSentBreaker ()) { m_LastError = "An exception occurred in Sentence breaker"; return false; }; if (m_bWriteTextBuffer) WriteVector(m_SaveTxtName, GetUnitBuf()); if (m_bWriteGraFile) WriteGraphMat (m_GraFileName.c_str()); return true; };
void MediaCodecDataDecoder::DecoderLoop() { bool outputDone = false; bool draining = false; bool waitingEOF = false; AutoLocalJNIFrame frame(GetJNIForThread(), 1); nsRefPtr<MediaRawData> sample; MediaFormat::LocalRef outputFormat(frame.GetEnv()); nsresult res; for (;;) { { MonitorAutoLock lock(mMonitor); while (!mStopping && !mDraining && !mFlushing && mQueue.empty()) { if (mQueue.empty()) { // We could be waiting here forever if we don't signal that we need more input ENVOKE_CALLBACK(InputExhausted); } lock.Wait(); } if (mStopping) { // Get out of the loop. This is the only exit point. break; } if (mFlushing) { mDecoder->Flush(); ClearQueue(); mFlushing = false; lock.Notify(); continue; } if (mDraining && !sample && !waitingEOF) { draining = true; } // We're not stopping or draining, so try to get a sample if (!mQueue.empty()) { sample = mQueue.front(); } } if (draining && !waitingEOF) { MOZ_ASSERT(!sample, "Shouldn't have a sample when pushing EOF frame"); int32_t inputIndex; res = mDecoder->DequeueInputBuffer(DECODER_TIMEOUT, &inputIndex); HANDLE_DECODER_ERROR(); if (inputIndex >= 0) { res = mDecoder->QueueInputBuffer(inputIndex, 0, 0, 0, MediaCodec::BUFFER_FLAG_END_OF_STREAM); HANDLE_DECODER_ERROR(); waitingEOF = true; } } if (sample) { // We have a sample, try to feed it to the decoder int inputIndex; res = mDecoder->DequeueInputBuffer(DECODER_TIMEOUT, &inputIndex); HANDLE_DECODER_ERROR(); if (inputIndex >= 0) { jni::Object::LocalRef buffer(frame.GetEnv()); res = GetInputBuffer(frame.GetEnv(), inputIndex, &buffer); HANDLE_DECODER_ERROR(); void* directBuffer = frame.GetEnv()->GetDirectBufferAddress(buffer.Get()); MOZ_ASSERT(frame.GetEnv()->GetDirectBufferCapacity(buffer.Get()) >= sample->Size(), "Decoder buffer is not large enough for sample"); { // We're feeding this to the decoder, so remove it from the queue MonitorAutoLock lock(mMonitor); mQueue.pop(); } PodCopy((uint8_t*)directBuffer, sample->Data(), sample->Size()); res = mDecoder->QueueInputBuffer(inputIndex, 0, sample->Size(), sample->mTime, 0); HANDLE_DECODER_ERROR(); mDurations.push(media::TimeUnit::FromMicroseconds(sample->mDuration)); sample = nullptr; outputDone = false; } } if (!outputDone) { BufferInfo::LocalRef bufferInfo; res = BufferInfo::New(&bufferInfo); HANDLE_DECODER_ERROR(); int32_t outputStatus; res = mDecoder->DequeueOutputBuffer(bufferInfo, DECODER_TIMEOUT, &outputStatus); HANDLE_DECODER_ERROR(); if (outputStatus == MediaCodec::INFO_TRY_AGAIN_LATER) { // We might want to call mCallback->InputExhausted() here, but there seems to be // some possible bad interactions here with the threading } else if (outputStatus == MediaCodec::INFO_OUTPUT_BUFFERS_CHANGED) { res = ResetOutputBuffers(); HANDLE_DECODER_ERROR(); } else if (outputStatus == MediaCodec::INFO_OUTPUT_FORMAT_CHANGED) { res = mDecoder->GetOutputFormat(ReturnTo(&outputFormat)); HANDLE_DECODER_ERROR(); } else if (outputStatus < 0) { NS_WARNING("unknown error from decoder!"); ENVOKE_CALLBACK(Error); // Don't break here just in case it's recoverable. If it's not, others stuff will fail later and // we'll bail out. } else { int32_t flags; res = bufferInfo->Flags(&flags); HANDLE_DECODER_ERROR(); // We have a valid buffer index >= 0 here if (flags & MediaCodec::BUFFER_FLAG_END_OF_STREAM) { if (draining) { draining = false; waitingEOF = false; mMonitor.Lock(); mDraining = false; mMonitor.Notify(); mMonitor.Unlock(); ENVOKE_CALLBACK(DrainComplete); } mDecoder->ReleaseOutputBuffer(outputStatus, false); outputDone = true; // We only queue empty EOF frames, so we're done for now continue; } MOZ_ASSERT(!mDurations.empty(), "Should have had a duration queued"); media::TimeUnit duration; if (!mDurations.empty()) { duration = mDurations.front(); mDurations.pop(); } auto buffer = jni::Object::LocalRef::Adopt( frame.GetEnv()->GetObjectArrayElement(mOutputBuffers.Get(), outputStatus)); if (buffer) { // The buffer will be null on Android L if we are decoding to a Surface void* directBuffer = frame.GetEnv()->GetDirectBufferAddress(buffer.Get()); Output(bufferInfo, directBuffer, outputFormat, duration); } // The Surface will be updated at this point (for video) mDecoder->ReleaseOutputBuffer(outputStatus, true); PostOutput(bufferInfo, outputFormat, duration); } } } Cleanup(); // We're done MonitorAutoLock lock(mMonitor); mStopping = false; mMonitor.Notify(); }
QByteArray CNetworkConnection::peek(qint64 maxlen) { qint64 nBytes = qMin((qint64)GetInputBuffer()->size(), maxlen); return GetInputBuffer()->left(nBytes); }
QByteArray CNetworkConnection::Peek(qint64 nMaxLength) { CBuffer* pBuffer = GetInputBuffer(); return QByteArray::fromRawData(pBuffer->data(), qMin<qint64>(nMaxLength > 0 ? nMaxLength : pBuffer->size(), pBuffer->size())); }