• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
welsStderrTrace(void * ctx,int level,const char * string)49 static void welsStderrTrace (void* ctx, int level, const char* string) {
50   fprintf (stderr, "%s\n", string);
51 }
52 
welsCodecTrace()53 welsCodecTrace::welsCodecTrace() {
54 
55   m_iTraceLevel = WELS_LOG_DEFAULT;
56   m_fpTrace = welsStderrTrace;
57   m_pTraceCtx = NULL;
58 
59   m_sLogCtx.pLogCtx = this;
60   m_sLogCtx.pfLog = StaticCodecTrace;
61   m_sLogCtx.pCodecInstance = NULL;
62 }
63 
~welsCodecTrace()64 welsCodecTrace::~welsCodecTrace() {
65   m_fpTrace = NULL;
66 }
67 
68 
69 
StaticCodecTrace(void * pCtx,const int32_t iLevel,const char * Str_Format,va_list vl)70 void welsCodecTrace::StaticCodecTrace (void* pCtx, const int32_t iLevel, const char* Str_Format, va_list vl) {
71   welsCodecTrace* self = (welsCodecTrace*) pCtx;
72   self->CodecTrace (iLevel, Str_Format, vl);
73 }
74 
CodecTrace(const int32_t iLevel,const char * Str_Format,va_list vl)75 void welsCodecTrace::CodecTrace (const int32_t iLevel, const char* Str_Format, va_list vl) {
76   if (m_iTraceLevel < iLevel) {
77     return;
78   }
79 
80   char pBuf[MAX_LOG_SIZE] = {0};
81   WelsVsnprintf (pBuf, MAX_LOG_SIZE, Str_Format, vl); // confirmed_safe_unsafe_usage
82   if (m_fpTrace) {
83     m_fpTrace (m_pTraceCtx, iLevel, pBuf);
84   }
85 }
86 
SetCodecInstance(void * pCodecInstance)87 void welsCodecTrace::SetCodecInstance (void* pCodecInstance) {
88   m_sLogCtx.pCodecInstance = pCodecInstance;
89 }
90 
SetTraceLevel(const int32_t iLevel)91 void welsCodecTrace::SetTraceLevel (const int32_t iLevel) {
92   if (iLevel >= 0)
93     m_iTraceLevel = iLevel;
94 }
95 
SetTraceCallback(WelsTraceCallback func)96 void welsCodecTrace::SetTraceCallback (WelsTraceCallback func) {
97   m_fpTrace = func;
98 }
99 
SetTraceCallbackContext(void * ctx)100 void welsCodecTrace::SetTraceCallbackContext (void* ctx) {
101   m_pTraceCtx = ctx;
102 }
103 
104