void InterSense::deviceThreadMethod(void) { /* Reset first measurement flags: */ for(int i=0;i<numTrackers;++i) notFirstMeasurements[i]=false; /* Read first record in synchronizing mode: */ int stationId; char recordBuffer[256]; stationId=readRecordSync(recordBuffer); /* Parse read buffer: */ processBuffer(stationIdToIndex[stationId],recordBuffer); while(true) { /* Try reading record in synchronized mode: */ if((stationId=readRecordNoSync(recordBuffer))==0) { /* Fall back to synchronizing mode: */ #ifdef VERBOSE printf("InterSense: Resynchronizing with tracker stream\n"); fflush(stdout); #endif stationId=readRecordSync(recordBuffer); } /* Parse read buffer: */ processBuffer(stationIdToIndex[stationId],recordBuffer); } }
static void readLogLines(int logfd) { while (1) { unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1] __attribute__((aligned(4))); struct logger_entry *entry = (struct logger_entry *) buf; int ret; ret = read(logfd, entry, LOGGER_ENTRY_MAX_LEN); if (ret < 0) { if (errno == EINTR) continue; if (errno == EAGAIN) break; perror("logcat read"); exit(EXIT_FAILURE); } else if (!ret) { fprintf(stderr, "read: Unexpected EOF!\n"); exit(EXIT_FAILURE); } /* NOTE: driver guarantees we read exactly one full entry */ entry->msg[entry->len] = '\0'; if (g_printBinary) { printBinary(entry); } else { (void) processBuffer(entry); } } }
bool KeyStream::decodeMessage(QByteArray& buffer, int macOffset, int offset, int length) { //qDebug() << "decodeMessage seq:" << seq; QByteArray base = buffer.left(buffer.size() - 4); QByteArray hmac = buffer.right(4); QByteArray buffer2 = processBuffer(base, seq++); buffer2 = mac->hmacSha1(buffer2); QByteArray origBuffer = buffer; buffer = base; rc4->Cipher(buffer.data(),0,buffer.size()); for (int i = 0; i < 4; i++) { if (buffer2[macOffset + i] != hmac[i]) { qDebug() << "error decoding message. macOffset:" << macOffset << "offset:" << offset << "length:" << length << "bufferSize:" << buffer.size(); qDebug() << "buffer mac:" << buffer2.toHex() << "hmac:" << hmac.toHex(); qDebug() << "buffer:" << buffer.toHex(); qDebug() << "origBuffer:" << origBuffer.toHex(); return false; } } return true; }
void ttSerialDevice::update() { if ( m_connection.isInitialized() ) { int available = m_connection.available(); if ( available > 0 ) { unsigned char* buffer = new unsigned char [ available + 1 ]; buffer[ available ] = 0; m_connection.readBytes(buffer,available); // // // bool partial_message = m_buffer.tellp() > 0; for ( int i = 0; i < available; i++ ) { if ( partial_message ) { if ( buffer[ i ] == ']' ) { // end message processBuffer(); return; } else { m_buffer << buffer[ i ]; } } else if ( buffer[ i ] == '[' ) { // start of message partial_message = true; } } } } }
void EPDStreamer::processResponse() { while (connState == STATE_CONN_CONNECTED) { while (client.available()) { char c = client.read(); if (httpState == STATE_HTTP_BODY) { if (callbacksEnabled && onBodyByteReadCallback) { onBodyByteReadCallback(c); } } else { if (c == 13) { continue; } else if (c == 10) { buffer[bufferPtr] = 0; processBuffer(); bufferPtr = 0; } else { buffer[bufferPtr++] = c; } } } if (!client.connected()) { Serial.println("The client has disconnected"); client.stop(); connState = STATE_CONN_DISCONNECTED; if (httpState == STATE_HTTP_BODY && callbacksEnabled && onStreamingCompletedCallback) { onStreamingCompletedCallback(); } } } }
void WebSocketChannel::didReceiveSocketStreamData(SocketStreamHandle& handle, const char* data, std::optional<size_t> len) { if (len) LOG(Network, "WebSocketChannel %p didReceiveSocketStreamData() Received %zu bytes", this, len.value()); else LOG(Network, "WebSocketChannel %p didReceiveSocketStreamData() Received no bytes", this); Ref<WebSocketChannel> protectedThis(*this); // The client can close the channel, potentially removing the last reference. ASSERT(&handle == m_handle); if (!m_document) { return; } if (!len || !len.value()) { handle.disconnect(); return; } if (!m_client) { m_shouldDiscardReceivedData = true; handle.disconnect(); return; } if (m_shouldDiscardReceivedData) return; if (!appendToBuffer(data, len.value())) { m_shouldDiscardReceivedData = true; fail("Ran out of memory while receiving WebSocket data."); return; } while (!m_suspended && m_client && !m_buffer.isEmpty()) { if (!processBuffer()) break; } }
void PackParser::processBuffer() { if(last_pack_unfinished){ if(raw_buffer_.bytesAvailable() >= pack_size){ QByteArray info = raw_buffer_.read(pack_size); last_pack_unfinished = false; emit newRawPack(info); }else{ return; } } if(raw_buffer_.size() < 4){ return; } // in case we have a lot of data to process QCoreApplication::processEvents(); char c1, c2, c3, c4; raw_buffer_.getChar(&c1); raw_buffer_.getChar(&c2); raw_buffer_.getChar(&c3); raw_buffer_.getChar(&c4); pack_size = (uchar(c1) << 24) + (uchar(c2) << 16) + (uchar(c3) << 8) + uchar(c4); processBuffer(); }
void MainThreadWebSocketChannel::resumeTimerFired(Timer<MainThreadWebSocketChannel>* timer) { ASSERT_UNUSED(timer, timer == &m_resumeTimer); processBuffer(); if (!m_suspended && m_client && (m_state == ChannelClosed) && m_handle) didCloseSocketStream(m_handle.get()); }
static void printNextEntry(log_device_t* dev) { maybePrintStart(dev); if (g_printBinary) { printBinary(&dev->queue->entry); } else { processBuffer(dev, &dev->queue->entry); } skipNextEntry(dev); }
void WebSocketChannel::resumeTimerFired() { Ref<WebSocketChannel> protectedThis(*this); // The client can close the channel, potentially removing the last reference. while (!m_suspended && m_client && !m_buffer.isEmpty()) if (!processBuffer()) break; if (!m_suspended && m_client && m_closed && m_handle) didCloseSocketStream(*m_handle); }
void TCPStreamSink::afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes) { if (numTruncatedBytes > 0) { envir() << "TCPStreamSink::afterGettingFrame(): The input frame data was too large for our buffer. " << numTruncatedBytes << " bytes of trailing data was dropped! Correct this by increasing the definition of \"TCP_STREAM_SINK_BUFFER_SIZE\" in \"include/TCPStreamSink.hh\".\n"; } fUnwrittenBytesEnd += frameSize; processBuffer(); }
void KeyStream::encodeMessage(QByteArray &buffer, int macOffset, int offset, int length, bool dout) { //qDebug() << "encodeMessage seq:" << seq; rc4->Cipher(buffer.data(),offset,length); QByteArray base = buffer.mid(offset,length); base = processBuffer(base, seq++); QByteArray hmac = mac->hmacSha1(base); hmac.resize(4); buffer.replace(macOffset, 4, hmac.constData(), 4); }
void WebSocketChannel::resumeTimerFired(Timer<WebSocketChannel>* timer) { ASSERT_UNUSED(timer, timer == &m_resumeTimer); RefPtr<WebSocketChannel> protect(this); // The client can close the channel, potentially removing the last reference. while (!m_suspended && m_client && m_buffer) if (!processBuffer()) break; if (!m_suspended && m_client && m_closed && m_handle) didClose(m_handle.get()); }
void Connection::socketData() { int toRead; int bytesRead=0; int thisRead; toRead=tcpSocket->bytesAvailable(); while(bytesRead<toRead) { switch(state) { case READ_HEADER_TYPE: thisRead=tcpSocket->read(&hdr[0],1); if (thisRead == 1) bytes++; if (hdr[0] == AUDIO_BUFFER) state=READ_AUDIO_HEADER; else state=READ_HEADER; break; case READ_AUDIO_HEADER: thisRead=tcpSocket->read(&hdr[bytes],AUDIO_HEADER_SIZE - bytes); bytes+=thisRead; if ((bytes == AUDIO_HEADER_SIZE)){ length = atoi(&hdr[AUDIO_LENGTH_POSITION]); buffer = (char*)malloc(length); bytes = 0; state = READ_BUFFER; } break; case READ_HEADER: thisRead=tcpSocket->read(&hdr[bytes],HEADER_SIZE - bytes); bytes+=thisRead; if(bytes==HEADER_SIZE) { length=atoi(&hdr[26]); buffer=(char*)malloc(length); bytes=0; state=READ_BUFFER; } break; case READ_BUFFER: thisRead=tcpSocket->read(&buffer[bytes],length-bytes); bytes+=thisRead; //qDebug() << "READ_BUFFER: read " << bytes << " of " << length; if(bytes==length) { queue.enqueue(new Buffer(hdr,buffer)); QTimer::singleShot(0,this,SLOT(processBuffer())); hdr=(char*)malloc(HEADER_SIZE); bytes=0; state=READ_HEADER_TYPE; } break; } bytesRead+=thisRead; } }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { Fdata=new fft; Wdata=new wavedata; probe=new QAudioProbe; Ddata=new detaildata; l=new QStringList; label=new QLabel; label->resize( QSize( 500, 100 )); QPalette pa; pa.setColor(QPalette::Background, QColor(0x00,0xff,0x00,0x00)); pa.setColor(QPalette::WindowText,Qt::white); label->setPalette (pa); QFont ft; ft.setPointSize(14); label->setFont(ft); volume=80; order=0; ismute=0; ui->setupUi(this); pushButtonc=0; ui->tableWidget->clearContents(); ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); playList=new QMediaPlaylist; playList->setPlaybackMode(QMediaPlaylist::Loop); player=new QMediaPlayer; player->setPlaylist(playList); player->setVolume(volume); ui->horizontalSlider->setRange(0, 0); ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->tableWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_contextmenu(const QPoint&))); connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged1(qint64))); connect(player, SIGNAL(durationChanged(qint64)), this, SLOT(durationChanged1(qint64))); probe->setSource(player); connect(probe,SIGNAL(audioBufferProbed(QAudioBuffer)),Wdata,SLOT(processBuffer(QAudioBuffer))); //connect(probe,SIGNAL(audioBufferProbed(QAudioBuffer)),this,SLOT(test(QAudioBuffer))); connect(Wdata,SIGNAL(wavedataUpdated(wavedata&)),Fdata,SLOT(calculateFFT(wavedata&))); connect(Wdata,SIGNAL(wavedataUpdated(wavedata&)),Ddata,SLOT(processWaveData(wavedata&))); connect(Fdata,SIGNAL(FFTstandby(fft&)),Ddata,SLOT(processFFTData(fft&))); connect(Ddata,SIGNAL(detailDataStandbyT(QString&)),this,SLOT(update_ZhuangBi(QString&))); }
void StreamingPlayer::poling() { int processed = cross::AudioSystem::getSourceProcessed(source_id_); if (processed) { cross::AudioSystem::BufferID buffer; // 処理を終えたキューをデキュー cross::AudioSystem::unqueueBuffers(source_id_, 1, &buffer); // バッファを埋める processBuffer(buffer); // エンキュー cross::AudioSystem::queueBuffers(source_id_, 1, &buffer); } }
bool ImuseChannel::appendData(Common::SeekableReadStream &b, int32 size) { if (_dataSize == -1) { assert(size > 8); uint32 imus_type = b.readUint32BE(); /*uint32 imus_size =*/ b.readUint32BE(); if (imus_type != MKTAG('i','M','U','S')) error("Invalid Chunk for imuse_channel"); size -= 8; _tbufferSize = size; assert(_tbufferSize); _tbuffer = (byte *)malloc(_tbufferSize); if (!_tbuffer) error("imuse_channel failed to allocate memory"); b.read(_tbuffer, size); _dataSize = -2; } else { if (_tbuffer) { byte *old = _tbuffer; int32 new_size = size + _tbufferSize; _tbuffer = (byte *)malloc(new_size); if (!_tbuffer) error("imuse_channel failed to allocate memory"); memcpy(_tbuffer, old, _tbufferSize); free(old); b.read(_tbuffer + _tbufferSize, size); _tbufferSize += size; } else { _tbufferSize = size; _tbuffer = (byte *)malloc(_tbufferSize); if (!_tbuffer) error("imuse_channel failed to allocate memory"); b.read(_tbuffer, size); } } processBuffer(); _srbufferSize = _sbufferSize; if (_sbuffer && _bitsize == 12) decode(); return true; }
// 读取客户端数据 void ReadFromClient(aeEventLoop *el, int fd, void *privdata, int mask) { int res; client_t* c = privdata; res = read(fd, c->request + c->len, MAX_LEN - c->len); if( res <= 0 ) { ClientClose(el, c, res); return; } c->len += res; if(processBuffer(el, c, res) == OK) { if(aeCreateFileEvent(el, fd, AE_WRITABLE, sendReplyToClient, c) == AE_ERR) { fprintf(stderr, "Can't Register File Writeable Event.\n"); ClientClose(el, c, res); } } }
// figure processing latency by doing 'dry runs' of processBuffer() bigtime_t AudioFilterNode::calcProcessingLatency() { PRINT(("AudioFilterNode::calcProcessingLatency()\n")); ASSERT(m_input.source != media_source::null); ASSERT(m_output.destination != media_destination::null); ASSERT(m_op); // initialize filter m_op->init(); size_t maxSize = max_c( m_input.format.u.raw_audio.buffer_size, m_output.format.u.raw_audio.buffer_size); // allocate a temporary buffer group BBufferGroup* testGroup = new BBufferGroup( maxSize, 1); // fetch a buffer big enough for in-place processing BBuffer* buffer = testGroup->RequestBuffer( maxSize, -1); ASSERT(buffer); buffer->Header()->type = B_MEDIA_RAW_AUDIO; buffer->Header()->size_used = m_input.format.u.raw_audio.buffer_size; // run the test bigtime_t preTest = system_time(); processBuffer(buffer, buffer); bigtime_t elapsed = system_time()-preTest; // clean up buffer->Recycle(); delete testGroup; // reset filter state m_op->init(); return elapsed;// + 100000LL; }
/// return latest hash as bytes void SHA1::getHash(unsigned char buffer[SHA1::HashBytes]) { // save old hash if buffer is partially filled uint32_t oldHash[HashValues]; for (int i = 0; i < HashValues; i++) oldHash[i] = m_hash[i]; // process remaining bytes processBuffer(); unsigned char* current = buffer; for (int i = 0; i < HashValues; i++) { *current++ = (m_hash[i] >> 24) & 0xFF; *current++ = (m_hash[i] >> 16) & 0xFF; *current++ = (m_hash[i] >> 8) & 0xFF; *current++ = m_hash[i] & 0xFF; // restore old hash m_hash[i] = oldHash[i]; } }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); createTrayIcon(); createAudioRecorder(); createDeviceList(); createRecordButtonsGroup(); connect(audioRecorder, SIGNAL(stateChanged(QMediaRecorder::State)), this, SLOT(onStateChanged(QMediaRecorder::State))); connect(audioRecorder, SIGNAL(durationChanged(qint64)), this, SLOT(updateProgress(qint64))); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); connect(recordButtons, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(toggleRecord(QAbstractButton*))); connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(processBuffer(QAudioBuffer))); }
bool SaudChannel::appendData(Common::SeekableReadStream &b, int32 size) { if (_dataSize == -1) { assert(size > 8); uint32 saud_type = b.readUint32BE(); /*uint32 saud_size =*/ b.readUint32BE(); if (saud_type != MKID_BE('SAUD')) error("Invalid Chunk for SaudChannel : %X", saud_type); size -= 8; _dataSize = -2; } if (_tbuffer) { byte *old = _tbuffer; _tbuffer = (byte *)malloc(_tbufferSize + size); if (!_tbuffer) error("saud_channel failed to allocate memory"); memcpy(_tbuffer, old, _tbufferSize); free(old); b.read(_tbuffer + _tbufferSize, size); _tbufferSize += size; } else { _tbufferSize = size; _tbuffer = (byte *)malloc(_tbufferSize); if (!_tbuffer) error("saud_channel failed to allocate memory"); b.read(_tbuffer, _tbufferSize); } if (_keepSize) { _sbufferSize = _tbufferSize; _sbuffer = _tbuffer; _tbufferSize = 0; _tbuffer = 0; } else { processBuffer(); } return true; }
/// return latest hash as 16 hex characters std::string Keccak::getHash() { // process remaining bytes processBuffer(); // convert hash to string static const char dec2hex[16 + 1] = "0123456789abcdef"; // number of significant elements in hash (uint64_t) unsigned int hashLength = m_bits / 64; std::string result; for (unsigned int i = 0; i < hashLength; i++) for (unsigned int j = 0; j < 8; j++) // 64 bits => 8 bytes { // convert a byte to hex unsigned char oneByte = (unsigned char) (m_hash[i] >> (8 * j)); result += dec2hex[oneByte >> 4]; result += dec2hex[oneByte & 15]; } return result; }
TestVideoSource::TestVideoSource(QString uid, QString name, int width, int height) { mUid = uid; mName = name; mConnected = false; mStreaming = false; mValidData = true; mInitialized = false; mFrames = 0; mResolution = 1; mWidth = width; mHeight = height; mImageImport = vtkImageImportPtr::New(); setResolution(mResolution); mImageTimer = new QTimer(this); connect(mImageTimer, SIGNAL(timeout()), this, SLOT(processBuffer())); mBuffer = (uint8_t*)malloc(width * height * 3); mImageImport->SetDataScalarTypeToUnsignedChar(); mImageImport->SetNumberOfScalarComponents(3); mImageImport->SetWholeExtent(0, mWidth - 1, 0, mHeight - 1, 0, 0); mImageImport->SetDataExtentToWholeExtent(); }
/// return latest hash as 16 hex characters std::string SHA3::getHash() { // process remaining bytes processBuffer(); // convert hash to string static const char dec2hex[16 + 1] = "0123456789abcdef"; // number of significant elements in hash (uint64_t) unsigned int hashLength = m_bits / 64; std::string result; result.reserve(m_bits / 4); for (unsigned int i = 0; i < hashLength; i++) for (unsigned int j = 0; j < 8; j++) // 64 bits => 8 bytes { // convert a byte to hex unsigned char oneByte = (unsigned char) (m_hash[i] >> (8 * j)); result += dec2hex[oneByte >> 4]; result += dec2hex[oneByte & 15]; } // SHA3-224's last entry in m_hash provides only 32 bits instead of 64 bits unsigned int remainder = m_bits - hashLength * 64; unsigned int processed = 0; while (processed < remainder) { // convert a byte to hex unsigned char oneByte = (unsigned char) (m_hash[hashLength] >> processed); result += dec2hex[oneByte >> 4]; result += dec2hex[oneByte & 15]; processed += 8; } return result; }
void MainThreadWebSocketChannel::didReceiveSocketStreamData(SocketStreamHandle* handle, const char* data, int len) { WTF_LOG(Network, "MainThreadWebSocketChannel %p didReceiveSocketStreamData() Received %d bytes", this, len); ASSERT(handle == m_handle); if (!m_document) return; if (len <= 0) { disconnectHandle(); return; } if (!m_client) { m_shouldDiscardReceivedData = true; disconnectHandle(); return; } if (m_shouldDiscardReceivedData) return; if (!appendToBuffer(data, len)) { m_shouldDiscardReceivedData = true; failAsError("Ran out of memory while receiving WebSocket data."); return; } processBuffer(); }
/// return latest hash as 16 hex characters std::string SHA1::getHash() { // convert hash to string static const char dec2hex[16+1] = "0123456789abcdef"; // save old hash if buffer is partially filled uint32_t oldHash[HashValues]; for (int i = 0; i < HashValues; i++) oldHash[i] = m_hash[i]; // process remaining bytes processBuffer(); // create hash string char hashBuffer[HashValues*8+1]; size_t offset = 0; for (int i = 0; i < HashValues; i++) { hashBuffer[offset++] = dec2hex[(m_hash[i] >> 28) & 15]; hashBuffer[offset++] = dec2hex[(m_hash[i] >> 24) & 15]; hashBuffer[offset++] = dec2hex[(m_hash[i] >> 20) & 15]; hashBuffer[offset++] = dec2hex[(m_hash[i] >> 16) & 15]; hashBuffer[offset++] = dec2hex[(m_hash[i] >> 12) & 15]; hashBuffer[offset++] = dec2hex[(m_hash[i] >> 8) & 15]; hashBuffer[offset++] = dec2hex[(m_hash[i] >> 4) & 15]; hashBuffer[offset++] = dec2hex[ m_hash[i] & 15]; // restore old hash m_hash[i] = oldHash[i]; } // zero-terminated string hashBuffer[offset] = 0; // convert to std::string return hashBuffer; }
void WebSocketChannel::didReceiveData(SocketStreamHandle* handle, const char* data, int len) { LOG(Network, "WebSocketChannel %p didReceiveData %d", this, len); RefPtr<WebSocketChannel> protect(this); // The client can close the channel, potentially removing the last reference. ASSERT(handle == m_handle); if (!m_context) { return; } if (!m_client) { m_shouldDiscardReceivedData = true; handle->close(); return; } if (m_shouldDiscardReceivedData) return; if (!appendToBuffer(data, len)) { m_shouldDiscardReceivedData = true; handle->close(); return; } while (!m_suspended && m_client && m_buffer) if (!processBuffer()) break; }
void TCPStreamSink::socketWritableHandler1() { envir().taskScheduler().disableBackgroundHandling(fOutputSocketNum); // disable this handler until the next time it's needed fOutputSocketIsWritable = True; processBuffer(); }
Boolean TCPStreamSink::continuePlaying() { fInputSourceIsOpen = fSource != NULL; processBuffer(); return True; }