pin.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. /*
  2. * Generic Implementation of IPin Interface
  3. *
  4. * Copyright 2003 Robert Shearman
  5. * Copyright 2010 Aric Stewart, CodeWeavers
  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. #include "strmbase_private.h"
  22. WINE_DEFAULT_DEBUG_CHANNEL(quartz);
  23. static const IMemInputPinVtbl MemInputPin_Vtbl;
  24. typedef HRESULT (*SendPinFunc)( IPin *to, LPVOID arg );
  25. struct enum_media_types
  26. {
  27. IEnumMediaTypes IEnumMediaTypes_iface;
  28. LONG refcount;
  29. unsigned int index, count;
  30. struct strmbase_pin *pin;
  31. };
  32. static const IEnumMediaTypesVtbl enum_media_types_vtbl;
  33. static HRESULT enum_media_types_create(struct strmbase_pin *pin, IEnumMediaTypes **out)
  34. {
  35. struct enum_media_types *object;
  36. AM_MEDIA_TYPE mt;
  37. if (!out)
  38. return E_POINTER;
  39. if (!(object = heap_alloc_zero(sizeof(*object))))
  40. {
  41. *out = NULL;
  42. return E_OUTOFMEMORY;
  43. }
  44. object->IEnumMediaTypes_iface.lpVtbl = &enum_media_types_vtbl;
  45. object->refcount = 1;
  46. object->pin = pin;
  47. IPin_AddRef(&pin->IPin_iface);
  48. if (pin->ops->pin_get_media_type)
  49. {
  50. while (pin->ops->pin_get_media_type(pin, object->count, &mt) == S_OK)
  51. {
  52. FreeMediaType(&mt);
  53. ++object->count;
  54. }
  55. }
  56. TRACE("Created enumerator %p.\n", object);
  57. *out = &object->IEnumMediaTypes_iface;
  58. return S_OK;
  59. }
  60. static struct enum_media_types *impl_from_IEnumMediaTypes(IEnumMediaTypes *iface)
  61. {
  62. return CONTAINING_RECORD(iface, struct enum_media_types, IEnumMediaTypes_iface);
  63. }
  64. static HRESULT WINAPI enum_media_types_QueryInterface(IEnumMediaTypes *iface, REFIID iid, void **out)
  65. {
  66. TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
  67. if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumMediaTypes))
  68. {
  69. IEnumMediaTypes_AddRef(iface);
  70. *out = iface;
  71. return S_OK;
  72. }
  73. WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
  74. *out = NULL;
  75. return E_NOINTERFACE;
  76. }
  77. static ULONG WINAPI enum_media_types_AddRef(IEnumMediaTypes *iface)
  78. {
  79. struct enum_media_types *enummt = impl_from_IEnumMediaTypes(iface);
  80. ULONG refcount = InterlockedIncrement(&enummt->refcount);
  81. TRACE("%p increasing refcount to %u.\n", enummt, refcount);
  82. return refcount;
  83. }
  84. static ULONG WINAPI enum_media_types_Release(IEnumMediaTypes *iface)
  85. {
  86. struct enum_media_types *enummt = impl_from_IEnumMediaTypes(iface);
  87. ULONG refcount = InterlockedDecrement(&enummt->refcount);
  88. TRACE("%p decreasing refcount to %u.\n", enummt, refcount);
  89. if (!refcount)
  90. {
  91. IPin_Release(&enummt->pin->IPin_iface);
  92. heap_free(enummt);
  93. }
  94. return refcount;
  95. }
  96. static HRESULT WINAPI enum_media_types_Next(IEnumMediaTypes *iface, ULONG count,
  97. AM_MEDIA_TYPE **mts, ULONG *ret_count)
  98. {
  99. struct enum_media_types *enummt = impl_from_IEnumMediaTypes(iface);
  100. AM_MEDIA_TYPE mt;
  101. unsigned int i;
  102. HRESULT hr;
  103. TRACE("enummt %p, count %u, mts %p, ret_count %p.\n", enummt, count, mts, ret_count);
  104. if (!enummt->pin->ops->pin_get_media_type)
  105. {
  106. if (ret_count)
  107. *ret_count = 0;
  108. return count ? S_FALSE : S_OK;
  109. }
  110. for (i = 0; i < count; ++i)
  111. {
  112. hr = enummt->pin->ops->pin_get_media_type(enummt->pin, enummt->index + i, &mt);
  113. if (hr == S_OK)
  114. {
  115. if ((mts[i] = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE))))
  116. *mts[i] = mt;
  117. else
  118. hr = E_OUTOFMEMORY;
  119. }
  120. if (FAILED(hr))
  121. {
  122. while (i--)
  123. DeleteMediaType(mts[i]);
  124. *ret_count = 0;
  125. return E_OUTOFMEMORY;
  126. }
  127. else if (hr != S_OK)
  128. break;
  129. if (TRACE_ON(quartz))
  130. {
  131. TRACE("Returning media type %u:\n", enummt->index + i);
  132. strmbase_dump_media_type(mts[i]);
  133. }
  134. }
  135. if (count != 1 || ret_count)
  136. *ret_count = i;
  137. enummt->index += i;
  138. return i == count ? S_OK : S_FALSE;
  139. }
  140. static HRESULT WINAPI enum_media_types_Skip(IEnumMediaTypes *iface, ULONG count)
  141. {
  142. struct enum_media_types *enummt = impl_from_IEnumMediaTypes(iface);
  143. TRACE("enummt %p, count %u.\n", enummt, count);
  144. enummt->index += count;
  145. return enummt->index > enummt->count ? S_FALSE : S_OK;
  146. }
  147. static HRESULT WINAPI enum_media_types_Reset(IEnumMediaTypes *iface)
  148. {
  149. struct enum_media_types *enummt = impl_from_IEnumMediaTypes(iface);
  150. AM_MEDIA_TYPE mt;
  151. TRACE("enummt %p.\n", enummt);
  152. enummt->count = 0;
  153. if (enummt->pin->ops->pin_get_media_type)
  154. {
  155. while (enummt->pin->ops->pin_get_media_type(enummt->pin, enummt->count, &mt) == S_OK)
  156. {
  157. FreeMediaType(&mt);
  158. ++enummt->count;
  159. }
  160. }
  161. enummt->index = 0;
  162. return S_OK;
  163. }
  164. static HRESULT WINAPI enum_media_types_Clone(IEnumMediaTypes *iface, IEnumMediaTypes **out)
  165. {
  166. struct enum_media_types *enummt = impl_from_IEnumMediaTypes(iface);
  167. HRESULT hr;
  168. TRACE("enummt %p, out %p.\n", enummt, out);
  169. if (FAILED(hr = enum_media_types_create(enummt->pin, out)))
  170. return hr;
  171. return IEnumMediaTypes_Skip(*out, enummt->index);
  172. }
  173. static const IEnumMediaTypesVtbl enum_media_types_vtbl =
  174. {
  175. enum_media_types_QueryInterface,
  176. enum_media_types_AddRef,
  177. enum_media_types_Release,
  178. enum_media_types_Next,
  179. enum_media_types_Skip,
  180. enum_media_types_Reset,
  181. enum_media_types_Clone,
  182. };
  183. static inline struct strmbase_pin *impl_from_IPin(IPin *iface)
  184. {
  185. return CONTAINING_RECORD(iface, struct strmbase_pin, IPin_iface);
  186. }
  187. /** Helper function, there are a lot of places where the error code is inherited
  188. * The following rules apply:
  189. *
  190. * Return the first received error code (E_NOTIMPL is ignored)
  191. * If no errors occur: return the first received non-error-code that isn't S_OK
  192. */
  193. static HRESULT updatehres( HRESULT original, HRESULT new )
  194. {
  195. if (FAILED( original ) || new == E_NOTIMPL)
  196. return original;
  197. if (FAILED( new ) || original == S_OK)
  198. return new;
  199. return original;
  200. }
  201. /** Sends a message from a pin further to other, similar pins
  202. * fnMiddle is called on each pin found further on the stream.
  203. * fnEnd (can be NULL) is called when the message can't be sent any further (this is a renderer or source)
  204. *
  205. * If the pin given is an input pin, the message will be sent downstream to other input pins
  206. * If the pin given is an output pin, the message will be sent upstream to other output pins
  207. */
  208. static HRESULT SendFurther(struct strmbase_sink *sink, SendPinFunc func, void *arg)
  209. {
  210. struct strmbase_pin *pin;
  211. HRESULT hr = S_OK;
  212. unsigned int i;
  213. for (i = 0; (pin = sink->pin.filter->ops->filter_get_pin(sink->pin.filter, i)); ++i)
  214. {
  215. if (pin->dir == PINDIR_OUTPUT && pin->peer)
  216. hr = updatehres(hr, func(pin->peer, arg));
  217. }
  218. return hr;
  219. }
  220. static HRESULT WINAPI pin_QueryInterface(IPin *iface, REFIID iid, void **out)
  221. {
  222. struct strmbase_pin *pin = impl_from_IPin(iface);
  223. HRESULT hr;
  224. TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
  225. *out = NULL;
  226. if (pin->ops->pin_query_interface && SUCCEEDED(hr = pin->ops->pin_query_interface(pin, iid, out)))
  227. return hr;
  228. if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IPin))
  229. *out = iface;
  230. else
  231. {
  232. WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
  233. return E_NOINTERFACE;
  234. }
  235. IUnknown_AddRef((IUnknown *)*out);
  236. return S_OK;
  237. }
  238. static ULONG WINAPI pin_AddRef(IPin *iface)
  239. {
  240. struct strmbase_pin *pin = impl_from_IPin(iface);
  241. return IBaseFilter_AddRef(&pin->filter->IBaseFilter_iface);
  242. }
  243. static ULONG WINAPI pin_Release(IPin *iface)
  244. {
  245. struct strmbase_pin *pin = impl_from_IPin(iface);
  246. return IBaseFilter_Release(&pin->filter->IBaseFilter_iface);
  247. }
  248. static HRESULT WINAPI pin_ConnectedTo(IPin * iface, IPin ** ppPin)
  249. {
  250. struct strmbase_pin *This = impl_from_IPin(iface);
  251. HRESULT hr;
  252. TRACE("pin %p %s:%s, peer %p.\n", This, debugstr_w(This->filter->name), debugstr_w(This->name), ppPin);
  253. EnterCriticalSection(&This->filter->filter_cs);
  254. {
  255. if (This->peer)
  256. {
  257. *ppPin = This->peer;
  258. IPin_AddRef(*ppPin);
  259. hr = S_OK;
  260. }
  261. else
  262. {
  263. hr = VFW_E_NOT_CONNECTED;
  264. *ppPin = NULL;
  265. }
  266. }
  267. LeaveCriticalSection(&This->filter->filter_cs);
  268. return hr;
  269. }
  270. static HRESULT WINAPI pin_ConnectionMediaType(IPin *iface, AM_MEDIA_TYPE *pmt)
  271. {
  272. struct strmbase_pin *This = impl_from_IPin(iface);
  273. HRESULT hr;
  274. TRACE("pin %p %s:%s, pmt %p.\n", This, debugstr_w(This->filter->name), debugstr_w(This->name), pmt);
  275. EnterCriticalSection(&This->filter->filter_cs);
  276. {
  277. if (This->peer)
  278. {
  279. CopyMediaType(pmt, &This->mt);
  280. strmbase_dump_media_type(pmt);
  281. hr = S_OK;
  282. }
  283. else
  284. {
  285. ZeroMemory(pmt, sizeof(*pmt));
  286. hr = VFW_E_NOT_CONNECTED;
  287. }
  288. }
  289. LeaveCriticalSection(&This->filter->filter_cs);
  290. return hr;
  291. }
  292. static HRESULT WINAPI pin_QueryPinInfo(IPin *iface, PIN_INFO *info)
  293. {
  294. struct strmbase_pin *pin = impl_from_IPin(iface);
  295. TRACE("pin %p %s:%s, info %p.\n", pin, debugstr_w(pin->filter->name), debugstr_w(pin->name), info);
  296. info->dir = pin->dir;
  297. IBaseFilter_AddRef(info->pFilter = &pin->filter->IBaseFilter_iface);
  298. lstrcpyW(info->achName, pin->name);
  299. return S_OK;
  300. }
  301. static HRESULT WINAPI pin_QueryDirection(IPin *iface, PIN_DIRECTION *dir)
  302. {
  303. struct strmbase_pin *pin = impl_from_IPin(iface);
  304. TRACE("pin %p %s:%s, dir %p.\n", pin, debugstr_w(pin->filter->name), debugstr_w(pin->name), dir);
  305. *dir = pin->dir;
  306. return S_OK;
  307. }
  308. static HRESULT WINAPI pin_QueryId(IPin *iface, WCHAR **id)
  309. {
  310. struct strmbase_pin *pin = impl_from_IPin(iface);
  311. TRACE("pin %p %s:%s, id %p.\n", pin, debugstr_w(pin->filter->name), debugstr_w(pin->name), id);
  312. if (!(*id = CoTaskMemAlloc((lstrlenW(pin->name) + 1) * sizeof(WCHAR))))
  313. return E_OUTOFMEMORY;
  314. lstrcpyW(*id, pin->name);
  315. return S_OK;
  316. }
  317. static BOOL query_accept(struct strmbase_pin *pin, const AM_MEDIA_TYPE *mt)
  318. {
  319. if (pin->ops->pin_query_accept && pin->ops->pin_query_accept(pin, mt) != S_OK)
  320. return FALSE;
  321. return TRUE;
  322. }
  323. static HRESULT WINAPI pin_QueryAccept(IPin *iface, const AM_MEDIA_TYPE *mt)
  324. {
  325. struct strmbase_pin *pin = impl_from_IPin(iface);
  326. TRACE("pin %p %s:%s, mt %p.\n", pin, debugstr_w(pin->filter->name), debugstr_w(pin->name), mt);
  327. strmbase_dump_media_type(mt);
  328. return query_accept(pin, mt) ? S_OK : S_FALSE;
  329. }
  330. static HRESULT WINAPI pin_EnumMediaTypes(IPin *iface, IEnumMediaTypes **enum_media_types)
  331. {
  332. struct strmbase_pin *pin = impl_from_IPin(iface);
  333. AM_MEDIA_TYPE mt;
  334. HRESULT hr;
  335. TRACE("pin %p %s:%s, enum_media_types %p.\n", pin, debugstr_w(pin->filter->name),
  336. debugstr_w(pin->name), enum_media_types);
  337. if (pin->ops->pin_get_media_type)
  338. {
  339. if (FAILED(hr = pin->ops->pin_get_media_type(pin, 0, &mt)))
  340. return hr;
  341. if (hr == S_OK)
  342. FreeMediaType(&mt);
  343. }
  344. return enum_media_types_create(pin, enum_media_types);
  345. }
  346. static HRESULT WINAPI pin_QueryInternalConnections(IPin *iface, IPin **pins, ULONG *count)
  347. {
  348. struct strmbase_pin *pin = impl_from_IPin(iface);
  349. TRACE("pin %p %s:%s, pins %p, count %p.\n", pin, debugstr_w(pin->filter->name),
  350. debugstr_w(pin->name), pins, count);
  351. return E_NOTIMPL; /* to tell caller that all input pins connected to all output pins */
  352. }
  353. /*** OutputPin implementation ***/
  354. static inline struct strmbase_source *impl_source_from_IPin( IPin *iface )
  355. {
  356. return CONTAINING_RECORD(iface, struct strmbase_source, pin.IPin_iface);
  357. }
  358. static BOOL compare_media_types(const AM_MEDIA_TYPE *req_mt, const AM_MEDIA_TYPE *pin_mt)
  359. {
  360. if (!req_mt)
  361. return TRUE;
  362. if (!IsEqualGUID(&req_mt->majortype, &pin_mt->majortype)
  363. && !IsEqualGUID(&req_mt->majortype, &GUID_NULL))
  364. return FALSE;
  365. if (!IsEqualGUID(&req_mt->subtype, &pin_mt->subtype)
  366. && !IsEqualGUID(&req_mt->subtype, &GUID_NULL))
  367. return FALSE;
  368. if (!IsEqualGUID(&req_mt->formattype, &pin_mt->formattype)
  369. && !IsEqualGUID(&req_mt->formattype, &GUID_NULL))
  370. return FALSE;
  371. return TRUE;
  372. }
  373. static HRESULT WINAPI source_Connect(IPin *iface, IPin *peer, const AM_MEDIA_TYPE *mt)
  374. {
  375. struct strmbase_source *pin = impl_source_from_IPin(iface);
  376. AM_MEDIA_TYPE candidate, *candidate_ptr;
  377. IEnumMediaTypes *enummt;
  378. PIN_DIRECTION dir;
  379. unsigned int i;
  380. ULONG count;
  381. HRESULT hr;
  382. TRACE("pin %p %s:%s, peer %p, mt %p.\n", pin, debugstr_w(pin->pin.filter->name),
  383. debugstr_w(pin->pin.name), peer, mt);
  384. strmbase_dump_media_type(mt);
  385. if (!peer)
  386. return E_POINTER;
  387. IPin_QueryDirection(peer, &dir);
  388. if (dir != PINDIR_INPUT)
  389. {
  390. WARN("Attempt to connect to another source pin, returning VFW_E_INVALID_DIRECTION.\n");
  391. return VFW_E_INVALID_DIRECTION;
  392. }
  393. EnterCriticalSection(&pin->pin.filter->filter_cs);
  394. if (pin->pin.peer)
  395. {
  396. LeaveCriticalSection(&pin->pin.filter->filter_cs);
  397. WARN("Pin is already connected, returning VFW_E_ALREADY_CONNECTED.\n");
  398. return VFW_E_ALREADY_CONNECTED;
  399. }
  400. if (pin->pin.filter->state != State_Stopped)
  401. {
  402. LeaveCriticalSection(&pin->pin.filter->filter_cs);
  403. WARN("Filter is not stopped; returning VFW_E_NOT_STOPPED.\n");
  404. return VFW_E_NOT_STOPPED;
  405. }
  406. /* We don't check the subtype here. The rationale (as given by the DirectX
  407. * documentation) is that the format type is supposed to provide at least
  408. * as much information as the subtype. */
  409. if (mt && !IsEqualGUID(&mt->majortype, &GUID_NULL)
  410. && !IsEqualGUID(&mt->formattype, &GUID_NULL))
  411. {
  412. hr = pin->pFuncsTable->pfnAttemptConnection(pin, peer, mt);
  413. LeaveCriticalSection(&pin->pin.filter->filter_cs);
  414. return hr;
  415. }
  416. if (SUCCEEDED(IPin_EnumMediaTypes(peer, &enummt)))
  417. {
  418. while (IEnumMediaTypes_Next(enummt, 1, &candidate_ptr, &count) == S_OK)
  419. {
  420. if (compare_media_types(mt, candidate_ptr)
  421. && pin->pFuncsTable->pfnAttemptConnection(pin, peer, candidate_ptr) == S_OK)
  422. {
  423. LeaveCriticalSection(&pin->pin.filter->filter_cs);
  424. DeleteMediaType(candidate_ptr);
  425. IEnumMediaTypes_Release(enummt);
  426. return S_OK;
  427. }
  428. DeleteMediaType(candidate_ptr);
  429. }
  430. IEnumMediaTypes_Release(enummt);
  431. }
  432. if (pin->pFuncsTable->base.pin_get_media_type)
  433. {
  434. for (i = 0; pin->pFuncsTable->base.pin_get_media_type(&pin->pin, i, &candidate) == S_OK; ++i)
  435. {
  436. strmbase_dump_media_type(&candidate);
  437. if (compare_media_types(mt, &candidate)
  438. && pin->pFuncsTable->pfnAttemptConnection(pin, peer, &candidate) == S_OK)
  439. {
  440. LeaveCriticalSection(&pin->pin.filter->filter_cs);
  441. FreeMediaType(&candidate);
  442. return S_OK;
  443. }
  444. FreeMediaType(&candidate);
  445. }
  446. }
  447. LeaveCriticalSection(&pin->pin.filter->filter_cs);
  448. return VFW_E_NO_ACCEPTABLE_TYPES;
  449. }
  450. static HRESULT WINAPI source_ReceiveConnection(IPin *iface, IPin *peer, const AM_MEDIA_TYPE *mt)
  451. {
  452. struct strmbase_source *pin = impl_source_from_IPin(iface);
  453. WARN("pin %p %s:%s, peer %p, mt %p, unexpected call.\n", pin,
  454. debugstr_w(pin->pin.filter->name), debugstr_w(pin->pin.name), peer, mt);
  455. return E_UNEXPECTED;
  456. }
  457. static HRESULT WINAPI source_Disconnect(IPin *iface)
  458. {
  459. HRESULT hr;
  460. struct strmbase_source *This = impl_source_from_IPin(iface);
  461. TRACE("pin %p %s:%s.\n", This, debugstr_w(This->pin.filter->name), debugstr_w(This->pin.name));
  462. EnterCriticalSection(&This->pin.filter->filter_cs);
  463. {
  464. if (This->pin.filter->state != State_Stopped)
  465. {
  466. LeaveCriticalSection(&This->pin.filter->filter_cs);
  467. WARN("Filter is not stopped; returning VFW_E_NOT_STOPPED.\n");
  468. return VFW_E_NOT_STOPPED;
  469. }
  470. if (This->pFuncsTable->source_disconnect)
  471. This->pFuncsTable->source_disconnect(This);
  472. if (This->pMemInputPin)
  473. {
  474. IMemInputPin_Release(This->pMemInputPin);
  475. This->pMemInputPin = NULL;
  476. }
  477. if (This->pAllocator)
  478. {
  479. IMemAllocator_Release(This->pAllocator);
  480. This->pAllocator = NULL;
  481. }
  482. if (This->pin.peer)
  483. {
  484. IPin_Release(This->pin.peer);
  485. This->pin.peer = NULL;
  486. FreeMediaType(&This->pin.mt);
  487. ZeroMemory(&This->pin.mt, sizeof(This->pin.mt));
  488. hr = S_OK;
  489. }
  490. else
  491. hr = S_FALSE;
  492. }
  493. LeaveCriticalSection(&This->pin.filter->filter_cs);
  494. return hr;
  495. }
  496. static HRESULT WINAPI source_EndOfStream(IPin *iface)
  497. {
  498. struct strmbase_source *pin = impl_source_from_IPin(iface);
  499. WARN("pin %p %s:%s, unexpected call.\n", pin, debugstr_w(pin->pin.filter->name), debugstr_w(pin->pin.name));
  500. /* not supposed to do anything in an output pin */
  501. return E_UNEXPECTED;
  502. }
  503. static HRESULT WINAPI source_BeginFlush(IPin *iface)
  504. {
  505. struct strmbase_source *pin = impl_source_from_IPin(iface);
  506. WARN("pin %p %s:%s, unexpected call.\n", pin, debugstr_w(pin->pin.filter->name), debugstr_w(pin->pin.name));
  507. /* not supposed to do anything in an output pin */
  508. return E_UNEXPECTED;
  509. }
  510. static HRESULT WINAPI source_EndFlush(IPin *iface)
  511. {
  512. struct strmbase_source *pin = impl_source_from_IPin(iface);
  513. WARN("pin %p %s:%s, unexpected call.\n", pin, debugstr_w(pin->pin.filter->name), debugstr_w(pin->pin.name));
  514. /* not supposed to do anything in an output pin */
  515. return E_UNEXPECTED;
  516. }
  517. static HRESULT WINAPI source_NewSegment(IPin * iface, REFERENCE_TIME start, REFERENCE_TIME stop, double rate)
  518. {
  519. struct strmbase_source *pin = impl_source_from_IPin(iface);
  520. TRACE("pin %p %s:%s, start %s, stop %s, rate %.16e.\n", pin, debugstr_w(pin->pin.filter->name),
  521. debugstr_w(pin->pin.name), debugstr_time(start), debugstr_time(stop), rate);
  522. return S_OK;
  523. }
  524. static const IPinVtbl source_vtbl =
  525. {
  526. pin_QueryInterface,
  527. pin_AddRef,
  528. pin_Release,
  529. source_Connect,
  530. source_ReceiveConnection,
  531. source_Disconnect,
  532. pin_ConnectedTo,
  533. pin_ConnectionMediaType,
  534. pin_QueryPinInfo,
  535. pin_QueryDirection,
  536. pin_QueryId,
  537. pin_QueryAccept,
  538. pin_EnumMediaTypes,
  539. pin_QueryInternalConnections,
  540. source_EndOfStream,
  541. source_BeginFlush,
  542. source_EndFlush,
  543. source_NewSegment,
  544. };
  545. HRESULT WINAPI BaseOutputPinImpl_GetDeliveryBuffer(struct strmbase_source *This,
  546. IMediaSample **ppSample, REFERENCE_TIME *tStart, REFERENCE_TIME *tStop, DWORD dwFlags)
  547. {
  548. HRESULT hr;
  549. TRACE("(%p)->(%p, %p, %p, %x)\n", This, ppSample, tStart, tStop, dwFlags);
  550. if (!This->pin.peer)
  551. hr = VFW_E_NOT_CONNECTED;
  552. else
  553. {
  554. hr = IMemAllocator_GetBuffer(This->pAllocator, ppSample, tStart, tStop, dwFlags);
  555. if (SUCCEEDED(hr))
  556. hr = IMediaSample_SetTime(*ppSample, tStart, tStop);
  557. }
  558. return hr;
  559. }
  560. HRESULT WINAPI BaseOutputPinImpl_InitAllocator(struct strmbase_source *This, IMemAllocator **pMemAlloc)
  561. {
  562. return CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER, &IID_IMemAllocator, (LPVOID*)pMemAlloc);
  563. }
  564. HRESULT WINAPI BaseOutputPinImpl_DecideAllocator(struct strmbase_source *This,
  565. IMemInputPin *pPin, IMemAllocator **pAlloc)
  566. {
  567. HRESULT hr;
  568. hr = IMemInputPin_GetAllocator(pPin, pAlloc);
  569. if (hr == VFW_E_NO_ALLOCATOR)
  570. /* Input pin provides no allocator, use standard memory allocator */
  571. hr = BaseOutputPinImpl_InitAllocator(This, pAlloc);
  572. if (SUCCEEDED(hr))
  573. {
  574. ALLOCATOR_PROPERTIES rProps;
  575. ZeroMemory(&rProps, sizeof(ALLOCATOR_PROPERTIES));
  576. IMemInputPin_GetAllocatorRequirements(pPin, &rProps);
  577. hr = This->pFuncsTable->pfnDecideBufferSize(This, *pAlloc, &rProps);
  578. }
  579. if (SUCCEEDED(hr))
  580. hr = IMemInputPin_NotifyAllocator(pPin, *pAlloc, FALSE);
  581. return hr;
  582. }
  583. /*** The Construct functions ***/
  584. /* Function called as a helper to IPin_Connect */
  585. /* specific AM_MEDIA_TYPE - it cannot be NULL */
  586. HRESULT WINAPI BaseOutputPinImpl_AttemptConnection(struct strmbase_source *This,
  587. IPin *pReceivePin, const AM_MEDIA_TYPE *pmt)
  588. {
  589. HRESULT hr;
  590. IMemAllocator * pMemAlloc = NULL;
  591. TRACE("(%p)->(%p, %p)\n", This, pReceivePin, pmt);
  592. if (!query_accept(&This->pin, pmt))
  593. return VFW_E_TYPE_NOT_ACCEPTED;
  594. This->pin.peer = pReceivePin;
  595. IPin_AddRef(pReceivePin);
  596. CopyMediaType(&This->pin.mt, pmt);
  597. hr = IPin_ReceiveConnection(pReceivePin, &This->pin.IPin_iface, pmt);
  598. /* get the IMemInputPin interface we will use to deliver samples to the
  599. * connected pin */
  600. if (SUCCEEDED(hr))
  601. {
  602. This->pMemInputPin = NULL;
  603. hr = IPin_QueryInterface(pReceivePin, &IID_IMemInputPin, (LPVOID)&This->pMemInputPin);
  604. if (SUCCEEDED(hr))
  605. {
  606. hr = This->pFuncsTable->pfnDecideAllocator(This, This->pMemInputPin, &pMemAlloc);
  607. if (SUCCEEDED(hr))
  608. This->pAllocator = pMemAlloc;
  609. else if (pMemAlloc)
  610. IMemAllocator_Release(pMemAlloc);
  611. }
  612. /* break connection if we couldn't get the allocator */
  613. if (FAILED(hr))
  614. {
  615. if (This->pMemInputPin)
  616. IMemInputPin_Release(This->pMemInputPin);
  617. This->pMemInputPin = NULL;
  618. IPin_Disconnect(pReceivePin);
  619. }
  620. }
  621. if (FAILED(hr))
  622. {
  623. IPin_Release(This->pin.peer);
  624. This->pin.peer = NULL;
  625. FreeMediaType(&This->pin.mt);
  626. }
  627. TRACE(" -- %x\n", hr);
  628. return hr;
  629. }
  630. void strmbase_source_init(struct strmbase_source *pin, struct strmbase_filter *filter,
  631. const WCHAR *name, const struct strmbase_source_ops *func_table)
  632. {
  633. memset(pin, 0, sizeof(*pin));
  634. pin->pin.IPin_iface.lpVtbl = &source_vtbl;
  635. pin->pin.filter = filter;
  636. pin->pin.dir = PINDIR_OUTPUT;
  637. lstrcpyW(pin->pin.name, name);
  638. pin->pin.ops = &func_table->base;
  639. pin->pFuncsTable = func_table;
  640. }
  641. void strmbase_source_cleanup(struct strmbase_source *pin)
  642. {
  643. FreeMediaType(&pin->pin.mt);
  644. if (pin->pAllocator)
  645. IMemAllocator_Release(pin->pAllocator);
  646. pin->pAllocator = NULL;
  647. }
  648. static struct strmbase_sink *impl_sink_from_IPin(IPin *iface)
  649. {
  650. return CONTAINING_RECORD(iface, struct strmbase_sink, pin.IPin_iface);
  651. }
  652. static HRESULT WINAPI sink_Connect(IPin *iface, IPin *peer, const AM_MEDIA_TYPE *mt)
  653. {
  654. struct strmbase_sink *pin = impl_sink_from_IPin(iface);
  655. WARN("pin %p %s:%s, peer %p, mt %p, unexpected call.\n", pin, debugstr_w(pin->pin.name),
  656. debugstr_w(pin->pin.filter->name), peer, mt);
  657. return E_UNEXPECTED;
  658. }
  659. static HRESULT WINAPI sink_ReceiveConnection(IPin *iface, IPin *pReceivePin, const AM_MEDIA_TYPE *pmt)
  660. {
  661. struct strmbase_sink *This = impl_sink_from_IPin(iface);
  662. PIN_DIRECTION pindirReceive;
  663. HRESULT hr = S_OK;
  664. TRACE("pin %p %s:%s, peer %p, mt %p.\n", This, debugstr_w(This->pin.filter->name),
  665. debugstr_w(This->pin.name), pReceivePin, pmt);
  666. strmbase_dump_media_type(pmt);
  667. if (!pmt)
  668. return E_POINTER;
  669. EnterCriticalSection(&This->pin.filter->filter_cs);
  670. {
  671. if (This->pin.filter->state != State_Stopped)
  672. {
  673. LeaveCriticalSection(&This->pin.filter->filter_cs);
  674. WARN("Filter is not stopped; returning VFW_E_NOT_STOPPED.\n");
  675. return VFW_E_NOT_STOPPED;
  676. }
  677. if (This->pin.peer)
  678. hr = VFW_E_ALREADY_CONNECTED;
  679. if (SUCCEEDED(hr) && !query_accept(&This->pin, pmt))
  680. hr = VFW_E_TYPE_NOT_ACCEPTED; /* FIXME: shouldn't we just map common errors onto
  681. * VFW_E_TYPE_NOT_ACCEPTED and pass the value on otherwise? */
  682. if (SUCCEEDED(hr))
  683. {
  684. IPin_QueryDirection(pReceivePin, &pindirReceive);
  685. if (pindirReceive != PINDIR_OUTPUT)
  686. {
  687. ERR("Can't connect from non-output pin\n");
  688. hr = VFW_E_INVALID_DIRECTION;
  689. }
  690. }
  691. if (SUCCEEDED(hr) && This->pFuncsTable->sink_connect)
  692. hr = This->pFuncsTable->sink_connect(This, pReceivePin, pmt);
  693. if (SUCCEEDED(hr))
  694. {
  695. CopyMediaType(&This->pin.mt, pmt);
  696. This->pin.peer = pReceivePin;
  697. IPin_AddRef(pReceivePin);
  698. }
  699. }
  700. LeaveCriticalSection(&This->pin.filter->filter_cs);
  701. return hr;
  702. }
  703. static HRESULT WINAPI sink_Disconnect(IPin *iface)
  704. {
  705. struct strmbase_sink *pin = impl_sink_from_IPin(iface);
  706. HRESULT hr;
  707. TRACE("pin %p %s:%s.\n", pin, debugstr_w(pin->pin.filter->name), debugstr_w(pin->pin.name));
  708. EnterCriticalSection(&pin->pin.filter->filter_cs);
  709. if (pin->pin.filter->state != State_Stopped)
  710. {
  711. LeaveCriticalSection(&pin->pin.filter->filter_cs);
  712. WARN("Filter is not stopped; returning VFW_E_NOT_STOPPED.\n");
  713. return VFW_E_NOT_STOPPED;
  714. }
  715. if (pin->pin.peer)
  716. {
  717. if (pin->pFuncsTable->sink_disconnect)
  718. pin->pFuncsTable->sink_disconnect(pin);
  719. if (pin->pAllocator)
  720. {
  721. IMemAllocator_Release(pin->pAllocator);
  722. pin->pAllocator = NULL;
  723. }
  724. IPin_Release(pin->pin.peer);
  725. pin->pin.peer = NULL;
  726. FreeMediaType(&pin->pin.mt);
  727. memset(&pin->pin.mt, 0, sizeof(AM_MEDIA_TYPE));
  728. hr = S_OK;
  729. }
  730. else
  731. hr = S_FALSE;
  732. LeaveCriticalSection(&pin->pin.filter->filter_cs);
  733. return hr;
  734. }
  735. static HRESULT deliver_endofstream(IPin* pin, LPVOID unused)
  736. {
  737. return IPin_EndOfStream( pin );
  738. }
  739. static HRESULT WINAPI sink_EndOfStream(IPin *iface)
  740. {
  741. struct strmbase_sink *pin = impl_sink_from_IPin(iface);
  742. HRESULT hr = S_OK;
  743. TRACE("pin %p %s:%s.\n", pin, debugstr_w(pin->pin.filter->name), debugstr_w(pin->pin.name));
  744. if (pin->pFuncsTable->sink_eos)
  745. {
  746. EnterCriticalSection(&pin->pin.filter->stream_cs);
  747. hr = pin->pFuncsTable->sink_eos(pin);
  748. LeaveCriticalSection(&pin->pin.filter->stream_cs);
  749. return hr;
  750. }
  751. EnterCriticalSection(&pin->pin.filter->filter_cs);
  752. if (pin->flushing)
  753. hr = S_FALSE;
  754. LeaveCriticalSection(&pin->pin.filter->filter_cs);
  755. if (hr == S_OK)
  756. hr = SendFurther(pin, deliver_endofstream, NULL);
  757. return hr;
  758. }
  759. static HRESULT deliver_beginflush(IPin* pin, LPVOID unused)
  760. {
  761. return IPin_BeginFlush( pin );
  762. }
  763. static HRESULT WINAPI sink_BeginFlush(IPin *iface)
  764. {
  765. struct strmbase_sink *pin = impl_sink_from_IPin(iface);
  766. HRESULT hr;
  767. TRACE("pin %p %s:%s.\n", pin, debugstr_w(pin->pin.filter->name), debugstr_w(pin->pin.name));
  768. EnterCriticalSection(&pin->pin.filter->filter_cs);
  769. pin->flushing = TRUE;
  770. if (pin->pFuncsTable->sink_begin_flush)
  771. hr = pin->pFuncsTable->sink_begin_flush(pin);
  772. else
  773. hr = SendFurther(pin, deliver_beginflush, NULL);
  774. LeaveCriticalSection(&pin->pin.filter->filter_cs);
  775. return hr;
  776. }
  777. static HRESULT deliver_endflush(IPin* pin, LPVOID unused)
  778. {
  779. return IPin_EndFlush( pin );
  780. }
  781. static HRESULT WINAPI sink_EndFlush(IPin * iface)
  782. {
  783. struct strmbase_sink *pin = impl_sink_from_IPin(iface);
  784. HRESULT hr;
  785. TRACE("pin %p %s:%s.\n", pin, debugstr_w(pin->pin.filter->name), debugstr_w(pin->pin.name));
  786. EnterCriticalSection(&pin->pin.filter->filter_cs);
  787. pin->flushing = FALSE;
  788. if (pin->pFuncsTable->sink_end_flush)
  789. hr = pin->pFuncsTable->sink_end_flush(pin);
  790. else
  791. hr = SendFurther(pin, deliver_endflush, NULL);
  792. LeaveCriticalSection(&pin->pin.filter->filter_cs);
  793. return hr;
  794. }
  795. typedef struct newsegmentargs
  796. {
  797. REFERENCE_TIME tStart, tStop;
  798. double rate;
  799. } newsegmentargs;
  800. static HRESULT deliver_newsegment(IPin *pin, LPVOID data)
  801. {
  802. newsegmentargs *args = data;
  803. return IPin_NewSegment(pin, args->tStart, args->tStop, args->rate);
  804. }
  805. static HRESULT WINAPI sink_NewSegment(IPin *iface, REFERENCE_TIME start, REFERENCE_TIME stop, double rate)
  806. {
  807. struct strmbase_sink *pin = impl_sink_from_IPin(iface);
  808. newsegmentargs args;
  809. TRACE("pin %p %s:%s, start %s, stop %s, rate %.16e.\n", pin, debugstr_w(pin->pin.filter->name),
  810. debugstr_w(pin->pin.name), debugstr_time(start), debugstr_time(stop), rate);
  811. if (pin->pFuncsTable->sink_new_segment)
  812. return pin->pFuncsTable->sink_new_segment(pin, start, stop, rate);
  813. args.tStart = start;
  814. args.tStop = stop;
  815. args.rate = rate;
  816. return SendFurther(pin, deliver_newsegment, &args);
  817. }
  818. static const IPinVtbl sink_vtbl =
  819. {
  820. pin_QueryInterface,
  821. pin_AddRef,
  822. pin_Release,
  823. sink_Connect,
  824. sink_ReceiveConnection,
  825. sink_Disconnect,
  826. pin_ConnectedTo,
  827. pin_ConnectionMediaType,
  828. pin_QueryPinInfo,
  829. pin_QueryDirection,
  830. pin_QueryId,
  831. pin_QueryAccept,
  832. pin_EnumMediaTypes,
  833. pin_QueryInternalConnections,
  834. sink_EndOfStream,
  835. sink_BeginFlush,
  836. sink_EndFlush,
  837. sink_NewSegment,
  838. };
  839. /*** IMemInputPin implementation ***/
  840. static inline struct strmbase_sink *impl_from_IMemInputPin(IMemInputPin *iface)
  841. {
  842. return CONTAINING_RECORD(iface, struct strmbase_sink, IMemInputPin_iface);
  843. }
  844. static HRESULT WINAPI MemInputPin_QueryInterface(IMemInputPin * iface, REFIID riid, LPVOID * ppv)
  845. {
  846. struct strmbase_sink *This = impl_from_IMemInputPin(iface);
  847. return IPin_QueryInterface(&This->pin.IPin_iface, riid, ppv);
  848. }
  849. static ULONG WINAPI MemInputPin_AddRef(IMemInputPin * iface)
  850. {
  851. struct strmbase_sink *This = impl_from_IMemInputPin(iface);
  852. return IPin_AddRef(&This->pin.IPin_iface);
  853. }
  854. static ULONG WINAPI MemInputPin_Release(IMemInputPin * iface)
  855. {
  856. struct strmbase_sink *This = impl_from_IMemInputPin(iface);
  857. return IPin_Release(&This->pin.IPin_iface);
  858. }
  859. static HRESULT WINAPI MemInputPin_GetAllocator(IMemInputPin * iface, IMemAllocator ** ppAllocator)
  860. {
  861. struct strmbase_sink *This = impl_from_IMemInputPin(iface);
  862. TRACE("pin %p %s:%s, allocator %p.\n", This, debugstr_w(This->pin.filter->name),
  863. debugstr_w(This->pin.name), ppAllocator);
  864. *ppAllocator = This->pAllocator;
  865. if (*ppAllocator)
  866. IMemAllocator_AddRef(*ppAllocator);
  867. return *ppAllocator ? S_OK : VFW_E_NO_ALLOCATOR;
  868. }
  869. static HRESULT WINAPI MemInputPin_NotifyAllocator(IMemInputPin * iface, IMemAllocator * pAllocator, BOOL bReadOnly)
  870. {
  871. struct strmbase_sink *This = impl_from_IMemInputPin(iface);
  872. TRACE("pin %p %s:%s, allocator %p, read_only %d.\n", This, debugstr_w(This->pin.filter->name),
  873. debugstr_w(This->pin.name), pAllocator, bReadOnly);
  874. if (bReadOnly)
  875. FIXME("Read only flag not handled yet!\n");
  876. /* FIXME: Should we release the allocator on disconnection? */
  877. if (!pAllocator)
  878. {
  879. WARN("Null allocator\n");
  880. return E_POINTER;
  881. }
  882. if (This->preferred_allocator && pAllocator != This->preferred_allocator)
  883. return E_FAIL;
  884. if (This->pAllocator)
  885. IMemAllocator_Release(This->pAllocator);
  886. This->pAllocator = pAllocator;
  887. if (This->pAllocator)
  888. IMemAllocator_AddRef(This->pAllocator);
  889. return S_OK;
  890. }
  891. static HRESULT WINAPI MemInputPin_GetAllocatorRequirements(IMemInputPin *iface, ALLOCATOR_PROPERTIES *props)
  892. {
  893. struct strmbase_sink *pin = impl_from_IMemInputPin(iface);
  894. TRACE("pin %p %s:%s, props %p.\n", pin, debugstr_w(pin->pin.filter->name),
  895. debugstr_w(pin->pin.name), props);
  896. /* override this method if you have any specific requirements */
  897. return E_NOTIMPL;
  898. }
  899. static HRESULT WINAPI MemInputPin_Receive(IMemInputPin *iface, IMediaSample *sample)
  900. {
  901. struct strmbase_sink *pin = impl_from_IMemInputPin(iface);
  902. HRESULT hr = S_FALSE;
  903. TRACE("pin %p %s:%s, sample %p.\n", pin, debugstr_w(pin->pin.filter->name),
  904. debugstr_w(pin->pin.name), sample);
  905. if (pin->pFuncsTable->pfnReceive)
  906. {
  907. EnterCriticalSection(&pin->pin.filter->stream_cs);
  908. hr = pin->pFuncsTable->pfnReceive(pin, sample);
  909. LeaveCriticalSection(&pin->pin.filter->stream_cs);
  910. }
  911. return hr;
  912. }
  913. static HRESULT WINAPI MemInputPin_ReceiveMultiple(IMemInputPin * iface, IMediaSample ** pSamples, LONG nSamples, LONG *nSamplesProcessed)
  914. {
  915. HRESULT hr = S_OK;
  916. for (*nSamplesProcessed = 0; *nSamplesProcessed < nSamples; (*nSamplesProcessed)++)
  917. {
  918. hr = IMemInputPin_Receive(iface, pSamples[*nSamplesProcessed]);
  919. if (hr != S_OK)
  920. break;
  921. }
  922. return hr;
  923. }
  924. static HRESULT WINAPI MemInputPin_ReceiveCanBlock(IMemInputPin * iface)
  925. {
  926. struct strmbase_sink *pin = impl_from_IMemInputPin(iface);
  927. TRACE("pin %p %s:%s.\n", pin, debugstr_w(pin->pin.filter->name), debugstr_w(pin->pin.name));
  928. return S_OK;
  929. }
  930. static const IMemInputPinVtbl MemInputPin_Vtbl =
  931. {
  932. MemInputPin_QueryInterface,
  933. MemInputPin_AddRef,
  934. MemInputPin_Release,
  935. MemInputPin_GetAllocator,
  936. MemInputPin_NotifyAllocator,
  937. MemInputPin_GetAllocatorRequirements,
  938. MemInputPin_Receive,
  939. MemInputPin_ReceiveMultiple,
  940. MemInputPin_ReceiveCanBlock
  941. };
  942. void strmbase_sink_init(struct strmbase_sink *pin, struct strmbase_filter *filter,
  943. const WCHAR *name, const struct strmbase_sink_ops *func_table, IMemAllocator *allocator)
  944. {
  945. memset(pin, 0, sizeof(*pin));
  946. pin->pin.IPin_iface.lpVtbl = &sink_vtbl;
  947. pin->pin.filter = filter;
  948. pin->pin.dir = PINDIR_INPUT;
  949. lstrcpyW(pin->pin.name, name);
  950. pin->pin.ops = &func_table->base;
  951. pin->pFuncsTable = func_table;
  952. pin->pAllocator = pin->preferred_allocator = allocator;
  953. if (pin->preferred_allocator)
  954. IMemAllocator_AddRef(pin->preferred_allocator);
  955. pin->IMemInputPin_iface.lpVtbl = &MemInputPin_Vtbl;
  956. }
  957. void strmbase_sink_cleanup(struct strmbase_sink *pin)
  958. {
  959. FreeMediaType(&pin->pin.mt);
  960. if (pin->pAllocator)
  961. IMemAllocator_Release(pin->pAllocator);
  962. pin->pAllocator = NULL;
  963. pin->pin.IPin_iface.lpVtbl = NULL;
  964. }