Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e4343f96 authored by codeworkx's avatar codeworkx
Browse files

audioflinger: workaround for samsungs volume bug

play music via headset -> notification comes in -> music volume gets set to 0 ->
notification gets played -> music resumes with wrong (much lower) volume

Change-Id: I3961ed48d0687bacb60ee8d4ddc82575f06c908e
parent a4905d0e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -34,6 +34,10 @@ ifeq ($(BOARD_USE_MOTO_DOCK_HACK),true)
   LOCAL_CFLAGS += -DMOTO_DOCK_HACK
endif

ifeq ($(BOARD_HAS_SAMSUNG_VOLUME_BUG),true)
   LOCAL_CFLAGS += -DHAS_SAMSUNG_VOLUME_BUG
endif

ifeq ($(ARCH_ARM_HAVE_NEON),true)
   LOCAL_CFLAGS += -D__ARM_HAVE_NEON
endif
+38 −0
Original line number Diff line number Diff line
@@ -95,6 +95,11 @@ static const uint32_t kMinThreadSleepTimeUs = 5000;
// maximum divider applied to the active sleep time in the mixer thread loop
static const uint32_t kMaxThreadSleepTimeShift = 2;

#ifdef HAS_SAMSUNG_VOLUME_BUG
float gPrevMusicStreamVolume = 0;
bool gMusicStreamIsMuted = false;
bool gMusicStreamNeedsPrevVolume = false;
#endif

// ----------------------------------------------------------------------------

@@ -2527,9 +2532,42 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp<Track
                    track->setPaused();
                }
            } else {
#ifdef HAS_SAMSUNG_VOLUME_BUG
                if (track->type() == AUDIO_STREAM_MUSIC && !track->isMuted() && !track->isPausing()) {
                    if(mStreamTypes[AUDIO_STREAM_MUSIC].volume > 0 && !gMusicStreamNeedsPrevVolume) {
                        gPrevMusicStreamVolume = mStreamTypes[AUDIO_STREAM_MUSIC].volume;
                        LOGD("Stored volume = %f", gPrevMusicStreamVolume);
                    } else {
                        gMusicStreamIsMuted = true;
                    }
                } else if (track->type() == AUDIO_STREAM_MUSIC && (track->isMuted() || track->isPausing())) {
                    gMusicStreamIsMuted = true;
                }

                if (track->type() == AUDIO_STREAM_NOTIFICATION && gMusicStreamIsMuted) {
                    LOGD("Music stream needs volume restore!");
                    LOGD("gPrevMusicStreamVolume = %f", gPrevMusicStreamVolume);
                    gMusicStreamNeedsPrevVolume = true;
                }
#endif
                // read original volumes with volume control
                float typeVolume = mStreamTypes[track->type()].volume;

#ifdef HAS_SAMSUNG_VOLUME_BUG
                if (track->type() == AUDIO_STREAM_MUSIC && typeVolume > 0 && !track->isMuted() &&
                        !track->isPausing() && gMusicStreamNeedsPrevVolume) {
                    LOGI("Restoring last known good volume value on music stream!");
                    LOGI("gPrevMusicStreamVolume = %f", gPrevMusicStreamVolume);
                    mStreamTypes[AUDIO_STREAM_MUSIC].volume = gPrevMusicStreamVolume;
                    typeVolume = gPrevMusicStreamVolume;
                    gMusicStreamIsMuted = false;
                    gMusicStreamNeedsPrevVolume = false;
                } else if (track->type() == AUDIO_STREAM_MUSIC && typeVolume > 0
                        && !track->isMuted() && !track->isPausing()) {
                    gMusicStreamIsMuted = false;
                }
#endif

                float v = masterVolume * typeVolume;
                vl = (uint32_t)(v * cblk->volume[0]) << 12;
                vr = (uint32_t)(v * cblk->volume[1]) << 12;