From 3ca08280cb3890560ce8c6c136df07a1a88de36b Mon Sep 17 00:00:00 2001 From: Trevor Martin Date: Sat, 18 Nov 2017 14:42:23 -0800 Subject: [PATCH 1/3] v1.07 --- mazda/outputs.cpp | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/mazda/outputs.cpp b/mazda/outputs.cpp index fb48587c..59a89e33 100644 --- a/mazda/outputs.cpp +++ b/mazda/outputs.cpp @@ -253,25 +253,11 @@ void VideoOutput::input_thread_func() /* if (hasMediaAudioFocus) { - if (isPressed) - { - pass_key_to_mzd(event.type, event.code, event.value); - } - else - { - scanCode = HUIB_PLAYPAUSE; - } + callbacks->releaseAudioFocus(); } else { - if (isPressed) - { - scanCode = HUIB_PLAYPAUSE; - } - else - { - pass_key_to_mzd(event.type, event.code, event.value); - } + scanCode = HUIB_PLAYPAUSE; } */ break; From 854b430067f16aaf03043d9f632928db27f22f13 Mon Sep 17 00:00:00 2001 From: Trevor Martin Date: Fri, 8 Dec 2017 00:25:47 -0800 Subject: [PATCH 2/3] Ignore Tansient Audio Focus Requests Also, do not set FocusType::NONE on temporarilyLost focus event to allow AA music player to resume playing when the transient stream passes audio focus back. --- mazda/callbacks.cpp | 16 +++++++++------- mazda/outputs.cpp | 11 ----------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/mazda/callbacks.cpp b/mazda/callbacks.cpp index 86c3467b..49d4ed44 100644 --- a/mazda/callbacks.cpp +++ b/mazda/callbacks.cpp @@ -90,8 +90,6 @@ 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) { audioMgrClient->audioMgrRequestAudioFocus(AudioManagerClient::FocusType::PERMANENT); //assume media } @@ -388,7 +386,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(); } } @@ -501,6 +499,7 @@ void AudioManagerClient::Notify(const std::string &signalName, const std::string auto result = json::parse(payload); std::string streamName = result["streamName"].get(); std::string newFocus = result["newFocus"].get(); + std::string focusType = result["focusType"].get(); auto findIt = streamToSessionIds.find(streamName); int eventSessionID = -1; @@ -524,12 +523,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; @@ -540,7 +539,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; + } } } } diff --git a/mazda/outputs.cpp b/mazda/outputs.cpp index 59a89e33..f563789c 100644 --- a/mazda/outputs.cpp +++ b/mazda/outputs.cpp @@ -248,18 +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) - { - callbacks->releaseAudioFocus(); - } - else - { - scanCode = HUIB_PLAYPAUSE; - } - */ break; case KEY_LEFTBRACE: printf("KEY_LEFTBRACE (next track with media focus: %i)\n", hasMediaAudioFocus ? 1 : 0); From 9811aa827781b48dc8f78ca63d271cd73e5f1e7e Mon Sep 17 00:00:00 2001 From: Trevor Martin Date: Sun, 10 Dec 2017 19:37:32 -0800 Subject: [PATCH 3/3] Ignore Tansient Audio Focus Requests Also, do not set FocusType::NONE on temporarilyLost focus event to allow AA music player to resume playing when the transient stream passes audio focus back. AUDIO_FOCUS_GAIN_NAVI Handle Audio Request if Mic Output in MediaStart() --- hu/hu.proto | 2 +- mazda/callbacks.cpp | 20 ++++++++++++-------- mazda/main.cpp | 3 +++ mazda/outputs.cpp | 11 ----------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/hu/hu.proto b/hu/hu.proto index 9a72d7da..f7adac67 100644 --- a/hu/hu.proto +++ b/hu/hu.proto @@ -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; diff --git a/mazda/callbacks.cpp b/mazda/callbacks.cpp index 86c3467b..a3e7979c 100644 --- a/mazda/callbacks.cpp +++ b/mazda/callbacks.cpp @@ -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); } @@ -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 } @@ -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(); } } @@ -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 newFocus = result["newFocus"].get(); + std::string focusType = result["focusType"].get(); auto findIt = streamToSessionIds.find(streamName); int eventSessionID = -1; @@ -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; @@ -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; + } } } } diff --git a/mazda/main.cpp b/mazda/main.cpp index c087be6d..d5774210 100644 --- a/mazda/main.cpp +++ b/mazda/main.cpp @@ -107,6 +107,9 @@ static void gps_thread_func(std::condition_variable& quitcv, std::mutex& quitmut location->set_accuracy(static_cast(data.horizontalAccuracy * 1E3)); +#ifdef NAV_DEBUG + printf("GPS data: %d %d %f %f %d %f %f %f %f \n",data.positionAccuracy, data.uTCtime, data.latitude, data.longitude, data.altitude, data.heading, data.velocity, data.horizontalAccuracy, data.verticalAccuracy); +#endif s.hu_aap_enc_send_message(0, AA_CH_SEN, HU_SENSOR_CHANNEL_MESSAGE::SensorEvent, sensorEvent); }); } diff --git a/mazda/outputs.cpp b/mazda/outputs.cpp index 59a89e33..f563789c 100644 --- a/mazda/outputs.cpp +++ b/mazda/outputs.cpp @@ -248,18 +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) - { - callbacks->releaseAudioFocus(); - } - else - { - scanCode = HUIB_PLAYPAUSE; - } - */ break; case KEY_LEFTBRACE: printf("KEY_LEFTBRACE (next track with media focus: %i)\n", hasMediaAudioFocus ? 1 : 0);