~ubuntu-branches/ubuntu/trusty/libavg/trusty-proposed

« back to all changes in this revision

Viewing changes to src/imaging/DSSampleGrabber.cpp

  • Committer: Package Import Robot
  • Author(s): OXullo Intersecans
  • Date: 2011-12-06 22:44:56 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20111206224456-qc7250z3ya1vi8s9
Tags: 1.7.0-0ubuntu1
* New upstream release (LP: #899183)
* Remove patches 0002-libav-0.7.patch, 0003-fglrx-segfault-on-startup.patch
  now merged to upstream
* Remove unnecessary .la files
* Update debian/watch file
* Fix debian/copyright dep-5 compliancy
* Update standards to version 3.9.2
* Add man pages for avg_checktouch, avg_checkvsync, avg_showsvg
* Minor debian/rules enhancement
* Add librsvg2-dev, libgdk-pixbuf2.0-dev to Build-Depends
* Proper transition to dh_python2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
//  libavg - Media Playback Engine. 
 
3
//  Copyright (C) 2003-2011 Ulrich von Zadow
 
4
//
 
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.
 
9
//
 
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.
 
14
//
 
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
 
18
//
 
19
//  Current versions can be found at www.libavg.de
 
20
//
 
21
 
 
22
#include "DSSampleGrabber.h"
 
23
 
 
24
#include <initguid.h>
 
25
 
 
26
#pragma warning(disable: 4800)
 
27
 
 
28
// {455A53B7-FC34-4960-94CE-A17A0B23F807}
 
29
DEFINE_GUID(CLSID_libavgGrabber, 
 
30
0x455a53b7, 0xfc34, 0x4960, 0x94, 0xce, 0xa1, 0x7a, 0xb, 0x23, 0xf8, 0x7);
 
31
 
 
32
namespace avg {
 
33
 
 
34
class CSampleGrabberAllocator : public CMemAllocator
 
35
{
 
36
public:
 
37
    CSampleGrabberAllocator(CSampleGrabberInPin* pParent, HRESULT* phr);
 
38
    ~CSampleGrabberAllocator();
 
39
 
 
40
    HRESULT Alloc();
 
41
    void ReallyFree();
 
42
    STDMETHODIMP SetProperties(ALLOCATOR_PROPERTIES* pRequest, 
 
43
            ALLOCATOR_PROPERTIES* pActual);
 
44
 
 
45
protected:
 
46
    CSampleGrabberInPin * m_pPin;
 
47
 
 
48
private:
 
49
    friend class CSampleGrabberInPin;
 
50
    friend class CSampleGrabber;
 
51
};
 
52
 
 
53
class CSampleGrabberInPin : public CTransInPlaceInputPin
 
54
{
 
55
public:
 
56
    CSampleGrabberInPin(CTransInPlaceFilter* pFilter, HRESULT* pHr);
 
57
    ~CSampleGrabberInPin();
 
58
 
 
59
    HRESULT GetMediaType(int iPosition, CMediaType* pMediaType);
 
60
 
 
61
    // override this or GetMediaType is never called
 
62
    STDMETHODIMP EnumMediaTypes(IEnumMediaTypes** ppEnum);
 
63
 
 
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);
 
67
 
 
68
private:
 
69
    friend class CSampleGrabberAllocator;
 
70
    friend class CSampleGrabber;
 
71
 
 
72
    CSampleGrabberAllocator* m_pPrivateAllocator;
 
73
    ALLOCATOR_PROPERTIES m_allocprops;
 
74
    BYTE* m_pBuffer;
 
75
    BOOL m_bMediaTypeChanged;
 
76
};
 
77
 
 
78
CSampleGrabber::CSampleGrabber(IUnknown * pOuter, HRESULT * phr)
 
79
    : CTransInPlaceFilter(TEXT("libavg sample grabber"), (IUnknown*) pOuter, 
 
80
              CLSID_libavgGrabber, phr, false),
 
81
      m_pCallback(NULL)
 
82
{
 
83
    m_pInput = (CTransInPlaceInputPin*) new CSampleGrabberInPin(this, phr);
 
84
    
 
85
    IPin *pOutput = GetPin(1);
 
86
}
 
87
 
 
88
STDMETHODIMP CSampleGrabber::NonDelegatingQueryInterface(REFIID riid, void** ppv)
 
89
{
 
90
    AVG_ASSERT(ppv);
 
91
 
 
92
    if (riid == IID_IlibavgGrabber) {                
 
93
        return GetInterface((IlibavgGrabber *)this, ppv);
 
94
    } else {
 
95
        return CTransInPlaceFilter::NonDelegatingQueryInterface(riid, ppv);
 
96
    }
 
97
}
 
98
 
 
99
HRESULT CSampleGrabber::CheckInputType(const CMediaType* pmt)
 
100
{
 
101
    AVG_ASSERT(pmt);
 
102
    CAutoLock lock(&m_Lock);
 
103
 
 
104
    if (MEDIATYPE_Video == *pmt->Type( )) {
 
105
        return NOERROR;
 
106
    } else {
 
107
        return VFW_E_INVALID_MEDIA_TYPE;
 
108
    }
 
109
}
 
110
 
 
111
HRESULT CSampleGrabber::Receive(IMediaSample * pms)
 
112
{
 
113
    AVG_ASSERT(pms);
 
114
 
 
115
    HRESULT hr;
 
116
    AM_SAMPLE2_PROPERTIES * const pProps = m_pInput->SampleProps();
 
117
 
 
118
    if (pProps->dwStreamId != AM_STREAM_MEDIA) {
 
119
        if (m_pOutput->IsConnected()) {
 
120
            return m_pOutput->Deliver(pms);
 
121
        } else {
 
122
            return NOERROR;
 
123
        }
 
124
    }
 
125
    if (UsingDifferentAllocators()) {
 
126
        pms = Copy(pms);
 
127
        AVG_ASSERT(pms);
 
128
    }
 
129
 
 
130
    hr = Transform(pms);
 
131
    AVG_ASSERT(!FAILED(hr));
 
132
    hr = m_pOutput->Deliver(pms);
 
133
    if (UsingDifferentAllocators()) {
 
134
        pms->Release();
 
135
    }
 
136
    return hr;
 
137
}
 
138
 
 
139
HRESULT CSampleGrabber::Transform(IMediaSample* pms)
 
140
{
 
141
    AVG_ASSERT(pms);
 
142
    CAutoLock lock(&m_Lock);
 
143
 
 
144
    if (m_pCallback) {
 
145
        REFERENCE_TIME StartTime;
 
146
        REFERENCE_TIME StopTime;
 
147
        pms->GetTime( &StartTime, &StopTime);
 
148
 
 
149
        StartTime += m_pInput->CurrentStartTime();
 
150
        StopTime  += m_pInput->CurrentStartTime();
 
151
 
 
152
        m_pCallback->onSample(pms);
 
153
    }
 
154
    return NOERROR;
 
155
}
 
156
 
 
157
void STDMETHODCALLTYPE CSampleGrabber::SetCallback(IDSSampleCallback* pCallback)
 
158
{
 
159
    CAutoLock lock( &m_Lock );
 
160
    m_pCallback = pCallback;
 
161
}
 
162
 
 
163
CSampleGrabberInPin::CSampleGrabberInPin(CTransInPlaceFilter* pFilter, HRESULT* pHr) 
 
164
    : CTransInPlaceInputPin(TEXT("SampleGrabberInputPin\0"), pFilter, pHr, L"Input\0"),
 
165
      m_pPrivateAllocator(NULL),
 
166
      m_pBuffer(NULL),
 
167
      m_bMediaTypeChanged(FALSE)
 
168
{
 
169
    memset(&m_allocprops, 0, sizeof(m_allocprops));
 
170
}
 
171
 
 
172
CSampleGrabberInPin::~CSampleGrabberInPin()
 
173
{
 
174
    if (m_pPrivateAllocator) {
 
175
        delete m_pPrivateAllocator;
 
176
    }
 
177
}
 
178
 
 
179
HRESULT CSampleGrabberInPin::GetMediaType(int iPosition, CMediaType* pMediaType)
 
180
{
 
181
    AVG_ASSERT(pMediaType);
 
182
    AVG_ASSERT(iPosition >= 0);
 
183
    if (iPosition > 0) {
 
184
        return VFW_S_NO_MORE_ITEMS;
 
185
    }
 
186
 
 
187
    *pMediaType = CMediaType();
 
188
    pMediaType->SetType(&MEDIATYPE_Video);
 
189
 
 
190
    return S_OK;
 
191
}
 
192
 
 
193
STDMETHODIMP CSampleGrabberInPin::EnumMediaTypes(IEnumMediaTypes** ppEnum) 
 
194
{
 
195
    AVG_ASSERT(ppEnum);
 
196
    ValidateReadWritePtr(ppEnum, sizeof(IEnumMediaTypes *));
 
197
 
 
198
    if(!((CSampleGrabber*)m_pTIPFilter)->OutputPin()->IsConnected())
 
199
    {
 
200
        *ppEnum = new CEnumMediaTypes(this, NULL);
 
201
        return NOERROR;
 
202
    }
 
203
 
 
204
    return ((CSampleGrabber*)m_pTIPFilter)->OutputPin()->GetConnected()
 
205
            ->EnumMediaTypes(ppEnum);
 
206
}
 
207
 
 
208
HRESULT CSampleGrabberInPin::GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps)
 
209
{
 
210
    AVG_ASSERT(pProps);
 
211
 
 
212
    if (m_pPrivateAllocator) {
 
213
        *pProps = m_allocprops;
 
214
        return S_OK;
 
215
    } else {
 
216
        return CTransInPlaceInputPin::GetAllocatorRequirements(pProps);
 
217
    }
 
218
}
 
219
 
 
220
}
 
 
b'\\ No newline at end of file'