📄 i810xvmc.c
字号:
pI810Surface->last_flip = 0; pI810Surface->second_field = 0; if((ret = _xvmc_create_surface(display, context, surface, &priv_count, &priv_data))) { free(pI810Surface); printf("Unable to create XvMCSurface.\n"); return ret; } /* _xvmc_create_subpicture returns 2 uints with the offset into the DRM map for the Y surface and UV surface. */ if(priv_count != 2) { printf("_xvmc_create_surface() return incorrect data size.\n"); printf("Expected 2 got %d\n",priv_count); free(priv_data); free(pI810Surface); return BadAlloc; } /* Data == Client Address, offset == Physical address offset */ pI810Surface->data = pI810XvMC->surfaces.address; pI810Surface->offset = pI810XvMC->surfaces.offset; /* i810's MC Engine needs surfaces of 2^x (x= 9,10,11,12) pitch and the Tiler need 512k aligned surfaces, basically we are stuck with fixed memory with pitch 1024 for Y data. UV = 512. */ pI810Surface->pitch = 10; if((surface->surface_type_id == FOURCC_UYVY) || (surface->surface_type_id == FOURCC_YUY2)) { /* This is not implemented server side. */ pI810Surface->pitch++; } /* offsets[0,1,2] == Offsets from either data or offset for the Y U and V surfaces. */ pI810Surface->offsets[0] = priv_data[0]; if(((unsigned long)pI810Surface->data + pI810Surface->offsets[0]) & 4095) { printf("XvMCCreateSurface: Surface offset 0 is not 4096 aligned\n"); } if((surface->surface_type_id == FOURCC_UYVY) || (surface->surface_type_id == FOURCC_YUY2)) { /* Packed surface, not fully implemented */ pI810Surface->offsets[1] = 0; pI810Surface->offsets[2] = 0; } else { /* Planar surface */ pI810Surface->offsets[1] = priv_data[1]; if(((unsigned long)pI810Surface->data + pI810Surface->offsets[1]) & 2047) { printf("XvMCCreateSurface: Surface offset 1 is not 2048 aligned\n"); } pI810Surface->offsets[2] = ((unsigned long)pI810Surface->offsets[1] + (1<<(pI810Surface->pitch - 1)) * 288); if(((unsigned long)pI810Surface->data + pI810Surface->offsets[2]) & 2047) { printf("XvMCCreateSurface: Surface offset 2 is not 2048 aligned\n"); } } /* Free data returned from xvmc_create_surface */ free(priv_data); /* Clear the surface to 0 */ memset((void *)((unsigned long)pI810Surface->data + (unsigned long)pI810Surface->offsets[0]), 0, ((1<<pI810Surface->pitch) * surface->height)); switch(surface->surface_type_id) { case FOURCC_YV12: case FOURCC_I420: /* Destination buffer info command */ pI810Surface->dbi1y = ((((unsigned int)pI810Surface->offset + pI810Surface->offsets[0]) & ~0xfc000fff) | (pI810Surface->pitch - 9)); pI810Surface->dbi1u = ((((unsigned int)pI810Surface->offset + pI810Surface->offsets[1]) & ~0xfc000fff) | (pI810Surface->pitch - 10)); pI810Surface->dbi1v = ((((unsigned int)pI810Surface->offset + pI810Surface->offsets[2]) & ~0xfc000fff) | (pI810Surface->pitch - 10)); /* Destination buffer variables command */ pI810Surface->dbv1 = (0x8<<20) | (0x8<<16); /* Map info command */ pI810Surface->mi1y = (0x1<<24) | (1<<9) | (pI810Surface->pitch - 3); pI810Surface->mi1u = (0x1<<24) | (1<<9) | (pI810Surface->pitch - 4); pI810Surface->mi1v = (0x1<<24) | (1<<9) | (pI810Surface->pitch - 4); pI810Surface->mi2y = (((unsigned int)surface->height - 1)<<16) | ((unsigned int)surface->width - 1); pI810Surface->mi2u = (((unsigned int)surface->height - 1)<<15) | (((unsigned int)surface->width - 1)>>1); pI810Surface->mi2v = pI810Surface->mi2u; pI810Surface->mi3y = ((unsigned int)pI810Surface->offset + pI810Surface->offsets[0]) & ~0x0000000f; pI810Surface->mi3u = ((unsigned int)pI810Surface->offset + pI810Surface->offsets[1]) & ~0x0000000f; pI810Surface->mi3v = ((unsigned int)pI810Surface->offset + pI810Surface->offsets[2]) & ~0x0000000f; break; case FOURCC_UYVY: case FOURCC_YUY2: default: /* Destination buffer info command */ pI810Surface->dbi1y = ((((unsigned int)pI810Surface->offset + pI810Surface->offsets[0]) & ~0xfc000fff) | (pI810Surface->pitch - 9)); /* Destination buffer variables command */ if(surface->surface_type_id == FOURCC_YUY2) { pI810Surface->dbv1 = 0x5<<8; pI810Surface->mi1y = 0x5<<24 | pI810Surface->pitch | 0x1<<21; } else { pI810Surface->dbv1 = 0x4<<8; pI810Surface->mi1y = 0x5<<24 | (pI810Surface->pitch - 3); } pI810Surface->mi2y = (((unsigned int)surface->width - 1)<<16) | ((unsigned int)surface->height - 1); pI810Surface->mi3y = ((unsigned int)pI810Surface->offset + pI810Surface->offsets[0]) & ~0xfc000fff; break; } pI810XvMC->ref++; return Success;}/***************************************************************************// Function: XvMCDestroySurface***************************************************************************/Status XvMCDestroySurface(Display *display, XvMCSurface *surface) { i810XvMCSurface *pI810Surface; i810XvMCContext *pI810XvMC; if((display == NULL) || (surface == NULL)) { return BadValue; } if(surface->privData == NULL) { return (error_base + XvMCBadSurface); } pI810Surface = (i810XvMCSurface *)surface->privData; if(pI810Surface->last_flip) { XvMCSyncSurface(display,surface); } pI810XvMC = (i810XvMCContext *)pI810Surface->privContext; _xvmc_destroy_surface(display,surface); i810_free_privContext(pI810XvMC); free(pI810Surface); surface->privData = NULL; return Success;}/***************************************************************************// Function: XvMCCreateBlocks***************************************************************************/Status XvMCCreateBlocks(Display *display, XvMCContext *context, unsigned int num_blocks, XvMCBlockArray *block) { if((display == NULL) || (context == NULL) || (num_blocks == 0)) { return BadValue; } block->blocks = (short *)malloc(num_blocks<<6 * sizeof(short)); if(block->blocks == NULL) { return BadAlloc; } block->num_blocks = num_blocks; block->context_id = context->context_id; block->privData = NULL; return Success;}/***************************************************************************// Function: XvMCDestroyBlocks***************************************************************************/Status XvMCDestroyBlocks(Display *display, XvMCBlockArray *block) { if(display == NULL) { return BadValue; } free(block->blocks); block->num_blocks = 0; block->context_id = 0; block->privData = NULL; return Success;}/***************************************************************************// Function: XvMCCreateMacroBlocks***************************************************************************/Status XvMCCreateMacroBlocks(Display *display, XvMCContext *context, unsigned int num_blocks, XvMCMacroBlockArray *blocks) { if((display == NULL) || (context == NULL) || (blocks == NULL) || (num_blocks == 0)) { return BadValue; } memset(blocks,0,sizeof(XvMCMacroBlockArray)); blocks->context_id = context->context_id; blocks->privData = NULL; blocks->macro_blocks = (XvMCMacroBlock *) malloc(num_blocks * sizeof(XvMCMacroBlock)); if(blocks->macro_blocks == NULL) { return BadAlloc; } blocks->num_blocks = num_blocks; return Success;}/***************************************************************************// Function: XvMCDestroyMacroBlocks***************************************************************************/Status XvMCDestroyMacroBlocks(Display *display, XvMCMacroBlockArray *block) { if((display == NULL) || (block == NULL)) { return BadValue; } if(block->macro_blocks) { free(block->macro_blocks); } block->context_id = 0; block->num_blocks = 0; block->privData = NULL; return Success;}/***************************************************************************// Function: dp (Debug Print)// Description: This function prints out in hex i * uint32_t at the address// supplied. This enables you to print out the dma buffers from// within the debugger even though they are not in your address space.***************************************************************************/void dp(unsigned int *address, unsigned int i) { int j; printf("DebugPrint:\n"); for(j=0; j<i; j++) { printf("0x%8.8x ",address[j]); if(j && !(j & 7)) { printf("\n");} }}/***************************************************************************// Macro: PACK_*// Description: Packs 16bit signed data from blocks into either 8bit unsigned// intra data or 16bit signed correction data, both packed into// 32 bit integers.***************************************************************************/#define PACK_INTRA_DATA(d,b,n) \ do { \ char *dp = (char *)d; \ char *bp = (char *)b; \ int counter; \ for(counter = 0; counter < n; counter++) { \ *dp++ = *bp; \ bp += 2; \ } \ }while(0);#define PACK_CORR_DATA(d,b,n) \ memcpy(d,b,n); \ d = (uint *)((unsigned long)d + n);#define MARK_CORR_DATA(d,n) \ do { \ uint* q = (uint*)((unsigned long)d - n); \ while((unsigned long)q < (unsigned long)d) { \ *q++ += 0x00330033; \ } \ }while(0);#define MARK_INTRA_BLOCK(d) \ do { \ int q; \ for(q=0; q<16; q++) { \ d[q] += 0x33333333; \ } \ }while(0);/* Used for DCT 1 when we need DCT 0. Instead of reading from one block we read from two and interlace.*/#define PACK_CORR_DATA_1to0(d,top,bottom) \ do { \ short *t = top,*b = bottom; \ PACK_CORR_DATA(d,t,16); \ t = (short *)((unsigned long)t + 16); \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 16); \ PACK_CORR_DATA(d,t,16); \ t = (short *)((unsigned long)t + 16); \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 16); \ PACK_CORR_DATA(d,t,16); \ t = (short *)((unsigned long)t + 16); \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 16); \ PACK_CORR_DATA(d,t,16); \ t = (short *)((unsigned long)t + 16); \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 16); \ }while(0);/* Used for DCT 0 when we need DCT 1. */#define PACK_CORR_DATA_0to1(d,top,bottom) \ do{ \ short *t = top,*b = bottom; \ PACK_CORR_DATA(d,t,16); \ t = (short *)((unsigned long)t + 32); \ PACK_CORR_DATA(d,t,16); \ t = (short *)((unsigned long)t + 32); \ PACK_CORR_DATA(d,t,16); \ t = (short *)((unsigned long)t + 32); \ PACK_CORR_DATA(d,t,16); \ t = (short *)((unsigned long)t + 32); \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 32); \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 32); \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 32); \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 32); \ }while(0);#define PACK_CORR_DATA_SHORT(d,block) \ do { \ short *b = block; \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 32); \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 32); \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 32); \ PACK_CORR_DATA(d,b,16); \ b = (short *)((unsigned long)b + 32); \ }while(0);/* Lookup tables to speed common calculations */static unsigned int drps_table[] = {2<<6,3<<6};static unsigned int mvfs_table[] = { 0x12, 0x1a, 0x13, 0x1b};static unsigned int type_table[] = { 0x1<<12, /* This is an error so make it Forward motion */ 0x1<<12, 0x1<<12, 0x1<<12, 0x2<<12, 0x2<<12, 0x3<<12, 0x3<<12, 0x1<<12, /* Pattern but no Motion, Make motion Forward */ 0x1<<12, 0x1<<12, 0x1<<12, 0x2<<12, 0x2<<12, 0x3<<12, 0x3<<12};static unsigned int y_frame_bytes[] = { 0,0,0,0,128,128,128,128, 128,128,128,128,256,256,256,256, 128,128,128,128,256,256,256,256, 256,256,256,256,384,384,384,384, 128,128,128,128,256,256,256,256, 256,256,256,256,384,384,384,384, 256,256,256,256,384,384,384,384, 384,384,384,384,512,512,512,512};static unsigned int u_frame_bytes[] = { 0,0,128,128,0,0,128,128, 0,0,128,128,0,0,128,128, 0,0,128,128,0,0,128,128, 0,0,128,128,0,0,128,128, 0,0,128,128,0,0,128,128, 0,0,128,128,0,0,128,128, 0,0,128,128,0,0,128,128, 0,0,128,128,0,0,128,128};static unsigned int v_frame_bytes[] = { 0,128,0,128,0,128,0,128, 0,128,0,128,0,128,0,128, 0,128,0,128,0,128,0,128, 0,128,0,128,0,128,0,128, 0,128,0,128,0,128,0,128, 0,128,0,128,0,128,0,128, 0,128,0,128,0,128,0,128, 0,128,0,128,0,128,0,128};static unsigned int y_first_field_bytes[] = { 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128, 256,256,256,256,256,256,256,256, 256,256,256,256,256,256,256,256};static unsigned int y_second_field_bytes[] = { 0,0,0,0,128,128,128,128, 128,128,128,128,256,256,256,256, 0,0,0,0,128,128,128,128, 128,128,128,128,256,256,256,256, 0,0,0,0,128,128,128,128, 128,128,128,128,256,256,256,256, 0,0,0,0,128,128,128,128, 128,128,128,128,256,256,256,256};static unsigned int y_dct0_field_bytes[] = { 0,0,0,0,128,128,128,128, 128,128,128,128,256,256,256,256, 128,128,128,128,128,128,128,128, 256,256,256,256,256,256,256,256,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -