APPLINK-6534; APPLINK-5167: PerformAudioPassThru fix
authorDmitriy Klimenko <DKlimenko@luxoft.com>
Fri, 4 Apr 2014 13:19:38 +0000 (06:19 -0700)
committerJustin Dickow <jjdickow@gmail.com>
Tue, 8 Jul 2014 22:51:28 +0000 (18:51 -0400)
src/components/application_manager/include/application_manager/commands/command_request_impl.h
src/components/application_manager/src/commands/command_request_impl.cc
src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc
src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc
src/components/media_manager/include/media_manager/audio/audio_stream_sender_thread.h
src/components/media_manager/src/audio/audio_stream_sender_thread.cc

index 008894b..6adbded 100644 (file)
@@ -146,6 +146,15 @@ class CommandRequestImpl : public CommandImpl,
   void CreateHMINotification(const hmi_apis::FunctionID::eType& function_id,
                              const NsSmart::SmartObject& msg_params) const;
 
+  /**
+   * @brief Converts HMI result code to Mobile result code
+   *
+   * @param hmi_code HMI result code
+   * @return Mobile result code
+   */
+  mobile_apis::Result::eType GetMobileResultCode(
+      const hmi_apis::Common_Result::eType& hmi_code) const;
+
  protected:
   unsigned int                default_timeout_;
   RequestState                current_state_;
index 30a9dbf..8fff7eb 100644 (file)
@@ -201,6 +201,116 @@ void CommandRequestImpl::CreateHMINotification(
   }
 }
 
