| 1 |
/* |
|---|
| 2 |
* Codecprintf.c |
|---|
| 3 |
* Perian |
|---|
| 4 |
* |
|---|
| 5 |
* Created by Augie Fackler on 7/16/06. |
|---|
| 6 |
* Copyright 2006 Perian Project. All rights reserved. |
|---|
| 7 |
* |
|---|
| 8 |
*/ |
|---|
| 9 |
|
|---|
| 10 |
#include "Codecprintf.h" |
|---|
| 11 |
#include <stdio.h> |
|---|
| 12 |
#include <stdarg.h> |
|---|
| 13 |
#include "log.h" |
|---|
| 14 |
|
|---|
| 15 |
#ifdef DEBUG_BUILD |
|---|
| 16 |
#define CODEC_HEADER "Perian Codec: " |
|---|
| 17 |
#define FILELOG |
|---|
| 18 |
|
|---|
| 19 |
static int Codecvprintf(FILE *fileLog, const char *format, va_list va, int print_header) |
|---|
| 20 |
{ |
|---|
| 21 |
int ret; |
|---|
| 22 |
|
|---|
| 23 |
#ifdef FILELOG |
|---|
| 24 |
if(fileLog) |
|---|
| 25 |
{ |
|---|
| 26 |
if(print_header) |
|---|
| 27 |
fprintf(fileLog, CODEC_HEADER); |
|---|
| 28 |
ret = vfprintf(fileLog, format, va); |
|---|
| 29 |
fflush(fileLog); |
|---|
| 30 |
} |
|---|
| 31 |
else |
|---|
| 32 |
{ |
|---|
| 33 |
#endif |
|---|
| 34 |
if(print_header) |
|---|
| 35 |
printf(CODEC_HEADER); |
|---|
| 36 |
|
|---|
| 37 |
ret = vprintf(format, va); |
|---|
| 38 |
#ifdef FILELOG |
|---|
| 39 |
} |
|---|
| 40 |
#endif |
|---|
| 41 |
|
|---|
| 42 |
return ret; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
int Codecprintf(FILE *fileLog, const char *format, ...) |
|---|
| 46 |
{ |
|---|
| 47 |
int ret; |
|---|
| 48 |
va_list va; |
|---|
| 49 |
va_start(va, format); |
|---|
| 50 |
ret = Codecvprintf(fileLog, format, va, !fileLog); |
|---|
| 51 |
va_end(va); |
|---|
| 52 |
return ret; |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
const char *FourCCString(FourCharCode c) |
|---|
| 56 |
{ |
|---|
| 57 |
static unsigned char fourcc[5] = {0}; |
|---|
| 58 |
int i; |
|---|
| 59 |
|
|---|
| 60 |
for (i = 0; i < 4; i++) fourcc[i] = c >> 8*(3-i); |
|---|
| 61 |
|
|---|
| 62 |
return (char*)fourcc; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
void FourCCprintf (char *string, FourCharCode a) |
|---|
| 66 |
{ |
|---|
| 67 |
Codecprintf(NULL, "%s%s\n", string, FourCCString(a)); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
#else |
|---|
| 71 |
#define Codecvprintf(file, fmt, va, print_header) /**/ |
|---|
| 72 |
#endif |
|---|
| 73 |
|
|---|
| 74 |
void FFMpegCodecprintf(void* ptr, int level, const char* fmt, va_list vl) |
|---|
| 75 |
{ |
|---|
| 76 |
static int print_prefix=1; |
|---|
| 77 |
int print_header = 1; |
|---|
| 78 |
AVClass* avc= ptr ? *(AVClass**)ptr : NULL; |
|---|
| 79 |
if(level>av_log_level) |
|---|
| 80 |
return; |
|---|
| 81 |
|
|---|
| 82 |
if(print_prefix && avc) { |
|---|
| 83 |
Codecprintf(NULL, "[%s @ %p]", avc->item_name(ptr), avc); |
|---|
| 84 |
print_header = 0; |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
print_prefix= strstr(fmt, "\n") != NULL; |
|---|
| 88 |
|
|---|
| 89 |
Codecvprintf(NULL, fmt, vl, print_header); |
|---|
| 90 |
} |
|---|