d3d8: Get rid of the format switching code in d3d8_device_CopyRects().
[wine.git] / dlls / winegstreamer / gstdemux.c
blob4e5f04de7b4d497b73fbb30a0db45548271772c9
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;
76 IQualityControl IQualityControl_iface;
78 GstPad *their_src;
79 GstPad *my_sink;
80 int isaud, isvid;
81 AM_MEDIA_TYPE * pmt;
82 HANDLE caps_event;
83 GstSegment *segment;
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 gboolean 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 FALSE;
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 FALSE;
126 if (!gst_structure_get_int(arg, "rate", (INT*)&wfx->nSamplesPerSec))
127 return FALSE;
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 TRUE;
162 static gboolean 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 FALSE;
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 FALSE;
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 FALSE;
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 FALSE;
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 FALSE;
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 TRUE;
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 gboolean 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 FALSE;
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 FALSE;
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 FALSE;
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 gboolean 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 FALSE;
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 FALSE;
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 FALSE;
291 TRACE("Linking returned %i for %s\n", ret, typename);
292 if (!ret)
293 return FALSE;
294 FreeMediaType(pin->pmt);
295 *pin->pmt = amt;
296 return TRUE;
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 FALSE;
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 TRUE;
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 TRUE;
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 TRUE;
397 case GST_EVENT_EOS:
398 if (pin->pin.pin.pConnectedTo)
399 IPin_EndOfStream(pin->pin.pin.pConnectedTo);
400 return TRUE;
401 case GST_EVENT_FLUSH_START:
402 if (pin->pin.pin.pConnectedTo)
403 IPin_BeginFlush(pin->pin.pin.pConnectedTo);
404 return TRUE;
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 TRUE;
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 TRACE("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 TRACE("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 TRACE("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 TRUE;
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 TRUE;
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 FALSE;
824 gst_query_set_seeking(query, GST_FORMAT_BYTES, 1, 0, This->filesize);
825 return TRUE;
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 FALSE;
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 TRUE;
861 static void no_more_pads(GstElement *decodebin, GSTImpl *This) {
862 TRACE("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 = TRUE;
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 = FALSE;
996 This->nextofs = This->nextpullofs = 0;
997 return hr;
1000 static inline GSTOutPin *impl_from_IMediaSeeking( IMediaSeeking *iface ) {
1001 return CONTAINING_RECORD(iface, GSTOutPin, seek.IMediaSeeking_iface);
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.IPin_iface.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 BaseFilter_Destroy(&This->filter);
1103 CoTaskMemFree(This);
1106 static HRESULT WINAPI GST_QueryInterface(IBaseFilter *iface, REFIID riid, LPVOID *ppv) {
1107 GSTImpl *This = (GSTImpl *)iface;
1108 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1110 *ppv = NULL;
1112 if (IsEqualIID(riid, &IID_IUnknown))
1113 *ppv = This;
1114 else if (IsEqualIID(riid, &IID_IPersist))
1115 *ppv = This;
1116 else if (IsEqualIID(riid, &IID_IMediaFilter))
1117 *ppv = This;
1118 else if (IsEqualIID(riid, &IID_IBaseFilter))
1119 *ppv = This;
1121 if (*ppv) {
1122 IUnknown_AddRef((IUnknown *)(*ppv));
1123 return S_OK;
1126 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow) &&
1127 !IsEqualIID(riid, &IID_IAMFilterMiscFlags))
1128 FIXME("No interface for %s!\n", debugstr_guid(riid));
1130 return E_NOINTERFACE;
1133 static ULONG WINAPI GST_Release(IBaseFilter *iface) {
1134 GSTImpl *This = (GSTImpl *)iface;
1135 ULONG refCount = InterlockedDecrement(&This->filter.refCount);
1137 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
1139 if (!refCount)
1140 GST_Destroy(This);
1142 return refCount;
1145 static HRESULT WINAPI GST_Stop(IBaseFilter *iface) {
1146 GSTImpl *This = (GSTImpl *)iface;
1148 TRACE("()\n");
1150 if (This->gstfilter)
1151 gst_element_set_state(This->gstfilter, GST_STATE_READY);
1152 return S_OK;
1155 static HRESULT WINAPI GST_Pause(IBaseFilter *iface) {
1156 HRESULT hr = S_OK;
1157 GSTImpl *This = (GSTImpl *)iface;
1158 GstState now;
1159 GstStateChangeReturn ret;
1160 TRACE("()\n");
1162 if (!This->gstfilter)
1163 return VFW_E_NOT_CONNECTED;
1165 gst_element_get_state(This->gstfilter, &now, NULL, -1);
1166 if (now == GST_STATE_PAUSED)
1167 return S_OK;
1168 if (now != GST_STATE_PLAYING)
1169 hr = IBaseFilter_Run(iface, -1);
1170 if (FAILED(hr))
1171 return hr;
1172 ret = gst_element_set_state(This->gstfilter, GST_STATE_PAUSED);
1173 if (ret == GST_STATE_CHANGE_ASYNC)
1174 hr = S_FALSE;
1175 return hr;
1178 static HRESULT WINAPI GST_Run(IBaseFilter *iface, REFERENCE_TIME tStart) {
1179 HRESULT hr = S_OK;
1180 GSTImpl *This = (GSTImpl *)iface;
1181 ULONG i;
1182 GstState now;
1183 HRESULT hr_any = VFW_E_NOT_CONNECTED;
1185 TRACE("(%s)\n", wine_dbgstr_longlong(tStart));
1187 if (!This->gstfilter)
1188 return VFW_E_NOT_CONNECTED;
1190 EnterCriticalSection(&This->filter.csFilter);
1191 This->filter.rtStreamStart = tStart;
1192 LeaveCriticalSection(&This->filter.csFilter);
1194 gst_element_get_state(This->gstfilter, &now, NULL, -1);
1195 if (now == GST_STATE_PLAYING)
1196 return S_OK;
1197 if (now == GST_STATE_PAUSED) {
1198 GstStateChangeReturn ret;
1199 ret = gst_element_set_state(This->gstfilter, GST_STATE_PLAYING);
1200 if (ret == GST_STATE_CHANGE_ASYNC)
1201 return S_FALSE;
1202 return S_OK;
1205 EnterCriticalSection(&This->filter.csFilter);
1206 gst_pad_set_blocked(This->my_src, 0);
1207 gst_pad_set_blocked(This->their_sink, 0);
1208 gst_element_set_state(This->gstfilter, GST_STATE_PLAYING);
1209 This->filter.rtStreamStart = tStart;
1211 for (i = 0; i < This->cStreams; i++) {
1212 hr = BaseOutputPinImpl_Active((BaseOutputPin *)This->ppPins[i]);
1213 if (SUCCEEDED(hr)) {
1214 gst_pad_set_blocked(This->ppPins[i]->my_sink, 0);
1215 if (This->ppPins[i]->their_src)
1216 gst_pad_set_blocked(This->ppPins[i]->their_src, 0);
1217 hr_any = hr;
1220 hr = hr_any;
1221 if (SUCCEEDED(hr))
1222 gst_pad_set_active(This->my_src, 1);
1223 LeaveCriticalSection(&This->filter.csFilter);
1225 return hr;
1228 static HRESULT WINAPI GST_GetState(IBaseFilter *iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState) {
1229 GSTImpl *This = (GSTImpl *)iface;
1230 HRESULT hr = S_OK;
1231 GstState now, pending;
1232 GstStateChangeReturn ret;
1234 TRACE("(%d, %p)\n", dwMilliSecsTimeout, pState);
1236 if (!This->gstfilter) {
1237 *pState = State_Stopped;
1238 return S_OK;
1241 ret = gst_element_get_state(This->gstfilter, &now, &pending, dwMilliSecsTimeout == INFINITE ? -1 : dwMilliSecsTimeout * 1000);
1243 if (ret == GST_STATE_CHANGE_ASYNC)
1244 hr = VFW_S_STATE_INTERMEDIATE;
1245 else
1246 pending = now;
1248 switch (pending) {
1249 case GST_STATE_PAUSED: *pState = State_Paused; return hr;
1250 case GST_STATE_PLAYING: *pState = State_Running; return hr;
1251 default: *pState = State_Stopped; return hr;
1255 static HRESULT WINAPI GST_FindPin(IBaseFilter *iface, LPCWSTR Id, IPin **ppPin) {
1256 FIXME("(%p)->(%s,%p) stub\n", iface, debugstr_w(Id), ppPin);
1257 return E_NOTIMPL;
1260 static const IBaseFilterVtbl GST_Vtbl = {
1261 GST_QueryInterface,
1262 BaseFilterImpl_AddRef,
1263 GST_Release,
1264 BaseFilterImpl_GetClassID,
1265 GST_Stop,
1266 GST_Pause,
1267 GST_Run,
1268 GST_GetState,
1269 BaseFilterImpl_SetSyncSource,
1270 BaseFilterImpl_GetSyncSource,
1271 BaseFilterImpl_EnumPins,
1272 GST_FindPin,
1273 BaseFilterImpl_QueryFilterInfo,
1274 BaseFilterImpl_JoinFilterGraph,
1275 BaseFilterImpl_QueryVendorInfo
1278 static HRESULT WINAPI GST_ChangeCurrent(IMediaSeeking *iface) {
1279 return S_OK;
1282 static HRESULT WINAPI GST_ChangeStop(IMediaSeeking *iface) {
1283 return S_OK;
1286 static HRESULT WINAPI GST_ChangeRate(IMediaSeeking *iface) {
1287 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1288 GstEvent *ev = gst_event_new_seek(This->seek.dRate, GST_FORMAT_TIME, 0, GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_NONE, -1);
1289 TRACE("(%p) New rate %g\n", iface, This->seek.dRate);
1290 gst_pad_push_event(This->my_sink, ev);
1291 return S_OK;
1294 static HRESULT WINAPI GST_Seeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppv) {
1295 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1296 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
1299 static ULONG WINAPI GST_Seeking_AddRef(IMediaSeeking *iface) {
1300 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1301 return IUnknown_AddRef((IUnknown *)This);
1304 static ULONG WINAPI GST_Seeking_Release(IMediaSeeking *iface) {
1305 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1306 return IUnknown_Release((IUnknown *)This);
1309 static HRESULT WINAPI GST_Seeking_GetCurrentPosition(IMediaSeeking *iface, REFERENCE_TIME *pos) {
1310 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1311 GstFormat format = GST_FORMAT_TIME;
1313 if (!pos)
1314 return E_POINTER;
1316 if (!This->their_src) {
1317 *pos = This->seek.llCurrent;
1318 TRACE("Cached value\n");
1319 if (This->seek.llDuration)
1320 return S_OK;
1321 else
1322 return E_NOTIMPL;
1325 if (!gst_pad_query_position(This->their_src, &format, pos)) {
1326 WARN("Could not query position\n");
1327 return E_NOTIMPL;
1329 *pos /= 100;
1330 This->seek.llCurrent = *pos;
1331 return S_OK;
1334 static GstSeekType type_from_flags(DWORD flags) {
1335 switch (flags & AM_SEEKING_PositioningBitsMask) {
1336 case AM_SEEKING_NoPositioning: return GST_SEEK_TYPE_NONE;
1337 case AM_SEEKING_AbsolutePositioning: return GST_SEEK_TYPE_SET;
1338 case AM_SEEKING_RelativePositioning: return GST_SEEK_TYPE_CUR;
1339 case AM_SEEKING_IncrementalPositioning: return GST_SEEK_TYPE_END;
1341 return GST_SEEK_TYPE_NONE;
1345 static HRESULT WINAPI GST_Seeking_SetPositions(IMediaSeeking *iface, REFERENCE_TIME *pCur, DWORD curflags, REFERENCE_TIME *pStop, DWORD stopflags) {
1346 HRESULT hr;
1347 GSTOutPin *This = impl_from_IMediaSeeking(iface);
1348 GstSeekFlags f = 0;
1349 GstSeekType curtype, stoptype;
1350 GstEvent *e;
1352 if (!This->seek.llDuration)
1353 return E_NOTIMPL;
1355 hr = SourceSeekingImpl_SetPositions(iface, pCur, curflags, pStop, stopflags);
1356 if (!This->their_src)
1357 return hr;
1359 curtype = type_from_flags(curflags);
1360 stoptype = type_from_flags(stopflags);
1361 if (curflags & AM_SEEKING_SeekToKeyFrame)
1362 f |= GST_SEEK_FLAG_KEY_UNIT;
1363 if (curflags & AM_SEEKING_Segment)
1364 f |= GST_SEEK_FLAG_SEGMENT;
1365 if (!(curflags & AM_SEEKING_NoFlush))
1366 f |= GST_SEEK_FLAG_FLUSH;
1368 e = gst_event_new_seek(This->seek.dRate, GST_FORMAT_TIME, f, curtype, pCur ? *pCur * 100 : -1, stoptype, pStop ? *pStop * 100 : -1);
1369 if (gst_pad_push_event(This->my_sink, e))
1370 return S_OK;
1371 else
1372 return E_NOTIMPL;
1375 static const IMediaSeekingVtbl GST_Seeking_Vtbl =
1377 GST_Seeking_QueryInterface,
1378 GST_Seeking_AddRef,
1379 GST_Seeking_Release,
1380 SourceSeekingImpl_GetCapabilities,
1381 SourceSeekingImpl_CheckCapabilities,
1382 SourceSeekingImpl_IsFormatSupported,
1383 SourceSeekingImpl_QueryPreferredFormat,
1384 SourceSeekingImpl_GetTimeFormat,
1385 SourceSeekingImpl_IsUsingTimeFormat,
1386 SourceSeekingImpl_SetTimeFormat,
1387 SourceSeekingImpl_GetDuration,
1388 SourceSeekingImpl_GetStopPosition,
1389 GST_Seeking_GetCurrentPosition,
1390 SourceSeekingImpl_ConvertTimeFormat,
1391 GST_Seeking_SetPositions,
1392 SourceSeekingImpl_GetPositions,
1393 SourceSeekingImpl_GetAvailable,
1394 SourceSeekingImpl_SetRate,
1395 SourceSeekingImpl_GetRate,
1396 SourceSeekingImpl_GetPreroll
1399 static inline GSTOutPin *impl_from_IQualityControl( IQualityControl *iface )
1401 return (GSTOutPin*)CONTAINING_RECORD(iface, GSTOutPin, IQualityControl_iface);
1404 static HRESULT WINAPI GST_QualityControl_QueryInterface(IQualityControl *iface, REFIID riid, void **ppv)
1406 GSTOutPin *pin = impl_from_IQualityControl(iface);
1407 return IPin_QueryInterface((IPin*)pin, riid, ppv);
1410 static ULONG WINAPI GST_QualityControl_AddRef(IQualityControl *iface)
1412 GSTOutPin *pin = impl_from_IQualityControl(iface);
1413 return IPin_AddRef((IPin*)pin);
1416 static ULONG WINAPI GST_QualityControl_Release(IQualityControl *iface)
1418 GSTOutPin *pin = impl_from_IQualityControl(iface);
1419 return IPin_Release((IPin*)pin);
1422 static HRESULT WINAPI GST_QualityControl_Notify(IQualityControl *iface, IBaseFilter *sender, Quality qm) {
1423 GSTOutPin *pin = impl_from_IQualityControl(iface);
1424 REFERENCE_TIME late = qm.Late;
1425 if (qm.Late < 0 && -qm.Late > qm.TimeStamp)
1426 late = -qm.TimeStamp;
1427 gst_pad_push_event(pin->my_sink, gst_event_new_qos(1000./qm.Proportion, late*100, qm.TimeStamp*100));
1428 return S_OK;
1431 static HRESULT WINAPI GST_QualityControl_SetSink(IQualityControl *iface, IQualityControl *tonotify)
1433 /* Do nothing */
1434 return S_OK;
1437 static const IQualityControlVtbl GSTOutPin_QualityControl_Vtbl = {
1438 GST_QualityControl_QueryInterface,
1439 GST_QualityControl_AddRef,
1440 GST_QualityControl_Release,
1441 GST_QualityControl_Notify,
1442 GST_QualityControl_SetSink
1445 static HRESULT WINAPI GSTOutPin_QueryInterface(IPin *iface, REFIID riid, void **ppv) {
1446 GSTOutPin *This = (GSTOutPin *)iface;
1448 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
1450 *ppv = NULL;
1452 if (IsEqualIID(riid, &IID_IUnknown))
1453 *ppv = iface;
1454 else if (IsEqualIID(riid, &IID_IPin))
1455 *ppv = iface;
1456 else if (IsEqualIID(riid, &IID_IMediaSeeking))
1457 *ppv = &This->seek;
1458 else if (IsEqualIID(riid, &IID_IQualityControl))
1459 *ppv = &This->IQualityControl_iface;
1461 if (*ppv) {
1462 IUnknown_AddRef((IUnknown *)(*ppv));
1463 return S_OK;
1465 FIXME("No interface for %s!\n", debugstr_guid(riid));
1466 return E_NOINTERFACE;
1469 static ULONG WINAPI GSTOutPin_Release(IPin *iface) {
1470 GSTOutPin *This = (GSTOutPin *)iface;
1471 ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
1472 TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
1474 if (!refCount) {
1475 if (This->their_src)
1476 gst_pad_unlink(This->their_src, This->my_sink);
1477 gst_object_unref(This->my_sink);
1478 CloseHandle(This->caps_event);
1479 DeleteMediaType(This->pmt);
1480 FreeMediaType(&This->pin.pin.mtCurrent);
1481 gst_segment_free(This->segment);
1482 if (This->pin.pAllocator)
1483 IMemAllocator_Release(This->pin.pAllocator);
1484 CoTaskMemFree(This);
1485 return 0;
1487 return refCount;
1490 static HRESULT WINAPI GSTOutPin_GetMediaType(BasePin *iface, int iPosition, AM_MEDIA_TYPE *pmt)
1492 GSTOutPin *This = (GSTOutPin *)iface;
1494 if (iPosition < 0)
1495 return E_INVALIDARG;
1496 if (iPosition > 0)
1497 return VFW_S_NO_MORE_ITEMS;
1498 CopyMediaType(pmt, This->pmt);
1499 return S_OK;
1502 static HRESULT WINAPI GSTOutPin_DecideBufferSize(BaseOutputPin *iface, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
1504 /* Unused */
1505 return S_OK;
1508 static HRESULT WINAPI GSTOutPin_DecideAllocator(BaseOutputPin *iface, IMemInputPin *pPin, IMemAllocator **pAlloc)
1510 HRESULT hr;
1511 GSTOutPin *This = (GSTOutPin *)iface;
1512 GSTImpl *GSTfilter = (GSTImpl*)This->pin.pin.pinInfo.pFilter;
1514 *pAlloc = NULL;
1515 if (GSTfilter->pInputPin.pAlloc)
1517 hr = IMemInputPin_NotifyAllocator(pPin, GSTfilter->pInputPin.pAlloc, FALSE);
1518 if (SUCCEEDED(hr))
1520 *pAlloc = GSTfilter->pInputPin.pAlloc;
1521 IMemAllocator_AddRef(*pAlloc);
1524 else
1525 hr = VFW_E_NO_ALLOCATOR;
1527 return hr;
1530 static HRESULT WINAPI GSTOutPin_BreakConnect(BaseOutputPin *This)
1532 HRESULT hr;
1534 TRACE("(%p)->()\n", This);
1536 EnterCriticalSection(This->pin.pCritSec);
1537 if (!This->pin.pConnectedTo || !This->pMemInputPin)
1538 hr = VFW_E_NOT_CONNECTED;
1539 else
1541 hr = IPin_Disconnect(This->pin.pConnectedTo);
1542 IPin_Disconnect((IPin *)This);
1544 LeaveCriticalSection(This->pin.pCritSec);
1546 return hr;
1549 static const IPinVtbl GST_OutputPin_Vtbl = {
1550 GSTOutPin_QueryInterface,
1551 BasePinImpl_AddRef,
1552 GSTOutPin_Release,
1553 BaseOutputPinImpl_Connect,
1554 BaseOutputPinImpl_ReceiveConnection,
1555 BaseOutputPinImpl_Disconnect,
1556 BasePinImpl_ConnectedTo,
1557 BasePinImpl_ConnectionMediaType,
1558 BasePinImpl_QueryPinInfo,
1559 BasePinImpl_QueryDirection,
1560 BasePinImpl_QueryId,
1561 GST_OutPin_QueryAccept,
1562 BasePinImpl_EnumMediaTypes,
1563 BasePinImpl_QueryInternalConnections,
1564 BaseOutputPinImpl_EndOfStream,
1565 BaseOutputPinImpl_BeginFlush,
1566 BaseOutputPinImpl_EndFlush,
1567 BasePinImpl_NewSegment
1570 static const BaseOutputPinFuncTable output_BaseOutputFuncTable = {
1572 NULL,
1573 BaseOutputPinImpl_AttemptConnection,
1574 BasePinImpl_GetMediaTypeVersion,
1575 GSTOutPin_GetMediaType
1577 GSTOutPin_DecideBufferSize,
1578 GSTOutPin_DecideAllocator,
1579 GSTOutPin_BreakConnect
1582 static HRESULT GST_AddPin(GSTImpl *This, const PIN_INFO *piOutput, const AM_MEDIA_TYPE *amt) {
1583 HRESULT hr;
1584 This->ppPins = CoTaskMemRealloc(This->ppPins, (This->cStreams + 1) * sizeof(IPin *));
1586 hr = BaseOutputPin_Construct(&GST_OutputPin_Vtbl, sizeof(GSTOutPin), piOutput, &output_BaseOutputFuncTable, &This->filter.csFilter, (IPin**)(This->ppPins + This->cStreams));
1587 if (SUCCEEDED(hr)) {
1588 GSTOutPin *pin = This->ppPins[This->cStreams];
1589 pin->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
1590 CopyMediaType(pin->pmt, amt);
1591 pin->pin.pin.pinInfo.pFilter = (LPVOID)This;
1592 pin->caps_event = CreateEventW(NULL, 0, 0, NULL);
1593 pin->segment = gst_segment_new();
1594 This->cStreams++;
1595 pin->IQualityControl_iface.lpVtbl = &GSTOutPin_QualityControl_Vtbl;
1596 SourceSeeking_Init(&pin->seek, &GST_Seeking_Vtbl, GST_ChangeStop, GST_ChangeCurrent, GST_ChangeRate, &This->filter.csFilter);
1597 BaseFilterImpl_IncrementPinVersion((BaseFilter*)This);
1598 } else
1599 ERR("Failed with error %x\n", hr);
1600 return hr;
1603 static HRESULT GST_RemoveOutputPins(GSTImpl *This) {
1604 HRESULT hr;
1605 ULONG i;
1606 GSTOutPin **ppOldPins = This->ppPins;
1607 TRACE("(%p)\n", This);
1609 if (!This->gstfilter)
1610 return S_OK;
1611 gst_element_set_bus(This->gstfilter, NULL);
1612 gst_element_set_state(This->gstfilter, GST_STATE_NULL);
1613 gst_pad_unlink(This->my_src, This->their_sink);
1614 if (This->push_thread)
1615 gst_pad_activate_push(This->my_src, 0);
1616 gst_object_unref(This->my_src);
1617 This->my_src = This->their_sink = NULL;
1619 for (i = 0; i < This->cStreams; i++) {
1620 hr = BaseOutputPinImpl_BreakConnect(&ppOldPins[i]->pin);
1621 TRACE("Disconnect: %08x\n", hr);
1622 IPin_Release((IPin*)ppOldPins[i]);
1624 This->cStreams = 0;
1625 This->ppPins = NULL;
1626 gst_object_unref(This->gstfilter);
1627 This->gstfilter = NULL;
1628 BaseFilterImpl_IncrementPinVersion((BaseFilter*)This);
1629 CoTaskMemFree(ppOldPins);
1630 return S_OK;
1633 static ULONG WINAPI GSTInPin_Release(IPin *iface) {
1634 GSTInPin *This = (GSTInPin*)iface;
1635 ULONG refCount = InterlockedDecrement(&This->pin.refCount);
1637 TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
1638 if (!refCount) {
1639 FreeMediaType(&This->pin.mtCurrent);
1640 if (This->pAlloc)
1641 IMemAllocator_Release(This->pAlloc);
1642 This->pAlloc = NULL;
1643 This->pin.IPin_iface.lpVtbl = NULL;
1644 return 0;
1645 } else
1646 return refCount;
1649 static HRESULT WINAPI GSTInPin_ReceiveConnection(IPin *iface, IPin *pReceivePin, const AM_MEDIA_TYPE *pmt) {
1650 PIN_DIRECTION pindirReceive;
1651 HRESULT hr = S_OK;
1652 GSTInPin *This = (GSTInPin*)iface;
1654 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pReceivePin, pmt);
1655 dump_AM_MEDIA_TYPE(pmt);
1657 EnterCriticalSection(This->pin.pCritSec);
1658 if (!This->pin.pConnectedTo) {
1659 ALLOCATOR_PROPERTIES props;
1661 props.cBuffers = 8;
1662 props.cbBuffer = 16384;
1663 props.cbAlign = 1;
1664 props.cbPrefix = 0;
1666 if (SUCCEEDED(hr) && IPin_QueryAccept(iface, pmt) != S_OK)
1667 hr = VFW_E_TYPE_NOT_ACCEPTED;
1668 if (SUCCEEDED(hr)) {
1669 IPin_QueryDirection(pReceivePin, &pindirReceive);
1670 if (pindirReceive != PINDIR_OUTPUT) {
1671 ERR("Can't connect from non-output pin\n");
1672 hr = VFW_E_INVALID_DIRECTION;
1676 This->pReader = NULL;
1677 This->pAlloc = NULL;
1678 if (SUCCEEDED(hr))
1679 hr = IPin_QueryInterface(pReceivePin, &IID_IAsyncReader, (LPVOID *)&This->pReader);
1680 if (SUCCEEDED(hr))
1681 hr = GST_Connect(This, pReceivePin, &props);
1682 if (SUCCEEDED(hr))
1683 hr = IAsyncReader_RequestAllocator(This->pReader, NULL, &props, &This->pAlloc);
1684 if (SUCCEEDED(hr)) {
1685 CopyMediaType(&This->pin.mtCurrent, pmt);
1686 This->pin.pConnectedTo = pReceivePin;
1687 IPin_AddRef(pReceivePin);
1688 hr = IMemAllocator_Commit(This->pAlloc);
1689 } else {
1690 GST_RemoveOutputPins((GSTImpl *)This->pin.pinInfo.pFilter);
1691 if (This->pReader)
1692 IAsyncReader_Release(This->pReader);
1693 This->pReader = NULL;
1694 if (This->pAlloc)
1695 IMemAllocator_Release(This->pAlloc);
1696 This->pAlloc = NULL;
1698 TRACE("Size: %i\n", props.cbBuffer);
1699 } else
1700 hr = VFW_E_ALREADY_CONNECTED;
1701 LeaveCriticalSection(This->pin.pCritSec);
1702 return hr;
1705 static HRESULT WINAPI GSTInPin_Disconnect(IPin *iface) {
1706 HRESULT hr;
1707 GSTInPin *This = (GSTInPin*)iface;
1708 FILTER_STATE state;
1709 TRACE("()\n");
1711 hr = IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
1712 EnterCriticalSection(This->pin.pCritSec);
1713 if (This->pin.pConnectedTo) {
1714 GSTImpl *Parser = (GSTImpl *)This->pin.pinInfo.pFilter;
1716 if (SUCCEEDED(hr) && state == State_Stopped) {
1717 IMemAllocator_Decommit(This->pAlloc);
1718 IPin_Disconnect(This->pin.pConnectedTo);
1719 This->pin.pConnectedTo = NULL;
1720 hr = GST_RemoveOutputPins(Parser);
1721 } else
1722 hr = VFW_E_NOT_STOPPED;
1723 } else
1724 hr = S_FALSE;
1725 LeaveCriticalSection(This->pin.pCritSec);
1726 return hr;
1729 static HRESULT WINAPI GSTInPin_QueryAccept(IPin *iface, const AM_MEDIA_TYPE *pmt) {
1730 GSTInPin *This = (GSTInPin*)iface;
1732 TRACE("(%p)->(%p)\n", This, pmt);
1733 dump_AM_MEDIA_TYPE(pmt);
1735 if (IsEqualIID(&pmt->majortype, &MEDIATYPE_Stream))
1736 return S_OK;
1737 return S_FALSE;
1740 static HRESULT WINAPI GSTInPin_EndOfStream(IPin *iface) {
1741 GSTInPin *pin = (GSTInPin*)iface;
1742 GSTImpl *This = (GSTImpl*)pin->pin.pinInfo.pFilter;
1744 FIXME("Propagate message on %p\n", This);
1745 return S_OK;
1748 static HRESULT WINAPI GSTInPin_BeginFlush(IPin *iface) {
1749 GSTInPin *pin = (GSTInPin*)iface;
1750 GSTImpl *This = (GSTImpl*)pin->pin.pinInfo.pFilter;
1752 FIXME("Propagate message on %p\n", This);
1753 return S_OK;
1756 static HRESULT WINAPI GSTInPin_EndFlush(IPin *iface) {
1757 GSTInPin *pin = (GSTInPin*)iface;
1758 GSTImpl *This = (GSTImpl*)pin->pin.pinInfo.pFilter;
1760 FIXME("Propagate message on %p\n", This);
1761 return S_OK;
1764 static HRESULT WINAPI GSTInPin_NewSegment(IPin *iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {
1765 GSTInPin *pin = (GSTInPin*)iface;
1766 GSTImpl *This = (GSTImpl*)pin->pin.pinInfo.pFilter;
1768 BasePinImpl_NewSegment(iface, tStart, tStop, dRate);
1769 FIXME("Propagate message on %p\n", This);
1770 return S_OK;
1773 static HRESULT WINAPI GSTInPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
1775 GSTInPin *This = (GSTInPin*)iface;
1777 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
1779 *ppv = NULL;
1781 if (IsEqualIID(riid, &IID_IUnknown))
1782 *ppv = iface;
1783 else if (IsEqualIID(riid, &IID_IPin))
1784 *ppv = iface;
1785 else if (IsEqualIID(riid, &IID_IMediaSeeking))
1787 return IBaseFilter_QueryInterface(This->pin.pinInfo.pFilter, &IID_IMediaSeeking, ppv);
1790 if (*ppv)
1792 IUnknown_AddRef((IUnknown *)(*ppv));
1793 return S_OK;
1796 FIXME("No interface for %s!\n", debugstr_guid(riid));
1798 return E_NOINTERFACE;
1801 static HRESULT WINAPI GSTInPin_EnumMediaTypes(IPin *iface, IEnumMediaTypes **ppEnum)
1803 BasePin *This = (BasePin *)iface;
1805 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
1807 return EnumMediaTypes_Construct(This, BasePinImpl_GetMediaType, BasePinImpl_GetMediaTypeVersion, ppEnum);
1810 static const IPinVtbl GST_InputPin_Vtbl = {
1811 GSTInPin_QueryInterface,
1812 BasePinImpl_AddRef,
1813 GSTInPin_Release,
1814 BaseInputPinImpl_Connect,
1815 GSTInPin_ReceiveConnection,
1816 GSTInPin_Disconnect,
1817 BasePinImpl_ConnectedTo,
1818 BasePinImpl_ConnectionMediaType,
1819 BasePinImpl_QueryPinInfo,
1820 BasePinImpl_QueryDirection,
1821 BasePinImpl_QueryId,
1822 GSTInPin_QueryAccept,
1823 GSTInPin_EnumMediaTypes,
1824 BasePinImpl_QueryInternalConnections,
1825 GSTInPin_EndOfStream,
1826 GSTInPin_BeginFlush,
1827 GSTInPin_EndFlush,
1828 GSTInPin_NewSegment