概述
\如何修改系统中已经注册的Filter的Merit值
typedef struct
{
DWORD dwVersion; //版本号
DWORD dwMerit; //Merit值
DWORD dwPinCount; //Pin的数量
DWORD dwReserved; //保留
}FILTER_HEADER;
typedef struct
{
DWORD dwVersion; //版本号
DWORD dwMerit; //Merit值
DWORD dwPinCount; //Pin的数量
DWORD dwReserved; //保留
}FILTER_HEADER;
BOOL SetFilterMerit(const char*inClsid,DWORD inMerit)
{
const char* cRegistryEntry="CLSID\{083863F1-70DE-11d0-BD40-00A0C911CE86}\Instance\";
const long cMaxLength=1024*16;
BYTE filterData[cMaxLength];
DWORD actualLength=0;
\生成Filter信息注册部分的注册表入口
char szEntry[1000];
strcpy(szEntry,cRegistryEntry);
strcat(szEntry,inClsid);
HKEY hKey=NULL;
LONG result=::RegOpenKeyEx(HKEY_CLASSES_ROOT,szEntry,0,KEY_ALL_ACCESS,&hKey);
BOOL pass=(result==ERROR_SUCCESS);
if(pass)
{
\读取FilterData的值
actualLength=actualLength;
result=::RegQueryValueEx(hKey,"FilterData",NULL,NULL,filterData,&actualLength);
pass=(result==ERROR_SUCCESS);
}
if(pass)
{
\修改FiterData中的Merit部分,然后写回到注册表
FILTER_HEADER *filterHeader=(FILTER_HEADER *)filterData;
filterHeader->dwMerit=inMerit;
result=::RegSetValueEx(hKey,"FilterData",NULL,REG_BINARy,filterData,actualLength);
pass=(result==ERROR_SUCCESS);
}
if(hKey)
{
::RegCloseKey(hKey);
}
return pass;
}
{
const char* cRegistryEntry="CLSID\{083863F1-70DE-11d0-BD40-00A0C911CE86}\Instance\";
const long cMaxLength=1024*16;
BYTE filterData[cMaxLength];
DWORD actualLength=0;
\生成Filter信息注册部分的注册表入口
char szEntry[1000];
strcpy(szEntry,cRegistryEntry);
strcat(szEntry,inClsid);
HKEY hKey=NULL;
LONG result=::RegOpenKeyEx(HKEY_CLASSES_ROOT,szEntry,0,KEY_ALL_ACCESS,&hKey);
BOOL pass=(result==ERROR_SUCCESS);
if(pass)
{
\读取FilterData的值
actualLength=actualLength;
result=::RegQueryValueEx(hKey,"FilterData",NULL,NULL,filterData,&actualLength);
pass=(result==ERROR_SUCCESS);
}
if(pass)
{
\修改FiterData中的Merit部分,然后写回到注册表
FILTER_HEADER *filterHeader=(FILTER_HEADER *)filterData;
filterHeader->dwMerit=inMerit;
result=::RegSetValueEx(hKey,"FilterData",NULL,REG_BINARy,filterData,actualLength);
pass=(result==ERROR_SUCCESS);
}
if(hKey)
{
::RegCloseKey(hKey);
}
return pass;
}
STDMETHODIMP CBaseInputPin::Receive(IMediaSample *pSample)
{
CheckPointer(pSample,E_POINTER);
ValidateReadPtr(pSample,sizeof(IMediaSample));
ASSERT(pSample);
\检查Filter内部状态,以及数据流传送状态
HRESULT hr=CheckStreaming();
if(S_OK!=hr)
{
return hr;
}
\查询IMediaSample2接口,获取输入Sample上的属性
IMediaSample2 *pSample2;
if(SUCCEEDED(pSample->QueryInterface(IID_IMediaSample2,(void **)&pSample2)))
{
hr=pSample2->GetProperties(sizeof(m_SampleProps),(PBYTE)&m_SampleProps);
pSample2->Release();
if(FAILED(hr))
{
return hr;
}
}
else
{
\使用ImediaSample接口获取输入Sample上的属性
m_SampleProps.cbData=sizeof(m_SampleProps);
m_SampleProps.dwTypeSpecificFlags=0;
m_SampleProps.dwStreamId=AM_STREAM_MEDIA;
m_SampleProps.dwSampleFlags=0;
if(S_OK==pSample->IsDiscontinuity())
{
m_SampleProps.dwSampleFlags|=AM_SAMPLE_DATADISCONTINUITY;
}
if(S_OK==pSample->IsPreroll())
{
m_SampleProps.dwSampleFlags|=AM_SAMPLE_PREROLL;
}
if(S_OK==pSample->IsSyncPoint())
{
m_SampleProps.dwSampleFlags|=AM_SAMPLE_SPLICEPOINT;
}
if(SUCCEEDED(pSample->GetTime(&m_SampleProps.tStart,&m_SampleProps.tStop)))
{
m_SampleProps.dwSampleFlags|=AM_SAMPLE_TIMEVALID|AM_SAMPLE_STOPVALID;
}
if(S_OK==pSample->GetMediaType(&m_SampleProps.pMediaType))
{
m_SampleProps.dwSampleFlags|=AM_SAMPLE_TYPECHANGED;
}
pSample->GetPointer(&m_SampleProps.pbBuffer);
m_SampleProps.lActual=pSample->GetActualDataLength();
m_SampleProps.cbBuffer=pSample->GetSize();
}
\检测Sample上的媒体类型是否改变
if(!(m_SampleProps.dwSampleFlags&AM_SAMPLE_TYPECHANGED))
{
return NOERROR;
}
\检查输入Pin上是否支持这种新的媒体类型。此时,输入Pin应该是支持这种媒体类型
\的,因为上一级Filter在做出这种媒体类型的动态改变之前,一般会先调用输入Pin
\上的IPin::QueryAccept接口方法进行确认
hr=CheckMediaType((CMediaType *)m_SampleProps.pMediaType);
if(hr==NOERROR)
{
return NOERROR;
}
m_bRunTimeError=TRUE;
EndOfStream();
m_pFilter->NotifyEvent(EC_ERRORABORT,VFN_E_TYPE_NOT_ACCEPTED,0);
return VFW_E_INVALIDMEDIATYPE;
}
{
CheckPointer(pSample,E_POINTER);
ValidateReadPtr(pSample,sizeof(IMediaSample));
ASSERT(pSample);
\检查Filter内部状态,以及数据流传送状态
HRESULT hr=CheckStreaming();
if(S_OK!=hr)
{
return hr;
}
\查询IMediaSample2接口,获取输入Sample上的属性
IMediaSample2 *pSample2;
if(SUCCEEDED(pSample->QueryInterface(IID_IMediaSample2,(void **)&pSample2)))
{
hr=pSample2->GetProperties(sizeof(m_SampleProps),(PBYTE)&m_SampleProps);
pSample2->Release();
if(FAILED(hr))
{
return hr;
}
}
else
{
\使用ImediaSample接口获取输入Sample上的属性
m_SampleProps.cbData=sizeof(m_SampleProps);
m_SampleProps.dwTypeSpecificFlags=0;
m_SampleProps.dwStreamId=AM_STREAM_MEDIA;
m_SampleProps.dwSampleFlags=0;
if(S_OK==pSample->IsDiscontinuity())
{
m_SampleProps.dwSampleFlags|=AM_SAMPLE_DATADISCONTINUITY;
}
if(S_OK==pSample->IsPreroll())
{
m_SampleProps.dwSampleFlags|=AM_SAMPLE_PREROLL;
}
if(S_OK==pSample->IsSyncPoint())
{
m_SampleProps.dwSampleFlags|=AM_SAMPLE_SPLICEPOINT;
}
if(SUCCEEDED(pSample->GetTime(&m_SampleProps.tStart,&m_SampleProps.tStop)))
{
m_SampleProps.dwSampleFlags|=AM_SAMPLE_TIMEVALID|AM_SAMPLE_STOPVALID;
}
if(S_OK==pSample->GetMediaType(&m_SampleProps.pMediaType))
{
m_SampleProps.dwSampleFlags|=AM_SAMPLE_TYPECHANGED;
}
pSample->GetPointer(&m_SampleProps.pbBuffer);
m_SampleProps.lActual=pSample->GetActualDataLength();
m_SampleProps.cbBuffer=pSample->GetSize();
}
\检测Sample上的媒体类型是否改变
if(!(m_SampleProps.dwSampleFlags&AM_SAMPLE_TYPECHANGED))
{
return NOERROR;
}
\检查输入Pin上是否支持这种新的媒体类型。此时,输入Pin应该是支持这种媒体类型
\的,因为上一级Filter在做出这种媒体类型的动态改变之前,一般会先调用输入Pin
\上的IPin::QueryAccept接口方法进行确认
hr=CheckMediaType((CMediaType *)m_SampleProps.pMediaType);
if(hr==NOERROR)
{
return NOERROR;
}
m_bRunTimeError=TRUE;
EndOfStream();
m_pFilter->NotifyEvent(EC_ERRORABORT,VFN_E_TYPE_NOT_ACCEPTED,0);
return VFW_E_INVALIDMEDIATYPE;
}
转载于:https://www.cnblogs.com/xiaomi-daming/p/11510844.html
最后
以上就是积极时光为你收集整理的DirectShow3的全部内容,希望文章能够帮你解决DirectShow3所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复