Skip to content

Commit

Permalink
Allow dynamic resolution changes in directshow
Browse files Browse the repository at this point in the history
  • Loading branch information
jp9000 committed Sep 15, 2014
1 parent 1d80b17 commit 11cc2ba
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 171 deletions.
42 changes: 33 additions & 9 deletions DShowPlugin/CaptureFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ STDMETHODIMP CapturePin::QueryDirection(PIN_DIRECTION *pPinDir) {*pPinDir = P
STDMETHODIMP CapturePin::QueryId(LPWSTR *lpId) {*lpId = L"Capture Pin"; return S_OK;}
STDMETHODIMP CapturePin::QueryAccept(const AM_MEDIA_TYPE *pmt)
{
if(filter->state != State_Stopped)
return S_FALSE;
if(pmt->majortype != expectedMajorType)
return S_FALSE;
if(!IsValidMediaType(pmt))
Expand All @@ -179,13 +177,17 @@ STDMETHODIMP CapturePin::EnumMediaTypes(IEnumMediaTypes **ppEnum)

STDMETHODIMP CapturePin::QueryInternalConnections(IPin **apPin, ULONG *nPin) {return E_NOTIMPL;}
STDMETHODIMP CapturePin::EndOfStream() {return S_OK;}
STDMETHODIMP CapturePin::BeginFlush() {return S_OK;}
STDMETHODIMP CapturePin::EndFlush()
STDMETHODIMP CapturePin::BeginFlush()
{
source->FlushSamples();
return S_OK;
}

STDMETHODIMP CapturePin::EndFlush()
{
return S_OK;
}

STDMETHODIMP CapturePin::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {return S_OK;}

// IMemInputPin methods
Expand Down Expand Up @@ -224,12 +226,10 @@ bool CapturePin::IsValidMediaType(const AM_MEDIA_TYPE *pmt) const

if(expectedMajorType == MEDIATYPE_Video)
{
VIDEOINFOHEADER *pVih = reinterpret_cast<VIDEOINFOHEADER*>(pmt->pbFormat);
if( pVih->bmiHeader.biHeight == 0 ||
pVih->bmiHeader.biWidth == 0)
{
BITMAPINFOHEADER *bih = GetVideoBMIHeader(pmt);

if( bih->biHeight == 0 || bih->biWidth == 0)
return false;
}
}
}

Expand All @@ -239,15 +239,39 @@ bool CapturePin::IsValidMediaType(const AM_MEDIA_TYPE *pmt) const

//========================================================================================================

class CaptureFlags : public IAMFilterMiscFlags {
long refCount = 1;
public:
inline CaptureFlags() {}
STDMETHODIMP_(ULONG) AddRef() {return ++refCount;}
STDMETHODIMP_(ULONG) Release() {if (!--refCount) {delete this; return 0;} return refCount;}
STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
{
if (riid == IID_IUnknown)
{
AddRef();
*ppv = (void*)this;
return NOERROR;
}

*ppv = nullptr;
return E_NOINTERFACE;
}

STDMETHODIMP_(ULONG) GetMiscFlags() {return AM_FILTER_MISC_FLAGS_IS_RENDERER;}
};

CaptureFilter::CaptureFilter(DeviceSource *source, const GUID &expectedMajorType, const GUID &expectedMediaType)
: state(State_Stopped), refCount(1)
{
pin = new CapturePin(this, source, expectedMajorType, expectedMediaType);
flags = new CaptureFlags();
}

CaptureFilter::~CaptureFilter()
{
pin->Release();
flags->Release();
}

// IUnknown methods
Expand Down
1 change: 1 addition & 0 deletions DShowPlugin/CaptureFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class CaptureFilter : public IBaseFilter
FILTER_STATE state;
IFilterGraph *graph;
CapturePin *pin;
IAMFilterMiscFlags *flags;

public:
CaptureFilter(DeviceSource *source, const GUID &expectedMajorType, const GUID &expectedMediaType);
Expand Down
Loading

0 comments on commit 11cc2ba

Please sign in to comment.