Line data Source code
1 : /*
2 : * GPAC - Multimedia Framework C SDK
3 : *
4 : * Authors: Deniz Ugur, Romain Bouqueau, Sohaib Larbi
5 : * Copyright (c) Motion Spell
6 : * All rights reserved
7 : *
8 : * This file is part of the GPAC/GStreamer wrapper
9 : *
10 : * This GPAC/GStreamer wrapper is free software; you can redistribute it
11 : * and/or modify it under the terms of the GNU Affero General Public License
12 : * as published by the Free Software Foundation; either version 3, or (at
13 : * your option) any later version.
14 : *
15 : * This GPAC/GStreamer wrapper is distributed in the hope that it will be
16 : * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : * GNU Affero General Public License for more details.
19 : *
20 : * You should have received a copy of the GNU Affero General Public
21 : * License along with this library; see the file LICENSE. If not, write to
22 : * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 : *
24 : */
25 :
26 : #include "lib/main.h"
27 : #include "gpacmessages.h"
28 :
29 : static void
30 2849993 : gpac_log_callback(void* cbck,
31 : GF_LOG_Level log_level,
32 : GF_LOG_Tool log_tool,
33 : const char* fmt,
34 : va_list vlist)
35 : {
36 : /* Define a custom log category for GPAC */
37 : static GstDebugCategory* gpac_cat = NULL;
38 2849993 : if (G_UNLIKELY(gpac_cat == NULL)) {
39 1 : gpac_cat = _gst_debug_get_category("gpac");
40 1 : if (gpac_cat == NULL) {
41 1 : gpac_cat =
42 1 : _gst_debug_category_new("gpac", 0, "GPAC GStreamer integration");
43 : }
44 : }
45 :
46 2849993 : GstElement* element = (GstElement*)cbck;
47 :
48 : char msg[1024];
49 2849993 : vsnprintf(msg, sizeof(msg), fmt, vlist);
50 2849993 : size_t len = strlen(msg);
51 2849993 : if (len > 0 && msg[len - 1] == '\n')
52 2849965 : msg[len - 1] = '\0';
53 :
54 2849993 : switch (log_level) {
55 0 : case GF_LOG_ERROR:
56 0 : GST_CAT_ERROR_OBJECT(gpac_cat, element, "%s", msg);
57 0 : break;
58 20 : case GF_LOG_WARNING:
59 20 : GST_CAT_WARNING_OBJECT(gpac_cat, element, "%s", msg);
60 20 : break;
61 8767 : case GF_LOG_INFO:
62 8767 : GST_CAT_INFO_OBJECT(gpac_cat, element, "%s", msg);
63 8767 : break;
64 2841206 : case GF_LOG_DEBUG:
65 2841206 : GST_CAT_DEBUG_OBJECT(gpac_cat, element, "%s", msg);
66 2841206 : break;
67 0 : default:
68 0 : GST_CAT_LOG_OBJECT(gpac_cat, element, "%s", msg);
69 0 : break;
70 : }
71 2849993 : }
72 :
73 : gboolean
74 16 : gpac_init(GPAC_Context* ctx, GstElement* element)
75 : {
76 16 : gpac_return_val_if_fail(gf_sys_init(GF_MemTrackerNone, NULL), FALSE);
77 16 : gf_log_set_callback(element, gpac_log_callback);
78 16 : gf_log_set_tools_levels("all@debug", GF_TRUE);
79 16 : return TRUE;
80 : }
81 :
82 : void
83 16 : gpac_destroy(GPAC_Context* ctx)
84 : {
85 16 : gf_sys_close();
86 16 : }
|