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
25 #include <gst/video/video.h>
26 #include <gst/audio/audio.h>
28 #include "gst_private.h"
29 #include "gst_guids.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(gstreamer
);
48 static pthread_key_t wine_gst_key
;
50 typedef struct GSTOutPin GSTOutPin
;
51 typedef struct GSTInPin
{
53 IAsyncReader
*pReader
;
54 IMemAllocator
*pAlloc
;
57 typedef struct GSTImpl
{
66 BOOL discont
, initial
, ignore_flush
;
67 GstElement
*container
;
68 GstPad
*my_src
, *their_sink
;
70 guint64 start
, nextofs
, nextpullofs
, stop
;
71 ALLOCATOR_PROPERTIES props
;
72 HANDLE event
, changed_ofs
;
79 IQualityControl IQualityControl_iface
;
81 GstElement
*flipfilter
;
82 GstPad
*flip_sink
, *flip_src
;
85 GstBufferPool
*gstpool
;
93 const char* media_quark_string
= "media-sample";
95 static const WCHAR wcsInputPinName
[] = {'i','n','p','u','t',' ','p','i','n',0};
96 static const IMediaSeekingVtbl GST_Seeking_Vtbl
;
97 static const IPinVtbl GST_OutputPin_Vtbl
;
98 static const IPinVtbl GST_InputPin_Vtbl
;
99 static const IBaseFilterVtbl GST_Vtbl
;
100 static const IQualityControlVtbl GSTOutPin_QualityControl_Vtbl
;
102 static HRESULT
GST_AddPin(GSTImpl
*This
, const PIN_INFO
*piOutput
, const AM_MEDIA_TYPE
*amt
);
103 static HRESULT
GST_RemoveOutputPins(GSTImpl
*This
);
104 static HRESULT WINAPI
GST_ChangeCurrent(IMediaSeeking
*iface
);
105 static HRESULT WINAPI
GST_ChangeStop(IMediaSeeking
*iface
);
106 static HRESULT WINAPI
GST_ChangeRate(IMediaSeeking
*iface
);
108 void mark_wine_thread(void)
110 /* set it to non-NULL to indicate that this is a Wine thread */
111 pthread_setspecific(wine_gst_key
, &wine_gst_key
);
114 BOOL
is_wine_thread(void)
116 return pthread_getspecific(wine_gst_key
) != NULL
;
119 static gboolean
amt_from_gst_caps_audio(GstCaps
*caps
, AM_MEDIA_TYPE
*amt
)
121 WAVEFORMATEXTENSIBLE
*wfe
;
126 if (!gst_audio_info_from_caps (&ainfo
, caps
))
129 wfe
= CoTaskMemAlloc(sizeof(*wfe
));
130 wfx
= (WAVEFORMATEX
*)wfe
;
131 amt
->majortype
= MEDIATYPE_Audio
;
132 amt
->subtype
= MEDIASUBTYPE_PCM
;
133 amt
->formattype
= FORMAT_WaveFormatEx
;
134 amt
->pbFormat
= (BYTE
*)wfe
;
135 amt
->cbFormat
= sizeof(*wfe
);
136 amt
->bFixedSizeSamples
= 0;
137 amt
->bTemporalCompression
= 1;
138 amt
->lSampleSize
= 0;
141 wfx
->wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
143 wfx
->nChannels
= ainfo
.channels
;
144 wfx
->nSamplesPerSec
= ainfo
.rate
;
145 depth
= GST_AUDIO_INFO_WIDTH(&ainfo
);
146 bpp
= GST_AUDIO_INFO_DEPTH(&ainfo
);
148 if (!depth
|| depth
> 32 || depth
% 8)
152 wfe
->Samples
.wValidBitsPerSample
= depth
;
153 wfx
->wBitsPerSample
= bpp
;
154 wfx
->cbSize
= sizeof(*wfe
)-sizeof(*wfx
);
155 switch (wfx
->nChannels
) {
156 case 1: wfe
->dwChannelMask
= KSAUDIO_SPEAKER_MONO
; break;
157 case 2: wfe
->dwChannelMask
= KSAUDIO_SPEAKER_STEREO
; break;
158 case 4: wfe
->dwChannelMask
= KSAUDIO_SPEAKER_SURROUND
; break;
159 case 5: wfe
->dwChannelMask
= (KSAUDIO_SPEAKER_5POINT1
& ~SPEAKER_LOW_FREQUENCY
); break;
160 case 6: wfe
->dwChannelMask
= KSAUDIO_SPEAKER_5POINT1
; break;
161 case 8: wfe
->dwChannelMask
= KSAUDIO_SPEAKER_7POINT1
; break;
163 wfe
->dwChannelMask
= 0;
165 if (GST_AUDIO_INFO_IS_FLOAT(&ainfo
)) {
166 wfe
->SubFormat
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
167 wfx
->wBitsPerSample
= wfe
->Samples
.wValidBitsPerSample
= 32;
169 wfe
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
170 if (wfx
->nChannels
<= 2 && bpp
<= 16 && depth
== bpp
) {
171 wfx
->wFormatTag
= WAVE_FORMAT_PCM
;
175 wfx
->nBlockAlign
= wfx
->nChannels
* wfx
->wBitsPerSample
/8;
176 wfx
->nAvgBytesPerSec
= wfx
->nSamplesPerSec
* wfx
->nBlockAlign
;
180 static gboolean
amt_from_gst_caps_video(GstCaps
*caps
, AM_MEDIA_TYPE
*amt
)
182 VIDEOINFOHEADER
*vih
;
183 BITMAPINFOHEADER
*bih
;
184 gint32 width
, height
, nom
, denom
;
187 if (!gst_video_info_from_caps (&vinfo
, caps
))
190 height
= vinfo
.height
;
194 vih
= CoTaskMemAlloc(sizeof(*vih
));
195 bih
= &vih
->bmiHeader
;
197 amt
->formattype
= FORMAT_VideoInfo
;
198 amt
->pbFormat
= (BYTE
*)vih
;
199 amt
->cbFormat
= sizeof(*vih
);
200 amt
->bFixedSizeSamples
= amt
->bTemporalCompression
= 1;
201 amt
->lSampleSize
= 0;
203 ZeroMemory(vih
, sizeof(*vih
));
204 amt
->majortype
= MEDIATYPE_Video
;
205 if (GST_VIDEO_INFO_IS_RGB(&vinfo
)) {
206 bih
->biBitCount
= GST_VIDEO_FORMAT_INFO_BITS(vinfo
.finfo
);
207 switch (bih
->biBitCount
) {
208 case 16: amt
->subtype
= MEDIASUBTYPE_RGB555
; break;
209 case 24: amt
->subtype
= MEDIASUBTYPE_RGB24
; break;
210 case 32: amt
->subtype
= MEDIASUBTYPE_RGB32
; break;
212 FIXME("Unknown bpp %u\n", bih
->biBitCount
);
216 bih
->biCompression
= BI_RGB
;
218 amt
->subtype
= MEDIATYPE_Video
;
219 if (!(amt
->subtype
.Data1
= gst_video_format_to_fourcc(vinfo
.finfo
->format
))) {
223 switch (amt
->subtype
.Data1
) {
224 case mmioFOURCC('I','4','2','0'):
225 case mmioFOURCC('Y','V','1','2'):
226 case mmioFOURCC('N','V','1','2'):
227 case mmioFOURCC('N','V','2','1'):
228 bih
->biBitCount
= 12; break;
229 case mmioFOURCC('Y','U','Y','2'):
230 case mmioFOURCC('Y','V','Y','U'):
231 bih
->biBitCount
= 16; break;
233 bih
->biCompression
= amt
->subtype
.Data1
;
235 bih
->biSizeImage
= width
* height
* bih
->biBitCount
/ 8;
236 if ((vih
->AvgTimePerFrame
= (REFERENCE_TIME
)MulDiv(10000000, denom
, nom
)) == -1)
237 vih
->AvgTimePerFrame
= 0; /* zero division or integer overflow */
238 vih
->rcSource
.left
= 0;
239 vih
->rcSource
.right
= width
;
240 vih
->rcSource
.top
= height
;
241 vih
->rcSource
.bottom
= 0;
242 vih
->rcTarget
= vih
->rcSource
;
243 bih
->biSize
= sizeof(*bih
);
244 bih
->biWidth
= width
;
245 bih
->biHeight
= height
;
250 static gboolean
accept_caps_sink(GstPad
*pad
, GstCaps
*caps
)
252 GSTOutPin
*pin
= gst_pad_get_element_private(pad
);
255 const char *typename
;
258 TRACE("%p %p\n", pad
, caps
);
260 arg
= gst_caps_get_structure(caps
, 0);
261 typename
= gst_structure_get_name(arg
);
262 if (!strcmp(typename
, "audio/x-raw")) {
264 ERR("Setting audio caps on non-audio pad?\n");
267 ret
= amt_from_gst_caps_audio(caps
, &amt
);
272 } else if (!strcmp(typename
, "video/x-raw")) {
274 ERR("Setting video caps on non-video pad?\n");
277 ret
= amt_from_gst_caps_video(caps
, &amt
);
283 FIXME("Unhandled type \"%s\"\n", typename
);
288 static gboolean
setcaps_sink(GstPad
*pad
, GstCaps
*caps
)
290 GSTOutPin
*pin
= gst_pad_get_element_private(pad
);
291 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pin
.pinInfo
.pFilter
;
294 const char *typename
;
297 TRACE("%p %p\n", pad
, caps
);
299 arg
= gst_caps_get_structure(caps
, 0);
300 typename
= gst_structure_get_name(arg
);
301 if (!strcmp(typename
, "audio/x-raw")) {
303 ERR("Setting audio caps on non-audio pad?\n");
306 ret
= amt_from_gst_caps_audio(caps
, &amt
);
307 } else if (!strcmp(typename
, "video/x-raw")) {
309 ERR("Setting video caps on non-video pad?\n");
312 ret
= amt_from_gst_caps_video(caps
, &amt
);
314 This
->props
.cbBuffer
= max(This
->props
.cbBuffer
, ((VIDEOINFOHEADER
*)amt
.pbFormat
)->bmiHeader
.biSizeImage
);
316 FIXME("Unhandled type \"%s\"\n", typename
);
319 TRACE("Linking returned %i for %s\n", ret
, typename
);
322 FreeMediaType(pin
->pmt
);
327 static gboolean
query_sink(GstPad
*pad
, GstObject
*parent
, GstQuery
*query
)
329 switch (GST_QUERY_TYPE (query
)) {
330 case GST_QUERY_ACCEPT_CAPS
:
334 gst_query_parse_accept_caps(query
, &caps
);
335 res
= accept_caps_sink(pad
, caps
);
336 gst_query_set_accept_caps_result(query
, res
);
337 return TRUE
; /* FIXME */
340 return gst_pad_query_default (pad
, parent
, query
);
344 static gboolean
gst_base_src_perform_seek(GSTImpl
*This
, GstEvent
*event
)
348 GstFormat seek_format
;
350 GstSeekType cur_type
, stop_type
;
355 BOOL thread
= !!This
->push_thread
;
357 TRACE("%p %p\n", This
, event
);
359 gst_event_parse_seek(event
, &rate
, &seek_format
, &flags
,
360 &cur_type
, &cur
, &stop_type
, &stop
);
362 if (seek_format
!= GST_FORMAT_BYTES
) {
363 FIXME("Not handling other format %i\n", seek_format
);
367 flush
= flags
& GST_SEEK_FLAG_FLUSH
;
368 seqnum
= gst_event_get_seqnum(event
);
370 /* send flush start */
372 tevent
= gst_event_new_flush_start();
373 gst_event_set_seqnum(tevent
, seqnum
);
374 gst_pad_push_event(This
->my_src
, tevent
);
375 if (This
->pInputPin
.pReader
)
376 IAsyncReader_BeginFlush(This
->pInputPin
.pReader
);
378 gst_pad_set_active(This
->my_src
, 1);
381 This
->nextofs
= This
->start
= cur
;
383 /* and prepare to continue streaming */
385 tevent
= gst_event_new_flush_stop(TRUE
);
386 gst_event_set_seqnum(tevent
, seqnum
);
387 gst_pad_push_event(This
->my_src
, tevent
);
388 if (This
->pInputPin
.pReader
)
389 IAsyncReader_EndFlush(This
->pInputPin
.pReader
);
391 gst_pad_set_active(This
->my_src
, 1);
397 static gboolean
event_src(GstPad
*pad
, GstObject
*parent
, GstEvent
*event
)
399 GSTImpl
*This
= gst_pad_get_element_private(pad
);
401 TRACE("%p %p\n", pad
, event
);
403 switch (event
->type
) {
405 return gst_base_src_perform_seek(This
, event
);
406 case GST_EVENT_FLUSH_START
:
407 EnterCriticalSection(&This
->filter
.csFilter
);
408 if (This
->pInputPin
.pReader
)
409 IAsyncReader_BeginFlush(This
->pInputPin
.pReader
);
410 LeaveCriticalSection(&This
->filter
.csFilter
);
412 case GST_EVENT_FLUSH_STOP
:
413 EnterCriticalSection(&This
->filter
.csFilter
);
414 if (This
->pInputPin
.pReader
)
415 IAsyncReader_EndFlush(This
->pInputPin
.pReader
);
416 LeaveCriticalSection(&This
->filter
.csFilter
);
419 FIXME("%p (%u) stub\n", event
, event
->type
);
422 return gst_pad_event_default(pad
, parent
, event
);
427 static gboolean
event_sink(GstPad
*pad
, GstObject
*parent
, GstEvent
*event
)
429 GSTOutPin
*pin
= gst_pad_get_element_private(pad
);
431 TRACE("%p %p\n", pad
, event
);
433 switch (event
->type
) {
434 case GST_EVENT_SEGMENT
: {
435 gdouble rate
, applied_rate
;
437 const GstSegment
*segment
;
439 gst_event_parse_segment(event
, &segment
);
441 pos
= segment
->position
;
442 stop
= segment
->stop
;
443 rate
= segment
->rate
;
444 applied_rate
= segment
->applied_rate
;
446 if (segment
->format
!= GST_FORMAT_TIME
) {
447 FIXME("Ignoring new segment because of format %i\n", segment
->format
);
451 gst_segment_copy_into(segment
, pin
->segment
);
458 if (pin
->pin
.pin
.pConnectedTo
)
459 IPin_NewSegment(pin
->pin
.pin
.pConnectedTo
, pos
, stop
, rate
*applied_rate
);
464 if (pin
->pin
.pin
.pConnectedTo
)
465 IPin_EndOfStream(pin
->pin
.pin
.pConnectedTo
);
467 case GST_EVENT_FLUSH_START
:
468 if (((GSTImpl
*)pin
->pin
.pin
.pinInfo
.pFilter
)->ignore_flush
) {
469 /* gst-plugins-base prior to 1.7 contains a bug which causes
470 * our sink pins to receive a flush-start event when the
471 * decodebin changes from PAUSED to READY (including
472 * PLAYING->PAUSED->READY), but no matching flush-stop event is
473 * sent. See <gst-plugins-base.git:60bad4815db966a8e4). Here we
474 * unset the flushing flag to avoid the problem. */
475 TRACE("Working around gst <1.7 bug, ignoring FLUSH_START\n");
476 GST_PAD_UNSET_FLUSHING (pad
);
479 if (pin
->pin
.pin
.pConnectedTo
)
480 IPin_BeginFlush(pin
->pin
.pin
.pConnectedTo
);
482 case GST_EVENT_FLUSH_STOP
:
483 gst_segment_init(pin
->segment
, GST_FORMAT_TIME
);
484 if (pin
->pin
.pin
.pConnectedTo
)
485 IPin_EndFlush(pin
->pin
.pin
.pConnectedTo
);
487 case GST_EVENT_CAPS
: {
489 gst_event_parse_caps(event
, &caps
);
490 return setcaps_sink(pad
, caps
);
493 TRACE("%p stub %s\n", event
, gst_event_type_get_name(event
->type
));
494 return gst_pad_event_default(pad
, parent
, event
);
498 static void release_sample(void *data
)
501 ret
= IMediaSample_Release((IMediaSample
*)data
);
502 TRACE("Releasing %p returns %u\n", data
, ret
);
505 static DWORD CALLBACK
push_data(LPVOID iface
)
507 LONGLONG maxlen
, curlen
;
508 GSTImpl
*This
= iface
;
514 IAsyncReader_Length(This
->pInputPin
.pReader
, &maxlen
, &curlen
);
518 TRACE("Waiting..\n");
520 WaitForSingleObject(This
->event
, INFINITE
);
522 TRACE("Starting..\n");
524 REFERENCE_TIME tStart
, tStop
;
531 TRACE("pAlloc: %p\n", This
->pInputPin
.pAlloc
);
532 hr
= IMemAllocator_GetBuffer(This
->pInputPin
.pAlloc
, &buf
, NULL
, NULL
, 0);
536 if (This
->nextofs
>= maxlen
)
538 len
= IMediaSample_GetSize(buf
);
539 if (This
->nextofs
+ len
> maxlen
)
540 len
= maxlen
- This
->nextofs
;
542 tStart
= MEDIATIME_FROM_BYTES(This
->nextofs
);
543 tStop
= tStart
+ MEDIATIME_FROM_BYTES(len
);
544 IMediaSample_SetTime(buf
, &tStart
, &tStop
);
546 hr
= IAsyncReader_Request(This
->pInputPin
.pReader
, buf
, 0);
548 IMediaSample_Release(buf
);
551 This
->nextofs
+= len
;
552 hr
= IAsyncReader_WaitForNext(This
->pInputPin
.pReader
, -1, &buf
, &user
);
553 if (FAILED(hr
) || !buf
) {
555 IMediaSample_Release(buf
);
559 IMediaSample_GetPointer(buf
, &data
);
560 bufsize
= IMediaSample_GetActualDataLength(buf
);
561 gstbuf
= gst_buffer_new_wrapped_full(0, data
, bufsize
, 0, bufsize
, buf
, release_sample_wrapper
);
562 IMediaSample_AddRef(buf
);
563 gst_mini_object_set_qdata(GST_MINI_OBJECT(gstbuf
), g_quark_from_static_string(media_quark_string
), buf
, release_sample_wrapper
);
565 IMediaSample_Release(buf
);
568 gstbuf
->duration
= gstbuf
->pts
= -1;
569 ret
= gst_pad_push(This
->my_src
, gstbuf
);
573 ERR("Sending returned: %i\n", ret
);
574 if (ret
== GST_FLOW_ERROR
)
576 else if (ret
== GST_FLOW_FLUSHING
)
577 hr
= VFW_E_WRONG_STATE
;
582 gst_pad_push_event(This
->my_src
, gst_event_new_eos());
584 TRACE("Almost stopping.. %08x\n", hr
);
586 IAsyncReader_WaitForNext(This
->pInputPin
.pReader
, 0, &buf
, &user
);
588 IMediaSample_Release(buf
);
591 TRACE("Stopping.. %08x\n", hr
);
595 static HRESULT WINAPI
GST_OutPin_QueryAccept(IPin
*iface
, const AM_MEDIA_TYPE
*pmt
)
597 GSTOutPin
*pin
= (GSTOutPin
*)iface
;
598 FIXME("stub %p\n", pin
);
602 static GstFlowReturn
got_data_sink(GstPad
*pad
, GstObject
*parent
, GstBuffer
*buf
)
604 GSTOutPin
*pin
= gst_pad_get_element_private(pad
);
605 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pin
.pinInfo
.pFilter
;
608 IMediaSample
*sample
;
611 TRACE("%p %p\n", pad
, buf
);
614 gst_buffer_unref(buf
);
615 TRACE("Triggering %p %p\n", pad
, pin
->caps_event
);
616 SetEvent(pin
->caps_event
);
620 hr
= BaseOutputPinImpl_GetDeliveryBuffer(&pin
->pin
, &sample
, NULL
, NULL
, 0);
622 if (hr
== VFW_E_NOT_CONNECTED
) {
623 gst_buffer_unref(buf
);
624 return GST_FLOW_NOT_LINKED
;
628 gst_buffer_unref(buf
);
629 ERR("Could not get a delivery buffer (%x), returning GST_FLOW_FLUSHING\n", hr
);
630 return GST_FLOW_FLUSHING
;
633 gst_buffer_map(buf
, &info
, GST_MAP_READ
);
635 hr
= IMediaSample_SetActualDataLength(sample
, info
.size
);
637 WARN("SetActualDataLength failed: %08x\n", hr
);
638 return GST_FLOW_FLUSHING
;
641 IMediaSample_GetPointer(sample
, &ptr
);
643 memcpy(ptr
, info
.data
, info
.size
);
645 gst_buffer_unmap(buf
, &info
);
647 if (GST_BUFFER_PTS_IS_VALID(buf
)) {
648 REFERENCE_TIME rtStart
= gst_segment_to_running_time(pin
->segment
, GST_FORMAT_TIME
, buf
->pts
);
652 if (GST_BUFFER_DURATION_IS_VALID(buf
)) {
653 REFERENCE_TIME tStart
= buf
->pts
/ 100;
654 REFERENCE_TIME tStop
= (buf
->pts
+ buf
->duration
) / 100;
655 REFERENCE_TIME rtStop
;
656 rtStop
= gst_segment_to_running_time(pin
->segment
, GST_FORMAT_TIME
, buf
->pts
+ buf
->duration
);
659 TRACE("Current time on %p: %i to %i ms\n", pin
, (int)(rtStart
/ 10000), (int)(rtStop
/ 10000));
660 IMediaSample_SetTime(sample
, &rtStart
, rtStop
>= 0 ? &rtStop
: NULL
);
661 IMediaSample_SetMediaTime(sample
, &tStart
, &tStop
);
663 IMediaSample_SetTime(sample
, rtStart
>= 0 ? &rtStart
: NULL
, NULL
);
664 IMediaSample_SetMediaTime(sample
, NULL
, NULL
);
667 IMediaSample_SetTime(sample
, NULL
, NULL
);
668 IMediaSample_SetMediaTime(sample
, NULL
, NULL
);
671 IMediaSample_SetDiscontinuity(sample
, GST_BUFFER_FLAG_IS_SET(buf
, GST_BUFFER_FLAG_DISCONT
));
672 IMediaSample_SetPreroll(sample
, GST_BUFFER_FLAG_IS_SET(buf
, GST_BUFFER_FLAG_LIVE
));
673 IMediaSample_SetSyncPoint(sample
, !GST_BUFFER_FLAG_IS_SET(buf
, GST_BUFFER_FLAG_DELTA_UNIT
));
675 if (!pin
->pin
.pin
.pConnectedTo
)
676 hr
= VFW_E_NOT_CONNECTED
;
678 hr
= IMemInputPin_Receive(pin
->pin
.pMemInputPin
, sample
);
680 TRACE("sending sample returned: %08x\n", hr
);
682 gst_buffer_unref(buf
);
683 IMediaSample_Release(sample
);
685 if (hr
== VFW_E_NOT_CONNECTED
)
686 return GST_FLOW_NOT_LINKED
;
689 return GST_FLOW_FLUSHING
;
694 static GstFlowReturn
request_buffer_src(GstPad
*pad
, GstObject
*parent
, guint64 ofs
, guint len
, GstBuffer
**buf
)
696 GSTImpl
*This
= gst_pad_get_element_private(pad
);
700 TRACE("%p %s %i %p\n", pad
, wine_dbgstr_longlong(ofs
), len
, buf
);
703 if (ofs
== GST_BUFFER_OFFSET_NONE
)
704 ofs
= This
->nextpullofs
;
705 if (ofs
>= This
->filesize
) {
706 WARN("Reading past eof: %s, %u\n", wine_dbgstr_longlong(ofs
), len
);
709 if (len
+ ofs
> This
->filesize
)
710 len
= This
->filesize
- ofs
;
711 This
->nextpullofs
= ofs
+ len
;
713 *buf
= gst_buffer_new_and_alloc(len
);
714 gst_buffer_map(*buf
, &info
, GST_MAP_WRITE
);
715 hr
= IAsyncReader_SyncRead(This
->pInputPin
.pReader
, ofs
, len
, info
.data
);
716 gst_buffer_unmap(*buf
, &info
);
718 ERR("Returned %08x\n", hr
);
719 return GST_FLOW_ERROR
;
722 GST_BUFFER_OFFSET(*buf
) = ofs
;
726 static DWORD CALLBACK
push_data_init(LPVOID iface
)
728 GSTImpl
*This
= iface
;
731 TRACE("Starting..\n");
734 GstFlowReturn ret
= request_buffer_src(This
->my_src
, NULL
, ofs
, 4096, &buf
);
736 ERR("Obtaining buffer returned: %i\n", ret
);
739 ret
= gst_pad_push(This
->my_src
, buf
);
742 TRACE("Sending returned: %i\n", ret
);
746 TRACE("Stopping..\n");
750 static void removed_decoded_pad(GstElement
*bin
, GstPad
*pad
, gpointer user
)
752 GSTImpl
*This
= (GSTImpl
*)user
;
756 TRACE("%p %p %p\n", This
, bin
, pad
);
758 EnterCriticalSection(&This
->filter
.csFilter
);
759 for (x
= 0; x
< This
->cStreams
; ++x
) {
760 if (This
->ppPins
[x
]->their_src
== pad
)
763 if (x
== This
->cStreams
)
766 pin
= This
->ppPins
[x
];
769 gst_pad_unlink(pin
->their_src
, pin
->flip_sink
);
771 gst_pad_unlink(pin
->their_src
, pin
->my_sink
);
773 gst_object_unref(pin
->their_src
);
774 pin
->their_src
= NULL
;
776 TRACE("Removed %i/%i\n", x
, This
->cStreams
);
777 LeaveCriticalSection(&This
->filter
.csFilter
);
780 static void init_new_decoded_pad(GstElement
*bin
, GstPad
*pad
, GSTImpl
*This
)
784 const char *typename
;
786 AM_MEDIA_TYPE amt
= {{0}};
792 BOOL isvid
= FALSE
, isaud
= FALSE
;
795 TRACE("%p %p %p\n", This
, bin
, pad
);
797 piOutput
.dir
= PINDIR_OUTPUT
;
798 piOutput
.pFilter
= &This
->filter
.IBaseFilter_iface
;
799 name
= gst_pad_get_name(pad
);
800 MultiByteToWideChar(CP_UNIXCP
, 0, name
, -1, piOutput
.achName
, sizeof(piOutput
.achName
) / sizeof(piOutput
.achName
[0]) - 1);
801 TRACE("Name: %s\n", name
);
802 strcpy(my_name
, "qz_sink_");
803 strcat(my_name
, name
);
805 piOutput
.achName
[sizeof(piOutput
.achName
) / sizeof(piOutput
.achName
[0]) - 1] = 0;
807 caps
= gst_pad_query_caps(pad
, NULL
);
808 caps
= gst_caps_make_writable(caps
);
809 arg
= gst_caps_get_structure(caps
, 0);
810 typename
= gst_structure_get_name(arg
);
812 mypad
= gst_pad_new(my_name
, GST_PAD_SINK
);
813 gst_pad_set_chain_function(mypad
, got_data_sink_wrapper
);
814 gst_pad_set_event_function(mypad
, event_sink_wrapper
);
815 gst_pad_set_query_function(mypad
, query_sink_wrapper
);
817 if (!strcmp(typename
, "audio/x-raw")) {
819 } else if (!strcmp(typename
, "video/x-raw")) {
822 FIXME("Unknown type \'%s\'\n", typename
);
826 hr
= GST_AddPin(This
, &piOutput
, &amt
);
832 pin
= This
->ppPins
[This
->cStreams
- 1];
833 gst_pad_set_element_private(mypad
, pin
);
834 pin
->my_sink
= mypad
;
838 gst_segment_init(pin
->segment
, GST_FORMAT_TIME
);
843 TRACE("setting up videoflip filter for pin %p, my_sink: %p, their_src: %p\n",
844 pin
, pin
->my_sink
, pad
);
846 /* gstreamer outputs video top-down, but dshow expects bottom-up, so
847 * make new transform filter to invert video */
848 vconv
= gst_element_factory_make("videoconvert", NULL
);
850 ERR("Missing videoconvert filter?\n");
855 pin
->flipfilter
= gst_element_factory_make("videoflip", NULL
);
856 if(!pin
->flipfilter
){
857 ERR("Missing videoflip filter?\n");
862 gst_util_set_object_arg(G_OBJECT(pin
->flipfilter
), "method", "vertical-flip");
864 gst_bin_add(GST_BIN(This
->container
), vconv
); /* bin takes ownership */
865 gst_element_sync_state_with_parent(vconv
);
866 gst_bin_add(GST_BIN(This
->container
), pin
->flipfilter
); /* bin takes ownership */
867 gst_element_sync_state_with_parent(pin
->flipfilter
);
869 gst_element_link (vconv
, pin
->flipfilter
);
871 pin
->flip_sink
= gst_element_get_static_pad(vconv
, "sink");
873 WARN("Couldn't find sink on flip filter\n");
874 pin
->flipfilter
= NULL
;
879 ret
= gst_pad_link(pad
, pin
->flip_sink
);
881 WARN("gst_pad_link failed: %d\n", ret
);
882 gst_object_unref(pin
->flip_sink
);
883 pin
->flip_sink
= NULL
;
884 pin
->flipfilter
= NULL
;
888 pin
->flip_src
= gst_element_get_static_pad(pin
->flipfilter
, "src");
890 WARN("Couldn't find src on flip filter\n");
891 gst_object_unref(pin
->flip_sink
);
892 pin
->flip_sink
= NULL
;
893 pin
->flipfilter
= NULL
;
898 ret
= gst_pad_link(pin
->flip_src
, pin
->my_sink
);
900 WARN("gst_pad_link failed: %d\n", ret
);
901 gst_object_unref(pin
->flip_src
);
902 pin
->flip_src
= NULL
;
903 gst_object_unref(pin
->flip_sink
);
904 pin
->flip_sink
= NULL
;
905 pin
->flipfilter
= NULL
;
909 ret
= gst_pad_link(pad
, mypad
);
911 gst_pad_set_active(mypad
, 1);
914 TRACE("Linking: %i\n", ret
);
917 pin
->their_src
= pad
;
918 gst_object_ref(pin
->their_src
);
922 static void existing_new_pad(GstElement
*bin
, GstPad
*pad
, gpointer user
)
924 GSTImpl
*This
= (GSTImpl
*)user
;
927 TRACE("%p %p %p\n", This
, bin
, pad
);
929 if (gst_pad_is_linked(pad
))
932 /* Still holding our own lock */
934 init_new_decoded_pad(bin
, pad
, This
);
938 EnterCriticalSection(&This
->filter
.csFilter
);
939 for (x
= 0; x
< This
->cStreams
; ++x
) {
940 GSTOutPin
*pin
= This
->ppPins
[x
];
941 if (!pin
->their_src
) {
942 gst_segment_init(pin
->segment
, GST_FORMAT_TIME
);
945 ret
= gst_pad_link(pad
, pin
->flip_sink
);
947 ret
= gst_pad_link(pad
, pin
->my_sink
);
950 pin
->their_src
= pad
;
951 gst_object_ref(pin
->their_src
);
953 LeaveCriticalSection(&This
->filter
.csFilter
);
958 init_new_decoded_pad(bin
, pad
, This
);
959 LeaveCriticalSection(&This
->filter
.csFilter
);
962 static gboolean
query_function(GstPad
*pad
, GstObject
*parent
, GstQuery
*query
)
964 GSTImpl
*This
= gst_pad_get_element_private(pad
);
969 TRACE("%p %p %p\n", This
, pad
, query
);
971 switch (GST_QUERY_TYPE(query
)) {
972 case GST_QUERY_DURATION
:
973 gst_query_parse_duration (query
, &format
, NULL
);
974 if (format
== GST_FORMAT_PERCENT
) {
975 gst_query_set_duration (query
, GST_FORMAT_PERCENT
, GST_FORMAT_PERCENT_MAX
);
978 ret
= gst_pad_query_convert (pad
, GST_FORMAT_BYTES
, This
->filesize
, format
, &duration
);
979 gst_query_set_duration(query
, format
, duration
);
981 case GST_QUERY_SEEKING
:
982 gst_query_parse_seeking (query
, &format
, NULL
, NULL
, NULL
);
983 TRACE("Seeking %i %i\n", format
, GST_FORMAT_BYTES
);
984 if (format
!= GST_FORMAT_BYTES
)
986 gst_query_set_seeking(query
, GST_FORMAT_BYTES
, 1, 0, This
->filesize
);
988 case GST_QUERY_SCHEDULING
:
989 gst_query_set_scheduling(query
, GST_SCHEDULING_FLAG_SEEKABLE
, 1, -1, 0);
990 gst_query_add_scheduling_mode(query
, GST_PAD_MODE_PUSH
);
991 gst_query_add_scheduling_mode(query
, GST_PAD_MODE_PULL
);
994 TRACE("Unhandled query type: %s\n", GST_QUERY_TYPE_NAME(query
));
999 static gboolean
activate_push(GstPad
*pad
, gboolean activate
)
1001 GSTImpl
*This
= gst_pad_get_element_private(pad
);
1003 TRACE("%p %p %u\n", This
, pad
, activate
);
1005 EnterCriticalSection(&This
->filter
.csFilter
);
1007 TRACE("Deactivating\n");
1009 IAsyncReader_BeginFlush(This
->pInputPin
.pReader
);
1010 if (This
->push_thread
) {
1011 WaitForSingleObject(This
->push_thread
, -1);
1012 CloseHandle(This
->push_thread
);
1013 This
->push_thread
= NULL
;
1016 IAsyncReader_EndFlush(This
->pInputPin
.pReader
);
1017 if (This
->filter
.state
== State_Stopped
)
1018 This
->nextofs
= This
->start
;
1019 } else if (!This
->push_thread
) {
1020 TRACE("Activating\n");
1022 This
->push_thread
= CreateThread(NULL
, 0, push_data_init
, This
, 0, NULL
);
1024 This
->push_thread
= CreateThread(NULL
, 0, push_data
, This
, 0, NULL
);
1026 LeaveCriticalSection(&This
->filter
.csFilter
);
1030 static gboolean
activate_mode(GstPad
*pad
, GstObject
*parent
, GstPadMode mode
, gboolean activate
)
1032 TRACE("%p %p 0x%x %u\n", pad
, parent
, mode
, activate
);
1034 case GST_PAD_MODE_PULL
:
1036 case GST_PAD_MODE_PUSH
:
1037 return activate_push(pad
, activate
);
1044 static void no_more_pads(GstElement
*decodebin
, gpointer user
)
1046 GSTImpl
*This
= (GSTImpl
*)user
;
1047 TRACE("%p %p\n", This
, decodebin
);
1048 SetEvent(This
->event
);
1051 static GstAutoplugSelectResult
autoplug_blacklist(GstElement
*bin
, GstPad
*pad
, GstCaps
*caps
, GstElementFactory
*fact
, gpointer user
)
1053 const char *name
= gst_element_factory_get_longname(fact
);
1055 if (strstr(name
, "Player protection")) {
1056 WARN("Blacklisted a/52 decoder because it only works in Totem\n");
1057 return GST_AUTOPLUG_SELECT_SKIP
;
1059 if (!strcmp(name
, "Fluendo Hardware Accelerated Video Decoder")) {
1060 WARN("Disabled video acceleration since it breaks in wine\n");
1061 return GST_AUTOPLUG_SELECT_SKIP
;
1063 TRACE("using \"%s\"\n", name
);
1064 return GST_AUTOPLUG_SELECT_TRY
;
1067 static GstBusSyncReply
watch_bus(GstBus
*bus
, GstMessage
*msg
, gpointer data
)
1069 GSTImpl
*This
= data
;
1071 gchar
*dbg_info
= NULL
;
1073 TRACE("%p %p %p\n", This
, bus
, msg
);
1075 if (GST_MESSAGE_TYPE(msg
) & GST_MESSAGE_ERROR
) {
1076 gst_message_parse_error(msg
, &err
, &dbg_info
);
1077 FIXME("%s: %s\n", GST_OBJECT_NAME(msg
->src
), err
->message
);
1078 WARN("%s\n", dbg_info
);
1079 SetEvent(This
->event
);
1080 } else if (GST_MESSAGE_TYPE(msg
) & GST_MESSAGE_WARNING
) {
1081 gst_message_parse_warning(msg
, &err
, &dbg_info
);
1082 WARN("%s: %s\n", GST_OBJECT_NAME(msg
->src
), err
->message
);
1083 WARN("%s\n", dbg_info
);
1088 return GST_BUS_DROP
;
1091 static void unknown_type(GstElement
*bin
, GstPad
*pad
, GstCaps
*caps
, gpointer user
)
1093 gchar
*strcaps
= gst_caps_to_string(caps
);
1094 FIXME("Could not find a filter for caps: %s\n", strcaps
);
1098 static HRESULT
GST_Connect(GSTInPin
*pPin
, IPin
*pConnectPin
, ALLOCATOR_PROPERTIES
*props
)
1100 GSTImpl
*This
= (GSTImpl
*)pPin
->pin
.pinInfo
.pFilter
;
1103 LONGLONG avail
, duration
;
1104 GstStaticPadTemplate src_template
= GST_STATIC_PAD_TEMPLATE(
1108 GST_STATIC_CAPS_ANY
);
1109 GstElement
*gstfilter
;
1111 TRACE("%p %p %p\n", pPin
, pConnectPin
, props
);
1113 This
->props
= *props
;
1114 IAsyncReader_Length(pPin
->pReader
, &This
->filesize
, &avail
);
1117 This
->bus
= gst_bus_new();
1118 gst_bus_set_sync_handler(This
->bus
, watch_bus_wrapper
, This
, NULL
);
1121 This
->container
= gst_bin_new(NULL
);
1122 gst_element_set_bus(This
->container
, This
->bus
);
1124 gstfilter
= gst_element_factory_make("decodebin", NULL
);
1126 FIXME("Could not make source filter, are gstreamer-plugins-* installed for %u bits?\n",
1127 8 * (int)sizeof(void*));
1131 gst_bin_add(GST_BIN(This
->container
), gstfilter
);
1133 g_signal_connect(gstfilter
, "pad-added", G_CALLBACK(existing_new_pad_wrapper
), This
);
1134 g_signal_connect(gstfilter
, "pad-removed", G_CALLBACK(removed_decoded_pad_wrapper
), This
);
1135 g_signal_connect(gstfilter
, "autoplug-select", G_CALLBACK(autoplug_blacklist_wrapper
), This
);
1136 g_signal_connect(gstfilter
, "unknown-type", G_CALLBACK(unknown_type_wrapper
), This
);
1138 This
->my_src
= gst_pad_new_from_static_template(&src_template
, "quartz-src");
1139 gst_pad_set_getrange_function(This
->my_src
, request_buffer_src_wrapper
);
1140 gst_pad_set_query_function(This
->my_src
, query_function_wrapper
);
1141 gst_pad_set_activatemode_function(This
->my_src
, activate_mode_wrapper
);
1142 gst_pad_set_event_function(This
->my_src
, event_src_wrapper
);
1143 gst_pad_set_element_private (This
->my_src
, This
);
1144 This
->their_sink
= gst_element_get_static_pad(gstfilter
, "sink");
1146 g_signal_connect(gstfilter
, "no-more-pads", G_CALLBACK(no_more_pads_wrapper
), This
);
1147 ret
= gst_pad_link(This
->my_src
, This
->their_sink
);
1149 ERR("Returns: %i\n", ret
);
1152 This
->start
= This
->nextofs
= This
->nextpullofs
= This
->stop
= 0;
1154 /* Add initial pins */
1155 This
->initial
= This
->discont
= TRUE
;
1156 ResetEvent(This
->event
);
1157 gst_element_set_state(This
->container
, GST_STATE_PLAYING
);
1158 WaitForSingleObject(This
->event
, -1);
1159 gst_element_get_state(This
->container
, NULL
, NULL
, -1);
1162 WARN("Ret: %i\n", ret
);
1164 } else if (!This
->cStreams
) {
1165 FIXME("GStreamer could not find any streams\n");
1168 gst_pad_query_duration(This
->ppPins
[0]->their_src
, GST_FORMAT_TIME
, &duration
);
1169 for (i
= 0; i
< This
->cStreams
; ++i
) {
1170 This
->ppPins
[i
]->seek
.llDuration
= This
->ppPins
[i
]->seek
.llStop
= duration
/ 100;
1171 This
->ppPins
[i
]->seek
.llCurrent
= 0;
1172 if (!This
->ppPins
[i
]->seek
.llDuration
)
1173 This
->ppPins
[i
]->seek
.dwCapabilities
= 0;
1174 WaitForSingleObject(This
->ppPins
[i
]->caps_event
, -1);
1178 *props
= This
->props
;
1180 This
->ignore_flush
= TRUE
;
1181 gst_element_set_state(This
->container
, GST_STATE_READY
);
1182 gst_element_get_state(This
->container
, NULL
, NULL
, -1);
1183 This
->ignore_flush
= FALSE
;
1185 This
->initial
= FALSE
;
1187 /* don't set active during test-play, as we don't want to push/pull data
1188 * from the source yet */
1189 gst_pad_set_active(This
->my_src
, 1);
1191 This
->nextofs
= This
->nextpullofs
= 0;
1195 static inline GSTOutPin
*impl_from_IMediaSeeking( IMediaSeeking
*iface
)
1197 return CONTAINING_RECORD(iface
, GSTOutPin
, seek
.IMediaSeeking_iface
);
1200 static IPin
* WINAPI
GST_GetPin(BaseFilter
*iface
, int pos
)
1202 GSTImpl
*This
= (GSTImpl
*)iface
;
1205 TRACE("%p: Asking for pos %x\n", This
, pos
);
1207 if (pos
> This
->cStreams
|| pos
< 0)
1211 pin
= &This
->pInputPin
.pin
.IPin_iface
;
1213 pin
= &This
->ppPins
[pos
- 1]->pin
.pin
.IPin_iface
;
1219 static LONG WINAPI
GST_GetPinCount(BaseFilter
*iface
)
1221 GSTImpl
*This
= (GSTImpl
*)iface
;
1222 TRACE("%p -> %u\n", This
, This
->cStreams
+ 1);
1223 return (This
->cStreams
+ 1);
1226 static const BaseFilterFuncTable BaseFuncTable
= {
1231 IUnknown
* CALLBACK
Gstreamer_Splitter_create(IUnknown
*pUnkOuter
, HRESULT
*phr
)
1233 IUnknown
*obj
= NULL
;
1237 TRACE("%p %p\n", pUnkOuter
, phr
);
1239 if (!Gstreamer_init())
1247 This
= CoTaskMemAlloc(sizeof(*This
));
1250 *phr
= E_OUTOFMEMORY
;
1254 obj
= (IUnknown
*)&This
->filter
.IBaseFilter_iface
;
1255 BaseFilter_Init(&This
->filter
, &GST_Vtbl
, &CLSID_Gstreamer_Splitter
, (DWORD_PTR
)(__FILE__
": GSTImpl.csFilter"), &BaseFuncTable
);
1258 This
->ppPins
= NULL
;
1259 This
->push_thread
= NULL
;
1260 This
->event
= CreateEventW(NULL
, 0, 0, NULL
);
1263 piInput
= &This
->pInputPin
.pin
.pinInfo
;
1264 piInput
->dir
= PINDIR_INPUT
;
1265 piInput
->pFilter
= &This
->filter
.IBaseFilter_iface
;
1266 lstrcpynW(piInput
->achName
, wcsInputPinName
, sizeof(piInput
->achName
) / sizeof(piInput
->achName
[0]));
1267 This
->pInputPin
.pin
.IPin_iface
.lpVtbl
= &GST_InputPin_Vtbl
;
1268 This
->pInputPin
.pin
.refCount
= 1;
1269 This
->pInputPin
.pin
.pConnectedTo
= NULL
;
1270 This
->pInputPin
.pin
.pCritSec
= &This
->filter
.csFilter
;
1271 ZeroMemory(&This
->pInputPin
.pin
.mtCurrent
, sizeof(AM_MEDIA_TYPE
));
1274 TRACE("returning %p\n", obj
);
1279 static void GST_Destroy(GSTImpl
*This
)
1281 IPin
*connected
= NULL
;
1285 TRACE("Destroying %p\n", This
);
1287 CloseHandle(This
->event
);
1289 /* Don't need to clean up output pins, disconnecting input pin will do that */
1290 IPin_ConnectedTo((IPin
*)&This
->pInputPin
, &connected
);
1292 hr
= IPin_Disconnect(connected
);
1294 IPin_Release(connected
);
1295 hr
= IPin_Disconnect(&This
->pInputPin
.pin
.IPin_iface
);
1298 pinref
= IPin_Release(&This
->pInputPin
.pin
.IPin_iface
);
1300 /* Valgrind could find this, if I kill it here */
1301 ERR("pinref should be null, is %u, destroying anyway\n", pinref
);
1302 assert((LONG
)pinref
> 0);
1305 pinref
= IPin_Release(&This
->pInputPin
.pin
.IPin_iface
);
1308 gst_bus_set_sync_handler(This
->bus
, NULL
, NULL
, NULL
);
1309 gst_object_unref(This
->bus
);
1311 BaseFilter_Destroy(&This
->filter
);
1312 CoTaskMemFree(This
);
1315 static HRESULT WINAPI
GST_QueryInterface(IBaseFilter
*iface
, REFIID riid
, LPVOID
*ppv
)
1317 GSTImpl
*This
= (GSTImpl
*)iface
;
1319 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1323 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1324 IsEqualIID(riid
, &IID_IPersist
) ||
1325 IsEqualIID(riid
, &IID_IMediaFilter
) ||
1326 IsEqualIID(riid
, &IID_IBaseFilter
))
1328 *ppv
= &This
->filter
.IBaseFilter_iface
;
1332 IUnknown_AddRef((IUnknown
*)(*ppv
));
1336 if (!IsEqualIID(riid
, &IID_IPin
) && !IsEqualIID(riid
, &IID_IVideoWindow
) &&
1337 !IsEqualIID(riid
, &IID_IAMFilterMiscFlags
))
1338 FIXME("No interface for %s!\n", debugstr_guid(riid
));
1340 return E_NOINTERFACE
;
1343 static ULONG WINAPI
GST_Release(IBaseFilter
*iface
)
1345 GSTImpl
*This
= (GSTImpl
*)iface
;
1346 ULONG refCount
= InterlockedDecrement(&This
->filter
.refCount
);
1348 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
1356 static HRESULT WINAPI
GST_Stop(IBaseFilter
*iface
)
1358 GSTImpl
*This
= (GSTImpl
*)iface
;
1360 TRACE("(%p)\n", This
);
1364 if (This
->container
) {
1365 This
->ignore_flush
= TRUE
;
1366 gst_element_set_state(This
->container
, GST_STATE_READY
);
1367 gst_element_get_state(This
->container
, NULL
, NULL
, -1);
1368 This
->ignore_flush
= FALSE
;
1373 static HRESULT WINAPI
GST_Pause(IBaseFilter
*iface
)
1376 GSTImpl
*This
= (GSTImpl
*)iface
;
1378 GstStateChangeReturn ret
;
1380 TRACE("(%p)\n", This
);
1382 if (!This
->container
)
1383 return VFW_E_NOT_CONNECTED
;
1387 gst_element_get_state(This
->container
, &now
, NULL
, -1);
1388 if (now
== GST_STATE_PAUSED
)
1390 if (now
!= GST_STATE_PLAYING
)
1391 hr
= IBaseFilter_Run(iface
, -1);
1394 ret
= gst_element_set_state(This
->container
, GST_STATE_PAUSED
);
1395 if (ret
== GST_STATE_CHANGE_ASYNC
)
1400 static HRESULT WINAPI
GST_Run(IBaseFilter
*iface
, REFERENCE_TIME tStart
)
1403 GSTImpl
*This
= (GSTImpl
*)iface
;
1406 HRESULT hr_any
= VFW_E_NOT_CONNECTED
;
1408 TRACE("(%p)->(%s)\n", This
, wine_dbgstr_longlong(tStart
));
1412 if (!This
->container
)
1413 return VFW_E_NOT_CONNECTED
;
1415 EnterCriticalSection(&This
->filter
.csFilter
);
1416 This
->filter
.rtStreamStart
= tStart
;
1417 LeaveCriticalSection(&This
->filter
.csFilter
);
1419 gst_element_get_state(This
->container
, &now
, NULL
, -1);
1420 if (now
== GST_STATE_PLAYING
)
1422 if (now
== GST_STATE_PAUSED
) {
1423 GstStateChangeReturn ret
;
1424 ret
= gst_element_set_state(This
->container
, GST_STATE_PLAYING
);
1425 if (ret
== GST_STATE_CHANGE_ASYNC
)
1430 EnterCriticalSection(&This
->filter
.csFilter
);
1431 gst_element_set_state(This
->container
, GST_STATE_PLAYING
);
1432 This
->filter
.rtStreamStart
= tStart
;
1434 for (i
= 0; i
< This
->cStreams
; i
++) {
1435 hr
= BaseOutputPinImpl_Active(&This
->ppPins
[i
]->pin
);
1436 if (SUCCEEDED(hr
)) {
1441 LeaveCriticalSection(&This
->filter
.csFilter
);
1446 static HRESULT WINAPI
GST_GetState(IBaseFilter
*iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
1448 GSTImpl
*This
= (GSTImpl
*)iface
;
1450 GstState now
, pending
;
1451 GstStateChangeReturn ret
;
1453 TRACE("(%p)->(%d, %p)\n", This
, dwMilliSecsTimeout
, pState
);
1457 if (!This
->container
) {
1458 *pState
= State_Stopped
;
1462 ret
= gst_element_get_state(This
->container
, &now
, &pending
, dwMilliSecsTimeout
== INFINITE
? -1 : dwMilliSecsTimeout
* 1000);
1464 if (ret
== GST_STATE_CHANGE_ASYNC
)
1465 hr
= VFW_S_STATE_INTERMEDIATE
;
1470 case GST_STATE_PAUSED
: *pState
= State_Paused
; return hr
;
1471 case GST_STATE_PLAYING
: *pState
= State_Running
; return hr
;
1472 default: *pState
= State_Stopped
; return hr
;
1476 static HRESULT WINAPI
GST_FindPin(IBaseFilter
*iface
, LPCWSTR Id
, IPin
**ppPin
)
1478 FIXME("(%p)->(%s,%p) stub\n", iface
, debugstr_w(Id
), ppPin
);
1482 static const IBaseFilterVtbl GST_Vtbl
= {
1484 BaseFilterImpl_AddRef
,
1486 BaseFilterImpl_GetClassID
,
1491 BaseFilterImpl_SetSyncSource
,
1492 BaseFilterImpl_GetSyncSource
,
1493 BaseFilterImpl_EnumPins
,
1495 BaseFilterImpl_QueryFilterInfo
,
1496 BaseFilterImpl_JoinFilterGraph
,
1497 BaseFilterImpl_QueryVendorInfo
1500 static HRESULT WINAPI
GST_ChangeCurrent(IMediaSeeking
*iface
)
1502 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1503 TRACE("(%p)\n", This
);
1507 static HRESULT WINAPI
GST_ChangeStop(IMediaSeeking
*iface
)
1509 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1510 TRACE("(%p)\n", This
);
1514 static HRESULT WINAPI
GST_ChangeRate(IMediaSeeking
*iface
)
1516 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1517 GstEvent
*ev
= gst_event_new_seek(This
->seek
.dRate
, GST_FORMAT_TIME
, 0, GST_SEEK_TYPE_NONE
, -1, GST_SEEK_TYPE_NONE
, -1);
1518 TRACE("(%p) New rate %g\n", This
, This
->seek
.dRate
);
1520 gst_pad_push_event(This
->my_sink
, ev
);
1524 static HRESULT WINAPI
GST_Seeking_QueryInterface(IMediaSeeking
*iface
, REFIID riid
, void **ppv
)
1526 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1527 return IPin_QueryInterface(&This
->pin
.pin
.IPin_iface
, riid
, ppv
);
1530 static ULONG WINAPI
GST_Seeking_AddRef(IMediaSeeking
*iface
)
1532 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1533 return IPin_AddRef(&This
->pin
.pin
.IPin_iface
);
1536 static ULONG WINAPI
GST_Seeking_Release(IMediaSeeking
*iface
)
1538 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1539 return IPin_Release(&This
->pin
.pin
.IPin_iface
);
1542 static HRESULT WINAPI
GST_Seeking_GetCurrentPosition(IMediaSeeking
*iface
, REFERENCE_TIME
*pos
)
1544 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1546 TRACE("(%p)->(%p)\n", This
, pos
);
1553 if (!This
->their_src
) {
1554 *pos
= This
->seek
.llCurrent
;
1555 TRACE("Cached value\n");
1556 if (This
->seek
.llDuration
)
1562 if (!gst_pad_query_position(This
->their_src
, GST_FORMAT_TIME
, pos
)) {
1563 WARN("Could not query position\n");
1567 This
->seek
.llCurrent
= *pos
;
1571 static GstSeekType
type_from_flags(DWORD flags
)
1573 switch (flags
& AM_SEEKING_PositioningBitsMask
) {
1574 case AM_SEEKING_NoPositioning
:
1575 return GST_SEEK_TYPE_NONE
;
1576 case AM_SEEKING_AbsolutePositioning
:
1577 case AM_SEEKING_RelativePositioning
:
1578 return GST_SEEK_TYPE_SET
;
1579 case AM_SEEKING_IncrementalPositioning
:
1580 return GST_SEEK_TYPE_END
;
1582 return GST_SEEK_TYPE_NONE
;
1585 static HRESULT WINAPI
GST_Seeking_SetPositions(IMediaSeeking
*iface
,
1586 REFERENCE_TIME
*pCur
, DWORD curflags
, REFERENCE_TIME
*pStop
,
1590 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1592 GstSeekType curtype
, stoptype
;
1594 gint64 stop_pos
= 0, curr_pos
= 0;
1596 TRACE("(%p)->(%p, 0x%x, %p, 0x%x)\n", This
, pCur
, curflags
, pStop
, stopflags
);
1600 if (!This
->seek
.llDuration
)
1603 hr
= SourceSeekingImpl_SetPositions(iface
, pCur
, curflags
, pStop
, stopflags
);
1604 if (!This
->their_src
)
1607 curtype
= type_from_flags(curflags
);
1608 stoptype
= type_from_flags(stopflags
);
1609 if (curflags
& AM_SEEKING_SeekToKeyFrame
)
1610 f
|= GST_SEEK_FLAG_KEY_UNIT
;
1611 if (curflags
& AM_SEEKING_Segment
)
1612 f
|= GST_SEEK_FLAG_SEGMENT
;
1613 if (!(curflags
& AM_SEEKING_NoFlush
))
1614 f
|= GST_SEEK_FLAG_FLUSH
;
1616 if (((curflags
& AM_SEEKING_PositioningBitsMask
) == AM_SEEKING_RelativePositioning
) ||
1617 ((stopflags
& AM_SEEKING_PositioningBitsMask
) == AM_SEEKING_RelativePositioning
)) {
1619 gst_pad_query_position (This
->my_sink
, GST_FORMAT_TIME
, &tmp_pos
);
1620 if ((curflags
& AM_SEEKING_PositioningBitsMask
) == AM_SEEKING_RelativePositioning
)
1622 if ((stopflags
& AM_SEEKING_PositioningBitsMask
) == AM_SEEKING_RelativePositioning
)
1626 e
= gst_event_new_seek(This
->seek
.dRate
, GST_FORMAT_TIME
, f
, curtype
, pCur
? curr_pos
+ *pCur
* 100 : -1, stoptype
, pStop
? stop_pos
+ *pStop
* 100 : -1);
1627 if (gst_pad_push_event(This
->my_sink
, e
))
1633 static const IMediaSeekingVtbl GST_Seeking_Vtbl
=
1635 GST_Seeking_QueryInterface
,
1637 GST_Seeking_Release
,
1638 SourceSeekingImpl_GetCapabilities
,
1639 SourceSeekingImpl_CheckCapabilities
,
1640 SourceSeekingImpl_IsFormatSupported
,
1641 SourceSeekingImpl_QueryPreferredFormat
,
1642 SourceSeekingImpl_GetTimeFormat
,
1643 SourceSeekingImpl_IsUsingTimeFormat
,
1644 SourceSeekingImpl_SetTimeFormat
,
1645 SourceSeekingImpl_GetDuration
,
1646 SourceSeekingImpl_GetStopPosition
,
1647 GST_Seeking_GetCurrentPosition
,
1648 SourceSeekingImpl_ConvertTimeFormat
,
1649 GST_Seeking_SetPositions
,
1650 SourceSeekingImpl_GetPositions
,
1651 SourceSeekingImpl_GetAvailable
,
1652 SourceSeekingImpl_SetRate
,
1653 SourceSeekingImpl_GetRate
,
1654 SourceSeekingImpl_GetPreroll
1657 static inline GSTOutPin
*impl_from_IQualityControl( IQualityControl
*iface
)
1659 return CONTAINING_RECORD(iface
, GSTOutPin
, IQualityControl_iface
);
1662 static HRESULT WINAPI
GST_QualityControl_QueryInterface(IQualityControl
*iface
, REFIID riid
, void **ppv
)
1664 GSTOutPin
*pin
= impl_from_IQualityControl(iface
);
1665 return IPin_QueryInterface(&pin
->pin
.pin
.IPin_iface
, riid
, ppv
);
1668 static ULONG WINAPI
GST_QualityControl_AddRef(IQualityControl
*iface
)
1670 GSTOutPin
*pin
= impl_from_IQualityControl(iface
);
1671 return IPin_AddRef(&pin
->pin
.pin
.IPin_iface
);
1674 static ULONG WINAPI
GST_QualityControl_Release(IQualityControl
*iface
)
1676 GSTOutPin
*pin
= impl_from_IQualityControl(iface
);
1677 return IPin_Release(&pin
->pin
.pin
.IPin_iface
);
1680 static HRESULT WINAPI
GST_QualityControl_Notify(IQualityControl
*iface
, IBaseFilter
*sender
, Quality qm
)
1682 GSTOutPin
*pin
= impl_from_IQualityControl(iface
);
1685 TRACE("(%p)->(%p, { 0x%x %u %s %s })\n", pin
, sender
,
1686 qm
.Type
, qm
.Proportion
,
1687 wine_dbgstr_longlong(qm
.Late
),
1688 wine_dbgstr_longlong(qm
.TimeStamp
));
1692 if (qm
.Type
== Flood
)
1695 evt
= gst_event_new_qos(qm
.Type
== Famine
? GST_QOS_TYPE_UNDERFLOW
: GST_QOS_TYPE_OVERFLOW
,
1696 qm
.Proportion
/ 1000., qm
.Late
* 100, qm
.TimeStamp
* 100);
1699 WARN("Failed to create QOS event\n");
1700 return E_INVALIDARG
;
1703 gst_pad_push_event(pin
->my_sink
, evt
);
1708 static HRESULT WINAPI
GST_QualityControl_SetSink(IQualityControl
*iface
, IQualityControl
*tonotify
)
1710 GSTOutPin
*pin
= impl_from_IQualityControl(iface
);
1711 TRACE("(%p)->(%p)\n", pin
, pin
);
1716 static const IQualityControlVtbl GSTOutPin_QualityControl_Vtbl
= {
1717 GST_QualityControl_QueryInterface
,
1718 GST_QualityControl_AddRef
,
1719 GST_QualityControl_Release
,
1720 GST_QualityControl_Notify
,
1721 GST_QualityControl_SetSink
1724 static HRESULT WINAPI
GSTOutPin_QueryInterface(IPin
*iface
, REFIID riid
, void **ppv
)
1726 GSTOutPin
*This
= (GSTOutPin
*)iface
;
1728 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1732 if (IsEqualIID(riid
, &IID_IUnknown
))
1734 else if (IsEqualIID(riid
, &IID_IPin
))
1736 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
1738 else if (IsEqualIID(riid
, &IID_IQualityControl
))
1739 *ppv
= &This
->IQualityControl_iface
;
1742 IUnknown_AddRef((IUnknown
*)(*ppv
));
1745 FIXME("No interface for %s!\n", debugstr_guid(riid
));
1746 return E_NOINTERFACE
;
1749 static ULONG WINAPI
GSTOutPin_Release(IPin
*iface
)
1751 GSTOutPin
*This
= (GSTOutPin
*)iface
;
1752 ULONG refCount
= InterlockedDecrement(&This
->pin
.pin
.refCount
);
1754 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
1759 if (This
->their_src
) {
1760 if (This
->flipfilter
) {
1761 gst_pad_unlink(This
->their_src
, This
->flip_sink
);
1762 gst_pad_unlink(This
->flip_src
, This
->my_sink
);
1763 gst_object_unref(This
->flip_src
);
1764 gst_object_unref(This
->flip_sink
);
1765 This
->flipfilter
= NULL
;
1766 This
->flip_src
= This
->flip_sink
= NULL
;
1768 gst_pad_unlink(This
->their_src
, This
->my_sink
);
1769 gst_object_unref(This
->their_src
);
1771 gst_object_unref(This
->my_sink
);
1772 CloseHandle(This
->caps_event
);
1773 DeleteMediaType(This
->pmt
);
1774 FreeMediaType(&This
->pin
.pin
.mtCurrent
);
1775 gst_segment_free(This
->segment
);
1777 gst_object_unref(This
->gstpool
);
1778 if (This
->pin
.pAllocator
)
1779 IMemAllocator_Release(This
->pin
.pAllocator
);
1780 CoTaskMemFree(This
);
1786 static HRESULT WINAPI
GSTOutPin_GetMediaType(BasePin
*iface
, int iPosition
, AM_MEDIA_TYPE
*pmt
)
1788 GSTOutPin
*This
= (GSTOutPin
*)iface
;
1790 TRACE("(%p)->(%i, %p)\n", This
, iPosition
, pmt
);
1793 return E_INVALIDARG
;
1796 return VFW_S_NO_MORE_ITEMS
;
1798 CopyMediaType(pmt
, This
->pmt
);
1803 static HRESULT WINAPI
GSTOutPin_DecideBufferSize(BaseOutputPin
*iface
, IMemAllocator
*pAlloc
, ALLOCATOR_PROPERTIES
*ppropInputRequest
)
1805 GSTOutPin
*This
= (GSTOutPin
*)iface
;
1806 TRACE("(%p)->(%p, %p)\n", This
, pAlloc
, ppropInputRequest
);
1811 static HRESULT WINAPI
GSTOutPin_DecideAllocator(BaseOutputPin
*iface
, IMemInputPin
*pPin
, IMemAllocator
**pAlloc
)
1814 GSTOutPin
*This
= (GSTOutPin
*)iface
;
1815 GSTImpl
*GSTfilter
= (GSTImpl
*)This
->pin
.pin
.pinInfo
.pFilter
;
1817 TRACE("(%p)->(%p, %p)\n", This
, pPin
, pAlloc
);
1820 if (GSTfilter
->pInputPin
.pAlloc
)
1822 hr
= IMemInputPin_NotifyAllocator(pPin
, GSTfilter
->pInputPin
.pAlloc
, FALSE
);
1825 *pAlloc
= GSTfilter
->pInputPin
.pAlloc
;
1826 IMemAllocator_AddRef(*pAlloc
);
1830 hr
= VFW_E_NO_ALLOCATOR
;
1835 static HRESULT WINAPI
GSTOutPin_BreakConnect(BaseOutputPin
*This
)
1839 TRACE("(%p)->()\n", This
);
1841 EnterCriticalSection(This
->pin
.pCritSec
);
1842 if (!This
->pin
.pConnectedTo
|| !This
->pMemInputPin
)
1843 hr
= VFW_E_NOT_CONNECTED
;
1846 hr
= IPin_Disconnect(This
->pin
.pConnectedTo
);
1847 IPin_Disconnect((IPin
*)This
);
1849 LeaveCriticalSection(This
->pin
.pCritSec
);
1854 static const IPinVtbl GST_OutputPin_Vtbl
= {
1855 GSTOutPin_QueryInterface
,
1858 BaseOutputPinImpl_Connect
,
1859 BaseOutputPinImpl_ReceiveConnection
,
1860 BaseOutputPinImpl_Disconnect
,
1861 BasePinImpl_ConnectedTo
,
1862 BasePinImpl_ConnectionMediaType
,
1863 BasePinImpl_QueryPinInfo
,
1864 BasePinImpl_QueryDirection
,
1865 BasePinImpl_QueryId
,
1866 GST_OutPin_QueryAccept
,
1867 BasePinImpl_EnumMediaTypes
,
1868 BasePinImpl_QueryInternalConnections
,
1869 BaseOutputPinImpl_EndOfStream
,
1870 BaseOutputPinImpl_BeginFlush
,
1871 BaseOutputPinImpl_EndFlush
,
1872 BasePinImpl_NewSegment
1875 static const BaseOutputPinFuncTable output_BaseOutputFuncTable
= {
1878 BaseOutputPinImpl_AttemptConnection
,
1879 BasePinImpl_GetMediaTypeVersion
,
1880 GSTOutPin_GetMediaType
1882 GSTOutPin_DecideBufferSize
,
1883 GSTOutPin_DecideAllocator
,
1884 GSTOutPin_BreakConnect
1887 static HRESULT
GST_AddPin(GSTImpl
*This
, const PIN_INFO
*piOutput
, const AM_MEDIA_TYPE
*amt
)
1890 This
->ppPins
= CoTaskMemRealloc(This
->ppPins
, (This
->cStreams
+ 1) * sizeof(IPin
*));
1892 hr
= BaseOutputPin_Construct(&GST_OutputPin_Vtbl
, sizeof(GSTOutPin
), piOutput
, &output_BaseOutputFuncTable
, &This
->filter
.csFilter
, (IPin
**)(This
->ppPins
+ This
->cStreams
));
1893 if (SUCCEEDED(hr
)) {
1894 GSTOutPin
*pin
= This
->ppPins
[This
->cStreams
];
1895 memset((char*)pin
+ sizeof(pin
->pin
), 0, sizeof(GSTOutPin
) - sizeof(pin
->pin
));
1896 pin
->pmt
= CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
));
1897 CopyMediaType(pin
->pmt
, amt
);
1898 pin
->pin
.pin
.pinInfo
.pFilter
= &This
->filter
.IBaseFilter_iface
;
1899 pin
->caps_event
= CreateEventW(NULL
, 0, 0, NULL
);
1900 pin
->segment
= gst_segment_new();
1902 pin
->IQualityControl_iface
.lpVtbl
= &GSTOutPin_QualityControl_Vtbl
;
1903 SourceSeeking_Init(&pin
->seek
, &GST_Seeking_Vtbl
, GST_ChangeStop
, GST_ChangeCurrent
, GST_ChangeRate
, &This
->filter
.csFilter
);
1904 BaseFilterImpl_IncrementPinVersion(&This
->filter
);
1906 ERR("Failed with error %x\n", hr
);
1910 static HRESULT
GST_RemoveOutputPins(GSTImpl
*This
)
1914 GSTOutPin
**ppOldPins
= This
->ppPins
;
1916 TRACE("(%p)\n", This
);
1919 if (!This
->container
)
1921 gst_element_set_state(This
->container
, GST_STATE_NULL
);
1922 gst_pad_unlink(This
->my_src
, This
->their_sink
);
1923 gst_object_unref(This
->my_src
);
1924 gst_object_unref(This
->their_sink
);
1925 This
->my_src
= This
->their_sink
= NULL
;
1927 for (i
= 0; i
< This
->cStreams
; i
++) {
1928 hr
= BaseOutputPinImpl_BreakConnect(&ppOldPins
[i
]->pin
);
1929 TRACE("Disconnect: %08x\n", hr
);
1930 IPin_Release(&ppOldPins
[i
]->pin
.pin
.IPin_iface
);
1933 This
->ppPins
= NULL
;
1934 gst_element_set_bus(This
->container
, NULL
);
1935 gst_object_unref(This
->container
);
1936 This
->container
= NULL
;
1937 BaseFilterImpl_IncrementPinVersion(&This
->filter
);
1938 CoTaskMemFree(ppOldPins
);
1942 static ULONG WINAPI
GSTInPin_Release(IPin
*iface
)
1944 GSTInPin
*This
= (GSTInPin
*)iface
;
1945 ULONG refCount
= InterlockedDecrement(&This
->pin
.refCount
);
1947 TRACE("(%p)->() Release from %d\n", iface
, refCount
+ 1);
1949 FreeMediaType(&This
->pin
.mtCurrent
);
1951 IMemAllocator_Release(This
->pAlloc
);
1952 This
->pAlloc
= NULL
;
1954 IAsyncReader_Release(This
->pReader
);
1955 This
->pReader
= NULL
;
1956 This
->pin
.IPin_iface
.lpVtbl
= NULL
;
1962 static HRESULT WINAPI
GSTInPin_ReceiveConnection(IPin
*iface
, IPin
*pReceivePin
, const AM_MEDIA_TYPE
*pmt
)
1964 PIN_DIRECTION pindirReceive
;
1966 GSTInPin
*This
= (GSTInPin
*)iface
;
1968 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, pReceivePin
, pmt
);
1969 dump_AM_MEDIA_TYPE(pmt
);
1973 EnterCriticalSection(This
->pin
.pCritSec
);
1974 if (!This
->pin
.pConnectedTo
) {
1975 ALLOCATOR_PROPERTIES props
;
1976 IMemAllocator
*pAlloc
= NULL
;
1979 props
.cbBuffer
= 16384;
1983 if (IPin_QueryAccept(iface
, pmt
) != S_OK
)
1984 hr
= VFW_E_TYPE_NOT_ACCEPTED
;
1986 if (SUCCEEDED(hr
)) {
1987 IPin_QueryDirection(pReceivePin
, &pindirReceive
);
1988 if (pindirReceive
!= PINDIR_OUTPUT
) {
1989 ERR("Can't connect from non-output pin\n");
1990 hr
= VFW_E_INVALID_DIRECTION
;
1994 This
->pReader
= NULL
;
1995 This
->pAlloc
= NULL
;
1997 hr
= IPin_QueryInterface(pReceivePin
, &IID_IAsyncReader
, (LPVOID
*)&This
->pReader
);
1999 hr
= GST_Connect(This
, pReceivePin
, &props
);
2001 /* A certain IAsyncReader::RequestAllocator expects to be passed
2002 non-NULL preferred allocator */
2004 hr
= CoCreateInstance(&CLSID_MemoryAllocator
, NULL
, CLSCTX_INPROC
,
2005 &IID_IMemAllocator
, (LPVOID
*)&pAlloc
);
2006 if (SUCCEEDED(hr
)) {
2007 hr
= IAsyncReader_RequestAllocator(This
->pReader
, pAlloc
, &props
, &This
->pAlloc
);
2009 WARN("Can't get an allocator, got %08x\n", hr
);
2012 IMemAllocator_Release(pAlloc
);
2013 if (SUCCEEDED(hr
)) {
2014 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
2015 This
->pin
.pConnectedTo
= pReceivePin
;
2016 IPin_AddRef(pReceivePin
);
2017 hr
= IMemAllocator_Commit(This
->pAlloc
);
2018 SetEvent(((GSTImpl
*)This
->pin
.pinInfo
.pFilter
)->event
);
2020 GST_RemoveOutputPins((GSTImpl
*)This
->pin
.pinInfo
.pFilter
);
2022 IAsyncReader_Release(This
->pReader
);
2023 This
->pReader
= NULL
;
2025 IMemAllocator_Release(This
->pAlloc
);
2026 This
->pAlloc
= NULL
;
2028 TRACE("Size: %i\n", props
.cbBuffer
);
2030 hr
= VFW_E_ALREADY_CONNECTED
;
2031 LeaveCriticalSection(This
->pin
.pCritSec
);
2035 static HRESULT WINAPI
GSTInPin_Disconnect(IPin
*iface
)
2038 GSTInPin
*This
= (GSTInPin
*)iface
;
2041 TRACE("(%p)\n", This
);
2045 hr
= IBaseFilter_GetState(This
->pin
.pinInfo
.pFilter
, INFINITE
, &state
);
2046 EnterCriticalSection(This
->pin
.pCritSec
);
2047 if (This
->pin
.pConnectedTo
) {
2048 GSTImpl
*Parser
= (GSTImpl
*)This
->pin
.pinInfo
.pFilter
;
2050 if (SUCCEEDED(hr
) && state
== State_Stopped
) {
2051 IMemAllocator_Decommit(This
->pAlloc
);
2052 IPin_Disconnect(This
->pin
.pConnectedTo
);
2053 IPin_Release(This
->pin
.pConnectedTo
);
2054 This
->pin
.pConnectedTo
= NULL
;
2055 hr
= GST_RemoveOutputPins(Parser
);
2057 hr
= VFW_E_NOT_STOPPED
;
2060 LeaveCriticalSection(This
->pin
.pCritSec
);
2064 static HRESULT WINAPI
GSTInPin_QueryAccept(IPin
*iface
, const AM_MEDIA_TYPE
*pmt
)
2066 GSTInPin
*This
= (GSTInPin
*)iface
;
2068 TRACE("(%p)->(%p)\n", This
, pmt
);
2069 dump_AM_MEDIA_TYPE(pmt
);
2071 if (IsEqualIID(&pmt
->majortype
, &MEDIATYPE_Stream
))
2076 static HRESULT WINAPI
GSTInPin_EndOfStream(IPin
*iface
)
2078 GSTInPin
*pin
= (GSTInPin
*)iface
;
2079 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pinInfo
.pFilter
;
2081 FIXME("Propagate message on %p\n", This
);
2085 static HRESULT WINAPI
GSTInPin_BeginFlush(IPin
*iface
)
2087 GSTInPin
*pin
= (GSTInPin
*)iface
;
2088 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pinInfo
.pFilter
;
2090 FIXME("Propagate message on %p\n", This
);
2094 static HRESULT WINAPI
GSTInPin_EndFlush(IPin
*iface
)
2096 GSTInPin
*pin
= (GSTInPin
*)iface
;
2097 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pinInfo
.pFilter
;
2099 FIXME("Propagate message on %p\n", This
);
2103 static HRESULT WINAPI
GSTInPin_NewSegment(IPin
*iface
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
2105 GSTInPin
*pin
= (GSTInPin
*)iface
;
2106 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pinInfo
.pFilter
;
2108 BasePinImpl_NewSegment(iface
, tStart
, tStop
, dRate
);
2109 FIXME("Propagate message on %p\n", This
);
2113 static HRESULT WINAPI
GSTInPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
2115 GSTInPin
*This
= (GSTInPin
*)iface
;
2117 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, debugstr_guid(riid
), ppv
);
2121 if (IsEqualIID(riid
, &IID_IUnknown
))
2123 else if (IsEqualIID(riid
, &IID_IPin
))
2125 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
2127 return IBaseFilter_QueryInterface(This
->pin
.pinInfo
.pFilter
, &IID_IMediaSeeking
, ppv
);
2132 IUnknown_AddRef((IUnknown
*)(*ppv
));
2136 FIXME("No interface for %s!\n", debugstr_guid(riid
));
2138 return E_NOINTERFACE
;
2141 static HRESULT WINAPI
GSTInPin_EnumMediaTypes(IPin
*iface
, IEnumMediaTypes
**ppEnum
)
2143 BasePin
*This
= (BasePin
*)iface
;
2145 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
2147 return EnumMediaTypes_Construct(This
, BasePinImpl_GetMediaType
, BasePinImpl_GetMediaTypeVersion
, ppEnum
);
2150 static const IPinVtbl GST_InputPin_Vtbl
= {
2151 GSTInPin_QueryInterface
,
2154 BaseInputPinImpl_Connect
,
2155 GSTInPin_ReceiveConnection
,
2156 GSTInPin_Disconnect
,
2157 BasePinImpl_ConnectedTo
,
2158 BasePinImpl_ConnectionMediaType
,
2159 BasePinImpl_QueryPinInfo
,
2160 BasePinImpl_QueryDirection
,
2161 BasePinImpl_QueryId
,
2162 GSTInPin_QueryAccept
,
2163 GSTInPin_EnumMediaTypes
,
2164 BasePinImpl_QueryInternalConnections
,
2165 GSTInPin_EndOfStream
,
2166 GSTInPin_BeginFlush
,
2171 pthread_mutex_t cb_list_lock
= PTHREAD_MUTEX_INITIALIZER
;
2172 pthread_cond_t cb_list_cond
= PTHREAD_COND_INITIALIZER
;
2173 struct list cb_list
= LIST_INIT(cb_list
);
2175 void CALLBACK
perform_cb(TP_CALLBACK_INSTANCE
*instance
, void *user
)
2177 struct cb_data
*cbdata
= user
;
2179 TRACE("got cb type: 0x%x\n", cbdata
->type
);
2181 switch(cbdata
->type
)
2185 struct watch_bus_data
*data
= &cbdata
->u
.watch_bus_data
;
2186 cbdata
->u
.watch_bus_data
.ret
= watch_bus(data
->bus
, data
->msg
, data
->user
);
2189 case EXISTING_NEW_PAD
:
2191 struct existing_new_pad_data
*data
= &cbdata
->u
.existing_new_pad_data
;
2192 existing_new_pad(data
->bin
, data
->pad
, data
->user
);
2195 case QUERY_FUNCTION
:
2197 struct query_function_data
*data
= &cbdata
->u
.query_function_data
;
2198 cbdata
->u
.query_function_data
.ret
= query_function(data
->pad
, data
->parent
, data
->query
);
2203 struct activate_mode_data
*data
= &cbdata
->u
.activate_mode_data
;
2204 cbdata
->u
.activate_mode_data
.ret
= activate_mode(data
->pad
, data
->parent
, data
->mode
, data
->activate
);
2209 struct no_more_pads_data
*data
= &cbdata
->u
.no_more_pads_data
;
2210 no_more_pads(data
->decodebin
, data
->user
);
2213 case REQUEST_BUFFER_SRC
:
2215 struct request_buffer_src_data
*data
= &cbdata
->u
.request_buffer_src_data
;
2216 cbdata
->u
.request_buffer_src_data
.ret
= request_buffer_src(data
->pad
, data
->parent
,
2217 data
->ofs
, data
->len
, data
->buf
);
2222 struct event_src_data
*data
= &cbdata
->u
.event_src_data
;
2223 cbdata
->u
.event_src_data
.ret
= event_src(data
->pad
, data
->parent
, data
->event
);
2228 struct event_sink_data
*data
= &cbdata
->u
.event_sink_data
;
2229 cbdata
->u
.event_sink_data
.ret
= event_sink(data
->pad
, data
->parent
, data
->event
);
2232 case ACCEPT_CAPS_SINK
:
2234 struct accept_caps_sink_data
*data
= &cbdata
->u
.accept_caps_sink_data
;
2235 cbdata
->u
.accept_caps_sink_data
.ret
= accept_caps_sink(data
->pad
, data
->caps
);
2240 struct setcaps_sink_data
*data
= &cbdata
->u
.setcaps_sink_data
;
2241 cbdata
->u
.setcaps_sink_data
.ret
= setcaps_sink(data
->pad
, data
->caps
);
2246 struct got_data_sink_data
*data
= &cbdata
->u
.got_data_sink_data
;
2247 cbdata
->u
.got_data_sink_data
.ret
= got_data_sink(data
->pad
, data
->parent
, data
->buf
);
2252 struct got_data_data
*data
= &cbdata
->u
.got_data_data
;
2253 cbdata
->u
.got_data_data
.ret
= got_data(data
->pad
, data
->parent
, data
->buf
);
2256 case REMOVED_DECODED_PAD
:
2258 struct removed_decoded_pad_data
*data
= &cbdata
->u
.removed_decoded_pad_data
;
2259 removed_decoded_pad(data
->bin
, data
->pad
, data
->user
);
2262 case AUTOPLUG_BLACKLIST
:
2264 struct autoplug_blacklist_data
*data
= &cbdata
->u
.autoplug_blacklist_data
;
2265 cbdata
->u
.autoplug_blacklist_data
.ret
= autoplug_blacklist(data
->bin
,
2266 data
->pad
, data
->caps
, data
->fact
, data
->user
);
2271 struct unknown_type_data
*data
= &cbdata
->u
.unknown_type_data
;
2272 unknown_type(data
->bin
, data
->pad
, data
->caps
, data
->user
);
2275 case RELEASE_SAMPLE
:
2277 struct release_sample_data
*data
= &cbdata
->u
.release_sample_data
;
2278 release_sample(data
->data
);
2281 case TRANSFORM_PAD_ADDED
:
2283 struct transform_pad_added_data
*data
= &cbdata
->u
.transform_pad_added_data
;
2284 Gstreamer_transform_pad_added(data
->filter
, data
->pad
, data
->user
);
2289 struct query_sink_data
*data
= &cbdata
->u
.query_sink_data
;
2290 cbdata
->u
.query_sink_data
.ret
= query_sink(data
->pad
, data
->parent
,
2296 pthread_mutex_lock(&cbdata
->lock
);
2297 cbdata
->finished
= 1;
2298 pthread_cond_broadcast(&cbdata
->cond
);
2299 pthread_mutex_unlock(&cbdata
->lock
);
2302 static DWORD WINAPI
dispatch_thread(void *user
)
2304 struct cb_data
*cbdata
;
2306 pthread_mutex_lock(&cb_list_lock
);
2309 pthread_cond_wait(&cb_list_cond
, &cb_list_lock
);
2311 while(!list_empty(&cb_list
)){
2312 cbdata
= LIST_ENTRY(list_head(&cb_list
), struct cb_data
, entry
);
2313 list_remove(&cbdata
->entry
);
2315 TrySubmitThreadpoolCallback(&perform_cb
, cbdata
, NULL
);
2319 pthread_mutex_unlock(&cb_list_lock
);
2324 void start_dispatch_thread(void)
2326 pthread_key_create(&wine_gst_key
, NULL
);
2327 CloseHandle(CreateThread(NULL
, 0, &dispatch_thread
, NULL
, 0, NULL
));