| 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 | #define CODEC_HEADER "Perian: " |
|---|
| 16 | |
|---|
| 17 | static int Codecvprintf(FILE *fileLog, const char *format, va_list va, int print_header) |
|---|
| 18 | { |
|---|
| 19 | int ret = 0; |
|---|
| 20 | |
|---|
| 21 | if(fileLog) |
|---|
| 22 | { |
|---|
| 23 | if(print_header) |
|---|
| 24 | fprintf(fileLog, CODEC_HEADER); |
|---|
| 25 | ret = vfprintf(fileLog, format, va); |
|---|
| 26 | fflush(fileLog); |
|---|
| 27 | } |
|---|
| 28 | else |
|---|
| 29 | { |
|---|
| 30 | #ifdef DEBUG_BUILD |
|---|
| 31 | if(print_header) |
|---|
| 32 | printf(CODEC_HEADER); |
|---|
| 33 | |
|---|
| 34 | ret = vprintf(format, va); |
|---|
| 35 | #endif |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | return ret; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | int Codecprintf(FILE *fileLog, const char *format, ...) |
|---|
| 42 | { |
|---|
| 43 | int ret; |
|---|
| 44 | va_list va; |
|---|
| 45 | va_start(va, format); |
|---|
| 46 | ret = Codecvprintf(fileLog, format, va, !fileLog); |
|---|
| 47 | va_end(va); |
|---|
| 48 | return ret; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | const char *FourCCString(FourCharCode c) |
|---|
| 52 | { |
|---|
| 53 | static char fourcc[sizeof("0xFFFF")] = {0}; |
|---|
| 54 | int i; |
|---|
| 55 | |
|---|
| 56 | //not a fourcc or twocc |
|---|
| 57 | if (c < '\0\0AA') { |
|---|
| 58 | snprintf(fourcc, sizeof(fourcc), "%#x", (unsigned)c); |
|---|
| 59 | } else { |
|---|
| 60 | for (i = 0; i < 4; i++) fourcc[i] = c >> 8*(3-i); |
|---|
| 61 | fourcc[4] = '\0'; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | return (char*)fourcc; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | void FourCCprintf(const char *string, FourCharCode a) |
|---|
| 68 | { |
|---|
| 69 | Codecprintf(NULL, "%s%s\n", string, FourCCString(a)); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | void FFMpegCodecprintf(void* ptr, int level, const char* fmt, va_list vl) |
|---|
| 73 | { |
|---|
| 74 | static int print_prefix=1; |
|---|
| 75 | int print_header = 1; |
|---|
| 76 | AVClass* avc= ptr ? *(AVClass**)ptr : NULL; |
|---|
| 77 | if(level>av_log_get_level()) |
|---|
| 78 | return; |
|---|
| 79 | |
|---|
| 80 | if(print_prefix && avc) { |
|---|
| 81 | Codecprintf(NULL, "[%s @ %p]", avc->item_name(ptr), avc); |
|---|
| 82 | print_header = 0; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | print_prefix= strstr(fmt, "\n") != NULL; |
|---|
| 86 | |
|---|
| 87 | Codecvprintf(NULL, fmt, vl, print_header); |
|---|
| 88 | } |
|---|