Line data Source code
1 : /*
2 : * If not stated otherwise in this file or this component's LICENSE file the
3 : * following copyright and licenses apply:
4 : *
5 : * Copyright 2022 Sky UK
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : #include "GstLogForwarding.h"
21 : #include "RialtoLogging.h"
22 : #include <gst/gst.h>
23 : #include <sstream>
24 :
25 : namespace
26 : {
27 0 : void gstreamerLogFunction(GstDebugCategory *category, GstDebugLevel level, const gchar *file, const gchar *function,
28 : gint line, GObject *object, GstDebugMessage *message, gpointer data)
29 : {
30 0 : std::stringstream ss;
31 0 : switch (level)
32 : {
33 0 : case GST_LEVEL_NONE:
34 : case GST_LEVEL_ERROR:
35 : {
36 0 : ss << "ERR: ";
37 0 : break;
38 : }
39 0 : case GST_LEVEL_WARNING:
40 : {
41 0 : ss << "WRN: ";
42 0 : break;
43 : }
44 0 : case GST_LEVEL_FIXME:
45 : {
46 0 : ss << "FIXME: ";
47 0 : break;
48 : }
49 0 : case GST_LEVEL_INFO:
50 : {
51 0 : ss << "NFO: ";
52 0 : break;
53 : }
54 0 : case GST_LEVEL_DEBUG:
55 : {
56 0 : ss << "DBG: ";
57 0 : break;
58 : }
59 0 : case GST_LEVEL_LOG:
60 : {
61 0 : ss << "LOG: ";
62 0 : break;
63 : }
64 0 : case GST_LEVEL_TRACE:
65 : {
66 0 : ss << "TRACE: ";
67 0 : break;
68 : }
69 0 : case GST_LEVEL_MEMDUMP:
70 : {
71 0 : ss << "MEMDUMP: ";
72 0 : break;
73 : }
74 0 : case GST_LEVEL_COUNT:
75 : {
76 0 : ss << "COUNT: ";
77 0 : break;
78 : }
79 0 : default:
80 : {
81 0 : break;
82 : }
83 : }
84 0 : ss << "C:" << gst_debug_category_get_name(category) << " M:" << file << " F:" << function << ":" << line;
85 0 : if (object)
86 : {
87 0 : if (GST_IS_PAD(object) && GST_OBJECT_NAME(object) && GST_OBJECT_PARENT(object) &&
88 0 : GST_OBJECT_NAME(GST_OBJECT_PARENT(object)))
89 : {
90 0 : ss << " <" << GST_OBJECT_NAME(GST_OBJECT_PARENT(object)) << ":" << GST_OBJECT_NAME(object) << ">";
91 : }
92 0 : else if (GST_IS_OBJECT(object) && GST_OBJECT_NAME(object))
93 : {
94 0 : ss << " <" << GST_OBJECT_NAME(object) << ">";
95 : }
96 0 : else if (G_IS_OBJECT(object))
97 : {
98 0 : ss << " <" << G_OBJECT_TYPE_NAME(object) << "@" << static_cast<void *>(object) << ">";
99 : }
100 : else
101 : {
102 0 : ss << " <" << static_cast<void *>(object) << ">";
103 : }
104 : }
105 0 : ss << ": " << gst_debug_message_get(message);
106 0 : RIALTO_LOG_EXTERNAL("%s", ss.str().c_str());
107 : }
108 : } // namespace
109 :
110 : namespace firebolt::rialto::server
111 : {
112 4 : void enableGstLogForwarding()
113 : {
114 4 : gst_debug_remove_log_function(gst_debug_log_default);
115 4 : gst_debug_add_log_function(gstreamerLogFunction, nullptr, nullptr);
116 : }
117 : } // namespace firebolt::rialto::server
|