summaryrefslogtreecommitdiff
path: root/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc')
-rw-r--r--src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc117
1 files changed, 66 insertions, 51 deletions
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 181c8c61b..88c358a49 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>
@@ -45,23 +45,32 @@ 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) {
- 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 +78,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 +96,7 @@ void FromMicToFileRecorderThread::initArgs() {
}
void FromMicToFileRecorderThread::threadMain() {
- LOG4CXX_TRACE_ENTER(logger_);
+ LOG4CXX_AUTO_TRACE(logger_);
{
sync_primitives::AutoLock auto_lock(stopFlagLock_);
@@ -177,19 +186,25 @@ void FromMicToFileRecorderThread::threadMain() {
LOG4CXX_TRACE(logger_, "Initializing pipeline ...");
while (GST_STATE(pipeline) != GST_STATE_PLAYING) {
- LOG4CXX_TRACE(logger_, "GST_STATE(pipeline) != GST_STATE_PLAYING");
-
bool shouldBeStoped;
{
+ // FIXME(dchmerev@luxoft.com):
sync_primitives::AutoLock auto_lock(stopFlagLock_);
shouldBeStoped = shouldBeStoped_;
}
if (shouldBeStoped) {
+ gst_element_set_state(pipeline, GST_STATE_NULL);
+ gst_object_unref(GST_OBJECT(pipeline));
+ g_option_context_free(context);
+
+ if (argv_) {
+ delete [] argv_;
+ argv_ = NULL;
+ }
return;
}
}
-
LOG4CXX_TRACE(logger_, "Pipeline started ...\n");
// Start up a timer for the pipeline
@@ -211,6 +226,12 @@ void FromMicToFileRecorderThread::threadMain() {
LOG4CXX_TRACE(logger_, "Deleting pipeline\n");
gst_object_unref(GST_OBJECT(pipeline));
g_main_loop_unref(loop);
+ g_option_context_free(context);
+
+ if (argv_) {
+ delete [] argv_;
+ argv_ = NULL;
+ }
loop = NULL;
}
@@ -233,8 +254,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 +264,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