void CPjAudioOutputEngine::MaoscBufferCopied(TInt aError, const TDesC8& aBuffer) { PJ_UNUSED_ARG(aBuffer); if (aError==KErrNone) { // Buffer successfully written, feed another one. // 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); // Write to playback stream. frame_.Set(frameBuf_, frameBufSize_); iOutputStream_->WriteL(frame_); } else if (aError==KErrAbort) { // playing was aborted, due to call to CMdaAudioOutputStream::Stop() state_ = STATE_INACTIVE; } else { // error writing data to output lastError_ = aError; state_ = STATE_INACTIVE; snd_perror("Error in MaoscBufferCopied()", aError); } }
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); } }