summaryrefslogtreecommitdiff
path: root/src/components/media_manager
diff options
context:
space:
mode:
authorArtem Nosach <ANosach@luxoft.com>2015-04-06 22:26:44 +0300
committerArtem Nosach <ANosach@luxoft.com>2015-04-23 15:33:23 +0300
commitabf0e0f76025f11fb046b5f92fc3d59c7966ba3c (patch)
treeb8bd213f8abcc7f33ec6b73f887b13b642e15ee4 /src/components/media_manager
parent28d88105cdfdcaff75688483f3bd89f046f42b68 (diff)
downloadsdl_core-abf0e0f76025f11fb046b5f92fc3d59c7966ba3c.tar.gz
Rework media manager.
Diffstat (limited to 'src/components/media_manager')
-rw-r--r--src/components/media_manager/include/media_manager/media_adapter_impl.h3
-rw-r--r--src/components/media_manager/include/media_manager/media_manager.h15
-rw-r--r--src/components/media_manager/include/media_manager/media_manager_impl.h42
-rw-r--r--src/components/media_manager/src/media_manager_impl.cc185
4 files changed, 83 insertions, 162 deletions
diff --git a/src/components/media_manager/include/media_manager/media_adapter_impl.h b/src/components/media_manager/include/media_manager/media_adapter_impl.h
index aad814224a..a3a296150b 100644
--- a/src/components/media_manager/include/media_manager/media_adapter_impl.h
+++ b/src/components/media_manager/include/media_manager/media_adapter_impl.h
@@ -56,6 +56,9 @@ class MediaAdapterImpl : public MediaAdapter {
private:
DISALLOW_COPY_AND_ASSIGN(MediaAdapterImpl);
};
+
+typedef utils::SharedPtr<MediaAdapterImpl> MediaAdapterImplPtr;
+
} // namespace media_manager
#endif // SRC_COMPONENTS_MEDIA_MANAGER_INCLUDE_MEDIA_MANAGER_MEDIA_ADAPTER_IMPL_H_
diff --git a/src/components/media_manager/include/media_manager/media_manager.h b/src/components/media_manager/include/media_manager/media_manager.h
index b879b7546e..af6aa857f8 100644
--- a/src/components/media_manager/include/media_manager/media_manager.h
+++ b/src/components/media_manager/include/media_manager/media_manager.h
@@ -34,22 +34,29 @@
#define SRC_COMPONENTS_MEDIA_MANAGER_INCLUDE_MEDIA_MANAGER_MEDIA_MANAGER_H_
#include <string>
+#include "protocol/service_type.h"
namespace media_manager {
+using protocol_handler::ServiceType;
+
class MediaManager {
public:
virtual void PlayA2DPSource(int32_t application_key) = 0;
virtual void StopA2DPSource(int32_t application_key) = 0;
+
virtual void StartMicrophoneRecording(int32_t application_key,
const std::string& outputFileName,
int32_t duration) = 0;
virtual void StopMicrophoneRecording(int32_t application_key) = 0;
- virtual void StartVideoStreaming(int32_t application_key) = 0;
- virtual void StopVideoStreaming(int32_t application_key) = 0;
- virtual void StartAudioStreaming(int32_t application_key) = 0;
- virtual void StopAudioStreaming(int32_t application_key) = 0;
+
+ virtual void StartStreaming(int32_t application_key,
+ ServiceType service_type) = 0;
+ virtual void StopStreaming(int32_t application_key,
+ ServiceType service_type) = 0;
virtual ~MediaManager(){}
};
+
} // namespace media_manager
+
#endif // SRC_COMPONENTS_MEDIA_MANAGER_INCLUDE_MEDIA_MANAGER_MEDIA_MANAGER_H_
diff --git a/src/components/media_manager/include/media_manager/media_manager_impl.h b/src/components/media_manager/include/media_manager/media_manager_impl.h
index 9b8a2abaa2..de9a16e9af 100644
--- a/src/components/media_manager/include/media_manager/media_manager_impl.h
+++ b/src/components/media_manager/include/media_manager/media_manager_impl.h
@@ -35,7 +35,6 @@
#include <string>
#include "utils/singleton.h"
-#include "utils/timer_thread.h"
#include "protocol_handler/protocol_observer.h"
#include "protocol_handler/protocol_handler.h"
#include "protocol/service_type.h"
@@ -44,24 +43,29 @@
#include "media_manager/media_adapter_listener.h"
namespace media_manager {
+using protocol_handler::ServiceType;
class MediaManagerImpl : public MediaManager,
public protocol_handler::ProtocolObserver,
public utils::Singleton<MediaManagerImpl> {
public:
virtual ~MediaManagerImpl();
- virtual void SetProtocolHandler(
- protocol_handler::ProtocolHandler* protocol_handler);
+
virtual void PlayA2DPSource(int32_t application_key);
virtual void StopA2DPSource(int32_t application_key);
+
virtual void StartMicrophoneRecording(int32_t application_key,
const std::string& outputFileName,
int32_t duration);
virtual void StopMicrophoneRecording(int32_t application_key);
- virtual void StartVideoStreaming(int32_t application_key);
- virtual void StopVideoStreaming(int32_t application_key);
- virtual void StartAudioStreaming(int32_t application_key);
- virtual void StopAudioStreaming(int32_t application_key);
+
+ virtual void StartStreaming(int32_t application_key,
+ ServiceType service_type);
+ virtual void StopStreaming(int32_t application_key,
+ ServiceType service_type);
+
+ virtual void SetProtocolHandler(
+ protocol_handler::ProtocolHandler* protocol_handler);
virtual void OnMessageReceived(
const ::protocol_handler::RawMessagePtr message);
virtual void OnMobileMessageSent(
@@ -71,33 +75,21 @@ class MediaManagerImpl : public MediaManager,
protected:
MediaManagerImpl();
virtual void Init();
+
protocol_handler::ProtocolHandler* protocol_handler_;
MediaAdapter* a2dp_player_;
+
MediaAdapterImpl* from_mic_recorder_;
MediaListenerPtr from_mic_listener_;
- MediaAdapterImpl* video_streamer_;
- MediaAdapterImpl* audio_streamer_;
- uint32_t stop_streaming_timeout_;
- MediaListenerPtr video_streamer_listener_;
- MediaListenerPtr audio_streamer_listener_;
- bool video_stream_active_;
- bool audio_stream_active_;
- private:
- void OnAudioStreamingTimeout();
- void OnVideoStreamingTimeout();
+ std::map<ServiceType, MediaAdapterImplPtr> streamer_;
+ std::map<ServiceType, MediaListenerPtr> streamer_listener_;
- timer::TimerThread<MediaManagerImpl> audio_streaming_timer_;
- timer::TimerThread<MediaManagerImpl> video_streaming_timer_;
- bool audio_streaming_suspended_;
- bool video_streaming_suspended_;
- sync_primitives::Lock audio_streaming_suspended_lock_;
- sync_primitives::Lock video_streaming_suspended_lock_;
-
- uint32_t streaming_app_id_;
+ private:
DISALLOW_COPY_AND_ASSIGN(MediaManagerImpl);
FRIEND_BASE_SINGLETON_CLASS(MediaManagerImpl);
};
} // namespace media_manager
+
#endif // SRC_COMPONENTS_MEDIA_MANAGER_INCLUDE_MEDIA_MANAGER_MEDIA_MANAGER_IMPL_H_
diff --git a/src/components/media_manager/src/media_manager_impl.cc b/src/components/media_manager/src/media_manager_impl.cc
index 165e273156..387b39eb66 100644
--- a/src/components/media_manager/src/media_manager_impl.cc
+++ b/src/components/media_manager/src/media_manager_impl.cc
@@ -50,7 +50,6 @@
#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;
@@ -60,18 +59,7 @@ 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)
- , audio_streaming_timer_("Audio streaming timer", this,
- &MediaManagerImpl::OnAudioStreamingTimeout)
- , video_streaming_timer_("Video streaming timer", this,
- &MediaManagerImpl::OnVideoStreamingTimeout)
- , audio_streaming_suspended_(true)
- , video_streaming_suspended_(true)
- , streaming_app_id_(0) {
+ , from_mic_recorder_(NULL) {
Init();
}
@@ -85,21 +73,6 @@ 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() {
@@ -129,44 +102,20 @@ void MediaManagerImpl::Init() {
profile::Profile::instance()->audio_stream_file());
}
- stop_streaming_timeout_ = profile::Profile::instance()->stop_streaming_timeout();
+ streamer_listener_[ServiceType::kMobileNav] = new StreamerListener();
+ streamer_listener_[ServiceType::kAudio] = new StreamerListener();
- video_streamer_listener_ = new StreamerListener();
- audio_streamer_listener_ = 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::OnAudioStreamingTimeout() {
- using namespace application_manager;
- using namespace protocol_handler;
- LOG4CXX_DEBUG(logger_, "Data is not available for service type "
- << ServiceType::kAudio);
- MessageHelper::SendOnDataStreaming(ServiceType::kAudio, false);
- ApplicationManagerImpl::instance()->StreamingEnded(streaming_app_id_);
-
- sync_primitives::AutoLock lock(audio_streaming_suspended_lock_);
- audio_streaming_suspended_ = true;
-}
-
-void media_manager::MediaManagerImpl::OnVideoStreamingTimeout() {
- using namespace application_manager;
- using namespace protocol_handler;
- LOG4CXX_DEBUG(logger_, "Data is not available for service type "
- << ServiceType::kMobileNav);
- MessageHelper::SendOnDataStreaming(ServiceType::kMobileNav, false);
- ApplicationManagerImpl::instance()->StreamingEnded(streaming_app_id_);
-
- sync_primitives::AutoLock lock(video_streaming_suspended_lock_);
- video_streaming_suspended_ = true;
-}
-
void MediaManagerImpl::PlayA2DPSource(int32_t application_key) {
LOG4CXX_AUTO_TRACE(logger_);
if (a2dp_player_) {
@@ -251,96 +200,66 @@ void MediaManagerImpl::StopMicrophoneRecording(int32_t application_key) {
#endif
}
-void MediaManagerImpl::StartVideoStreaming(int32_t application_key) {
+void MediaManagerImpl::StartStreaming(int32_t application_key,
+ 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_AUTO_TRACE(logger_);
- if (video_streamer_) {
- video_stream_active_ = false;
- application_manager::MessageHelper::SendNaviStopStream(application_key);
- video_streamer_->StopActivity(application_key);
+ if (streamer_listener_[service_type]) {
+ streamer_listener_[service_type]->OnActivityStarted(application_key);
}
}
-void MediaManagerImpl::StartAudioStreaming(int32_t application_key) {
+void MediaManagerImpl::StopStreaming(int32_t application_key,
+ ServiceType service_type) {
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);
- }
+ if (streamer_listener_[service_type]) {
+ streamer_listener_[service_type]->OnActivityEnded(application_key);
+ }
+ if (streamer_[service_type]) {
+ streamer_[service_type]->StopActivity(application_key);
}
}
-void MediaManagerImpl::StopAudioStreaming(int32_t application_key) {
- LOG4CXX_AUTO_TRACE(logger_);
- if (audio_streamer_) {
- audio_stream_active_ = false;
- application_manager::MessageHelper::SendAudioStopStream(application_key);
- audio_streamer_->StopActivity(application_key);
- }
+void MediaManagerImpl::SetProtocolHandler(
+ protocol_handler::ProtocolHandler* protocol_handler) {
+ protocol_handler_ = protocol_handler;
}
void MediaManagerImpl::OnMessageReceived(
const ::protocol_handler::RawMessagePtr message) {
LOG4CXX_AUTO_TRACE(logger_);
-
using namespace application_manager;
- using namespace protocol_handler;
-
- streaming_app_id_ = message->connection_key();
- ServiceType streaming_app_service_type = message->service_type();
-
- if (streaming_app_service_type == kMobileNav) {
- if ((ApplicationManagerImpl::instance()->
- IsVideoStreamingAllowed(streaming_app_id_))) {
- if (ApplicationManagerImpl::instance()->CanAppStream(streaming_app_id_)) {
- sync_primitives::AutoLock lock(video_streaming_suspended_lock_);
- if (video_streaming_suspended_) {
- LOG4CXX_DEBUG(logger_, "Data is available for service type "
- << streaming_app_service_type);
- MessageHelper::SendOnDataStreaming(streaming_app_service_type, true);
- video_streaming_suspended_ = false;
- }
- video_streamer_->SendData(streaming_app_id_, message);
- video_streaming_timer_.start(video_data_stopped_timeout_);
- } else {
- ApplicationManagerImpl::instance()->ForbidStreaming(streaming_app_id_);
- LOG4CXX_ERROR(logger_,
- "The application trying to stream when it should not.");
- }
- }
- } else if (streaming_app_service_type == kAudio) {
- if ((ApplicationManagerImpl::instance()->
- IsAudioStreamingAllowed(streaming_app_id_))) {
- if (ApplicationManagerImpl::instance()->CanAppStream(streaming_app_id_)) {
- sync_primitives::AutoLock lock(audio_streaming_suspended_lock_);
- if (audio_streaming_suspended_) {
- LOG4CXX_DEBUG(logger_, "Data is available for service type "
- << streaming_app_service_type);
- MessageHelper::SendOnDataStreaming(streaming_app_service_type, true);
- audio_streaming_suspended_ = false;
- }
- audio_streamer_->SendData(streaming_app_id_, message);
- audio_streaming_timer_.start(audio_data_stopped_timeout_);
- } else {
- ApplicationManagerImpl::instance()->ForbidStreaming(streaming_app_id_);
- LOG4CXX_ERROR(logger_,
- "The application trying to stream when it should not.");
- }
- }
+ using namespace helpers;
+
+ 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;
+ }
+
+ ApplicationManagerImpl* app_mgr = ApplicationManagerImpl::instance();
+ if (!app_mgr) {
+ LOG4CXX_ERROR(logger_, "Application manager not found");
+ return;
+ }
+
+ 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;
+ }
+
+ ApplicationSharedPtr app = app_mgr->application(streaming_app_id);
+ if (app) {
+ app->WakeUpStreaming(service_type);
+ streamer_[service_type]->SendData(streaming_app_id, message);
}
}