diff options
Diffstat (limited to 'src/components/media_manager/src/media_manager_impl.cc')
-rw-r--r-- | src/components/media_manager/src/media_manager_impl.cc | 217 |
1 files changed, 100 insertions, 117 deletions
diff --git a/src/components/media_manager/src/media_manager_impl.cc b/src/components/media_manager/src/media_manager_impl.cc index e8156795b..61b2c5bb9 100644 --- a/src/components/media_manager/src/media_manager_impl.cc +++ b/src/components/media_manager/src/media_manager_impl.cc @@ -1,34 +1,34 @@ -/** -* Copyright (c) 2013, Ford Motor Company -* All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* Redistributions of source code must retain the above copyright notice, this -* list of conditions and the following disclaimer. -* -* Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following -* disclaimer in the documentation and/or other materials provided with the -* distribution. -* -* Neither the name of the Ford Motor Company nor the names of its contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ +/* + * Copyright (c) 2014, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #include "config_profile/profile.h" #include "media_manager/media_manager_impl.h" @@ -38,8 +38,10 @@ #include "application_manager/application.h" #include "application_manager/application_manager_impl.h" #include "application_manager/application_impl.h" +#include "protocol_handler/protocol_handler.h" #include "utils/file_system.h" #include "utils/logger.h" +#include "utils/helpers.h" #if defined(EXTENDED_MEDIA_MODE) #include "media_manager/audio/a2dp_source_player_adapter.h" #include "media_manager/audio/from_mic_recorder_adapter.h" @@ -50,19 +52,17 @@ #include "media_manager/audio/pipe_audio_streamer_adapter.h" #include "media_manager/video/video_stream_to_file_adapter.h" - namespace media_manager { +using profile::Profile; +using timer::TimerThread; + CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManagerImpl") MediaManagerImpl::MediaManagerImpl() : protocol_handler_(NULL) , a2dp_player_(NULL) - , from_mic_recorder_(NULL) - , video_streamer_(NULL) - , audio_streamer_(NULL) - , video_stream_active_(false) - , audio_stream_active_(false) { + , from_mic_recorder_(NULL) { Init(); } @@ -76,24 +76,10 @@ MediaManagerImpl::~MediaManagerImpl() { delete from_mic_recorder_; from_mic_recorder_ = NULL; } - - if (video_streamer_) { - delete video_streamer_; - video_streamer_ = NULL; - } - - if (audio_streamer_) { - delete audio_streamer_; - audio_streamer_ = NULL; - } -} - -void MediaManagerImpl::SetProtocolHandler( - protocol_handler::ProtocolHandler* protocol_handler) { - protocol_handler_ = protocol_handler; } void MediaManagerImpl::Init() { + using namespace protocol_handler; LOG4CXX_INFO(logger_, "MediaManagerImpl::Init()"); #if defined(EXTENDED_MEDIA_MODE) @@ -103,44 +89,46 @@ void MediaManagerImpl::Init() { #endif if ("socket" == profile::Profile::instance()->video_server_type()) { - video_streamer_ = new SocketVideoStreamerAdapter(); + streamer_[ServiceType::kMobileNav] = new SocketVideoStreamerAdapter(); } else if ("pipe" == profile::Profile::instance()->video_server_type()) { - video_streamer_ = new PipeVideoStreamerAdapter(); + streamer_[ServiceType::kMobileNav] = new PipeVideoStreamerAdapter(); } else if ("file" == profile::Profile::instance()->video_server_type()) { - video_streamer_ = new VideoStreamToFileAdapter( + streamer_[ServiceType::kMobileNav] = new VideoStreamToFileAdapter( profile::Profile::instance()->video_stream_file()); } if ("socket" == profile::Profile::instance()->audio_server_type()) { - audio_streamer_ = new SocketAudioStreamerAdapter(); + streamer_[ServiceType::kAudio] = new SocketAudioStreamerAdapter(); } else if ("pipe" == profile::Profile::instance()->audio_server_type()) { - audio_streamer_ = new PipeAudioStreamerAdapter(); + streamer_[ServiceType::kAudio] = new PipeAudioStreamerAdapter(); } else if ("file" == profile::Profile::instance()->audio_server_type()) { - audio_streamer_ = new VideoStreamToFileAdapter( + streamer_[ServiceType::kAudio] = new VideoStreamToFileAdapter( profile::Profile::instance()->audio_stream_file()); } - video_streamer_listener_ = new StreamerListener(); - audio_streamer_listener_ = new StreamerListener(); + streamer_listener_[ServiceType::kMobileNav] = new StreamerListener(); + streamer_listener_[ServiceType::kAudio] = new StreamerListener(); - if (NULL != video_streamer_) { - video_streamer_->AddListener(video_streamer_listener_); + if (streamer_[ServiceType::kMobileNav]) { + streamer_[ServiceType::kMobileNav]->AddListener( + streamer_listener_[ServiceType::kMobileNav]); } - if (NULL != audio_streamer_) { - audio_streamer_->AddListener(audio_streamer_listener_); + if (streamer_[ServiceType::kAudio]) { + streamer_[ServiceType::kAudio]->AddListener( + streamer_listener_[ServiceType::kAudio]); } } void MediaManagerImpl::PlayA2DPSource(int32_t application_key) { - LOG4CXX_INFO(logger_, "MediaManagerImpl::PlayA2DPSource"); + LOG4CXX_AUTO_TRACE(logger_); if (a2dp_player_) { a2dp_player_->StartActivity(application_key); } } void MediaManagerImpl::StopA2DPSource(int32_t application_key) { - LOG4CXX_INFO(logger_, "MediaManagerImpl::StopA2DPSource"); + LOG4CXX_AUTO_TRACE(logger_); if (a2dp_player_) { a2dp_player_->StopActivity(application_key); } @@ -200,7 +188,7 @@ void MediaManagerImpl::StartMicrophoneRecording( } void MediaManagerImpl::StopMicrophoneRecording(int32_t application_key) { - LOG4CXX_INFO(logger_, "MediaManagerImpl::StopMicrophoneRecording"); + LOG4CXX_AUTO_TRACE(logger_); #if defined(EXTENDED_MEDIA_MODE) if (from_mic_recorder_) { from_mic_recorder_->StopActivity(application_key); @@ -209,70 +197,65 @@ void MediaManagerImpl::StopMicrophoneRecording(int32_t application_key) { if (from_mic_listener_) { from_mic_listener_->OnActivityEnded(application_key); } +#if defined(EXTENDED_MEDIA_MODE) + if (from_mic_recorder_) { + from_mic_recorder_->RemoveListener(from_mic_listener_); + } +#endif } -void MediaManagerImpl::StartVideoStreaming(int32_t application_key) { - LOG4CXX_INFO(logger_, "MediaManagerImpl::StartVideoStreaming"); +void MediaManagerImpl::StartStreaming( + int32_t application_key, protocol_handler::ServiceType service_type) { + LOG4CXX_AUTO_TRACE(logger_); - if (video_streamer_) { - if (!video_stream_active_) { - video_stream_active_ = true; - video_streamer_->StartActivity(application_key); - application_manager::MessageHelper::SendNaviStartStream(application_key); - } + if (streamer_[service_type]) { + streamer_[service_type]->StartActivity(application_key); } } -void MediaManagerImpl::StopVideoStreaming(int32_t application_key) { - LOG4CXX_INFO(logger_, "MediaManagerImpl::StopVideoStreaming"); - if (video_streamer_) { - video_stream_active_ = false; - application_manager::MessageHelper::SendNaviStopStream(application_key); - video_streamer_->StopActivity(application_key); +void MediaManagerImpl::StopStreaming( + int32_t application_key, protocol_handler::ServiceType service_type) { + LOG4CXX_AUTO_TRACE(logger_); + + if (streamer_[service_type]) { + streamer_[service_type]->StopActivity(application_key); } } -void MediaManagerImpl::StartAudioStreaming(int32_t application_key) { - LOG4CXX_INFO(logger_, "MediaManagerImpl::StartAudioStreaming"); +void MediaManagerImpl::SetProtocolHandler( + protocol_handler::ProtocolHandler* protocol_handler) { + protocol_handler_ = protocol_handler; +} + +void MediaManagerImpl::OnMessageReceived( + const ::protocol_handler::RawMessagePtr message) { + using namespace protocol_handler; + using namespace application_manager; + using namespace helpers; + LOG4CXX_AUTO_TRACE(logger_); - if (audio_streamer_) { - if (!audio_stream_active_) { - audio_stream_active_ = true; - audio_streamer_->StartActivity(application_key); - application_manager::MessageHelper::SendAudioStartStream(application_key); - } + const uint32_t streaming_app_id = message->connection_key(); + const ServiceType service_type = message->service_type(); + + if (Compare<ServiceType, NEQ, ALL>( + service_type, ServiceType::kMobileNav, ServiceType::kAudio)) { + LOG4CXX_DEBUG(logger_, "Unsupported service type in MediaManager"); + return; } -} -void MediaManagerImpl::StopAudioStreaming(int32_t application_key) { - LOG4CXX_INFO(logger_, "MediaManagerImpl::StopAudioStreaming"); - if (audio_streamer_) { - audio_stream_active_ = false; - application_manager::MessageHelper::SendAudioStopStream(application_key); - audio_streamer_->StopActivity(application_key); + ApplicationManagerImpl* app_mgr = ApplicationManagerImpl::instance(); + DCHECK_OR_RETURN_VOID(app_mgr); + + if (!app_mgr->CanAppStream(streaming_app_id, service_type)) { + app_mgr->ForbidStreaming(streaming_app_id); + LOG4CXX_ERROR(logger_, "The application trying to stream when it should not."); + return; } -} -void MediaManagerImpl::OnMessageReceived( - const ::protocol_handler::RawMessagePtr message) { - if (message->service_type() - == protocol_handler::kMobileNav) { - if (!(application_manager::ApplicationManagerImpl::instance()-> - IsVideoStreamingAllowed(message->connection_key()))) { - return; - } - if (video_streamer_) { - video_streamer_->SendData(message->connection_key(), message); - } - } else if (message->service_type() - == protocol_handler::kAudio) { - if (!(application_manager::ApplicationManagerImpl::instance()-> - IsAudioStreamingAllowed(message->connection_key()))) { - return; - } - if (audio_streamer_) { - audio_streamer_->SendData(message->connection_key(), message); - } + ApplicationSharedPtr app = app_mgr->application(streaming_app_id); + if (app) { + app->WakeUpStreaming(service_type); + streamer_[service_type]->SendData(streaming_app_id, message); } } |