diff options
Diffstat (limited to 'src/components/media_manager/src')
15 files changed, 292 insertions, 298 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 f8b0d9599b..b2495a2bfe 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 @@ -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) 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. + */ #include <net/if.h> #include <pulse/simple.h> #include <pulse/error.h> @@ -37,7 +37,6 @@ #include "utils/threads/thread.h" #include "media_manager/audio/a2dp_source_player_adapter.h" #include "utils/lock.h" -#include "utils/threads/thread_delegate.h" #include "utils/logger.h" #include "connection_handler/connection_handler_impl.h" @@ -54,7 +53,7 @@ class A2DPSourcePlayerAdapter::A2DPSourcePlayerThread void threadMain(); - bool exitThreadMain(); + void exitThreadMain(); private: // The Sample format to use @@ -74,13 +73,12 @@ A2DPSourcePlayerAdapter::A2DPSourcePlayerAdapter() { } A2DPSourcePlayerAdapter::~A2DPSourcePlayerAdapter() { - for (std::map<int32_t, threads::Thread*>::iterator it = sources_.begin(); - sources_.end() != it; - ++it) { - if (NULL != it->second) { - it->second->stop(); - threads::DeleteThread(it->second); - } + for (SourcesMap::iterator it = sources_.begin(); + sources_.end() != it; ++it) { + Pair pair = *it; + pair.first->join(); + delete pair.second; + threads::DeleteThread(pair.first); } sources_.clear(); } @@ -105,10 +103,11 @@ void A2DPSourcePlayerAdapter::StartActivity(int32_t application_key) { // following format : "bluez_source.XX_XX_XX_XX_XX_XX" if needed // before passing to the A2DPSourcePlayerThread constructor + A2DPSourcePlayerThread* delegate = + new A2DPSourcePlayerAdapter::A2DPSourcePlayerThread(mac_adddress); threads::Thread* new_activity = threads::CreateThread( - mac_adddress.c_str(), - new A2DPSourcePlayerAdapter::A2DPSourcePlayerThread(mac_adddress)); - sources_[application_key] = new_activity; + mac_adddress.c_str(), delegate); + sources_[application_key] = Pair(new_activity, delegate); new_activity->start(); } } @@ -119,19 +118,12 @@ void A2DPSourcePlayerAdapter::StopActivity(int32_t application_key) { if (application_key != current_application_) { return; } - std::map<int32_t, threads::Thread*>::iterator it = - sources_.find(application_key); + SourcesMap::iterator it = sources_.find(application_key); if (sources_.end() != it) { - LOG4CXX_DEBUG(logger_, "Source exists."); - if (NULL != it->second) { - LOG4CXX_DEBUG(logger_, "Sources thread was allocated"); - if ((*it).second->is_running()) { - // Sources thread was started - stop it - LOG4CXX_DEBUG(logger_, "Sources thread was started - stop it"); - (*it).second->stop(); - threads::DeleteThread(it->second); - } - } + Pair pair = *it; + pair.first->join(); + delete pair.second; + threads::DeleteThread(pair.first); current_application_ = 0; } } @@ -165,10 +157,9 @@ void A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::freeStreams() { } } -bool A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::exitThreadMain() { +void A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::exitThreadMain() { sync_primitives::AutoLock auto_lock(should_be_stopped_lock_); should_be_stopped_ = true; - return true; } void A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::threadMain() { @@ -239,6 +230,7 @@ void A2DPSourcePlayerAdapter::A2DPSourcePlayerThread::threadMain() { bool should_be_stopped; { + // FIXME (dchmerev@luxoft.com): Remove these insane blockings sync_primitives::AutoLock auto_lock(should_be_stopped_lock_); should_be_stopped = should_be_stopped_; } 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 a3ef5af0bf..a52936e850 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 @@ -38,6 +38,7 @@ #include <string> +#include <string.h> #include "application_manager/application_manager_impl.h" #include "application_manager/mobile_command_factory.h" #include "application_manager/application_impl.h" @@ -65,14 +66,14 @@ AudioStreamSenderThread::AudioStreamSenderThread( shouldBeStoped_(false), shouldBeStoped_lock_(), shouldBeStoped_cv_() { - LOG4CXX_TRACE_ENTER(logger_); + LOG4CXX_AUTO_TRACE(logger_); } AudioStreamSenderThread::~AudioStreamSenderThread() { } void AudioStreamSenderThread::threadMain() { - LOG4CXX_TRACE_ENTER(logger_); + LOG4CXX_AUTO_TRACE(logger_); offset_ = 0; @@ -82,11 +83,10 @@ void AudioStreamSenderThread::threadMain() { sendAudioChunkToMobile(); } - LOG4CXX_TRACE_EXIT(logger_); } void AudioStreamSenderThread::sendAudioChunkToMobile() { - LOG4CXX_TRACE_ENTER(logger_); + LOG4CXX_AUTO_TRACE(logger_); std::vector<uint8_t> binaryData; std::vector<uint8_t>::iterator from; @@ -112,10 +112,10 @@ void AudioStreamSenderThread::sendAudioChunkToMobile() { LOG4CXX_INFO_EXT(logger_, "from != binaryData.end()"); offset_ = offset_ + to - from; + std::vector<uint8_t> data(from, to); application_manager::ApplicationManagerImpl::instance()-> - SendAudioPassThroughNotification(session_key_, - std::vector<uint8_t>(from, to)); + SendAudioPassThroughNotification(session_key_, data); binaryData.clear(); } #if !defined(EXTENDED_MEDIA_MODE) @@ -136,10 +136,9 @@ void AudioStreamSenderThread::setShouldBeStopped(bool should_stop) { shouldBeStoped_cv_.NotifyOne(); } -bool AudioStreamSenderThread::exitThreadMain() { - LOG4CXX_INFO(logger_, "AudioStreamSenderThread::exitThreadMain"); +void AudioStreamSenderThread::exitThreadMain() { + LOG4CXX_AUTO_TRACE(logger_); setShouldBeStopped(true); - return true; } uint32_t AudioStreamSenderThread::session_key() const { 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 7559512a80..2c28e250bd 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 @@ -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) 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. + */ #include <string> #include "utils/threads/thread.h" @@ -44,18 +44,21 @@ FromMicRecorderAdapter::FromMicRecorderAdapter() : recorder_thread_(NULL) , output_file_("default_recorded_audio.wav") , kDefaultDuration(1000) - , duration_(0) { - duration_ = kDefaultDuration; + , duration_(kDefaultDuration) { + } FromMicRecorderAdapter::~FromMicRecorderAdapter() { - LOG4CXX_INFO(logger_, "FromMicRecorderAdapter::~FromMicRecorderAdapter()"); - StopActivity(current_application_); + LOG4CXX_AUTO_TRACE(logger_); + if (recorder_thread_) { + recorder_thread_->join(); + delete recorder_thread_->delegate(); + threads::DeleteThread(recorder_thread_); + } } void FromMicRecorderAdapter::StartActivity(int32_t application_key) { - LOG4CXX_INFO(logger_, "FromMicRecorderAdapter::StartActivity " - << 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_); @@ -86,9 +89,8 @@ void FromMicRecorderAdapter::StopActivity(int32_t application_key) { return; } - if (NULL != recorder_thread_) { + if (recorder_thread_) { recorder_thread_->stop(); - recorder_thread_ = NULL; } current_application_ = 0; } 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 06dce2d4ea..2d305d98b0 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 @@ -46,9 +46,11 @@ FromMicRecorderListener::FromMicRecorderListener( } FromMicRecorderListener::~FromMicRecorderListener() { + LOG4CXX_AUTO_TRACE(logger_); if (reader_) { - reader_->stop(); - reader_ = NULL; + reader_->join(); + delete reader_->delegate(); + threads::DeleteThread(reader_); } } @@ -89,7 +91,6 @@ void FromMicRecorderListener::OnActivityEnded(int32_t application_key) { } if (reader_) { reader_->stop(); - reader_ = NULL; } current_application_ = 0; } 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 181c8c61b3..a18299750f 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 @@ -1,34 +1,34 @@ /* -* 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. -*/ + * 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 "media_manager/audio/from_mic_to_file_recorder_thread.h" #include <unistd.h> @@ -49,19 +49,27 @@ FromMicToFileRecorderThread::FromMicToFileRecorderThread( tKey_("-t"), sleepThread_(NULL), outputFileName_(output_file) { - LOG4CXX_TRACE_ENTER(logger_); + LOG4CXX_AUTO_TRACE(logger_); set_record_duration(duration); } +FromMicToFileRecorderThread::~FromMicToFileRecorderThread() { + LOG4CXX_AUTO_TRACE(logger_); + if (sleepThread_) { + sleepThread_->join(); + delete sleepThread_->delegate(); + threads::DeleteThread(sleepThread_); + } +} + void FromMicToFileRecorderThread::set_output_file( const std::string& output_file) { - LOG4CXX_TRACE_ENTER(logger_); - + LOG4CXX_AUTO_TRACE(logger_); outputFileName_ = output_file; } void FromMicToFileRecorderThread::set_record_duration(int32_t duration) { - LOG4CXX_TRACE_ENTER(logger_); + LOG4CXX_AUTO_TRACE(logger_); std::stringstream stringStream; stringStream << duration / 1000; @@ -69,7 +77,7 @@ void FromMicToFileRecorderThread::set_record_duration(int32_t duration) { } void FromMicToFileRecorderThread::initArgs() { - LOG4CXX_TRACE_ENTER(logger_); + LOG4CXX_AUTO_TRACE(logger_); argv_ = new gchar*[argc_]; @@ -87,7 +95,7 @@ void FromMicToFileRecorderThread::initArgs() { } void FromMicToFileRecorderThread::threadMain() { - LOG4CXX_TRACE_ENTER(logger_); + LOG4CXX_AUTO_TRACE(logger_); { sync_primitives::AutoLock auto_lock(stopFlagLock_); @@ -181,6 +189,7 @@ void FromMicToFileRecorderThread::threadMain() { bool shouldBeStoped; { + // FIXME(dchmerev@luxoft.com): sync_primitives::AutoLock auto_lock(stopFlagLock_); shouldBeStoped = shouldBeStoped_; } @@ -233,8 +242,8 @@ void FromMicToFileRecorderThread::SleepThreadDelegate::threadMain() { } } -bool FromMicToFileRecorderThread::exitThreadMain() { - LOG4CXX_TRACE_ENTER(logger_); +void FromMicToFileRecorderThread::exitThreadMain() { + LOG4CXX_AUTO_TRACE(logger_); if (NULL != loop) { if (g_main_loop_is_running(loop)) { @@ -243,20 +252,14 @@ bool FromMicToFileRecorderThread::exitThreadMain() { } } - if (NULL != sleepThread_) { - LOG4CXX_TRACE(logger_, "Stop sleep thread\n"); + if (sleepThread_) { + LOG4CXX_DEBUG(logger_, "Stop sleep thread\n"); sleepThread_->stop(); - threads::DeleteThread(sleepThread_); - sleepThread_ = NULL; } LOG4CXX_TRACE(logger_, "Set should be stopped flag\n"); - { - sync_primitives::AutoLock auto_lock(stopFlagLock_); - shouldBeStoped_ = true; - } - - return true; + sync_primitives::AutoLock auto_lock(stopFlagLock_); + shouldBeStoped_ = true; } } // namespace media_manager 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 5faebf93d5..4c6c8a2bb7 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,4 +1,4 @@ -/** +/* * Copyright (c) 2013, Ford Motor Company * All rights reserved. * @@ -39,7 +39,7 @@ namespace media_manager { CREATE_LOGGERPTR_GLOBAL(logger, "PipeAudioStreamerAdapter") PipeAudioStreamerAdapter::PipeAudioStreamerAdapter() { - LOG4CXX_INFO(logger, "PipeAudioStreamerAdapter::PipeAudioStreamerAdapter"); + LOG4CXX_AUTO_TRACE(logger); named_pipe_path_ = profile::Profile::instance()->named_audio_pipe_path(); Init(); 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 eb93032e42..dfb15e2079 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,4 +1,4 @@ -/** +/* * Copyright (c) 2013, Ford Motor Company * All rights reserved. * @@ -39,7 +39,7 @@ namespace media_manager { CREATE_LOGGERPTR_GLOBAL(logger, "SocketAudioStreamerAdapter") SocketAudioStreamerAdapter::SocketAudioStreamerAdapter() { - LOG4CXX_INFO(logger, "SocketAudioStreamerAdapter::SocketAudioStreamerAdapter"); + LOG4CXX_AUTO_TRACE(logger); port_ = profile::Profile::instance()->audio_streaming_port(); ip_ = profile::Profile::instance()->server_address(); diff --git a/src/components/media_manager/src/media_adapter_impl.cc b/src/components/media_manager/src/media_adapter_impl.cc index 1a52b003ff..23afe4543e 100644 --- a/src/components/media_manager/src/media_adapter_impl.cc +++ b/src/components/media_manager/src/media_adapter_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) 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. + */ #include "media_manager/media_adapter_impl.h" #include "utils/logger.h" @@ -46,12 +46,12 @@ MediaAdapterImpl::~MediaAdapterImpl() { } void MediaAdapterImpl::AddListener(const MediaListenerPtr& listener) { - LOG4CXX_INFO(logger_, "MediaAdapterImpl::AddListener"); + LOG4CXX_AUTO_TRACE(logger_); media_listeners_.insert(listener); } void MediaAdapterImpl::RemoveListener(const MediaListenerPtr& listener) { - LOG4CXX_INFO(logger_, "MediaAdapterImpl::RemoveListener"); + LOG4CXX_AUTO_TRACE(logger_); media_listeners_.erase(listener); } diff --git a/src/components/media_manager/src/media_manager_impl.cc b/src/components/media_manager/src/media_manager_impl.cc index e8156795b1..d69ff56368 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) 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. + */ #include "config_profile/profile.h" #include "media_manager/media_manager_impl.h" @@ -133,14 +133,14 @@ void MediaManagerImpl::Init() { } 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 +200,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); @@ -212,7 +212,7 @@ void MediaManagerImpl::StopMicrophoneRecording(int32_t application_key) { } void MediaManagerImpl::StartVideoStreaming(int32_t application_key) { - LOG4CXX_INFO(logger_, "MediaManagerImpl::StartVideoStreaming"); + LOG4CXX_AUTO_TRACE(logger_); if (video_streamer_) { if (!video_stream_active_) { @@ -224,7 +224,7 @@ void MediaManagerImpl::StartVideoStreaming(int32_t application_key) { } void MediaManagerImpl::StopVideoStreaming(int32_t application_key) { - LOG4CXX_INFO(logger_, "MediaManagerImpl::StopVideoStreaming"); + LOG4CXX_AUTO_TRACE(logger_); if (video_streamer_) { video_stream_active_ = false; application_manager::MessageHelper::SendNaviStopStream(application_key); @@ -233,7 +233,7 @@ void MediaManagerImpl::StopVideoStreaming(int32_t application_key) { } void MediaManagerImpl::StartAudioStreaming(int32_t application_key) { - LOG4CXX_INFO(logger_, "MediaManagerImpl::StartAudioStreaming"); + LOG4CXX_AUTO_TRACE(logger_); if (audio_streamer_) { if (!audio_stream_active_) { @@ -245,7 +245,7 @@ void MediaManagerImpl::StartAudioStreaming(int32_t application_key) { } void MediaManagerImpl::StopAudioStreaming(int32_t application_key) { - LOG4CXX_INFO(logger_, "MediaManagerImpl::StopAudioStreaming"); + LOG4CXX_AUTO_TRACE(logger_); if (audio_streamer_) { audio_stream_active_ = false; application_manager::MessageHelper::SendAudioStopStream(application_key); diff --git a/src/components/media_manager/src/pipe_streamer_adapter.cc b/src/components/media_manager/src/pipe_streamer_adapter.cc index 43f0d71530..c1a0e1fa20 100644 --- a/src/components/media_manager/src/pipe_streamer_adapter.cc +++ b/src/components/media_manager/src/pipe_streamer_adapter.cc @@ -41,32 +41,34 @@ namespace media_manager { -CREATE_LOGGERPTR_GLOBAL(logger, "PipeStreamerAdapter") +CREATE_LOGGERPTR_GLOBAL(logger_, "PipeStreamerAdapter") PipeStreamerAdapter::PipeStreamerAdapter() : is_ready_(false), - thread_(NULL), + thread_(threads::CreateThread("PipeStreamer", new Streamer(this))), messages_() { - LOG4CXX_INFO(logger, "PipeStreamerAdapter::PipeStreamerAdapter"); + LOG4CXX_AUTO_TRACE(logger_); } PipeStreamerAdapter::~PipeStreamerAdapter() { - LOG4CXX_INFO(logger, "PipeStreamerAdapter::~PipeStreamerAdapter"); + LOG4CXX_AUTO_TRACE(logger_); if ((0 != current_application_ ) && (is_ready_)) { StopActivity(current_application_); } - thread_->stop(); + thread_->join(); + delete thread_->delegate(); + threads::DeleteThread(thread_); } void PipeStreamerAdapter::SendData( int32_t application_key, const ::protocol_handler::RawMessagePtr message) { - LOG4CXX_INFO(logger, "PipeStreamerAdapter::SendData"); + LOG4CXX_AUTO_TRACE(logger_); if (application_key != current_application_) { - LOG4CXX_WARN(logger, "Wrong application " << application_key); + LOG4CXX_WARN(logger_, "Wrong application " << application_key); return; } @@ -76,10 +78,10 @@ void PipeStreamerAdapter::SendData( } void PipeStreamerAdapter::StartActivity(int32_t application_key) { - LOG4CXX_INFO(logger, "PipeStreamerAdapter::StartActivity"); + LOG4CXX_AUTO_TRACE(logger_); if (application_key == current_application_) { - LOG4CXX_WARN(logger, "Already started activity for " << application_key); + LOG4CXX_WARN(logger_, "Already started activity for " << application_key); return; } @@ -92,14 +94,14 @@ void PipeStreamerAdapter::StartActivity(int32_t application_key) { (*it)->OnActivityStarted(application_key); } - LOG4CXX_TRACE(logger, "Pipe was opened for writing " << named_pipe_path_); + LOG4CXX_DEBUG(logger_, "Pipe was opened for writing " << named_pipe_path_); } void PipeStreamerAdapter::StopActivity(int32_t application_key) { - LOG4CXX_INFO(logger, "PipeStreamerAdapter::StopActivity"); + LOG4CXX_AUTO_TRACE(logger_); if (application_key != current_application_) { - LOG4CXX_WARN(logger, "Not performing activity for " << application_key); + LOG4CXX_WARN(logger_, "Not performing activity for " << application_key); return; } @@ -113,18 +115,19 @@ void PipeStreamerAdapter::StopActivity(int32_t application_key) { } } -bool PipeStreamerAdapter::is_app_performing_activity( - int32_t application_key) { +bool PipeStreamerAdapter::is_app_performing_activity( int32_t application_key) { return (application_key == current_application_); } void PipeStreamerAdapter::Init() { - if (!thread_) { - LOG4CXX_INFO(logger, "Create and start sending thread"); - thread_ = threads::CreateThread("PipeStreamer", new Streamer(this)); - const size_t kStackSize = 16384; - thread_->startWithOptions(threads::ThreadOptions(kStackSize)); + LOG4CXX_AUTO_TRACE(logger_); + if (thread_->is_running()) { + thread_->stop(); + thread_->join(); } + LOG4CXX_DEBUG(logger_, "Start sending thread"); + const size_t kStackSize = 16384; + thread_->start(threads::ThreadOptions(kStackSize)); } PipeStreamerAdapter::Streamer::Streamer( @@ -139,7 +142,7 @@ PipeStreamerAdapter::Streamer::~Streamer() { } void PipeStreamerAdapter::Streamer::threadMain() { - LOG4CXX_INFO(logger, "Streamer::threadMain"); + LOG4CXX_AUTO_TRACE(logger_); open(); @@ -147,7 +150,7 @@ void PipeStreamerAdapter::Streamer::threadMain() { while (!server_->messages_.empty()) { ::protocol_handler::RawMessagePtr msg = server_->messages_.pop(); if (!msg) { - LOG4CXX_ERROR(logger, "Null pointer message"); + LOG4CXX_ERROR(logger_, "Null pointer message"); continue; } @@ -155,7 +158,7 @@ void PipeStreamerAdapter::Streamer::threadMain() { msg.get()->data_size()); if (ret == -1) { - LOG4CXX_ERROR(logger, "Failed writing data to pipe " + LOG4CXX_ERROR(logger_, "Failed writing data to pipe " << server_->named_pipe_path_); std::set<MediaListenerPtr>::iterator it = @@ -164,14 +167,14 @@ void PipeStreamerAdapter::Streamer::threadMain() { (*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 " + 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_INFO(logger, "Handling map streaming message. This is " + LOG4CXX_DEBUG(logger_, "Handling map streaming message. This is " << messsages_for_session << " the message for " << server_->current_application_); std::set<MediaListenerPtr>::iterator it = @@ -186,16 +189,14 @@ void PipeStreamerAdapter::Streamer::threadMain() { close(); } -bool PipeStreamerAdapter::Streamer::exitThreadMain() { - LOG4CXX_INFO(logger, "Streamer::exitThreadMain"); +void PipeStreamerAdapter::Streamer::exitThreadMain() { + LOG4CXX_AUTO_TRACE(logger_); stop_flag_ = true; server_->messages_.Shutdown(); - return false; } void PipeStreamerAdapter::Streamer::open() { - - LOG4CXX_INFO(logger, "Streamer::open() " << server_->named_pipe_path_.c_str()); + LOG4CXX_AUTO_TRACE(logger_); DCHECK(file_system::CreateDirectoryRecursively( profile::Profile::instance()->app_storage_folder())); @@ -203,22 +204,23 @@ void PipeStreamerAdapter::Streamer::open() { 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_); + LOG4CXX_ERROR(logger_, "Cannot create pipe " << server_->named_pipe_path_); return; } pipe_fd_ = ::open(server_->named_pipe_path_.c_str(), O_RDWR, 0); if (-1 == pipe_fd_) { - LOG4CXX_ERROR(logger, "Cannot open pipe for writing " + LOG4CXX_ERROR(logger_, "Cannot open pipe for writing " << server_->named_pipe_path_); return; } - LOG4CXX_TRACE(logger, "Pipe " << server_->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()); } diff --git a/src/components/media_manager/src/socket_streamer_adapter.cc b/src/components/media_manager/src/socket_streamer_adapter.cc index c6da8c7a75..4f3a805b45 100644 --- a/src/components/media_manager/src/socket_streamer_adapter.cc +++ b/src/components/media_manager/src/socket_streamer_adapter.cc @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2013, Ford Motor Company * All rights reserved. * @@ -51,14 +51,16 @@ CREATE_LOGGERPTR_GLOBAL(logger, "SocketStreamerAdapter") SocketStreamerAdapter::SocketStreamerAdapter() : socket_fd_(0), is_ready_(false), - thread_(NULL), - streamer_(NULL), + streamer_(new Streamer(this)), + thread_(threads::CreateThread("SocketStreamer", streamer_)), messages_() { } SocketStreamerAdapter::~SocketStreamerAdapter() { - thread_->stop(); - streamer_ = NULL; + LOG4CXX_AUTO_TRACE(logger); + thread_->join(); + delete streamer_; + threads::DeleteThread(thread_); } void SocketStreamerAdapter::StartActivity(int32_t application_key) { @@ -110,15 +112,9 @@ bool SocketStreamerAdapter::is_app_performing_activity( } void SocketStreamerAdapter::Init() { - if (!thread_) { - LOG4CXX_INFO(logger, "Create and start sending thread"); - streamer_ = new Streamer(this); - thread_ = threads::CreateThread("SocketStreamer", streamer_); - const size_t kStackSize = 16384; - thread_->startWithOptions(threads::ThreadOptions(kStackSize)); - } else { - LOG4CXX_WARN(logger, "thread is already exist"); - } + LOG4CXX_DEBUG(logger, "Start sending thread"); + const size_t kStackSize = 16384; + thread_->start(threads::ThreadOptions(kStackSize)); } void SocketStreamerAdapter::SendData( @@ -201,19 +197,16 @@ void SocketStreamerAdapter::Streamer::threadMain() { LOG4CXX_TRACE(logger,"exit " << this); } -bool SocketStreamerAdapter::Streamer::exitThreadMain() { +void SocketStreamerAdapter::Streamer::exitThreadMain() { LOG4CXX_TRACE(logger,"enter " << this); stop_flag_ = true; stop(); server_->messages_.Shutdown(); - //exith threadMainshould whait while threadMain will be finished if (server_->socket_fd_ != -1) { shutdown(server_->socket_fd_, SHUT_RDWR); close(server_->socket_fd_); } - sync_primitives::AutoLock auto_lock(thread_lock); LOG4CXX_TRACE(logger,"exit " << this); - return true; } void SocketStreamerAdapter::Streamer::start() { @@ -253,7 +246,7 @@ void SocketStreamerAdapter::Streamer::start() { void SocketStreamerAdapter::Streamer::stop() { LOG4CXX_TRACE(logger,"enter " << this); if (0 == new_socket_fd_) { - LOG4CXX_ERROR(logger, "Client Socket does not exits: "); + 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_)) { diff --git a/src/components/media_manager/src/streamer_listener.cc b/src/components/media_manager/src/streamer_listener.cc index 17306f486a..613744c768 100644 --- a/src/components/media_manager/src/streamer_listener.cc +++ b/src/components/media_manager/src/streamer_listener.cc @@ -59,7 +59,7 @@ void StreamerListener::OnErrorReceived( } void StreamerListener::OnActivityStarted(int32_t application_key) { - LOG4CXX_INFO(logger_, "StreamerListener::OnActivityStarted"); + LOG4CXX_AUTO_TRACE(logger_); if (current_application_ == application_key) { LOG4CXX_WARN(logger_, "Already performing activity for " << application_key); @@ -69,7 +69,7 @@ void StreamerListener::OnActivityStarted(int32_t application_key) { } void StreamerListener::OnActivityEnded(int32_t application_key) { - LOG4CXX_INFO(logger_, "StreamerListener::OnActivityEnded"); + LOG4CXX_AUTO_TRACE(logger_); if (current_application_ != application_key) { LOG4CXX_WARN(logger_, "Already not performing activity for " << application_key); 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 fc0668b8d3..77abddd57c 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,4 +1,4 @@ -/** +/* * Copyright (c) 2013, Ford Motor Company * All rights reserved. * @@ -38,7 +38,7 @@ namespace media_manager { CREATE_LOGGERPTR_GLOBAL(logger, "PipeVideoStreamerAdapter") PipeVideoStreamerAdapter::PipeVideoStreamerAdapter() { - LOG4CXX_INFO(logger, "PipeVideoStreamerAdapter::PipeVideoStreamerAdapter"); + LOG4CXX_AUTO_TRACE(logger); named_pipe_path_ = profile::Profile::instance()->named_video_pipe_path(); Init(); 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 9fe16d6e93..d4b3e0812b 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,4 +1,4 @@ -/** +/* * Copyright (c) 2013, Ford Motor Company * All rights reserved. * @@ -39,7 +39,7 @@ namespace media_manager { CREATE_LOGGERPTR_GLOBAL(logger, "SocketVideoStreamerAdapter") SocketVideoStreamerAdapter::SocketVideoStreamerAdapter() { - LOG4CXX_INFO(logger, "SocketVideoStreamerAdapter::SocketVideoStreamerAdapter"); + LOG4CXX_AUTO_TRACE(logger); port_ = profile::Profile::instance()->video_streaming_port(); ip_ = profile::Profile::instance()->server_address(); 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 983f1278c9..6b038a9fd2 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 @@ -42,25 +42,28 @@ CREATE_LOGGERPTR_GLOBAL(logger, "VideoStreamToFileAdapter") VideoStreamToFileAdapter::VideoStreamToFileAdapter(const std::string& file_name) : file_name_(file_name), is_ready_(false), - thread_(NULL) { + thread_(threads::CreateThread("VideoStreamer", + new Streamer(this))) { Init(); } VideoStreamToFileAdapter::~VideoStreamToFileAdapter() { + LOG4CXX_AUTO_TRACE(logger); if ((0 != current_application_ ) && (is_ready_)) { StopActivity(current_application_); } - - thread_->stop(); + thread_->join(); + delete thread_->delegate(); + threads::DeleteThread(thread_); } void VideoStreamToFileAdapter::Init() { - if (!thread_) { - LOG4CXX_INFO(logger, "Create and start sending thread"); - thread_ = threads::CreateThread("VideoStreamer", - new Streamer(this)); + if (thread_->is_running()) { + LOG4CXX_DEBUG(logger, "Start sending thread"); const size_t kStackSize = 16384; - thread_->startWithOptions(threads::ThreadOptions(kStackSize)); + thread_->start(threads::ThreadOptions(kStackSize)); + } else { + LOG4CXX_WARN(logger, "thread is already running"); } } @@ -169,11 +172,10 @@ void VideoStreamToFileAdapter::Streamer::threadMain() { close(); } -bool VideoStreamToFileAdapter::Streamer::exitThreadMain() { +void VideoStreamToFileAdapter::Streamer::exitThreadMain() { LOG4CXX_INFO(logger, "Streamer::exitThreadMain"); stop_flag_ = true; server_->messages_.Shutdown(); - return false; } void VideoStreamToFileAdapter::Streamer::open() { |