📄 halvpe.cpp
字号:
// -----------------------------------------------------------------------------
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) 1997-2000 Microsoft Corporation. All Rights Reserved.
// COPYRIGHT (C) 1999-2000 IGS TECHNOLOGIES, INC. (iGST)
//
// -----------------------------------------------------------------------------
#include "precomp.h"
#ifdef DD_ENABLE
//#include <nkintr.h>
#include <mmddk.h>
#include <wdm.h>
#ifdef VPE_ENABLE
// Local variables
DWORD dwCurrentSurface;
BOOL bVPEWeave = FALSE;
BOOL bVPEFirstTime = FALSE;
/* data */
const DDPIXELFORMAT InputFormats[] = {
{sizeof(DDPIXELFORMAT),DDPF_FOURCC, mmioFOURCC('Y','U','Y','V'),16,(DWORD)-1,(DWORD)-1,(DWORD)-1},
{sizeof(DDPIXELFORMAT),DDPF_FOURCC, mmioFOURCC('U','Y','V','Y'),16,(DWORD)-1,(DWORD)-1,(DWORD)-1},
{sizeof(DDPIXELFORMAT),DDPF_RGB, 0, 16, (DWORD)0xF800,(DWORD)0x07E0,(DWORD)0x001F}, //5-6-5 RGB
// {sizeof(DDPIXELFORMAT),DDPF_RGB, 0, 16, (DWORD)0x7C00,(DWORD)0x03E0,(DWORD)0x001F} //5-5-5 RGB
};
#define MAX_VIDEO_INPUT_FORMATS sizeof(InputFormats)/sizeof(DDPIXELFORMAT)
// It seems that SMI input and output formats are the same
//const DDPIXELFORMAT OutputFormats[] = {
// {sizeof(DDPIXELFORMAT),DDPF_FOURCC, mmioFOURCC('Y','U','Y','V'),16,(DWORD)-1,(DWORD)-1,(DWORD)-1},
//};
//#define MAX_VIDEO_OUTPUT_FORMATS sizeof(OutputFormats)/sizeof(DDPIXELFORMAT)
/* VPE Port Type Definition*/
// {A472D5F5-0FD9-4ac1-8E76-78E34A1F9657}
static const GUID DDVPTYPE_PHILIPS_SAA7118_8 =
{ 0xa472d5f5, 0x0fd9, 0x4ac1, { 0x8e, 0x76, 0x78, 0xe3, 0x4a, 0x1f, 0x96, 0x57 } };
// {F577F5BA-297E-4c51-90D0-91AE72B38BF5}
static const GUID DDVPTYPE_PHILIPS_SAA7118_16 =
{ 0xf577f5ba, 0x297e, 0x4c51, { 0x90, 0xd0, 0x91, 0xae, 0x72, 0xb3, 0x8b, 0xf5 } };
const GUID *SupportedGUID[] = {
// &DDVPTYPE_CCIR656,
// &DDVPTYPE_BROOKTREE,
&DDVPTYPE_PHILIPS,
&DDVPTYPE_E_HREFH_VREFL,
&DDVPTYPE_E_HREFH_VREFH,
&DDVPTYPE_E_HREFL_VREFL,
&DDVPTYPE_E_HREFL_VREFH,
&DDVPTYPE_PHILIPS_SAA7118_8,
&DDVPTYPE_PHILIPS_SAA7118_16
};
// The following table must following the above table exactly
enum eVideoPortType {
// VPE_CCIR656,
// VPE_BROOKTREE,
VPE_PHILIPS,
VPE_E_HREFH_VREFL,
VPE_E_HREFH_VREFH,
VPE_E_HREFL_VREFL,
VPE_E_HREFL_VREFH,
VPE_PHILIPS_SAA7118_8,
VPE_PHILIPS_SAA7118_16
};
#define MAX_SUPPORTED_DDVPTYPE sizeof(SupportedGUID)/sizeof(void*)
/* helper */
int IsVPTypeSupported(GUID *pguid)
{
for (int i=0; i<MAX_SUPPORTED_DDVPTYPE; i++) {
if (memcmp(SupportedGUID[i],pguid,sizeof(GUID))==0) return i;
}
return -1;
}
// SMI Implemented
DWORD WINAPI HalCanCreateVideoPort(LPDDHAL_CANCREATEVPORTDATA pd)
{
/*
typedef struct _DDHAL_CANCREATEVPORTDATA {
LPDDRAWI_DIRECTDRAW_LCL lpDD; // driver struct
LPDDVIDEOPORTDESC lpDDVideoPortDesc;
HRESULT ddRVal; // return value
LPDDHALVPORTCB_CANCREATEVIDEOPORT CanCreateVideoPort; // PRIVATE: ptr to callback
} DDHAL_CANCREATEVPORTDATA;
*/
//Well, We do.
DEBUGENTER( HalCanCreateVideoPort );
//DebugBreak();
/*
* If the pd->lpDDVideoPortDesc can not be supported, set
* pd->ddRVal to the correct error code and return
* DDHAL_DRIVER_HANDLED
*/
LPDDVIDEOPORTCONNECT pvpd = &pd->lpDDVideoPortDesc->VideoPortType;
if (IsVPTypeSupported(&pvpd->guidTypeID) == -1)
{
pd->ddRVal = DDERR_INVALIDDIRECTDRAWGUID; // TBD: Better error code
return DDHAL_DRIVER_HANDLED;
}
/*
* We can check videoport surf size here, and reject if it's too big, or not enough
* FIFO, or wrong type, or anything that you can think of.
*/
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
};
// SMI Implemented
DWORD WINAPI HalCreateVideoPort(LPDDHAL_CREATEVPORTDATA pd)
{
/*
typedef struct _DDHAL_CREATEVPORTDATA {
LPDDRAWI_DIRECTDRAW_LCL lpDD; // driver struct
LPDDVIDEOPORTDESC lpDDVideoPortDesc;
LPDDRAWI_DDVIDEOPORT_LCL lpVideoPort; // Video port created
HRESULT ddRVal; // return value
LPDDHALVPORTCB_CREATEVIDEOPORT CreateVideoPort; // PRIVATE: ptr to callback
} DDHAL_CREATEVPORTDATA;
*/
DEBUGENTER(HalCreateVideoPort);
//DebugBreak();
bVPEFirstTime = TRUE;
((SMI *)g_pGPE)->VPE_Disable();
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_NOTHANDLED;
/*
error:
pd->ddRVal = DDERR_GENERIC;
return DDHAL_DRIVER_HANDLED;
*/
};
// SMI Implemented
DWORD WINAPI HalFlipVideoPort(LPDDHAL_FLIPVPORTDATA pd)
{
/*
typedef struct _DDHAL_FLIPVPORTDATA {
LPDDRAWI_DIRECTDRAW_LCL lpDD; // driver struct
LPDDRAWI_DDVIDEOPORT_LCL lpVideoPort; // Video port object
LPDDRAWI_DDRAWSURFACE_LCL lpSurfCurr; // current surface
LPDDRAWI_DDRAWSURFACE_LCL lpSurfTarg; // target surface
HRESULT ddRVal; // return value
LPDDHALVPORTCB_FLIP FlipVideoPort; // PRIVATE: ptr to callback
} DDHAL_FLIPVPORTDATA;
*/
DEBUGENTER(HalFlipVideoPort);
//DebugBreak();
((SMI *)g_pGPE)->VPE_Disable();
DWORD dwTargOfs = pd->lpSurfTarg->lpGbl->fpVidMem - (DWORD)g_pVideoMemory;
//WORD wTargPitch = (WORD) pd->lpSurfTarg->lpGbl->lPitch;
((SMI *)g_pGPE)->VPE_SetDst(dwTargOfs);
dwCurrentSurface = dwTargOfs;
((SMI *)g_pGPE)->VPE_Enable();
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
};
// SMI Implemented
DWORD WINAPI HalGetVideoPortBandwidth(LPDDHAL_GETVPORTBANDWIDTHDATA pd)
{
/*
typedef struct _DDHAL_GETVPORTBANDWIDTHDATA {
LPDDRAWI_DIRECTDRAW_LCL lpDD; // driver struct
LPDDRAWI_DDVIDEOPORT_LCL lpVideoPort; // Video port object
LPDDPIXELFORMAT lpddpfFormat; // Format for bandwidth
DWORD dwWidth;
DWORD dwHeight;
DWORD dwFlags; // Prescale factor for bandwidth
LPDDVIDEOPORTBANDWIDTH lpBandwidth; // Returned bandwidth parameters
HRESULT ddRVal; // return value
LPDDHALVPORTCB_GETBANDWIDTH GetVideoPortBandwidth; // PRIVATE: ptr to callback
} DDHAL_GETVPORTBANDWIDTHDATA;
*/
DEBUGENTER(HalGetVideoPortBandwidth);
pd->lpBandwidth->dwSize = sizeof(DDVIDEOPORTBANDWIDTH);
pd->lpBandwidth->dwCaps = DDVPBCAPS_DESTINATION;
//if(pd->dwFlags & DDVPB_TYPE) {
// pd->lpBandwidth->dwCaps = DDVPBCAPS_SOURCE;
//}
if (pd->dwFlags & DDVPB_VIDEOPORT) {
DEBUGMSG(GPE_ZONE_VPE,(TEXT("Bandwidth for videoport\r\n")));
pd->lpBandwidth->dwOverlay = 1000;
pd->lpBandwidth->dwColorkey = 1000;
pd->lpBandwidth->dwYInterpolate = 1000;
pd->lpBandwidth->dwYInterpAndColorkey=1000;
}
if (pd->dwFlags & DDVPB_OVERLAY) {
DEBUGMSG(1,(TEXT("Bandwidth for overlay\r\n")));
pd->lpBandwidth->dwOverlay = 250;
pd->lpBandwidth->dwColorkey = 250;
pd->lpBandwidth->dwYInterpolate = 250;
pd->lpBandwidth->dwYInterpAndColorkey=250;
}
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
};
// SMI Implemented
DWORD WINAPI HalGetVideoPortInputFormats(LPDDHAL_GETVPORTINPUTFORMATDATA pd)
{
/*
typedef struct _DDHAL_GETVPORTINPUTFORMATDATA {
LPDDRAWI_DIRECTDRAW_LCL lpDD; // driver struct
LPDDRAWI_DDVIDEOPORT_LCL lpVideoPort; // Video port object
DWORD dwFlags; // VBI, regular, or both
LPDDPIXELFORMAT lpddpfFormat; // Array of formats
DWORD dwNumFormats; // # of formats in array
HRESULT ddRVal; // return value
LPDDHALVPORTCB_GETINPUTFORMATS GetVideoPortInputFormats; // PRIVATE: ptr to callback
} DDHAL_GETVPORTINPUTFORMATDATA;
*/
DEBUGENTER(HalGetVideoPortInputFormats);
//DebugBreak();
pd->dwNumFormats = MAX_VIDEO_INPUT_FORMATS;
if (pd->lpddpfFormat) {
DEBUGMSG(GPE_ZONE_VPE,(TEXT("Fill input format to buffer\r\n")));
memcpy (pd->lpddpfFormat, InputFormats, (sizeof(DDPIXELFORMAT)*pd->dwNumFormats));
}
else {
DEBUGMSG(GPE_ZONE_VPE,(TEXT("Need only number of input format\r\n")));
}
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
};
// SMI Implemented
DWORD WINAPI HalGetVideoPortOutputFormats(LPDDHAL_GETVPORTOUTPUTFORMATDATA pd)
{
/*
typedef struct _DDHAL_GETVPORTOUTPUTFORMATDATA {
LPDDRAWI_DIRECTDRAW_LCL lpDD; // driver struct
LPDDRAWI_DDVIDEOPORT_LCL lpVideoPort; // Video port object
DWORD dwFlags; // VBI, regular, or both
LPDDPIXELFORMAT lpddpfInputFormat; // Input format
LPDDPIXELFORMAT lpddpfOutputFormats; // Array of output formats
DWORD dwNumFormats; // # of formats in array
HRESULT ddRVal; // return value
LPDDHALVPORTCB_GETOUTPUTFORMATS GetVideoPortOutputFormats; // PRIVATE: ptr to callback
} DDHAL_GETVPORTOUTPUTFORMATDATA;
*/
DEBUGENTER(HalVideoPortOutputFormats);
//DebugBreak();
//Actually, we should validate input format first.
//Base on input format, we decide which output format is supported.
/*
pd->dwNumFormats = 0;
if (pd->dwFlags & DDVPFORMAT_VIDEO) {
pd->dwNumFormats++;
if (pd->lpddpfOutputFormats) {
memcpy (pd->lpddpfOutputFormats, &OutputFormats[0], sizeof (DDPIXELFORMAT));
}
}
*/
pd->dwNumFormats = MAX_VIDEO_INPUT_FORMATS;
// SMI support same Input and Output formats
if (pd->lpddpfOutputFormats) {
DEBUGMSG(GPE_ZONE_VPE,(TEXT("Fill output format to buffer\r\n")));
memcpy (pd->lpddpfOutputFormats, InputFormats, (sizeof(DDPIXELFORMAT)*pd->dwNumFormats));
}
else {
DEBUGMSG(GPE_ZONE_VPE,(TEXT("Need only number of output format\r\n")));
}
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
};
// SMI Implemented
DWORD WINAPI HalGetVideoPortField(LPDDHAL_GETVPORTFIELDDATA pd)
{
/*
typedef struct _DDHAL_GETVPORTFIELDDATA {
LPDDRAWI_DIRECTDRAW_LCL lpDD; // driver struct
LPDDRAWI_DDVIDEOPORT_LCL lpVideoPort; // Video port object
BOOL bField; // TRUE if even
HRESULT ddRVal; // return value
LPDDHALVPORTCB_GETFIELD GetVideoPortField; // PRIVATE: ptr to callback
} DDHAL_GETVPORTFIELDDATA;
*/
DEBUGENTER(HalGetVideoPortField);
// DebugBreak();
int wGUID = IsVPTypeSupported(&(pd->lpVideoPort->ddvpDesc.VideoPortType.guidTypeID));
if (wGUID == -1) {
pd->ddRVal = DDERR_VIDEONOTACTIVE;
}
else if (((SMI *)g_pGPE)->VPE_IsEnable()) {
pd->bField = ((SMI *)g_pGPE)->VPE_IsEvenField();
pd->ddRVal = DD_OK;
}
else {
pd->ddRVal = DDERR_VIDEONOTACTIVE;
}
return DDHAL_DRIVER_HANDLED;
};
// SMI Implemented
DWORD WINAPI HalGetVideoPortLine(LPDDHAL_GETVPORTLINEDATA pd)
{
/*
typedef struct _DDHAL_GETVPORTLINEDATA {
LPDDRAWI_DIRECTDRAW_LCL lpDD; // driver struct
LPDDRAWI_DDVIDEOPORT_LCL lpVideoPort; // Video port object
DWORD dwLine; // Current line counter
HRESULT ddRVal; // return value
LPDDHALVPORTCB_GETLINE GetVideoPortLine; // PRIVATE: ptr to callback
} DDHAL_GETVPORTLINEDATA;
*/
DEBUGENTER(HalGetVideoPortLine);
// DebugBreak();
/*
* (1)Make sure the video port is ON. If not, set
* pd->ddRVal to DDERR_VIDEONOTACTIVE and return.
* (2)Readback the current line number and put it in
* pd->dwLine
*/
int wGUID = IsVPTypeSupported(&(pd->lpVideoPort->ddvpDesc.VideoPortType.guidTypeID));
if (wGUID == -1) {
pd->ddRVal = DDERR_VIDEONOTACTIVE;
}
else if (((SMI *)g_pGPE)->VPE_IsEnable()) {
pd->dwLine = 0; // SMI Hardware Do Not Support Read back line
pd->ddRVal = DD_OK;
}
else {
pd->ddRVal = DDERR_VIDEONOTACTIVE;
}
return DDHAL_DRIVER_HANDLED;
};
// SMI Implemented
DWORD WINAPI HalGetVideoPortConnectInfo(LPDDHAL_GETVPORTCONNECTDATA pd)
{
/*
typedef struct _DDHAL_GETVPORTCONNECTDATA {
LPDDRAWI_DIRECTDRAW_LCL lpDD; // driver struct
DWORD dwPortId; // ID of desired video port
LPDDVIDEOPORTCONNECT lpConnect; // Array of DDVIDEOPORTCONNECT structures
DWORD dwNumEntries; // # of structures in array
HRESULT ddRVal; // return value
LPDDHALVPORTCB_GETVPORTCONNECT GetVideoPortConnectInfo; // PRIVATE: ptr to callback
} DDHAL_GETVPORTCONNECTDATA;
*/
LPDDVIDEOPORTCONNECT pcn = pd->lpConnect;
DEBUGENTER(HalGetVideoPortConnectInfo);
//DebugBreak();
pd->dwNumEntries = MAX_SUPPORTED_DDVPTYPE;
/*
* If pd->lpGUIDs is NULL, simply return the number of GUIDS
* supported
* Otherwise, copy the supported GUIDs into the specifed buffer.
* The HAL is guarenteed that the buffer is large enough to hold
* the GUIDs.
*/
if (pcn)
{
for (int i=0; i< MAX_SUPPORTED_DDVPTYPE; i++)
{
pcn->dwSize = sizeof(DDVIDEOPORTCONNECT);
pcn->dwPortWidth = 16; // SMI ZV port is always 16 bits width
memcpy(&pcn->guidTypeID, SupportedGUID[i], sizeof(GUID));
pcn->dwFlags = DDVPCONNECT_INVERTPOLARITY |
DDVPCONNECT_DISCARDSVREFDATA |
//DDVPCONNECT_HALFLINE |
DDVPCONNECT_INTERLACED |
//DDVPCONNECT_SHAREEVEN |
//DDVPCONNECT_VACT |
//DDVPCONNECT_DOUBLECLOCK |
//DDVPCONNECT_SHAREODD |
0;
pcn++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -