Android Audio代码分析26 - Audio Strategy
在看示例代码 testPlaybackHeadPositionIncrease 的时候,我们对 play 函数进行了研究。
不过,当时对 Android 中声音竞争策略相关的内容,并没有详细分析。
今天就以 AudioTrack 的播放为引子,来仔细看看 Anroid 中各种声音是以什么样的策略来竞争的。
从 Java 侧类 AudioTrack 的 play 函数到函数 AudioFlinger::PlaybackThread::Track::start 之间的调用关系就不再叙述了。
在看示例代码 testPlaybackHeadPositionIncrease 的时候已经说明过了。
今天就从函数 AudioFlinger::PlaybackThread::Track::start 开始分析。
*****************************************源码*************************************************
status_t AudioFlinger::PlaybackThread::Track::start()
{
status_t status = NO_ERROR;
LOGV("start(%d), calling thread %d session %d",
mName, IPCThreadState::self()->getCallingPid(), mSessionId);
sp<ThreadBase> thread = mThread.promote();
if (thread != 0) {
Mutex::Autolock _l(thread->mLock);
int state = mState;
// here the track could be either new, or restarted
// in both cases "unstop" the track
if (mState == PAUSED) {
mState = TrackBase::RESUMING;
LOGV("PAUSED => RESUMING (%d) on thread %p", mName, this);
} else {
mState = TrackBase::ACTIVE;
LOGV("? => ACTIVE (%d) on thread %p", mName, this);
}
if (!isOutputTrack() && state != ACTIVE && state != RESUMING) {
thread->mLock.unlock();
status = AudioSystem::startOutput(thread->id(),
(AudioSystem::stream_type)mStreamType,
mSessionId);
thread->mLock.lock();
}
if (status == NO_ERROR) {
PlaybackThread *playbackThread = (PlaybackThread *)thread.get();
playbackThread->addTrack_l(this);
} else {
mState = state;
}
} else {
status = BAD_VALUE;
}
return status;
}
**********************************************************************************************
源码路径:
frameworks\base\services\AudioFlinger.cpp
#######################说明################################
status_t AudioFlinger::PlaybackThread::Track::start()
{
status_t status = NO_ERROR;
LOGV("start(%d), calling thread %d session %d",
mName, IPCThreadState::self()->getCallingPid(), mSessionId);
sp<ThreadBase> thread = mThread.promote();
if (thread != 0) {
Mutex::Autolock _l(thread->mLock);
int state = mState;
// here the track could be either new, or restarted
// in both cases "unstop" the track
if (mState == PAUSED) {
mState = TrackBase::RESUMING;
LOGV("PAUSED => RESUMING (%d) on thread %p", mName, this);
} else {
mState = TrackBase::ACTIVE;
LOGV("? => ACTIVE (%d) on thread %p", mName, this);
}
if (!isOutputTrack() && state != ACTIVE && state != RESUMING) {
thread->mLock.unlock();
status = AudioSystem::startOutput(thread->id(),
(AudioSystem::stream_type)mStreamType,
mSessionId);
++++++++++++++++++++++++++++AudioSystem::startOutput++++++++++++++++++++++++++++++++++++
从函数 AudioFlinger::PlaybackThread::Track::start 进入:
status_t AudioSystem::startOutput(audio_io_handle_t output,
AudioSystem::stream_type stream,
int session)
{
const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
if (aps == 0) return PERMISSION_DENIED;
return aps->startOutput(output, stream, session);
+++++++++++++++++++++++++++++AudioPolicyService::startOutput+++++++++++++++++++++++++++++++++++
从函数 AudioSystem::startOutput 进入:
status_t AudioPolicyService::startOutput(audio_io_handle_t output,
&n
补充:移动开发 , Android ,