Skip to content

Commit 6f7d201

Browse files
committed
[EGD-4076] Headphones auto detect fix
1 parent b82e804 commit 6f7d201

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# MuditaOS changelog
22

3+
## Current release
4+
5+
### Fixed
6+
* `[audio]` Fix headphones autodetection.
7+
38
## [0.42.2 2020-10-16]
49

510
### Added

module-services/service-audio/ServiceAudio.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -330,22 +330,10 @@ std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStart(const Operation:
330330

331331
std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleSendEvent(std::shared_ptr<Event> evt)
332332
{
333-
auto input = audioMux.GetRoutingInput();
334-
input = input ? input : audioMux.GetActiveInput();
335-
336-
if (!input) {
337-
return std::make_unique<AudioResponseMessage>(RetCode::OperationNotSet);
338-
}
339-
340-
if (evt->getType() == EventType::HeadphonesPlugin) {
341-
headphonesInserted = true;
342-
}
343-
else if (evt->getType() == EventType::HeadphonesUnplug) {
344-
headphonesInserted = false;
333+
for (auto &input : audioMux.GetAllInputs()) {
334+
input.audio->SendEvent(evt);
345335
}
346-
347-
auto retVal = input.value()->audio->SendEvent(evt);
348-
return std::make_unique<AudioEventResponse>(retVal);
336+
return std::make_unique<AudioEventResponse>(RetCode::Success);
349337
}
350338

351339
std::unique_ptr<AudioResponseMessage> ServiceAudio::HandleStop(const std::vector<audio::PlaybackType> &stopTypes,
@@ -546,7 +534,9 @@ std::string ServiceAudio::getSetting(const Setting &setting,
546534
targetPlayback = currentPlaybackType;
547535
}
548536
else if (setting == Setting::Volume) {
549-
targetProfile = headphonesInserted ? Profile::Type::PlaybackHeadphones : Profile::Type::PlaybackLoudspeaker;
537+
auto input = audioMux.GetIdleInput();
538+
targetProfile = ((*input)->audio->GetHeadphonesInserted()) ? Profile::Type::PlaybackHeadphones
539+
: Profile::Type::PlaybackLoudspeaker;
550540
targetPlayback = PlaybackType::CallRingtone;
551541
}
552542
else {
@@ -581,8 +571,9 @@ void ServiceAudio::setSetting(const Setting &setting,
581571
updatedPlayback = (*activeInput)->audio->GetCurrentOperationPlaybackType();
582572
}
583573
else if (setting == audio::Setting::Volume) {
584-
updatedProfile =
585-
headphonesInserted ? Profile::Type::PlaybackHeadphones : Profile::Type::PlaybackLoudspeaker;
574+
auto input = audioMux.GetIdleInput();
575+
updatedProfile = (*input)->audio->GetHeadphonesInserted() ? Profile::Type::PlaybackHeadphones
576+
: Profile::Type::PlaybackLoudspeaker;
586577
updatedPlayback = PlaybackType::CallRingtone;
587578
valueToSet = std::clamp(utils::getValue<audio::Volume>(value), minVolume, maxVolume);
588579
}

module-services/service-audio/ServiceAudio.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ class ServiceAudio : public sys::Service
4242
audio::AudioMux audioMux;
4343
audio::AudioMux::VibrationStatus vibrationMotorStatus = audio::AudioMux::VibrationStatus::Off;
4444

45-
bool headphonesInserted = false;
46-
4745
auto IsVibrationMotorOn()
4846
{
4947
return vibrationMotorStatus == audio::AudioMux::VibrationStatus::On;

module-services/service-evtmgr/WorkerEvent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ bool WorkerEvent::handleMessage(uint32_t queueID)
7272
if (bsp::headset::Handler(notification) == true) {
7373
bool state = bsp::headset::IsInserted();
7474
auto message = std::make_shared<AudioEventRequest>(state ? audio::EventType::HeadphonesPlugin
75-
: audio::EventType::CallSpeakerphoneOff);
75+
: audio::EventType::HeadphonesUnplug);
7676
sys::Bus::SendUnicast(message, service::name::evt_manager, this->service);
7777
}
7878
}

0 commit comments

Comments
 (0)