root/tags/perian-0.5/Codecprintf.c

Revision 57, 1.6 kB (checked in by gbooker, 2 years ago)

Use our Codecprintf for ffmpeg's av_log.
Fixes #3

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