FastTack and Normal Track
Android 4.1 开始 Audio的变化之一就是有了audio output path:lower latency
所谓的low latency 即 对应native framework层的fast track 和fastmixer
也是application framework层对应的STATIC_MODE
FAST TACK 的创建
通过flag的设置创建,在AudioTrack 的构造函数或者AudioTrack::set()中将参数audio_output_flags_t设置为 AUDIO_OUTPUT_FLAG_FAST
目前使用fastrack的例子如:
Android native audio based on OpenSL ES or AAudio
android.media.SoundPool
android.media.ToneGenerator
AudioTrack会去检验AUDIO_OUTPUT_FLAG_FAST的设置是否合理,可能会以客户端的层次上否定要求的fasttrack方式;
同样AudioFlinger也会去进一步检验,并且可能在audio服务端的层次上否定在AudioTrack中的设置,然后通知客户端是否fastrack的要求被接受,客户端通过共享内存的方式获取fastrack flags来加以控制
Presence of a fast mixer thread for this output (see below)
Track sample rate
Presence of a client thread to execute callback handlers for this track
Track buffer size
Available fast track slots (see below)
normal track 是相对于fasttrack来说的,除了fasttrack其他成为normal track
Mixer Threads
AudioFlinger创建Mixer Threads的时候就会决定是否也创建一个快速混音线程fast mixer thread,Normal mixer 与 fast mixer 跟一组tracks有关.
总是会存在一个Normal mixer thread,而Fast mixer thread如果存在的话,一定受Normal mixer thread控制并且从属于它。
Fast mixer
特点:
- Mixing of the normal mixer’s sub-mix and up to 7 client fast tracks
- Per track attenuation
//android/frameworks/av/services/audioflinger/FastMixerState.h
static const unsigned kDefaultFastTracks = 8;
周期性
Fast mixer以推荐的2至3毫秒的时间周期性运行,如果因为调度稳定性有需要可以稍微增加到5毫秒的周期。选定这样的周期总延时大约10毫秒。更小的周期也可以,但是会增加功耗和出现故障的机会。更大的周期可以达到20毫秒,但是会导致总延时的退化,因此应避免。
Scheduling
Fast mixer遵从fifo优先级运行。它只需要很少的CPU时间,但运行频繁,具有低调度jitter。jitter表示周期时间的变化:实际循环时间与预期周期时间之间的差异。不能运行太早也不能太晚。
Blocking
除了在hal层write()数据,理想状态下Fast mixer从来不会阻塞,否则就被认为是bug。
Relationship to other components
Fast mixer 与客户端很少有直接的交互. 特别是它没有binder级别的操作,但是却可以访问 客户端的共享内存控制块.
The fast mixer receives commands from the normal mixer via a state queue.
Other than pulling track data, interaction with clients is via the normal mixer.
The fast mixer's primary sink is the audio HAL.
Normal mixer
特征
Up to 32 tracks
Per track attenuation(衰减)
Per track sample rate conversion(转换)
Effects processing
周期(Period)
The period is computed to be the first integral multiple(integral multiple:整倍数) of the fast mixer period that is >= 20 ms.
Scheduling
The normal mixer runs at elevated SCHED_OTHER priority(优先级).
Blocking
The normal mixer is permitted to block, and often does so at various mutexes as well as at a blocking pipe to write its sub-mix.
Relationship to other components
The normal mixer interacts extensively with the outside world, including binder threads, audio policy manager, fast mixer thread, and client tracks.
The normal mixer’s sink is a blocking pipe to the fast mixer’s track 0.
Flags
AUDIO_OUTPUT_FLAG_FAST bit is a hint. There’s no guarantee the request will be fulfilled.
AUDIO_OUTPUT_FLAG_FAST is a client-level concept. It does not appear in server.
TRACK_FAST is a client -> server concept.