// We could consider having CActiveSchedulerWait owned by the watchdog // object, as then the watchdog itself could implement a Loop method; // no one else really uses CActiveSchedulerWait anyway. void MainLoopL() { CActiveSchedulerWait* loop = new (ELeave) CActiveSchedulerWait; CleanupStack::PushL(loop); // The watchdog will be running after its initialization. In error // situations it will invoke AsyncStop() on the passed loop. CWatchdog* watchdog = CWatchdog::NewLC(*loop); watchdog->Start(); // AsyncStop will cause an exit from the loop, but we only want to // invoke AsyncStop in severe error situations. This means that if // Start() does return, then there must have been an error. loop->Start(); CleanupStack::PopAndDestroy(watchdog); CleanupStack::PopAndDestroy(loop); }
TInt CAsyWait::StartWaitD() { SetActive(); iWaiter->Start(); TInt err = iStatus.Int(); delete this; return err; }
pj_status_t CPjAudioInputEngine::StartRecord() { // Ignore command if recording is in progress. if (state_ == STATE_ACTIVE) return PJ_SUCCESS; // According to Nokia's AudioStream example, some 2nd Edition, FP2 devices // (such as Nokia 6630) require the stream to be reconstructed each time // before calling Open() - otherwise the callback never gets called. // For uniform behavior, lets just delete/re-create the stream for all // devices. // Destroy existing stream. if (iInputStream_) delete iInputStream_; iInputStream_ = NULL; // Create the stream. TRAPD(err, iInputStream_ = CMdaAudioInputStream::NewL(*this)); if (err != KErrNone) return PJ_RETURN_OS_ERROR(err); // Initialize settings. TMdaAudioDataSettings iStreamSettings; iStreamSettings.iChannels = get_channel_cap(parentStrm_->param.channel_count); iStreamSettings.iSampleRate = get_clock_rate_cap(parentStrm_->param.clock_rate); pj_assert(iStreamSettings.iChannels != 0 && iStreamSettings.iSampleRate != 0); PJ_LOG(4,(THIS_FILE, "Opening sound device for capture, " "clock rate=%d, channel count=%d..", parentStrm_->param.clock_rate, parentStrm_->param.channel_count)); // Open stream. lastError_ = KRequestPending; iInputStream_->Open(&iStreamSettings); #if defined(PJMEDIA_AUDIO_DEV_MDA_USE_SYNC_START) && \ PJMEDIA_AUDIO_DEV_MDA_USE_SYNC_START != 0 startAsw_.Start(); #endif // Success PJ_LOG(4,(THIS_FILE, "Sound capture started.")); return PJ_SUCCESS; }
LOCAL_C void DoStartL() { CActiveScheduler *scheduler = new (ELeave) CActiveScheduler; CleanupStack::PushL(scheduler); CActiveScheduler::Install(scheduler); CActiveSchedulerWait *asw = new CActiveSchedulerWait; CleanupStack::PushL(asw); MyTask *task = MyTask::NewL(asw); task->Start(); asw->Start(); delete task; CleanupStack::Pop(asw); delete asw; CActiveScheduler::Install(NULL); CleanupStack::Pop(scheduler); delete scheduler; }
void CPjAudioOutputEngine::Stop() { // Stop stream if it's playing if (iOutputStream_ && state_ != STATE_INACTIVE) { lastError_ = KRequestPending; iOutputStream_->Stop(); // Wait until it's actually stopped while (lastError_ == KRequestPending) pj_symbianos_poll(-1, 100); } if (iOutputStream_) { delete iOutputStream_; iOutputStream_ = NULL; } if (startAsw_.IsStarted()) { startAsw_.AsyncStop(); } state_ = STATE_INACTIVE; }
void CPjAudioInputEngine::Stop() { // If capture is in progress, stop it. if (iInputStream_ && state_ == STATE_ACTIVE) { lastError_ = KRequestPending; iInputStream_->Stop(); // Wait until it's actually stopped while (lastError_ == KRequestPending) pj_symbianos_poll(-1, 100); } if (iInputStream_) { delete iInputStream_; iInputStream_ = NULL; } if (startAsw_.IsStarted()) { startAsw_.AsyncStop(); } state_ = STATE_INACTIVE; }
void CPjAudioInputEngine::MaiscOpenComplete(TInt aError) { if (startAsw_.IsStarted()) { startAsw_.AsyncStop(); } lastError_ = aError; if (aError != KErrNone) { snd_perror("Error in MaiscOpenComplete()", aError); return; } /* Apply input volume setting if specified */ if (parentStrm_->param.flags & PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING) { stream_set_cap(&parentStrm_->base, PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING, &parentStrm_->param.input_vol); } // set stream priority to normal and time sensitive iInputStream_->SetPriority(EPriorityNormal, EMdaPriorityPreferenceTime); // Read the first frame. TPtr8 & frm = GetFrame(); TRAPD(err2, iInputStream_->ReadL(frm)); if (err2) { PJ_LOG(4,(THIS_FILE, "Exception in iInputStream_->ReadL()")); lastError_ = err2; return; } // input stream opened succesfully, set status to Active state_ = STATE_ACTIVE; }
void CFeatureNotifierStepBase::WaitL( TInt aIntervalInMicorseconds ) { TWaitInfo info; // Construct periodic CPeriodic* periodic = CPeriodic::NewL( CActive::EPriorityStandard ); CleanupStack::PushL( periodic ); info.iPeriodic = periodic; // Construct active scheduler wait CActiveSchedulerWait* wait = new( ELeave ) CActiveSchedulerWait; CleanupStack::PushL( wait ); info.iWait = wait; iWait = wait; // Start timer and wait TCallBack cb( WaitCallBack, &info ); periodic->Start( aIntervalInMicorseconds, aIntervalInMicorseconds, cb ); wait->Start(); // Cleanup CleanupStack::PopAndDestroy( wait ); CleanupStack::PopAndDestroy( periodic ); }
pj_status_t CPjAudioOutputEngine::StartPlay() { // Ignore command if playing is in progress. if (state_ == STATE_ACTIVE) return PJ_SUCCESS; // Destroy existing stream. if (iOutputStream_) delete iOutputStream_; iOutputStream_ = NULL; // Create the stream TRAPD(err, iOutputStream_ = CMdaAudioOutputStream::NewL(*this)); if (err != KErrNone) return PJ_RETURN_OS_ERROR(err); // Initialize settings. TMdaAudioDataSettings iStreamSettings; iStreamSettings.iChannels = get_channel_cap(parentStrm_->param.channel_count); iStreamSettings.iSampleRate = get_clock_rate_cap(parentStrm_->param.clock_rate); pj_assert(iStreamSettings.iChannels != 0 && iStreamSettings.iSampleRate != 0); PJ_LOG(4,(THIS_FILE, "Opening sound device for playback, " "clock rate=%d, channel count=%d..", parentStrm_->param.clock_rate, parentStrm_->param.channel_count)); // Open stream. lastError_ = KRequestPending; iOutputStream_->Open(&iStreamSettings); #if defined(PJMEDIA_AUDIO_DEV_MDA_USE_SYNC_START) && \ PJMEDIA_AUDIO_DEV_MDA_USE_SYNC_START != 0 startAsw_.Start(); #endif // Success PJ_LOG(4,(THIS_FILE, "Sound playback started")); return PJ_SUCCESS; }
void CAsyWait::RunL() { iWaiter->AsyncStop(); }
void CAsyWait::DoCancel() { iWaiter->AsyncStop(); }
void MyTask::RunL() { int rc = app_main(); asw_->AsyncStop(); }
void CPjAudioOutputEngine::MaoscOpenComplete(TInt aError) { if (startAsw_.IsStarted()) { startAsw_.AsyncStop(); } lastError_ = aError; if (aError==KErrNone) { // set stream properties, 16bit 8KHz mono TMdaAudioDataSettings iSettings; iSettings.iChannels = get_channel_cap(parentStrm_->param.channel_count); iSettings.iSampleRate = get_clock_rate_cap(parentStrm_->param.clock_rate); iOutputStream_->SetAudioPropertiesL(iSettings.iSampleRate, iSettings.iChannels); /* Apply output volume setting if specified */ if (parentStrm_->param.flags & PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING) { stream_set_cap(&parentStrm_->base, PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING, &parentStrm_->param.output_vol); } else { // set volume to 1/2th of stream max volume iOutputStream_->SetVolume(iOutputStream_->MaxVolume()/2); } // set stream priority to normal and time sensitive iOutputStream_->SetPriority(EPriorityNormal, EMdaPriorityPreferenceTime); // Call callback to retrieve frame from upstream. pjmedia_frame f; pj_status_t status; f.type = PJMEDIA_FRAME_TYPE_AUDIO; f.buf = frameBuf_; f.size = frameBufSize_; f.timestamp.u32.lo = timestamp_; f.bit_info = 0; status = playCb_(this->userData_, &f); if (status != PJ_SUCCESS) { this->Stop(); return; } if (f.type != PJMEDIA_FRAME_TYPE_AUDIO) pj_bzero(frameBuf_, frameBufSize_); // Increment timestamp. timestamp_ += (frameBufSize_ / BYTES_PER_SAMPLE); // issue WriteL() to write the first audio data block, // subsequent calls to WriteL() will be issued in // MMdaAudioOutputStreamCallback::MaoscBufferCopied() // until whole data buffer is written. frame_.Set(frameBuf_, frameBufSize_); iOutputStream_->WriteL(frame_); // output stream opened succesfully, set status to Active state_ = STATE_ACTIVE; } else { snd_perror("Error in MaoscOpenComplete()", aError); } }