SyncResponse::SyncResponse(int16_t operation, int32_t base_count) : DataServerResponse(operation) { AtomicSet(&base_count_, base_count); response_ok_ = false; AtomicSet(&response_count_, 0); AtomicSet(&error_, 0); wait_ = true; }
WriteResponse::WriteResponse(int16_t operation, AmFrame::StreamEndPoint end_point, uint32_t channel_id, uint64_t peer_id) :DataServerResponse(operation), end_point_(end_point), channel_id_(channel_id), peer_id_(peer_id) { AtomicSet(&response_count_,0); AtomicSet(&error_,0); }
void OpenSLPlayer::play(bool loop, bool reset) { lock(); accessTime = currentTimeMillis(); if (player == NULL) { unlock(); return; } //SLresult result; if (reset) (*playerSeek)->SetPosition(playerSeek, 0, SL_SEEKMODE_FAST); /*result = */(*playerSeek)->SetLoop(playerSeek, loop ? SL_BOOLEAN_TRUE : SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN); /*result= */(*player)->SetPlayState(player, SL_PLAYSTATE_PLAYING); AtomicSet(&state, SL_PLAYSTATE_PLAYING); AtomicSet(&this->loop, loop); unlock(); }
void OpenSLPlayer::stop() { lock(); accessTime = currentTimeMillis(); AtomicSet(&state, SL_PLAYSTATE_STOPPED); AtomicSet(&resume, false); AtomicSet(&reset, false); if (player == NULL) { unlock(); return; } //SLresult result; /*result= */(*player)->SetPlayState(player, SL_PLAYSTATE_STOPPED); OpenSLSound* sound = AtomicGetPtr(&this->sound); if (sound != NULL) { sound->reset(); } unlock(); }
void OpenSLPlayer::restore() { lock(); accessTime = currentTimeMillis(); if (player == NULL) { unlock(); return; } if (isPaused() && AtomicExchange(&resume, false)) { if (AtomicExchange(&reset, false)) (*playerSeek)->SetPosition(playerSeek, 0, SL_SEEKMODE_FAST); (*playerSeek)->SetLoop(playerSeek, AtomicGet(&loop) ? SL_BOOLEAN_TRUE : SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN); (*player)->SetPlayState(player, SL_PLAYSTATE_PLAYING); AtomicSet(&state, SL_PLAYSTATE_PLAYING); } unlock(); }
void OpenSLContext::pause() { lock(); if (!AtomicExchange(&paused, true)) { for (int i = 0; i < OPENSL_CHANNELS; i++) { OpenSLPlayer *player = AtomicGet(&(players[i])); if (player != NULL) { player->lock(); if (player->isPlaying()) { player->pause(); AtomicSet(&player->resume, true); } player->unlock(); } } } unlock(); }
OpenSLPlayer::OpenSLPlayer(OpenSLContext* context) { AtomicSet(&(this->context), context); }
OpenSLPlayer* OpenSLContext::getFreePlayer(OpenSLSound* sound) { lock(); int empty = -1; int old_index = -1; uint64_t old_access = 0; OpenSLContext_getFreePlayer_repeat: for (int i = 0; i < OPENSL_CHANNELS; i++) { OpenSLPlayer *player = AtomicGet(&(players[i])); if (player == NULL) { empty = i; } else { player->lock(); if ((old_access == 0) || (player->accessTime <= old_access)) { old_index = i; old_access = player->accessTime; } if (player->isStopped()) { unlock(); AtomicSet(&player->resume, false); return player; } player->unlock(); } } if (empty >= 0) { OpenSLPlayer *player; AtomicSet(&(players[empty]), player = new OpenSLPlayer(this)); player->lock(); unlock(); return player; } if (old_index >= 0) { OpenSLPlayer *player = AtomicGet(&(players[old_index])); if (player != NULL) { player->lock(); if (player->isPlaying()) { player->stop(); } AtomicSet(&player->resume, false); unlock(); return player; } } goto OpenSLContext_getFreePlayer_repeat; }
/*----------------------------------WriteResponse-----------------------------------------*/ WriteResponse::WriteResponse() : DataServerResponse() { channel_id_ = 0; AtomicSet(&response_count_,0); }