一.Standby
当使用MediaPlayer停止本地播放后,如果切换我们自定义的音频通道(线路输入,只有模拟通道,数字通道没有工作),开始正常但隔几秒钟后就会没声音输出
Android系统默认播放停止后3秒(默认)会进入Standby模式来降低功耗
1.1.frameworksavservicesaudioflingerAudioFlinger.cpp
ro.audio.flinger_standbytime_ms=2592000000
standby时间 由ro.audio.flinger_standbytime_ms控制 如果没有 这个属性 则默认是3秒
void AudioFlinger::onFirstRef() { Mutex::Autolock _l(mLock); /* TODO: move all this work into an Init() function */ char val_str[PROPERTY_VALUE_MAX] = { 0 }; if (property_get("ro.audio.flinger_standbytime_ms", val_str, NULL) >= 0) { uint32_t int_val; if (1 == sscanf(val_str, "%u", &int_val)) { mStandbyTimeInNsecs = milliseconds(int_val); ALOGI("Using %u mSec as standby time.", int_val); } else { mStandbyTimeInNsecs = kDefaultStandbyTimeInNsecs; ALOGI("Using default %u mSec as standby time.", (uint32_t)(mStandbyTimeInNsecs / 1000000)); } } mPatchPanel = new PatchPanel(this); mMode = AUDIO_MODE_NORMAL; }
1.2.frameworksavservicesaudioflingerAudioFlinger.h
Android系统默认播放停止后3秒会进入Standby模式以节省电源
// ---------------------------------------------------------------------------- static const nsecs_t kDefaultStandbyTimeInNsecs = seconds(3);
1.3.进入Standby 之前关闭 Speak 功放
hardware/rockchip/audio/tinyalsa_hal/audio_hw.c
--- a/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c +++ b/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c @@ -1162,6 +1162,11 @@ static void do_out_standby(struct stream_out *out) } out->standby = true; out->nframes = 0; + speaker_mute(1); property_set("media.audio.slice", "0"); if (out == adev->outputs[OUTPUT_HDMI_MULTI]) { /* force standby on low latency output stream so that it can reuse HDMI driver if static void speaker_mute(int mute) { int ret=0; int fdp =0; fdp= open("/sys/class/xh_custom/xh_custom_gpio/device/speaker_en",O_RDWR); if(fdp > 0) { if(mute==1) { ALOGD("MUTE speaker"); ret= write(fdp,"0",1); } else { ALOGD("UNMUTE speaker"); ret= write(fdp,"1",1); } if(ret != 1) { ALOGD("MUTE speaker FAILED"); close(fdp); } close(fdp); } }