1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-27 09:32:40 +00:00

buffer alloc cleanup / 10l

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8631 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
michael 2002-12-29 00:57:23 +00:00
parent df1abf6c69
commit 9e0d37a9b9
2 changed files with 48 additions and 32 deletions

View File

@ -714,37 +714,48 @@ void pp_free_mode(pp_mode_t *mode){
if(mode) free(mode); if(mode) free(mode);
} }
pp_context_t *pp_get_context(int width, int height, int cpuCaps){ static void reallocAlign(void **p, int alignment, int size){
PPContext *c= memalign(32, sizeof(PPContext)); if(*p) free(*p);
int i; *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 mbWidth = (width+15)>>4;
int mbHeight= (height+15)>>4; int mbHeight= (height+15)>>4;
int i;
c->cpuCaps= cpuCaps;
c->tempBlocks= (uint8_t*)memalign(8, 2*16*8); c->stride= stride;
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++) for(i=0; i<256; i++)
c->yHistogram[i]= width*height/64*15/256; c->yHistogram[i]= width*height/64*15/256;
for(i=0; i<3; i++) 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 //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 reallocAlign((void **)&c->tempBlured[i], 8, stride*mbHeight*16 + 17*1024);
c->tempBluredPast[i]= (uint32_t*)memalign(8, 256*((height+7)&(~7))/2 + 17*1024); reallocAlign((void **)&c->tempBluredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size
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);
} }
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; c->frameNum=-1;
return c; return c;
@ -761,11 +772,12 @@ void pp_free_context(void *vc){
free(c->yHistogram); free(c->yHistogram);
free(c->tempDst); free(c->tempDst);
free(c->tempSrc); free(c->tempSrc);
free(c->tempDstBlock);
free(c->tempSrcBlock);
free(c->deintTemp); free(c->deintTemp);
free(c->nonBQPTable); free(c->nonBQPTable);
free(c->forcedQPTable);
memset(c, 0, sizeof(PPContext));
free(c); free(c);
} }
@ -777,19 +789,23 @@ void pp_postprocess(uint8_t * src[3], int srcStride[3],
{ {
int mbWidth = (width+15)>>4; int mbWidth = (width+15)>>4;
int mbHeight= (height+15)>>4; int mbHeight= (height+15)>>4;
QP_STORE_T quantArray[2048/8];
PPMode *mode = (PPMode*)vm; PPMode *mode = (PPMode*)vm;
PPContext *c = (PPContext*)vc; 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)) if(QP_store==NULL || (mode->lumMode & FORCE_QUANT))
{ {
int i; int i;
QP_store= quantArray; QP_store= c->forcedQPTable;
QPStride= 0; QPStride= 0;
if(mode->lumMode & FORCE_QUANT) 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 else
for(i=0; i<2048/8; i++) quantArray[i]= 1; for(i=0; i<mbWidth; i++) QP_store[i]= 1;
} }
if(0){ if(0){
int x,y; int x,y;

View File

@ -100,9 +100,6 @@ typedef struct PPContext{
uint8_t *tempDst; uint8_t *tempDst;
uint8_t *tempSrc; uint8_t *tempSrc;
/* Temporary buffers for handling the last block */
uint8_t *tempDstBlock;
uint8_t *tempSrcBlock;
uint8_t *deintTemp; uint8_t *deintTemp;
uint64_t __attribute__((aligned(8))) pQPb; uint64_t __attribute__((aligned(8))) pQPb;
@ -110,15 +107,18 @@ typedef struct PPContext{
uint64_t __attribute__((aligned(8))) mmxDcOffset[32]; uint64_t __attribute__((aligned(8))) mmxDcOffset[32];
uint64_t __attribute__((aligned(8))) mmxDcThreshold[32]; uint64_t __attribute__((aligned(8))) mmxDcThreshold[32];
QP_STORE_T *nonBQPTable; QP_STORE_T *nonBQPTable;
QP_STORE_T *forcedQPTable;
int QP; int QP;
int nonBQP; int nonBQP;
int frameNum; int frameNum;
int cpuCaps; int cpuCaps;
int stride; //size of some buffers (needed to realloc them if needed)
PPMode ppMode; PPMode ppMode;
} PPContext; } PPContext;