📄 enc_image.c
字号:
#include "portab.h"
#include "ftmcp100.h"
#include "enc_image.h"
#include "define.h"
//#include "mem_align.h"
#include "encoder.h"
#include "Mp4Venc.h"
#define SAFETY 64
#define EDGE_SIZE 16
#define EDGE_SIZE2 (EDGE_SIZE/2)
/*
size creat:
EDGE_SIZE mb_width * PIXEL_Y
| / \
/ \/ \
-------------------------------------
| | |\
| | | EDGE_SIZE
| | |/
-------------------------------------
| |\
| | \
| |
| |
| |
| |
| | mb_height * PIXEL_Y
| |
| |
| |
| | /
| |/
-------------------------------------
| | |\
| | | EDGE_SIZE
| | |/
-------------------------------------
\ /
EDGE_SIZE
*/
unsigned int y_virt_sz,u_virt_sz,v_virt_sz;
int32_t
enc_image_create(IMAGE * image,
uint32_t mbwidth,
uint32_t mbheight,FTMCP100_CODEC *pCodec)
{
#if 1 //ivan
y_virt_sz = mbwidth * (2 + mbheight) * PIXEL_Y * PIXEL_Y+ 2 * EDGE_SIZE * EDGE_SIZE;
image->y_virt=consistent_alloc(GFP_ATOMIC,y_virt_sz,(dma_addr_t *)&image->y);
if(image->y_virt==0)
{
printk("Fail to alloc y size\n");
return -1;
}
u_virt_sz = mbwidth * (2 + mbheight) * PIXEL_U * PIXEL_U + 2 * EDGE_SIZE2 * EDGE_SIZE2;
image->u_virt=consistent_alloc(GFP_ATOMIC,u_virt_sz,(dma_addr_t *)&image->u);
if(image->u_virt==0)
{
printk("Fail to alloc u size\n");
consistent_free(image->y_virt,y_virt_sz,image->y);
return -1;
}
v_virt_sz = mbwidth * (2 + mbheight) * PIXEL_V * PIXEL_V + 2 * EDGE_SIZE2 * EDGE_SIZE2;
image->v_virt=consistent_alloc(GFP_ATOMIC,v_virt_sz,(dma_addr_t *)&image->v);
if(image->v_virt==0)
{
printk("Fail to alloc v size\n");
consistent_free(image->y_virt,y_virt_sz,image->y);
consistent_free(image->u_virt,u_virt_sz,image->u);
return -1;
}
#else
image->y_virt = (uint8_t *)(*(DMA_MALLOC_PTR)pCodec->pfnDmaMalloc)(mbwidth * (2 + mbheight) * PIXEL_Y * PIXEL_Y+
2 * EDGE_SIZE * EDGE_SIZE, CACHE_LINE, CACHE_LINE,
(void **)&(image->y));
if (image->y_virt == NULL) {
return -1;
}
image->u_virt = (uint8_t *)(*(DMA_MALLOC_PTR)pCodec->pfnDmaMalloc)(mbwidth * (2 + mbheight) * PIXEL_U * PIXEL_U +
2 * EDGE_SIZE2 * EDGE_SIZE2, CACHE_LINE, CACHE_LINE,
(void **)&(image->u));
if (image->u_virt == NULL) {
(*(DMA_FREE_PTR)pCodec->pfnDmaFree)(image->y_virt, image->y);
return -1;
}
image->v_virt = (uint8_t *)(*(DMA_MALLOC_PTR)pCodec->pfnDmaMalloc)(mbwidth * (2 + mbheight) * PIXEL_V * PIXEL_V +
2 * EDGE_SIZE2 * EDGE_SIZE2, CACHE_LINE, CACHE_LINE,
(void **)&(image->v));
if (image->v_virt == NULL) {
(*(DMA_FREE_PTR)pCodec->pfnDmaFree)(image->u_virt, image->u);
(*(DMA_FREE_PTR)pCodec->pfnDmaFree)(image->y_virt, image->y);
return -1;
}
#endif
image->y_virt += mbwidth * PIXEL_Y * EDGE_SIZE + EDGE_SIZE * EDGE_SIZE;
image->u_virt += mbwidth * PIXEL_U * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2;
image->v_virt += mbwidth * PIXEL_V * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2;
image->y += mbwidth * PIXEL_Y * EDGE_SIZE + EDGE_SIZE * EDGE_SIZE;
image->u += mbwidth * PIXEL_U * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2;
image->v += mbwidth * PIXEL_V * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2;
return 0;
}
void enc_image_adjust(IMAGE * image,
uint32_t mbwidth,
uint32_t mbheight,unsigned char *addr)
{
// the addr are user-provided physical address
image->y=addr;
image->u=image->y+((mbwidth*(2+mbheight)+2)*256);
image->v=image->u+((mbwidth*(2+mbheight)+2)*64);
//image->y_virt += mbwidth * PIXEL_Y * EDGE_SIZE + EDGE_SIZE * EDGE_SIZE;
//image->u_virt += mbwidth * PIXEL_U * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2;
//image->v_virt += mbwidth * PIXEL_V * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2;
image->y += mbwidth * PIXEL_Y * EDGE_SIZE + EDGE_SIZE * EDGE_SIZE;
image->u += mbwidth * PIXEL_U * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2;
image->v += mbwidth * PIXEL_V * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2;
}
void
enc_image_destroy(IMAGE * image,
uint32_t mbwidth,FTMCP100_CODEC *pCodec)
{
#if 1
if(image->y_virt)
consistent_free(image->y_virt,y_virt_sz,image->y);
if(image->u_virt)
consistent_free(image->u_virt,u_virt_sz,image->u);
if(image->v_virt)
consistent_free(image->v_virt,v_virt_sz,image->v);
#else
if (image->y_virt) {
(*(DMA_FREE_PTR)pCodec->pfnDmaFree)(image->y_virt - (mbwidth * PIXEL_Y * EDGE_SIZE + EDGE_SIZE * EDGE_SIZE),
image->y - (mbwidth * PIXEL_Y * EDGE_SIZE + EDGE_SIZE * EDGE_SIZE));
}
if (image->u_virt) {
(*(DMA_FREE_PTR)pCodec->pfnDmaFree)(image->u_virt - (mbwidth * PIXEL_U * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2),
image->u - (mbwidth * PIXEL_U * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2));
}
if (image->v_virt) {
(*(DMA_FREE_PTR)pCodec->pfnDmaFree)(image->v_virt - (mbwidth * PIXEL_V * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2),
image->v - (mbwidth * PIXEL_V * EDGE_SIZE2 + EDGE_SIZE2 * EDGE_SIZE2));
}
#endif
}
void
enc_image_swap(IMAGE * image1,
IMAGE * image2)
{
uint8_t *tmp;
tmp = image1->y_virt;
image1->y_virt = image2->y_virt;
image2->y_virt = tmp;
tmp = image1->u_virt;
image1->u_virt = image2->u_virt;
image2->u_virt = tmp;
tmp = image1->v_virt;
image1->v_virt = image2->v_virt;
image2->v_virt = tmp;
tmp = image1->y;
image1->y = image2->y;
image2->y = tmp;
tmp = image1->u;
image1->u = image2->u;
image2->u = tmp;
tmp = image1->v;
image1->v = image2->v;
image2->v = tmp;
/*
uint8_t *tmp;
tmp = image1->y;
image1->y = image2->y;
image2->y = tmp;
tmp = image1->u;
image1->u = image2->u;
image2->u = tmp;
tmp = image1->v;
image1->v = image2->v;
image2->v = tmp;
*/
}
/*
void
image_copy(IMAGE * image1,
IMAGE * image2,
uint32_t edged_width,
uint32_t height)
{
memcpy(image1->y, image2->y, edged_width * height);
memcpy(image1->u, image2->u, edged_width * height / 4);
memcpy(image1->v, image2->v, edged_width * height / 4);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -