⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vpusdk.c

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 C
📖 第 1 页 / 共 4 页
字号:

    if(!handle)
	{
        ERRORMSG(TRUE, (TEXT("Invalid instance!\r\n")));
        return RETCODE_INVALID_HANDLE;
	}
	// Issue the IOCTL to flush the bitstream
    if (!DeviceIoControl(g_hVPU,        // file handle to the driver
        IOCTL_DEC_BIT_BUFFER_FLUSH,     // I/O control code
        &handle,				    	// in buffer
        sizeof(DecHandle),              // in buffer size
        &retcode,                       // out buffer
        sizeof(RetCode),                // out buffer size
        &retnum,                        // number of bytes returned
        NULL))                          // ignored (=NULL)
    {
        ERRORMSG(TRUE, (TEXT("IOCTL_DEC_BIT_BUFFER_FLUSH failed!\r\n")));
		return RETCODE_FAILURE;
    }
    return retcode;
}

//------------------------------------------------------------------------------
//
//  Function:  vpu_DecGiveCommand
//
//  This function sends the command to the decoder.
//
//  Parameters: 
//      handle
//          [in] Handle obtained form vpu_DecOpen().
//      cmd
//          [in] Command sent to decoder
//      param
//          [in/out] Parameter used for specific cmd.
//  Returns:
//      RETCODE_SUCCESS for successful closing.
//      RETCODE_INVALID_HANDLE for invalid handle.
//      RETCODE_INVALID_COMMAND for invalid command
//      RETCODE_INVALID_PARAM for invalid parameter.
//      RETCODE_ROTATOR_OUTPUT_NOT_SET for no output setting.
//      RETCODE_ROTATOR_STRIDE_NOT_SET for no stride setting.
//      RETCODE_INVALID_STRIDE for invalid input stride value
//
//------------------------------------------------------------------------------
RetCode vpu_DecGiveCommand(DecHandle handle, CodecCommand cmd, void *param)
{    
    DecGiveCommandInput input;
	RetCode retcode;
	DWORD   retnum;

    if(!handle)
	{
        ERRORMSG(TRUE, (TEXT("Invalid instance!\r\n")));
        return RETCODE_INVALID_HANDLE;
	}

	input.handle = handle;
	input.cmd = cmd;
	input.pparam = param;

	// Issue the IOCTL to send the command to a decoder
    if (!DeviceIoControl(g_hVPU,        // file handle to the driver
        IOCTL_DEC_GIVE_COMMAND,         // I/O control code
        &input,			    	    	// in buffer
        sizeof(DecGiveCommandInput),    // in buffer size
        &retcode,                       // out buffer
        sizeof(RetCode),                // out buffer size
        &retnum,                        // number of bytes returned
        NULL))                          // ignored (=NULL)
    {
        ERRORMSG(TRUE, (TEXT("IOCTL_DEC_GIVE_COMMAND failed!\r\n")));
		return RETCODE_FAILURE;
    }

    return retcode;
}

//------------------------------------------------------------------------------
//
//  Function:  vpu_AllocPhysMem
//
//  This function allocates physically contiguous memory
//  
//  Parameters:  
//      cbSize   
//          [in] Number of bytes to allocate
//
//      VPUMemAlloc
//          [out] Pointer to a PhysicalAddress that stores 
//          the physical address of the memory allocation.
//
//  Returns:
//      RETCODE_SUCCESS for success.
//      RETCODE_FAILURE for failure
// 
//------------------------------------------------------------------------------
RetCode vpu_AllocPhysMem(Uint32 cbSize, VPUMemAlloc *pmemalloc)
{    
	DWORD   retnum;

    if(g_hVPU == NULL) 
    {
        ERRORMSG(TRUE, (TEXT("VPU isn't initialized!\r\n")));
        return RETCODE_FAILURE;
    }

	// Issue the IOCTL to allocate physcial memory for VPU
    if (!DeviceIoControl(g_hVPU,        // file handle to the driver
        IOCTL_ALLOC_PHY_MEM,            // I/O control code
        &cbSize,			    	    // in buffer
        sizeof(Uint32),                 // in buffer size
        pmemalloc,                       // out buffer
        sizeof(VPUMemAlloc),            // out buffer size
        &retnum,                        // number of bytes returned
        NULL))                          // ignored (=NULL)
    {
        ERRORMSG(TRUE, (TEXT("IOCTL_ALLOC_PHY_MEM failed!\r\n")));
		return RETCODE_FAILURE;
    }

    return RETCODE_SUCCESS;
}

//------------------------------------------------------------------------------
//
//  Function:  vpu_FreePhysMem
//
//  This function releases physical memory back to the system
//  
//  Parameters:
//      VPUMemAlloc
//          [in] Pointer to a PhysicalAddress that stores 
//          the physical address of the memory allocation.
//
//  Returns:
//      RETCODE_SUCCESS for success.
//      RETCODE_FAILURE for failure
//
//------------------------------------------------------------------------------
RetCode vpu_FreePhysMem(VPUMemAlloc *pmemalloc)
{    
	DWORD   retnum;

    if(g_hVPU == NULL) 
    {
        ERRORMSG(TRUE, (TEXT("VPU isn't initialized!\r\n")));
        return RETCODE_FAILURE;
    }

	// Issue the IOCTL to release physcial memory for VPU
    if (!DeviceIoControl(g_hVPU,        // file handle to the driver
        IOCTL_FREE_PHY_MEM,             // I/O control code
        pmemalloc,			    	    // in buffer
        sizeof(VPUMemAlloc),            // in buffer size
        NULL,                           // out buffer
        0,                              // out buffer size
        &retnum,                        // number of bytes returned
        NULL))                          // ignored (=NULL)
    {
        ERRORMSG(TRUE, (TEXT("IOCTL_FREE_PHY_MEM failed!\r\n")));
		return RETCODE_FAILURE;
    }

    return RETCODE_SUCCESS;
}

//------------------------------------------------------------------------------
//
//  Function:  vpu_GetPhysAddrFromVirtAddr
//
//  This function gets physical address from inputted virtual address
//  
//  Parameters:
//      pVirtAdd
//          [in]  Pointer to a specified virtual buffer
//      size
//          [in]  Size of the virtual buffer
//      pPhysAdd
//          [out] Pointer to the pysical address of specified virtual buffer
//
//  Returns:
//      RETCODE_SUCCESS for success.
//      RETCODE_FAILURE for failure
// 
//------------------------------------------------------------------------------
RetCode vpu_GetPhysAddrFromVirtAddr(void *lpvAddress, Uint32 cbSize, PhysicalAddress* lppAddress)
{
	GetPhysAddressInput getPhysAddrInput;
	DWORD  retnum;
    if(g_hVPU == NULL) 
    {
        ERRORMSG(TRUE, (TEXT("VPU isn't initialized!\r\n")));
        return RETCODE_NOT_INITIALIZED;
    }

	getPhysAddrInput.lpvAddress = lpvAddress;
	getPhysAddrInput.size       = cbSize;
	// Issue the IOCTL to get VPU firmware version information
    if (!DeviceIoControl(g_hVPU,    // file handle to the driver
        IOCTL_GET_PHY_ADDR,         // I/O control code
        &getPhysAddrInput,		  // in buffer
        sizeof(GetPhysAddressInput), // in buffer size
        (PBYTE)(lppAddress),           // out buffer
        sizeof(PhysicalAddress),   // out buffer size
        &retnum,                    // number of bytes returned
        NULL))                      // ignored (=NULL)
    {
        ERRORMSG(TRUE, (TEXT("IOCTL_LOCKPAGES failed!\r\n")));
		return RETCODE_FAILURE;
    }

	return RETCODE_SUCCESS;
}

//------------------------------------------------------------------------------
//
//  Function:  vpu_EncOpen
//
//  This function opens a encoding processing instance.
//
//  Parameters: 
//      pHandle
//          [out] Pointer to the storage that contains the handle by which
//          you can refer to an encoder instance. NULL returned if no instance
//          is available.
//      pop
//          [in] Pointer to the EncOpenParam type which describes parameters
//          necessary for decoding
//
//  Returns:
//      RETCODE_SUCCESS for in acquisition of an encoder 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_EncOpen(EncHandle *pHandle, EncOpenParam *pop)
{
	EncOpenOutput	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_ENC_OPEN,             // I/O control code
        pop,					    // in buffer
        sizeof(EncOpenParam),       // in buffer size
        &outputparam,               // out buffer
        sizeof(EncOpenOutput),      // out buffer size
        &retnum,                    // number of bytes returned
        NULL))                      // ignored (=NULL)
    {
        ERRORMSG(TRUE, (TEXT("IOCTL_ENC_OPEN failed!\r\n")));
		return RETCODE_FAILURE;
    }

	*pHandle = outputparam.handle;
 
    return outputparam.retcode;
}

//------------------------------------------------------------------------------
//
//  Function:  vpu_EncClose
//
//  This function closed the encoder instance
//
//  Parameters: 
//      handle
//          [in] Pointer to the handle obtained form vpu_EncOpen().
//  Returns:
//      RETCODE_SUCCESS for successful closing.
//      RETCODE_INVALID_HANDLE  for invalid handle.
//      RETCODE_FAILURE_TIMEOUT for timeout on calling
//
//------------------------------------------------------------------------------
RetCode vpu_EncClose(EncHandle handle)
{
	RetCode encret;
	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_ENC_CLOSE,            // I/O control code
        &handle,					// in buffer
        sizeof(EncHandle),          // in buffer size
        &encret,                    // out buffer
        sizeof(RetCode),            // out buffer size
        &retnum,                    // number of bytes returned
        NULL))                      // ignored (=NULL)
    {
        ERRORMSG(TRUE, (TEXT("IOCTL_ENC_CLOSE failed!\r\n")));
		return RETCODE_FAILURE;
    }
    return encret;
}

//------------------------------------------------------------------------------
//
//  Function:  vpu_EncGetInitialInfo
//
//  This function gets the bitstream header information.
//
//  Parameters: 
//      handle
//          [in] Pointer to the handle obtained form vpu_EncOpen().
//      info
//          [out] Pointer to EncInitialInfo data structure
//  Returns:
//      RETCODE_SUCCESS for successful closing.
//      RETCODE_FAILURE for failure in getting initial information
//      RETCODE_INVALID_HANDLE for invalid handle.
//      RETCODE_INVALID_PARAM for invalid info pinter.
//      RETCODE_WRONG_CALL_SEQUENCE for wrong calling sequence.
//      RETCODE_CALLED_BEFORE for the case called before.
//      RETCODE_FAILURE_TIMEOUT for timeout on the calling
//
//------------------------------------------------------------------------------
RetCode vpu_EncGetInitialInfo(EncHandle handle, EncInitialInfo * info)
{
	EncGetInitialInfoOutput outputparam;
	DWORD retnum;

    if(!handle || !info)
	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -