Use upstream filter's preferred media type order.
[xy_vsfilter.git] / src / filters / transform / basevideofilter / BaseVideoFilter.h
blob005541bb2b4e9c05325463cea814dba0add20ff7
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #pragma once
24 struct OutputFormatBase
26 const GUID* subtype;
27 WORD biPlanes, biBitCount;
28 DWORD biCompression;
31 typedef int ColorSpaceId;
32 enum ColorSpaceDir
34 INPUT_COLOR_SPACE = 0,
35 OUTPUT_COLOR_SPACE = 1
37 CString GetColorSpaceName(ColorSpaceId colorSpace, ColorSpaceDir inputOrOutput);
38 UINT GetOutputColorSpaceNumber();
39 UINT GetInputColorSpaceNumber();
40 ColorSpaceId Subtype2OutputColorSpaceId( const GUID& subtype, ColorSpaceId startPos =0 );
42 class CBaseVideoFilter : public CTransformFilter
44 private:
45 HRESULT Receive(IMediaSample* pIn);
46 HRESULT ReconnectOutput(int w, int h);
48 // these are private for a reason, don't bother them
49 DWORD m_win, m_hin, m_arxin, m_aryin;
50 DWORD m_wout, m_hout, m_arxout, m_aryout;
52 long m_cBuffers;
54 protected:
55 CCritSec m_csReceive;
56 bool m_donot_follow_upstream_preferred_order;
58 int m_w, m_h, m_arx, m_ary;
60 static const int MAX_COLOR_SPACE_NUM = 256;
61 const GUID* m_inputFmt[MAX_COLOR_SPACE_NUM];
62 int m_inputFmtCount;
64 const OutputFormatBase* m_outputFmt[MAX_COLOR_SPACE_NUM];
65 int m_outputFmtCount;
67 HRESULT GetDeliveryBuffer(int w, int h, IMediaSample** ppOut);
68 HRESULT CopyBuffer(BYTE* pOut, BYTE* pIn, int w, int h, int pitchIn, const GUID& subtype, bool fInterlaced = false);
69 HRESULT CopyBuffer(BYTE* pOut, BYTE** ppIn, int w, int h, int pitchIn, const GUID& subtype, bool fInterlaced = false);
71 virtual void GetOutputSize(int& w, int& h, int& arx, int& ary) {}
72 virtual HRESULT Transform(IMediaSample* pIn) = 0;
73 virtual HRESULT IsVideoInterlaced() {return false;}
75 void InitInputColorSpaces();
76 void InitOutputColorSpaces();
77 virtual void GetInputColorspaces(ColorSpaceId *preferredOrder, UINT *count);
78 virtual void GetOutputColorspaces(ColorSpaceId *preferredOrder, UINT *count);
79 HRESULT GetUpstreamOutputPriority(int *priorities, UINT count);
80 HRESULT CombineOutputPriority( ColorSpaceId *preferredOrder, UINT *count );
81 HRESULT DoCheckTransform(const CMediaType* mtIn, const CMediaType* mtOut, bool checkReconnection);
82 int GetInputSubtypePosition(const GUID& subtype);
83 int GetOutputSubtypePosition( const GUID& subtype, int startPos =0 );
84 public:
85 CBaseVideoFilter(TCHAR* pName, LPUNKNOWN lpunk, HRESULT* phr, REFCLSID clsid, long cBuffers = 1);
86 virtual ~CBaseVideoFilter();
88 int GetPinCount();
89 CBasePin* GetPin(int n);
91 HRESULT CheckInputType(const CMediaType* mtIn);
92 HRESULT CheckOutputType(const CMediaType& mtOut);
93 HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
94 HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
95 HRESULT GetMediaType(int iPosition, CMediaType* pMediaType);
96 HRESULT SetMediaType(PIN_DIRECTION dir, const CMediaType* pmt);
98 friend class CBaseVideoOutputPin;
101 class CBaseVideoInputAllocator : public CMemAllocator
103 CMediaType m_mt;
105 public:
106 CBaseVideoInputAllocator(HRESULT* phr);
107 void SetMediaType(const CMediaType& mt);
108 STDMETHODIMP GetBuffer(IMediaSample** ppBuffer, REFERENCE_TIME* pStartTime, REFERENCE_TIME* pEndTime, DWORD dwFlags);
111 class CBaseVideoInputPin : public CTransformInputPin
113 CBaseVideoInputAllocator* m_pAllocator;
115 public:
116 CBaseVideoInputPin(TCHAR* pObjectName, CBaseVideoFilter* pFilter, HRESULT* phr, LPCWSTR pName);
117 ~CBaseVideoInputPin();
119 STDMETHODIMP GetAllocator(IMemAllocator** ppAllocator);
120 STDMETHODIMP ReceiveConnection(IPin* pConnector, const AM_MEDIA_TYPE* pmt);
123 class CBaseVideoOutputPin : public CTransformOutputPin
125 public:
126 CBaseVideoOutputPin(TCHAR* pObjectName, CBaseVideoFilter* pFilter, HRESULT* phr, LPCWSTR pName);
128 HRESULT CheckMediaType(const CMediaType* mtOut);
129 //STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );