diff options
Diffstat (limited to 'src/components/media_manager/src/audio/a2dp_source_player_adapter.cc')
-rw-r--r-- | src/components/media_manager/src/audio/a2dp_source_player_adapter.cc | 106 |
1 files changed, 49 insertions, 57 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..a6a36ef547 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) 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 <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->second; + 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->second; + 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_; } |