forked from MaddTheSane/perian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Codecprintf.c
101 lines (85 loc) · 2.35 KB
/
Codecprintf.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
/*
* Codecprintf.c
* Created by Augie Fackler on 7/16/06.
*
* This file is part of Perian.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdarg.h>
#include <libavutil/log.h>
#include "Codecprintf.h"
#define CODEC_HEADER "Perian: "
static int Codecvprintf(FILE *fileLog, const char *format, va_list va, int print_header)
{
int ret = 0;
if(fileLog)
{
if(print_header)
fprintf(fileLog, CODEC_HEADER);
ret = vfprintf(fileLog, format, va);
fflush(fileLog);
}
else
{
#ifdef DEBUG_BUILD
if(print_header)
printf(CODEC_HEADER);
ret = vprintf(format, va);
#endif
}
return ret;
}
int Codecprintf(FILE *fileLog, const char *format, ...)
{
int ret;
va_list va;
va_start(va, format);
ret = Codecvprintf(fileLog, format, va, !fileLog);
va_end(va);
return ret;
}
const char *FourCCString(FourCharCode c)
{
static char fourcc[sizeof("0xFFFF")] = {0};
int i;
//not a fourcc or twocc
if (c < '\0\0AA') {
snprintf(fourcc, sizeof(fourcc), "%#x", (unsigned)c);
} else {
for (i = 0; i < 4; i++) fourcc[i] = c >> 8*(3-i);
fourcc[4] = '\0';
}
return (char*)fourcc;
}
void FourCCprintf(const char *string, FourCharCode a)
{
Codecprintf(NULL, "%s%s\n", string, FourCCString(a));
}
void FFMpegCodecprintf(void* ptr, int level, const char* fmt, va_list vl)
{
static int print_prefix=1;
int print_header = 1;
AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
if(level>av_log_get_level())
return;
if(print_prefix && avc) {
Codecprintf(NULL, "[%s @ %p]", avc->item_name(ptr), avc);
print_header = 0;
}
print_prefix= strstr(fmt, "\n") != NULL;
Codecvprintf(NULL, fmt, vl, print_header);
}