神龙卡的底层我也有,动态连接库我也有,有一点我不懂,就是怎么控制OSD功能?哪位高手能指点一下,(关于Win API 函数 CoCreateInstance() 用法?)
这段代码是控制OSD功能的,
#include "stdafx.h"
#include "..//..//Inc//mpegcmn.h"
#include "..//..//Inc//irminc.h"
typedef struct
{
RMMULTIPLE_ITEM multi;
RMSTREAM_HEADER header;
}HEADER;
int main(int argc, _TCHAR* argv[])
{
HRESULT hr;
FILE *f;
int i;
IRmStream * pOSD;
IRmControlNode * pDevice;
IRmMapMem * pMemAlloc;
IRmObjectFinder *pIRmObjectFinder;
size_t count, size = 0;
BYTE buff_8[8];
MPEG_OVERLAY_RECT rc_dest = {100,10,100,100};
PUCHAR pshared = NULL;
if (argv[1] == NULL)
{
printf("USAGE: osd_test <filename>.osd/n");
return 1;
}
CoInitialize(NULL);
hr = CoCreateInstance(CLSID_RMBASE,NULL,CLSCTX_INPROC_SERVER,IID_IRmObjectFinder,(void**)&pIRmObjectFinder);
if (FAILED(hr)) goto exit_1;
// GET OSD
//
hr = pIRmObjectFinder->FindObject(
NULL,
FIRST_AVALIABLE_INSTANCE,
CATEGORY_PIN_OSD,
IID_IRmStream,
(void**)&pOSD);
pIRmObjectFinder->Release();
if (FAILED(hr)) goto exit_1;
/////////////////////////////////////////////////////////////////////////////////////
//do
something useful
pOSD->Reset();
long dwTvOutKeep;
pDevice = NULL;
hr = pOSD->QueryInterface(IID_IRmControlNode,(void**)&pDevice);
if (FAILED(hr)) goto exit_1;
hr = pOSD->QueryInterface(IID_IRmMapMem,(void**)&pMemAlloc);
if (FAILED(hr)) goto exit_1;
long HwLibVersion = 0, dwTvOut;
// switch to TV
//
pDevice->GetAttributes(MpegAttrCodeVersion,&HwLibVersion);
pDevice->GetAttributes(MpegAttrVideoTv,&dwTvOutKeep);
dwTvOut = dwTvOutKeep &~OUTPUT_OFF;
if (HwLibVersion < 9)
{
dwTvOut |= SET_TV;
}
else
{
dwTvOut |= SET_TV | 0x80000000;
dwTvOut &= ~SET_HDTV;
}
pDevice->SetAttributes(MpegAttrVideoTv,dwTvOut);
f = fopen(argv[1],"rb");
if (NULL == f) goto exit_10;
// Read header
//
count = fread(buff_8,sizeof(char),8,f);
if (count != 8) goto exit_20;
// extract some bitmap information from header
//
size = buff_8[1]<<8*2 | buff_8[2]<<8 | buff_8[3];
rc_dest.cX = buff_8[4] << 8 | buff_8[5];
rc_dest.cY = buff_8[6] << 8 | buff_8[7];
// rewind to begin
ning
//
if (0 == size) goto exit_20;
long pos = 0;
// if(fsetpos(f,&pos)) goto exit_20;
// if data will be sent using physically continious memory buffer
// it will be transferred by one DMA operation. OSD only: anything
// more then
~63K will be devided by separate transfers ~63K each,
// up to 8 transfers can be programmed by one VSYNC.
//
PVOID phys;
hr = pMemAlloc->GetDMABuffer(size,(void**)&pshared,&phys);
if (pshared == NULL)
{
goto exit_20;
}
fread(pshared,sizeof(char),size,f);
pOSD->Play();
// for(i=0;i<20;i++)
for(i=0;i<1;i++)
{
ULONG ret;
HEADER hdr;
ZeroMemory(&hdr,sizeof(hdr));
RMOVERLAPIO ovr = {0,0,0,0,CreateEvent(NULL,TRUE,FALSE,NULL)};
hdr.multi.Count = 1;
hdr.multi.Size = sizeof(HEADER);
hdr.header.Size = sizeof(RMSTREAM_HEADER);
hdr.header.pData = pshared;
hdr.header.FrameExtent = size;
// Send whole bitmapdo
wn
//
pOSD->Write(&hdr.multi,&ovr);
// Wait for completion
//
ret = WaitForSingleObject(ovr.hEvent,10000);
if (ret == WAIT_TIMEOUT)
{
printf(" !!! TIMEOUT/n");
}
// Attributes can be set only if bitmap was completely loaded in DRAM
// or after last packet with bitmap data has been released by the driver.
//
printf("Set OSD Destination: x - %X, y - %X, w - %X, h - %X/n",
rc_dest.X, rc_dest.Y, rc_dest.cX, rc_dest.cY);
pDevice->SetAttributes(MpegAttrOsdDest,(long)&rc_dest);
// rc_dest.X += 10;
// rc_dest.Y += 10;
pDevice->SetAttributes(MpegAttrOsdON,1);
CloseHandle(ovr.hEvent);
}
pOSD->Stop();
printf("Press any key/n");
_kbhit();
_getch();
if (NULL != pDevice)
{
// pDevice->SetAttributes(MpegAttrVideoTv,dwTvOutKeep);
}
pDevice->SetAttributes(MpegAttrOsdOFF,1);
// pDevice->SetAttributes(MpegAttrOsdFLUSH,0);
/////////////////////////////////////////////////////////////////////////////////////
// end
exit_20:
fclose(f);
if (NULL != pDevice)
{
pDevice->Release();
}
exit_10:
if (NULL != pMemAlloc)
{
if (NULL != pshared)
pMemAlloc->FreeDMABuffer(pshared);
pMemAlloc->Release();
}
pOSD->Release();
exit_1:
CoUninitialize();
exit(0);
return 0;
}