From: Dmitriy Klimenko Date: Fri, 4 Apr 2014 13:19:38 +0000 (-0700) Subject: APPLINK-6534; APPLINK-5167: PerformAudioPassThru fix X-Git-Tag: 3.5~121 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b0c1c61b02e5982eef818819bc7c12db437cf619;p=profile%2Fivi%2Fsmartdevicelink.git APPLINK-6534; APPLINK-5167: PerformAudioPassThru fix --- diff --git a/src/components/application_manager/include/application_manager/commands/command_request_impl.h b/src/components/application_manager/include/application_manager/commands/command_request_impl.h index 008894b..6adbded 100644 --- a/src/components/application_manager/include/application_manager/commands/command_request_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_request_impl.h @@ -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_; diff --git a/src/components/application_manager/src/commands/command_request_impl.cc b/src/components/application_manager/src/commands/command_request_impl.cc index 30a9dbf..8fff7eb 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -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 diff --git a/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc b/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc index 71eec0e..2e9aa92 100644 --- a/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc +++ b/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc @@ -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"); diff --git a/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc b/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc index 9d496f0..d17bb26 100644 --- a/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc +++ b/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc @@ -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( - 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( + 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(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: { diff --git a/src/components/media_manager/include/media_manager/audio/audio_stream_sender_thread.h b/src/components/media_manager/include/media_manager/audio/audio_stream_sender_thread.h index 74c1d13..d01b08a 100644 --- a/src/components/media_manager/include/media_manager/audio/audio_stream_sender_thread.h +++ b/src/components/media_manager/include/media_manager/audio/audio_stream_sender_thread.h @@ -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; diff --git a/src/components/media_manager/src/audio/audio_stream_sender_thread.cc b/src/components/media_manager/src/audio/audio_stream_sender_thread.cc index e690093..2a91845 100644 --- a/src/components/media_manager/src/audio/audio_stream_sender_thread.cc +++ b/src/components/media_manager/src/audio/audio_stream_sender_thread.cc @@ -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::iterator from; std::vector::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_; }