wshom.ocx: Implement IWshShortcut::Save().
[wine.git] / dlls / winegstreamer / gstdemux.c
blob655a9f2e6fe41f9edcc49cc45505c52617bc68c7
1 /*
2 * GStreamer splitter + decoder, adapted from parser.c
4 * Copyright 2010 Maarten Lankhorst for CodeWeavers
5 * Copyright 2010 Aric Stewart for 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 "config.h"
23 #include <gst/app/gstappsink.h>
24 #include <gst/app/gstappsrc.h>
25 #include <gst/app/gstappbuffer.h>
26 #include <gst/gstutils.h>
28 #include "gst_private.h"
29 #include "gst_guids.h"
31 #include "vfwmsgs.h"
32 #include "amvideo.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 #include <assert.h>
39 #include "dvdmedia.h"
40 #include "mmreg.h"
41 #include "ks.h"
42 #include "initguid.h"
43 #include "ksmedia.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(gstreamer);
47 typedef struct GSTOutPin GSTOutPin;
48 typedef struct GSTInPin {
49 BasePin pin;
50 IAsyncReader *pReader;
51 IMemAllocator *pAlloc;
52 } GSTInPin;
54 typedef struct GSTImpl {
55 BaseFilter filter;
57 GSTInPin pInputPin;
58 GSTOutPin **ppPins;
59 LONG cStreams;
61 LONGLONG filesize;
63 BOOL discont, initial;
64 GstElement *gstfilter;
65 GstPad *my_src, *their_sink;
66 GstBus *bus;
67 guint64 start, nextofs, nextpullofs, stop;
68 ALLOCATOR_PROPERTIES props;
69 HANDLE event, changed_ofs;
71 HANDLE push_thread;
72 } GSTImpl;
74 struct GSTOutPin {
75 BaseOutputPin pin;
77 GstPad *their_src;
78 GstPad *my_sink;
79 int isaud, isvid;
80 AM_MEDIA_TYPE * pmt;
81 HANDLE caps_event;
82 GstSegment *segment;
83 QualityControlImpl qcimpl;
84 SourceSeeking seek;
87 static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};
88 static const IMediaSeekingVtbl GST_Seeking_Vtbl;
89 static const IPinVtbl GST_OutputPin_Vtbl;
90 static const IPinVtbl GST_InputPin_Vtbl;
91 static const IBaseFilterVtbl GST_Vtbl;
92 static const IQualityControlVtbl GSTOutPin_QualityControl_Vtbl;
94 static HRESULT GST_AddPin(GSTImpl *This, const PIN_INFO *piOutput, const AM_MEDIA_TYPE *amt);
95 static HRESULT GST_RemoveOutputPins(GSTImpl *This);
96 static HRESULT WINAPI GST_ChangeCurrent(IMediaSeeking *iface);
97 static HRESULT WINAPI GST_ChangeStop(IMediaSeeking *iface);
98 static HRESULT WINAPI GST_ChangeRate(IMediaSeeking *iface);
100 static int amt_from_gst_caps_audio(GstCaps *caps, AM_MEDIA_TYPE *amt) {
101 WAVEFORMATEXTENSIBLE *wfe;
102 WAVEFORMATEX *wfx;
103 GstStructure *arg;
104 gint32 depth = 0, bpp = 0;
105 const char *typename;
106 arg = gst_caps_get_structure(caps, 0);
107 typename = gst_structure_get_name(arg);
108 if (!typename)
109 return 0;
111 wfe = CoTaskMemAlloc(sizeof(*wfe));
112 wfx = (WAVEFORMATEX*)wfe;
113 amt->majortype = MEDIATYPE_Audio;
114 amt->subtype = MEDIASUBTYPE_PCM;
115 amt->formattype = FORMAT_WaveFormatEx;
116 amt->pbFormat = (BYTE*)wfe;
117 amt->cbFormat = sizeof(*wfe);
118 amt->bFixedSizeSamples = 0;
119 amt->bTemporalCompression = 1;
120 amt->lSampleSize = 0;
121 amt->pUnk = NULL;
123 wfx->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
124 if (!gst_structure_get_int(arg, "channels", (INT*)&wfx->nChannels))
125 return 0;
126 if (!gst_structure_get_int(arg, "rate", (INT*)&wfx->nSamplesPerSec))
127 return 0;
128 gst_structure_get_int(arg, "width", &depth);
129 gst_structure_get_int(arg, "depth", &bpp);
130 if (!depth || depth > 32 || depth % 8)
131 depth = bpp;
132 else if (!bpp)
133 bpp = depth;
134 wfe->Samples.wValidBitsPerSample = depth;
135 wfx->wBitsPerSample = bpp;
136 wfx->cbSize = sizeof(*wfe)-sizeof(*wfx);
137 switch (wfx->nChannels) {
138 case 1: wfe->dwChannelMask = KSAUDIO_SPEAKER_MONO; break;
139 case 2: wfe->dwChannelMask = KSAUDIO_SPEAKER_STEREO; break;
140 case 4: wfe->dwChannelMask = KSAUDIO_SPEAKER_SURROUND; break;
141 case 5: wfe->dwChannelMask = (KSAUDIO_SPEAKER_5POINT1 & ~SPEAKER_LOW_FREQUENCY); break;
142 case 6: wfe->dwChannelMask = KSAUDIO_SPEAKER_5POINT1; break;
143 case 8: wfe->dwChannelMask = KSAUDIO_SPEAKER_7POINT1; break;
144 default:
145 wfe->dwChannelMask = 0;
147 if (!strcmp(typename, "audio/x-raw-float")) {
148 wfe->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
149 wfx->wBitsPerSample = wfe->Samples.wValidBitsPerSample = 32;
150 } else {
151 wfe->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
152 if (wfx->nChannels <= 2 && bpp <= 16 && depth == bpp) {
153 wfx->wFormatTag = WAVE_FORMAT_PCM;
154 wfx->cbSize = 0;
157 wfx->nBlockAlign = wfx->nChannels * wfx->wBitsPerSample/8;
158 wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign;
159 return 1;
162 static int amt_from_gst_caps_video(GstCaps *caps, AM_MEDIA_TYPE *amt) {
163 VIDEOINFOHEADER *vih = CoTaskMemAlloc(sizeof(*vih));
164 BITMAPINFOHEADER *bih = &vih->bmiHeader;
165 GstStructure *arg;
166 gint32 width = 0, height = 0, nom = 0, denom = 0;
167 const char *typename;
168 arg = gst_caps_get_structure(caps, 0);
169 typename = gst_structure_get_name(arg);
170 if (!typename)
171 return 0;
172 if (!gst_structure_get_int(arg, "width", &width) ||
173 !gst_structure_get_int(arg, "height", &height) ||
174 !gst_structure_get_fraction(arg, "framerate", &nom, &denom))
175 return 0;
176 amt->formattype = FORMAT_VideoInfo;
177 amt->pbFormat = (BYTE*)vih;
178 amt->cbFormat = sizeof(*vih);
179 amt->bFixedSizeSamples = amt->bTemporalCompression = 1;
180 amt->lSampleSize = 0;
181 amt->pUnk = NULL;
182 ZeroMemory(vih, sizeof(*vih));
183 amt->majortype = MEDIATYPE_Video;
184 if (!strcmp(typename, "video/x-raw-rgb")) {
185 if (!gst_structure_get_int(arg, "bpp", (INT*)&bih->biBitCount))
186 return 0;
187 switch (bih->biBitCount) {
188 case 16: amt->subtype = MEDIASUBTYPE_RGB555; break;
189 case 24: amt->subtype = MEDIASUBTYPE_RGB24; break;
190 case 32: amt->subtype = MEDIASUBTYPE_RGB32; break;
191 default:
192 FIXME("Unknown bpp %u\n", bih->biBitCount);
193 return 0;
195 bih->biCompression = BI_RGB;
196 } else {
197 amt->subtype = MEDIATYPE_Video;
198 if (!gst_structure_get_fourcc(arg, "format", &amt->subtype.Data1))
199 return 0;
200 switch (amt->subtype.Data1) {
201 case mmioFOURCC('I','4','2','0'):
202 case mmioFOURCC('Y','V','1','2'):
203 case mmioFOURCC('N','V','1','2'):
204 case mmioFOURCC('N','V','2','1'):
205 bih->biBitCount = 12; break;
206 case mmioFOURCC('Y','U','Y','2'):
207 case mmioFOURCC('Y','V','Y','U'):
208 bih->biBitCount = 16; break;
210 bih->biCompression = amt->subtype.Data1;
212 bih->biSizeImage = width * height * bih->biBitCount / 8;
213 vih->AvgTimePerFrame = 10000000;
214 vih->AvgTimePerFrame *= denom;
215 vih->AvgTimePerFrame /= nom;
216 vih->rcSource.left = 0;
217 vih->rcSource.right = width;
218 vih->rcSource.top = height;
219 vih->rcSource.bottom = 0;
220 vih->rcTarget = vih->rcSource;
221 bih->biSize = sizeof(*bih);
222 bih->biWidth = width;
223 bih->biHeight = height;
224 bih->biPlanes = 1;
225 return 1;
228 static gboolean accept_caps_sink(GstPad *pad, GstCaps *caps) {
229 GSTOutPin *pin = gst_pad_get_element_private(pad);
230 AM_MEDIA_TYPE amt;
231 GstStructure *arg;
232 const char *typename;
233 int ret;
234 arg = gst_caps_get_structure(caps, 0);
235 typename = gst_structure_get_name(arg);
236 if (!strcmp(typename, "audio/x-raw-int") ||
237 !strcmp(typename, "audio/x-raw-float")) {
238 if (!pin->isaud) {
239 ERR("Setting audio caps on non-audio pad?\n");
240 return 0;
242 ret = amt_from_gst_caps_audio(caps, &amt);
243 FreeMediaType(&amt);
244 TRACE("+%i\n", ret);
245 return ret;
246 } else if (!strcmp(typename, "video/x-raw-rgb")
247 || !strcmp(typename, "video/x-raw-yuv")) {
248 if (!pin->isvid) {
249 ERR("Setting video caps on non-video pad?\n");
250 return 0;
252 ret = amt_from_gst_caps_video(caps, &amt);
253 FreeMediaType(&amt);
254 TRACE("-%i\n", ret);
255 return ret;
256 } else {
257 FIXME("Unhandled type \"%s\"\n", typename);
258 return 0;
262 static gboolean setcaps_sink(GstPad *pad, GstCaps *caps) {
263 GSTOutPin *pin = gst_pad_get_element_private(pad);
264 GSTImpl *This = (GSTImpl *)pin->pin.pin.pinInfo.pFilter;
265 AM_MEDIA_TYPE amt;
266 GstStructure *arg;
267 const char *typename;
268 int ret;
269 arg = gst_caps_get_structure(caps, 0);
270 typename = gst_structure_get_name(arg);
271 if (!strcmp(typename, "audio/x-raw-int") ||
272 !strcmp(typename, "audio/x-raw-float")) {
273 if (!pin->isaud) {
274 ERR("Setting audio caps on non-audio pad?\n");
275 return 0;
277 ret = amt_from_gst_caps_audio(caps, &amt);
278 } else if (!strcmp(typename, "video/x-raw-rgb")
279 || !strcmp(typename, "video/x-raw-yuv")) {
280 if (!pin->isvid) {
281 ERR("Setting video caps on non-video pad?\n");
282 return 0;
284 ret = amt_from_gst_caps_video(caps, &amt);
285 if (ret)
286 This->props.cbBuffer = max(This->props.cbBuffer, ((VIDEOINFOHEADER*)amt.pbFormat)->bmiHeader.biSizeImage);
287 } else {
288 FIXME("Unhandled type \"%s\"\n", typename);
289 return 0;
291 TRACE("Linking returned %i for %s\n", ret, typename);
292 if (!ret)
293 return 0;
294 FreeMediaType(pin->pmt);
295 *pin->pmt = amt;
296 return 1;
299 static gboolean gst_base_src_perform_seek(GSTImpl *This, GstEvent *event)
301 gboolean res = TRUE;
302 gdouble rate;
303 GstFormat seek_format;
304 GstSeekFlags flags;
305 GstSeekType cur_type, stop_type;
306 gint64 cur, stop;
307 gboolean flush;
308 guint32 seqnum;
309 GstEvent *tevent;
310 BOOL thread = !!This->push_thread;
312 gst_event_parse_seek(event, &rate, &seek_format, &flags,
313 &cur_type, &cur, &stop_type, &stop);
315 if (seek_format != GST_FORMAT_BYTES) {
316 FIXME("Not handling other format %i\n", seek_format);
317 return 0;
320 flush = flags & GST_SEEK_FLAG_FLUSH;
321 seqnum = gst_event_get_seqnum(event);
323 /* send flush start */
324 if (flush) {
325 tevent = gst_event_new_flush_start();
326 gst_event_set_seqnum(tevent, seqnum);
327 gst_pad_push_event(This->my_src, tevent);
328 if (This->pInputPin.pReader)
329 IAsyncReader_BeginFlush(This->pInputPin.pReader);
330 if (thread)
331 gst_pad_activate_push(This->my_src, 0);
334 This->nextofs = This->start = cur;
336 /* and prepare to continue streaming */
337 if (flush) {
338 tevent = gst_event_new_flush_stop();
339 gst_event_set_seqnum(tevent, seqnum);
340 gst_pad_push_event(This->my_src, tevent);
341 if (This->pInputPin.pReader)
342 IAsyncReader_EndFlush(This->pInputPin.pReader);
343 if (thread)
344 gst_pad_activate_push(This->my_src, 1);
347 return res;
350 static gboolean event_src(GstPad *pad, GstEvent *event) {
351 GSTImpl *This = gst_pad_get_element_private(pad);
352 switch (event->type) {
353 case GST_EVENT_SEEK:
354 return gst_base_src_perform_seek(This, event);
355 case GST_EVENT_FLUSH_START:
356 EnterCriticalSection(&This->filter.csFilter);
357 if (This->pInputPin.pReader)
358 IAsyncReader_BeginFlush(This->pInputPin.pReader);
359 LeaveCriticalSection(&This->filter.csFilter);
360 break;
361 case GST_EVENT_FLUSH_STOP:
362 EnterCriticalSection(&This->filter.csFilter);
363 if (This->pInputPin.pReader)
364 IAsyncReader_EndFlush(This->pInputPin.pReader);
365 LeaveCriticalSection(&This->filter.csFilter);
366 break;
367 default:
368 FIXME("%p (%u) stub\n", event, event->type);
369 case GST_EVENT_TAG:
370 case GST_EVENT_QOS:
371 return gst_pad_event_default(pad, event);
373 return 1;
376 static gboolean event_sink(GstPad *pad, GstEvent *event) {
377 GSTOutPin *pin = gst_pad_get_element_private(pad);
378 switch (event->type) {
379 case GST_EVENT_NEWSEGMENT: {
380 gboolean update;
381 gdouble rate, applied_rate;
382 GstFormat format;
383 gint64 start, stop, pos;
384 gst_event_parse_new_segment_full(event, &update, &rate, &applied_rate, &format, &start, &stop, &pos);
385 if (format != GST_FORMAT_TIME) {
386 FIXME("Ignoring new segment because of format %i\n", format);
387 return 1;
389 gst_segment_set_newsegment_full(pin->segment, update, rate, applied_rate, format, start, stop, pos);
390 pos /= 100;
391 if (stop > 0)
392 stop /= 100;
393 if (pin->pin.pin.pConnectedTo)
394 IPin_NewSegment(pin->pin.pin.pConnectedTo, pos, stop, rate*applied_rate);
395 return 1;
397 case GST_EVENT_EOS:
398 if (pin->pin.pin.pConnectedTo)
399 IPin_EndOfStream(pin->pin.pin.pConnectedTo);
400 return 1;
401 case GST_EVENT_FLUSH_START:
402 if (pin->pin.pin.pConnectedTo)
403 IPin_BeginFlush(pin->pin.pin.pConnectedTo);
404 return 1;
405 case GST_EVENT_FLUSH_STOP:
406 gst_segment_init(pin->segment, GST_FORMAT_TIME);
407 if (pin->pin.pin.pConnectedTo)
408 IPin_EndFlush(pin->pin.pin.pConnectedTo);
409 return 1;
410 default:
411 FIXME("%p stub %s\n", event, gst_event_type_get_name(event->type));
412 return gst_pad_event_default(pad, event);
416 static void release_sample(void *data) {
417 ULONG ret;
418 ret = IMediaSample_Release((IMediaSample *)data);
419 TRACE("Releasing %p returns %u\n", data, ret);
422 static DWORD CALLBACK push_data(LPVOID iface) {
423 LONGLONG maxlen, curlen;
424 GSTImpl *This = iface;
425 IMediaSample *buf;
426 DWORD_PTR user;
427 HRESULT hr;
429 if (!This->stop)
430 IAsyncReader_Length(This->pInputPin.pReader, &maxlen, &curlen);
431 else
432 maxlen = This->stop;
433 TRACE("Starting..\n");
434 for (;;) {
435 REFERENCE_TIME tStart, tStop;
436 ULONG len;
437 GstBuffer *gstbuf;
438 BYTE *data;
439 int ret;
441 hr = IMemAllocator_GetBuffer(This->pInputPin.pAlloc, &buf, NULL, NULL, 0);
442 if (FAILED(hr))
443 break;
445 if (This->nextofs >= maxlen)
446 break;
447 len = IMediaSample_GetSize(buf);
448 if (This->nextofs + len > maxlen)
449 len = maxlen - This->nextofs;
451 tStart = MEDIATIME_FROM_BYTES(This->nextofs);
452 tStop = tStart + MEDIATIME_FROM_BYTES(len);
453 IMediaSample_SetTime(buf, &tStart, &tStop);
455 hr = IAsyncReader_Request(This->pInputPin.pReader, buf, 0);
456 if (FAILED(hr)) {
457 IMediaSample_Release(buf);
458 break;
460 This->nextofs += len;
461 hr = IAsyncReader_WaitForNext(This->pInputPin.pReader, -1, &buf, &user);
462 if (FAILED(hr) || !buf) {
463 if (buf)
464 IMediaSample_Release(buf);
465 break;
468 IMediaSample_GetPointer(buf, &data);
469 gstbuf = gst_app_buffer_new(data, IMediaSample_GetActualDataLength(buf), release_sample, buf);
470 if (!gstbuf) {
471 IMediaSample_Release(buf);
472 break;
474 gstbuf->duration = gstbuf->timestamp = -1;
475 ret = gst_pad_push(This->my_src, gstbuf);
476 if (ret >= 0)
477 hr = S_OK;
478 else
479 ERR("Sending returned: %i\n", ret);
480 if (ret == GST_FLOW_ERROR)
481 hr = E_FAIL;
482 else if (ret == GST_FLOW_WRONG_STATE)
483 hr = VFW_E_WRONG_STATE;
484 else if (ret == GST_FLOW_RESEND)
485 hr = S_FALSE;
486 if (hr != S_OK)
487 break;
490 gst_pad_push_event(This->my_src, gst_event_new_eos());
492 TRACE("Almost stopping.. %08x\n", hr);
493 do {
494 IAsyncReader_WaitForNext(This->pInputPin.pReader, 0, &buf, &user);
495 if (buf)
496 IMediaSample_Release(buf);
497 } while (buf);
499 TRACE("Stopping.. %08x\n", hr);
500 return 0;
503 static HRESULT WINAPI GST_OutPin_QueryAccept(IPin *iface, const AM_MEDIA_TYPE *pmt) {
504 GSTOutPin *pin = (GSTOutPin*)iface;
505 FIXME("stub %p\n", pin);
506 return S_OK;
509 static GstFlowReturn got_data_sink(GstPad *pad, GstBuffer *buf) {
510 GSTOutPin *pin = gst_pad_get_element_private(pad);
511 GSTImpl *This = (GSTImpl *)pin->pin.pin.pinInfo.pFilter;
512 IMediaSample *sample;
513 HRESULT hr;
514 BOOL freeSamp = FALSE;
516 if (This->initial) {
517 gst_buffer_unref(buf);
518 FIXME("Triggering %p %p\n", pad, pin->caps_event);
519 SetEvent(pin->caps_event);
520 return GST_FLOW_NOT_LINKED;
523 if (GST_IS_APP_BUFFER(buf)) {
524 sample = GST_APP_BUFFER(buf)->priv;
525 TRACE("Pushing buffer\n");
526 } else if (buf->parent && GST_IS_APP_BUFFER(buf->parent)) {
527 sample = GST_APP_BUFFER(buf->parent)->priv;
528 TRACE("Pushing sub-buffer\n");
529 } else {
530 BYTE *ptr = NULL;
531 hr = BaseOutputPinImpl_GetDeliveryBuffer(&pin->pin, &sample, NULL, NULL, 0);
532 freeSamp = TRUE;
533 if (hr == VFW_E_NOT_CONNECTED) {
534 gst_buffer_unref(buf);
535 return GST_FLOW_NOT_LINKED;
537 if (FAILED(hr)) {
538 gst_buffer_unref(buf);
539 ERR("Didn't get a GST_APP_BUFFER, and could not get a delivery buffer (%x), returning GST_FLOW_WRONG_STATE\n", hr);
540 return GST_FLOW_WRONG_STATE;
542 FIXME("Did not get a GST_APP_BUFFER, creating a sample\n");
543 IMediaSample_GetPointer(sample, &ptr);
544 memcpy(ptr, GST_BUFFER_DATA(buf), GST_BUFFER_SIZE(buf));
546 IMediaSample_SetActualDataLength(sample, GST_BUFFER_SIZE(buf));
548 if (GST_BUFFER_TIMESTAMP_IS_VALID(buf)) {
549 REFERENCE_TIME rtStart = gst_segment_to_running_time(pin->segment, GST_FORMAT_TIME, buf->timestamp);
550 if (rtStart >= 0)
551 rtStart /= 100;
553 if (GST_BUFFER_DURATION_IS_VALID(buf)) {
554 REFERENCE_TIME tStart = buf->timestamp / 100;
555 REFERENCE_TIME tStop = (buf->timestamp + buf->duration) / 100;
556 REFERENCE_TIME rtStop;
557 rtStop = gst_segment_to_running_time(pin->segment, GST_FORMAT_TIME, buf->timestamp + buf->duration);
558 if (rtStop >= 0)
559 rtStop /= 100;
560 TRACE("Current time on %p: %i to %i ms\n", pin, (int)(rtStart / 10000), (int)(rtStop / 10000));
561 IMediaSample_SetTime(sample, &rtStart, rtStop >= 0 ? &rtStop : NULL);
562 IMediaSample_SetMediaTime(sample, &tStart, &tStop);
563 } else {
564 IMediaSample_SetTime(sample, rtStart >= 0 ? &rtStart : NULL, NULL);
565 IMediaSample_SetMediaTime(sample, NULL, NULL);
567 } else {
568 IMediaSample_SetTime(sample, NULL, NULL);
569 IMediaSample_SetMediaTime(sample, NULL, NULL);
572 IMediaSample_SetDiscontinuity(sample, GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_DISCONT));
573 IMediaSample_SetPreroll(sample, GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_PREROLL));
574 IMediaSample_SetSyncPoint(sample, !GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_DELTA_UNIT));
576 if (!pin->pin.pin.pConnectedTo)
577 hr = VFW_E_NOT_CONNECTED;
578 else
579 hr = IMemInputPin_Receive(pin->pin.pMemInputPin, sample);
580 TRACE("sending sample: %08x\n", hr);
581 gst_buffer_unref(buf);
582 if (freeSamp)
583 IMediaSample_Release(sample);
584 if (hr == VFW_E_NOT_CONNECTED)
585 return GST_FLOW_NOT_LINKED;
586 else if (FAILED(hr))
587 return GST_FLOW_WRONG_STATE;
588 if (hr != S_OK)
589 return GST_FLOW_RESEND;
590 return GST_FLOW_OK;
593 static GstFlowReturn request_buffer_sink(GstPad *pad, guint64 ofs, guint size, GstCaps *caps, GstBuffer **buf) {
594 GSTOutPin *pin = gst_pad_get_element_private(pad);
595 GSTImpl *This = (GSTImpl *)pin->pin.pin.pinInfo.pFilter;
596 IMediaSample *sample;
597 BYTE *ptr;
598 HRESULT hr;
600 TRACE("Requesting buffer\n");
601 if (This->initial) {
602 int ret;
603 ret = setcaps_sink(pad, caps);
604 if (!ret)
605 return GST_FLOW_NOT_NEGOTIATED;
606 *buf = gst_buffer_new_and_alloc(size);
607 return GST_FLOW_OK;
610 if (caps && caps != GST_PAD_CAPS(pad))
611 if (!setcaps_sink(pad, caps))
612 return GST_FLOW_NOT_NEGOTIATED;
614 hr = BaseOutputPinImpl_GetDeliveryBuffer(&pin->pin, &sample, NULL, NULL, 0);
615 if (hr == VFW_E_NOT_CONNECTED)
616 return GST_FLOW_NOT_LINKED;
617 if (FAILED(hr)) {
618 ERR("Could not get output buffer: %08x\n", hr);
619 *buf = NULL;
620 return GST_FLOW_WRONG_STATE;
622 IMediaSample_SetActualDataLength(sample, size);
623 IMediaSample_GetPointer(sample, &ptr);
624 *buf = gst_app_buffer_new(ptr, size, release_sample, sample);
625 if (!*buf) {
626 IMediaSample_Release(sample);
627 ERR("Out of memory\n");
628 return GST_FLOW_ERROR;
630 gst_buffer_set_caps(*buf, caps);
631 return GST_FLOW_OK;
634 static GstFlowReturn request_buffer_src(GstPad *pad, guint64 ofs, guint len, GstBuffer **buf) {
635 GSTImpl *This = gst_pad_get_element_private(pad);
636 int ret;
638 *buf = NULL;
639 TRACE("Requesting %s %u\n", wine_dbgstr_longlong(ofs), len);
640 if (ofs == (guint64)-1)
641 ofs = This->nextpullofs;
642 if (ofs >= This->filesize) {
643 WARN("Reading past eof: %s, %u\n", wine_dbgstr_longlong(ofs), len);
644 return GST_FLOW_UNEXPECTED;
646 if (len + ofs > This->filesize)
647 len = This->filesize - ofs;
648 This->nextpullofs = ofs + len;
650 ret = gst_pad_alloc_buffer(This->my_src, ofs, len, NULL, buf);
651 if (ret >= 0) {
652 HRESULT hr;
653 hr = IAsyncReader_SyncRead(This->pInputPin.pReader, ofs, len, GST_BUFFER_DATA(*buf));
654 if (FAILED(hr)) {
655 ERR("Returned %08x\n", hr);
656 return GST_FLOW_ERROR;
659 return ret;
662 static DWORD CALLBACK push_data_init(LPVOID iface) {
663 GSTImpl *This = iface;
664 DWORD64 ofs = 0;
666 TRACE("Starting..\n");
667 for (;;) {
668 GstBuffer *buf;
669 GstFlowReturn ret = request_buffer_src(This->my_src, ofs, 4096, &buf);
670 if (ret < 0) {
671 ERR("Obtaining buffer returned: %i\n", ret);
672 break;
674 ret = gst_pad_push(This->my_src, buf);
675 ofs += 4096;
676 if (ret)
677 TRACE("Sending returned: %i\n", ret);
678 if (ret < 0)
679 break;
681 TRACE("Stopping..\n");
682 return 0;
685 static void removed_decoded_pad(GstElement *bin, GstPad *pad, GSTImpl *This) {
686 int x;
687 GSTOutPin *pin;
689 EnterCriticalSection(&This->filter.csFilter);
690 for (x = 0; x < This->cStreams; ++x) {
691 if (This->ppPins[x]->their_src == pad)
692 break;
694 if (x == This->cStreams)
695 goto out;
696 pin = This->ppPins[x];
697 gst_pad_unlink(pin->their_src, pin->my_sink);
698 gst_object_unref(pin->their_src);
699 pin->their_src = NULL;
700 out:
701 TRACE("Removed %i/%i\n", x, This->cStreams);
702 LeaveCriticalSection(&This->filter.csFilter);
705 static void init_new_decoded_pad(GstElement *bin, GstPad *pad, gboolean last, GSTImpl *This) {
706 HRESULT hr;
707 PIN_INFO piOutput;
708 const char *typename;
709 char *name;
710 AM_MEDIA_TYPE amt = { };
711 GstCaps *caps;
712 GstStructure *arg;
713 GstPad *mypad;
714 GSTOutPin *pin;
715 int ret;
716 int isvid = 0, isaud = 0;
718 piOutput.dir = PINDIR_OUTPUT;
719 piOutput.pFilter = (IBaseFilter *)This;
720 name = gst_pad_get_name(pad);
721 MultiByteToWideChar(CP_UNIXCP, 0, name, -1, piOutput.achName, sizeof(piOutput.achName) / sizeof(piOutput.achName[0]) - 1);
722 TRACE("Name: %s\n", name);
723 g_free(name);
724 piOutput.achName[sizeof(piOutput.achName) / sizeof(piOutput.achName[0]) - 1] = 0;
726 caps = gst_pad_get_caps_reffed(pad);
727 arg = gst_caps_get_structure(caps, 0);
728 typename = gst_structure_get_name(arg);
730 mypad = gst_pad_new(NULL, GST_PAD_SINK);
731 gst_pad_set_chain_function(mypad, got_data_sink);
732 gst_pad_set_event_function(mypad, event_sink);
733 gst_pad_set_bufferalloc_function(mypad, request_buffer_sink);
734 gst_pad_set_acceptcaps_function(mypad, accept_caps_sink);
735 gst_pad_set_setcaps_function(mypad, setcaps_sink);
737 if (!strcmp(typename, "audio/x-raw-int") ||
738 !strcmp(typename, "audio/x-raw-float")) {
739 isaud = 1;
740 } else if (!strcmp(typename, "video/x-raw-rgb")
741 || !strcmp(typename, "video/x-raw-yuv")) {
742 isvid = 1;
743 } else {
744 FIXME("Unknown type \'%s\'\n", typename);
745 return;
747 GST_PAD_CAPS(mypad) = GST_CAPS_ANY;
748 hr = GST_AddPin(This, &piOutput, &amt);
749 if (FAILED(hr)) {
750 ERR("%08x\n", hr);
751 return;
753 pin = This->ppPins[This->cStreams - 1];
754 gst_pad_set_element_private(mypad, pin);
755 pin->my_sink = mypad;
756 pin->isaud = isaud;
757 pin->isvid = isvid;
759 gst_segment_init(pin->segment, GST_FORMAT_TIME);
760 ret = gst_pad_link(pad, mypad);
761 gst_pad_activate_push(mypad, 1);
762 FIXME("Linking: %i\n", ret);
763 if (ret >= 0) {
764 pin->their_src = pad;
765 gst_object_ref(pin->their_src);
769 static void existing_new_pad(GstElement *bin, GstPad *pad, gboolean last, GSTImpl *This) {
770 int x;
772 if (gst_pad_is_linked(pad))
773 return;
775 /* Still holding our own lock */
776 if (This->initial) {
777 init_new_decoded_pad(bin, pad, last, This);
778 return;
781 EnterCriticalSection(&This->filter.csFilter);
782 for (x = 0; x < This->cStreams; ++x) {
783 GSTOutPin *pin = This->ppPins[x];
784 if (!pin->their_src) {
785 gst_segment_init(pin->segment, GST_FORMAT_TIME);
786 if (gst_pad_link(pad, pin->my_sink) >= 0) {
787 pin->their_src = pad;
788 gst_object_ref(pin->their_src);
789 TRACE("Relinked\n");
790 LeaveCriticalSection(&This->filter.csFilter);
791 return;
795 init_new_decoded_pad(bin, pad, last, This);
796 LeaveCriticalSection(&This->filter.csFilter);
799 static gboolean check_get_range(GstPad *pad) {
800 return 1;
803 static gboolean query_function(GstPad *pad, GstQuery *query) {
804 GSTImpl *This = gst_pad_get_element_private(pad);
805 GstFormat format;
806 int ret;
807 LONGLONG duration;
809 switch (GST_QUERY_TYPE(query)) {
810 case GST_QUERY_DURATION:
811 gst_query_parse_duration (query, &format, NULL);
812 if (format == GST_FORMAT_PERCENT) {
813 gst_query_set_duration (query, GST_FORMAT_PERCENT, GST_FORMAT_PERCENT_MAX);
814 return 1;
816 ret = gst_pad_query_convert (pad, GST_FORMAT_BYTES, This->filesize, &format, &duration);
817 gst_query_set_duration(query, format, duration);
818 return ret;
819 case GST_QUERY_SEEKING:
820 gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
821 TRACE("Seeking %i %i\n", format, GST_FORMAT_BYTES);
822 if (format != GST_FORMAT_BYTES)
823 return 0;
824 gst_query_set_seeking(query, GST_FORMAT_BYTES, 1, 0, This->filesize);
825 return 1;
826 default:
827 FIXME("Unhandled query type %i\n", GST_QUERY_TYPE(query));
828 case GST_QUERY_URI:
829 case GST_QUERY_CONVERT:
830 return 0;
834 static gboolean activate_push(GstPad *pad, gboolean activate) {
835 GSTImpl *This = gst_pad_get_element_private(pad);
836 EnterCriticalSection(&This->filter.csFilter);
837 if (!activate) {
838 TRACE("Deactivating\n");
839 if (!This->initial)
840 IAsyncReader_BeginFlush(This->pInputPin.pReader);
841 if (This->push_thread) {
842 WaitForSingleObject(This->push_thread, -1);
843 CloseHandle(This->push_thread);
844 This->push_thread = NULL;
846 if (!This->initial)
847 IAsyncReader_EndFlush(This->pInputPin.pReader);
848 if (This->filter.state == State_Stopped)
849 This->nextofs = This->start;
850 } else if (!This->push_thread) {
851 TRACE("Activating\n");
852 if (This->initial)
853 This->push_thread = CreateThread(NULL, 0, push_data_init, This, 0, NULL);
854 else
855 This->push_thread = CreateThread(NULL, 0, push_data, This, 0, NULL);
857 LeaveCriticalSection(&This->filter.csFilter);
858 return 1;
861 static void no_more_pads(GstElement *decodebin, GSTImpl *This) {
862 FIXME("Done\n");
863 SetEvent(This->event);
866 typedef enum {
867 GST_AUTOPLUG_SELECT_TRY,
868 GST_AUTOPLUG_SELECT_EXPOSE,
869 GST_AUTOPLUG_SELECT_SKIP
870 } GstAutoplugSelectResult;
872 static GstAutoplugSelectResult autoplug_blacklist(GstElement *bin, GstPad *pad, GstCaps *caps, GstElementFactory *fact, GSTImpl *This) {
873 const char *name = gst_element_factory_get_longname(fact);
875 if (strstr(name, "Player protection")) {
876 WARN("Blacklisted a/52 decoder because it only works in Totem\n");
877 return GST_AUTOPLUG_SELECT_SKIP;
879 if (!strcmp(name, "Fluendo Hardware Accelerated Video Decoder")) {
880 WARN("Disabled video acceleration since it breaks in wine\n");
881 return GST_AUTOPLUG_SELECT_SKIP;
883 TRACE("using \"%s\"\n", name);
884 return GST_AUTOPLUG_SELECT_TRY;
887 static GstBusSyncReply watch_bus(GstBus *bus, GstMessage *msg, gpointer data) {
888 GSTImpl *This = data;
889 GError *err = NULL;
890 gchar *dbg_info = NULL;
891 if (GST_MESSAGE_TYPE(msg) & GST_MESSAGE_ERROR) {
892 gst_message_parse_error(msg, &err, &dbg_info);
893 FIXME("%s: %s\n", GST_OBJECT_NAME(msg->src), err->message);
894 WARN("%s\n", dbg_info);
895 SetEvent(This->event);
896 } else if (GST_MESSAGE_TYPE(msg) & GST_MESSAGE_WARNING) {
897 gst_message_parse_warning(msg, &err, &dbg_info);
898 WARN("%s: %s\n", GST_OBJECT_NAME(msg->src), err->message);
899 WARN("%s\n", dbg_info);
901 if (err)
902 g_error_free(err);
903 g_free(dbg_info);
904 return GST_BUS_DROP;
907 static void unknown_type(GstElement *bin, GstPad *pad, GstCaps *caps, GSTImpl *This) {
908 gchar *strcaps = gst_caps_to_string(caps);
909 FIXME("Could not find a filter for caps: %s\n", strcaps);
910 g_free(strcaps);
913 static HRESULT GST_Connect(GSTInPin *pPin, IPin *pConnectPin, ALLOCATOR_PROPERTIES *props) {
914 GSTImpl *This = (GSTImpl*)pPin->pin.pinInfo.pFilter;
915 HRESULT hr;
916 int ret, i;
917 LONGLONG avail, duration;
918 GstFormat format = GST_FORMAT_TIME;
919 GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE(
920 "quartz_src",
921 GST_PAD_SRC,
922 GST_PAD_ALWAYS,
923 GST_STATIC_CAPS_ANY);
925 TRACE("%p %p %p\n", pPin, pConnectPin, props);
926 This->props = *props;
927 IAsyncReader_Length(pPin->pReader, &This->filesize, &avail);
929 if (!This->bus) {
930 This->bus = gst_bus_new();
931 gst_bus_set_sync_handler(This->bus, watch_bus, This);
934 This->gstfilter = gst_element_factory_make("decodebin2", NULL);
935 if (!This->gstfilter) {
936 FIXME("Could not make source filter, are gstreamer-plugins-* installed for %u bits?\n",
937 8 * (int)sizeof(void*));
938 return E_FAIL;
940 gst_element_set_bus(This->gstfilter, This->bus);
941 g_signal_connect(This->gstfilter, "new-decoded-pad", G_CALLBACK(existing_new_pad), This);
942 g_signal_connect(This->gstfilter, "pad-removed", G_CALLBACK(removed_decoded_pad), This);
943 g_signal_connect(This->gstfilter, "autoplug-select", G_CALLBACK(autoplug_blacklist), This);
944 g_signal_connect(This->gstfilter, "unknown-type", G_CALLBACK(unknown_type), This);
946 This->my_src = gst_pad_new_from_static_template(&src_template, "quartz-src");
947 gst_pad_set_getrange_function(This->my_src, request_buffer_src);
948 gst_pad_set_checkgetrange_function(This->my_src, check_get_range);
949 gst_pad_set_query_function(This->my_src, query_function);
950 gst_pad_set_activatepush_function(This->my_src, activate_push);
951 gst_pad_set_event_function(This->my_src, event_src);
952 gst_pad_set_element_private (This->my_src, This);
953 This->their_sink = gst_element_get_static_pad(This->gstfilter, "sink");
955 g_signal_connect(This->gstfilter, "no-more-pads", G_CALLBACK(no_more_pads), This);
956 ret = gst_pad_link(This->my_src, This->their_sink);
957 gst_object_unref(This->their_sink);
958 if (ret < 0) {
959 ERR("Returns: %i\n", ret);
960 return E_FAIL;
962 This->start = This->nextofs = This->nextpullofs = This->stop = 0;
964 /* Add initial pins */
965 This->initial = This->discont = 1;
966 ResetEvent(This->event);
967 gst_element_set_state(This->gstfilter, GST_STATE_PLAYING);
968 gst_pad_set_active(This->my_src, 1);
969 WaitForSingleObject(This->event, -1);
970 gst_element_get_state(This->gstfilter, NULL, NULL, -1);
972 if (ret < 0) {
973 WARN("Ret: %i\n", ret);
974 hr = E_FAIL;
975 } else if (!This->cStreams) {
976 FIXME("Gstreamer could not find any streams\n");
977 hr = E_FAIL;
978 } else {
979 gst_pad_query_duration(This->ppPins[0]->their_src, &format, &duration);
980 for (i = 0; i < This->cStreams; ++i) {
981 This->ppPins[i]->seek.llDuration = This->ppPins[i]->seek.llStop = duration / 100;
982 This->ppPins[i]->seek.llCurrent = 0;
983 if (!This->ppPins[i]->seek.llDuration)
984 This->ppPins[i]->seek.dwCapabilities = 0;
985 WaitForSingleObject(This->ppPins[i]->caps_event, -1);
987 hr = S_OK;
989 *props = This->props;
990 gst_element_set_state(This->gstfilter, GST_STATE_READY);
991 gst_element_get_state(This->gstfilter, NULL, NULL, -1);
992 if (This->push_thread)
993 gst_pad_activate_push(This->my_src, 0);
995 This->initial = 0;
996 This->nextofs = This->nextpullofs = 0;
997 return hr;
1000 static inline GSTOutPin *impl_from_IMediaSeeking( IMediaSeeking *iface ) {
1001 return (GSTOutPin *)((char*)iface - FIELD_OFFSET(GSTOutPin, seek.lpVtbl));
1004 static IPin* WINAPI GST_GetPin(BaseFilter *iface, int pos)
1006 GSTImpl *This = (GSTImpl *)iface;
1007 TRACE("Asking for pos %x\n", pos);
1009 if (pos > This->cStreams || pos < 0)
1010 return NULL;
1011 if (!pos)
1013 IPin_AddRef((IPin*)&This->pInputPin);
1014 return (IPin*)&This->pInputPin;
1016 else
1018 IPin_AddRef((IPin*)This->ppPins[pos - 1]);
1019 return (IPin*)This->ppPins[pos - 1];
1023 static LONG WINAPI GST_GetPinCount(BaseFilter *iface)
1025 GSTImpl *This = (GSTImpl *)iface;
1026 return (This->cStreams + 1);
1029 static const BaseFilterFuncTable BaseFuncTable = {
1030 GST_GetPin,
1031 GST_GetPinCount
1034 IUnknown * CALLBACK Gstreamer_Splitter_create(IUnknown *punkout, HRESULT *phr) {
1035 IUnknown *obj = NULL;
1036 PIN_INFO *piInput;
1037 GSTImpl *This;
1039 if (!Gstreamer_init())
1041 *phr = E_FAIL;
1042 return NULL;
1045 This = CoTaskMemAlloc(sizeof(*This));
1046 obj = (IUnknown*)This;
1047 if (!This)
1049 *phr = E_OUTOFMEMORY;
1050 return NULL;
1053 BaseFilter_Init(&This->filter, &GST_Vtbl, &CLSID_Gstreamer_Splitter, (DWORD_PTR)(__FILE__ ": GSTImpl.csFilter"), &BaseFuncTable);
1055 This->cStreams = 0;
1056 This->ppPins = NULL;
1057 This->push_thread = NULL;
1058 This->event = CreateEventW(NULL, 0, 0, NULL);
1059 This->bus = NULL;
1061 piInput = &This->pInputPin.pin.pinInfo;
1062 piInput->dir = PINDIR_INPUT;
1063 piInput->pFilter = (IBaseFilter *)This;
1064 lstrcpynW(piInput->achName, wcsInputPinName, sizeof(piInput->achName) / sizeof(piInput->achName[0]));
1065 This->pInputPin.pin.lpVtbl = &GST_InputPin_Vtbl;
1066 This->pInputPin.pin.refCount = 1;
1067 This->pInputPin.pin.pConnectedTo = NULL;
1068 This->pInputPin.pin.pCritSec = &This->filter.csFilter;
1069 ZeroMemory(&This->pInputPin.pin.mtCurrent, sizeof(AM_MEDIA_TYPE));
1070 *phr = S_OK;
1071 return obj;
1074 static void GST_Destroy(GSTImpl *This) {
1075 IPin *connected = NULL;
1076 ULONG pinref;
1078 TRACE("Destroying\n");
1080 CloseHandle(This->event);
1082 /* Don't need to clean up output pins, disconnecting input pin will do that */
1083 IPin_ConnectedTo((IPin *)&This->pInputPin, &connected);
1084 if (connected) {
1085 assert(IPin_Disconnect(connected) == S_OK);
1086 IPin_Release(connected);
1087 assert(IPin_Disconnect((IPin *)&This->pInputPin) == S_OK);
1089 pinref = IPin_Release((IPin *)&This->pInputPin);
1090 if (pinref) {
1091 /* Valgrind could find this, if I kill it here */
1092 ERR("pinref should be null, is %u, destroying anyway\n", pinref);
1093 assert((LONG)pinref > 0);
1095 while (pinref)
1096 pinref = IPin_Release((IPin *)&This->pInputPin);
1098 if (This->bus) {
1099 gst_bus_set_sync_handler(This->bus, NULL, NULL);
1100 gst_object_unref(This->bus);
1102 CoTaskMemFree(This);
1105 static HRESULT WINAPI GST_QueryInterface(IBaseFilter *iface, REFIID riid, LPVOID *ppv) {
1106 GSTImpl *This = (GSTImpl *)iface;
1107 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1109 *ppv = NULL;
1111 if (IsEqualIID(riid, &IID_IUnknown))
1112 *ppv = This;
1113 else if (IsEqualIID(riid, &IID_IPersist))
1114 *ppv = This;
1115 else if (IsEqualIID(riid, &IID_IMediaFilter))
1116 *ppv = This;
1117 else if (IsEqualIID(riid, &IID_IBaseFilter))
1118 *ppv = This;
1120 if (*ppv) {
1121 IUnknown_AddRef((IUnknown *)(*ppv));
1122 return S_OK;
1125 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow) &&
1126 !IsEqualIID(riid, &IID_IAMFilterMiscFlags))
1127 FIXME("No interface for %s!\n", debugstr_guid(riid));
1129 return E_NOINTERFACE;
1132 static ULONG WINAPI GST_Release(IBaseFilter *iface) {
1133 GSTImpl *This = (GSTImpl *)iface;
1134 ULONG refCount = BaseFilterImpl_Release(iface);
1136 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
1138 if (!refCount)
1139 GST_Destroy(This);
1141 return refCount;
1144 static HRESULT WINAPI GST_Stop(IBaseFilter *iface) {
1145 GSTImpl *This = (GSTImpl *)iface;
1147 TRACE("()\n");
1149 if (This->gstfilter)
1150 gst_element_set_state(This->gstfilter, GST_STATE_READY);
1151 return S_OK;
1154 static HRESULT WINAPI GST_Pause(IBaseFilter *iface) {
1155 HRESULT hr = S_OK;
1156 GSTImpl *This = (GSTImpl *)iface;
1157 GstState now;
1158 GstStateChangeReturn ret;
1159 TRACE("()\n");
1161 if (!This->gstfilter)
1162 return VFW_E_NOT_CONNECTED;
1164 gst_element_get_state(This->gstfilter, &now, NULL, -1);
1165 if (now == GST_STATE_PAUSED)
1166 return S_OK;
1167 if (now != GST_STATE_PLAYING)
1168 hr = IBaseFilter_Run(iface, -1);
1169 if (FAILED(hr))
1170 return hr;
1171 ret = gst_element_set_state(This->gstfilter, GST_STATE_PAUSED);
1172 if (ret == GST_STATE_CHANGE_ASYNC)
1173 hr = S_FALSE;
1174 return hr;
1177 static HRESULT WINAPI GST_Run(IBaseFilter *iface, REFERENCE_TIME tStart) {
1178 HRESULT hr = S_OK;
1179 GSTImpl *This = (GSTImpl *)iface;
1180 ULONG i;
1181 GstState now;
1182 HRESULT hr_any = VFW_E_NOT_CONNECTED;
1184 TRACE("(%s)\n", wine_dbgstr_longlong(tStart));
1186 if (!This->gstfilter)
1187 return VFW_E_NOT_CONNECTED;
1189 EnterCriticalSection(&This->filter.csFilter);
1190 This->filter.rtStreamStart = tStart;
1191 LeaveCriticalSection(&This->filter.csFilter);
1193 gst_element_get_state(This->gstfilter, &now, NULL, -1);
1194 if (now == GST_STATE_PLAYING)
1195 return S_OK;
1196 if (now == GST_STATE_PAUSED) {
1197 GstStateChangeReturn ret;
1198 ret = gst_element_set_state(This->gstfilter, GST_STATE_PLAYING);
1199 if (ret == GST_STATE_CHANGE_ASYNC)
1200 return S_FALSE;
1201 return S_OK;
1204 EnterCriticalSection(&This->filter.csFilter);
1205 gst_pad_set_blocked(This->my_src, 0);
1206 gst_pad_set_blocked(This->their_sink, 0);
1207 gst_element_set_state(This->gstfilter, GST_STATE_PLAYING);
1208 This->filter.rtStreamStart = tStart;
1210 for (i = 0; i < This->cStreams; i++) {
1211 hr = BaseOutputPinImpl_Active((BaseOutputPin *)This->ppPins[i]);
1212 if (SUCCEEDED(hr)) {
1213 gst_pad_set_blocked(This->ppPins[i]->my_sink, 0);
1214 if (This->ppPins[i]->their_src)
1215 gst_pad_set_blocked(This->ppPins[i]->their_src, 0);
1216 hr_any = hr;
1219 hr = hr_any;
1220 if (SUCCEEDED(hr))
1221 gst_pad_set_active(This->my_src, 1);
1222 LeaveCriticalSection(&This->filter.csFilter);
1224 return hr;
1227 static HRESULT WINAPI GST_GetState(IBaseFilter *iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState) {
1228 GSTImpl *This = (GSTImpl *)iface;
1229 HRESULT hr = S_OK;
1230 GstState now, pending;
1231 GstStateChangeReturn ret;
1233 TRACE("(%d, %p)\n", dwMilliSecsTimeout, pState);
1235 if (!This->gstfilter) {
1236 *pState = State_Stopped;
1237 return S_OK;
1240 ret = gst_element_get_state(This->gstfilter, &now, &pending, dwMilliSecsTimeout == INFINITE ? -1 : dwMilliSecsTimeout * 1000);
1242 if (ret == GST_STATE_CHANGE_ASYNC)
1243 hr = VFW_S_STATE_INTERMEDIATE;
1244 else
1245 pending = now;
1247 switch (pending) {
1248 case GST_STATE_PAUSED: *pState = State_Paused; return hr;
1249 case GST_STATE_PLAYING: *pState = State_Running; return hr;
1250 default: *pState = State_Stopped; return hr;
1254 static HRESULT WINAPI GST_FindPin(IBaseFilter *iface, LPCWSTR Id, IPin **ppPin) {
1255 FIXME("(%p)->(%s,%p) stub\n", iface, debugstr_w(Id), ppPin);
1256 return E_NOTIMPL;
1259 static const IBaseFilterVtbl GST_Vtbl = {
1260 GST_QueryInterface,
1261 BaseFilterImpl_AddRef,
1262 GST_Release,
1263 BaseFilterImpl_GetClassID,
1264 GST_Stop,
1265 GST_Pause,
1266 GST_Run,
1267 GST_GetState,
1268 BaseFilterImpl_SetSyncSource,
1269 BaseFilterImpl_GetSyncSource,
1270 BaseFilterImpl_EnumPins,
1271 GST_FindPin,
1272 BaseFilterImpl_QueryFilterInfo,
1273 BaseFilterImpl_JoinFilterGraph,
1274 BaseFilterImpl_QueryVendorInfo
1277 static HRESULT WINAPI GST_ChangeCurrent(IMediaSeeking *iface) {
1278 return S_OK;
1281 static HRESULT WINAPI GST_ChangeStop(IMediaSeeking *iface) {
1282 return S_OK;
1285 static HRESULT WINAPI GST_ChangeRate(IMediaSeeking *iface) {
1286 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1287 GstEvent *ev = gst_event_new_seek(This->seek.dRate, GST_FORMAT_TIME, 0, GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_NONE, -1);
1288 TRACE("(%p) New rate %g\n", iface, This->seek.dRate);
1289 gst_pad_push_event(This->my_sink, ev);
1290 return S_OK;
1293 static HRESULT WINAPI GST_Seeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppv) {
1294 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1295 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
1298 static ULONG WINAPI GST_Seeking_AddRef(IMediaSeeking *iface) {
1299 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1300 return IUnknown_AddRef((IUnknown *)This);
1303 static ULONG WINAPI GST_Seeking_Release(IMediaSeeking *iface) {
1304 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1305 return IUnknown_Release((IUnknown *)This);
1308 static HRESULT WINAPI GST_Seeking_GetCurrentPosition(IMediaSeeking *iface, REFERENCE_TIME *pos) {
1309 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1310 GstFormat format = GST_FORMAT_TIME;
1312 if (!pos)
1313 return E_POINTER;
1315 if (!This->their_src) {
1316 *pos = This->seek.llCurrent;
1317 TRACE("Cached value\n");
1318 if (This->seek.llDuration)
1319 return S_OK;
1320 else
1321 return E_NOTIMPL;
1324 if (!gst_pad_query_position(This->their_src, &format, pos)) {
1325 WARN("Could not query position\n");
1326 return E_NOTIMPL;
1328 *pos /= 100;
1329 This->seek.llCurrent = *pos;
1330 return S_OK;
1333 static GstSeekType type_from_flags(DWORD flags) {
1334 switch (flags & AM_SEEKING_PositioningBitsMask) {
1335 case AM_SEEKING_NoPositioning: return GST_SEEK_TYPE_NONE;
1336 case AM_SEEKING_AbsolutePositioning: return GST_SEEK_TYPE_SET;
1337 case AM_SEEKING_RelativePositioning: return GST_SEEK_TYPE_CUR;
1338 case AM_SEEKING_IncrementalPositioning: return GST_SEEK_TYPE_END;
1340 return GST_SEEK_TYPE_NONE;
1344 static HRESULT WINAPI GST_Seeking_SetPositions(IMediaSeeking *iface, REFERENCE_TIME *pCur, DWORD curflags, REFERENCE_TIME *pStop, DWORD stopflags) {
1345 HRESULT hr;
1346 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1347 GstSeekFlags f = 0;
1348 GstSeekType curtype, stoptype;
1349 GstEvent *e;
1351 if (!This->seek.llDuration)
1352 return E_NOTIMPL;
1354 hr = SourceSeekingImpl_SetPositions(iface, pCur, curflags, pStop, stopflags);
1355 if (!This->their_src)
1356 return hr;
1358 curtype = type_from_flags(curflags);
1359 stoptype = type_from_flags(stopflags);
1360 if (curflags & AM_SEEKING_SeekToKeyFrame)
1361 f |= GST_SEEK_FLAG_KEY_UNIT;
1362 if (curflags & AM_SEEKING_Segment)
1363 f |= GST_SEEK_FLAG_SEGMENT;
1364 if (!(curflags & AM_SEEKING_NoFlush))
1365 f |= GST_SEEK_FLAG_FLUSH;
1367 e = gst_event_new_seek(This->seek.dRate, GST_FORMAT_TIME, f, curtype, pCur ? *pCur * 100 : -1, stoptype, pStop ? *pStop * 100 : -1);
1368 if (gst_pad_push_event(This->my_sink, e))
1369 return S_OK;
1370 else
1371 return E_NOTIMPL;
1374 static const IMediaSeekingVtbl GST_Seeking_Vtbl =
1376 GST_Seeking_QueryInterface,
1377 GST_Seeking_AddRef,
1378 GST_Seeking_Release,
1379 SourceSeekingImpl_GetCapabilities,
1380 SourceSeekingImpl_CheckCapabilities,
1381 SourceSeekingImpl_IsFormatSupported,
1382 SourceSeekingImpl_QueryPreferredFormat,
1383 SourceSeekingImpl_GetTimeFormat,
1384 SourceSeekingImpl_IsUsingTimeFormat,
1385 SourceSeekingImpl_SetTimeFormat,
1386 SourceSeekingImpl_GetDuration,
1387 SourceSeekingImpl_GetStopPosition,
1388 GST_Seeking_GetCurrentPosition,
1389 SourceSeekingImpl_ConvertTimeFormat,
1390 GST_Seeking_SetPositions,
1391 SourceSeekingImpl_GetPositions,
1392 SourceSeekingImpl_GetAvailable,
1393 SourceSeekingImpl_SetRate,
1394 SourceSeekingImpl_GetRate,
1395 SourceSeekingImpl_GetPreroll
1398 static HRESULT WINAPI GST_QualityControl_Notify(IQualityControl *iface, IBaseFilter *sender, Quality qm) {
1399 QualityControlImpl *This = (QualityControlImpl*)iface;
1400 GSTOutPin *pin = (GSTOutPin*)This->self;
1401 REFERENCE_TIME late = qm.Late;
1402 if (qm.Late < 0 && -qm.Late > qm.TimeStamp)
1403 late = -qm.TimeStamp;
1404 gst_pad_push_event(pin->my_sink, gst_event_new_qos(1000./qm.Proportion, late*100, qm.TimeStamp*100));
1405 return S_OK;
1408 static const IQualityControlVtbl GSTOutPin_QualityControl_Vtbl = {
1409 QualityControlImpl_QueryInterface,
1410 QualityControlImpl_AddRef,
1411 QualityControlImpl_Release,
1412 GST_QualityControl_Notify,
1413 QualityControlImpl_SetSink
1416 static HRESULT WINAPI GSTOutPin_QueryInterface(IPin *iface, REFIID riid, void **ppv) {
1417 GSTOutPin *This = (GSTOutPin *)iface;
1419 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1421 *ppv = NULL;
1423 if (IsEqualIID(riid, &IID_IUnknown))
1424 *ppv = iface;
1425 else if (IsEqualIID(riid, &IID_IPin))
1426 *ppv = iface;
1427 else if (IsEqualIID(riid, &IID_IMediaSeeking))
1428 *ppv = &This->seek;
1429 else if (IsEqualIID(riid, &IID_IQualityControl))
1430 *ppv = &This->qcimpl;
1432 if (*ppv) {
1433 IUnknown_AddRef((IUnknown *)(*ppv));
1434 return S_OK;
1436 FIXME("No interface for %s!\n", debugstr_guid(riid));
1437 return E_NOINTERFACE;
1440 static ULONG WINAPI GSTOutPin_Release(IPin *iface) {
1441 GSTOutPin *This = (GSTOutPin *)iface;
1442 ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
1443 TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
1445 if (!refCount) {
1446 if (This->their_src)
1447 gst_pad_unlink(This->their_src, This->my_sink);
1448 gst_object_unref(This->my_sink);
1449 CloseHandle(This->caps_event);
1450 DeleteMediaType(This->pmt);
1451 FreeMediaType(&This->pin.pin.mtCurrent);
1452 gst_segment_free(This->segment);
1453 CoTaskMemFree(This);
1454 return 0;
1456 return refCount;
1459 static HRESULT WINAPI GSTOutPin_GetMediaType(BasePin *iface, int iPosition, AM_MEDIA_TYPE *pmt)
1461 GSTOutPin *This = (GSTOutPin *)iface;
1463 if (iPosition < 0)
1464 return E_INVALIDARG;
1465 if (iPosition > 0)
1466 return VFW_S_NO_MORE_ITEMS;
1467 CopyMediaType(pmt, This->pmt);
1468 return S_OK;
1471 static HRESULT WINAPI GSTOutPin_DecideBufferSize(BaseOutputPin *iface, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
1473 /* Unused */
1474 return S_OK;
1477 static HRESULT WINAPI GSTOutPin_DecideAllocator(BaseOutputPin *iface, IMemInputPin *pPin, IMemAllocator **pAlloc)
1479 HRESULT hr;
1480 GSTOutPin *This = (GSTOutPin *)iface;
1481 GSTImpl *GSTfilter = (GSTImpl*)This->pin.pin.pinInfo.pFilter;
1483 *pAlloc = NULL;
1484 if (GSTfilter->pInputPin.pAlloc)
1485 hr = IMemInputPin_NotifyAllocator(pPin, GSTfilter->pInputPin.pAlloc, FALSE);
1486 else
1487 hr = VFW_E_NO_ALLOCATOR;
1489 return hr;
1492 static HRESULT WINAPI GSTOutPin_BreakConnect(BaseOutputPin *This)
1494 HRESULT hr;
1496 TRACE("(%p)->()\n", This);
1498 EnterCriticalSection(This->pin.pCritSec);
1499 if (!This->pin.pConnectedTo || !This->pMemInputPin)
1500 hr = VFW_E_NOT_CONNECTED;
1501 else
1503 hr = IPin_Disconnect(This->pin.pConnectedTo);
1504 IPin_Disconnect((IPin *)This);
1506 LeaveCriticalSection(This->pin.pCritSec);
1508 return hr;
1511 static const IPinVtbl GST_OutputPin_Vtbl = {
1512 GSTOutPin_QueryInterface,
1513 BasePinImpl_AddRef,
1514 GSTOutPin_Release,
1515 BaseOutputPinImpl_Connect,
1516 BaseOutputPinImpl_ReceiveConnection,
1517 BaseOutputPinImpl_Disconnect,
1518 BasePinImpl_ConnectedTo,
1519 BasePinImpl_ConnectionMediaType,
1520 BasePinImpl_QueryPinInfo,
1521 BasePinImpl_QueryDirection,
1522 BasePinImpl_QueryId,
1523 GST_OutPin_QueryAccept,
1524 BasePinImpl_EnumMediaTypes,
1525 BasePinImpl_QueryInternalConnections,
1526 BaseOutputPinImpl_EndOfStream,
1527 BaseOutputPinImpl_BeginFlush,
1528 BaseOutputPinImpl_EndFlush,
1529 BasePinImpl_NewSegment
1532 static const BasePinFuncTable output_BaseFuncTable = {
1533 NULL,
1534 BaseOutputPinImpl_AttemptConnection,
1535 BasePinImpl_GetMediaTypeVersion,
1536 GSTOutPin_GetMediaType
1539 static const BaseOutputPinFuncTable output_BaseOutputFuncTable = {
1540 GSTOutPin_DecideBufferSize,
1541 GSTOutPin_DecideAllocator,
1542 GSTOutPin_BreakConnect
1545 static HRESULT GST_AddPin(GSTImpl *This, const PIN_INFO *piOutput, const AM_MEDIA_TYPE *amt) {
1546 HRESULT hr;
1547 This->ppPins = CoTaskMemRealloc(This->ppPins, (This->cStreams + 1) * sizeof(IPin *));
1549 hr = BaseOutputPin_Construct(&GST_OutputPin_Vtbl, sizeof(GSTOutPin), piOutput, &output_BaseFuncTable, &output_BaseOutputFuncTable, &This->filter.csFilter, (IPin**)(This->ppPins + This->cStreams));
1550 if (SUCCEEDED(hr)) {
1551 GSTOutPin *pin = This->ppPins[This->cStreams];
1552 pin->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
1553 CopyMediaType(pin->pmt, amt);
1554 pin->pin.pin.pinInfo.pFilter = (LPVOID)This;
1555 pin->caps_event = CreateEventW(NULL, 0, 0, NULL);
1556 pin->segment = gst_segment_new();
1557 This->cStreams++;
1558 QualityControlImpl_init(&pin->qcimpl, NULL, (IBaseFilter*)pin);
1559 pin->qcimpl.lpVtbl = &GSTOutPin_QualityControl_Vtbl;
1560 SourceSeeking_Init(&pin->seek, &GST_Seeking_Vtbl, GST_ChangeStop, GST_ChangeCurrent, GST_ChangeRate, &This->filter.csFilter);
1561 BaseFilterImpl_IncrementPinVersion((BaseFilter*)This);
1562 } else
1563 ERR("Failed with error %x\n", hr);
1564 return hr;
1567 static HRESULT GST_RemoveOutputPins(GSTImpl *This) {
1568 HRESULT hr;
1569 ULONG i;
1570 GSTOutPin **ppOldPins = This->ppPins;
1571 TRACE("(%p)\n", This);
1573 if (!This->gstfilter)
1574 return S_OK;
1575 gst_element_set_bus(This->gstfilter, NULL);
1576 gst_element_set_state(This->gstfilter, GST_STATE_NULL);
1577 gst_pad_unlink(This->my_src, This->their_sink);
1578 if (This->push_thread)
1579 gst_pad_activate_push(This->my_src, 0);
1580 gst_object_unref(This->my_src);
1581 This->my_src = This->their_sink = NULL;
1583 for (i = 0; i < This->cStreams; i++) {
1584 hr = BaseOutputPinImpl_BreakConnect(&ppOldPins[i]->pin);
1585 TRACE("Disconnect: %08x\n", hr);
1586 IPin_Release((IPin*)ppOldPins[i]);
1588 This->cStreams = 0;
1589 This->ppPins = NULL;
1590 gst_object_unref(This->gstfilter);
1591 This->gstfilter = NULL;
1592 BaseFilterImpl_IncrementPinVersion((BaseFilter*)This);
1593 CoTaskMemFree(ppOldPins);
1594 return S_OK;
1597 static ULONG WINAPI GSTInPin_Release(IPin *iface) {
1598 GSTInPin *This = (GSTInPin*)iface;
1599 ULONG refCount = InterlockedDecrement(&This->pin.refCount);
1601 TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
1602 if (!refCount) {
1603 FreeMediaType(&This->pin.mtCurrent);
1604 if (This->pAlloc)
1605 IMemAllocator_Release(This->pAlloc);
1606 This->pAlloc = NULL;
1607 This->pin.lpVtbl = NULL;
1608 return 0;
1609 } else
1610 return refCount;
1613 static HRESULT WINAPI GSTInPin_ReceiveConnection(IPin *iface, IPin *pReceivePin, const AM_MEDIA_TYPE *pmt) {
1614 PIN_DIRECTION pindirReceive;
1615 HRESULT hr = S_OK;
1616 GSTInPin *This = (GSTInPin*)iface;
1618 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pReceivePin, pmt);
1619 dump_AM_MEDIA_TYPE(pmt);
1621 EnterCriticalSection(This->pin.pCritSec);
1622 if (!This->pin.pConnectedTo) {
1623 ALLOCATOR_PROPERTIES props;
1625 props.cBuffers = 8;
1626 props.cbBuffer = 16384;
1627 props.cbAlign = 1;
1628 props.cbPrefix = 0;
1630 if (SUCCEEDED(hr) && IPin_QueryAccept(iface, pmt) != S_OK)
1631 hr = VFW_E_TYPE_NOT_ACCEPTED;
1632 if (SUCCEEDED(hr)) {
1633 IPin_QueryDirection(pReceivePin, &pindirReceive);
1634 if (pindirReceive != PINDIR_OUTPUT) {
1635 ERR("Can't connect from non-output pin\n");
1636 hr = VFW_E_INVALID_DIRECTION;
1640 This->pReader = NULL;
1641 This->pAlloc = NULL;
1642 if (SUCCEEDED(hr))
1643 hr = IPin_QueryInterface(pReceivePin, &IID_IAsyncReader, (LPVOID *)&This->pReader);
1644 if (SUCCEEDED(hr))
1645 hr = GST_Connect(This, pReceivePin, &props);
1646 if (SUCCEEDED(hr))
1647 hr = IAsyncReader_RequestAllocator(This->pReader, NULL, &props, &This->pAlloc);
1648 if (SUCCEEDED(hr)) {
1649 CopyMediaType(&This->pin.mtCurrent, pmt);
1650 This->pin.pConnectedTo = pReceivePin;
1651 IPin_AddRef(pReceivePin);
1652 hr = IMemAllocator_Commit(This->pAlloc);
1653 } else {
1654 GST_RemoveOutputPins((GSTImpl *)This->pin.pinInfo.pFilter);
1655 if (This->pReader)
1656 IAsyncReader_Release(This->pReader);
1657 This->pReader = NULL;
1658 if (This->pAlloc)
1659 IMemAllocator_Release(This->pAlloc);
1660 This->pAlloc = NULL;
1662 TRACE("Size: %i\n", props.cbBuffer);
1663 } else
1664 hr = VFW_E_ALREADY_CONNECTED;
1665 LeaveCriticalSection(This->pin.pCritSec);
1666 return hr;
1669 static HRESULT WINAPI GSTInPin_Disconnect(IPin *iface) {
1670 HRESULT hr;
1671 GSTInPin *This = (GSTInPin*)iface;
1672 FILTER_STATE state;
1673 TRACE("()\n");
1675 hr = IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
1676 EnterCriticalSection(This->pin.pCritSec);
1677 if (This->pin.pConnectedTo) {
1678 GSTImpl *Parser = (GSTImpl *)This->pin.pinInfo.pFilter;
1680 if (SUCCEEDED(hr) && state == State_Stopped) {
1681 IMemAllocator_Decommit(This->pAlloc);
1682 IPin_Disconnect(This->pin.pConnectedTo);
1683 This->pin.pConnectedTo = NULL;
1684 hr = GST_RemoveOutputPins(Parser);
1685 } else
1686 hr = VFW_E_NOT_STOPPED;
1687 } else
1688 hr = S_FALSE;
1689 LeaveCriticalSection(This->pin.pCritSec);
1690 return hr;
1693 static HRESULT WINAPI GSTInPin_QueryAccept(IPin *iface, const AM_MEDIA_TYPE *pmt) {
1694 GSTInPin *This = (GSTInPin*)iface;
1696 TRACE("(%p)->(%p)\n", This, pmt);
1697 dump_AM_MEDIA_TYPE(pmt);
1699 if (IsEqualIID(&pmt->majortype, &MEDIATYPE_Stream))
1700 return S_OK;
1701 return S_FALSE;
1704 static HRESULT WINAPI GSTInPin_EndOfStream(IPin *iface) {
1705 GSTInPin *pin = (GSTInPin*)iface;
1706 GSTImpl *This = (GSTImpl*)pin->pin.pinInfo.pFilter;
1708 FIXME("Propagate message on %p\n", This);
1709 return S_OK;
1712 static HRESULT WINAPI GSTInPin_BeginFlush(IPin *iface) {
1713 GSTInPin *pin = (GSTInPin*)iface;
1714 GSTImpl *This = (GSTImpl*)pin->pin.pinInfo.pFilter;
1716 FIXME("Propagate message on %p\n", This);
1717 return S_OK;
1720 static HRESULT WINAPI GSTInPin_EndFlush(IPin *iface) {
1721 GSTInPin *pin = (GSTInPin*)iface;
1722 GSTImpl *This = (GSTImpl*)pin->pin.pinInfo.pFilter;
1724 FIXME("Propagate message on %p\n", This);
1725 return S_OK;
1728 static HRESULT WINAPI GSTInPin_NewSegment(IPin *iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {
1729 GSTInPin *pin = (GSTInPin*)iface;
1730 GSTImpl *This = (GSTImpl*)pin->pin.pinInfo.pFilter;
1732 BasePinImpl_NewSegment(iface, tStart, tStop, dRate);
1733 FIXME("Propagate message on %p\n", This);
1734 return S_OK;
1737 static HRESULT WINAPI GSTInPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
1739 GSTInPin *This = (GSTInPin*)iface;
1741 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
1743 *ppv = NULL;
1745 if (IsEqualIID(riid, &IID_IUnknown))
1746 *ppv = iface;
1747 else if (IsEqualIID(riid, &IID_IPin))
1748 *ppv = iface;
1749 else if (IsEqualIID(riid, &IID_IMediaSeeking))
1751 return IBaseFilter_QueryInterface(This->pin.pinInfo.pFilter, &IID_IMediaSeeking, ppv);
1754 if (*ppv)
1756 IUnknown_AddRef((IUnknown *)(*ppv));
1757 return S_OK;
1760 FIXME("No interface for %s!\n", debugstr_guid(riid));
1762 return E_NOINTERFACE;
1765 static HRESULT WINAPI GSTInPin_EnumMediaTypes(IPin *iface, IEnumMediaTypes **ppEnum)
1767 BasePin *This = (BasePin *)iface;
1769 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
1771 return EnumMediaTypes_Construct(This, BasePinImpl_GetMediaType, BasePinImpl_GetMediaTypeVersion, ppEnum);
1774 static const IPinVtbl GST_InputPin_Vtbl = {
1775 GSTInPin_QueryInterface,
1776 BasePinImpl_AddRef,
1777 GSTInPin_Release,
1778 BaseInputPinImpl_Connect,
1779 GSTInPin_ReceiveConnection,
1780 GSTInPin_Disconnect,
1781 BasePinImpl_ConnectedTo,
1782 BasePinImpl_ConnectionMediaType,
1783 BasePinImpl_QueryPinInfo,
1784 BasePinImpl_QueryDirection,
1785 BasePinImpl_QueryId,
1786 GSTInPin_QueryAccept,
1787 GSTInPin_EnumMediaTypes,
1788 BasePinImpl_QueryInternalConnections,
1789 GSTInPin_EndOfStream,
1790 GSTInPin_BeginFlush,
1791 GSTInPin_EndFlush,
1792 GSTInPin_NewSegment