Android Audio代码分析12 - stream type续
前几天在看stream type的时候,调用函数AudioSystem::getOutput的地方并没有继续往下看。
今天深入看看。
*****************************************源码*************************************************
status_t AudioTrack::set(
int streamType,
uint32_t sampleRate,
int format,
int channels,
int frameCount,
uint32_t flags,
callback_t cbf,
void* user,
int notificationFrames,
const sp<IMemory>& sharedBuffer,
bool threadCanCallJava,
int sessionId)
{
LOGV_IF(sharedBuffer != 0, "sharedBuffer: %p, size: %d", sharedBuffer->pointer(), sharedBuffer->size());
if (mAudioTrack != 0) {
LOGE("Track already in use");
return INVALID_OPERATION;
}
int afSampleRate;
if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
return NO_INIT;
}
uint32_t afLatency;
if (AudioSystem::getOutputLatency(&afLatency, streamType) != NO_ERROR) {
return NO_INIT;
}
// handle default values first.
if (streamType == AudioSystem::DEFAULT) {
streamType = AudioSystem::MUSIC;
}
if (sampleRate == 0) {
sampleRate = afSampleRate;
}
// these below should probably come from the audioFlinger too...
if (format == 0) {
format = AudioSystem::PCM_16_BIT;
}
if (channels == 0) {
channels = AudioSystem::CHANNEL_OUT_STEREO;
}
// validate parameters
if (!AudioSystem::isValidFormat(format)) {
LOGE("Invalid format");
return BAD_VALUE;
}
// force direct flag if format is not linear PCM
if (!AudioSystem::isLinearPCM(format)) {
flags |= AudioSystem::OUTPUT_FLAG_DIRECT;
}
if (!AudioSystem::isOutputChannel(channels)) {
LOGE("Invalid channel mask");
return BAD_VALUE;
}
uint32_t channelCount = AudioSystem::popCount(channels);
audio_io_handle_t output = AudioSystem::getOutput((AudioSystem::stream_type)streamType,
sampleRate, format, channels, (AudioSystem::output_flags)flags);
if (output == 0) {
LOGE("Could not get audio output for stream type %d", streamType);
return BAD_VALUE;
}
mVolume[LEFT] = 1.0f;
mVolume[RIGHT] = 1.0f;
mSendLevel = 0;
mFrameCount = frameCount;
mNotificationFramesReq = notificationFrames;
mSessionId = sessionId;
mAuxEffectId = 0;
// create the IAudioTrack
status_t status = createTrack(streamType, sampleRate, format, channelCount,
frameCount, flags, sharedBuffer, output, true);
if (status != NO_ERROR) {
return status;
}
if (cbf != 0) {
mAudioTrackThread = new AudioTrackThread(*this, threadCanCallJava);
if (mAudioTrackThread == 0) {
LOGE("Could not create callback thread");
return NO_INIT;
}
}
mStatus = NO_ERROR;
mStreamType = streamType;
mFormat = format;
mChannels = channels;
mChannelCount = channelCount;
mSharedBuffer = sharedBuffer;
mMuted = false;
mActive = 0;
mCbf = cbf;
mUserData = user;
mLoopCount = 0;
mMarkerPosition = 0;
mMarkerReached = false;
mNewPosition = 0;
mUpdatePeriod = 0;
mFlags = flags;
return NO_ERROR;
}
**********************************************************************************************
#######################说明################################
+++++++++++++++++++++++++AudioSystem::getOutput+++++++++++++++++++++++++++++++++++++++
audio_io_handle_t AudioSystem::getOutput(stream_type stream,
uint32_t samplingRate,
uint32_t format,
uint32_t channels,
output_flags flags)
{
audio_io_handle_t output = 0;
// Do not use stream to output map cache if the
补充:移动开发 , Android ,