changeset 937:04fd733c5e4b libavcodec

buffer alloc cleanup / 10l
author michael
date Sun, 29 Dec 2002 00:57:23 +0000
parents caa77cd960c0
children 1e22655551b9
files libpostproc/postprocess.c libpostproc/postprocess_internal.h
diffstat 2 files changed, 48 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/libpostproc/postprocess.c	Fri Dec 27 23:51:46 2002 +0000
+++ b/libpostproc/postprocess.c	Sun Dec 29 00:57:23 2002 +0000
@@ -714,37 +714,48 @@
     if(mode) free(mode);
 }
 
-pp_context_t *pp_get_context(int width, int height, int cpuCaps){
-	PPContext *c= memalign(32, sizeof(PPContext));
-	int i;
+static void reallocAlign(void **p, int alignment, int size){
+	if(*p) free(*p);
+	*p= memalign(alignment, size);
+	memset(*p, 0, size);
+}
+
+static void reallocBuffers(PPContext *c, int width, int height, int stride){
 	int mbWidth = (width+15)>>4;
 	int mbHeight= (height+15)>>4;
-	
-	c->cpuCaps= cpuCaps;
+	int i;
+
+	c->stride= stride;
 
-	c->tempBlocks= (uint8_t*)memalign(8, 2*16*8);
-	c->yHistogram= (uint64_t*)memalign(8, 256*sizeof(uint64_t));
+	reallocAlign((void **)&c->tempDst, 8, stride*24);
+	reallocAlign((void **)&c->tempSrc, 8, stride*24);
+	reallocAlign((void **)&c->tempBlocks, 8, 2*16*8);
+	reallocAlign((void **)&c->yHistogram, 8, 256*sizeof(uint64_t));
 	for(i=0; i<256; i++)
 		c->yHistogram[i]= width*height/64*15/256;
 
 	for(i=0; i<3; i++)
 	{
 		//Note:the +17*1024 is just there so i dont have to worry about r/w over te end
-		c->tempBlured[i]= (uint8_t*)memalign(8, ((width+7)&(~7))*2*((height+7)&(~7)) + 17*1024); //FIXME dstStride instead of width
-		c->tempBluredPast[i]= (uint32_t*)memalign(8, 256*((height+7)&(~7))/2 + 17*1024);
-
-		memset(c->tempBlured[i], 0, ((width+7)&(~7))*2*((height+7)&(~7)) + 17*1024);
-		memset(c->tempBluredPast[i], 0, 256*((height+7)&(~7))/2 + 17*1024);
+		reallocAlign((void **)&c->tempBlured[i], 8, stride*mbHeight*16 + 17*1024);
+		reallocAlign((void **)&c->tempBluredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size
 	}
-	
-	c->tempDst= (uint8_t*)memalign(8, 1024*24);
-	c->tempSrc= (uint8_t*)memalign(8, 1024*24);
-	c->tempDstBlock= (uint8_t*)memalign(8, 1024*24);
-	c->tempSrcBlock= (uint8_t*)memalign(8, 1024*24);
-	c->deintTemp= (uint8_t*)memalign(8, width+16);
-	c->nonBQPTable= (QP_STORE_T*)memalign(8, mbWidth*mbHeight*sizeof(QP_STORE_T));
-	memset(c->nonBQPTable, 0, mbWidth*mbHeight*sizeof(QP_STORE_T));
+
+	reallocAlign((void **)&c->deintTemp, 8, width+16);
+	reallocAlign((void **)&c->nonBQPTable, 8, mbWidth*mbHeight*sizeof(QP_STORE_T));
+	reallocAlign((void **)&c->forcedQPTable, 8, mbWidth*sizeof(QP_STORE_T));
+}
 
+pp_context_t *pp_get_context(int width, int height, int cpuCaps){
+	PPContext *c= memalign(32, sizeof(PPContext));
+	int i;
+	int stride= (width+15)&(~15); //assumed / will realloc if needed
+        
+	memset(c, 0, sizeof(PPContext));
+	c->cpuCaps= cpuCaps;
+
+	reallocBuffers(c, width, height, stride);
+        
 	c->frameNum=-1;
 
 	return c;
@@ -761,11 +772,12 @@
 	free(c->yHistogram);
 	free(c->tempDst);
 	free(c->tempSrc);
-	free(c->tempDstBlock);
-	free(c->tempSrcBlock);
 	free(c->deintTemp);
 	free(c->nonBQPTable);
-	
+	free(c->forcedQPTable);
+        
+	memset(c, 0, sizeof(PPContext));
+
 	free(c);
 }
 
@@ -777,19 +789,23 @@
 {
 	int mbWidth = (width+15)>>4;
 	int mbHeight= (height+15)>>4;
-	QP_STORE_T quantArray[2048/8];
 	PPMode *mode = (PPMode*)vm;
 	PPContext *c = (PPContext*)vc;
+        int minStride= MAX(srcStride[0], dstStride[0]);
+	
+	if(c->stride < minStride)
+		reallocBuffers(c, width, height, minStride);
+        
 
 	if(QP_store==NULL || (mode->lumMode & FORCE_QUANT)) 
 	{
 		int i;
-		QP_store= quantArray;
+		QP_store= c->forcedQPTable;
 		QPStride= 0;
 		if(mode->lumMode & FORCE_QUANT)
-			for(i=0; i<2048/8; i++) quantArray[i]= mode->forcedQuant;
+			for(i=0; i<mbWidth; i++) QP_store[i]= mode->forcedQuant;
 		else
-			for(i=0; i<2048/8; i++) quantArray[i]= 1;
+			for(i=0; i<mbWidth; i++) QP_store[i]= 1;
 	}
 if(0){
 int x,y;
--- a/libpostproc/postprocess_internal.h	Fri Dec 27 23:51:46 2002 +0000
+++ b/libpostproc/postprocess_internal.h	Sun Dec 29 00:57:23 2002 +0000
@@ -100,9 +100,6 @@
 	uint8_t *tempDst;
 	uint8_t *tempSrc;
 
-	/* Temporary buffers for handling the last block */
-	uint8_t *tempDstBlock;
-	uint8_t *tempSrcBlock;
 	uint8_t *deintTemp;
 
 	uint64_t __attribute__((aligned(8))) pQPb;
@@ -110,15 +107,18 @@
 
 	uint64_t __attribute__((aligned(8))) mmxDcOffset[32];
 	uint64_t __attribute__((aligned(8))) mmxDcThreshold[32];
-	
+
 	QP_STORE_T *nonBQPTable;
-	
+	QP_STORE_T *forcedQPTable;
+
 	int QP;
 	int nonBQP;
 
 	int frameNum;
 	
 	int cpuCaps;
+        
+	int stride; //size of some buffers (needed to realloc them if needed)
 
 	PPMode ppMode;
 } PPContext;