/src/openh264/codec/common/src/welsCodecTrace.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /*! |
2 | | * \copy |
3 | | * Copyright (c) 2013, Cisco Systems |
4 | | * All rights reserved. |
5 | | * |
6 | | * Redistribution and use in source and binary forms, with or without |
7 | | * modification, are permitted provided that the following conditions |
8 | | * are met: |
9 | | * |
10 | | * * Redistributions of source code must retain the above copyright |
11 | | * notice, this list of conditions and the following disclaimer. |
12 | | * |
13 | | * * Redistributions in binary form must reproduce the above copyright |
14 | | * notice, this list of conditions and the following disclaimer in |
15 | | * the documentation and/or other materials provided with the |
16 | | * distribution. |
17 | | * |
18 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
21 | | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
22 | | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
23 | | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
24 | | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
25 | | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
26 | | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
28 | | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | | * POSSIBILITY OF SUCH DAMAGE. |
30 | | * |
31 | | */ |
32 | | |
33 | | #ifdef _WIN32 |
34 | | #include <windows.h> |
35 | | #include <tchar.h> |
36 | | #endif |
37 | | |
38 | | #include <stdio.h> |
39 | | #include <stdarg.h> |
40 | | #include <string.h> |
41 | | |
42 | | #include "crt_util_safe_x.h" // Safe CRT routines like utils for cross platforms |
43 | | |
44 | | #include "welsCodecTrace.h" |
45 | | #include "utils.h" |
46 | | |
47 | | |
48 | | |
49 | 0 | static void welsStderrTrace (void* ctx, int level, const char* string) { |
50 | 0 | fprintf (stderr, "%s\n", string); |
51 | 0 | } |
52 | | |
53 | 23.7k | welsCodecTrace::welsCodecTrace() { |
54 | | |
55 | 23.7k | m_iTraceLevel = WELS_LOG_DEFAULT; |
56 | 23.7k | m_fpTrace = welsStderrTrace; |
57 | 23.7k | m_pTraceCtx = NULL; |
58 | | |
59 | 23.7k | m_sLogCtx.pLogCtx = this; |
60 | 23.7k | m_sLogCtx.pfLog = StaticCodecTrace; |
61 | 23.7k | m_sLogCtx.pCodecInstance = NULL; |
62 | 23.7k | } |
63 | | |
64 | 23.7k | welsCodecTrace::~welsCodecTrace() { |
65 | 23.7k | m_fpTrace = NULL; |
66 | 23.7k | } |
67 | | |
68 | | |
69 | | |
70 | 10.8M | void welsCodecTrace::StaticCodecTrace (void* pCtx, const int32_t iLevel, const char* Str_Format, va_list vl) { |
71 | 10.8M | welsCodecTrace* self = (welsCodecTrace*) pCtx; |
72 | 10.8M | self->CodecTrace (iLevel, Str_Format, vl); |
73 | 10.8M | } |
74 | | |
75 | 10.8M | void welsCodecTrace::CodecTrace (const int32_t iLevel, const char* Str_Format, va_list vl) { |
76 | 10.8M | if (m_iTraceLevel < iLevel) { |
77 | 10.8M | return; |
78 | 10.8M | } |
79 | | |
80 | 0 | char pBuf[MAX_LOG_SIZE] = {0}; |
81 | 0 | WelsVsnprintf (pBuf, MAX_LOG_SIZE, Str_Format, vl); // confirmed_safe_unsafe_usage |
82 | 0 | if (m_fpTrace) { |
83 | 0 | m_fpTrace (m_pTraceCtx, iLevel, pBuf); |
84 | 0 | } |
85 | 0 | } |
86 | | |
87 | 23.7k | void welsCodecTrace::SetCodecInstance (void* pCodecInstance) { |
88 | 23.7k | m_sLogCtx.pCodecInstance = pCodecInstance; |
89 | 23.7k | } |
90 | | |
91 | 47.5k | void welsCodecTrace::SetTraceLevel (const int32_t iLevel) { |
92 | 47.5k | if (iLevel >= 0) |
93 | 47.5k | m_iTraceLevel = iLevel; |
94 | 47.5k | } |
95 | | |
96 | 0 | void welsCodecTrace::SetTraceCallback (WelsTraceCallback func) { |
97 | 0 | m_fpTrace = func; |
98 | 0 | } |
99 | | |
100 | 0 | void welsCodecTrace::SetTraceCallbackContext (void* ctx) { |
101 | 0 | m_pTraceCtx = ctx; |
102 | 0 | } |
103 | | |