changeset 21981:a14ddab18acd

Pass a context to av_log(), when possible
author lucabe
date Tue, 23 Jan 2007 13:41:45 +0000
parents e389774184e2
children fa66a03e8920
files libswscale/swscale.c libswscale/swscale_internal.h libswscale/swscale_template.c libswscale/yuv2rgb.c libswscale/yuv2rgb_altivec.c
diffstat 5 files changed, 78 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/libswscale/swscale.c	Tue Jan 23 10:06:02 2007 +0000
+++ b/libswscale/swscale.c	Tue Jan 23 13:41:45 2007 +0000
@@ -203,6 +203,12 @@
 extern const uint8_t dither_8x8_73[8][8];
 extern const uint8_t dither_8x8_220[8][8];
 
+static const char * sws_context_to_name(void * ptr) {
+    return "swscaler";
+}
+
+static AVClass sws_context_class = { "SWScaler", sws_context_to_name, NULL };
+
 char *sws_format_name(enum PixelFormat format)
 {
     switch (format) {
@@ -1196,7 +1202,7 @@
 	*outFilterSize= filterSize;
 
 	if(flags&SWS_PRINT_INFO)
-		MSG_V("SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize);
+		av_log(NULL, AV_LOG_VERBOSE, "SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize);
 	/* try to reduce the filter-size (step2 reduce it) */
 	for(i=0; i<dstW; i++)
 	{
@@ -1572,7 +1578,7 @@
 		case 0x83: conv= rgb15to32; break;
 		case 0x84: conv= rgb16to32; break;
 		case 0x86: conv= rgb24to32; break;
-		default: MSG_ERR("swScaler: internal error %s -> %s converter\n", 
+		default: av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", 
 				 sws_format_name(srcFormat), sws_format_name(dstFormat)); break;
 		}
 	}else if(   (isBGR(srcFormat) && isRGB(dstFormat))
@@ -1594,11 +1600,11 @@
 		case 0x84: conv= rgb16tobgr32; break;
 		case 0x86: conv= rgb24tobgr32; break;
 		case 0x88: conv= rgb32tobgr32; break;
-		default: MSG_ERR("swScaler: internal error %s -> %s converter\n", 
+		default: av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", 
 				 sws_format_name(srcFormat), sws_format_name(dstFormat)); break;
 		}
 	}else{
-		MSG_ERR("swScaler: internal error %s -> %s converter\n", 
+		av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", 
 			 sws_format_name(srcFormat), sws_format_name(dstFormat));
 	}
 
@@ -1967,19 +1973,19 @@
 
 	if(!isSupportedIn(srcFormat)) 
 	{
-		MSG_ERR("swScaler: %s is not supported as input format\n", sws_format_name(srcFormat));
+		av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input format\n", sws_format_name(srcFormat));
 		return NULL;
 	}
 	if(!isSupportedOut(dstFormat))
 	{
-		MSG_ERR("swScaler: %s is not supported as output format\n", sws_format_name(dstFormat));
+		av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output format\n", sws_format_name(dstFormat));
 		return NULL;
 	}
 
 	/* sanity check */
 	if(srcW<4 || srcH<1 || dstW<8 || dstH<1) //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code
 	{
-		 MSG_ERR("swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", 
+		 av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", 
 			srcW, srcH, dstW, dstH);
 		return NULL;
 	}
@@ -1989,6 +1995,7 @@
 
 	c= av_mallocz(sizeof(SwsContext));
 
+	c->av_class = &sws_context_class;
 	c->srcW= srcW;
 	c->srcH= srcH;
 	c->dstW= dstW;
@@ -2130,7 +2137,7 @@
 
 		if(c->swScale){
 			if(flags&SWS_PRINT_INFO)
-				MSG_INFO("SwScaler: using unscaled %s -> %s special converter\n", 
+				av_log(c, AV_LOG_INFO, "SwScaler: using unscaled %s -> %s special converter\n", 
 					sws_format_name(srcFormat), sws_format_name(dstFormat));
 			return c;
 		}
@@ -2142,7 +2149,7 @@
 		if(!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR))
 		{
 			if(flags&SWS_PRINT_INFO)
-				MSG_INFO("SwScaler: output Width is not a multiple of 32 -> no MMX2 scaler\n");
+				av_log(c, AV_LOG_INFO, "SwScaler: output Width is not a multiple of 32 -> no MMX2 scaler\n");
 		}
 		if(usesHFilter) c->canMMX2BeUsed=0;
 	}
@@ -2291,47 +2298,47 @@
 		char *dither= "";
 #endif
 		if(flags&SWS_FAST_BILINEAR)
-			MSG_INFO("SwScaler: FAST_BILINEAR scaler, ");
+			av_log(c, AV_LOG_INFO, "SwScaler: FAST_BILINEAR scaler, ");
 		else if(flags&SWS_BILINEAR)
-			MSG_INFO("SwScaler: BILINEAR scaler, ");
+			av_log(c, AV_LOG_INFO, "SwScaler: BILINEAR scaler, ");
 		else if(flags&SWS_BICUBIC)
-			MSG_INFO("SwScaler: BICUBIC scaler, ");
+			av_log(c, AV_LOG_INFO, "SwScaler: BICUBIC scaler, ");
 		else if(flags&SWS_X)
-			MSG_INFO("SwScaler: Experimental scaler, ");
+			av_log(c, AV_LOG_INFO, "SwScaler: Experimental scaler, ");
 		else if(flags&SWS_POINT)
-			MSG_INFO("SwScaler: Nearest Neighbor / POINT scaler, ");
+			av_log(c, AV_LOG_INFO, "SwScaler: Nearest Neighbor / POINT scaler, ");
 		else if(flags&SWS_AREA)
-			MSG_INFO("SwScaler: Area Averageing scaler, ");
+			av_log(c, AV_LOG_INFO, "SwScaler: Area Averageing scaler, ");
 		else if(flags&SWS_BICUBLIN)
-			MSG_INFO("SwScaler: luma BICUBIC / chroma BILINEAR scaler, ");
+			av_log(c, AV_LOG_INFO, "SwScaler: luma BICUBIC / chroma BILINEAR scaler, ");
 		else if(flags&SWS_GAUSS)
-			MSG_INFO("SwScaler: Gaussian scaler, ");
+			av_log(c, AV_LOG_INFO, "SwScaler: Gaussian scaler, ");
 		else if(flags&SWS_SINC)
-			MSG_INFO("SwScaler: Sinc scaler, ");
+			av_log(c, AV_LOG_INFO, "SwScaler: Sinc scaler, ");
 		else if(flags&SWS_LANCZOS)
-			MSG_INFO("SwScaler: Lanczos scaler, ");
+			av_log(c, AV_LOG_INFO, "SwScaler: Lanczos scaler, ");
 		else if(flags&SWS_SPLINE)
-			MSG_INFO("SwScaler: Bicubic spline scaler, ");
+			av_log(c, AV_LOG_INFO, "SwScaler: Bicubic spline scaler, ");
 		else
-			MSG_INFO("SwScaler: ehh flags invalid?! ");
+			av_log(c, AV_LOG_INFO, "SwScaler: ehh flags invalid?! ");
 
 		if(dstFormat==PIX_FMT_BGR555 || dstFormat==PIX_FMT_BGR565)
-			MSG_INFO("from %s to%s %s ", 
+			av_log(c, AV_LOG_INFO, "from %s to%s %s ", 
 				sws_format_name(srcFormat), dither, sws_format_name(dstFormat));
 		else
-			MSG_INFO("from %s to %s ", 
+			av_log(c, AV_LOG_INFO, "from %s to %s ", 
 				sws_format_name(srcFormat), sws_format_name(dstFormat));
 
 		if(flags & SWS_CPU_CAPS_MMX2)
-			MSG_INFO("using MMX2\n");
+			av_log(c, AV_LOG_INFO, "using MMX2\n");
 		else if(flags & SWS_CPU_CAPS_3DNOW)
-			MSG_INFO("using 3DNOW\n");
+			av_log(c, AV_LOG_INFO, "using 3DNOW\n");
 		else if(flags & SWS_CPU_CAPS_MMX)
-			MSG_INFO("using MMX\n");
+			av_log(c, AV_LOG_INFO, "using MMX\n");
 		else if(flags & SWS_CPU_CAPS_ALTIVEC)
-			MSG_INFO("using AltiVec\n");
+			av_log(c, AV_LOG_INFO, "using AltiVec\n");
 		else 
-			MSG_INFO("using C\n");
+			av_log(c, AV_LOG_INFO, "using C\n");
 	}
 
 	if(flags & SWS_PRINT_INFO)
@@ -2339,70 +2346,70 @@
 		if(flags & SWS_CPU_CAPS_MMX)
 		{
 			if(c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR))
-				MSG_V("SwScaler: using FAST_BILINEAR MMX2 scaler for horizontal scaling\n");
+				av_log(c, AV_LOG_VERBOSE, "SwScaler: using FAST_BILINEAR MMX2 scaler for horizontal scaling\n");
 			else
 			{
 				if(c->hLumFilterSize==4)
-					MSG_V("SwScaler: using 4-tap MMX scaler for horizontal luminance scaling\n");
+					av_log(c, AV_LOG_VERBOSE, "SwScaler: using 4-tap MMX scaler for horizontal luminance scaling\n");
 				else if(c->hLumFilterSize==8)
-					MSG_V("SwScaler: using 8-tap MMX scaler for horizontal luminance scaling\n");
+					av_log(c, AV_LOG_VERBOSE, "SwScaler: using 8-tap MMX scaler for horizontal luminance scaling\n");
 				else
-					MSG_V("SwScaler: using n-tap MMX scaler for horizontal luminance scaling\n");
+					av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap MMX scaler for horizontal luminance scaling\n");
 
 				if(c->hChrFilterSize==4)
-					MSG_V("SwScaler: using 4-tap MMX scaler for horizontal chrominance scaling\n");
+					av_log(c, AV_LOG_VERBOSE, "SwScaler: using 4-tap MMX scaler for horizontal chrominance scaling\n");
 				else if(c->hChrFilterSize==8)
-					MSG_V("SwScaler: using 8-tap MMX scaler for horizontal chrominance scaling\n");
+					av_log(c, AV_LOG_VERBOSE, "SwScaler: using 8-tap MMX scaler for horizontal chrominance scaling\n");
 				else
-					MSG_V("SwScaler: using n-tap MMX scaler for horizontal chrominance scaling\n");
+					av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap MMX scaler for horizontal chrominance scaling\n");
 			}
 		}
 		else
 		{
 #if defined(ARCH_X86)
-			MSG_V("SwScaler: using X86-Asm scaler for horizontal scaling\n");
+			av_log(c, AV_LOG_VERBOSE, "SwScaler: using X86-Asm scaler for horizontal scaling\n");
 #else
 			if(flags & SWS_FAST_BILINEAR)
-				MSG_V("SwScaler: using FAST_BILINEAR C scaler for horizontal scaling\n");
+				av_log(c, AV_LOG_VERBOSE, "SwScaler: using FAST_BILINEAR C scaler for horizontal scaling\n");
 			else
-				MSG_V("SwScaler: using C scaler for horizontal scaling\n");
+				av_log(c, AV_LOG_VERBOSE, "SwScaler: using C scaler for horizontal scaling\n");
 #endif
 		}
 		if(isPlanarYUV(dstFormat))
 		{
 			if(c->vLumFilterSize==1)
-				MSG_V("SwScaler: using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
+				av_log(c, AV_LOG_VERBOSE, "SwScaler: using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
 			else
-				MSG_V("SwScaler: using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
+				av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
 		}
 		else
 		{
 			if(c->vLumFilterSize==1 && c->vChrFilterSize==2)
-				MSG_V("SwScaler: using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n"
+				av_log(c, AV_LOG_VERBOSE, "SwScaler: using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n"
 				       "SwScaler:       2-tap scaler for vertical chrominance scaling (BGR)\n",(flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
 			else if(c->vLumFilterSize==2 && c->vChrFilterSize==2)
-				MSG_V("SwScaler: using 2-tap linear %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
+				av_log(c, AV_LOG_VERBOSE, "SwScaler: using 2-tap linear %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
 			else
-				MSG_V("SwScaler: using n-tap %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
+				av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
 		}
 
 		if(dstFormat==PIX_FMT_BGR24)
-			MSG_V("SwScaler: using %s YV12->BGR24 Converter\n",
+			av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR24 Converter\n",
 				(flags & SWS_CPU_CAPS_MMX2) ? "MMX2" : ((flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"));
 		else if(dstFormat==PIX_FMT_RGB32)
-			MSG_V("SwScaler: using %s YV12->BGR32 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
+			av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR32 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
 		else if(dstFormat==PIX_FMT_BGR565)
-			MSG_V("SwScaler: using %s YV12->BGR16 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
+			av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR16 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
 		else if(dstFormat==PIX_FMT_BGR555)
-			MSG_V("SwScaler: using %s YV12->BGR15 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
+			av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR15 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C");
 
-		MSG_V("SwScaler: %dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);
+		av_log(c, AV_LOG_VERBOSE, "SwScaler: %dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);
 	}
 	if(flags & SWS_PRINT_INFO)
 	{
-		MSG_DBG2("SwScaler:Lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
+		av_log(c, AV_LOG_DEBUG, "SwScaler:Lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
 			c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc);
-		MSG_DBG2("SwScaler:Chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
+		av_log(c, AV_LOG_DEBUG, "SwScaler:Chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
 			c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc);
 	}
 
@@ -2417,7 +2424,7 @@
 int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
                            int srcSliceH, uint8_t* dst[], int dstStride[]){
 	if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) {
-	    MSG_ERR("swScaler: slices start in the middle!\n");
+	    av_log(c, AV_LOG_ERROR, "swScaler: slices start in the middle!\n");
 	    return 0;
 	}
 	if (c->sliceDir == 0) {
@@ -2715,9 +2722,9 @@
 	for(i=0; i<a->length; i++)
 	{
 		int x= (int)((a->coeff[i]-min)*60.0/range +0.5);
-		MSG_DBG2("%1.3f ", a->coeff[i]);
-		for(;x>0; x--) MSG_DBG2(" ");
-		MSG_DBG2("|\n");
+		av_log(NULL, AV_LOG_DEBUG, "%1.3f ", a->coeff[i]);
+		for(;x>0; x--) av_log(NULL, AV_LOG_DEBUG, " ");
+		av_log(NULL, AV_LOG_DEBUG, "|\n");
 	}
 }
 
--- a/libswscale/swscale_internal.h	Tue Jan 23 10:06:02 2007 +0000
+++ b/libswscale/swscale_internal.h	Tue Jan 23 13:41:45 2007 +0000
@@ -33,13 +33,6 @@
 #define AVV(x...) {x}
 #endif
 
-#define MSG_WARN(args...) av_log(NULL, AV_LOG_DEBUG, ##args )
-#define MSG_FATAL(args...) av_log(NULL, AV_LOG_ERROR, ##args )
-#define MSG_ERR(args...) av_log(NULL, AV_LOG_ERROR, ##args )
-#define MSG_V(args...) av_log(NULL, AV_LOG_INFO, ##args )
-#define MSG_DBG2(args...) av_log(NULL, AV_LOG_DEBUG, ##args )
-#define MSG_INFO(args...) av_log(NULL, AV_LOG_INFO, ##args )
-
 #define MAX_FILTER_SIZE 256
 
 typedef int (*SwsFunc)(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
@@ -47,6 +40,11 @@
 
 /* this struct should be aligned on at least 32-byte boundary */
 typedef struct SwsContext{
+        /**
+         * info on struct for av_log
+         */
+        AVClass *av_class;
+
 	/**
 	 *
 	 * Note the src,dst,srcStride,dstStride will be copied, in the sws_scale() warper so they can freely be modified here
--- a/libswscale/swscale_template.c	Tue Jan 23 10:06:02 2007 +0000
+++ b/libswscale/swscale_template.c	Tue Jan 23 13:41:45 2007 +0000
@@ -2972,7 +2972,7 @@
 		static int firstTime=1; //FIXME move this into the context perhaps
 		if(flags & SWS_PRINT_INFO && firstTime)
 		{
-			MSG_WARN("SwScaler: Warning: dstStride is not aligned!\n"
+			av_log(c, AV_LOG_WARNING, "SwScaler: Warning: dstStride is not aligned!\n"
 					"SwScaler:          ->cannot do aligned memory acesses anymore\n");
 			firstTime=0;
 		}
--- a/libswscale/yuv2rgb.c	Tue Jan 23 10:06:02 2007 +0000
+++ b/libswscale/yuv2rgb.c	Tue Jan 23 13:41:45 2007 +0000
@@ -611,7 +611,7 @@
     }
 #endif
 
-    MSG_WARN("No accelerated colorspace conversion found\n");
+    av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found\n");
 
     switch(c->dstFormat){
     case PIX_FMT_BGR32:
@@ -828,7 +828,7 @@
 
     default:
 	table_start= NULL;
-	MSG_ERR("%ibpp not supported by yuv2rgb\n", bpp);
+	av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
 	//free mem?
 	return -1;
     }
--- a/libswscale/yuv2rgb_altivec.c	Tue Jan 23 10:06:02 2007 +0000
+++ b/libswscale/yuv2rgb_altivec.c	Tue Jan 23 13:41:45 2007 +0000
@@ -710,22 +710,22 @@
 
     switch(c->dstFormat){
     case PIX_FMT_RGB24:
-      MSG_WARN("ALTIVEC: Color Space RGB24\n");
+      av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n");
       return altivec_yuv2_rgb24;
     case PIX_FMT_BGR24:
-      MSG_WARN("ALTIVEC: Color Space BGR24\n");
+      av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGR24\n");
       return altivec_yuv2_bgr24;
     case PIX_FMT_ARGB:
-      MSG_WARN("ALTIVEC: Color Space ARGB\n");
+      av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ARGB\n");
       return altivec_yuv2_argb;
     case PIX_FMT_ABGR:
-      MSG_WARN("ALTIVEC: Color Space ABGR\n");
+      av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ABGR\n");
       return altivec_yuv2_abgr;
     case PIX_FMT_RGBA:
-      MSG_WARN("ALTIVEC: Color Space RGBA\n");
+      av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGBA\n");
       return altivec_yuv2_rgba;
     case PIX_FMT_BGRA:
-      MSG_WARN("ALTIVEC: Color Space BGRA\n");
+      av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGRA\n");
       return altivec_yuv2_bgra;
     default: return NULL;
     }
@@ -734,7 +734,7 @@
   case PIX_FMT_UYVY422:
     switch(c->dstFormat){
     case PIX_FMT_BGR32:
-      MSG_WARN("ALTIVEC: Color Space UYVY -> RGB32\n");
+      av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n");
       return altivec_uyvy_rgb32;
     default: return NULL;
     }
@@ -877,7 +877,7 @@
              instead. */
           static int printed_error_message;
           if(!printed_error_message) {
-            MSG_ERR("altivec_yuv2packedX doesn't support %s output\n",
+            av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n",
                     sws_format_name(c->dstFormat));
             printed_error_message=1;
           }
@@ -952,7 +952,7 @@
       case PIX_FMT_BGR24: out_bgr24 (R,G,B,nout); break;
       default:
         /* Unreachable, I think. */
-        MSG_ERR("altivec_yuv2packedX doesn't support %s output\n",
+        av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n",
                 sws_format_name(c->dstFormat));
         return;
     }