include: Add IFACEMETHOD macros.
[wine.git] / include / wine / strmbase.h
blob978d1c6716028baa3a172417a9ae9f8ac79c7ffc
1 /*
2 * Header file for Wine's strmbase implementation
4 * Copyright 2003 Robert Shearman
5 * Copyright 2010 Aric Stewart, CodeWeavers
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.
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.
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
22 #include "dshow.h"
23 #include "wine/debug.h"
25 HRESULT WINAPI CopyMediaType(AM_MEDIA_TYPE * pDest, const AM_MEDIA_TYPE *pSrc);
26 void WINAPI FreeMediaType(AM_MEDIA_TYPE * pMediaType);
27 AM_MEDIA_TYPE * WINAPI CreateMediaType(AM_MEDIA_TYPE const * pSrc);
28 void WINAPI DeleteMediaType(AM_MEDIA_TYPE * pMediaType);
30 void strmbase_dump_media_type(const AM_MEDIA_TYPE *mt);
32 static inline const char *debugstr_time(REFERENCE_TIME time)
34 ULONGLONG abstime = time >= 0 ? time : -time;
35 unsigned int i = 0, j = 0;
36 char buffer[23], rev[23];
38 while (abstime || i <= 8)
40 buffer[i++] = '0' + (abstime % 10);
41 abstime /= 10;
42 if (i == 7) buffer[i++] = '.';
44 if (time < 0) buffer[i++] = '-';
46 while (i--) rev[j++] = buffer[i];
47 while (rev[j-1] == '0' && rev[j-2] != '.') --j;
48 rev[j] = 0;
50 return wine_dbg_sprintf("%s", rev);
53 /* Pin functions */
55 struct strmbase_pin
57 IPin IPin_iface;
58 struct strmbase_filter *filter;
59 PIN_DIRECTION dir;
60 WCHAR name[128];
61 WCHAR id[128];
62 IPin *peer;
63 AM_MEDIA_TYPE mt;
65 const struct strmbase_pin_ops *ops;
68 struct strmbase_pin_ops
70 /* Required for QueryAccept(), Connect(), ReceiveConnection(). */
71 HRESULT (*pin_query_accept)(struct strmbase_pin *pin, const AM_MEDIA_TYPE *mt);
72 /* Required for EnumMediaTypes(). */
73 HRESULT (*pin_get_media_type)(struct strmbase_pin *pin, unsigned int index, AM_MEDIA_TYPE *mt);
74 HRESULT (*pin_query_interface)(struct strmbase_pin *pin, REFIID iid, void **out);
77 struct strmbase_source
79 struct strmbase_pin pin;
80 IMemInputPin *pMemInputPin;
81 IMemAllocator *pAllocator;
83 const struct strmbase_source_ops *pFuncsTable;
86 typedef HRESULT (WINAPI *BaseOutputPin_AttemptConnection)(struct strmbase_source *pin, IPin *peer, const AM_MEDIA_TYPE *mt);
87 typedef HRESULT (WINAPI *BaseOutputPin_DecideBufferSize)(struct strmbase_source *pin, IMemAllocator *allocator, ALLOCATOR_PROPERTIES *props);
88 typedef HRESULT (WINAPI *BaseOutputPin_DecideAllocator)(struct strmbase_source *pin, IMemInputPin *peer, IMemAllocator **allocator);
90 struct strmbase_source_ops
92 struct strmbase_pin_ops base;
94 /* Required for Connect(). */
95 BaseOutputPin_AttemptConnection pfnAttemptConnection;
96 /* Required for BaseOutputPinImpl_DecideAllocator */
97 BaseOutputPin_DecideBufferSize pfnDecideBufferSize;
98 /* Required for BaseOutputPinImpl_AttemptConnection */
99 BaseOutputPin_DecideAllocator pfnDecideAllocator;
101 void (*source_disconnect)(struct strmbase_source *pin);
104 struct strmbase_sink
106 struct strmbase_pin pin;
108 IMemInputPin IMemInputPin_iface;
109 IMemAllocator *pAllocator;
110 BOOL flushing;
111 IMemAllocator *preferred_allocator;
113 const struct strmbase_sink_ops *pFuncsTable;
116 typedef HRESULT (WINAPI *BaseInputPin_Receive)(struct strmbase_sink *This, IMediaSample *pSample);
118 struct strmbase_sink_ops
120 struct strmbase_pin_ops base;
121 BaseInputPin_Receive pfnReceive;
122 HRESULT (*sink_connect)(struct strmbase_sink *pin, IPin *peer, const AM_MEDIA_TYPE *mt);
123 void (*sink_disconnect)(struct strmbase_sink *pin);
124 HRESULT (*sink_eos)(struct strmbase_sink *pin);
125 HRESULT (*sink_begin_flush)(struct strmbase_sink *pin);
126 HRESULT (*sink_end_flush)(struct strmbase_sink *pin);
127 HRESULT (*sink_new_segment)(struct strmbase_sink *pin, REFERENCE_TIME start, REFERENCE_TIME stop, double rate);
130 /* Base Pin */
131 HRESULT WINAPI BaseOutputPinImpl_DecideAllocator(struct strmbase_source *pin, IMemInputPin *peer, IMemAllocator **allocator);
132 HRESULT WINAPI BaseOutputPinImpl_AttemptConnection(struct strmbase_source *pin, IPin *peer, const AM_MEDIA_TYPE *mt);
134 void strmbase_source_cleanup(struct strmbase_source *pin);
135 void strmbase_source_init(struct strmbase_source *pin, struct strmbase_filter *filter,
136 const WCHAR *name, const struct strmbase_source_ops *func_table);
138 void strmbase_sink_init(struct strmbase_sink *pin, struct strmbase_filter *filter,
139 const WCHAR *name, const struct strmbase_sink_ops *ops, IMemAllocator *allocator);
140 void strmbase_sink_cleanup(struct strmbase_sink *pin);
142 struct strmbase_filter
144 IBaseFilter IBaseFilter_iface;
145 IUnknown IUnknown_inner;
146 IUnknown *outer_unk;
147 LONG refcount;
148 CRITICAL_SECTION filter_cs;
149 CRITICAL_SECTION stream_cs;
151 FILTER_STATE state;
152 IReferenceClock *clock;
153 WCHAR name[128];
154 IFilterGraph *graph;
155 CLSID clsid;
156 LONG pin_version;
158 const struct strmbase_filter_ops *ops;
161 struct strmbase_filter_ops
163 struct strmbase_pin *(*filter_get_pin)(struct strmbase_filter *iface, unsigned int index);
164 void (*filter_destroy)(struct strmbase_filter *iface);
165 HRESULT (*filter_query_interface)(struct strmbase_filter *iface, REFIID iid, void **out);
167 HRESULT (*filter_init_stream)(struct strmbase_filter *iface);
168 HRESULT (*filter_start_stream)(struct strmbase_filter *iface, REFERENCE_TIME time);
169 HRESULT (*filter_stop_stream)(struct strmbase_filter *iface);
170 HRESULT (*filter_cleanup_stream)(struct strmbase_filter *iface);
171 HRESULT (*filter_wait_state)(struct strmbase_filter *iface, DWORD timeout);
174 VOID WINAPI BaseFilterImpl_IncrementPinVersion(struct strmbase_filter *filter);
176 void strmbase_filter_init(struct strmbase_filter *filter, IUnknown *outer,
177 const CLSID *clsid, const struct strmbase_filter_ops *func_table);
178 void strmbase_filter_cleanup(struct strmbase_filter *filter);
180 /* Source Seeking */
181 typedef HRESULT (WINAPI *SourceSeeking_ChangeRate)(IMediaSeeking *iface);
182 typedef HRESULT (WINAPI *SourceSeeking_ChangeStart)(IMediaSeeking *iface);
183 typedef HRESULT (WINAPI *SourceSeeking_ChangeStop)(IMediaSeeking *iface);
185 typedef struct SourceSeeking
187 IMediaSeeking IMediaSeeking_iface;
189 ULONG refCount;
190 SourceSeeking_ChangeStop fnChangeStop;
191 SourceSeeking_ChangeStart fnChangeStart;
192 SourceSeeking_ChangeRate fnChangeRate;
193 DWORD dwCapabilities;
194 double dRate;
195 LONGLONG llCurrent, llStop, llDuration;
196 GUID timeformat;
197 CRITICAL_SECTION cs;
198 } SourceSeeking;
200 HRESULT strmbase_seeking_init(SourceSeeking *seeking, const IMediaSeekingVtbl *vtbl,
201 SourceSeeking_ChangeStop fnChangeStop, SourceSeeking_ChangeStart fnChangeStart,
202 SourceSeeking_ChangeRate fnChangeRate);
203 void strmbase_seeking_cleanup(SourceSeeking *seeking);
205 HRESULT WINAPI SourceSeekingImpl_GetCapabilities(IMediaSeeking * iface, DWORD * pCapabilities);
206 HRESULT WINAPI SourceSeekingImpl_CheckCapabilities(IMediaSeeking * iface, DWORD * pCapabilities);
207 HRESULT WINAPI SourceSeekingImpl_IsFormatSupported(IMediaSeeking * iface, const GUID * pFormat);
208 HRESULT WINAPI SourceSeekingImpl_QueryPreferredFormat(IMediaSeeking * iface, GUID * pFormat);
209 HRESULT WINAPI SourceSeekingImpl_GetTimeFormat(IMediaSeeking * iface, GUID * pFormat);
210 HRESULT WINAPI SourceSeekingImpl_IsUsingTimeFormat(IMediaSeeking * iface, const GUID * pFormat);
211 HRESULT WINAPI SourceSeekingImpl_SetTimeFormat(IMediaSeeking * iface, const GUID * pFormat);
212 HRESULT WINAPI SourceSeekingImpl_GetDuration(IMediaSeeking * iface, LONGLONG * pDuration);
213 HRESULT WINAPI SourceSeekingImpl_GetStopPosition(IMediaSeeking * iface, LONGLONG * pStop);
214 HRESULT WINAPI SourceSeekingImpl_GetCurrentPosition(IMediaSeeking * iface, LONGLONG * pCurrent);
215 HRESULT WINAPI SourceSeekingImpl_ConvertTimeFormat(IMediaSeeking * iface, LONGLONG * pTarget, const GUID * pTargetFormat, LONGLONG Source, const GUID * pSourceFormat);
216 HRESULT WINAPI SourceSeekingImpl_SetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, DWORD dwCurrentFlags, LONGLONG * pStop, DWORD dwStopFlags);
217 HRESULT WINAPI SourceSeekingImpl_GetPositions(IMediaSeeking * iface, LONGLONG * pCurrent, LONGLONG * pStop);
218 HRESULT WINAPI SourceSeekingImpl_GetAvailable(IMediaSeeking * iface, LONGLONG * pEarliest, LONGLONG * pLatest);
219 HRESULT WINAPI SourceSeekingImpl_SetRate(IMediaSeeking * iface, double dRate);
220 HRESULT WINAPI SourceSeekingImpl_GetRate(IMediaSeeking * iface, double * dRate);
221 HRESULT WINAPI SourceSeekingImpl_GetPreroll(IMediaSeeking * iface, LONGLONG * pPreroll);
223 enum strmbase_type_id
225 IBasicAudio_tid,
226 IBasicVideo_tid,
227 IMediaControl_tid,
228 IMediaEvent_tid,
229 IMediaPosition_tid,
230 IVideoWindow_tid,
231 last_tid
234 HRESULT strmbase_get_typeinfo(enum strmbase_type_id tid, ITypeInfo **typeinfo);
235 void strmbase_release_typelibs(void);
237 struct strmbase_passthrough
239 ISeekingPassThru ISeekingPassThru_iface;
240 IMediaSeeking IMediaSeeking_iface;
241 IMediaPosition IMediaPosition_iface;
243 IUnknown *outer_unk;
244 IPin *pin;
245 BOOL renderer;
246 BOOL timevalid;
247 CRITICAL_SECTION time_cs;
248 REFERENCE_TIME time_earliest;
251 void strmbase_passthrough_init(struct strmbase_passthrough *passthrough, IUnknown *outer);
252 void strmbase_passthrough_cleanup(struct strmbase_passthrough *passthrough);
254 void strmbase_passthrough_eos(struct strmbase_passthrough *passthrough);
255 void strmbase_passthrough_invalidate_time(struct strmbase_passthrough *passthrough);
256 void strmbase_passthrough_update_time(struct strmbase_passthrough *passthrough, REFERENCE_TIME time);
258 struct strmbase_renderer
260 struct strmbase_filter filter;
261 struct strmbase_passthrough passthrough;
262 IQualityControl IQualityControl_iface;
264 struct strmbase_sink sink;
266 /* Signaled when the filter has completed a state change. The filter waits
267 * for this event in IBaseFilter::GetState(). */
268 HANDLE state_event;
269 /* Signaled when the sample presentation time occurs. The streaming thread
270 * waits for this event in Receive() if applicable. */
271 HANDLE advise_event;
272 /* Signaled when the filter is running. The streaming thread waits for this
273 * event in Receive() while paused. */
274 HANDLE run_event;
275 /* Signaled when a flush or state change occurs, i.e. anything that needs
276 * to immediately unblock the streaming thread. */
277 HANDLE flush_event;
278 REFERENCE_TIME stream_start;
280 IMediaSample *current_sample;
282 IQualityControl *qc_sink;
283 REFERENCE_TIME last_left, avg_duration, avg_pt;
284 double avg_rate;
286 const struct strmbase_renderer_ops *ops;
288 BOOL eos;
291 struct strmbase_renderer_ops
293 HRESULT (*renderer_query_accept)(struct strmbase_renderer *iface, const AM_MEDIA_TYPE *mt);
294 HRESULT (*renderer_render)(struct strmbase_renderer *iface, IMediaSample *sample);
295 void (*renderer_init_stream)(struct strmbase_renderer *iface);
296 void (*renderer_start_stream)(struct strmbase_renderer *iface);
297 void (*renderer_stop_stream)(struct strmbase_renderer *iface);
298 HRESULT (*renderer_connect)(struct strmbase_renderer *iface, const AM_MEDIA_TYPE *mt);
299 void (*renderer_disconnect)(struct strmbase_renderer *iface);
300 void (*renderer_destroy)(struct strmbase_renderer *iface);
301 HRESULT (*renderer_query_interface)(struct strmbase_renderer *iface, REFIID iid, void **out);
302 HRESULT (*renderer_pin_query_interface)(struct strmbase_renderer *iface, REFIID iid, void **out);
305 void strmbase_renderer_init(struct strmbase_renderer *filter, IUnknown *outer,
306 const CLSID *clsid, const WCHAR *sink_name, const struct strmbase_renderer_ops *ops);
307 void strmbase_renderer_cleanup(struct strmbase_renderer *filter);