📄 pptest.cpp
字号:
//
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//-----------------------------------------------------------------------------
//
// File: PPTest.cpp
//
// This file contains test code for the PP driver.
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004-2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include <strsafe.h>
#include "pp.h"
#include "main.h"
#include "globals.h"
#include "bsp.h"
//-----------------------------------------------------------------------------
// External Functions
//-----------------------------------------------------------------------------
// External Variables
//-----------------------------------------------------------------------------
// Defines
#define PP_ZONE_INFO 0
#define PP_ZONE_ERROR 0
#define PP_ZONE_FUNCTION 0
#define PP_TEST_FUNCTION_ENTRY() \
g_pKato->Log(PP_ZONE_FUNCTION, (TEXT("++%s\r\n"), __WFUNCTION__))
#define PP_TEST_FUNCTION_EXIT() \
g_pKato->Log(PP_ZONE_FUNCTION, (TEXT("--%s\r\n"), __WFUNCTION__))
#ifdef DEBUG
// Debug zone bit positions
#define ZONEID_INFO 12
#define ZONEID_FUNCTION 13
#define ZONEID_WARN 14
#define ZONEID_ERROR 15
// Debug zone masks
#define ZONEMASK_INFO (1<<ZONEID_INFO)
#define ZONEMASK_FUNCTION (1<<ZONEID_FUNCTION)
#define ZONEMASK_WARN (1<<ZONEID_WARN)
#define ZONEMASK_ERROR (1<<ZONEID_ERROR)
// Debug zone args to DEBUGMSG
#define ZONE_INFO DEBUGZONE(ZONEID_INFO)
#define ZONE_FUNCTION DEBUGZONE(ZONEID_FUNCTION)
#define ZONE_WARN DEBUGZONE(ZONEID_WARN)
#define ZONE_ERROR DEBUGZONE(ZONEID_ERROR)
#endif
// Screen size
#define PP_TEST_SCREEN_WIDTH 240
#define PP_TEST_SCREEN_HEIGHT 320
#define PP_TEST_SCREEN_SIZE (PP_TEST_SCREEN_HEIGHT * PP_TEST_SCREEN_WIDTH * 2)
// Input parameters (YUV420)
#define PP_TEST_INPUT_FILENAME TEXT("\\release\\Capture.yuv")
// #define PP_TEST_INPUT_WIDTH 176
// #define PP_TEST_INPUT_HEIGHT 144
//#define PP_TEST_INPUT_WIDTH 640
//#define PP_TEST_INPUT_HEIGHT 480
#define PP_TEST_INPUT_WIDTH 240
#define PP_TEST_INPUT_HEIGHT 320
#define YUV420_U_OFFSET(x) (x * 2 / 3)
#define YUV420_V_OFFSET(x) (x * 5 / 6)
// Ouput parameters (RGB565/RGB888/YUV422)
#define PP_TEST_OUTPUT_RGB888 0
#define PP_TEST_OUTPUT_RGB565 1
#define PP_TEST_OUTPUT_YUV422 2
#define PP_TEST_OUTPUT_FORMAT PP_TEST_OUTPUT_RGB565
#if (PP_TEST_OUTPUT_FORMAT == PP_TEST_OUTPUT_RGB888)
#define PP_TEST_OUTPUT_FILENAME TEXT("\\release\\PpOut_RGB32.bmp")
#define PP_TEST_OUTPUT_WIDTH 176
#define PP_TEST_OUTPUT_HEIGHT 144
#define PP_TEST_OUTPUT_BPP 4
#elif (PP_TEST_OUTPUT_FORMAT == PP_TEST_OUTPUT_RGB565)
#define PP_TEST_OUTPUT_FILENAME TEXT("")
#define PP_TEST_OUTPUT_WIDTH 240
#define PP_TEST_OUTPUT_HEIGHT 320
// #define PP_TEST_OUTPUT_WIDTH 320
// #define PP_TEST_OUTPUT_HEIGHT 240
// #define PP_TEST_OUTPUT_WIDTH 160
// #define PP_TEST_OUTPUT_HEIGHT 120
#define PP_TEST_OUTPUT_BPP 2
#elif (PP_TEST_OUTPUT_FORMAT == PP_TEST_OUTPUT_YUV422)
#define PP_TEST_OUTPUT_FILENAME TEXT("\\release\\PpOut_YUV422.yuv")
#define PP_TEST_OUTPUT_WIDTH 176
#define PP_TEST_OUTPUT_HEIGHT 144
#define PP_TEST_OUTPUT_BPP 2
#endif
// Time interval
#define PP_TEST_TIME_INTERVAL 33 // For 30fps
//-----------------------------------------------------------------------------
// Types
//-----------------------------------------------------------------------------
// Global Variables
#ifdef DEBUG
extern DBGPARAM dpCurSettings =
{
_T("PP"),
{
_T(""), _T(""), _T(""), _T(""),
_T(""), _T(""), _T(""), _T(""),
_T(""),_T(""),_T(""),_T(""),
_T("Info"),_T("Function"),_T("Warnings"),_T("Errors")
},
ZONEMASK_ERROR | ZONEMASK_WARN | ZONEMASK_INFO
};
#endif
//-----------------------------------------------------------------------------
// Local Variables
static HANDLE hPP;
static HANDLE g_hPPEOFEvent;
static UINT8 *FrameBufferVirtualAddr;
//-----------------------------------------------------------------------------
// Local Functions
static BOOL PPTestInit();
static void PPTestDeinit();
static BOOL generateBMP(UINT8 *pImageBuf, INT32 width, INT32 height);
static void displayRGB565(UINT8 *pImageBuf, UINT32 width, UINT32 height);
void TestIdle()
{
DWORD dwStartTick, dwIdleSt, dwStopTick, dwIdleEd, PercentIdle;
dwIdleSt = GetIdleTime();
dwStartTick = GetTickCount();
Sleep(100);
dwIdleEd = GetIdleTime();
dwStopTick = GetTickCount();
DEBUGMSG(1,
(TEXT("%s: dwStartTick = %d, dwStopTick = %d, dwIdleSt = %d, dwIdleEd = %d, \r\n"),
__WFUNCTION__, dwStartTick, dwStopTick, dwIdleSt, dwIdleEd));
PercentIdle = ((100*(dwIdleEd - dwIdleSt)) / (dwStopTick - dwStartTick));
DEBUGMSG(1,
(TEXT("%s: PercentIdle = %d, \r\n"),
__WFUNCTION__, PercentIdle));
}
//------------------------------------------------------------------------------
//
// Function: PPTest
//
// This function tests the Post-processor, reading YUV420 frames from a
// file, converting them to RGB, and displaying them using the
// display overlay plane.
//
// Parameters:
// uiMsg
// [in] Ignored.
//
// tpParam
// [in] Ignored.
//
// lpFTE
// [in] Ignored.
//
// Returns:
// Specifies if the test passed (TPR_PASS), failed (TPR_FAIL), or was
// skipped (TPR_SKIP).
//
//------------------------------------------------------------------------------
TESTPROCAPI PPTest(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
INT32 startTime, nextFrameRunTime, waitTimeInMilliSec, currentTime;
ppConfigData ppData;
ppBuffers bufs;
HANDLE hPpTestFile;
#if (PP_TEST_OUTPUT_FORMAT == PP_TEST_OUTPUT_YUV422)
HANDLE hPpResultFile;
DWORD bytesWritten;
#endif
UINT8 *pInputFrameVirtAddr, *pInputFramePhysAddr;
UINT8 *pOutputFrameVirtAddr, *pOutputFramePhysAddr;
UINT32 iOutputWidth, iOutputHeight, iOutputBPP, iOutputStride;
UINT32 iInputWidth, iInputHeight, iInputStride;
DWORD iInputBytesPerFrame, iOutputBytesPerFrame, bytesRead;
DWORD iCurrentFrame = 0;
DWORD iFrameCountRead = 0;
BOOL bFirstFrame;
BOOL bCompleted = FALSE;
PP_TEST_FUNCTION_ENTRY();
// Validate that the shell wants the test to run
if (uMsg != TPM_EXECUTE)
return TPR_NOT_HANDLED;
// Initialization
PPTestInit();
// Allocate input buffers
iInputWidth = PP_TEST_INPUT_WIDTH;
iInputHeight = PP_TEST_INPUT_HEIGHT;
iInputStride = iInputWidth; // In pixels
iInputBytesPerFrame = iInputWidth * iInputHeight * 3 / 2;
pInputFrameVirtAddr = (UINT8 *) AllocPhysMem(iInputBytesPerFrame,
PAGE_EXECUTE_READWRITE, 0, 0, (ULONG *) &pInputFramePhysAddr);
// Allocate output buffers
iOutputWidth = PP_TEST_OUTPUT_WIDTH;
iOutputHeight = PP_TEST_OUTPUT_HEIGHT;
iOutputBPP = PP_TEST_OUTPUT_BPP;
// iOutputStride = iOutputWidth * iOutputBPP; // In bytes
// iOutputBytesPerFrame = iOutputHeight * iOutputWidth * iOutputBPP;
iOutputStride = PP_TEST_SCREEN_WIDTH * iOutputBPP; // In bytes
iOutputBytesPerFrame = iOutputHeight * iOutputStride;
pOutputFrameVirtAddr = (UINT8 *) AllocPhysMem(iOutputBytesPerFrame,
PAGE_EXECUTE_READWRITE, 0, 0, (ULONG *) &pOutputFramePhysAddr);
// Open file to read frames
hPpTestFile = CreateFile(
PP_TEST_INPUT_FILENAME, // "special" file name
GENERIC_READ, // desired access
0, // sharing mode
NULL, // security attributes (=NULL)
OPEN_EXISTING, // creation disposition
FILE_ATTRIBUTE_NORMAL, // flags and attributes
NULL); // template file (ignored)
if (hPpTestFile == INVALID_HANDLE_VALUE) {
g_pKato->Log(PP_ZONE_ERROR,
(TEXT("%s: Could not open file to read YUV data.\r\n"),
__WFUNCTION__));
return TPR_FAIL;
}
#if (PP_TEST_OUTPUT_FORMAT == PP_TEST_OUTPUT_YUV422)
// Open file to write YUV422 results
hPpResultFile = CreateFile(
PP_TEST_OUTPUT_FILENAME, // "special" file name
GENERIC_WRITE | GENERIC_READ, // desired access
0, // sharing mode
NULL, // security attributes (=NULL)
CREATE_ALWAYS, // creation disposition
FILE_ATTRIBUTE_NORMAL, // flags and attributes
NULL); // template file (ignored)
if (hPpResultFile == INVALID_HANDLE_VALUE) {
g_pKato->Log(PP_ZONE_ERROR,
(TEXT("%s: Could not open file to write post-processing results.\r\n"),
__WFUNCTION__));
return TPR_FAIL;
}
#endif
// Set up input configuration
ppData.inputSize.height = iInputHeight;
ppData.inputSize.width = iInputWidth;
ppData.inputStride = iInputStride;
// Set up output configuration
ppData.outputSize.height = iOutputHeight;
ppData.outputSize.width = iOutputWidth;
ppData.outputStride = iOutputStride;
#if (PP_TEST_OUTPUT_FORMAT == PP_TEST_OUTPUT_RGB888)
ppData.outputFormat = ppCSCOutputFormat_RGB32;
ppData.outputPixelFormat.component0_offset = 16;
ppData.outputPixelFormat.component1_offset = 8;
ppData.outputPixelFormat.component2_offset = 0;
ppData.outputPixelFormat.component0_width = 8;
ppData.outputPixelFormat.component1_width = 8;
ppData.outputPixelFormat.component2_width = 8;
#elif (PP_TEST_OUTPUT_FORMAT == PP_TEST_OUTPUT_RGB565)
ppData.outputFormat = ppCSCOutputFormat_RGB16;
ppData.outputPixelFormat.component0_offset = 11;
ppData.outputPixelFormat.component1_offset = 5;
ppData.outputPixelFormat.component2_offset = 0;
ppData.outputPixelFormat.component0_width = 5;
ppData.outputPixelFormat.component1_width = 6;
ppData.outputPixelFormat.component2_width = 5;
#elif (PP_TEST_OUTPUT_FORMAT == PP_TEST_OUTPUT_YUV422)
ppData.outputFormat = ppCSCOutputFormat_YUV422;
// YUYV case
ppData.outputPixelFormat.component0_offset = 24;
ppData.outputPixelFormat.component1_offset = 16;
ppData.outputPixelFormat.component2_offset = 0;
ppData.outputPixelFormat.component0_width = 8;
ppData.outputPixelFormat.component1_width = 8;
ppData.outputPixelFormat.component2_width = 8;
#endif
// Set up post-processing CSC equation
ppData.CSCEquation = ppCSCEquationA_1;
// Set up required operations if need
ppData.bDeblock = FALSE;
ppData.bDering = FALSE;
PPConfigure(hPP, &ppData);
// Read input file for new frame
if (!ReadFile(hPpTestFile, pInputFrameVirtAddr,
iInputBytesPerFrame, &bytesRead, NULL)) {
g_pKato->Log(PP_ZONE_ERROR,
(TEXT("%s: Read input file failed.\r\n"), __WFUNCTION__));
return TPR_FAIL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -