Demo entry 6358603

c

   

Submitted by anonymous on Apr 26, 2017 at 10:36
Language: C++. Code size: 3.6 kB.

AudioFlinger::PlaybackThread::mixer_state AudioFlinger::MixerThread::prepareTracks_l(Vector< sp<Track> > *tracksToRemove) 
{
    //默认为空闲状态
    mixer_state mixerStatus = MIXER_IDLE;
    size_t count = mActiveTracks.size();
 
    //对于所有在mActiveTracks里面的Track,都需要进行设置
    for (size_t i=0 ; i<count ; i++) {
        const sp<Track> t = mActiveTracks[i].promote();
        Track* const track = t.get();
 
        //由于不是fastTrack,因此不会跑这里,而且fastTrack也不会在这里进行混音,我是没有发现有跑进过这个条件里面的
        if (track->isFastTrack()) {
            ...
        }
 
        //获取track的name,其实是个索引,AudioMixer会最多维护32个track,分别对饮int的32个bit,如果track的name还没定下来的话,会自行选择一个空位
        int name = track->name();
 
        //查看当前track是否stop,如果track被stop,那么这个track不需要设置AudioMixer参数,即frameReady = 0
        size_t framesReady;                                                     
        if (track->sharedBuffer() == 0) {                                           
            framesReady = track->framesReady();                                 
        } else if (track->isStopped()) {                                            
            framesReady = 0;                               
        } else {             
            framesReady = 1;                                  
        }
 
        //混音的情况下,frameReady = 1,那么会进入下面的条件,进行AudioMixer参数设置
        if ((framesReady >= minFrames) && track->isReady() && !track->isPaused() && !track->isTerminated())                                 {
            //音量参数
            ...
 
            //设置AudioMixer参数
            //源buffer
            mAudioMixer->setBufferProvider(name, track);
            //使能该track,即可以混音
            mAudioMixer->enable(name);
            //左音轨
            mAudioMixer->setParameter(name, param, AudioMixer::VOLUME0, (void *)vl);
            //右音轨
            mAudioMixer->setParameter(name, param, AudioMixer::VOLUME1, (void *)vr);    
            //aux                    
            mAudioMixer->setParameter(name, param, AudioMixer::AUXLEVEL, (void *)va); 
            //音频format,相应的接受方也要修改
            mAudioMixer->setParameter( 
                           name,                 
                           AudioMixer::TRACK,
                           AudioMixer::FORMAT, (void *)AUDIO_FORMAT_PCM_32_BIT;
            //音轨mask,哪个需要或者不需要混音
            mAudioMixer->setParameter(
                           name,
                           AudioMixer::TRACK,
                           AudioMixer::CHANNEL_MASK, (void *)track->channelMask());  
            //进行重采样
            mAudioMixer->setParameter(
                           name, 
                           AudioMixer::RESAMPLE,
                           AudioMixer::SAMPLE_RATE, 
                          (void *)reqSampleRate);
            //目的buffer
            mAudioMixer->setParameter(
                           name,
                           AudioMixer::TRACK,
                           AudioMixer::MAIN_BUFFER, (void *)track->mainBuffer());
            //aux
            mAudioMixer->setParameter(
                           name,
                           AudioMixer::TRACK,
                           AudioMixer::AUX_BUFFER, (void *)track->auxBuffer());
             
            //当前状态为ready,即可以混音
            mixerStatus = MIXER_TRACKS_READY;
        }else{
            //track stop时才会走这里
            ...
        }
   
    }
    //从mActiveTracks删除需要移除的track
    removeTracks_l(*tracksToRemove);
 
    //返回mMixerStatus, 正常混音准备时,这里返回的是MIXER_TRACK_READY
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).