summaryrefslogtreecommitdiff
path: root/src/components/media_manager/src
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/media_manager/src')
-rw-r--r--src/components/media_manager/src/audio/a2dp_source_player_adapter.cc122
-rw-r--r--src/components/media_manager/src/audio/audio_stream_sender_thread.cc38
-rw-r--r--src/components/media_manager/src/audio/file_audio_streamer_adapter.cc43
-rw-r--r--src/components/media_manager/src/audio/from_mic_recorder_adapter.cc36
-rw-r--r--src/components/media_manager/src/audio/from_mic_recorder_listener.cc39
-rw-r--r--src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc82
-rw-r--r--src/components/media_manager/src/audio/pipe_audio_streamer_adapter.cc20
-rw-r--r--src/components/media_manager/src/audio/socket_audio_streamer_adapter.cc28
-rw-r--r--src/components/media_manager/src/file_streamer_adapter.cc102
-rw-r--r--src/components/media_manager/src/media_adapter_impl.cc6
-rw-r--r--src/components/media_manager/src/media_manager_impl.cc161
-rw-r--r--src/components/media_manager/src/pipe_streamer_adapter.cc216
-rw-r--r--src/components/media_manager/src/socket_streamer_adapter.cc312
-rw-r--r--src/components/media_manager/src/streamer_adapter.cc172
-rw-r--r--src/components/media_manager/src/streamer_listener.cc29
-rw-r--r--src/components/media_manager/src/video/file_video_streamer_adapter.cc43
-rw-r--r--src/components/media_manager/src/video/pipe_video_streamer_adapter.cc19
-rw-r--r--src/components/media_manager/src/video/socket_video_streamer_adapter.cc28
-rw-r--r--src/components/media_manager/src/video/video_stream_to_file_adapter.cc50
19 files changed, 826 insertions, 720 deletions
diff --git a/src/components/media_manager/src/audio/a2dp_source_player_adapter.cc b/src/components/media_manager/src/audio/a2dp_source_player_adapter.cc
index a6a36ef547..e5cd41c8c3 100644
--- a/src/components/media_manager/src/audio/a2dp_source_player_adapter.cc
+++ b/src/components/media_manager/src/audio/a2dp_source_player_adapter.cc
@@ -39,42 +39,43 @@
#include "utils/lock.h"
#include "utils/logger.h"
#include "connection_handler/connection_handler_impl.h"
+#include "protocol_handler/session_observer.h"
namespace media_manager {
-CREATE_LOGGERPTR_GLOBAL(logger_, "A2DPSourcePlayerAdapter");
+CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManager")
const static size_t BUFSIZE = 32;
class A2DPSourcePlayerAdapter::A2DPSourcePlayerThread
: public threads::ThreadDelegate {
- public:
- explicit A2DPSourcePlayerThread(const std::string& device);
+ public:
+ explicit A2DPSourcePlayerThread(const std::string& device);
- void threadMain();
+ void threadMain();
- void exitThreadMain();
+ void exitThreadMain();
- private:
- // The Sample format to use
- static const pa_sample_spec sSampleFormat_;
+ private:
+ // The Sample format to use
+ static const pa_sample_spec sSampleFormat_;
- pa_simple* s_in, *s_out;
- std::string device_;
- bool should_be_stopped_;
- sync_primitives::Lock should_be_stopped_lock_;
+ pa_simple* s_in, *s_out;
+ std::string device_;
+ bool should_be_stopped_;
+ sync_primitives::Lock should_be_stopped_lock_;
- void freeStreams();
+ void freeStreams();
- DISALLOW_COPY_AND_ASSIGN(A2DPSourcePlayerThread);
+ DISALLOW_COPY_AND_ASSIGN(A2DPSourcePlayerThread);
};
-A2DPSourcePlayerAdapter::A2DPSourcePlayerAdapter() {
-}
+A2DPSourcePlayerAdapter::A2DPSourcePlayerAdapter(
+ protocol_handler::SessionObserver& session_observer)
+ : session_observer_(session_observer) {}
A2DPSourcePlayerAdapter::~A2DPSourcePlayerAdapter() {
- for (SourcesMap::iterator it = sources_.begin();
- sources_.end() != it; ++it) {
+ for (SourcesMap::iterator it = sources_.begin(); sources_.end() != it; ++it) {
Pair pair = it->second;
pair.first->join();
delete pair.second;
@@ -84,20 +85,19 @@ A2DPSourcePlayerAdapter::~A2DPSourcePlayerAdapter() {
}
void A2DPSourcePlayerAdapter::StartActivity(int32_t application_key) {
- LOG4CXX_INFO(logger_, "Starting a2dp playing music for "
- << application_key << " application.");
+ LOG4CXX_INFO(logger_,
+ "Starting a2dp playing music for " << application_key
+ << " application.");
if (application_key != current_application_) {
current_application_ = application_key;
+ const protocol_handler::SessionObserver&
+ session_observer =->connection_handler().get_session_observer();
+
uint32_t device_id = 0;
- connection_handler::ConnectionHandlerImpl::instance()->
- GetDataOnSessionKey(application_key, 0, NULL, &device_id);
+ session_observer_.GetDataOnSessionKey(application_key, 0, NULL, &device_id);
std::string mac_adddress;
- connection_handler::ConnectionHandlerImpl::instance()->GetDataOnDeviceID(
- device_id,
- NULL,
- NULL,
- &mac_adddress);
+ session_observer_.GetDataOnDeviceID(device_id, NULL, NULL, &mac_adddress);
// TODO(PK): Convert mac_adddress to the
// following format : "bluez_source.XX_XX_XX_XX_XX_XX" if needed
@@ -105,16 +105,17 @@ void A2DPSourcePlayerAdapter::StartActivity(int32_t application_key) {
A2DPSourcePlayerThread* delegate =
new A2DPSourcePlayerAdapter::A2DPSourcePlayerThread(mac_adddress);
- threads::Thread* new_activity = threads::CreateThread(
- mac_adddress.c_str(), delegate);
+ threads::Thread* new_activity =
+ threads::CreateThread(mac_adddress.c_str(), delegate);
sources_[application_key] = Pair(new_activity, delegate);
new_activity->start();
}
}
void A2DPSourcePlayerAdapter::StopActivity(int32_t application_key) {
- LOG4CXX_INFO(logger_, "Stopping 2dp playing for "
- << application_key << " application.");
+ LOG4CXX_INFO(logger_,
+ "Stopping 2dp playing for " << application_key
+ << " application.");
if (application_key != current_application_) {
return;
}
@@ -128,23 +129,20 @@ void A2DPSourcePlayerAdapter::StopActivity(int32_t application_key) {
}
}
-bool A2DPSourcePlayerAdapter::is_app_performing_activity(int32_t
- application_key) {
+bool A2DPSourcePlayerAdapter::is_app_performing_activity(
+ int32_t application_key) const {
return (application_key == current_application_);
}
-const pa_sample_spec A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::
-sSampleFormat_ = {
- /*format*/ PA_SAMPLE_S16LE,
- /*rate*/ 44100,
- /*channels*/ 2
-};
+const pa_sample_spec
+ A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::sSampleFormat_ = {
+ /*format*/ PA_SAMPLE_S16LE,
+ /*rate*/ 44100,
+ /*channels*/ 2};
A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::A2DPSourcePlayerThread(
- const std::string& device)
- : threads::ThreadDelegate(),
- device_(device) {
-}
+ const std::string& device)
+ : threads::ThreadDelegate(), device_(device) {}
void A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::freeStreams() {
LOG4CXX_INFO(logger_, "Free streams in A2DPSourcePlayerThread.");
@@ -179,15 +177,29 @@ void A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::threadMain() {
LOG4CXX_DEBUG(logger_, "Creating streams");
/* Create a new playback stream */
- if (!(s_out = pa_simple_new(NULL, "AudioManager", PA_STREAM_PLAYBACK, NULL,
- "playback", &sSampleFormat_, NULL, NULL, &error))) {
+ if (!(s_out = pa_simple_new(NULL,
+ "AudioManager",
+ PA_STREAM_PLAYBACK,
+ NULL,
+ "playback",
+ &sSampleFormat_,
+ NULL,
+ NULL,
+ &error))) {
LOG4CXX_ERROR(logger_, "pa_simple_new() failed: " << pa_strerror(error));
freeStreams();
return;
}
- if (!(s_in = pa_simple_new(NULL, "AudioManager", PA_STREAM_RECORD, a2dpSource,
- "record", &sSampleFormat_, NULL, NULL, &error))) {
+ if (!(s_in = pa_simple_new(NULL,
+ "AudioManager",
+ PA_STREAM_RECORD,
+ a2dpSource,
+ "record",
+ &sSampleFormat_,
+ NULL,
+ NULL,
+ &error))) {
LOG4CXX_ERROR(logger_, "pa_simple_new() failed: " << pa_strerror(error));
freeStreams();
return;
@@ -200,17 +212,17 @@ void A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::threadMain() {
pa_usec_t latency;
- if ((latency = pa_simple_get_latency(s_in, &error)) == (pa_usec_t) - 1) {
- LOG4CXX_ERROR(logger_, "pa_simple_get_latency() failed: "
- << pa_strerror(error));
+ if ((latency = pa_simple_get_latency(s_in, &error)) == (pa_usec_t)-1) {
+ LOG4CXX_ERROR(logger_,
+ "pa_simple_get_latency() failed: " << pa_strerror(error));
break;
}
// LOG4CXX_INFO(logger_, "In: " << static_cast<float>(latency));
- if ((latency = pa_simple_get_latency(s_out, &error)) == (pa_usec_t) - 1) {
- LOG4CXX_ERROR(logger_, "pa_simple_get_latency() failed: "
- << pa_strerror(error));
+ if ((latency = pa_simple_get_latency(s_out, &error)) == (pa_usec_t)-1) {
+ LOG4CXX_ERROR(logger_,
+ "pa_simple_get_latency() failed: " << pa_strerror(error));
break;
}
@@ -223,8 +235,8 @@ void A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::threadMain() {
/* ... and play it */
if (pa_simple_write(s_out, buf, sizeof(buf), &error) < 0) {
- LOG4CXX_ERROR(logger_, "pa_simple_write() failed: "
- << pa_strerror(error));
+ LOG4CXX_ERROR(logger_,
+ "pa_simple_write() failed: " << pa_strerror(error));
break;
}
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 a78ca8b49c..24b12cabad 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
@@ -30,23 +30,21 @@
// POSSIBILITY OF SUCH DAMAGE.
//
-
#if defined(OS_POSIX) && defined(OS_LINUX)
#include <pthread.h> // TODO(DK): Need to remove
#include <unistd.h>
#endif
-
#include <string>
#include <string.h>
-#include "application_manager/application_manager_impl.h"
+#include "application_manager/application_manager.h"
#include "application_manager/mobile_command_factory.h"
#include "application_manager/application_impl.h"
#include "smart_objects/smart_object.h"
#include "interfaces/MOBILE_API.h"
#include "utils/file_system.h"
#include "utils/logger.h"
-
+#include "media_manager/media_manager_settings.h"
#include "media_manager/audio/audio_stream_sender_thread.h"
#include "application_manager/smart_object_keys.h"
#include "application_manager/message.h"
@@ -57,20 +55,22 @@ using sync_primitives::AutoLock;
const int32_t AudioStreamSenderThread::kAudioPassThruTimeout = 1;
const uint32_t kMqueueMessageSize = 4095;
-CREATE_LOGGERPTR_GLOBAL(logger_, "AudioPassThruThread")
+CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManager")
AudioStreamSenderThread::AudioStreamSenderThread(
- const std::string fileName, uint32_t session_key)
- : session_key_(session_key),
- fileName_(fileName),
- shouldBeStoped_(false),
- shouldBeStoped_lock_(),
- shouldBeStoped_cv_() {
+ const std::string& fileName,
+ uint32_t session_key,
+ application_manager::ApplicationManager& app_mngr)
+ : session_key_(session_key)
+ , fileName_(fileName)
+ , shouldBeStoped_(false)
+ , shouldBeStoped_lock_()
+ , shouldBeStoped_cv_()
+ , application_manager_(app_mngr) {
LOG4CXX_AUTO_TRACE(logger_);
}
-AudioStreamSenderThread::~AudioStreamSenderThread() {
-}
+AudioStreamSenderThread::~AudioStreamSenderThread() {}
void AudioStreamSenderThread::threadMain() {
LOG4CXX_AUTO_TRACE(logger_);
@@ -82,7 +82,6 @@ void AudioStreamSenderThread::threadMain() {
shouldBeStoped_cv_.WaitFor(auto_lock, kAudioPassThruTimeout * 1000);
sendAudioChunkToMobile();
}
-
}
void AudioStreamSenderThread::sendAudioChunkToMobile() {
@@ -93,29 +92,28 @@ void AudioStreamSenderThread::sendAudioChunkToMobile() {
std::vector<uint8_t>::iterator to;
if (!file_system::ReadBinaryFile(fileName_, binaryData)) {
- LOG4CXX_ERROR_EXT(logger_, "Unable to read file." << fileName_);
+ LOG4CXX_ERROR(logger_, "Unable to read file." << fileName_);
return;
}
if (binaryData.empty()) {
- LOG4CXX_ERROR_EXT(logger_, "Binary data is empty.");
+ LOG4CXX_ERROR(logger_, "Binary data is empty.");
return;
}
- LOG4CXX_INFO_EXT(logger_, "offset = " << offset_);
+ LOG4CXX_INFO(logger_, "offset = " << offset_);
from = binaryData.begin() + offset_;
to = binaryData.end();
if (from < binaryData.end() /*from != binaryData.end()*/) {
- LOG4CXX_INFO_EXT(logger_, "from != binaryData.end()");
+ LOG4CXX_INFO(logger_, "from != binaryData.end()");
offset_ = offset_ + to - from;
std::vector<uint8_t> data(from, to);
- application_manager::ApplicationManagerImpl::instance()->
- SendAudioPassThroughNotification(session_key_, data);
+ application_manager_.SendAudioPassThroughNotification(session_key_, data);
binaryData.clear();
}
#if !defined(EXTENDED_MEDIA_MODE)
diff --git a/src/components/media_manager/src/audio/file_audio_streamer_adapter.cc b/src/components/media_manager/src/audio/file_audio_streamer_adapter.cc
new file mode 100644
index 0000000000..f632fa81af
--- /dev/null
+++ b/src/components/media_manager/src/audio/file_audio_streamer_adapter.cc
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2014-2015, 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 "media_manager/audio/file_audio_streamer_adapter.h"
+
+namespace media_manager {
+
+FileAudioStreamerAdapter::FileAudioStreamerAdapter(
+ const std::string& audio_stream_file, const std::string& app_storage_folder)
+ : FileStreamerAdapter(audio_stream_file, app_storage_folder) {}
+
+FileAudioStreamerAdapter::~FileAudioStreamerAdapter() {}
+
+} // namespace media_manager
diff --git a/src/components/media_manager/src/audio/from_mic_recorder_adapter.cc b/src/components/media_manager/src/audio/from_mic_recorder_adapter.cc
index ef9d5b8de6..d9735fcbbc 100644
--- a/src/components/media_manager/src/audio/from_mic_recorder_adapter.cc
+++ b/src/components/media_manager/src/audio/from_mic_recorder_adapter.cc
@@ -38,15 +38,13 @@
namespace media_manager {
-CREATE_LOGGERPTR_GLOBAL(logger_, "FromMicRecorderAdapter")
+CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManager")
FromMicRecorderAdapter::FromMicRecorderAdapter()
- : recorder_thread_(NULL)
- , output_file_("default_recorded_audio.wav")
- , kDefaultDuration(1000)
- , duration_(kDefaultDuration) {
-
-}
+ : recorder_thread_(NULL)
+ , output_file_("default_recorded_audio.wav")
+ , kDefaultDuration(1000)
+ , duration_(kDefaultDuration) {}
FromMicRecorderAdapter::~FromMicRecorderAdapter() {
LOG4CXX_AUTO_TRACE(logger_);
@@ -60,18 +58,16 @@ FromMicRecorderAdapter::~FromMicRecorderAdapter() {
void FromMicRecorderAdapter::StartActivity(int32_t application_key) {
LOG4CXX_DEBUG(logger_, "Start with app " << application_key);
if (application_key == current_application_) {
- LOG4CXX_WARN(logger_, "Running recording from mic for "
- << current_application_);
+ LOG4CXX_WARN(logger_,
+ "Running recording from mic for " << current_application_);
return;
}
-// Todd: No gstreamer recorder thread
+ // Todd: No gstreamer recorder thread
if (!recorder_thread_) {
FromMicToFileRecorderThread* thread_delegate =
- new FromMicToFileRecorderThread(
- output_file_, duration_);
- recorder_thread_ = threads::CreateThread("MicrophoneRec",
- thread_delegate);
+ new FromMicToFileRecorderThread(output_file_, duration_);
+ recorder_thread_ = threads::CreateThread("MicrophoneRec", thread_delegate);
}
if (NULL != recorder_thread_) {
@@ -81,11 +77,11 @@ void FromMicRecorderAdapter::StartActivity(int32_t application_key) {
}
void FromMicRecorderAdapter::StopActivity(int32_t application_key) {
- LOG4CXX_INFO(logger_, "FromMicRecorderAdapter::StopActivity "
- << application_key);
+ LOG4CXX_INFO(logger_,
+ "FromMicRecorderAdapter::StopActivity " << application_key);
if (application_key != current_application_) {
- LOG4CXX_WARN(logger_, "Running activity on other app key "
- << current_application_);
+ LOG4CXX_WARN(logger_,
+ "Running activity on other app key " << current_application_);
return;
}
@@ -98,8 +94,8 @@ void FromMicRecorderAdapter::StopActivity(int32_t application_key) {
current_application_ = 0;
}
-bool FromMicRecorderAdapter::is_app_performing_activity(int32_t
- application_key) {
+bool FromMicRecorderAdapter::is_app_performing_activity(
+ int32_t application_key) const {
return (application_key == current_application_);
}
diff --git a/src/components/media_manager/src/audio/from_mic_recorder_listener.cc b/src/components/media_manager/src/audio/from_mic_recorder_listener.cc
index 3718e82c60..a02ec17f90 100644
--- a/src/components/media_manager/src/audio/from_mic_recorder_listener.cc
+++ b/src/components/media_manager/src/audio/from_mic_recorder_listener.cc
@@ -37,13 +37,12 @@
namespace media_manager {
-CREATE_LOGGERPTR_GLOBAL(logger_, "FromMicRecorderListener")
+CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManager")
FromMicRecorderListener::FromMicRecorderListener(
- const std::string& file_name)
- : reader_(NULL)
- , file_name_(file_name) {
-}
+ const std::string& file_name,
+ application_manager::ApplicationManager& app_mngr)
+ : reader_(NULL), file_name_(file_name), application_manager_(app_mngr) {}
FromMicRecorderListener::~FromMicRecorderListener() {
LOG4CXX_AUTO_TRACE(logger_);
@@ -54,25 +53,22 @@ FromMicRecorderListener::~FromMicRecorderListener() {
}
}
-void FromMicRecorderListener::OnDataReceived(
- int32_t application_key,
- const DataForListener& data) {
-}
+void FromMicRecorderListener::OnDataReceived(int32_t application_key,
+ const DataForListener& data) {}
-void FromMicRecorderListener::OnErrorReceived(
- int32_t application_key,
- const DataForListener& data) {
-}
+void FromMicRecorderListener::OnErrorReceived(int32_t application_key,
+ const DataForListener& data) {}
void FromMicRecorderListener::OnActivityStarted(int32_t application_key) {
- LOG4CXX_INFO(logger_, "FromMicRecorderListener::OnActivityStarted "
- << application_key);
+ LOG4CXX_INFO(logger_,
+ "FromMicRecorderListener::OnActivityStarted "
+ << application_key);
if (application_key == current_application_) {
return;
}
if (!reader_) {
- AudioStreamSenderThread* thread_delegate =
- new AudioStreamSenderThread(file_name_, application_key);
+ AudioStreamSenderThread* thread_delegate = new AudioStreamSenderThread(
+ file_name_, application_key, application_manager_);
reader_ = threads::CreateThread("RecorderSender", thread_delegate);
}
if (reader_) {
@@ -82,11 +78,12 @@ void FromMicRecorderListener::OnActivityStarted(int32_t application_key) {
}
void FromMicRecorderListener::OnActivityEnded(int32_t application_key) {
- LOG4CXX_INFO(logger_, "FromMicRecorderListener::OnActivityEnded "
- << application_key);
+ LOG4CXX_INFO(logger_,
+ "FromMicRecorderListener::OnActivityEnded " << application_key);
if (application_key != current_application_) {
- LOG4CXX_WARN(logger_, "Not performing activity on " << application_key
- << " but on " << current_application_);
+ LOG4CXX_WARN(logger_,
+ "Not performing activity on " << application_key << " but on "
+ << current_application_);
return;
}
if (reader_) {
diff --git a/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc b/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc
index 88c358a494..0239795d75 100644
--- a/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc
+++ b/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc
@@ -37,19 +37,19 @@
namespace media_manager {
-CREATE_LOGGERPTR_GLOBAL(logger_, "FromMicToFileRecorderThread")
+CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManager")
GMainLoop* FromMicToFileRecorderThread::loop = NULL;
FromMicToFileRecorderThread::FromMicToFileRecorderThread(
- const std::string& output_file, int32_t duration)
- : threads::ThreadDelegate(),
- argc_(5),
- argv_(NULL),
- oKey_("-o"),
- tKey_("-t"),
- sleepThread_(NULL),
- outputFileName_(output_file) {
+ const std::string& output_file, int32_t duration)
+ : threads::ThreadDelegate()
+ , argc_(5)
+ , argv_(NULL)
+ , oKey_("-o")
+ , tKey_("-t")
+ , sleepThread_(NULL)
+ , outputFileName_(output_file) {
LOG4CXX_AUTO_TRACE(logger_);
set_record_duration(duration);
}
@@ -64,7 +64,7 @@ FromMicToFileRecorderThread::~FromMicToFileRecorderThread() {
}
void FromMicToFileRecorderThread::set_output_file(
- const std::string& output_file) {
+ const std::string& output_file) {
LOG4CXX_AUTO_TRACE(logger_);
outputFileName_ = output_file;
}
@@ -80,7 +80,7 @@ void FromMicToFileRecorderThread::set_record_duration(int32_t duration) {
void FromMicToFileRecorderThread::initArgs() {
LOG4CXX_AUTO_TRACE(logger_);
- argv_ = new gchar*[argc_];
+ argv_ = new gchar* [argc_];
argv_[0] = new gchar[14];
argv_[1] = new gchar[3];
@@ -114,20 +114,29 @@ void FromMicToFileRecorderThread::threadMain() {
gint duration = -1;
GOptionContext* context = NULL;
GError* err = NULL;
- GOptionEntry entries[] = { {
- "device", 'd', 0, G_OPTION_ARG_FILENAME, &device,
- "device file (Default: hw:0,0)", "SRC"
- }, {
- "output", 'o', 0, G_OPTION_ARG_FILENAME, &outfile,
- "save output of the stream to DEST", "DEST"
- }, {
- "duration", 't', 0, G_OPTION_ARG_INT, &duration,
- "length of time in seconds to capture", "int32_t"
- }, {
- NULL
- }
- };
-#ifndef GLIB_VERSION_2_32 // g_thread_init() does nothing since 2.32
+ GOptionEntry entries[] = {{"device",
+ 'd',
+ 0,
+ G_OPTION_ARG_FILENAME,
+ &device,
+ "device file (Default: hw:0,0)",
+ "SRC"},
+ {"output",
+ 'o',
+ 0,
+ G_OPTION_ARG_FILENAME,
+ &outfile,
+ "save output of the stream to DEST",
+ "DEST"},
+ {"duration",
+ 't',
+ 0,
+ G_OPTION_ARG_INT,
+ &duration,
+ "length of time in seconds to capture",
+ "int32_t"},
+ {NULL}};
+#ifndef GLIB_VERSION_2_32 // g_thread_init() does nothing since 2.32
if (!g_thread_supported()) {
g_thread_init(NULL);
}
@@ -156,10 +165,10 @@ void FromMicToFileRecorderThread::threadMain() {
// Set up error handling
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
- gst_bus_add_watch(bus,
- reinterpret_cast<int32_t (*)(_GstBus*, _GstMessage*, void*)>
- (recvmsg),
- NULL);
+ gst_bus_add_watch(
+ bus,
+ reinterpret_cast<int32_t (*)(_GstBus*, _GstMessage*, void*)>(recvmsg),
+ NULL);
gst_object_unref(bus);
// Create all of the elements to be added to the pipeline
@@ -199,7 +208,7 @@ void FromMicToFileRecorderThread::threadMain() {
g_option_context_free(context);
if (argv_) {
- delete [] argv_;
+ delete[] argv_;
argv_ = NULL;
}
return;
@@ -213,7 +222,8 @@ void FromMicToFileRecorderThread::threadMain() {
timeout.pipeline = pipeline;
timeout.duration = duration;
- sleepThread_ = threads::CreateThread("SleepThread", new SleepThreadDelegate(timeout));
+ sleepThread_ =
+ threads::CreateThread("SleepThread", new SleepThreadDelegate(timeout));
sleepThread_->start();
}
@@ -229,18 +239,16 @@ void FromMicToFileRecorderThread::threadMain() {
g_option_context_free(context);
if (argv_) {
- delete [] argv_;
+ delete[] argv_;
argv_ = NULL;
}
loop = NULL;
}
-FromMicToFileRecorderThread::SleepThreadDelegate::SleepThreadDelegate(GstTimeout
- timeout)
- : threads::ThreadDelegate(),
- timeout_(timeout) {
-}
+FromMicToFileRecorderThread::SleepThreadDelegate::SleepThreadDelegate(
+ GstTimeout timeout)
+ : threads::ThreadDelegate(), timeout_(timeout) {}
void FromMicToFileRecorderThread::SleepThreadDelegate::threadMain() {
LOG4CXX_TRACE(logger_, "Sleep for " << timeout_.duration << " seconds");
diff --git a/src/components/media_manager/src/audio/pipe_audio_streamer_adapter.cc b/src/components/media_manager/src/audio/pipe_audio_streamer_adapter.cc
index 5c120397cf..2220c08b26 100644
--- a/src/components/media_manager/src/audio/pipe_audio_streamer_adapter.cc
+++ b/src/components/media_manager/src/audio/pipe_audio_streamer_adapter.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, Ford Motor Company
+ * Copyright (c) 2014-2015, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,22 +31,14 @@
*/
#include "media_manager/audio/pipe_audio_streamer_adapter.h"
-#include "config_profile/profile.h"
-#include "utils/logger.h"
namespace media_manager {
-CREATE_LOGGERPTR_GLOBAL(logger, "PipeAudioStreamerAdapter")
+PipeAudioStreamerAdapter::PipeAudioStreamerAdapter(
+ const std::string& named_audio_pipe_path,
+ const std::string& app_storage_folder)
+ : PipeStreamerAdapter(named_audio_pipe_path, app_storage_folder) {}
-PipeAudioStreamerAdapter::PipeAudioStreamerAdapter() {
- LOG4CXX_AUTO_TRACE(logger);
- named_pipe_path_ = profile::Profile::instance()->named_audio_pipe_path();
-
- Init();
-}
-
-PipeAudioStreamerAdapter::~PipeAudioStreamerAdapter() {
- LOG4CXX_INFO(logger, "PipeAudioStreamerAdapter::~PipeAudioStreamerAdapter");
-}
+PipeAudioStreamerAdapter::~PipeAudioStreamerAdapter() {}
} // namespace media_manager
diff --git a/src/components/media_manager/src/audio/socket_audio_streamer_adapter.cc b/src/components/media_manager/src/audio/socket_audio_streamer_adapter.cc
index 06dc877d89..429fab01b3 100644
--- a/src/components/media_manager/src/audio/socket_audio_streamer_adapter.cc
+++ b/src/components/media_manager/src/audio/socket_audio_streamer_adapter.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 Ford Motor Company
+ * Copyright (c) 2014-2015, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,22 +30,24 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "config_profile/profile.h"
+#include <string>
#include "media_manager/audio/socket_audio_streamer_adapter.h"
-#include "utils/logger.h"
+
+namespace {
+const std::string kHeader =
+ "HTTP/1.1 200 OK\r\n"
+ "Connection: Keep-Alive\r\n"
+ "Keep-Alive: timeout=15, max=300\r\n"
+ "Server: SDL\r\n"
+ "Content-Type: video/mp4\r\n\r\n";
+}
namespace media_manager {
-CREATE_LOGGERPTR_GLOBAL(logger, "SocketAudioStreamerAdapter")
+SocketAudioStreamerAdapter::SocketAudioStreamerAdapter(
+ const std::string& server_address, uint16_t audio_streaming_port)
+ : SocketStreamerAdapter(server_address, audio_streaming_port, kHeader) {}
-SocketAudioStreamerAdapter::SocketAudioStreamerAdapter() {
- LOG4CXX_AUTO_TRACE(logger);
- port_ = profile::Profile::instance()->audio_streaming_port();
- ip_ = profile::Profile::instance()->server_address();
+SocketAudioStreamerAdapter::~SocketAudioStreamerAdapter() {}
- Init();
-}
-
-SocketAudioStreamerAdapter::~SocketAudioStreamerAdapter() {
-}
} // namespace media_manager
diff --git a/src/components/media_manager/src/file_streamer_adapter.cc b/src/components/media_manager/src/file_streamer_adapter.cc
new file mode 100644
index 0000000000..3418f7d963
--- /dev/null
+++ b/src/components/media_manager/src/file_streamer_adapter.cc
@@ -0,0 +1,102 @@
+/*
+ * 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 "utils/logger.h"
+#include "utils/file_system.h"
+#include "media_manager/file_streamer_adapter.h"
+
+namespace media_manager {
+
+CREATE_LOGGERPTR_GLOBAL(logger_, "FileStreamerAdapter")
+
+FileStreamerAdapter::FileStreamerAdapter(const std::string& file_name,
+ const std::string& app_storage_folder)
+ : StreamerAdapter(new FileStreamer(this, file_name, app_storage_folder)) {}
+
+FileStreamerAdapter::~FileStreamerAdapter() {}
+
+FileStreamerAdapter::FileStreamer::FileStreamer(
+ FileStreamerAdapter* const adapter,
+ const std::string& file_name,
+ const std::string& app_storage_folder)
+ : Streamer(adapter)
+ , file_name_(file_name)
+ , app_storage_folder_(app_storage_folder)
+ , file_stream_(NULL) {}
+
+FileStreamerAdapter::FileStreamer::~FileStreamer() {}
+
+bool FileStreamerAdapter::FileStreamer::Connect() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ if (!file_system::CreateDirectoryRecursively(app_storage_folder_)) {
+ LOG4CXX_ERROR(logger_, "Cannot create app folder");
+ return false;
+ }
+
+ file_stream_ = file_system::Open(file_name_);
+ if (!file_stream_) {
+ LOG4CXX_ERROR(logger_, "Cannot open file stream " << file_name_);
+ return false;
+ }
+
+ LOG4CXX_INFO(logger_, "File " << file_name_ << " was successfuly opened");
+ return true;
+}
+
+void FileStreamerAdapter::FileStreamer::Disconnect() {
+ LOG4CXX_AUTO_TRACE(logger_);
+ if (file_stream_) {
+ file_system::Close(file_stream_);
+ delete file_stream_;
+ file_stream_ = NULL;
+ }
+ file_system::DeleteFile(file_name_);
+}
+
+bool FileStreamerAdapter::FileStreamer::Send(
+ protocol_handler::RawMessagePtr msg) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ if (!file_stream_) {
+ LOG4CXX_ERROR(logger_, "File stream not found " << file_name_);
+ return false;
+ }
+
+ if (!file_system::Write(file_stream_, msg->data(), msg->data_size())) {
+ LOG4CXX_ERROR(logger_, "Failed writing data to file " << file_name_);
+ return false;
+ }
+
+ LOG4CXX_INFO(logger_, "Streamer::sent " << msg->data_size());
+ return true;
+}
+
+} // namespace media_manager
diff --git a/src/components/media_manager/src/media_adapter_impl.cc b/src/components/media_manager/src/media_adapter_impl.cc
index 257801ffd8..cf15a7af97 100644
--- a/src/components/media_manager/src/media_adapter_impl.cc
+++ b/src/components/media_manager/src/media_adapter_impl.cc
@@ -35,11 +35,9 @@
namespace media_manager {
-CREATE_LOGGERPTR_GLOBAL(logger_, "MediaAdapterImpl")
+CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManager")
-MediaAdapterImpl::MediaAdapterImpl()
- : current_application_(0) {
-}
+MediaAdapterImpl::MediaAdapterImpl() : current_application_(0) {}
MediaAdapterImpl::~MediaAdapterImpl() {
media_listeners_.clear();
diff --git a/src/components/media_manager/src/media_manager_impl.cc b/src/components/media_manager/src/media_manager_impl.cc
index 61b2c5bb92..e531894b27 100644
--- a/src/components/media_manager/src/media_manager_impl.cc
+++ b/src/components/media_manager/src/media_manager_impl.cc
@@ -30,13 +30,12 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "config_profile/profile.h"
#include "media_manager/media_manager_impl.h"
#include "media_manager/audio/from_mic_recorder_listener.h"
#include "media_manager/streamer_listener.h"
#include "application_manager/message_helper.h"
#include "application_manager/application.h"
-#include "application_manager/application_manager_impl.h"
+#include "application_manager/application_manager.h"
#include "application_manager/application_impl.h"
#include "protocol_handler/protocol_handler.h"
#include "utils/file_system.h"
@@ -50,19 +49,22 @@
#include "media_manager/audio/socket_audio_streamer_adapter.h"
#include "media_manager/video/pipe_video_streamer_adapter.h"
#include "media_manager/audio/pipe_audio_streamer_adapter.h"
-#include "media_manager/video/video_stream_to_file_adapter.h"
+#include "media_manager/video/file_video_streamer_adapter.h"
+#include "media_manager/audio/file_audio_streamer_adapter.h"
+#include "media_manager/media_manager_settings.h"
namespace media_manager {
-using profile::Profile;
-using timer::TimerThread;
+CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManager")
-CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManagerImpl")
-
-MediaManagerImpl::MediaManagerImpl()
- : protocol_handler_(NULL)
- , a2dp_player_(NULL)
- , from_mic_recorder_(NULL) {
+MediaManagerImpl::MediaManagerImpl(
+ application_manager::ApplicationManager& application_manager,
+ const MediaManagerSettings& settings)
+ : settings_(settings)
+ , protocol_handler_(NULL)
+ , a2dp_player_(NULL)
+ , from_mic_recorder_(NULL)
+ , application_manager_(application_manager) {
Init();
}
@@ -78,36 +80,69 @@ MediaManagerImpl::~MediaManagerImpl() {
}
}
+#ifdef BUILD_TESTS
+void MediaManagerImpl::set_mock_a2dp_player(MediaAdapter* media_adapter) {
+ a2dp_player_ = media_adapter;
+}
+
+void MediaManagerImpl::set_mock_mic_listener(MediaListenerPtr media_listener) {
+ from_mic_listener_ = media_listener;
+}
+
+#ifdef EXTENDED_MEDIA_MODE
+void MediaManagerImpl::set_mock_mic_recorder(MediaAdapterImpl* media_adapter) {
+ from_mic_recorder_ = media_adapter;
+}
+
+#endif // EXTENDED_MEDIA_MODE
+
+void MediaManagerImpl::set_mock_streamer(protocol_handler::ServiceType stype,
+ MediaAdapterImpl* mock_stream) {
+ streamer_[stype] = mock_stream;
+}
+
+void MediaManagerImpl::set_mock_streamer_listener(
+ protocol_handler::ServiceType stype, MediaAdapterListener* mock_stream) {
+ streamer_listener_[stype] = mock_stream;
+}
+
+#endif // BUILD_TESTS
+
void MediaManagerImpl::Init() {
using namespace protocol_handler;
LOG4CXX_INFO(logger_, "MediaManagerImpl::Init()");
#if defined(EXTENDED_MEDIA_MODE)
LOG4CXX_INFO(logger_, "Called Init with default configuration.");
- a2dp_player_ = new A2DPSourcePlayerAdapter();
+ a2dp_player_ =
+ new A2DPSourcePlayerAdapter(protocol_handler_->get_session_observer());
from_mic_recorder_ = new FromMicRecorderAdapter();
#endif
- if ("socket" == profile::Profile::instance()->video_server_type()) {
- streamer_[ServiceType::kMobileNav] = new SocketVideoStreamerAdapter();
- } else if ("pipe" == profile::Profile::instance()->video_server_type()) {
- streamer_[ServiceType::kMobileNav] = new PipeVideoStreamerAdapter();
- } else if ("file" == profile::Profile::instance()->video_server_type()) {
- streamer_[ServiceType::kMobileNav] = new VideoStreamToFileAdapter(
- profile::Profile::instance()->video_stream_file());
+ if ("socket" == settings().video_server_type()) {
+ streamer_[ServiceType::kMobileNav] = new SocketVideoStreamerAdapter(
+ settings().server_address(), settings().video_streaming_port());
+ } else if ("pipe" == settings().video_server_type()) {
+ streamer_[ServiceType::kMobileNav] = new PipeVideoStreamerAdapter(
+ settings().named_video_pipe_path(), settings().app_storage_folder());
+ } else if ("file" == settings().video_server_type()) {
+ streamer_[ServiceType::kMobileNav] = new FileVideoStreamerAdapter(
+ settings().video_stream_file(), settings().app_storage_folder());
}
- if ("socket" == profile::Profile::instance()->audio_server_type()) {
- streamer_[ServiceType::kAudio] = new SocketAudioStreamerAdapter();
- } else if ("pipe" == profile::Profile::instance()->audio_server_type()) {
- streamer_[ServiceType::kAudio] = new PipeAudioStreamerAdapter();
- } else if ("file" == profile::Profile::instance()->audio_server_type()) {
- streamer_[ServiceType::kAudio] = new VideoStreamToFileAdapter(
- profile::Profile::instance()->audio_stream_file());
+ if ("socket" == settings().audio_server_type()) {
+ streamer_[ServiceType::kAudio] = new SocketAudioStreamerAdapter(
+ settings().server_address(), settings().audio_streaming_port());
+ } else if ("pipe" == settings().audio_server_type()) {
+ streamer_[ServiceType::kAudio] = new PipeAudioStreamerAdapter(
+ settings().named_audio_pipe_path(), settings().app_storage_folder());
+ } else if ("file" == settings().audio_server_type()) {
+ streamer_[ServiceType::kAudio] = new FileAudioStreamerAdapter(
+ settings().audio_stream_file(), settings().app_storage_folder());
}
- streamer_listener_[ServiceType::kMobileNav] = new StreamerListener();
- streamer_listener_[ServiceType::kAudio] = new StreamerListener();
+ streamer_listener_[ServiceType::kMobileNav] = new StreamerListener(*this);
+ streamer_listener_[ServiceType::kAudio] = new StreamerListener(*this);
if (streamer_[ServiceType::kMobileNav]) {
streamer_[ServiceType::kMobileNav]->AddListener(
@@ -134,27 +169,25 @@ void MediaManagerImpl::StopA2DPSource(int32_t application_key) {
}
}
-void MediaManagerImpl::StartMicrophoneRecording(
- int32_t application_key,
- const std::string& output_file,
- int32_t duration) {
- LOG4CXX_INFO(logger_, "MediaManagerImpl::StartMicrophoneRecording to "
- << output_file);
+void MediaManagerImpl::StartMicrophoneRecording(int32_t application_key,
+ const std::string& output_file,
+ int32_t duration) {
+ LOG4CXX_INFO(logger_,
+ "MediaManagerImpl::StartMicrophoneRecording to " << output_file);
application_manager::ApplicationSharedPtr app =
- application_manager::ApplicationManagerImpl::instance()->
- application(application_key);
- std::string file_path =
- profile::Profile::instance()->app_storage_folder();
+ application_manager_.application(application_key);
+ std::string file_path = settings().app_storage_folder();
file_path += "/";
file_path += output_file;
- from_mic_listener_ = new FromMicRecorderListener(file_path);
-#if defined(EXTENDED_MEDIA_MODE)
+ from_mic_listener_ =
+ new FromMicRecorderListener(file_path, application_manager_);
+#ifdef EXTENDED_MEDIA_MODE
if (from_mic_recorder_) {
from_mic_recorder_->AddListener(from_mic_listener_);
(static_cast<FromMicRecorderAdapter*>(from_mic_recorder_))
- ->set_output_file(file_path);
+ ->set_output_file(file_path);
(static_cast<FromMicRecorderAdapter*>(from_mic_recorder_))
- ->set_duration(duration);
+ ->set_duration(duration);
from_mic_recorder_->StartActivity(application_key);
}
#else
@@ -162,25 +195,23 @@ void MediaManagerImpl::StartMicrophoneRecording(
LOG4CXX_INFO(logger_, "File " << output_file << " exists, removing");
if (file_system::DeleteFile(file_path)) {
LOG4CXX_INFO(logger_, "File " << output_file << " removed");
- }
- else {
+ } else {
LOG4CXX_WARN(logger_, "Could not remove file " << output_file);
}
}
- const std::string record_file_source =
- profile::Profile::instance()->app_resourse_folder() + "/" +
- profile::Profile::instance()->recording_file_source();
+ const std::string record_file_source = settings().app_resource_folder() +
+ "/" +
+ settings().recording_file_source();
std::vector<uint8_t> buf;
if (file_system::ReadBinaryFile(record_file_source, buf)) {
if (file_system::Write(file_path, buf)) {
LOG4CXX_INFO(logger_,
- "File " << record_file_source << " copied to " << output_file);
- }
- else {
+ "File " << record_file_source << " copied to "
+ << output_file);
+ } else {
LOG4CXX_WARN(logger_, "Could not write to file " << output_file);
}
- }
- else {
+ } else {
LOG4CXX_WARN(logger_, "Could not read file " << record_file_source);
}
#endif
@@ -223,7 +254,7 @@ void MediaManagerImpl::StopStreaming(
}
void MediaManagerImpl::SetProtocolHandler(
- protocol_handler::ProtocolHandler* protocol_handler) {
+ protocol_handler::ProtocolHandler* protocol_handler) {
protocol_handler_ = protocol_handler;
}
@@ -238,21 +269,19 @@ void MediaManagerImpl::OnMessageReceived(
const ServiceType service_type = message->service_type();
if (Compare<ServiceType, NEQ, ALL>(
- service_type, ServiceType::kMobileNav, ServiceType::kAudio)) {
+ service_type, ServiceType::kMobileNav, ServiceType::kAudio)) {
LOG4CXX_DEBUG(logger_, "Unsupported service type in MediaManager");
return;
}
- 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.");
+ if (!application_manager_.CanAppStream(streaming_app_id, service_type)) {
+ application_manager_.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);
+ ApplicationSharedPtr app = application_manager_.application(streaming_app_id);
if (app) {
app->WakeUpStreaming(service_type);
streamer_[service_type]->SendData(streaming_app_id, message);
@@ -260,15 +289,17 @@ void MediaManagerImpl::OnMessageReceived(
}
void MediaManagerImpl::OnMobileMessageSent(
- const ::protocol_handler::RawMessagePtr message) {
-}
+ const ::protocol_handler::RawMessagePtr message) {}
void MediaManagerImpl::FramesProcessed(int32_t application_key,
int32_t frame_number) {
if (protocol_handler_) {
- protocol_handler_->SendFramesNumber(application_key,
- frame_number);
+ protocol_handler_->SendFramesNumber(application_key, frame_number);
}
}
+const MediaManagerSettings& MediaManagerImpl::settings() const {
+ return settings_;
+}
+
} // namespace media_manager
diff --git a/src/components/media_manager/src/pipe_streamer_adapter.cc b/src/components/media_manager/src/pipe_streamer_adapter.cc
index 5990428c68..8bf14a546e 100644
--- a/src/components/media_manager/src/pipe_streamer_adapter.cc
+++ b/src/components/media_manager/src/pipe_streamer_adapter.cc
@@ -36,195 +36,89 @@
#include <unistd.h>
#include "utils/logger.h"
#include "utils/file_system.h"
-#include "config_profile/profile.h"
#include "media_manager/pipe_streamer_adapter.h"
namespace media_manager {
CREATE_LOGGERPTR_GLOBAL(logger_, "PipeStreamerAdapter")
-PipeStreamerAdapter::PipeStreamerAdapter()
- : is_ready_(false),
- thread_(threads::CreateThread("PipeStreamer", new Streamer(this))),
- messages_() {
- LOG4CXX_AUTO_TRACE(logger_);
-}
-
-PipeStreamerAdapter::~PipeStreamerAdapter() {
- LOG4CXX_AUTO_TRACE(logger_);
-
- if ((0 != current_application_ ) && (is_ready_)) {
- StopActivity(current_application_);
- }
-
- thread_->join();
- delete thread_->delegate();
- threads::DeleteThread(thread_);
-}
-
-void PipeStreamerAdapter::SendData(
- int32_t application_key,
- const ::protocol_handler::RawMessagePtr message) {
- LOG4CXX_AUTO_TRACE(logger_);
-
- if (application_key != current_application_) {
- LOG4CXX_WARN(logger_, "Wrong application " << application_key);
+PipeStreamerAdapter::PipeStreamerAdapter(const std::string& named_pipe_path,
+ const std::string& app_storage_folder)
+ : StreamerAdapter(
+ new PipeStreamer(this, named_pipe_path, app_storage_folder)) {}
+
+PipeStreamerAdapter::~PipeStreamerAdapter() {}
+
+PipeStreamerAdapter::PipeStreamer::PipeStreamer(
+ PipeStreamerAdapter* const adapter,
+ const std::string& named_pipe_path,
+ const std::string& app_storage_folder)
+ : Streamer(adapter)
+ , named_pipe_path_(named_pipe_path)
+ , app_storage_folder_(app_storage_folder)
+ , pipe_fd_(0) {
+ if (!file_system::CreateDirectoryRecursively(app_storage_folder_)) {
+ LOG4CXX_ERROR(logger_,
+ "Cannot create app storage folder " << app_storage_folder_);
return;
}
-
- if (is_ready_) {
- messages_.push(message);
+ if ((mkfifo(named_pipe_path_.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) <
+ 0) &&
+ (errno != EEXIST)) {
+ LOG4CXX_ERROR(logger_, "Cannot create pipe " << named_pipe_path_);
+ } else {
+ LOG4CXX_INFO(logger_,
+ "Pipe " << named_pipe_path_ << " was successfully created");
}
}
-
-void PipeStreamerAdapter::StartActivity(int32_t application_key) {
- LOG4CXX_AUTO_TRACE(logger_);
-
- if (application_key == current_application_) {
- LOG4CXX_WARN(logger_, "Already started activity for " << application_key);
- return;
+PipeStreamerAdapter::PipeStreamer::~PipeStreamer() {
+ if (0 == unlink(named_pipe_path_.c_str())) {
+ LOG4CXX_INFO(logger_, "Pipe " << named_pipe_path_ << " was removed");
+ } else {
+ LOG4CXX_ERROR(logger_, "Error removing pipe " << named_pipe_path_);
}
-
- current_application_ = application_key;
- is_ready_ = true;
-
- for (std::set<MediaListenerPtr>::iterator it = media_listeners_.begin();
- media_listeners_.end() != it;
- ++it) {
- (*it)->OnActivityStarted(application_key);
- }
-
- LOG4CXX_DEBUG(logger_, "Pipe was opened for writing " << named_pipe_path_);
}
-void PipeStreamerAdapter::StopActivity(int32_t application_key) {
+bool PipeStreamerAdapter::PipeStreamer::Connect() {
LOG4CXX_AUTO_TRACE(logger_);
- if (application_key != current_application_) {
- LOG4CXX_WARN(logger_, "Not performing activity for " << application_key);
- return;
- }
-
- is_ready_ = false;
- current_application_ = 0;
-
- messages_.Reset();
-
- for (std::set<MediaListenerPtr>::iterator it = media_listeners_.begin();
- media_listeners_.end() != it;
- ++it) {
- (*it)->OnActivityEnded(application_key);
- }
-}
-
-bool PipeStreamerAdapter::is_app_performing_activity( int32_t application_key) {
- return (application_key == current_application_);
-}
-
-void PipeStreamerAdapter::Init() {
- LOG4CXX_AUTO_TRACE(logger_);
- if (thread_->is_running()) {
- thread_->stop();
- thread_->join();
+ pipe_fd_ = open(named_pipe_path_.c_str(), O_RDWR, 0);
+ if (-1 == pipe_fd_) {
+ LOG4CXX_ERROR(logger_, "Cannot open pipe for writing " << named_pipe_path_);
+ return false;
}
- LOG4CXX_DEBUG(logger_, "Start sending thread");
- const size_t kStackSize = 16384;
- thread_->start(threads::ThreadOptions(kStackSize));
-}
-PipeStreamerAdapter::Streamer::Streamer(
- PipeStreamerAdapter* server)
- : server_(server),
- pipe_fd_(0),
- stop_flag_(false) {
+ LOG4CXX_INFO(logger_,
+ "Pipe " << named_pipe_path_
+ << " was successfuly opened for writing");
+ return true;
}
-PipeStreamerAdapter::Streamer::~Streamer() {
- server_ = NULL;
-}
-
-void PipeStreamerAdapter::Streamer::threadMain() {
+void PipeStreamerAdapter::PipeStreamer::Disconnect() {
LOG4CXX_AUTO_TRACE(logger_);
-
- open();
-
- while (!stop_flag_) {
- while (!server_->messages_.empty()) {
- ::protocol_handler::RawMessagePtr msg = server_->messages_.pop();
- if (!msg) {
- LOG4CXX_ERROR(logger_, "Null pointer message");
- continue;
- }
-
- ssize_t ret = write(pipe_fd_, msg.get()->data(),
- msg.get()->data_size());
-
- if (ret == -1) {
- LOG4CXX_ERROR(logger_, "Failed writing data to pipe "
- << server_->named_pipe_path_);
-
- std::set<MediaListenerPtr>::iterator it =
- server_->media_listeners_.begin();
- for (;server_->media_listeners_.end() != it; ++it) {
- (*it)->OnErrorReceived(server_->current_application_, -1);
- }
- } else if (static_cast<uint32_t>(ret) != msg.get()->data_size()) {
- LOG4CXX_WARN(logger_, "Couldn't write all the data to pipe "
- << server_->named_pipe_path_);
- }
-
- static int32_t messsages_for_session = 0;
- ++messsages_for_session;
-
- LOG4CXX_DEBUG(logger_, "Handling map streaming message. This is "
- << messsages_for_session << " the message for "
- << server_->current_application_);
- std::set<MediaListenerPtr>::iterator it =
- server_->media_listeners_.begin();
- for (; server_->media_listeners_.end() != it; ++it) {
- (*it)->OnDataReceived(server_->current_application_,
- messsages_for_session);
- }
- }
- server_->messages_.wait();
+ if (0 == close(pipe_fd_)) {
+ LOG4CXX_INFO(logger_, "Pipe " << named_pipe_path_ << " was closed");
+ } else {
+ LOG4CXX_ERROR(logger_, "Error closing pipe " << named_pipe_path_);
}
- close();
}
-void PipeStreamerAdapter::Streamer::exitThreadMain() {
+bool PipeStreamerAdapter::PipeStreamer::Send(
+ protocol_handler::RawMessagePtr msg) {
LOG4CXX_AUTO_TRACE(logger_);
- stop_flag_ = true;
- server_->messages_.Shutdown();
-}
-
-void PipeStreamerAdapter::Streamer::open() {
- LOG4CXX_AUTO_TRACE(logger_);
-
- DCHECK(file_system::CreateDirectoryRecursively(
- profile::Profile::instance()->app_storage_folder()));
-
- if ((mkfifo(server_->named_pipe_path_.c_str(),
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0)
- && (errno != EEXIST)) {
- LOG4CXX_ERROR(logger_, "Cannot create pipe " << server_->named_pipe_path_);
- return;
+ ssize_t ret = write(pipe_fd_, msg->data(), msg->data_size());
+ if (-1 == ret) {
+ LOG4CXX_ERROR(logger_, "Failed writing data to pipe " << named_pipe_path_);
+ return false;
}
- pipe_fd_ = ::open(server_->named_pipe_path_.c_str(), O_RDWR, 0);
- if (-1 == pipe_fd_) {
- LOG4CXX_ERROR(logger_, "Cannot open pipe for writing "
- << server_->named_pipe_path_);
- return;
+ if (static_cast<uint32_t>(ret) != msg->data_size()) {
+ LOG4CXX_WARN(logger_,
+ "Couldn't write all the data to pipe " << named_pipe_path_);
}
- LOG4CXX_DEBUG(logger_, "Pipe " << server_->named_pipe_path_
- << " was successfully created");
-}
-
-void PipeStreamerAdapter::Streamer::close() {
- LOG4CXX_AUTO_TRACE(logger_);
- ::close(pipe_fd_);
- unlink(server_->named_pipe_path_.c_str());
+ LOG4CXX_INFO(logger_, "Streamer::sent " << msg->data_size());
+ return true;
}
} // namespace media_manager
diff --git a/src/components/media_manager/src/socket_streamer_adapter.cc b/src/components/media_manager/src/socket_streamer_adapter.cc
index 45b1f63a17..2bb0fe10ec 100644
--- a/src/components/media_manager/src/socket_streamer_adapter.cc
+++ b/src/components/media_manager/src/socket_streamer_adapter.cc
@@ -33,282 +33,116 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/select.h>
-#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "config_profile/profile.h"
-#include "media_manager/video/socket_video_streamer_adapter.h"
#include "utils/logger.h"
+#include "media_manager/socket_streamer_adapter.h"
namespace media_manager {
CREATE_LOGGERPTR_GLOBAL(logger, "SocketStreamerAdapter")
-SocketStreamerAdapter::SocketStreamerAdapter()
- : socket_fd_(0),
- is_ready_(false),
- streamer_(new Streamer(this)),
- thread_(threads::CreateThread("SocketStreamer", streamer_)),
- messages_() {
-}
-
-SocketStreamerAdapter::~SocketStreamerAdapter() {
+SocketStreamerAdapter::SocketStreamerAdapter(const std::string& ip,
+ const uint16_t port,
+ const std::string& header)
+ : StreamerAdapter(new SocketStreamer(this, ip, port, header)) {}
+
+SocketStreamerAdapter::~SocketStreamerAdapter() {}
+
+SocketStreamerAdapter::SocketStreamer::SocketStreamer(
+ SocketStreamerAdapter* const adapter,
+ const std::string& ip,
+ const uint16_t port,
+ const std::string& header)
+ : Streamer(adapter)
+ , ip_(ip)
+ , port_(port)
+ , header_(header)
+ , socket_fd_(0)
+ , send_socket_fd_(0)
+ , is_first_frame_(true) {}
+
+SocketStreamerAdapter::SocketStreamer::~SocketStreamer() {}
+
+bool SocketStreamerAdapter::SocketStreamer::Connect() {
LOG4CXX_AUTO_TRACE(logger);
- thread_->join();
- delete streamer_;
- threads::DeleteThread(thread_);
-}
-
-void SocketStreamerAdapter::StartActivity(int32_t application_key) {
- LOG4CXX_TRACE(logger, "enter " << application_key);
-
- if (application_key == current_application_) {
- LOG4CXX_INFO(logger, "Already running for app " << application_key);
- } else {
- is_ready_ = true;
- current_application_ = application_key;
-
- messages_.Reset();
-
- for (std::set<MediaListenerPtr>::iterator it = media_listeners_.begin();
- media_listeners_.end() != it;
- ++it) {
- (*it)->OnActivityStarted(application_key);
- }
- }
- LOG4CXX_TRACE(logger, "exit");
-}
-
-void SocketStreamerAdapter::StopActivity(int32_t application_key) {
- LOG4CXX_TRACE(logger, "enter " << application_key);
-
- if (application_key != current_application_) {
- LOG4CXX_WARN(logger, "Streaming is not active for " << application_key);
- } else {
- is_ready_ = false;
- current_application_ = 0;
-
- if (streamer_) {
- streamer_->stop();
- messages_.Shutdown();
- }
-
- for (std::set<MediaListenerPtr>::iterator it = media_listeners_.begin();
- media_listeners_.end() != it;
- ++it) {
- (*it)->OnActivityEnded(application_key);
- }
- }
- LOG4CXX_TRACE(logger, "exit");
-}
-
-bool SocketStreamerAdapter::is_app_performing_activity(
- int32_t application_key) {
- return (application_key == current_application_);
-}
-
-void SocketStreamerAdapter::Init() {
- LOG4CXX_DEBUG(logger, "Start sending thread");
- const size_t kStackSize = 16384;
- thread_->start(threads::ThreadOptions(kStackSize));
-}
-
-void SocketStreamerAdapter::SendData(
- int32_t application_key,
- const ::protocol_handler::RawMessagePtr message) {
- LOG4CXX_INFO(logger, "SendData(application_key = " << application_key << ")");
-
-
- if (application_key != current_application_) {
- LOG4CXX_WARN(logger, "Currently working with other app "
- << current_application_);
- return;
- }
-
- if (is_ready_) {
- messages_.push(message);
- }
-}
-
-SocketStreamerAdapter::Streamer::Streamer(
- SocketStreamerAdapter* const server)
- : server_(server),
- new_socket_fd_(0),
- is_first_loop_(true),
- is_client_connected_(false),
- stop_flag_(false) {
-}
-
-SocketStreamerAdapter::Streamer::~Streamer() {
- stop();
-}
-
-void SocketStreamerAdapter::Streamer::threadMain() {
- LOG4CXX_TRACE(logger,"enter " << this);
- sync_primitives::AutoLock auto_lock(thread_lock);
- start();
-
- while (!stop_flag_) {
- new_socket_fd_ = accept(server_->socket_fd_, NULL, NULL);
- LOG4CXX_INFO(logger, "Client connectd " << new_socket_fd_);
- if (0 > new_socket_fd_) {
- LOG4CXX_ERROR(logger, "Socket is closed " << strerror(errno));
- sleep(1);
- continue;
- }
-
- is_client_connected_ = true;
- is_first_loop_ = true;
- while (is_client_connected_) {
- while (!server_->messages_.empty()) {
- ::protocol_handler::RawMessagePtr msg = server_->messages_.pop();
- if (!msg) {
- LOG4CXX_ERROR(logger, "Null pointer message");
- continue;
- }
-
- is_client_connected_ = send(msg);
- static int32_t messages_for_session = 0;
- ++messages_for_session;
-
- LOG4CXX_INFO(logger, "Handling map streaming message. This is "
- << messages_for_session << " the message for "
- << server_->current_application_);
- std::set<MediaListenerPtr>::iterator it = server_->media_listeners_
- .begin();
- for (; server_->media_listeners_.end() != it; ++it) {
- (*it)->OnDataReceived(server_->current_application_,
- messages_for_session);
- }
- }
-
- if (!is_ready()) {
- LOG4CXX_INFO(logger, "Client disconnected.");
- stop();
- break;
- }
- server_->messages_.wait();
- }
- }
- LOG4CXX_TRACE(logger,"exit " << this);
-}
-
-void SocketStreamerAdapter::Streamer::exitThreadMain() {
- LOG4CXX_TRACE(logger,"enter " << this);
- stop_flag_ = true;
- stop();
- server_->messages_.Shutdown();
- if (server_->socket_fd_ != -1) {
- shutdown(server_->socket_fd_, SHUT_RDWR);
- close(server_->socket_fd_);
- }
- LOG4CXX_TRACE(logger,"exit " << this);
-}
-
-void SocketStreamerAdapter::Streamer::start() {
- server_->socket_fd_ = socket(AF_INET, SOCK_STREAM, 0);
-
- if (0 >= server_->socket_fd_) {
- LOG4CXX_ERROR_EXT(logger, "Server open error");
- return;
+ socket_fd_ = socket(AF_INET, SOCK_STREAM, 0);
+ if (0 >= socket_fd_) {
+ LOG4CXX_ERROR(logger, "Unable to create socket");
+ return false;
}
int32_t optval = 1;
- if (-1 == setsockopt(server_->socket_fd_, SOL_SOCKET, SO_REUSEADDR,
- &optval, sizeof optval)) {
- LOG4CXX_ERROR_EXT(logger, "Unable to set sockopt");
- return;
+ if (-1 == setsockopt(
+ socket_fd_, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval)) {
+ LOG4CXX_ERROR(logger, "Unable to set sockopt");
+ return false;
}
- struct sockaddr_in serv_addr_ = { 0 };
- serv_addr_.sin_addr.s_addr = inet_addr(server_->ip_.c_str());
+ struct sockaddr_in serv_addr_ = {0};
+ serv_addr_.sin_addr.s_addr = inet_addr(ip_.c_str());
serv_addr_.sin_family = AF_INET;
- serv_addr_.sin_port = htons(server_->port_);
-
- if (-1 == bind(server_->socket_fd_,
+ serv_addr_.sin_port = htons(port_);
+ if (-1 == bind(socket_fd_,
reinterpret_cast<struct sockaddr*>(&serv_addr_),
sizeof(serv_addr_))) {
- LOG4CXX_ERROR_EXT(logger, "Unable to bind");
- return;
+ LOG4CXX_ERROR(logger, "Unable to bind");
+ return false;
}
- LOG4CXX_INFO(logger, "SocketStreamerAdapter::listen for connections");
- if (-1 == listen(server_->socket_fd_, 5)) {
- LOG4CXX_ERROR_EXT(logger, "Unable to listen");
- return;
+ if (-1 == listen(socket_fd_, 5)) {
+ LOG4CXX_ERROR(logger, "Unable to listen");
+ return false;
}
-}
-void SocketStreamerAdapter::Streamer::stop() {
- LOG4CXX_TRACE(logger,"enter " << this);
- if (0 == new_socket_fd_) {
- LOG4CXX_ERROR(logger, "Client Socket does not exist: ");
- } else if (-1 == shutdown(new_socket_fd_, SHUT_RDWR)) {
- LOG4CXX_ERROR(logger, "Unable to shutdown socket " << strerror(errno));
- } else if (-1 == ::close(new_socket_fd_)) {
- LOG4CXX_ERROR(logger, "Unable to close socket " << strerror(errno));
+ send_socket_fd_ = accept(socket_fd_, NULL, NULL);
+ if (0 >= send_socket_fd_) {
+ LOG4CXX_ERROR(logger, "Unable to accept");
+ return false;
}
- new_socket_fd_ = 0;
- is_client_connected_ = false;
- LOG4CXX_TRACE(logger,"exit" << this);
+ is_first_frame_ = true;
+ LOG4CXX_INFO(logger, "Client connected: " << send_socket_fd_);
+ return true;
}
-bool SocketStreamerAdapter::Streamer::is_ready() const {
- bool result = true;
- fd_set fds;
- FD_ZERO(&fds);
- FD_SET(new_socket_fd_, &fds);
- struct timeval tv;
- tv.tv_sec = 5; // set a 5 second timeout
- tv.tv_usec = 0;
-
- int32_t retval = 0;
- retval = select(new_socket_fd_ + 1, 0, &fds, 0, &tv);
-
- if (-1 == retval) {
- LOG4CXX_ERROR_EXT(logger, "An error occurred");
- result = false;
- } else if (0 == retval) {
- LOG4CXX_ERROR_EXT(logger, "The timeout expired");
- result = false;
+void SocketStreamerAdapter::SocketStreamer::Disconnect() {
+ LOG4CXX_AUTO_TRACE(logger);
+ if (0 < send_socket_fd_) {
+ close(send_socket_fd_);
}
- return result;
-}
-
-bool SocketStreamerAdapter::Streamer::send(
- const ::protocol_handler::RawMessagePtr msg) {
- if (!is_ready()) {
- LOG4CXX_ERROR_EXT(logger, " Socket is not ready");
- return false;
+ if (0 < socket_fd_) {
+ close(socket_fd_);
}
+}
- if (is_first_loop_) {
- is_first_loop_ = false;
- char hdr[] = {"HTTP/1.1 200 OK\r\n "
- "Connection: Keep-Alive\r\n"
- "Keep-Alive: timeout=15, max=300\r\n"
- "Server: SDL\r\n"
- "Content-Type: video/mp4\r\n\r\n"
- };
-
- if (-1 == ::send(new_socket_fd_, hdr, strlen(hdr), MSG_NOSIGNAL)) {
- LOG4CXX_ERROR_EXT(logger, " Unable to send");
+bool SocketStreamerAdapter::SocketStreamer::Send(
+ protocol_handler::RawMessagePtr msg) {
+ LOG4CXX_AUTO_TRACE(logger);
+ ssize_t ret;
+ if (is_first_frame_) {
+ ret = send(send_socket_fd_, header_.c_str(), header_.size(), MSG_NOSIGNAL);
+ if (static_cast<uint32_t>(ret) != header_.size()) {
+ LOG4CXX_ERROR(logger, "Unable to send data to socket");
return false;
}
+ is_first_frame_ = false;
}
- if (-1 == ::send(new_socket_fd_, (*msg).data(),
- (*msg).data_size(), MSG_NOSIGNAL)) {
- LOG4CXX_ERROR_EXT(logger, " Unable to send");
+ ret = send(send_socket_fd_, msg->data(), msg->data_size(), MSG_NOSIGNAL);
+ if (-1 == ret) {
+ LOG4CXX_ERROR(logger, "Unable to send data to socket");
return false;
}
- LOG4CXX_INFO(logger, "Streamer::sent " << (*msg).data_size());
+ if (static_cast<uint32_t>(ret) != msg->data_size()) {
+ LOG4CXX_WARN(logger,
+ "Couldn't send all the data to socket " << send_socket_fd_);
+ }
+
+ LOG4CXX_INFO(logger, "Streamer::sent " << msg->data_size());
return true;
}
diff --git a/src/components/media_manager/src/streamer_adapter.cc b/src/components/media_manager/src/streamer_adapter.cc
new file mode 100644
index 0000000000..20c067da1c
--- /dev/null
+++ b/src/components/media_manager/src/streamer_adapter.cc
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2015, 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 "media_manager/streamer_adapter.h"
+#include "utils/logger.h"
+
+namespace media_manager {
+
+CREATE_LOGGERPTR_GLOBAL(logger, "StreamerAdapter")
+
+StreamerAdapter::StreamerAdapter(Streamer* const streamer)
+ : current_application_(0), messages_(), streamer_(streamer), thread_(NULL) {
+ DCHECK(streamer_);
+ thread_ = threads::CreateThread("StreamerAdapter", streamer_);
+}
+
+StreamerAdapter::~StreamerAdapter() {
+ delete streamer_;
+ thread_->join();
+ threads::DeleteThread(thread_);
+}
+
+void StreamerAdapter::StartActivity(int32_t application_key) {
+ LOG4CXX_AUTO_TRACE(logger);
+ if (is_app_performing_activity(application_key)) {
+ LOG4CXX_WARN(logger,
+ "Activity for application: " << application_key
+ << " has been already started");
+ return;
+ }
+ messages_.Reset();
+
+ DCHECK(thread_);
+ const size_t kStackSize = 16384;
+ thread_->start(threads::ThreadOptions(kStackSize));
+
+ for (std::set<MediaListenerPtr>::iterator it = media_listeners_.begin();
+ media_listeners_.end() != it;
+ ++it) {
+ (*it)->OnActivityStarted(application_key);
+ }
+ current_application_ = application_key;
+}
+
+void StreamerAdapter::StopActivity(int32_t application_key) {
+ LOG4CXX_AUTO_TRACE(logger);
+ if (!is_app_performing_activity(application_key)) {
+ LOG4CXX_WARN(logger,
+ "Activity for application: " << application_key
+ << " has not been started");
+ return;
+ }
+
+ DCHECK(thread_);
+ thread_->stop();
+
+ for (std::set<MediaListenerPtr>::iterator it = media_listeners_.begin();
+ media_listeners_.end() != it;
+ ++it) {
+ (*it)->OnActivityEnded(application_key);
+ }
+ current_application_ = 0;
+}
+
+void StreamerAdapter::SendData(int32_t application_key,
+ const ::protocol_handler::RawMessagePtr msg) {
+ LOG4CXX_AUTO_TRACE(logger);
+ if (!is_app_performing_activity(application_key)) {
+ LOG4CXX_ERROR(logger,
+ "Activity for application: " << application_key
+ << " has not been started");
+ return;
+ }
+ messages_.push(msg);
+}
+
+bool StreamerAdapter::is_app_performing_activity(
+ int32_t application_key) const {
+ return application_key == current_application_;
+}
+
+StreamerAdapter::Streamer::Streamer(StreamerAdapter* const adapter)
+ : stop_flag_(false), adapter_(adapter) {
+ DCHECK(adapter_);
+}
+
+StreamerAdapter::Streamer::~Streamer() {}
+
+void StreamerAdapter::Streamer::threadMain() {
+ LOG4CXX_AUTO_TRACE(logger);
+ if (!adapter_) {
+ LOG4CXX_ERROR(logger, "Null pointer to adapter");
+ return;
+ }
+ if (!Connect()) {
+ LOG4CXX_ERROR(logger, "Unable to connect");
+ return;
+ }
+ stop_flag_ = false;
+ while (!stop_flag_) {
+ adapter_->messages_.wait();
+ while (!adapter_->messages_.empty()) {
+ protocol_handler::RawMessagePtr msg;
+ if (!adapter_->messages_.pop(msg)) {
+ LOG4CXX_ERROR(logger, "Empty message queue");
+ continue;
+ }
+ if (!msg) {
+ LOG4CXX_ERROR(logger, "Null pointer message");
+ continue;
+ }
+ if (!Send(msg)) {
+ LOG4CXX_ERROR(logger, "Unable to send. Disconnecting");
+ Disconnect();
+ return;
+ }
+ static int32_t messages_for_session = 0;
+ ++messages_for_session;
+
+ LOG4CXX_DEBUG(logger,
+ "Handling map streaming message. This is "
+ << messages_for_session << " message for "
+ << adapter_->current_application_);
+ std::set<MediaListenerPtr>::iterator it =
+ adapter_->media_listeners_.begin();
+ for (; adapter_->media_listeners_.end() != it; ++it) {
+ (*it)->OnDataReceived(adapter_->current_application_,
+ messages_for_session);
+ }
+ }
+ }
+ Disconnect();
+}
+
+void StreamerAdapter::Streamer::exitThreadMain() {
+ LOG4CXX_AUTO_TRACE(logger);
+ stop_flag_ = true;
+ if (adapter_) {
+ adapter_->messages_.Shutdown();
+ }
+}
+
+} // namespace media_manager
diff --git a/src/components/media_manager/src/streamer_listener.cc b/src/components/media_manager/src/streamer_listener.cc
index 3181ba8e09..2d6c3bc984 100644
--- a/src/components/media_manager/src/streamer_listener.cc
+++ b/src/components/media_manager/src/streamer_listener.cc
@@ -36,33 +36,30 @@
namespace media_manager {
-CREATE_LOGGERPTR_GLOBAL(logger_, "StreamerListener")
+CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManager")
-StreamerListener::StreamerListener()
- : current_application_(0) {
-}
+StreamerListener::StreamerListener(MediaManager& media_manager)
+ : current_application_(0), media_manager_(media_manager) {}
StreamerListener::~StreamerListener() {
OnActivityEnded(current_application_);
}
-void StreamerListener::OnDataReceived(
- int32_t application_key,
- const DataForListener& data) {
- MediaManagerImpl::instance()->FramesProcessed(application_key, data);
+void StreamerListener::OnDataReceived(int32_t application_key,
+ const DataForListener& data) {
+ media_manager_.FramesProcessed(application_key, data);
}
-void StreamerListener::OnErrorReceived(
- int32_t application_key,
- const DataForListener& data) {
- LOG4CXX_ERROR(logger_, "StreamerListener::OnErrorReceived");
+void StreamerListener::OnErrorReceived(int32_t application_key,
+ const DataForListener& data) {
+ LOG4CXX_AUTO_TRACE(logger_);
}
void StreamerListener::OnActivityStarted(int32_t application_key) {
LOG4CXX_AUTO_TRACE(logger_);
if (current_application_ == application_key) {
- LOG4CXX_WARN(logger_, "Already performing activity for "
- << application_key);
+ LOG4CXX_WARN(logger_,
+ "Already performing activity for " << application_key);
return;
}
current_application_ = application_key;
@@ -71,8 +68,8 @@ void StreamerListener::OnActivityStarted(int32_t application_key) {
void StreamerListener::OnActivityEnded(int32_t application_key) {
LOG4CXX_AUTO_TRACE(logger_);
if (current_application_ != application_key) {
- LOG4CXX_WARN(logger_, "Already not performing activity for "
- << application_key);
+ LOG4CXX_WARN(logger_,
+ "Already not performing activity for " << application_key);
return;
}
current_application_ = 0;
diff --git a/src/components/media_manager/src/video/file_video_streamer_adapter.cc b/src/components/media_manager/src/video/file_video_streamer_adapter.cc
new file mode 100644
index 0000000000..f9e4d58a0e
--- /dev/null
+++ b/src/components/media_manager/src/video/file_video_streamer_adapter.cc
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2014-2015, 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 "media_manager/video/file_video_streamer_adapter.h"
+
+namespace media_manager {
+
+FileVideoStreamerAdapter::FileVideoStreamerAdapter(
+ const std::string& video_stream_file, const std::string& app_storage_folder)
+ : FileStreamerAdapter(video_stream_file, app_storage_folder) {}
+
+FileVideoStreamerAdapter::~FileVideoStreamerAdapter() {}
+
+} // namespace media_manager
diff --git a/src/components/media_manager/src/video/pipe_video_streamer_adapter.cc b/src/components/media_manager/src/video/pipe_video_streamer_adapter.cc
index 4812e19c9f..cf1a6fb347 100644
--- a/src/components/media_manager/src/video/pipe_video_streamer_adapter.cc
+++ b/src/components/media_manager/src/video/pipe_video_streamer_adapter.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, Ford Motor Company
+ * Copyright (c) 2014-2015, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,21 +31,14 @@
*/
#include "media_manager/video/pipe_video_streamer_adapter.h"
-#include "config_profile/profile.h"
namespace media_manager {
-CREATE_LOGGERPTR_GLOBAL(logger, "PipeVideoStreamerAdapter")
+PipeVideoStreamerAdapter::PipeVideoStreamerAdapter(
+ const std::string& named_video_pipe_path,
+ const std::string& app_storage_folder)
+ : PipeStreamerAdapter(named_video_pipe_path, app_storage_folder) {}
-PipeVideoStreamerAdapter::PipeVideoStreamerAdapter() {
- LOG4CXX_AUTO_TRACE(logger);
- named_pipe_path_ = profile::Profile::instance()->named_video_pipe_path();
-
- Init();
-}
-
-PipeVideoStreamerAdapter::~PipeVideoStreamerAdapter() {
- LOG4CXX_INFO(logger, "PipeVideoStreamerAdapter::~PipeVideoStreamerAdapter");
-}
+PipeVideoStreamerAdapter::~PipeVideoStreamerAdapter() {}
} // namespace media_manager
diff --git a/src/components/media_manager/src/video/socket_video_streamer_adapter.cc b/src/components/media_manager/src/video/socket_video_streamer_adapter.cc
index 3a83aabd10..12ae93da69 100644
--- a/src/components/media_manager/src/video/socket_video_streamer_adapter.cc
+++ b/src/components/media_manager/src/video/socket_video_streamer_adapter.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, Ford Motor Company
+ * Copyright (c) 2014-2015, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,23 +30,23 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "config_profile/profile.h"
#include "media_manager/video/socket_video_streamer_adapter.h"
-#include "utils/logger.h"
-namespace media_manager {
-
-CREATE_LOGGERPTR_GLOBAL(logger, "SocketVideoStreamerAdapter")
+namespace {
+const std::string kHeader =
+ "HTTP/1.1 200 OK\r\n"
+ "Connection: Keep-Alive\r\n"
+ "Keep-Alive: timeout=15, max=300\r\n"
+ "Server: SDL\r\n"
+ "Content-Type: video/mp4\r\n\r\n";
+}
-SocketVideoStreamerAdapter::SocketVideoStreamerAdapter() {
- LOG4CXX_AUTO_TRACE(logger);
- port_ = profile::Profile::instance()->video_streaming_port();
- ip_ = profile::Profile::instance()->server_address();
+namespace media_manager {
- Init();
-}
+SocketVideoStreamerAdapter::SocketVideoStreamerAdapter(
+ const std::string& server_address, uint16_t video_streaming_port)
+ : SocketStreamerAdapter(server_address, video_streaming_port, kHeader) {}
-SocketVideoStreamerAdapter::~SocketVideoStreamerAdapter() {
-}
+SocketVideoStreamerAdapter::~SocketVideoStreamerAdapter() {}
} // namespace media_manager
diff --git a/src/components/media_manager/src/video/video_stream_to_file_adapter.cc b/src/components/media_manager/src/video/video_stream_to_file_adapter.cc
index 33b0c43ee5..f41954b117 100644
--- a/src/components/media_manager/src/video/video_stream_to_file_adapter.cc
+++ b/src/components/media_manager/src/video/video_stream_to_file_adapter.cc
@@ -40,16 +40,15 @@ namespace media_manager {
CREATE_LOGGERPTR_GLOBAL(logger, "VideoStreamToFileAdapter")
VideoStreamToFileAdapter::VideoStreamToFileAdapter(const std::string& file_name)
- : file_name_(file_name),
- is_ready_(false),
- thread_(threads::CreateThread("VideoStreamer",
- new Streamer(this))) {
+ : file_name_(file_name)
+ , is_ready_(false)
+ , thread_(threads::CreateThread("VideoStreamer", new Streamer(this))) {
Init();
}
VideoStreamToFileAdapter::~VideoStreamToFileAdapter() {
LOG4CXX_AUTO_TRACE(logger);
- if ((0 != current_application_ ) && (is_ready_)) {
+ if ((0 != current_application_) && (is_ready_)) {
StopActivity(current_application_);
}
thread_->join();
@@ -68,10 +67,9 @@ void VideoStreamToFileAdapter::Init() {
}
void VideoStreamToFileAdapter::SendData(
- int32_t application_key,
- const ::protocol_handler::RawMessagePtr message) {
- LOG4CXX_INFO(logger, "VideoStreamToFileAdapter::SendData "
- << application_key);
+ int32_t application_key, const ::protocol_handler::RawMessagePtr message) {
+ LOG4CXX_INFO(logger,
+ "VideoStreamToFileAdapter::SendData " << application_key);
if (application_key != current_application_) {
LOG4CXX_WARN(logger, "Wrong application " << application_key);
@@ -84,11 +82,11 @@ void VideoStreamToFileAdapter::SendData(
}
void VideoStreamToFileAdapter::StartActivity(int32_t application_key) {
- LOG4CXX_INFO(logger, "VideoStreamToFileAdapter::StartActivity "
- << application_key);
+ LOG4CXX_INFO(logger,
+ "VideoStreamToFileAdapter::StartActivity " << application_key);
if (application_key == current_application_) {
- LOG4CXX_WARN(logger, "Already running video stream to file for "
- << application_key);
+ LOG4CXX_WARN(
+ logger, "Already running video stream to file for " << application_key);
return;
}
@@ -103,11 +101,11 @@ void VideoStreamToFileAdapter::StartActivity(int32_t application_key) {
}
void VideoStreamToFileAdapter::StopActivity(int32_t application_key) {
- LOG4CXX_INFO(logger, "VideoStreamToFileAdapter::StopActivity "
- << application_key);
+ LOG4CXX_INFO(logger,
+ "VideoStreamToFileAdapter::StopActivity " << application_key);
if (application_key != current_application_) {
- LOG4CXX_WARN(logger, "Performing activity for another key "
- << current_application_);
+ LOG4CXX_WARN(
+ logger, "Performing activity for another key " << current_application_);
return;
}
@@ -121,17 +119,13 @@ void VideoStreamToFileAdapter::StopActivity(int32_t application_key) {
}
}
-bool VideoStreamToFileAdapter::is_app_performing_activity(int32_t
- application_key) {
+bool VideoStreamToFileAdapter::is_app_performing_activity(
+ int32_t application_key) {
return (application_key == current_application_ && is_ready_);
}
-VideoStreamToFileAdapter::Streamer::Streamer(
- VideoStreamToFileAdapter* server)
- : server_(server),
- stop_flag_(false),
- file_stream_(NULL) {
-}
+VideoStreamToFileAdapter::Streamer::Streamer(VideoStreamToFileAdapter* server)
+ : server_(server), stop_flag_(false), file_stream_(NULL) {}
VideoStreamToFileAdapter::Streamer::~Streamer() {
server_ = NULL;
@@ -139,7 +133,7 @@ VideoStreamToFileAdapter::Streamer::~Streamer() {
}
void VideoStreamToFileAdapter::Streamer::threadMain() {
- LOG4CXX_INFO(logger, "Streamer::threadMain");
+ LOG4CXX_AUTO_TRACE(logger);
open();
@@ -173,7 +167,7 @@ void VideoStreamToFileAdapter::Streamer::threadMain() {
}
void VideoStreamToFileAdapter::Streamer::exitThreadMain() {
- LOG4CXX_INFO(logger, "Streamer::exitThreadMain");
+ LOG4CXX_AUTO_TRACE(logger);
stop_flag_ = true;
server_->messages_.Shutdown();
}
@@ -186,7 +180,7 @@ void VideoStreamToFileAdapter::Streamer::open() {
file_stream_ = file_system::Open(server_->file_name_);
if (!file_stream_) {
- LOG4CXX_WARN(logger, "Can't open file stream! " << server_->file_name_);
+ LOG4CXX_WARN(logger, "Can't open file stream! " << server_->file_name_);
} else {
LOG4CXX_INFO(logger, "file_stream_ opened :" << file_stream_);
}