?? test.c
字號:
#define TEST_GLOBALS
#include "../fmpeg4_driver/fmpeg4.h"
#include "portab.h"
#include "test.h"
#include "vpe_m.h"
#include "define.h"
#include "dma_m.h"
#include "mp4.h"
#include "mp4vdec.h"
#include "decoder.h"
//#include "utils/mem_align.h"
static file_info * BS_fileinput;
static int32_t file_no;
#ifdef FPGA
#if (OUTPUT_FMT == OUTPUT_FMT_CbYCrY)
static char path[80] = "G:\\Notes\\mpeg4\\From_R\\data\\compliance\\Error\\rtl_CbYCrY\\";
#elif (OUTPUT_FMT == OUTPUT_FMT_RGB555)
static char path[80] = "G:\\Notes\\mpeg4\\From_R\\data\\compliance\\Error\\rtl_rgb555\\";
#elif (OUTPUT_FMT == OUTPUT_FMT_RGB888)
static char path[80] = "G:\\Notes\\mpeg4\\From_R\\data\\compliance\\Error\\rtl_rgb888\\";
#elif (OUTPUT_FMT == OUTPUT_FMT_RGB565)
static char path[80] = "G:\\Notes\\mpeg4\\From_R\\data\\compliance\\Error\\rtl_rgb565\\";
#elif (OUTPUT_FMT == OUTPUT_FMT_YUV)
static char path[80] = "G:\\Notes\\mpeg4\\From_R\\data\\compliance\\Error\\rtl_yuv\\";
#endif
void
vTest_FsdbDumpOff(void)
{
}
void
vTest_FsdbDumpOn(void)
{
}
FILE *
ptTest_open(char *filename, char * mode, int x)
{
FILE * file;
char string[0x80];
strcpy(string, path);
strcat(string, filename);
printk("open file \"%s\"", string);
file = fopen(string, mode);
printk(", return handle 0x%x\n", (int32_t)file);
return file;
}
void
vTest_read(FILE * file, void * mp4_buffer, uint32_t size, int swap_endian)
{
int i;
uint8_t * buf = (uint8_t *)mp4_buffer;
printk("read file(0x%x), sz = 0x%x, to 0x%x ...\n", (int32_t)file, size, (int32_t)mp4_buffer);
if (fread(mp4_buffer, sizeof(uint8_t), size, file) != size)
printk("... error\n");
else
printk("... ok\n");
if (swap_endian) {
for (i = 0; i < size; i += 4, buf += 4)
BSWAP(*(uint32_t *)buf);
}
}
int
s32Test_comp(uint8_t * buffer, uint8_t * bufferg, int size)
{
int i;
printk("compare: raw 0x%x, gld 0x%x", (int32_t)buffer, (int32_t)bufferg);
for (i = 0; i < size; i ++) {
if (*buffer != *bufferg) {
printk("\n------ ERROR @ offset: 0x%x ------\n", i);
printk("addr: raw = 0x%x, gld = 0x%x\n", (int32_t)buffer, (int32_t) bufferg);
printk("data: raw = 0x%x, gld = 0x%x\n", *buffer, * bufferg);
return -1;
}
++ buffer;
++ bufferg;
}
printk("... ok\n");
return 0;
}
int32_t
bTest_PatternInfo(void)
{
FILE * file;
char string[0x80];
file_info * pfile;
int c;
file_no = 0;
if ((BS_fileinput = malloc_align(MAX_FILE_TEST * sizeof(file_info), CACHE_LINE, CACHE_LINE)) == NULL)
return FARADAY_ERR_MEMORY;
pfile = &BS_fileinput[0];
strcpy(string, path);
strcat(string, "pattern_pc.txt");
if ((file = fopen(string, "r")) == NULL) {
printk( "The file '%s' was not opened\n", string);
return FARADAY_ERR_FAIL;
}
c = fgetc(file);
while (c != EOF) {
// Check the first character for comment
if (c == '/')
fgets(string, 0x80, file);
else {
// Push the character back to the file then read the next time
ungetc(c, file);
fscanf(file,"%s %d %d\n", pfile->filename, &(pfile->filesize), &(pfile->framesize));
printk("file_info %d: %s %d %d\n", file_no, pfile->filename, pfile->filesize, pfile->framesize);
++ pfile;
if (++ file_no == MAX_FILE_TEST) {
printk("over MAX_FILE_TEST %d\n", MAX_FILE_TEST);
break;
}
}
c = fgetc(file);
}
// write NULL, no more pattern
strcpy(pfile->filename, "");
file_no = 0;
return FARADAY_ERR_OK;
}
boolean
bTest_GetBS(file_info *ptf, file_handle * pth)
{
char filename_temp[80];
int x;
if (BS_fileinput[file_no].filename[0] == '\0') {
ptf->filesize = 0;
return FARADAY_ERR_OK;
}
if ((pth->bitstream_file = ptTest_open(BS_fileinput[file_no].filename, "rb", VPE_FILE_BITSTREAM)) == NULL)
return FARADAY_ERR_FAIL;
ptf->filesize = BS_fileinput[file_no].filesize;
ptf->framesize = BS_fileinput[file_no].framesize;
x = (int)strrchr(BS_fileinput[file_no].filename, '\\');
x = x - (int)BS_fileinput[file_no].filename + 1;
strncpy(filename_temp, BS_fileinput[file_no].filename, x);
filename_temp[x] = '\0';
strcat(filename_temp, "decu_gld.yuv");
if ((pth->yuv_gld_file = ptTest_open(filename_temp, "rb", VPE_FILE_YUV_GLD)) == NULL)
return FARADAY_ERR_FAIL;
x = (int)strrchr(BS_fileinput[file_no].filename, '\\');
x = x - (int)BS_fileinput[file_no].filename + 1;
strncpy(filename_temp, BS_fileinput[file_no].filename, x);
filename_temp[x] = '\0';
strcat(filename_temp, "decu_gld.display");
if ((pth->rgb_gld_file = ptTest_open(filename_temp, "rb", VPE_FILE_RGB_GLD)) == NULL)
return FARADAY_ERR_FAIL;
++ file_no;
return FARADAY_ERR_OK;
}
void
vTest_close(FILE * handle)
{
printk("close file(0x%x)\n", (int)handle);
fclose(handle);
}
#else
int
s32Test_open(char *filename, char * string, int x)
{
// start string
*(volatile uint32_t *)VPE = 0xdddd1100;
// fill string
while(*filename != '\0')
*(volatile uint8_t *)(VPE + 4) = *(filename ++);
// 1. trickbox_2: file_handle
*(volatile uint32_t *)(VPE + 0x1008) = (uint32_t)x;
// 2. trickbox_3: mode
*(volatile uint32_t *)(VPE + 0x100C) = (uint32_t)*string << 24;
// 3. trickbox_0: action-open
*(volatile uint32_t *)(VPE + 0x1000) = 0x00000000;
// 4. vpe: trigger
*(volatile uint32_t *)(VPE) = 0x60000003;
return x;
}
void
vTest_read(int file, void * mp4_buffer, uint32_t size, int swap_endian)
{
// 1. trickbox_2: file_handle
*(volatile uint32_t *)(VPE + 0x1008) = (uint32_t)file;
// 2. trickbox_3: sdram start address
*(volatile uint32_t *)(VPE + 0x100C) = (uint32_t)mp4_buffer & ~3;
// 3. trickbox_4: read size
*(volatile uint32_t *)(VPE + 0x1010) = size;
// 4. trickbox_5: endian swapping
*(volatile uint32_t *)(VPE + 0x1014) = swap_endian;
// 5. trickbox_0: action-read
*(volatile uint32_t *)(VPE + 0x1000) = 0x00000001;
// 6. vpe: trigger
*(volatile uint32_t *)(VPE) = 0x60000003;
}
int
s32Test_comp(uint8_t * buffer, uint8_t * bufferg, int size)
{
// 1. trickbox_2: raw data sdram start address
*(volatile uint32_t *)(VPE + 0x1008) = (uint32_t)buffer;
// 2. trickbox_3: golden data sdram start address
*(volatile uint32_t *)(VPE + 0x100C) = (uint32_t)bufferg;
// 3. trickbox_4: size will be compare
*(volatile uint32_t *)(VPE + 0x1010) = size;
// 4. trickbox_0: action-compare
*(volatile uint32_t *)(VPE + 0x1000) = 0x00000002;
// 5. vpe: trigger
*(volatile uint32_t *)(VPE) = 0x60000003;
return 0;
}
int
s32Test_memcpy(uint8_t * dst, uint8_t * src, int size)
{
// 1. trickbox_2: source address
*(volatile uint32_t *)(VPE + 0x1008) = (uint32_t)src;
// 2. trickbox_3: dst address
*(volatile uint32_t *)(VPE + 0x100C) = (uint32_t)dst;
// 3. trickbox_4: copy length
*(volatile uint32_t *)(VPE + 0x1010) = size;
// 4. trickbox_0: action-memcpy
*(volatile uint32_t *)(VPE + 0x1000) = 0x00000007;
// 5. vpe: trigger
*(volatile uint32_t *)(VPE) = 0x60000003;
return 0;
}
int32_t
bTest_PatternInfo(void)
{
if ((BS_fileinput = malloc_align(MAX_FILE_TEST * sizeof(file_info), CACHE_LINE, CACHE_LINE)) == NULL)
return FARADAY_ERR_MEMORY;
// 1. trickbox_2: buffer sdram start address
*(volatile uint32_t *)(VPE + 0x1008) = (uint32_t)BS_fileinput;
// 2. trickbox_0: action-get_pattern_file
*(volatile uint32_t *)(VPE + 0x1000) = 0x00000003;
// 3. vpe: trigger
*(volatile uint32_t *)(VPE) = 0x60000003;
file_no = 0;
return FARADAY_ERR_OK;
}
boolean
bTest_GetBS(file_info *ptf, file_handle * pth)
{
char filename_temp[80];
int x;
if (BS_fileinput[file_no].filename[0] == '\0') {
ptf->filesize = 0;
return FARADAY_ERR_OK;
}
if ((pth->bitstream_file = s32Test_open(BS_fileinput[file_no].filename, "rb", VPE_FILE_BITSTREAM)) == NULL)
return FARADAY_ERR_FAIL;
ptf->filesize = BS_fileinput[file_no].filesize;
ptf->framesize = BS_fileinput[file_no].framesize;
x = (int)strrchr(BS_fileinput[file_no].filename, '/');
x = x - (int)BS_fileinput[file_no].filename + 1;
strncpy(filename_temp, BS_fileinput[file_no].filename, x);
filename_temp[x] = '\0';
strcat(filename_temp, "decu_gld.yuv");
if ((pth->yuv_gld_file = s32Test_open(filename_temp, "rb", VPE_FILE_YUV_GLD)) == NULL)
return FARADAY_ERR_FAIL;
x = (int)strrchr(BS_fileinput[file_no].filename, '/');
x = x - (int)BS_fileinput[file_no].filename + 1;
strncpy(filename_temp, BS_fileinput[file_no].filename, x);
filename_temp[x] = '\0';
strcat(filename_temp, "decu_gld.display");
if ((pth->rgb_gld_file = s32Test_open(filename_temp, "rb", VPE_FILE_RGB_GLD)) == NULL)
return FARADAY_ERR_FAIL;
++ file_no;
return FARADAY_ERR_OK;
}
void
vTest_FsdbDumpOff(void)
{
#ifdef TEST_BY_PATTERN_FILE
#ifdef FSDB_DUMP_ONOFF
// 1. trickbox_0: action-get_pattern_file
*(volatile uint32_t *)(VPE + 0x1000) = 0x00000004;
// 2. vpe: trigger
*(volatile uint32_t *)(VPE) = 0x60000003;
#endif
#endif
}
void
vTest_FsdbDumpOn(void)
{
#ifdef TEST_BY_PATTERN_FILE
#ifdef FSDB_DUMP_ONOFF
// 1. trickbox_0: action-get_pattern_file
*(volatile uint32_t *)(VPE + 0x1000) = 0x00000005;
// 2. vpe: trigger
*(volatile uint32_t *)(VPE) = 0x60000003;
#endif
#endif
}
void
vTest_close(int handle)
{
// 1. trickbox_2: file_handle
*(volatile uint32_t *)(VPE + 0x1008) = (uint32_t)handle;
// 2. trickbox_0: action-close
*(volatile uint32_t *)(VPE + 0x1000) = 0x00000006;
// 3. vpe: trigger
*(volatile uint32_t *)(VPE) = 0x60000003;
}
// additional function call for speed up simulation in VPE
int32_t
Mp4VDec_FillBuffer_VPE(void * ptDecHandle, uint8_t * ptBuf, uint32_t u32BufSize)
{
DECODER * dec = (DECODER *)ptDecHandle;
if (u32BufSize > (dec->u32BS_buf_sz - dec->u32BS_buf_sz_remain))
return FARADAY_ERR_FAIL;
if ((dec->u32BS_buf_sz_remain) && (dec->pu8BS_start_virt != dec->pu8BS_ptr_virt))
s32Test_memcpy(dec->pu8BS_start_virt, dec->pu8BS_ptr_virt, dec->u32BS_buf_sz_remain);
if (u32BufSize)
s32Test_memcpy(dec->pu8BS_start_virt + dec->u32BS_buf_sz_remain, ptBuf, u32BufSize);
dec->pu8BS_ptr_virt = dec->pu8BS_start_virt;
dec->pu8BS_ptr_phy = dec->pu8BS_start_phy;
dec->u32BS_buf_sz_remain += u32BufSize;
return FARADAY_ERR_OK;
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -