~phablet-team/aethercast/fix-for-microsoft-dongle

« back to all changes in this revision

Viewing changes to src/mcs/initgstreameronce.cpp

  • Committer: Tarmac
  • Author(s): Simon Fels
  • Date: 2016-03-15 08:36:21 UTC
  • mfrom: (130.1.1 ac-drop-gstreamer)
  • Revision ID: tarmac-20160315083621-f5ptj1tls050zpbq
Drop gstreamer backend

We're not going to support gstreamer as a streaming backend as of now. However this doesn't prevent us from bringing it back later but for now we want to remove that code portion to keep the code base we have to maintain as focused as possible and not ship code we never test or use.

Approved by Thomas Voß, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2015 Canonical, Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 */
17
 
 
18
 
#include <atomic>
19
 
 
20
 
#include <gst/gst.h>
21
 
 
22
 
#include "initgstreameronce.h"
23
 
#include "logger.h"
24
 
 
25
 
namespace {
26
 
void GstLog (GstDebugCategory *category,
27
 
          GstDebugLevel level,
28
 
          const gchar *file,
29
 
          const gchar *function,
30
 
          gint line,
31
 
          GObject *object,
32
 
          GstDebugMessage *message,
33
 
          gpointer user_data) {
34
 
 
35
 
    boost::optional<mcs::Logger::Location> location;
36
 
    if (file && function && line > 0) {
37
 
        location = mcs::Logger::Location{file, function, line};
38
 
    }
39
 
 
40
 
    mcs::Log().Log(mcs::GstDebugLevelToSeverity(level), gst_debug_message_get(message), location);
41
 
}
42
 
}
43
 
namespace mcs {
44
 
Logger::Severity GstDebugLevelToSeverity(GstDebugLevel level) {
45
 
    switch (level) {
46
 
    case GST_LEVEL_NONE:
47
 
    case GST_LEVEL_ERROR:
48
 
        return Logger::Severity::kError;
49
 
    case GST_LEVEL_WARNING:
50
 
    case GST_LEVEL_FIXME:
51
 
        return Logger::Severity::kWarning;
52
 
    case GST_LEVEL_INFO:
53
 
        return Logger::Severity::kInfo;
54
 
    case GST_LEVEL_DEBUG:
55
 
        return Logger::Severity::kDebug;
56
 
    case GST_LEVEL_LOG:
57
 
        return Logger::Severity::kDebug;
58
 
    case GST_LEVEL_TRACE:
59
 
    case GST_LEVEL_MEMDUMP:
60
 
        return Logger::Severity::kTrace;
61
 
    default:
62
 
        return Logger::Severity::kInfo;
63
 
    }
64
 
}
65
 
 
66
 
void InitGstreamerOnceOrThrow() {
67
 
    static std::atomic<bool> initialized(false);
68
 
    if (initialized.exchange(true))
69
 
        return;
70
 
 
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);
74
 
        g_error_free(error);
75
 
        throw std::runtime_error{what};
76
 
    }
77
 
 
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);
87
 
}
88
 
}