This repository has been archived by the owner on Jul 30, 2022. It is now read-only.
mirrored from https://chromium.googlesource.com/webm/webmquicktime
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathlog.c
153 lines (109 loc) · 3.38 KB
/
log.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright (c) 2010 The WebM project authors. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
#include "log.h"
#if ENABLE_DEBUG_LOG
#include <sys/time.h>
#include <stdarg.h>
#include <QuickTime/QuickTime.h>
#define OUTPUT_FILE "/var/tmp/webm_debug.txt"
static FILE *defaultLogFile = NULL;
static inline void _check_init_logfile()
{
if (!defaultLogFile) {
defaultLogFile = fopen(OUTPUT_FILE, "a");
}
}
void log_time(FILE *logFile, const char *id, const char *fmt, ...)
{
if (logFile == 0)
return;
va_list ap;
struct timeval now;
char info[80];
va_start(ap, fmt);
vsnprintf(info, 80, fmt, ap);
info[79] = 0;
va_end(ap);
gettimeofday(&now, NULL);
fprintf(logFile, "%s, %d%06d, -- %s\n", id, (int) now.tv_sec,
now.tv_usec, info);
}
void dbg_printf(const char *s, ...)
{
va_list args;
int count;
time_t time_val = time(NULL);
struct tm *now = NULL;
_check_init_logfile();
now = localtime(&time_val);
fprintf(defaultLogFile, "%d-%02d:%02d:%02d -- ", getpid(),
now->tm_hour, now->tm_min, now->tm_sec);
va_start(args, s);
count = vfprintf(defaultLogFile, s, args);
va_end(args);
if (count < 0) {
fprintf(defaultLogFile, "\ndbg_printf error (%d) in \"%s\" - aborting.\n", count, s);
fflush(NULL);
abort();
}
fflush(defaultLogFile);
}
void dbg_dumpBytes(unsigned char *bytes, int size)
{
int i;
FILE *logFile = fopen(OUTPUT_FILE, "a");
time_t time_val = time(NULL);
struct tm *now = NULL;
now = localtime(&time_val);
fprintf(logFile, "%d-%d:%d:%d\n", getpid(), now->tm_hour, now->tm_min, now->tm_sec);
int mysize = size < 3000 ? size : 3000;
for (i = 0; i < mysize; i++)
{
if (i % 40 == 0)
{
fprintf(logFile, "\n");
}
fprintf(logFile, "%x ", bytes[i]);
}
fprintf(logFile, "\n");
fclose(logFile);
}
static void _dbg_dumpAtom(QTAtomContainer container, QTAtom head, int level)
{
short numChildren = QTCountChildrenOfType(container, head, 0);
QTAtomType atomType;
QTAtomID id;
QTGetAtomTypeAndID(container, head, &atomType, &id);
int i;
char *indent = malloc(level + 1);
memset(indent, ' ', level);
indent[level] = 0;
dbg_printf("%s id %ld type %4.4s children %d\n", indent, id, (char *)&atomType, numChildren);
free(indent);
//print all children
int ref;
QTAtom curChild, nextChild;
curChild = 0;
for (ref = 0; ref < numChildren; ref++)
{
ComponentResult err = QTNextChildAnyType(container, head, curChild, &nextChild);
if (err) break;
_dbg_dumpAtom(container, nextChild, level + 1);
curChild = nextChild;
}
}
void dbg_dumpAtom(QTAtomContainer container)
{
_dbg_dumpAtom(container, 0, 0);
}
#else //ENABLE_DEBUG_LOG
void log_time(FILE *logFile, const char *id, const char *fmt, ...) {};
void dbg_printf(const char *s, ...) {};
void dbg_dumpBytes(unsigned char *bytes, int size) {};
void dbg_dumpAtom(QTAtomContainer container) {};
#endif //ENABLE_DEBUG_LOG