📄 vpusdk.c
字号:
//------------------------------------------------------------------------------
//
// Copyright (C) 2007, 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
//
//------------------------------------------------------------------------------
//
// File: vpusdk.c
//
// This module implements the VPU API interfaces by wrapping functions
// for accessing the stream interface for the VPU driver.
//
//-----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// INCLUDE FILES
//------------------------------------------------------------------------------
#pragma warning(push)
#pragma warning(disable: 4115)
#pragma warning(disable: 4201)
#pragma warning(disable: 4204)
#pragma warning(disable: 4214)
#include <windows.h>
#pragma warning(pop)
//#include <csp.h>
#include "vpu_api.h"
#include "vpu_io.h"
//----------------------------------------------------------------------------
// Global Variables
static HANDLE g_hVPU;
//------------------------------------------------------------------------------
//
// Function: vpu_Init
//
// This function initializes the video codec module hardware.
//
// Parameters:
// No inputs
//
// Returns:
// RETCODE_SUCCESS if initializing successfullly.
// RETCODE_FAILURE for error occuring.
//
//------------------------------------------------------------------------------
RetCode vpu_Init()
{
if(g_hVPU != NULL)
{
return RETCODE_CALLED_BEFORE;
}
g_hVPU = CreateFile(TEXT("VPU1:"), // name of device
GENERIC_READ|GENERIC_WRITE, // desired access
FILE_SHARE_READ|FILE_SHARE_WRITE, // sharing mode
NULL, // security attributes (ignored)
OPEN_EXISTING, // creation disposition
FILE_FLAG_RANDOM_ACCESS, // flags/attributes
NULL); // template file (ignored)
// if we failed to get handle to VPU
if (g_hVPU == INVALID_HANDLE_VALUE)
{
ERRORMSG(TRUE, (TEXT("CreateFile VPU failed!\r\n")));
return RETCODE_FAILURE;
}
return RETCODE_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: vpu_Deinit
//
// This function deinitializes the video codec module hardware.
//
// Parameters:
// No inputs
//
// Returns:
// No return value
//
//------------------------------------------------------------------------------
RetCode vpu_Deinit(void)
{
if(g_hVPU == NULL)
{
ERRORMSG(TRUE, (TEXT("VPU isn't initialized!\r\n")));
return RETCODE_NOT_INITIALIZED;
}
if(!CloseHandle(g_hVPU))
{
ERRORMSG(TRUE, (TEXT("Close VPU handle failed!\r\n")));
return RETCODE_FAILURE;
}
g_hVPU = NULL;
return RETCODE_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: vpu_IsBusy
//
// This function indicates if the BIT processor stops execution
// or starts execution
//
// Parameters:
// No inputs
//
// Returns:
// 0 for idle; Non-zero for busy
//
//------------------------------------------------------------------------------
RetCode vpu_IsBusy()
{
Uint32 vpubusy;
DWORD retnum;
if(g_hVPU == NULL)
{
ERRORMSG(TRUE, (TEXT("VPU isnot initialized!\r\n")));
return RETCODE_NOT_INITIALIZED;
}
// Issue the IOCTL to VPU busy status
if (!DeviceIoControl(g_hVPU, // file handle to the driver
IOCTL_VPU_IS_BUSY, // I/O control code
NULL, // in buffer
0, // in buffer size
&vpubusy, // out buffer
sizeof(Uint32), // out buffer size
&retnum, // number of bytes returned
NULL)) // ignored (=NULL)
{
ERRORMSG(TRUE, (TEXT("IOCTL_VPU_IS_BUSY failed!\r\n")));
return RETCODE_FAILURE;
}
if(vpubusy)
return RETCODE_BUSY;
else
return RETCODE_IDLE;
}
//------------------------------------------------------------------------------
//
// Function: vpu_GetVersionInfo
//
// This function gets the the version information of BIT Processor microcode
// by calling this function.
//
// Parameters:
// versionInfo
// [out] The 16 MSB means product ID and the 16 LSB means
// firmware version ID.
//
//
// Returns:
// RETCODE_SUCCESS for success
// RETCODE_FAILURE for failure
// RETCODE_NOT_INITIALIZED for not initialization
// RETCODE_FAILURE_TIMEOUT for timeout on this call
//
//------------------------------------------------------------------------------
RetCode vpu_GetVersionInfo(Uint32 *versionInfo)
{
DWORD retnum;
if(g_hVPU == NULL)
{
ERRORMSG(TRUE, (TEXT("VPU isn't initialized!\r\n")));
return RETCODE_NOT_INITIALIZED;
}
// Issue the IOCTL to get VPU firmware version information
if (!DeviceIoControl(g_hVPU, // file handle to the driver
IOCTL_VERSION_INFO, // I/O control code
NULL, // in buffer
0, // in buffer size
versionInfo, // out buffer
sizeof(Uint32), // out buffer size
&retnum, // number of bytes returned
NULL)) // ignored (=NULL)
{
ERRORMSG(TRUE, (TEXT("IOCTL_VERSION_INFO failed!\r\n")));
return RETCODE_FAILURE;
}
return RETCODE_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: vpu_DecOpen
//
// This function opens a decoding processing instance.
//
// Parameters:
// pHandle
// [out] Pointer to the storage that contains the handle by which
// you can refer to an decoder instance. NULL returned if no instance
// is available.
// pop
// [in] Pointer to the DecOpenParam type which describes parameters
// necessary for decoding
//
// Returns:
// RETCODE_SUCCESS for in acquisition of an decoder instance.
// RETCODE_FAILURE for Failure if now more free available instance
// RETCODE_INVALID_PARAM for pop is a NULL pointer,or some parameters
// passed are invalid.
// RETCODE_NOT_INITIALIZED for hardware being not initialized
// RETCODE_FAILURE_TIMEOUT for timeout on function call
//
//------------------------------------------------------------------------------
RetCode vpu_DecOpen(DecHandle *pHandle, DecOpenParam *pop)
{
DecOpenOutput outputparam;
DWORD retnum;
if(g_hVPU == NULL)
{
ERRORMSG(TRUE, (TEXT("VPU isn't initialized!\r\n")));
return RETCODE_NOT_INITIALIZED;
}
// Issue the IOCTL to open a decoder instance
if (!DeviceIoControl(g_hVPU, // file handle to the driver
IOCTL_DEC_OPEN, // I/O control code
pop, // in buffer
sizeof(DecOpenParam), // in buffer size
&outputparam, // out buffer
sizeof(DecOpenOutput), // out buffer size
&retnum, // number of bytes returned
NULL)) // ignored (=NULL)
{
ERRORMSG(TRUE, (TEXT("IOCTL_DEC_OPEN failed!\r\n")));
return RETCODE_FAILURE;
}
*pHandle = outputparam.handle;
return outputparam.retcode;
}
//------------------------------------------------------------------------------
//
// Function: vpu_DecClose
//
// This function closed the decoder instance
//
// Parameters:
// handle
// [in] Pointer to the handle obtained form vpu_DecOpen().
// Returns:
// RETCODE_SUCCESS for successful closing.
// RETCODE_INVALID_HANDLE for invalid handle.
// RETCODE_FAILURE_TIMEOUT for timeout on calling
//
//------------------------------------------------------------------------------
RetCode vpu_DecClose(DecHandle handle)
{
RetCode decret;
DWORD retnum;
if(!handle)
{
ERRORMSG(TRUE, (TEXT("Invalid instance!\r\n")));
return RETCODE_INVALID_HANDLE;
}
// Issue the IOCTL to close a decoder instance
if (!DeviceIoControl(g_hVPU, // file handle to the driver
IOCTL_DEC_CLOSE, // I/O control code
&handle, // in buffer
sizeof(DecHandle), // in buffer size
&decret, // out buffer
sizeof(RetCode), // out buffer size
&retnum, // number of bytes returned
NULL)) // ignored (=NULL)
{
ERRORMSG(TRUE, (TEXT("IOCTL_DEC_CLOSE failed!\r\n")));
return RETCODE_FAILURE;
}
return decret;
}
//------------------------------------------------------------------------------
//
// Function: vpu_DecSetEscSeqInit
//
// This function is provided to let application escape from hanging state
// while running vpu_DecGetInitialInfo()
//
// Parameters:
// handle
// [in] Pointer to the handle obtained form vpu_DecOpen().
// escape
// [in] Value to indicate if escaping from hang satus
// Returns:
// RETCODE_SUCCESS for successful closing.
// RETCODE_INVALID_HANDLE for invalid handle.
// RETCODE_FAILURE_TIMEOUT for timeout on the calling
//
//------------------------------------------------------------------------------
RetCode vpu_DecSetEscSeqInit(DecHandle handle, int escape)
{
RetCode retcode;
DecSetEscSeqInitInput inputparam;
DWORD retnum;
if(!handle)
{
ERRORMSG(TRUE, (TEXT("Invalid instance!\r\n")));
return RETCODE_INVALID_HANDLE;
}
inputparam.handle = handle;
inputparam.escape = escape;
// Issue the IOCTL to set escape register
if (!DeviceIoControl(g_hVPU, // file handle to the driver
IOCTL_DEC_SET_ESC_SEQ_INIT, // I/O control code
&inputparam, // in buffer
sizeof(DecSetEscSeqInitInput), // in buffer size
&retcode, // out buffer
sizeof(RetCode), // out buffer size
&retnum, // number of bytes returned
NULL)) // ignored (=NULL)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -