[Ffmpeg-devel] [PATCH/RFC] change (f)printf calls in libpostproc to av_log

Diego Biurrun diego
Tue Oct 10 01:12:10 CEST 2006


On Sun, Oct 08, 2006 at 11:36:00PM +0200, Michael Niedermayer wrote:
> 
> On Sun, Oct 08, 2006 at 01:58:13PM +0200, Diego Biurrun wrote:
> > This changes all printf/fprintf occurrences in libpostproc to av_log.  I
> > used NULL as context, if there is a better alternative, let me know.
> 
> yes use the PPContext (add a AVClass as first field) like AVCodecContexts

More or less like the attached patch?  Thanks to Oded for some help.

Diego
-------------- next part --------------
Index: libpostproc/postprocess_template.c
===================================================================
--- libpostproc/postprocess_template.c	(revision 6597)
+++ libpostproc/postprocess_template.c	(working copy)
@@ -896,7 +896,7 @@
                         num++;
                         if(num%1000000 == 0)
                         {
-                                printf(" %d %d %d %d\n", num, sum, max, bias);
+                                av_log(c, AV_LOG_INFO, " %d %d %d %d\n", num, sum, max, bias);
                         }
                 }
         }
@@ -1507,7 +1507,7 @@
 
                                         if(1024LL*1024LL*1024LL % numSkiped == 0)
                                         {
-                                                printf( "sum:%1.3f, skip:%d, wQP:%d, "
+                                                av_log(c, AV_LOG_INFO, "sum:%1.3f, skip:%d, wQP:%d, "
                                                         "wRange:%d, wDiff:%d, relSkip:%1.3f\n",
                                                         (float)errorSum/numSkiped, numSkiped, worstQP, worstRange,
                                                         worstDiff, (float)numSkiped/numPixels);
@@ -2535,7 +2535,6 @@
                 :: "r" (src), "r" (tempBlured), "r"((long)stride), "m" (tempBluredPast)
                 : "%"REG_a, "%"REG_d, "%"REG_c, "memory"
                 );
-//printf("%d\n", test);
 #else //defined (HAVE_MMX2) || defined (HAVE_3DNOW)
 {
         int y;
@@ -2568,7 +2567,6 @@
         *tempBluredPast=i;
 //        ((*tempBluredPast)*3 + d + 2)>>2;
 
-//printf("%d %d %d\n", maxNoise[0], maxNoise[1], maxNoise[2]);
 /*
 Switch between
  1  0  0  0  0  0  0  (0)
@@ -3415,9 +3413,7 @@
                 for(i=0; i<256; i++)
                 {
                         sum+= yHistogram[i];
-//                        printf("%d ", yHistogram[i]);
                 }
-//                printf("\n\n");
 
                 /* we allways get a completly black picture first */
                 maxClipped= (uint64_t)(sum * c.ppMode.maxClippedThreshold);
@@ -3545,7 +3541,6 @@
                 }
         }
 
-//printf("\n");
         for(y=0; y<height; y+=BLOCK_SIZE)
         {
                 //1% speedup if these are here instead of the inner loop
@@ -3582,7 +3577,6 @@
                         dstBlock= tempDst + dstStride;
                         srcBlock= tempSrc;
                 }
-//printf("\n");
 
                 // From this point on it is guranteed that we can read and write 16 lines downward
                 // finish 1 block before the next otherwise we might have a problem
Index: libpostproc/postprocess.c
===================================================================
--- libpostproc/postprocess.c	(revision 6597)
+++ libpostproc/postprocess.c	(working copy)
@@ -132,8 +132,6 @@
 static uint8_t clip_table[3*256];
 static uint8_t * const clip_tab= clip_table + 256;
 
-static const int verbose= 0;
-
 static const int attribute_used deringThreshold= 20;
 
 
@@ -786,7 +784,7 @@
 
         strncpy(temp, name, GET_MODE_BUFFER_SIZE);
 
-        if(verbose>1) printf("pp: %s\n", name);
+        av_log(NULL, AV_LOG_DEBUG, "pp: %s\n", name);
 
         for(;;){
                 char *filterName;
@@ -804,7 +802,7 @@
                 if(filterToken == NULL) break;
                 p+= strlen(filterToken) + 1; // p points to next filterToken
                 filterName= strtok(filterToken, optionDelimiters);
-                if(verbose>1) printf("pp: %s::%s\n", filterToken, filterName);
+                av_log(NULL, AV_LOG_DEBUG, "pp: %s::%s\n", filterToken, filterName);
 
                 if(*filterName == '-')
                 {
@@ -816,7 +814,7 @@
                         option= strtok(NULL, optionDelimiters);
                         if(option == NULL) break;
 
-                        if(verbose>1) printf("pp: option: %s\n", option);
+                        av_log(NULL, AV_LOG_DEBUG, "pp: option: %s\n", option);
                         if(!strcmp("autoq", option) || !strcmp("a", option)) q= quality;
                         else if(!strcmp("nochrom", option) || !strcmp("y", option)) chrom=0;
                         else if(!strcmp("chrom", option) || !strcmp("c", option)) chrom=1;
@@ -857,7 +855,6 @@
 
                 for(i=0; filters[i].shortName!=NULL; i++)
                 {
-//                        printf("Compareing %s, %s, %s\n", filters[i].shortName,filters[i].longName, filterName);
                         if(   !strcmp(filters[i].longName, filterName)
                            || !strcmp(filters[i].shortName, filterName))
                         {
@@ -944,10 +941,10 @@
                 ppMode->error += numOfUnknownOptions;
         }
 
-        if(verbose>1) printf("pp: lumMode=%X, chromMode=%X\n", ppMode->lumMode, ppMode->chromMode);
+        av_log(NULL, AV_LOG_DEBUG, "pp: lumMode=%X, chromMode=%X\n", ppMode->lumMode, ppMode->chromMode);
         if(ppMode->error)
         {
-                fprintf(stderr, "%d errors in postprocess string \"%s\"\n", ppMode->error, name);
+                av_log(NULL, AV_LOG_ERROR, "%d errors in postprocess string \"%s\"\n", ppMode->error, name);
                 av_free(ppMode);
                 return NULL;
         }
@@ -999,6 +996,12 @@
         memset(clip_table+512, 0, 256);
 }
 
+static const char * context_to_name(void * ptr) {
+    return "postproc";
+}
+
+static AVClass av_codec_context_class = { "Postproc", context_to_name, NULL };
+
 pp_context_t *pp_get_context(int width, int height, int cpuCaps){
         PPContext *c= av_malloc(sizeof(PPContext));
         int stride= (width+15)&(~15);    //assumed / will realloc if needed
@@ -1007,6 +1010,7 @@
         global_init();
 
         memset(c, 0, sizeof(PPContext));
+        c->av_class = &av_codec_context_class;
         c->cpuCaps= cpuCaps;
         if(cpuCaps&PP_FORMAT){
                 c->hChromaSubSample= cpuCaps&0x3;
@@ -1073,7 +1077,6 @@
                 else
                         for(i=0; i<mbWidth; i++) QP_store[i]= 1;
         }
-//printf("pict_type:%d\n", pict_type);
 
         if(pict_type & PP_PICT_TYPE_QP2){
                 int i;
@@ -1092,11 +1095,11 @@
 int x,y;
 for(y=0; y<mbHeight; y++){
         for(x=0; x<mbWidth; x++){
-                printf("%2d ", QP_store[x + y*QPStride]);
+                av_log(c, AV_LOG_INFO, "%2d ", QP_store[x + y*QPStride]);
         }
-        printf("\n");
+        av_log(c, AV_LOG_INFO, "\n");
 }
-        printf("\n");
+        av_log(c, AV_LOG_INFO, "\n");
 }
 
         if((pict_type&7)!=3)
@@ -1120,10 +1123,8 @@
                 }
         }
 
-        if(verbose>2)
-        {
-                printf("using npp filters 0x%X/0x%X\n", mode->lumMode, mode->chromMode);
-        }
+        av_log(c, AV_LOG_DEBUG, "using npp filters 0x%X/0x%X\n",
+               mode->lumMode, mode->chromMode);
 
         postProcess(src[0], srcStride[0], dst[0], dstStride[0],
                 width, height, QP_store, QPStride, 0, mode, c);
Index: libpostproc/postprocess_internal.h
===================================================================
--- libpostproc/postprocess_internal.h	(revision 6597)
+++ libpostproc/postprocess_internal.h	(working copy)
@@ -119,6 +119,8 @@
  * postprocess context.
  */
 typedef struct PPContext{
+        AVClass *av_class;
+
         uint8_t *tempBlocks; ///<used for the horizontal code
 
         /**



More information about the ffmpeg-devel mailing list