2
// libavg - Media Playback Engine.
3
// Copyright (C) 2003-2011 Ulrich von Zadow
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation; either
8
// version 2 of the License, or (at your option) any later version.
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public
16
// License along with this library; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
// Current versions can be found at www.libavg.de
22
#include "DSSampleGrabber.h"
26
#pragma warning(disable: 4800)
28
// {455A53B7-FC34-4960-94CE-A17A0B23F807}
29
DEFINE_GUID(CLSID_libavgGrabber,
30
0x455a53b7, 0xfc34, 0x4960, 0x94, 0xce, 0xa1, 0x7a, 0xb, 0x23, 0xf8, 0x7);
34
class CSampleGrabberAllocator : public CMemAllocator
37
CSampleGrabberAllocator(CSampleGrabberInPin* pParent, HRESULT* phr);
38
~CSampleGrabberAllocator();
42
STDMETHODIMP SetProperties(ALLOCATOR_PROPERTIES* pRequest,
43
ALLOCATOR_PROPERTIES* pActual);
46
CSampleGrabberInPin * m_pPin;
49
friend class CSampleGrabberInPin;
50
friend class CSampleGrabber;
53
class CSampleGrabberInPin : public CTransInPlaceInputPin
56
CSampleGrabberInPin(CTransInPlaceFilter* pFilter, HRESULT* pHr);
57
~CSampleGrabberInPin();
59
HRESULT GetMediaType(int iPosition, CMediaType* pMediaType);
61
// override this or GetMediaType is never called
62
STDMETHODIMP EnumMediaTypes(IEnumMediaTypes** ppEnum);
64
// we override this to tell whoever's upstream of us what kind of
65
// properties we're going to demand to have
66
STDMETHODIMP GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps);
69
friend class CSampleGrabberAllocator;
70
friend class CSampleGrabber;
72
CSampleGrabberAllocator* m_pPrivateAllocator;
73
ALLOCATOR_PROPERTIES m_allocprops;
75
BOOL m_bMediaTypeChanged;
78
CSampleGrabber::CSampleGrabber(IUnknown * pOuter, HRESULT * phr)
79
: CTransInPlaceFilter(TEXT("libavg sample grabber"), (IUnknown*) pOuter,
80
CLSID_libavgGrabber, phr, false),
83
m_pInput = (CTransInPlaceInputPin*) new CSampleGrabberInPin(this, phr);
85
IPin *pOutput = GetPin(1);
88
STDMETHODIMP CSampleGrabber::NonDelegatingQueryInterface(REFIID riid, void** ppv)
92
if (riid == IID_IlibavgGrabber) {
93
return GetInterface((IlibavgGrabber *)this, ppv);
95
return CTransInPlaceFilter::NonDelegatingQueryInterface(riid, ppv);
99
HRESULT CSampleGrabber::CheckInputType(const CMediaType* pmt)
102
CAutoLock lock(&m_Lock);
104
if (MEDIATYPE_Video == *pmt->Type( )) {
107
return VFW_E_INVALID_MEDIA_TYPE;
111
HRESULT CSampleGrabber::Receive(IMediaSample * pms)
116
AM_SAMPLE2_PROPERTIES * const pProps = m_pInput->SampleProps();
118
if (pProps->dwStreamId != AM_STREAM_MEDIA) {
119
if (m_pOutput->IsConnected()) {
120
return m_pOutput->Deliver(pms);
125
if (UsingDifferentAllocators()) {
131
AVG_ASSERT(!FAILED(hr));
132
hr = m_pOutput->Deliver(pms);
133
if (UsingDifferentAllocators()) {
139
HRESULT CSampleGrabber::Transform(IMediaSample* pms)
142
CAutoLock lock(&m_Lock);
145
REFERENCE_TIME StartTime;
146
REFERENCE_TIME StopTime;
147
pms->GetTime( &StartTime, &StopTime);
149
StartTime += m_pInput->CurrentStartTime();
150
StopTime += m_pInput->CurrentStartTime();
152
m_pCallback->onSample(pms);
157
void STDMETHODCALLTYPE CSampleGrabber::SetCallback(IDSSampleCallback* pCallback)
159
CAutoLock lock( &m_Lock );
160
m_pCallback = pCallback;
163
CSampleGrabberInPin::CSampleGrabberInPin(CTransInPlaceFilter* pFilter, HRESULT* pHr)
164
: CTransInPlaceInputPin(TEXT("SampleGrabberInputPin\0"), pFilter, pHr, L"Input\0"),
165
m_pPrivateAllocator(NULL),
167
m_bMediaTypeChanged(FALSE)
169
memset(&m_allocprops, 0, sizeof(m_allocprops));
172
CSampleGrabberInPin::~CSampleGrabberInPin()
174
if (m_pPrivateAllocator) {
175
delete m_pPrivateAllocator;
179
HRESULT CSampleGrabberInPin::GetMediaType(int iPosition, CMediaType* pMediaType)
181
AVG_ASSERT(pMediaType);
182
AVG_ASSERT(iPosition >= 0);
184
return VFW_S_NO_MORE_ITEMS;
187
*pMediaType = CMediaType();
188
pMediaType->SetType(&MEDIATYPE_Video);
193
STDMETHODIMP CSampleGrabberInPin::EnumMediaTypes(IEnumMediaTypes** ppEnum)
196
ValidateReadWritePtr(ppEnum, sizeof(IEnumMediaTypes *));
198
if(!((CSampleGrabber*)m_pTIPFilter)->OutputPin()->IsConnected())
200
*ppEnum = new CEnumMediaTypes(this, NULL);
204
return ((CSampleGrabber*)m_pTIPFilter)->OutputPin()->GetConnected()
205
->EnumMediaTypes(ppEnum);
208
HRESULT CSampleGrabberInPin::GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps)
212
if (m_pPrivateAllocator) {
213
*pProps = m_allocprops;
216
return CTransInPlaceInputPin::GetAllocatorRequirements(pProps);
b'\\ No newline at end of file'