调用MediaPlayer的setAudioStreamType、prepare方法后,经过一系列处理,最终后调用MediaPlayerService的setAudioStreamType方法,具体如下:
sp<AudioOutput> mAudioOutput;
//frameworks/av/media/libmediaplayerservice/MediaPlayerService.cpp
status_t MediaPlayerService::Client::setAudioStreamType(audio_stream_type_t type)
{
ALOGV("[%d] setAudioStreamType(%d)", mConnId, type);
// TODO: for hardware output, call player instead
Mutex::Autolock l(mLock);
if (mAudioOutput != 0) mAudioOutput->setAudioStreamType(type); //调用AudioOutput的setAudioStreamType方法
return NO_ERROR;
}
调用AudioOutput的setAudioStreamType方法:
void MediaPlayerService::AudioOutput::setAudioStreamType(audio_stream_type_t streamType)
{
Mutex::Autolock lock(mLock);
// do not allow direct stream type modification if attributes have been set
if (mAttributes == NULL) {
mStreamType = streamType;
}
}