void AVIDecoder::readNextPacket() { // Shouldn't get this unless called on a non-open video if (_videoTracks.empty()) return; // Get the video frame first handleNextPacket(_videoTracks[0]); // Handle audio tracks next for (uint32 i = 0; i < _audioTracks.size(); i++) handleNextPacket(_audioTracks[i]); }
//----------------------------------------------------------------------------- void ScanDataReceiver::handleSocketRead(const boost::system::error_code& error) { if (!error ) { // Read all received data and write it to the internal ring buffer instream_.clear(); while(!instream_.eof()) { char buf[4096]; instream_.read(buf,4096); int bytes_read = instream_.gcount(); writeBufferBack(buf,bytes_read); } // Handle (read and parse) packets stored in the internal ring buffer while( handleNextPacket() ) {} // Read data asynchronously boost::asio::async_read(*tcp_socket_, inbuf_, boost::bind(&ScanDataReceiver::handleSocketRead, this, boost::asio::placeholders::error)); } else { if( error.value() != 995 ) std::cerr << "ERROR: " << "data connection error: " << error.message() << "(" << error.value() << ")" << std::endl; disconnect(); } last_data_time_ = std::time(0); }
void AVIDecoder::checkTruemotion1() { // If we got here from loadStream(), we know the track is valid assert(!_videoTracks.empty()); TrackStatus &status = _videoTracks[0]; AVIVideoTrack *track = (AVIVideoTrack *)status.track; // Ignore non-truemotion tracks if (!track->isTruemotion1()) return; // Read the next video packet handleNextPacket(status); const Graphics::Surface *frame = track->decodeNextFrame(); if (!frame) { rewind(); return; } // Fill in the width/height based on the frame's width/height _header.width = frame->w; _header.height = frame->h; track->forceDimensions(frame->w, frame->h); // Rewind us back to the beginning rewind(); }
void AVIDecoder::readNextPacket() { // Shouldn't get this unless called on a non-open video if (_videoTracks.empty()) return; // Handle the video first for (uint idx = 0; idx < _videoTracks.size(); ++idx) handleNextPacket(_videoTracks[idx]); // Handle any transparency track if (_transparencyTrack.track) handleNextPacket(_transparencyTrack); // Handle audio tracks next for (uint idx = 0; idx < _audioTracks.size(); ++idx) handleNextPacket(_audioTracks[idx]); }
void ScanDataReceiverTCP::run() { char* buffer = data_buffer_.data(); // thread worker #if __cplusplus>=201103 isRunning = true; while(isRunning) #else bool doIt = true; run_mutex.lock(); isRunning = true; run_mutex.unlock(); while(doIt) #endif { // do std::size_t numBytes = tcp_socket.receiveBytes(buffer, data_buffer_.size()); if (numBytes == 0) break; // gracefull shutdown... // write data to ringbuffer writeBufferBack(buffer, numBytes); // handle packets while( handleNextPacket() ) {} #if __cplusplus<201103 run_mutex.lock(); doIt = isRunning; run_mutex.unlock(); #endif } // thread done }
//----------------------------------------------------------------------------- void ScanDataReceiver::handleSocketRead(const boost::system::error_code &error, std::size_t bytes_transferred) { if (!error ) { // Read all received data and write it to the internal ring buffer writeBufferBack(&udp_buffer_[0],bytes_transferred); // Handle (read and parse) packets stored in the internal ring buffer while( handleNextPacket() ) {} // Read data asynchronously udp_socket_->async_receive_from(boost::asio::buffer(&udp_buffer_[0],udp_buffer_.size()), udp_endpoint_, boost::bind(&ScanDataReceiver::handleSocketRead, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); } else { if( error.value() != 995 ) std::cerr << "ERROR: " << "data connection error: " << error.message() << "(" << error.value() << ")" << std::endl; disconnect(); } last_data_time_ = std::time(0); }