+mobile_apis::Result::eType CommandRequestImpl::GetMobileResultCode(
+    const hmi_apis::Common_Result::eType& hmi_code) const {
+
+  mobile_apis::Result::eType mobile_result = mobile_apis::Result::GENERIC_ERROR;
+  switch (hmi_code) {
+    case hmi_apis::Common_Result::SUCCESS: {
+      mobile_result = mobile_apis::Result::SUCCESS;
+      break;
+    }
+    case hmi_apis::Common_Result::UNSUPPORTED_REQUEST: {
+      mobile_result = mobile_apis::Result::UNSUPPORTED_REQUEST;
+      break;
+    }
+    case hmi_apis::Common_Result::UNSUPPORTED_RESOURCE: {
+      mobile_result = mobile_apis::Result::UNSUPPORTED_RESOURCE;
+      break;
+    }
+    case hmi_apis::Common_Result::DISALLOWED: {
+      mobile_result = mobile_apis::Result::DISALLOWED;
+      break;
+    }
+    case hmi_apis::Common_Result::REJECTED: {
+      mobile_result = mobile_apis::Result::REJECTED;
+      break;
+    }
+    case hmi_apis::Common_Result::ABORTED: {
+      mobile_result = mobile_apis::Result::ABORTED;
+      break;
+    }
+    case hmi_apis::Common_Result::IGNORED: {
+      mobile_result = mobile_apis::Result::IGNORED;
+      break;
+    }
+    case hmi_apis::Common_Result::RETRY: {
+      mobile_result = mobile_apis::Result::RETRY;
+      break;
+    }
+    case hmi_apis::Common_Result::IN_USE: {
+      mobile_result = mobile_apis::Result::IN_USE;
+      break;
+    }
+    case hmi_apis::Common_Result::DATA_NOT_AVAILABLE: {
+      mobile_result = mobile_apis::Result::VEHICLE_DATA_NOT_AVAILABLE;
+      break;
+    }
+    case hmi_apis::Common_Result::TIMED_OUT: {
+      mobile_result = mobile_apis::Result::TIMED_OUT;
+      break;
+    }
+    case hmi_apis::Common_Result::INVALID_DATA: {
+      mobile_result = mobile_apis::Result::INVALID_DATA;
+      break;
+    }
+    case hmi_apis::Common_Result::CHAR_LIMIT_EXCEEDED: {
+      mobile_result = mobile_apis::Result::CHAR_LIMIT_EXCEEDED;
+      break;
+    }
+    case hmi_apis::Common_Result::INVALID_ID: {
+      mobile_result = mobile_apis::Result::INVALID_ID;
+      break;
+    }
+    case hmi_apis::Common_Result::DUPLICATE_NAME: {
+      mobile_result = mobile_apis::Result::DUPLICATE_NAME;
+      break;
+    }
+    case hmi_apis::Common_Result::APPLICATION_NOT_REGISTERED: {
+      mobile_result = mobile_apis::Result::APPLICATION_NOT_REGISTERED;
+      break;
+    }
+    case hmi_apis::Common_Result::WRONG_LANGUAGE: {
+      mobile_result = mobile_apis::Result::WRONG_LANGUAGE;
+      break;
+    }
+    case hmi_apis::Common_Result::OUT_OF_MEMORY: {
+      mobile_result = mobile_apis::Result::OUT_OF_MEMORY;
+      break;
+    }
+    case hmi_apis::Common_Result::TOO_MANY_PENDING_REQUESTS: {
+      mobile_result = mobile_apis::Result::TOO_MANY_PENDING_REQUESTS;
+      break;
+    }
+    case hmi_apis::Common_Result::NO_APPS_REGISTERED: {
+      mobile_result = mobile_apis::Result::APPLICATION_NOT_REGISTERED;
+      break;
+    }
+    case hmi_apis::Common_Result::NO_DEVICES_CONNECTED: {
+      mobile_result = mobile_apis::Result::APPLICATION_NOT_REGISTERED;
+      break;
+    }
+    case hmi_apis::Common_Result::WARNINGS: {
+      mobile_result = mobile_apis::Result::WARNINGS;
+      break;
+    }
+    case hmi_apis::Common_Result::GENERIC_ERROR: {
+      mobile_result = mobile_apis::Result::GENERIC_ERROR;
+      break;
+    }
+    case hmi_apis::Common_Result::USER_DISALLOWED: {
+      mobile_result = mobile_apis::Result::USER_DISALLOWED;
+      break;
+    }
+    default: {
+      LOG4CXX_ERROR(logger_, "Unknown HMI result code " << hmi_code);
+      break;
+    }
+  }
+
+  return mobile_result;
+}
+
 }  // namespace commands
 
 }  // namespace application_manager
