C++ Outputpin中的调用约定冲突
尝试将筛选器输出引脚连接到另一个筛选器时,我遇到以下错误 这是触发错误的行(在outputpin代码中) 这里是函数声明:C++ Outputpin中的调用约定冲突,c++,directshow,C++,Directshow,尝试将筛选器输出引脚连接到另一个筛选器时,我遇到以下错误 这是触发错误的行(在outputpin代码中) 这里是函数声明: class MCMyOutputPin : public CBaseOutputPin { .... HRESULT CheckMediaType(const CMediaType *pmt); HRESULT SetMediaType(const CMediaType *pmt); HRESULT CompleteConnect(IPin
class MCMyOutputPin : public CBaseOutputPin
{
....
HRESULT CheckMediaType(const CMediaType *pmt);
HRESULT SetMediaType(const CMediaType *pmt);
HRESULT CompleteConnect(IPin *pReceivePin);
//virtual HRESULT __stdcall Connect(IPin* pPin, const AM_MEDIA_TYPE *pmt);
HRESULT BreakConnect();
HRESULT GetMediaType(int i, CMediaType *pmt);
HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pProps);
HRESULT DecideAllocator(IMemInputPin *pPin, IMemAllocator **ppAlloc);
HRESULT Deliver(IMediaSample* sample);
BOOL IsConnected();
...
我相信DecideAllocator是由GetAllocatorRequirements调用的
根据msdn,函数必须用u stdcall声明。
因此,调用和被调用函数之间似乎存在调用冲突。
但是,如果我尝试将函数设置为u stdcall:
HRESULT __stdcall DecideAllocator(IMemInputPin *pPin, IMemAllocator **ppAlloc);
我得到编译错误:
“MCMyOutputPin::DecideAllocator”:重写虚拟函数不同
仅通过调用约定从“CBaseOutputPin::DecideAllocator”
因此,我尝试确保基类是使用stdcall调用约定构建的:
我打开了baseclasses项目(C:\ProgramFiles(x86)\Microsoft SDK\Windows\v7.0\Samples\multimedia\directshow\baseclasses)并设置
ConfigurationProperties->C/C++->Advanced->调用约定
到stdcall(/Gz)
总而言之:
- 我相信我有冲突
- 我无法更改代码中的调用约定
- 在基类项目中设置调用约定并重新编译仍然不能解决问题
STDMETHODIMP MyFilter::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
if(riid == IID_IMyInterfilter) {
mylogger->LogDebug("In Nondelegationqueryinterface", L"D:\\TEMP\\yc.log");
return GetInterface((IMyFilter*)this, ppv);
}
else
{
return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
}
}
此处显示过滤器标题:
class MyFilter : public CBaseFilter, public IMyFilter
{
public:
CCritSec lockfilter;
DECLARE_IUNKNOWN;
const LONGLONG MEDIATIME = 5;
MyFilter(LPUNKNOWN pUnk, HRESULT* phr);
virtual ~MyFilter(void);
virtual int GetPinCount();
virtual CBasePin* GetPin(int n);
STDMETHODIMP Run(REFERENCE_TIME tStart);
STDMETHODIMP Pause();
STDMETHODIMP Stop();
void acceptFilterInput(LPCWSTR pinname, IMediaSample* sample);
CMyInputPin* getPreviousPIN(LPCWSTR pinname);
CMyInputPin* getNextPIN(LPCWSTR pinname);
//BOOL requestRecordMode(LPCWSTR pinname); //returns false if previous pin thread is not sleeping
static CUnknown* WINAPI CreateInstance(LPUNKNOWN pUnk, HRESULT *phr);
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);
//STDMETHODIMP StartRecording();
STDMETHODIMP GetThePinCount(int* result);
//STDMETHODIMP StopRecording();
STDMETHOD_(IPin*,GetMyPin)(int index);
//STDMETHODIMP Next(ULONG cPins, IPin** pppins, ULONG fetched);
//STDMETHODIMP Clone(IEnumPins **ppenum);
//STDMETHODIMP Reset();
//STDMETHODIMP Skip(ULONG cpins);
//
CCritSec m_lock_filter;
TimeGiver* m_pTimeGiver;
MCMyOutputPin *outpin;
static const int COUNT_INPUTPINS = 3;
static unsigned __stdcall workerthreadfunc(void *);
HANDLE workerThreadHandle;
private:
MyLogger *mylogger;
CCritSec m_critSec;
bool running;
LPCWSTR currentInputPin;
void startSyncThread();
CMyInputPin* GetPinByName(LPCWSTR name);
LONGLONG* mediaTimeBuffer;
CMyInputPin* inputpins[COUNT_INPUTPINS];
};
以下是过滤器的实现:
#include "MyInputPin.h"
#include "CMyOutPutPin.h"
#include "MyLogger.h"
#include <windows.h>
#include <process.h>
#include <string>
using namespace std;
MyFilter::MyFilter(LPUNKNOWN pUnk, HRESULT* phr) : CBaseFilter(NAME("MyFilter"), pUnk, &lockfilter, CLSID_MyInterFilter)
{
HRESULT *hr_0 = NOERROR;
HRESULT *hr_1 = NOERROR;
HRESULT* hr_2 = NOERROR;
HRESULT* hr_3 = NOERROR;
inputpins[0] = new CMyInputPin(TEXT("PIN0"), L"PIN0", pUnk, this, &this->m_lock_filter, hr_0, 0);
inputpins[1] = new CMyInputPin(TEXT("PIN1"), L"PIN1", pUnk, this, &this->m_lock_filter, hr_1, 1);
inputpins[2] = new CMyInputPin(TEXT("PIN2"), L"PIN2", pUnk, this, &this->m_lock_filter, hr_2, 2);
outpin = new MCMyOutputPin(this, hr_3, TEXT("PINOUT0"));
this->running = false;
mylogger = new MyLogger();
mylogger->LogDebug("Construtor of Filter", L"D:\\TEMP\\yc.log");
m_pTimeGiver = new TimeGiver(2, MEDIATIME);
}
CMyInputPin* MyFilter::getPreviousPIN(LPCWSTR pinname)
{
CMyInputPin *inpin = GetPinByName(pinname);
int position = inpin->m_position;
int adjused = position + COUNT_INPUTPINS - 1;
int newInex = adjused % COUNT_INPUTPINS;
return inputpins[newInex];
}
CMyInputPin* MyFilter::getNextPIN(LPCWSTR pinname)
{
CMyInputPin *inpin = GetPinByName(pinname);
int position = inpin->m_position;
int incremented = position++;
int newIndex = incremented % COUNT_INPUTPINS;
return inputpins[newIndex];
}
//BOOL MyFilter::requestRecordMode(LPCWSTR pinname) { //returns false if previous pin thread is not sleeping
// for (int i = 0; i < COUNT_INPUTPINS; i++)
// {
// if (wcscmp(pinname, inputpins[i]->Name()) == 0)
// {
// inputpins[i]->m_bIsSleeping = false;
// }
// else {
// inputpins[i]->m_bIsSleeping = true;
// }
//
// }
// return TRUE;
//}
HRESULT MyFilter::Run(REFERENCE_TIME tStart)
{
mylogger->LogDebug("In MyFilter::Run:", L"D:\\TEMP\\yc.log");
CAutoLock cobjectlock(&m_critSec);
workerThreadHandle = (HANDLE) _beginthreadex(NULL, 0, workerthreadfunc, (void *)this, 0, NULL);
//boost::thread workerThread(&MyFilter::startSyncThread, this);
m_tStart = tStart;
if (m_State == State_Stopped){
HRESULT hr = Pause();
if (FAILED(hr)) {
return hr;
}
}
return S_OK;
}
HRESULT MyFilter::Stop()
{
mylogger->LogDebug("In MyFilter::Stop:", L"D:\\TEMP\\yc.log");
CAutoLock cobjectlock(&m_critSec);
m_State = State_Stopped;
this->m_pTimeGiver->stop();
//this->m_thread.join();
return S_OK;
}
HRESULT MyFilter::Pause()
{
CAutoLock cobjectlock(&m_critSec);
m_State = State_Paused;
mylogger->LogDebug("In MyFilter::PAuse:", L"D:\\TEMP\\yc.log");
return S_OK;
}
MyFilter::~MyFilter(void)
{
//delete mylogger;
//delete outpin;
//delete[] inputpins;
}
int MyFilter::GetPinCount()
{
return COUNT_INPUTPINS + 1; //One outputpin
}
IPin* MyFilter::GetMyPin(int n)
{
CBasePin* pin = this->GetPin(n);
return pin;
}
CBasePin* MyFilter::GetPin(int n)
{
if (n >= 0 && n < COUNT_INPUTPINS)
{
return inputpins[n];
}
if (n == 3)
{
return outpin;
}
return NULL;
}
//HRESULT MyFilter::GetThePinCount(int *result)
//{
// *result = 4;
//}
HRESULT MyFilter::GetThePinCount(int* giveme)
{
*giveme = COUNT_INPUTPINS + 1;
return S_OK;
}
STDMETHODIMP MyFilter::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
if(riid == IID_IMyInterfilter) {
mylogger->LogDebug("In Nondelegationqueryinterface", L"D:\\TEMP\\yc.log");
return GetInterface((IMyFilter*)this, ppv);
}
else
{
return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
}
}
/*RESULT MyFilter::StartRecording()
{
this->running = true;
return S_OK;
}*/
//
//HRESULT MyFilter::StopRecording()
//{
// this->running = false;
// return S_OK;
//
//}
CUnknown* WINAPI MyFilter::CreateInstance(LPUNKNOWN pUnk, HRESULT *phr)
{
CUnknown* pNewFilter = new MyFilter(pUnk, phr);
if (phr)
{
if (pNewFilter == NULL)
*phr = E_OUTOFMEMORY;
else
*phr = S_OK;
}
return pNewFilter;
}
void MyFilter::acceptFilterInput(LPCWSTR pinname, IMediaSample* sample)
{
mylogger->LogDebug("In acceptFIlterInput", L"D:\\TEMP\\yc.log");
outpin->Deliver(sample);
}
//STDMETHODIMP MyFilter::Next(ULONG cPins, IPin** pppins, ULONG fetched)
//{
//
//}
//STDMETHODIMP MyFilter::(IEnumPins **ppenum)
//{
//
//}
//STDMETHODIMP MyFilter::Reset()
//{
//
//}
//STDMETHODIMP MyFilter::Skip(ULONG cpins)
//{
//
//}
CMyInputPin* MyFilter::GetPinByName(LPCWSTR name)
{
for (int i = 0; i < COUNT_INPUTPINS; i++)
{
if (wcscmp(name, inputpins[0]->Name()))
{
return inputpins[0];
}
}
return NULL;
}
void MyFilter::startSyncThread()
{
this->m_pTimeGiver->start();
}
unsigned int MyFilter::workerthreadfunc(void * param)
{
MyFilter* myfilter;
myfilter = (MyFilter *)param;
myfilter->m_pTimeGiver->start();
return S_OK;
}
#包括“MyInputPin.h”
#包括“CMyOutPutPin.h”
#包括“MyLogger.h”
#包括
#包括
#包括
使用名称空间std;
MyFilter::MyFilter(LPUNKNOWN朋克,HRESULT*phr):CBaseFilter(名称(“MyFilter”)、朋克和锁过滤器、CLSID_MyInterFilter)
{
HRESULT*hr_0=无错误;
HRESULT*hr_1=无错误;
HRESULT*hr_2=无错误;
HRESULT*hr_3=无错误;
inputpins[0]=新的CMyInputPin(文本(“PIN0”)、L“PIN0”、朋克、this和this->m_锁定过滤器、hr_0、0);
inputpins[1]=新的CMyInputPin(文本(“PIN1”)、L“PIN1”、朋克、this和this->m_锁定过滤器、hr_1、1);
inputpins[2]=新的CMyInputPin(文本(“PIN2”)、L“PIN2”、朋克、this和this->m_锁定过滤器、hr_2、2);
outpin=新的MCMyOutputPin(这个,hr_3,文本(“PINOUT0”);
此->运行=错误;
mylogger=新的mylogger();
mylogger->LogDebug(“过滤器构造器”,L“D:\\TEMP\\yc.log”);
m_pTimeGiver=新的计时器(2,MEDIATIME);
}
CMyInputPin*MyFilter::getPreviousPIN(LPCWSTR pinname)
{
CMyInputPin*inpin=GetPinByName(pinname);
int位置=inpin->m_位置;
int adjused=位置+计数\输入引脚-1;
int newInex=调整的%COUNT\u INPUTPINS;
返回输入引脚[newInex];
}
CMyInputPin*MyFilter::getNextPIN(LPCWSTR-pinname)
{
CMyInputPin*inpin=GetPinByName(pinname);
int位置=inpin->m_位置;
int递增=位置++;
int newIndex=递增的%COUNT\u INPUTPINS;
返回inputpins[newIndex];
}
//BOOL MyFilter::requestRecordMode(LPCWSTR pinname){//如果前一个pin线程未休眠,则返回false
//对于(int i=0;iName())==0)
// {
//inputpins[i]>m_=false;
// }
//否则{
//inputpins[i]>m_=true;
// }
//
// }
//返回TRUE;
//}
HRESULT MyFilter::Run(参考时间启动)
{
mylogger->LogDebug(“在MyFilter::Run:,L“D:\\TEMP\\yc.log中”);
CAutoLock-cobjectlock(&m_-critSec);
workerThreadHandle=(HANDLE)u beginthreadex(NULL,0,workerthreadfunc,(void*)this,0,NULL);
//boost::threadworkerthread(&MyFilter::startSyncThread,this);
m_tStart=tStart;
如果(m_State==State_Stopped){
HRESULT hr=暂停();
如果(失败(小时)){
返回人力资源;
}
}
返回S_OK;
}
HRESULT MyFilter::Stop()
{
mylogger->LogDebug(“在MyFilter::Stop:,L“D:\\TEMP\\yc.log中”);
CAutoLock-cobjectlock(&m_-critSec);
m_状态=停止状态;
此->m_pTimeGiver->停止();
//此->m_thread.join();
返回S_OK;
}
HRESULT MyFilter::Pause()
{
CAutoLock-cobjectlock(&m_-critSec);
m_State=状态_暂停;
mylogger->LogDebug(“在MyFilter::PAuse:,L“D:\\TEMP\\yc.log中”);
返回S_OK;
}
MyFilter::~MyFilter(无效)
{
//删除mylogger;
//删除outpin;
//删除[]输入引脚;
}
int MyFilter::GetPinCount()
{
返回计数\u INPUTPINS+1;//一个outputpin
}
IPin*MyFilter::GetMyPin(int n)
{
CBasePin*pin=this->GetPin(n);
回位销;
}
CBasePin*MyFilter::GetPin(int n)
{
如果(n>=0&&nLogDebug(“在非删除查询接口中”,L“D:\\TEMP\\yc.log”);
返回GetInterface((IMyFilter*)this,ppv);
}
其他的
{
返回CBaseFilter::NonDelegatingQueryInterface(riid,ppv);
}
}
/*结果MyFilter::StartRecording()
{
此->运行=真;
返回S_OK;
}*/
//
//HRESULT MyFilter::StopRecording()
//{
//此->运行=错误;
//返回S_OK;
//
//}
CUnknown*WINAPI MyFilter::CreateInstance(LPUNKNOWN朋克,HRESULT*phr)
{
CUnknown*pNewFilter=新的MyFilter(朋克,phr);
if(phr)
{
if(pNewFilter==NULL)
*phr=E_OUTOFMEMORY;
其他的
*phr=S_正常;
}
返回pNewFilter;
}
void MyFilter::acceptFilterInput(LPCWSTR pinname,IMediaSample*sample)
{
mylogger->LogDebug(“在acceptFIlterInput中,L“D:\\TEMP\\yc.log”);
输出->交付(样品);
}
//STDMETHODIMP MyFilter::Next(ULONG cPins,IPin**pppins,ULONG已获取)
//{
//
//}
#include "MyInputPin.h"
#include "CMyOutPutPin.h"
#include "MyLogger.h"
#include <windows.h>
#include <process.h>
#include <string>
using namespace std;
MyFilter::MyFilter(LPUNKNOWN pUnk, HRESULT* phr) : CBaseFilter(NAME("MyFilter"), pUnk, &lockfilter, CLSID_MyInterFilter)
{
HRESULT *hr_0 = NOERROR;
HRESULT *hr_1 = NOERROR;
HRESULT* hr_2 = NOERROR;
HRESULT* hr_3 = NOERROR;
inputpins[0] = new CMyInputPin(TEXT("PIN0"), L"PIN0", pUnk, this, &this->m_lock_filter, hr_0, 0);
inputpins[1] = new CMyInputPin(TEXT("PIN1"), L"PIN1", pUnk, this, &this->m_lock_filter, hr_1, 1);
inputpins[2] = new CMyInputPin(TEXT("PIN2"), L"PIN2", pUnk, this, &this->m_lock_filter, hr_2, 2);
outpin = new MCMyOutputPin(this, hr_3, TEXT("PINOUT0"));
this->running = false;
mylogger = new MyLogger();
mylogger->LogDebug("Construtor of Filter", L"D:\\TEMP\\yc.log");
m_pTimeGiver = new TimeGiver(2, MEDIATIME);
}
CMyInputPin* MyFilter::getPreviousPIN(LPCWSTR pinname)
{
CMyInputPin *inpin = GetPinByName(pinname);
int position = inpin->m_position;
int adjused = position + COUNT_INPUTPINS - 1;
int newInex = adjused % COUNT_INPUTPINS;
return inputpins[newInex];
}
CMyInputPin* MyFilter::getNextPIN(LPCWSTR pinname)
{
CMyInputPin *inpin = GetPinByName(pinname);
int position = inpin->m_position;
int incremented = position++;
int newIndex = incremented % COUNT_INPUTPINS;
return inputpins[newIndex];
}
//BOOL MyFilter::requestRecordMode(LPCWSTR pinname) { //returns false if previous pin thread is not sleeping
// for (int i = 0; i < COUNT_INPUTPINS; i++)
// {
// if (wcscmp(pinname, inputpins[i]->Name()) == 0)
// {
// inputpins[i]->m_bIsSleeping = false;
// }
// else {
// inputpins[i]->m_bIsSleeping = true;
// }
//
// }
// return TRUE;
//}
HRESULT MyFilter::Run(REFERENCE_TIME tStart)
{
mylogger->LogDebug("In MyFilter::Run:", L"D:\\TEMP\\yc.log");
CAutoLock cobjectlock(&m_critSec);
workerThreadHandle = (HANDLE) _beginthreadex(NULL, 0, workerthreadfunc, (void *)this, 0, NULL);
//boost::thread workerThread(&MyFilter::startSyncThread, this);
m_tStart = tStart;
if (m_State == State_Stopped){
HRESULT hr = Pause();
if (FAILED(hr)) {
return hr;
}
}
return S_OK;
}
HRESULT MyFilter::Stop()
{
mylogger->LogDebug("In MyFilter::Stop:", L"D:\\TEMP\\yc.log");
CAutoLock cobjectlock(&m_critSec);
m_State = State_Stopped;
this->m_pTimeGiver->stop();
//this->m_thread.join();
return S_OK;
}
HRESULT MyFilter::Pause()
{
CAutoLock cobjectlock(&m_critSec);
m_State = State_Paused;
mylogger->LogDebug("In MyFilter::PAuse:", L"D:\\TEMP\\yc.log");
return S_OK;
}
MyFilter::~MyFilter(void)
{
//delete mylogger;
//delete outpin;
//delete[] inputpins;
}
int MyFilter::GetPinCount()
{
return COUNT_INPUTPINS + 1; //One outputpin
}
IPin* MyFilter::GetMyPin(int n)
{
CBasePin* pin = this->GetPin(n);
return pin;
}
CBasePin* MyFilter::GetPin(int n)
{
if (n >= 0 && n < COUNT_INPUTPINS)
{
return inputpins[n];
}
if (n == 3)
{
return outpin;
}
return NULL;
}
//HRESULT MyFilter::GetThePinCount(int *result)
//{
// *result = 4;
//}
HRESULT MyFilter::GetThePinCount(int* giveme)
{
*giveme = COUNT_INPUTPINS + 1;
return S_OK;
}
STDMETHODIMP MyFilter::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
if(riid == IID_IMyInterfilter) {
mylogger->LogDebug("In Nondelegationqueryinterface", L"D:\\TEMP\\yc.log");
return GetInterface((IMyFilter*)this, ppv);
}
else
{
return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
}
}
/*RESULT MyFilter::StartRecording()
{
this->running = true;
return S_OK;
}*/
//
//HRESULT MyFilter::StopRecording()
//{
// this->running = false;
// return S_OK;
//
//}
CUnknown* WINAPI MyFilter::CreateInstance(LPUNKNOWN pUnk, HRESULT *phr)
{
CUnknown* pNewFilter = new MyFilter(pUnk, phr);
if (phr)
{
if (pNewFilter == NULL)
*phr = E_OUTOFMEMORY;
else
*phr = S_OK;
}
return pNewFilter;
}
void MyFilter::acceptFilterInput(LPCWSTR pinname, IMediaSample* sample)
{
mylogger->LogDebug("In acceptFIlterInput", L"D:\\TEMP\\yc.log");
outpin->Deliver(sample);
}
//STDMETHODIMP MyFilter::Next(ULONG cPins, IPin** pppins, ULONG fetched)
//{
//
//}
//STDMETHODIMP MyFilter::(IEnumPins **ppenum)
//{
//
//}
//STDMETHODIMP MyFilter::Reset()
//{
//
//}
//STDMETHODIMP MyFilter::Skip(ULONG cpins)
//{
//
//}
CMyInputPin* MyFilter::GetPinByName(LPCWSTR name)
{
for (int i = 0; i < COUNT_INPUTPINS; i++)
{
if (wcscmp(name, inputpins[0]->Name()))
{
return inputpins[0];
}
}
return NULL;
}
void MyFilter::startSyncThread()
{
this->m_pTimeGiver->start();
}
unsigned int MyFilter::workerthreadfunc(void * param)
{
MyFilter* myfilter;
myfilter = (MyFilter *)param;
myfilter->m_pTimeGiver->start();
return S_OK;
}
CMyInputPin* MyFilter::GetPinByName(LPCWSTR name)
{
for (int i = 0; i < COUNT_INPUTPINS; i++)
{
// 1. you want [i], not [0]
// 2. you want if(wcscmp(...) == 0)
if (wcscmp(name, inputpins[0]->Name()))
{
// 3. you want [i], not [0]
return inputpins[0];
}
}