static void iterate( void ) { if( sourceIsPlaying( movingSource ) == AL_FALSE ) { alSourcePlay( movingSource ); fprintf( stderr, "have to sourceplay\n" ); } else { microSleep( 10000 ); } }
int main( int argc, char *argv[] ) { testInit( &argc, argv ); init( ( const ALbyte * ) ( ( argc == 1 ) ? WAVEFILE : argv[1] ) ); start( ); while( sourceIsPlaying( multis ) == AL_TRUE ) { microSleep( 1000000 ); microSleep( 1000000 ); microSleep( 1000000 ); microSleep( 1000000 ); } testExit(); return EXIT_SUCCESS; }
static void iterate( void ) { int i; for ( i = 0; i < NUMSOURCES; i++ ) { if( sourceIsPlaying( multis[i] ) != AL_TRUE ) { alSourcePlay( multis[i] ); } microSleep( 20000 ); } }
static void iterate( void ) { /* static float pitch = 1.0; pitch -= .0021; alSourcef( movingSource, AL_PITCH, pitch ); */ microSleep( 80000 ); }
static void iterate( void ) { static ALfloat speed[3] = { 0.0, 0.0, 0.0 }; speed[2] += .0005; srcposition[0] += speed[0]; srcposition[1] += speed[1]; srcposition[2] += speed[2]; alSourcefv( movingSource, AL_VELOCITY, speed ); alSourcefv( movingSource, AL_POSITION, srcposition ); microSleep( 20000 ); }
void FFmpegDecoderAudio::decodeLoop() { const bool skip_audio = ! validContext() || ! m_audio_sink.valid(); if (! skip_audio && ! m_audio_sink->playing()) { m_clocks.audioSetDelay(m_audio_sink->getDelay()); m_audio_sink->play(); } else { m_clocks.audioDisable(); } while (! m_exit) { if(m_paused) { m_clocks.pause(true); m_pause_timer.setStartTick(); while(m_paused && !m_exit) { microSleep(10000); } m_clocks.setPauseTime(m_pause_timer.time_s()); m_clocks.pause(false); } // If skipping audio, make sure the audio stream is still consumed. if (skip_audio) { bool is_empty; FFmpegPacket packet = m_packets.timedPop(is_empty, 10); if (packet.valid()) packet.clear(); } // Else, just idle in this thread. // Note: If m_audio_sink has an audio callback, this thread will still be awaken // from time to time to refill the audio buffer. else { OpenThreads::Thread::microSleep(10000); } } }
void ParallelRenderingClientIBVerbs::run() { struct ibv_wc wc; struct ibv_cq *ev_cq; void *ev_ctx; while (keepRunning) { lock.lock(); int ne; do { ne = ibv_poll_cq(ctx->cq, 1, &wc); if (ne > 0) { if (ibv_get_cq_event(ctx->ch, &ev_cq, &ev_ctx)) { fprintf(stderr, "Failed to get cq event!\n"); return; } if (ev_cq != ctx->cq) { fprintf(stderr, "Unkown CQ!\n"); return; } ibv_ack_cq_events(ctx->cq, 1); ibv_req_notify_cq(ctx->cq, 0); } microSleep(100); } while (ne == 0); if (ne < 0) { fprintf(stderr, "poll CQ failed %d\n", ne); return; } if (wc.status != IBV_WC_SUCCESS) { fprintf(stderr, "Completion with error at client\n"); fprintf(stderr, "Failed status %d: wr_id %d\n", wc.status, (int)wc.wr_id); return; } } }
virtual void run() { do { std::cout << "(" << _count << ")"; ++_count; if ( _count==10 ) { _operator.release(); _operator.reset(); _operator.block(); } microSleep( 150000L ); } while( !_done ); }
static void iterate( ALuint movingSource ) { static ALfloat position[] = { 10, 0, 4 }; static ALfloat moveFactor = 4.5; static time_t then = 0; time_t now = time( NULL ); /* Switch between left and right stereo sample every two seconds. */ if( now - then > 2 ) { then = now; moveFactor *= -1; } position[0] += moveFactor; alSourcefv( movingSource, AL_POSITION, position ); microSleep( 500000 ); }
void LoadQueue::run() { _finished = false; ErrorDispatcher errorDispatcher("", ErrorDispatcher::THREAD_SAFE); while (!_cancelled) { s_lqMutex->lock(); unsigned int s = _queue.size(); s_lqMutex->unlock(); if ((s > 0) && (_pausing == false)) { s_lqMutex->lock(); osg::ref_ptr<AbstractDataContainer> data = _queue.front().get(); // erstes element holen _queue.pop_front(); // und loeschen _loadInProgress = true; s_lqMutex->unlock(); data->load(); data->setLoadFlag(); data->setQueued(false); _loadInProgress = false; if (data->getErrorCount() > 0) { s_lqMutex->lock(); AbstractDataContainer::ErrorVector errs = data->getErrors(); for ( AbstractDataContainer::ErrorVector::iterator i = errs.begin(); i != errs.end(); i++) { _errors.push_back((*i)); } data->clearErrors(); errorDispatcher.handle("", _errors); _errors.clear(); s_lqMutex->unlock(); } } if (s > 0) osg::notify(osg::INFO) << "LoadQueue:: " << s << " items remaining in the queue." << std::endl; microSleep(100000); } _finished = true; }
void FKFSDynamics::run() // receiving and sending thread, also does the low level simulation like hard limits { fprintf(stderr, "starting Thread\n"); while (doRun) { sendBuffer.wheelAngle = -(InputDevice::instance()->getSteeringWheelAngle() / M_PI) * 180; sendBuffer.gasPedal = InputDevice::instance()->getAccelerationPedal(); sendBuffer.breakPedal = InputDevice::instance()->getBrakePedal(); sendBuffer.gear = InputDevice::instance()->getGear(); sendBuffer.clutchPedal = InputDevice::instance()->getClutchPedal(); sendData(); while (doRun && !readData()) { microSleep(10); } } fprintf(stderr, "waiting2\n"); endBarrier.block(2); fprintf(stderr, "done2\n"); }
static void iterate( void ) { static ALfloat position[] = { 2.0f, 0.0f, 1.0f }; static ALfloat movefactor = 10.0; static time_t then = 0; time_t now; now = time( NULL ); /* Switch between left and right boom every five seconds. */ if( now - then > 5 ) { then = now; movefactor *= -1.0; } position[0] += movefactor; alSourcefv( movingSource, AL_POSITION, position ); microSleep( 500000 ); }
void FFmpegDecoderVideo::decodeLoop() { FFmpegPacket packet; double pts; while (! m_exit) { // Work on the current packet until we have decoded all of it while (m_bytes_remaining > 0) { // Save global PTS to be stored in m_frame via getBuffer() m_packet_pts = packet.packet.pts; // Decode video frame int frame_finished = 0; // We want to use the entire packet since some codecs will require extra information for decoding const int bytes_decoded = avcodec_decode_video2(m_context, m_frame.get(), &frame_finished, &(packet.packet)); if (bytes_decoded < 0) throw std::runtime_error("avcodec_decode_video failed()"); m_bytes_remaining -= bytes_decoded; m_packet_data += bytes_decoded; // Publish the frame if we have decoded a complete frame if (frame_finished) { AVRational timebase; // Find out the frame pts if (m_frame->pts != int64_t(AV_NOPTS_VALUE)) { pts = m_frame->pts; timebase = m_context->time_base; } else if (packet.packet.dts == int64_t(AV_NOPTS_VALUE) && m_frame->opaque != 0 && *reinterpret_cast<const int64_t*>(m_frame->opaque) != int64_t(AV_NOPTS_VALUE)) { pts = *reinterpret_cast<const int64_t*>(m_frame->opaque); timebase = m_stream->time_base; } else if (packet.packet.dts != int64_t(AV_NOPTS_VALUE)) { pts = packet.packet.dts; timebase = m_stream->time_base; } else { pts = 0; timebase = m_context->time_base; } pts *= av_q2d(timebase); const double synched_pts = m_clocks.videoSynchClock(m_frame.get(), av_q2d(timebase), pts); const double frame_delay = m_clocks.videoRefreshSchedule(synched_pts); publishFrame(frame_delay, m_clocks.audioDisabled()); } } while(m_paused && !m_exit) { microSleep(10000); } // Get the next packet pts = 0; if (packet.valid()) packet.clear(); bool is_empty = true; packet = m_packets.timedPop(is_empty, 10); if (! is_empty) { if (packet.type == FFmpegPacket::PACKET_DATA) { m_bytes_remaining = packet.packet.size; m_packet_data = packet.packet.data; } else if (packet.type == FFmpegPacket::PACKET_FLUSH) { avcodec_flush_buffers(m_context); } } } }
void GameServerThread::run() { // small lambda takes and runs next message from the given queue // returns false if queue was empty; true otherwise. auto pullAndRunNextMessage = [this](std::deque<MessagePeer::workPair> &msgQueue) -> bool{ MessagePeer::workPair wP; { OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_serverObject->m_messageQueueMutex); if (msgQueue.empty()) return false; wP = msgQueue.front(); msgQueue.pop_front(); } m_serverObject->takeMessage(wP.first, wP.second); return true; }; // VS steady_clock has about 1 ms precision, which is good enough here m_previousTime = std::chrono::steady_clock::now(); while (m_continueRun) { std::chrono::steady_clock::time_point startTick = std::chrono::steady_clock::now(); // Don't run more work items than you can do per tick // half a tick is a soft boundary here std::chrono::steady_clock::time_point timepoint = std::chrono::steady_clock::now(); // First, dispatch all high priority messages while (pullAndRunNextMessage(m_serverObject->m_highPriorityQueue)) { timepoint = std::chrono::steady_clock::now(); if (timepoint - startTick >= g_serverTick / 2) break; } // Then dispatch normal priority messages, if we have time still if (timepoint - startTick < g_serverTick / 2) while (pullAndRunNextMessage(m_serverObject->m_messageQueue)) { timepoint = std::chrono::steady_clock::now(); if (timepoint - startTick >= g_serverTick / 2) break; } // And then, run the eventService /*if (timepoint - startTick < g_serverTick / 2) */while (m_serverObject->m_eventService.poll_one() > 0) { timepoint = std::chrono::steady_clock::now(); if (timepoint - startTick >= g_serverTick/2) break; } m_serverObject->m_eventService.reset(); timepoint = std::chrono::steady_clock::now(); float dt = std::chrono::duration_cast<std::chrono::microseconds>(timepoint - m_previousTime).count() / 1000.0f; m_serverObject->physicsTick(dt); m_previousTime = timepoint; timepoint = std::chrono::steady_clock::now(); //dt = std::chrono::duration_cast<std::chrono::microseconds>(timepoint - startTick).count() / 1000.0f; if (timepoint - startTick < g_serverTick) microSleep(g_serverTick.count() - std::chrono::duration_cast<std::chrono::microseconds>(timepoint - startTick).count()); } }
void TiledDisplayServerVV::run() { #ifdef TILED_DISPLAY_SERVER_TIME_RUN Timer runTimer; bool startTimer = true; #endif cerr << "TiledDisplayServerVV::run info: server " << number << " start server" << endl; #ifdef TILE_ENCODE_JPEG cerr << "TiledDisplayServerVV::run info: server " << number << " uses JPEG encoding" << endl; #endif isRunning = true; accept(); char frameTimeBuffer[sizeof(opencover::cover->frameTime())]; while (keepRunning) { if (bufferAvailable) { #ifdef TILED_DISPLAY_SERVER_TIME_RUN if (startTimer) { runTimer.start(number); startTimer = false; } else { runTimer.restart(number); } #endif //cerr << "TiledDisplayServerVV::run info: server " << number << " before lock" << endl; #ifndef TILED_DISPLAY_SYNC sendLock.lock(); #endif //cerr << "TiledDisplayServerVV::run info: server " << number << " receive image" << endl; socket->getData(frameTimeBuffer, sizeof(double), vvSocketIO::VV_UCHAR); memcpy(&frameTime, frameTimeBuffer, sizeof(double)); /* if (frameTime == cover->frameTime()) { cerr << "TiledDisplayServerVV::run info: server" << number << ": local time = " << cover->frameTime() - 1.15333e+09 << ", remote time = " << frameTime - 1.15333e+09 << ", equals: " << (frameTime == cover->frameTime()) << endl; } else { cerr << "TiledDisplayServerVV::run info: server" << number << ": local time = " << cover->frameTime() - 1.15333e+09 << ", remote time = " << frameTime - 1.15333e+09 << ", equals: " << (frameTime == cover->frameTime()) << endl; } */ #ifdef TILE_ENCODE_JPEG unsigned int compressedDataSize = jpegImage.compressedDataSize; socket->getInt32(jpegImage.compressedDataSize); if (jpegImage.compressedDataSize == 0) continue; if (compressedDataSize < jpegImage.compressedDataSize) { delete[] jpegImage.compressedData; jpegImage.compressedData = new unsigned char[jpegImage.compressedDataSize]; compressedDataSize = jpegImage.compressedDataSize; } vvSocket::ErrorType err; err = socket->getData(jpegImage.compressedData, jpegImage.compressedDataSize, vvSocketIO::VV_UCHAR); if (err != vvSocket::VV_OK) { cerr << "TiledDisplayServerVV::run err: comm error " << err << " for server " << number << " reading " << jpegImage.compressedDataSize << " bytes" << endl; } else { //cerr << "TiledDisplayServerVV::run info: got " << jpegImage.compressedDataSize // << " bytes from server " << number << endl; } if (!jpegImage.compressedData) continue; jpegDecoder.decode(jpegImage); int w = jpegImage.width; int h = jpegImage.height; if (dimension.width != w || dimension.height != h) { cerr << "TiledDisplayServerVV::run info: resizing pixelarray from [" << dimension.width << "|" << dimension.height << "] to [" << w << "|" << h << "]" << endl; dimension.width = w; dimension.height = h; delete[] pixels; pixels = new unsigned char[w * h * 3]; } memcpy(pixels, jpegImage.data, w * h * 3); #else int w; int h; socket->getInt32(w); socket->getInt32(h); if (dimension.width != w || dimension.height != h) { cerr << "TiledDisplayServerVV::run info: resizing pixelarray from [" << dimension.width << "|" << dimension.height << "] to [" << w << "|" << h << "]" << endl; dimension.width = w; dimension.height = h; delete[] pixels; pixels = new unsigned char[w * h * 4]; } vvSocket::ErrorType err = socket->getData((void *)pixels, w * h * 4, vvSocketIO::VV_UCHAR); if (err == vvSocket::VV_OK) { //cerr << "TiledDisplayServerVV::run info: received " << w*h*4 << " bytes from client " << number << endl; } else { cerr << "TiledDisplayServerVV::run err: comm error " << err << endl; } #endif // TILE_ENCODE_JPEG bufferAvailable = false; dataAvailable = true; #ifdef TILED_DISPLAY_SYNC sendBarrier.block(2); #else sendLock.unlock(); #endif #ifdef TILED_DISPLAY_SERVER_TIME_RUN cerr << "TiledDisplayServerVV::run info: server " << number << " recv. data in " << runTimer.elapsed(number) << " usec, avg. cps = " << runTimer.cps(number) << endl; #endif } microSleep(10000); } isRunning = false; cerr << "TiledDisplayServerVV::run info: server " << number << " stop server" << endl; }
int main( int argc, char *argv[] ) { ALCdevice *device; int attributeList[] = { ALC_FREQUENCY, 22050, 0 }; time_t shouldend, start; ALint test = AL_FALSE; device = alcOpenDevice( NULL ); if( device == NULL ) { return EXIT_FAILURE; } /* Initialize ALUT. */ context = alcCreateContext( device, attributeList ); if( context == NULL ) { alcCloseDevice( device ); exit( EXIT_FAILURE ); } alcMakeContextCurrent( context ); testInitWithoutContext( &argc, argv ); getExtensionEntries( ); palBombOnError( ); init( ( const ALbyte * ) ( ( argc == 1 ) ? WAVEFILE : argv[1] ) ); fprintf( stderr, "Loop for 4 seconds\n" ); alSourcePlay( movingSource ); shouldend = start = time( NULL ); while( shouldend - start <= 4 ) { shouldend = time( NULL ); microSleep( 1000000 ); } alSourceStop( movingSource ); test = -1; alGetSourceiv( movingSource, AL_LOOPING, &test ); fprintf( stderr, "is looping? getsi says %s\n", ( test == AL_TRUE ) ? "AL_TRUE" : "AL_FALSE" ); /* part the second */ fprintf( stderr, "Play once\n" ); microSleep( 1000000 ); alSourcei( movingSource, AL_LOOPING, AL_FALSE ); alSourcePlay( movingSource ); do { microSleep( 1000000 ); } while( sourceIsPlaying( movingSource ) ); testExit(); alcDestroyContext( context ); alcCloseDevice( device ); return EXIT_SUCCESS; }