Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly Handle Transient Audio Focus Requests #111

Merged
merged 4 commits into from
Dec 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hu/hu.proto
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ message AudioFocusRequest
{
AUDIO_FOCUS_GAIN = 1;
AUDIO_FOCUS_GAIN_TRANSIENT = 2;
AUDIO_FOCUS_UNKNOWN = 3;
AUDIO_FOCUS_GAIN_NAVI = 3;
AUDIO_FOCUS_RELEASE = 4;
}
required AUDIO_FOCUS focus_type = 1;
Expand Down
20 changes: 12 additions & 8 deletions mazda/callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ int MazdaEventCallbacks::MediaPacket(int chan, uint64_t timestamp, const byte *b

int MazdaEventCallbacks::MediaStart(int chan) {
if (chan == AA_CH_MIC) {
// We ignored transient requests to avoid capturing phone calls so we handle the request here
audioMgrClient->audioMgrRequestAudioFocus(AudioManagerClient::FocusType::TRANSIENT);
printf("SHAI1 : Mic Started\n");
micInput.Start(g_hu);
}
Expand Down Expand Up @@ -90,9 +92,7 @@ void MazdaEventCallbacks::AudioFocusRequest(int chan, const HU::AudioFocusReques
//The chan passed here is always AA_CH_CTR but internally we pass the channel AA means
if (request.focus_type() == HU::AudioFocusRequest::AUDIO_FOCUS_RELEASE) {
audioMgrClient->audioMgrReleaseAudioFocus();
} else if (request.focus_type() == HU::AudioFocusRequest::AUDIO_FOCUS_GAIN_TRANSIENT) {
audioMgrClient->audioMgrRequestAudioFocus(AudioManagerClient::FocusType::TRANSIENT); //assume navigation
} else if (request.focus_type() == HU::AudioFocusRequest::AUDIO_FOCUS_GAIN || request.focus_type() == HU::AudioFocusRequest::AUDIO_FOCUS_UNKNOWN) {
} else if (request.focus_type() == HU::AudioFocusRequest::AUDIO_FOCUS_GAIN || request.focus_type() == HU::AudioFocusRequest::AUDIO_FOCUS_GAIN_NAVI) {
audioMgrClient->audioMgrRequestAudioFocus(AudioManagerClient::FocusType::PERMANENT); //assume media
}

Expand Down Expand Up @@ -388,7 +388,7 @@ void AudioManagerClient::populateStreamTable()
// Create and register stream (only if we need to)
if (aaSessionID < 0)
{
logw("When using the USB stream we should never have to register since it should be already there");
//logw("When using the USB stream we should never have to register since it should be already there");
aaRegisterStream();
}
}
Expand Down Expand Up @@ -501,6 +501,7 @@ void AudioManagerClient::Notify(const std::string &signalName, const std::string
auto result = json::parse(payload);
std::string streamName = result["streamName"].get<std::string>();
std::string newFocus = result["newFocus"].get<std::string>();
std::string focusType = result["focusType"].get<std::string>();

auto findIt = streamToSessionIds.find(streamName);
int eventSessionID = -1;
Expand All @@ -524,12 +525,12 @@ void AudioManagerClient::Notify(const std::string &signalName, const std::string

if (eventSessionID == aaSessionID)
{
bool hasFocus = newFocus == "gained";
if (hasFocus)
if (newFocus == "gained")
{
requestPending = false;
pendingFocus = FocusType::PERMANENT;
}
else
else if (newFocus != "temporarilyLost")
{
releasePending = false;
pendingFocus = FocusType::NONE;
Expand All @@ -540,7 +541,10 @@ void AudioManagerClient::Notify(const std::string &signalName, const std::string
currentFocus = pendingFocus;
callbacks.AudioFocusHappend(currentFocus);
}
pendingFocus = FocusType::NONE;
if (newFocus != "temporarilyLost")
{
pendingFocus = FocusType::NONE;
}
}
}
}
Expand Down
25 changes: 0 additions & 25 deletions mazda/outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,32 +248,7 @@ void VideoOutput::input_thread_func()
//Make the music button play/pause
case KEY_E:
printf("KEY_E\n");
//The FAV key basically does this right? We need a normal Play/Pause button
scanCode = HUIB_PLAYPAUSE;
/*
if (hasMediaAudioFocus)
{
if (isPressed)
{
pass_key_to_mzd(event.type, event.code, event.value);
}
else
{
scanCode = HUIB_PLAYPAUSE;
}
}
else
{
if (isPressed)
{
scanCode = HUIB_PLAYPAUSE;
}
else
{
pass_key_to_mzd(event.type, event.code, event.value);
}
}
*/
break;
case KEY_LEFTBRACE:
printf("KEY_LEFTBRACE (next track with media focus: %i)\n", hasMediaAudioFocus ? 1 : 0);
Expand Down