Esempio n. 1
0
GF_Err EPOCAudio::Open(u32 sample_rate, Bool stereo)
{
	TInt res = 0;
	u32 count;
	TMdaAudioDataSettings::TAudioCaps epoc_sr;

	
	switch (sample_rate) {
	case 8000: epoc_sr = TMdaAudioDataSettings::ESampleRate8000Hz; break;
	case 11025: epoc_sr = TMdaAudioDataSettings::ESampleRate11025Hz; break;
	case 12000: epoc_sr = TMdaAudioDataSettings::ESampleRate12000Hz; break;
	case 16000: epoc_sr = TMdaAudioDataSettings::ESampleRate16000Hz; break;
	case 22050: epoc_sr = TMdaAudioDataSettings::ESampleRate22050Hz; break;
	case 24000: epoc_sr = TMdaAudioDataSettings::ESampleRate24000Hz; break;
	case 32000: epoc_sr = TMdaAudioDataSettings::ESampleRate32000Hz; break;
	case 44100: epoc_sr = TMdaAudioDataSettings::ESampleRate44100Hz; break;
	case 48000: epoc_sr = TMdaAudioDataSettings::ESampleRate48000Hz; break;
	default:
		return GF_NOT_SUPPORTED;
	}
	
	state = EPOC_AUDIO_INIT;

	gf_sleep(10);
	TRAP(res, m_stream = CMdaAudioOutputStream::NewL(*this) );
	if ((res!=KErrNone) || !m_stream) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_MMIO, ("[EPOCAudio] Cannot create output audio stream\n"));
		return GF_IO_ERR;
	}
	m_stream->Open(&m_settings);

	/*wait for ack - if not getting it in 50*40 = 2sec, abort*/
	count = 50;
	while (count) {
		if (state == EPOC_AUDIO_OPEN) break;
		else if (state == EPOC_AUDIO_ERROR) {
			return GF_IO_ERR;
		}
		gf_sleep(40);

		TInt error;
		CActiveScheduler::RunIfReady(error, CActive::EPriorityIdle);
		count--;
	}
	if (state != EPOC_AUDIO_OPEN) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_MMIO, ("[EPOCAudio] Failed to open sound device - is it present?\n"));
		return GF_NOT_SUPPORTED;
	}

	TRAP(res, m_stream->SetAudioPropertiesL(epoc_sr, stereo ? TMdaAudioDataSettings::EChannelsStereo : TMdaAudioDataSettings::EChannelsMono) );
	m_stream->SetPriority(EPriorityAbsoluteHigh, EMdaPriorityPreferenceTime );
	m_stream->SetVolume(init_vol * m_stream->MaxVolume() / 100);

	current_buffer = nb_buffers_queued = 0;

	GF_LOG(GF_LOG_DEBUG, GF_LOG_MMIO, ("[EPOCAudio] output audio stream ready - sample rate %d - %d channels\n", sample_rate, stereo ? 2 : 1));
	return GF_OK;
}
Esempio n. 2
0
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);
    }
}