filter.h 7.77 KB
Newer Older
Gildas Bazin's avatar
 
Gildas Bazin committed
1 2 3
/*****************************************************************************
 * filter.h : DirectShow access module for vlc
 *****************************************************************************
4
 * Copyright (C) 2002 the VideoLAN team
5
 * $Id$
Gildas Bazin's avatar
 
Gildas Bazin committed
6
 *
7
 * Author: Gildas Bazin <gbazin@videolan.org>
Gildas Bazin's avatar
 
Gildas Bazin committed
8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
Gildas Bazin's avatar
 
Gildas Bazin committed
22 23 24 25 26 27 28 29 30 31
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <string>
#include <list>
#include <deque>
using namespace std;

Gildas Bazin's avatar
 
Gildas Bazin committed
32 33 34 35 36
#ifndef _MSC_VER
#   include <wtypes.h>
#   include <unknwn.h>
#   include <ole2.h>
#   include <limits.h>
37 38 39
#   ifdef _WINGDI_
#      undef _WINGDI_
#   endif
Gildas Bazin's avatar
 
Gildas Bazin committed
40 41 42 43 44 45 46 47 48 49 50
#   define _WINGDI_ 1
#   define AM_NOVTABLE
#   define _OBJBASE_H_
#   undef _X86_
#   define _I64_MAX LONG_LONG_MAX
#   define LONGLONG long long
#endif

#include <dshow.h>

extern const GUID MEDIASUBTYPE_I420;
Gildas Bazin's avatar
 
Gildas Bazin committed
51
extern const GUID MEDIASUBTYPE_PREVIEW_VIDEO;
Gildas Bazin's avatar
 
Gildas Bazin committed
52

Gildas Bazin's avatar
 
Gildas Bazin committed
53 54 55 56 57 58 59 60 61 62 63 64 65
typedef struct VLCMediaSample
{
    IMediaSample *p_sample;
    mtime_t i_timestamp;

} VLCMediaSample;

class CaptureFilter;

void WINAPI FreeMediaType( AM_MEDIA_TYPE& mt );
HRESULT WINAPI CopyMediaType( AM_MEDIA_TYPE *pmtTarget,
                              const AM_MEDIA_TYPE *pmtSource );

66 67
int GetFourCCFromMediaType(const AM_MEDIA_TYPE &media_type);

Gildas Bazin's avatar
 
Gildas Bazin committed
68 69 70 71 72
/****************************************************************************
 * Declaration of our dummy directshow filter pin class
 ****************************************************************************/
class CapturePin: public IPin, public IMemInputPin
{
73 74
    friend class CaptureEnumMediaTypes;

Gildas Bazin's avatar
Gildas Bazin committed
75 76
    vlc_object_t *p_input;
    access_sys_t *p_sys;
Gildas Bazin's avatar
 
Gildas Bazin committed
77
    CaptureFilter  *p_filter;
Gildas Bazin's avatar
 
Gildas Bazin committed
78 79

    IPin *p_connected_pin;
80 81 82 83 84

    AM_MEDIA_TYPE *media_types;
    size_t media_type_count;

    AM_MEDIA_TYPE cx_media_type;
Gildas Bazin's avatar
 
Gildas Bazin committed
85 86 87

    deque<VLCMediaSample> samples_queue;

88
    long i_ref;
Gildas Bazin's avatar
 
Gildas Bazin committed
89 90

  public:
Gildas Bazin's avatar
Gildas Bazin committed
91 92
    CapturePin( vlc_object_t *_p_input, access_sys_t *p_sys,
                CaptureFilter *_p_filter,
93
                AM_MEDIA_TYPE *mt, size_t mt_count );
Gildas Bazin's avatar
 
Gildas Bazin committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
    virtual ~CapturePin();

    /* IUnknown methods */
    STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();

    /* IPin methods */
    STDMETHODIMP Connect( IPin * pReceivePin, const AM_MEDIA_TYPE *pmt );
    STDMETHODIMP ReceiveConnection( IPin * pConnector,
                                    const AM_MEDIA_TYPE *pmt );
    STDMETHODIMP Disconnect();
    STDMETHODIMP ConnectedTo( IPin **pPin );
    STDMETHODIMP ConnectionMediaType( AM_MEDIA_TYPE *pmt );
    STDMETHODIMP QueryPinInfo( PIN_INFO * pInfo );
    STDMETHODIMP QueryDirection( PIN_DIRECTION * pPinDir );
    STDMETHODIMP QueryId( LPWSTR * Id );
    STDMETHODIMP QueryAccept( const AM_MEDIA_TYPE *pmt );
    STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
    STDMETHODIMP QueryInternalConnections( IPin* *apPin, ULONG *nPin );
    STDMETHODIMP EndOfStream( void );

    STDMETHODIMP BeginFlush( void );
    STDMETHODIMP EndFlush( void );
    STDMETHODIMP NewSegment( REFERENCE_TIME tStart, REFERENCE_TIME tStop,
                             double dRate );

    /* IMemInputPin methods */
    STDMETHODIMP GetAllocator( IMemAllocator **ppAllocator );
    STDMETHODIMP NotifyAllocator(  IMemAllocator *pAllocator, BOOL bReadOnly );
    STDMETHODIMP GetAllocatorRequirements( ALLOCATOR_PROPERTIES *pProps );
    STDMETHODIMP Receive( IMediaSample *pSample );
    STDMETHODIMP ReceiveMultiple( IMediaSample **pSamples, long nSamples,
                                  long *nSamplesProcessed );
    STDMETHODIMP ReceiveCanBlock( void );

