[QUARTZ][STRMBASE]
[reactos.git] / reactos / dll / directx / wine / quartz / nullrenderer.c
1 /*
2 * Null Renderer (Promiscuous, not rendering anything at all!)
3 *
4 * Copyright 2004 Christian Costa
5 * Copyright 2008 Maarten Lankhorst
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "quartz_private.h"
23
24 typedef struct NullRendererImpl
25 {
26 BaseRenderer renderer;
27 IUnknown IUnknown_inner;
28 IAMFilterMiscFlags IAMFilterMiscFlags_iface;
29 IUnknown *outer_unk;
30 } NullRendererImpl;
31
32 static HRESULT WINAPI NullRenderer_DoRenderSample(BaseRenderer *iface, IMediaSample *pMediaSample)
33 {
34 return S_OK;
35 }
36
37 static HRESULT WINAPI NullRenderer_CheckMediaType(BaseRenderer *iface, const AM_MEDIA_TYPE * pmt)
38 {
39 TRACE("Not a stub!\n");
40 return S_OK;
41 }
42
43 static const BaseRendererFuncTable RendererFuncTable = {
44 NullRenderer_CheckMediaType,
45 NullRenderer_DoRenderSample,
46 /**/
47 NULL,
48 NULL,
49 NULL,
50 NULL,
51 NULL,
52 NULL,
53 NULL,
54 NULL,
55 NULL,
56 NULL,
57 /**/
58 NULL,
59 NULL,
60 NULL,
61 NULL,
62 NULL,
63 };
64
65 static inline NullRendererImpl *impl_from_IUnknown(IUnknown *iface)
66 {
67 return CONTAINING_RECORD(iface, NullRendererImpl, IUnknown_inner);
68 }
69
70 static HRESULT WINAPI NullRendererInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
71 {
72 NullRendererImpl *This = impl_from_IUnknown(iface);
73
74 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
75
76 *ppv = NULL;
77
78 if (IsEqualIID(riid, &IID_IUnknown))
79 *ppv = &This->IUnknown_inner;
80 else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
81 *ppv = &This->IAMFilterMiscFlags_iface;
82 else
83 {
84 HRESULT hr;
85 hr = BaseRendererImpl_QueryInterface(&This->renderer.filter.IBaseFilter_iface, riid, ppv);
86 if (SUCCEEDED(hr))
87 return hr;
88 }
89
90 if (*ppv)
91 {
92 IUnknown_AddRef((IUnknown *)*ppv);
93 return S_OK;
94 }
95
96 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
97 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
98
99 return E_NOINTERFACE;
100 }
101
102 static ULONG WINAPI NullRendererInner_AddRef(IUnknown *iface)
103 {
104 NullRendererImpl *This = impl_from_IUnknown(iface);
105 return BaseFilterImpl_AddRef(&This->renderer.filter.IBaseFilter_iface);
106 }
107
108 static ULONG WINAPI NullRendererInner_Release(IUnknown *iface)
109 {
110 NullRendererImpl *This = impl_from_IUnknown(iface);
111 ULONG refCount = BaseRendererImpl_Release(&This->renderer.filter.IBaseFilter_iface);
112
113 if (!refCount)
114 {
115 TRACE("Destroying Null Renderer\n");
116 CoTaskMemFree(This);
117 }
118
119 return refCount;
120 }
121
122 static const IUnknownVtbl IInner_VTable =
123 {
124 NullRendererInner_QueryInterface,
125 NullRendererInner_AddRef,
126 NullRendererInner_Release
127 };
128
129 static inline NullRendererImpl *impl_from_IBaseFilter(IBaseFilter *iface)
130 {
131 return CONTAINING_RECORD(iface, NullRendererImpl, renderer.filter.IBaseFilter_iface);
132 }
133
134 static HRESULT WINAPI NullRenderer_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
135 {
136 NullRendererImpl *This = impl_from_IBaseFilter(iface);
137 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
138 }
139
140 static ULONG WINAPI NullRenderer_AddRef(IBaseFilter * iface)
141 {
142 NullRendererImpl *This = impl_from_IBaseFilter(iface);
143 return IUnknown_AddRef(This->outer_unk);
144 }
145
146 static ULONG WINAPI NullRenderer_Release(IBaseFilter * iface)
147 {
148 NullRendererImpl *This = impl_from_IBaseFilter(iface);
149 return IUnknown_Release(This->outer_unk);
150 }
151
152 static const IBaseFilterVtbl NullRenderer_Vtbl =
153 {
154 NullRenderer_QueryInterface,
155 NullRenderer_AddRef,
156 NullRenderer_Release,
157 BaseFilterImpl_GetClassID,
158 BaseRendererImpl_Stop,
159 BaseRendererImpl_Pause,
160 BaseRendererImpl_Run,
161 BaseRendererImpl_GetState,
162 BaseRendererImpl_SetSyncSource,
163 BaseFilterImpl_GetSyncSource,
164 BaseFilterImpl_EnumPins,
165 BaseRendererImpl_FindPin,
166 BaseFilterImpl_QueryFilterInfo,
167 BaseFilterImpl_JoinFilterGraph,
168 BaseFilterImpl_QueryVendorInfo
169 };
170
171 static NullRendererImpl *impl_from_IAMFilterMiscFlags(IAMFilterMiscFlags *iface)
172 {
173 return CONTAINING_RECORD(iface, NullRendererImpl, IAMFilterMiscFlags_iface);
174 }
175
176 static HRESULT WINAPI AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags *iface, REFIID riid,
177 void **ppv)
178 {
179 NullRendererImpl *This = impl_from_IAMFilterMiscFlags(iface);
180 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
181 }
182
183 static ULONG WINAPI AMFilterMiscFlags_AddRef(IAMFilterMiscFlags *iface)
184 {
185 NullRendererImpl *This = impl_from_IAMFilterMiscFlags(iface);
186 return IUnknown_AddRef(This->outer_unk);
187 }
188
189 static ULONG WINAPI AMFilterMiscFlags_Release(IAMFilterMiscFlags *iface)
190 {
191 NullRendererImpl *This = impl_from_IAMFilterMiscFlags(iface);
192 return IUnknown_Release(This->outer_unk);
193 }
194
195 static ULONG WINAPI AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags *iface)
196 {
197 return AM_FILTER_MISC_FLAGS_IS_RENDERER;
198 }
199
200 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl = {
201 AMFilterMiscFlags_QueryInterface,
202 AMFilterMiscFlags_AddRef,
203 AMFilterMiscFlags_Release,
204 AMFilterMiscFlags_GetMiscFlags
205 };
206
207 HRESULT NullRenderer_create(IUnknown *pUnkOuter, void **ppv)
208 {
209 HRESULT hr;
210 NullRendererImpl *pNullRenderer;
211
212 TRACE("(%p, %p)\n", pUnkOuter, ppv);
213
214 *ppv = NULL;
215
216 pNullRenderer = CoTaskMemAlloc(sizeof(NullRendererImpl));
217 pNullRenderer->IUnknown_inner.lpVtbl = &IInner_VTable;
218 pNullRenderer->IAMFilterMiscFlags_iface.lpVtbl = &IAMFilterMiscFlags_Vtbl;
219
220 if (pUnkOuter)
221 pNullRenderer->outer_unk = pUnkOuter;
222 else
223 pNullRenderer->outer_unk = &pNullRenderer->IUnknown_inner;
224
225 hr = BaseRenderer_Init(&pNullRenderer->renderer, &NullRenderer_Vtbl, pUnkOuter,
226 &CLSID_NullRenderer, (DWORD_PTR)(__FILE__ ": NullRendererImpl.csFilter"),
227 &RendererFuncTable);
228
229 if (FAILED(hr))
230 {
231 BaseRendererImpl_Release(&pNullRenderer->renderer.filter.IBaseFilter_iface);
232 CoTaskMemFree(pNullRenderer);
233 }
234 else
235 *ppv = &pNullRenderer->IUnknown_inner;
236
237 return S_OK;
238 }