Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92
用原生SoundRecorder apk为例,以sample rate, channel及buffer size这些参数为线索来跟踪,,流程如下:
openRecord_l ->
AudioSystem::getInputForAttr ->
aps->getInputForAttr ->
AudioPolicyManager::getInputForAttr ->
getInputProfile -> 根据上apk给的profileSamplingRate, profileFormat以及profileChannelMask找到对应的profile
mpClientInterface->openInput -> 上层的录音参数传递给HAL.
AudioFlinger::openInput_l ->
inHwHal->open_input_stream ->
adev_open_input_stream -> audio_hw.c
OS: Android 6.0
Kernel: 3.10.92
用原生SoundRecorder apk为例,以sample rate, channel及buffer size这些参数为线索来跟踪,,流程如下:
openRecord_l ->
AudioSystem::getInputForAttr ->
aps->getInputForAttr ->
AudioPolicyManager::getInputForAttr ->
getInputProfile -> 根据上apk给的profileSamplingRate, profileFormat以及profileChannelMask找到对应的profile
mpClientInterface->openInput -> 上层的录音参数传递给HAL.
AudioFlinger::openInput_l ->
inHwHal->open_input_stream ->
adev_open_input_stream -> audio_hw.c
static int adev_open_input_stream(struct audio_hw_device *dev,
audio_io_handle_t handle,
audio_devices_t devices,
struct audio_config *config,
struct audio_stream_in **stream_in, //传进来是新的
audio_input_flags_t flags,
const char *address __unused,
audio_source_t source __unused)
{
struct audio_device *adev = (struct audio_device *)dev;
struct stream_in *in;
int ret;
*stream_in = NULL;
//不管它传进来是哪种,直接定死为双声道.
config->channel_mask = AUDIO_CHANNEL_IN_STEREO;
#ifdef ALSA_IN_DEBUG
//用来调试抓取pcm数据
in_debug = fopen("/data/debug.pcm","wb");//please touch /data/debug.pcm first
#endif
......
in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
if (!in)
return -ENOMEM;
......
//SoundRecorder apk使用的是8kHz的采样率.
in->requested_rate = config->sample_rate;
......
//上面定死为双通道.
in->channel_mask = config->channel_mask;
......
//默认用的是pcm_config_in
//struct pcm_config pcm_config_in = {
//.channels = 2,
//.rate = 44100,
//.period_size = 16,
//.period_count = 128,
//.format = PCM_FORMAT_S16_LE,
//};
struct pcm_config *pcm_config = flags & AUDIO_INPUT_FLAG_FAST ?
&pcm_config_in_low_latency : &pcm_config_in;
in->config = pcm_config;
//用