/src/vvenc/source/Lib/Utilities/MsgLog.h
Line | Count | Source |
1 | | /* ----------------------------------------------------------------------------- |
2 | | The copyright in this software is being made available under the Clear BSD |
3 | | License, included below. No patent rights, trademark rights and/or |
4 | | other Intellectual Property Rights other than the copyrights concerning |
5 | | the Software are granted under this license. |
6 | | |
7 | | The Clear BSD License |
8 | | |
9 | | Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors. |
10 | | All rights reserved. |
11 | | |
12 | | Redistribution and use in source and binary forms, with or without modification, |
13 | | are permitted (subject to the limitations in the disclaimer below) provided that |
14 | | the following conditions are met: |
15 | | |
16 | | * Redistributions of source code must retain the above copyright notice, |
17 | | this list of conditions and the following disclaimer. |
18 | | |
19 | | * Redistributions in binary form must reproduce the above copyright |
20 | | notice, this list of conditions and the following disclaimer in the |
21 | | documentation and/or other materials provided with the distribution. |
22 | | |
23 | | * Neither the name of the copyright holder nor the names of its |
24 | | contributors may be used to endorse or promote products derived from this |
25 | | software without specific prior written permission. |
26 | | |
27 | | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY |
28 | | THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
29 | | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
31 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
32 | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
33 | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
34 | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
35 | | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
36 | | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
37 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
38 | | POSSIBILITY OF SUCH DAMAGE. |
39 | | |
40 | | |
41 | | ------------------------------------------------------------------------------------------- */ |
42 | | /** |
43 | | \file MsgLog.h |
44 | | \brief A logger for the logging callback function |
45 | | */ |
46 | | |
47 | | #pragma once |
48 | | |
49 | | #include <functional> |
50 | | #include <stdarg.h> |
51 | | #include <mutex> |
52 | | |
53 | | #include "CommonLib/CommonDef.h" |
54 | | #include "vvenc/vvenc.h" |
55 | | |
56 | | namespace vvenc { |
57 | | |
58 | | static std::mutex m_msgMutex; |
59 | | |
60 | | class MsgLog |
61 | | { |
62 | | public: |
63 | | |
64 | 0 | MsgLog(){} |
65 | | MsgLog(void *msgCtx, vvencLoggingCallback msgFnc) |
66 | 0 | { |
67 | 0 | m_msgCtx = msgCtx; |
68 | 0 | m_msgFnc = msgFnc; |
69 | 0 | } |
70 | | |
71 | 0 | ~MsgLog() {}; |
72 | | |
73 | | void setCallback( void *msgCtx, vvencLoggingCallback msgFnc ) |
74 | 0 | { |
75 | 0 | m_msgCtx = msgCtx; |
76 | 0 | m_msgFnc = msgFnc; |
77 | 0 | } |
78 | | |
79 | | void log( int level, const char* fmt, ... ) |
80 | 0 | { |
81 | 0 | if ( this->m_msgFnc ) |
82 | 0 | { |
83 | 0 | std::unique_lock<std::mutex> _lock( m_msgMutex ); |
84 | 0 | va_list args; |
85 | 0 | va_start( args, fmt ); |
86 | 0 | m_msgFnc( m_msgCtx, level, fmt, args ); |
87 | 0 | va_end( args ); |
88 | 0 | } |
89 | 0 | else if ( g_msgFnc ) |
90 | 0 | { |
91 | | // global log (deprecated) |
92 | 0 | std::unique_lock<std::mutex> _lock( m_msgMutex ); |
93 | 0 | va_list args; |
94 | 0 | va_start( args, fmt ); |
95 | 0 | g_msgFnc( g_msgFncCtx, level, fmt, args ); |
96 | | va_end( args ); |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | | private: |
101 | | std::function<void( void*, int, const char*, va_list )> m_msgFnc{}; |
102 | | void *m_msgCtx{}; |
103 | | }; |
104 | | |
105 | | } // namespace vvenc |