Android8.1开机铃声不同步,首次开机无铃声问题
问题描述:客户定制的开机动画是带有开机铃声的,但发现用system/media/bootanimation.ts和/oem/media/bootanimation.zip(包含了audio.wav)的方式都试过,开机(视频)动画没问题,但开机铃声会延迟一两秒。
logcat分析:
D BootAnimation found audio.wav, creating playback engine 04-04 185737.155 371 383 D BootAnimation BootAnimationShownTiming start time 5115ms 04-04 185737.155 371 383 D BootAnimation playing clip for part0, size=2642254 04-04 185737.156 371 395 E libOpenSLES CEngine_Realize binding to audio service failed, service up 04-04 185737.158 371 395 D PlayerBasePlayerBase() 04-04 185737.158 371 395 E PlayerBase() binding to audio service f
看开机的logcat,个人理解是播放audio.wav这段音频铃声的时候,audio service服务还没有初始化成功,一直在等待,导致会延迟一点播放。
最终参考了一位网友的文章,顺利解决此问题。修改如下:
frameworks/av/
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp index bb17943..a1652c2 100755 --- a/media/libmediaplayerservice/MediaPlayerService.cpp +++ b/media/libmediaplayerservice/MediaPlayerService.cpp @@ -2622,7 +2622,7 @@ MediaPlayerService::BatteryTracker::BatteryTracker() { // reset battery stats // if the mediaserver has crashed, battery stats could be left // in bad state, reset the state upon service start. - BatteryNotifier::getInstance().noteResetVideo(); + // BatteryNotifier::getInstance().noteResetVideo(); } void MediaPlayerService::BatteryTracker::addBatteryData(uint32_t params) diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp old mode 100644 new mode 100755 index ff5f745..b02e74a --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -156,7 +156,7 @@ AudioFlinger::AudioFlinger() mIsLowRamDevice(true), mIsDeviceTypeKnown(false), mGlobalEffectEnableTime(0), - mSystemReady(false) + mSystemReady(true) { // unsigned instead of audio_unique_id_use_t, because ++ operator is unavailable for enum for (unsigned use = AUDIO_UNIQUE_ID_USE_UNSPECIFIED; use < AUDIO_UNIQUE_ID_USE_MAX; use++) { diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp old mode 100644 new mode 100755 index a30c460..fb536d6 --- a/services/audioflinger/Threads.cpp +++ b/services/audioflinger/Threads.cpp @@ -576,11 +576,11 @@ status_t AudioFlinger::ThreadBase::sendConfigEvent_l(sp<ConfigEvent>& event) { status_t status = NO_ERROR; - if (event->mRequiresSystemReady && !mSystemReady) { +/* if (event->mRequiresSystemReady && !mSystemReady) { event->mWaitStatus = false; mPendingConfigEvents.add(event); return status; - } + }*/ mConfigEvents.add(event); ALOGV("sendConfigEvent_l() num events %zu event %d", mConfigEvents.size(), event->mType); mWaitWorkCV.signal(); @@ -934,7 +934,7 @@ void AudioFlinger::ThreadBase::releaseWakeLock_l() } void AudioFlinger::ThreadBase::getPowerManager_l() { - if (mSystemReady && mPowerManager == 0) { + if (mPowerManager == 0) { // use checkService() to avoid blocking if power service is not up yet sp<IBinder> binder = defaultServiceManager()->checkService(String16("power")); @@ -2642,6 +2642,9 @@ ssize_t AudioFlinger::PlaybackThread::threadLoop_write() ssize_t bytesWritten; const size_t offset = mCurrentWriteLength - mBytesRemaining; + if (mPowerManager == 0) + acquireWakeLock(); + // If an NBAIO sink is present, use it to write the normal mixer's submix if (mNormalSink != 0) {
初次开机无开机铃声:
frameworks/av/services/audioflinger/Threads.cpp
@@ -4383,6 +4383,15 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::MixerThread::prepareTrac track->mHasVolumeController = false; } + /*wmc modify start */ + char mvalue[PROPERTY_VALUE_MAX] = { 1 }; + property_get("service.bootanim.exit", mvalue, ""); + if (strcmp(mvalue,"0") == 0){ + vlf = 0.25f; + vrf = 0.25f; + } + /*wmc modify end */ + // For dedicated VoIP outputs, let the HAL apply the stream volume. Track volume is // still applied by the mixer. if ((mOutput->flags & AUDIO_OUTPUT_FLAG_VOIP_RX) != 0) {
参考:https://blog.csdn.net/m1126125223/article/details/100656625?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-100656625-blog-103196458.235%5Ev27%5Epc_relevant_t0_download&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-100656625-blog-103196458.235%5Ev27%5Epc_relevant_t0_download&utm_relevant_index=2
https://blog.csdn.net/wangjicong_215/article/details/112251199?spm=1001.2101.3001.6650.5&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-5-112251199-blog-88976117.235%5Ev27%5Epc_relevant_t0_download&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-5-112251199-blog-88976117.235%5Ev27%5Epc_relevant_t0_download&utm_relevant_index=6