index 71eec0e..2e9aa92 100644 (file)
@@ -48,13 +48,12 @@ EndAudioPassThruRequest::~EndAudioPassThruRequest() {
 
 void EndAudioPassThruRequest::Run() {
   LOG4CXX_INFO(logger_, "EndAudioPassThruRequest::Run");
-  bool ended_successfully = ApplicationManagerImpl::instance()->end_audio_pass_thru();
+  bool ended_successfully =
+      ApplicationManagerImpl::instance()->end_audio_pass_thru();
 
   if (ended_successfully) {
     SendHMIRequest(hmi_apis::FunctionID::UI_EndAudioPassThru, NULL, true);
-    int32_t session_key =
-      (*message_)[strings::params][strings::connection_key].asInt();
-    ApplicationManagerImpl::instance()->StopAudioPassThru(session_key);
+    ApplicationManagerImpl::instance()->StopAudioPassThru(connection_key());
   } else {
     SendResponse(false, mobile_apis::Result::REJECTED,
                  "No PerformAudioPassThru is now active");
index 9d496f0..d17bb26 100644 (file)
@@ -100,35 +100,35 @@ void PerformAudioPassThruRequest::on_event(const event_engine::Event& event) {
 
   switch (event.id()) {
     case hmi_apis::FunctionID::UI_PerformAudioPassThru: {
-      mobile_apis::Result::eType result_code =
-          static_cast<mobile_apis::Result::eType>(
-              message[strings::params][hmi_response::code].asInt());
 
-      bool result = mobile_apis::Result::SUCCESS == result_code ||
-                    mobile_apis::Result::RETRY == result_code;
+      std::string return_info;
+      mobile_apis::Result::eType mobile_code =
+          GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>(
+          message[strings::params][hmi_response::code].asUInt()));
 
-      if (ApplicationManagerImpl::instance()->end_audio_pass_thru()) {
-        int32_t session_key =
-          (*message_)[strings::params][strings::connection_key].asUInt();
-        ApplicationManagerImpl::instance()->StopAudioPassThru(session_key);
+      if (mobile_apis::Result::UNSUPPORTED_RESOURCE == mobile_code) {
+        mobile_code = mobile_apis::Result::WARNINGS;
+        return_info = "Unsupported phoneme type sent in a prompt";
       }
 
-      const char* return_info = NULL;
-
-      if (result) {
-        if (hmi_apis::Common_Result::UNSUPPORTED_RESOURCE ==
-            static_cast<hmi_apis::Common_Result::eType>(result_code)) {
-          result_code = mobile_apis::Result::WARNINGS;
-          return_info = std::string("Unsupported phoneme type sent in a prompt").c_str();
-        }
+      if (ApplicationManagerImpl::instance()->end_audio_pass_thru()) {
+        ApplicationManagerImpl::instance()->StopAudioPassThru(connection_key());
       }
 
-      SendResponse(result, result_code, return_info, &(message[strings::msg_params]));
+      bool result = mobile_apis::Result::SUCCESS == mobile_code ||
+                    mobile_apis::Result::RETRY == mobile_code;
+
+      SendResponse(result, mobile_code, return_info.c_str(),
+                   &(message[strings::msg_params]));
       break;
     }
     case hmi_apis::FunctionID::TTS_Stopped:{
       SendRecordStartNotification();
       StartMicrophoneRecording();
+      ApplicationManagerImpl::instance()->
+          updateRequestTimeout(connection_key(),
+                               correlation_id(),
+                               default_timeout());
       break;
     }
     default: {
index 74c1d13..d01b08a 100644 (file)
@@ -122,7 +122,7 @@ class AudioStreamSenderThread : public threads::ThreadDelegate {
     uint32_t session_key_;
     const std::string fileName_;
     int32_t offset_;
-    bool shouldBeStoped_;
+    volatile bool shouldBeStoped_;
     sync_primitives::Lock shouldBeStoped_lock_;
 
     static const int32_t kAudioPassThruTimeout;
index e690093..2a91845 100644 (file)
@@ -75,19 +75,21 @@ void AudioStreamSenderThread::threadMain() {
 
   offset_ = 0;
 
-  setShouldBeStopped(false);
-
   while (true) {
     if (getShouldBeStopped()) {
       break;
     }
 
-    sendAudioChunkToMobile();
+    usleep(kAudioPassThruTimeout * 1000000);
 
     if (getShouldBeStopped()) {
       break;
     }
+
+    sendAudioChunkToMobile();
   }
+
+  LOG4CXX_TRACE_EXIT(logger_);
 }
 
 void AudioStreamSenderThread::sendAudioChunkToMobile() {
@@ -97,8 +99,6 @@ void AudioStreamSenderThread::sendAudioChunkToMobile() {
   std::vector<uint8_t>::iterator from;
   std::vector<uint8_t>::iterator to;
 
-  usleep(kAudioPassThruTimeout * 1000000);
-
   if (!file_system::ReadBinaryFile(fileName_, binaryData)) {
     LOG4CXX_ERROR_EXT(logger_, "Unable to read file." << fileName_);
 
@@ -133,6 +133,7 @@ void AudioStreamSenderThread::sendAudioChunkToMobile() {
 
 bool AudioStreamSenderThread::getShouldBeStopped() {
   AutoLock auto_lock(shouldBeStoped_lock_);
+
   return shouldBeStoped_;
 }