2
* Copyright (C) 2015 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "initgstreameronce.h"
26
void GstLog (GstDebugCategory *category,
29
const gchar *function,
32
GstDebugMessage *message,
35
boost::optional<mcs::Logger::Location> location;
36
if (file && function && line > 0) {
37
location = mcs::Logger::Location{file, function, line};
40
mcs::Log().Log(mcs::GstDebugLevelToSeverity(level), gst_debug_message_get(message), location);
44
Logger::Severity GstDebugLevelToSeverity(GstDebugLevel level) {
48
return Logger::Severity::kError;
49
case GST_LEVEL_WARNING:
51
return Logger::Severity::kWarning;
53
return Logger::Severity::kInfo;
55
return Logger::Severity::kDebug;
57
return Logger::Severity::kDebug;
59
case GST_LEVEL_MEMDUMP:
60
return Logger::Severity::kTrace;
62
return Logger::Severity::kInfo;
66
void InitGstreamerOnceOrThrow() {
67
static std::atomic<bool> initialized(false);
68
if (initialized.exchange(true))
71
GError* error = nullptr;
72
if (gst_init_check(nullptr, nullptr, &error) == FALSE) {
73
auto what = Utils::Sprintf("Failed to initialize gstreamer (%s: %s)", g_quark_to_string(error->domain), error->message);
75
throw std::runtime_error{what};
78
// Get rid of gstreamer's default log function.
79
gst_debug_remove_log_function(nullptr);
80
// And install our own.
81
gst_debug_add_log_function(GstLog, nullptr, nullptr);
82
// No need to, our logging infra takes care of that, too.
83
gst_debug_set_colored(FALSE);
84
auto gst_debug = Utils::GetEnvValue("AETHERCAST_GST_DEBUG");
85
if (not gst_debug.empty())
86
gst_debug_set_threshold_from_string(gst_debug.c_str(), FALSE);