    /* Custom methods */
    HRESULT CustomGetSample( VLCMediaSample * );
132
    AM_MEDIA_TYPE &CustomGetMediaType();
Gildas Bazin's avatar
 
Gildas Bazin committed
133 134 135 136 137 138 139
};

/****************************************************************************
 * Declaration of our dummy directshow filter class
 ****************************************************************************/
class CaptureFilter : public IBaseFilter
{
140 141
    friend class CapturePin;

Gildas Bazin's avatar
Gildas Bazin committed
142
    vlc_object_t   *p_input;
Gildas Bazin's avatar
 
Gildas Bazin committed
143 144
    CapturePin     *p_pin;
    IFilterGraph   *p_graph;
145
    //AM_MEDIA_TYPE  media_type;
Gildas Bazin's avatar
 
Gildas Bazin committed
146
    FILTER_STATE   state;
Gildas Bazin's avatar
 
Gildas Bazin committed
147

148
    long i_ref;
Gildas Bazin's avatar
 
Gildas Bazin committed
149 150

  public:
Gildas Bazin's avatar
Gildas Bazin committed
151 152
    CaptureFilter( vlc_object_t *_p_input, access_sys_t *p_sys,
                   AM_MEDIA_TYPE *mt, size_t mt_count );
Gildas Bazin's avatar
 
Gildas Bazin committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
    virtual ~CaptureFilter();

    /* IUnknown methods */
    STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();

    /* IPersist method */
    STDMETHODIMP GetClassID(CLSID *pClsID);

    /* IMediaFilter methods */
    STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State);
    STDMETHODIMP SetSyncSource(IReferenceClock *pClock);
    STDMETHODIMP GetSyncSource(IReferenceClock **pClock);
    STDMETHODIMP Stop();
    STDMETHODIMP Pause();
    STDMETHODIMP Run(REFERENCE_TIME tStart);

    /* IBaseFilter methods */
    STDMETHODIMP EnumPins( IEnumPins ** ppEnum );
    STDMETHODIMP FindPin( LPCWSTR Id, IPin ** ppPin );
    STDMETHODIMP QueryFilterInfo( FILTER_INFO * pInfo );
    STDMETHODIMP JoinFilterGraph( IFilterGraph * pGraph, LPCWSTR pName );
    STDMETHODIMP QueryVendorInfo( LPWSTR* pVendorInfo );

    /* Custom methods */
    CapturePin *CustomGetPin();
};

/****************************************************************************
 * Declaration of our dummy directshow enumpins class
 ****************************************************************************/
class CaptureEnumPins : public IEnumPins
{
Gildas Bazin's avatar
Gildas Bazin committed
187
    vlc_object_t *p_input;
Gildas Bazin's avatar
 
Gildas Bazin committed
188
    CaptureFilter  *p_filter;
Gildas Bazin's avatar
 
Gildas Bazin committed
189

Gildas Bazin's avatar
 
Gildas Bazin committed
190
    int i_position;
191
    long i_ref;
Gildas Bazin's avatar
 
Gildas Bazin committed
192 193

public:
Gildas Bazin's avatar
Gildas Bazin committed
194
    CaptureEnumPins( vlc_object_t *_p_input, CaptureFilter *_p_filter,
Gildas Bazin's avatar
 
Gildas Bazin committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
                     CaptureEnumPins *pEnumPins );
    virtual ~CaptureEnumPins();

    // IUnknown
    STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();

    // IEnumPins
    STDMETHODIMP Next( ULONG cPins, IPin ** ppPins, ULONG * pcFetched );
    STDMETHODIMP Skip( ULONG cPins );
    STDMETHODIMP Reset();
    STDMETHODIMP Clone( IEnumPins **ppEnum );
};

/****************************************************************************
 * Declaration of our dummy directshow enummediatypes class
 ****************************************************************************/
class CaptureEnumMediaTypes : public IEnumMediaTypes
{
Gildas Bazin's avatar
Gildas Bazin committed
215
    vlc_object_t *p_input;
Gildas Bazin's avatar
 
Gildas Bazin committed
216
    CapturePin     *p_pin;
217
    AM_MEDIA_TYPE cx_media_type;
Gildas Bazin's avatar
 
Gildas Bazin committed
218

219
    size_t i_position;
220
    long i_ref;
Gildas Bazin's avatar
 
Gildas Bazin committed
221 222

public:
Gildas Bazin's avatar
Gildas Bazin committed
223
    CaptureEnumMediaTypes( vlc_object_t *_p_input, CapturePin *_p_pin,
Gildas Bazin's avatar
 
Gildas Bazin committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
                           CaptureEnumMediaTypes *pEnumMediaTypes );

    virtual ~CaptureEnumMediaTypes();

    // IUnknown
    STDMETHODIMP QueryInterface( REFIID riid, void **ppv );
    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();

    // IEnumMediaTypes
    STDMETHODIMP Next( ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes,
                       ULONG * pcFetched );
    STDMETHODIMP Skip( ULONG cMediaTypes );
    STDMETHODIMP Reset();
    STDMETHODIMP Clone( IEnumMediaTypes **ppEnum );
};