📄 deblock_test.sc
字号:
// -------------------------------------------------------------------// ?2005 Stream Processors, Inc. All rights reserved.// This Software is the property of Stream Processors, Inc. (SPI) and// is Proprietary and Confidential. It has been provided under// license for solely use in evaluating and/or developing code for a// stream processor device. Any use of the Software to develop code// for a semiconductor device not manufactured by or for SPI is// prohibited. Unauthorized use of this Software is strictly// prohibited.//// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES ARE GIVEN,// WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING WARRANTIES OR// MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,// NONINFRINGEMENT AND TITLE. RECIPIENT SHALL HAVE THE SOLE// RESPONSIBILITY FOR THE ADEQUATE PROTECTION AND BACK-UP OF ITS DATA// USED IN CONNECTION WITH THIS SOFTWARE. IN NO EVENT WILL SPI BE// LIABLE FOR ANY CONSEQUENTIAL DAMAGES WHATSOEVER, INCLUDING LOSS OF// DATA OR USE, LOST PROFITS OR ANY INCIDENTAL OR SPECIAL DAMAGES,// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS// SOFTWARE, WHETHER IN ACTION OF CONTRACT OR TORT, INCLUDING// NEGLIGENCE. SPI FURTHER DISCLAIMS ANY LIABILITY WHATSOEVER FOR// INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS OF ANY THIRD// PARTY.// -------------------------------------------------------------------//--------------------------------------------------------------------// File: $File: //depot/main/software/demo/deblock/deblock_test.c $// Revision: $Revision: #3 $// Last Modified: $DateTime: 2007/06/20 19:49:19 $//// Description:// Deblocking filter test program//--------------------------------------------------------------------#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include <assert.h>#include <time.h>#include "spi_common.h"#include "const_defines.h"#include "encoder_context.h"#include "mb_info.h"void deblock_frame_sc(encoder_context_t *p_enc);void deblock_frame_ref(encoder_context_t *p_enc);//--------------------------------------------------------------------// Local Protocols//--------------------------------------------------------------------int deblock_test();void ParseArguments(int argc, char *argv[], int* NumTests, int* Width, int* Height, int* Random, unsigned int* Seed, int* use_jm_data, int* PrintErr);void Success();void CreateFrame(yuv_frame_t* Frame, int Width, int Height, int buf_width, int buf_height);void DestroyFrame(yuv_frame_t* Frame);void CopyFrame(yuv_frame_t* FrameIn, yuv_frame_t* FrameOut);void InitPixels(yuv_frame_t* Frame, int Random);void InitMBContext(S_BLK_MB_INFO *pBlkMBInfo, S_BLK_MB_INFO_COMPRESSED *p_blk_mb_info_comp, int Random, int NumMBx, int NumMBy);void RandomData(unsigned char *arr, int len);void LinearData(unsigned char *arr, int len);int CompareData(unsigned char *arr1, unsigned char *arr2, int len, char *name, int width);int CompareDecData(unsigned char *arr1,unsigned char *arr2, int width,int height, char *name);char * jm_data_file = NULL;int PrintErr = 0;//--------------------------------------------------------------------int spi_main(int argc, char *argv[])//--------------------------------------------------------------------{ ////////////////////////////////////////////////////// // Initialize and parse parameters ////////////////////////////////////////////////////// int Width = 1280; int Height = 720; int Random = 1;#ifndef SPI_TARGET_DEVICE unsigned int Seed = time(NULL);#else unsigned int Seed = 1;#endif //! SPI_TARGET_DEVICE int NumTests = 1; //int PrintErr = 1; int use_jm_data = 0; yuv_frame_t RefFrame, StrFrame; int NumLumaPix = 0; int NumChromaPix = 0; int NumMBx = 0; int NumMBy = 0; S_BLK_MB_INFO *pBlkMBInfo = NULL; S_BLK_MB_INFO_COMPRESSED *p_blk_mb_info_comp = NULL; int n; SPI_PERF_T deblock_timer; ParseArguments(argc, argv, &NumTests, &Width, &Height, &Random, &Seed, &use_jm_data, &PrintErr); spi_start_trace(); ////////////////////////////////////////////////////// // Initialize Random seed with time() for a different data input // each time this function is called. ////////////////////////////////////////////////////// srand(Seed); if (Random) { spi_printf("Random seed used = %u\n", Seed); } spi_printf("\nRunning tests with an image size of %d by %d\n\n", Width, Height); ////////////////////////////////////////////////////// // Error checking and derivations ////////////////////////////////////////////////////// assert(SPI_LANES == 16); assert(Width % 16 == 0); assert(Height % 16 == 0); assert(Height >= 64); NumMBx = Width / 16; NumMBy = Height / 16; ////////////////////////////////////////////////////// // Allocate memory ////////////////////////////////////////////////////// CreateFrame(&RefFrame, Width, Height, Width+2*16, Height+2*16); CreateFrame(&StrFrame, Width, Height, Width+2*16, Height+2*16); pBlkMBInfo = spi_malloc(NumMBx * NumMBy * BLOCKS_PER_MB * sizeof(*pBlkMBInfo)); p_blk_mb_info_comp = spi_malloc(NumMBx * NumMBy * BLOCKS_PER_MB * sizeof(*p_blk_mb_info_comp)); if ((pBlkMBInfo == NULL) || (p_blk_mb_info_comp == NULL)) { spi_printf("Error allocating memory for MB context!! Exiting..."); exit(-1); } spi_perf_init(&deblock_timer, "H.264 Deblocking"); ////////////////////////////////////////////////////// // Main loop over tests ////////////////////////////////////////////////////// for (n = 0; n < NumTests; n++) { int DisableFilter, FilterOffsetA, FilterOffsetB; int ResultY = 0, ResultU = 0, ResultV = 0, ResultHlf, ResultQt; int ResultYCF = 0, ResultUCF = 0; int uv_pad_sz = 8; spi_printf("Running test #%d of %d...\n", n+1, NumTests); // Initialize with random or deterministic linear data InitPixels(&RefFrame, Random); CopyFrame(&RefFrame, &StrFrame); InitMBContext(pBlkMBInfo, p_blk_mb_info_comp, Random, NumMBx, NumMBy); if (Random) { DisableFilter = ((rand() % 100) == 99) ? 2 : ((rand() % 2) ? 0 : 1); FilterOffsetA = ((rand() % 7) << 1) * ((rand() % 2) ? -1 : 0); FilterOffsetB = ((rand() % 7) << 1) * ((rand() % 2) ? -1 : 0); } else { DisableFilter = ((n % 7) % 3); FilterOffsetA = (((n % 5) % 7) << 1) * (((n % 9) % 2) ? -1 : 0); FilterOffsetB = (((n % 11) % 7) << 1) * (((n % 3) % 2) ? -1 : 0); } { encoder_context_t enc_ctxt; enc_ctxt.p_blk_mb_info = p_blk_mb_info_comp; enc_ctxt.pBlkMBInfo = pBlkMBInfo; enc_ctxt.loopfilter_params.disable_flag = DisableFilter; enc_ctxt.loopfilter_params.alpha_c0_offset = FilterOffsetA; enc_ctxt.loopfilter_params.beta_offset = FilterOffsetB; spi_printf("DisableFilter %d FilterOffsetA %d FilterOffsetB %d \n", DisableFilter, FilterOffsetA, FilterOffsetB); enc_ctxt.pRecFrame = &StrFrame; // Initialize deblocking for the sequence init_deblock_context(&enc_ctxt); // Call Stream Version spi_perf_start(&deblock_timer); deblock_frame_sc(&enc_ctxt); spi_perf_stop(&deblock_timer); enc_ctxt.pRecFrame = &RefFrame; deblock_frame_ref(&enc_ctxt); // Free deblocking context for the sequence free_deblock_context(&enc_ctxt); } // Check the results NumLumaPix = (Width+2*16) * (Height+2*16); NumChromaPix = (Width+2*16) * (Height+2*16) / 4; ResultY = CompareData(StrFrame.y, RefFrame.y, NumLumaPix, "Y", Width+2*16); //Disable top/bottom padding checks. ResultU = CompareData(StrFrame.u + uv_pad_sz * (Width+2*16)/2, RefFrame.u + uv_pad_sz * (Width+2*16)/2, NumChromaPix - 2*uv_pad_sz*(Width+2*16)/2, "U", (Width+2*16)/2); ResultV = CompareData(StrFrame.v + uv_pad_sz * (Width+2*16)/2, RefFrame.v + uv_pad_sz * (Width+2*16)/2, NumChromaPix - 2*uv_pad_sz*(Width+2*16)/2, "V", (Width+2*16)/2); if (ResultY || ResultU || ResultV) { spi_printf("Test #%d of %d Failed ( random seed = %d ) !!!\n\n", n+1, NumTests, Seed); exit(-1); } } spi_perf_print(&deblock_timer, 1); spi_runtime_kernel_dpu_perf_print(1); spi_stop_trace(); ////////////////////////////////////////////////////// // Cleanup ////////////////////////////////////////////////////// DestroyFrame(&RefFrame); DestroyFrame(&StrFrame); spi_free(pBlkMBInfo); spi_printf("\nSuccess!\n\n"); return(0);}//--------------------------------------------------------------------void ParseArguments//--------------------------------------------------------------------( int argc, char *argv[], int* NumTests, int* Width, int* Height, int* Random, unsigned int* Seed, int* use_jm_data, int* PrintErr)//--------------------------------------------------------------------{ int argnum = 1; *use_jm_data = 0; while (argnum < argc) { if (strcmp(argv[argnum], "-num") == 0) { *NumTests = atoi(argv[++argnum]); } else if (strcmp(argv[argnum], "-width") == 0) { *Width = atoi(argv[++argnum]); } else if (strcmp(argv[argnum], "-height") == 0) { *Height = atoi(argv[++argnum]); } else if (strcmp(argv[argnum], "-random") == 0) { argnum++; if (strcmp(argv[argnum], "y") == 0) { *Random = 1; } else if (strcmp(argv[argnum], "n") == 0) { *Random = 0; } else { spi_printf("Invalid argument to -random: %s\n", argv[argnum]); exit(-1); } } else if (strcmp(argv[argnum], "-jm_data") == 0) { argnum++; *use_jm_data = 1; jm_data_file = argv[argnum++]; } else if (strcmp(argv[argnum], "-seed") == 0) { *Seed = atoi(argv[++argnum]); } else if (strcmp(argv[argnum], "-printerr") == 0) { argnum++; if (strcmp(argv[argnum], "y") == 0) { *PrintErr = 1; } else if (strcmp(argv[argnum], "n") == 0) { *PrintErr = 0; } else { spi_printf("Invalid argument to -printerr: %s", argv[argnum]); exit(-1); } } else if (strcmp(argv[argnum], "-h") == 0) { spi_printf("\nArguments: \n"); spi_printf(" -h : print this help message\n"); spi_printf(" -num _num_ : Number of tests to run\n"); spi_printf(" (default: 1)\n"); spi_printf(" -width _num_ : width of image to test, must be a multiple of 16\n"); spi_printf(" (default: 256)\n"); spi_printf(" -height _num_ : height of image to test, must be a multiple of 16\n"); spi_printf(" (default: 256)\n"); spi_printf(" -random _y/n_ : use random data to initialize image (y or n)\n"); spi_printf(" (default: y)\n"); spi_printf(" -seed _num_ : seed to initialize random number generator\n"); spi_printf(" (default: time(NULL))\n"); spi_printf(" -printerr _y/n_ : print out image data and differences on failure\n"); spi_printf(" (default: y)\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -