diff options
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.cc | 47 |
1 files changed, 32 insertions, 15 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 0239795d75..99548e71bd 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 @@ -32,6 +32,7 @@ #include "media_manager/audio/from_mic_to_file_recorder_thread.h" #include <unistd.h> +#include <cstring> #include <sstream> #include "utils/logger.h" @@ -88,11 +89,23 @@ void FromMicToFileRecorderThread::initArgs() { argv_[3] = new gchar[3]; argv_[4] = new gchar[durationString_.length() + 1]; - argv_[0] = const_cast<gchar*>(std::string("AudioManager").c_str()); - argv_[1] = const_cast<gchar*>(oKey_.c_str()); - argv_[2] = const_cast<gchar*>(outputFileName_.c_str()); - argv_[3] = const_cast<gchar*>(tKey_.c_str()); - argv_[4] = const_cast<gchar*>(durationString_.c_str()); + std::strcpy(argv_[0], "AudioManager"); + std::strcpy(argv_[1], oKey_.c_str()); + std::strcpy(argv_[2], outputFileName_.c_str()); + std::strcpy(argv_[3], tKey_.c_str()); + std::strcpy(argv_[4], durationString_.c_str()); +} + +void FromMicToFileRecorderThread::deinitArgs() { + LOG4CXX_AUTO_TRACE(logger_); + + if (argv_) { + for (int32_t i = 0; i < argc_; i++) { + delete[] argv_[i]; + } + delete[] argv_; + argv_ = NULL; + } } void FromMicToFileRecorderThread::threadMain() { @@ -136,6 +149,13 @@ void FromMicToFileRecorderThread::threadMain() { "length of time in seconds to capture", "int32_t"}, {NULL}}; + // g_option_context_parse() modifies params, so keep argc_ and argv_ + int32_t argc = argc_; + gchar** argv = new gchar* [argc]; + for (int32_t i = 0; i < argc; i++) { + argv[i] = argv_[i]; + } + #ifndef GLIB_VERSION_2_32 // g_thread_init() does nothing since 2.32 if (!g_thread_supported()) { g_thread_init(NULL); @@ -145,7 +165,7 @@ void FromMicToFileRecorderThread::threadMain() { context = g_option_context_new("-- M-AUDIO RAW"); g_option_context_add_main_entries(context, entries, NULL); g_option_context_add_group(context, gst_init_get_option_group()); - if (!g_option_context_parse(context, &argc_, &argv_, &err)) { + if (!g_option_context_parse(context, &argc, &argv, &err)) { g_error("%s\n", err->message); } @@ -159,7 +179,10 @@ void FromMicToFileRecorderThread::threadMain() { LOG4CXX_TRACE(logger_, "Duration set to: " << duration); // Initialize gstreamer and setup the main loop information - gst_init(&argc_, &argv_); + gst_init(&argc, &argv); + + delete[] argv; + argv = NULL; pipeline = gst_pipeline_new("vga2usb-h264"); @@ -207,10 +230,7 @@ void FromMicToFileRecorderThread::threadMain() { gst_object_unref(GST_OBJECT(pipeline)); g_option_context_free(context); - if (argv_) { - delete[] argv_; - argv_ = NULL; - } + deinitArgs(); return; } } @@ -238,10 +258,7 @@ void FromMicToFileRecorderThread::threadMain() { g_main_loop_unref(loop); g_option_context_free(context); - if (argv_) { - delete[] argv_; - argv_ = NULL; - } + deinitArgs(); loop = NULL; } |