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
*gstfilter
;
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
;
83 GstBufferPool
*gstpool
;
91 const char* media_quark_string
= "media-sample";
93 static const WCHAR wcsInputPinName
[] = {'i','n','p','u','t',' ','p','i','n',0};
94 static const IMediaSeekingVtbl GST_Seeking_Vtbl
;
95 static const IPinVtbl GST_OutputPin_Vtbl
;
96 static const IPinVtbl GST_InputPin_Vtbl
;
97 static const IBaseFilterVtbl GST_Vtbl
;
98 static const IQualityControlVtbl GSTOutPin_QualityControl_Vtbl
;
100 static HRESULT
GST_AddPin(GSTImpl
*This
, const PIN_INFO
*piOutput
, const AM_MEDIA_TYPE
*amt
);
101 static HRESULT
GST_RemoveOutputPins(GSTImpl
*This
);
102 static HRESULT WINAPI
GST_ChangeCurrent(IMediaSeeking
*iface
);
103 static HRESULT WINAPI
GST_ChangeStop(IMediaSeeking
*iface
);
104 static HRESULT WINAPI
GST_ChangeRate(IMediaSeeking
*iface
);
106 void mark_wine_thread(void)
108 /* set it to non-NULL to indicate that this is a Wine thread */
109 pthread_setspecific(wine_gst_key
, &wine_gst_key
);
112 BOOL
is_wine_thread(void)
114 return pthread_getspecific(wine_gst_key
) != NULL
;
117 static gboolean
amt_from_gst_caps_audio(GstCaps
*caps
, AM_MEDIA_TYPE
*amt
)
119 WAVEFORMATEXTENSIBLE
*wfe
;
121 gint32 depth
= 0, bpp
= 0;
124 if (!gst_audio_info_from_caps (&ainfo
, caps
))
127 wfe
= CoTaskMemAlloc(sizeof(*wfe
));
128 wfx
= (WAVEFORMATEX
*)wfe
;
129 amt
->majortype
= MEDIATYPE_Audio
;
130 amt
->subtype
= MEDIASUBTYPE_PCM
;
131 amt
->formattype
= FORMAT_WaveFormatEx
;
132 amt
->pbFormat
= (BYTE
*)wfe
;
133 amt
->cbFormat
= sizeof(*wfe
);
134 amt
->bFixedSizeSamples
= 0;
135 amt
->bTemporalCompression
= 1;
136 amt
->lSampleSize
= 0;
139 wfx
->wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
141 wfx
->nChannels
= ainfo
.channels
;
142 wfx
->nSamplesPerSec
= ainfo
.rate
;
143 depth
= GST_AUDIO_INFO_WIDTH(&ainfo
);
144 bpp
= GST_AUDIO_INFO_DEPTH(&ainfo
);
146 if (!depth
|| depth
> 32 || depth
% 8)
150 wfe
->Samples
.wValidBitsPerSample
= depth
;
151 wfx
->wBitsPerSample
= bpp
;
152 wfx
->cbSize
= sizeof(*wfe
)-sizeof(*wfx
);
153 switch (wfx
->nChannels
) {
154 case 1: wfe
->dwChannelMask
= KSAUDIO_SPEAKER_MONO
; break;
155 case 2: wfe
->dwChannelMask
= KSAUDIO_SPEAKER_STEREO
; break;
156 case 4: wfe
->dwChannelMask
= KSAUDIO_SPEAKER_SURROUND
; break;
157 case 5: wfe
->dwChannelMask
= (KSAUDIO_SPEAKER_5POINT1
& ~SPEAKER_LOW_FREQUENCY
); break;
158 case 6: wfe
->dwChannelMask
= KSAUDIO_SPEAKER_5POINT1
; break;
159 case 8: wfe
->dwChannelMask
= KSAUDIO_SPEAKER_7POINT1
; break;
161 wfe
->dwChannelMask
= 0;
163 if (GST_AUDIO_INFO_IS_FLOAT(&ainfo
)) {
164 wfe
->SubFormat
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
165 wfx
->wBitsPerSample
= wfe
->Samples
.wValidBitsPerSample
= 32;
167 wfe
->SubFormat
= KSDATAFORMAT_SUBTYPE_PCM
;
168 if (wfx
->nChannels
<= 2 && bpp
<= 16 && depth
== bpp
) {
169 wfx
->wFormatTag
= WAVE_FORMAT_PCM
;
173 wfx
->nBlockAlign
= wfx
->nChannels
* wfx
->wBitsPerSample
/8;
174 wfx
->nAvgBytesPerSec
= wfx
->nSamplesPerSec
* wfx
->nBlockAlign
;
178 static gboolean
amt_from_gst_caps_video(GstCaps
*caps
, AM_MEDIA_TYPE
*amt
)
180 VIDEOINFOHEADER
*vih
= CoTaskMemAlloc(sizeof(*vih
));
181 BITMAPINFOHEADER
*bih
= &vih
->bmiHeader
;
182 gint32 width
= 0, height
= 0, nom
= 0, denom
= 0;
185 if (!gst_video_info_from_caps (&vinfo
, caps
))
188 height
= vinfo
.height
;
192 amt
->formattype
= FORMAT_VideoInfo
;
193 amt
->pbFormat
= (BYTE
*)vih
;
194 amt
->cbFormat
= sizeof(*vih
);
195 amt
->bFixedSizeSamples
= amt
->bTemporalCompression
= 1;
196 amt
->lSampleSize
= 0;
198 ZeroMemory(vih
, sizeof(*vih
));
199 amt
->majortype
= MEDIATYPE_Video
;
200 if (GST_VIDEO_INFO_IS_RGB(&vinfo
)) {
201 bih
->biBitCount
= GST_VIDEO_FORMAT_INFO_BITS(vinfo
.finfo
);
202 switch (bih
->biBitCount
) {
203 case 16: amt
->subtype
= MEDIASUBTYPE_RGB555
; break;
204 case 24: amt
->subtype
= MEDIASUBTYPE_RGB24
; break;
205 case 32: amt
->subtype
= MEDIASUBTYPE_RGB32
; break;
207 FIXME("Unknown bpp %u\n", bih
->biBitCount
);
210 bih
->biCompression
= BI_RGB
;
212 amt
->subtype
= MEDIATYPE_Video
;
213 if (!(amt
->subtype
.Data1
= gst_video_format_to_fourcc(vinfo
.finfo
->format
)))
215 switch (amt
->subtype
.Data1
) {
216 case mmioFOURCC('I','4','2','0'):
217 case mmioFOURCC('Y','V','1','2'):
218 case mmioFOURCC('N','V','1','2'):
219 case mmioFOURCC('N','V','2','1'):
220 bih
->biBitCount
= 12; break;
221 case mmioFOURCC('Y','U','Y','2'):
222 case mmioFOURCC('Y','V','Y','U'):
223 bih
->biBitCount
= 16; break;
225 bih
->biCompression
= amt
->subtype
.Data1
;
227 bih
->biSizeImage
= width
* height
* bih
->biBitCount
/ 8;
228 vih
->AvgTimePerFrame
= 10000000;
229 vih
->AvgTimePerFrame
*= denom
;
230 vih
->AvgTimePerFrame
/= nom
;
231 vih
->rcSource
.left
= 0;
232 vih
->rcSource
.right
= width
;
233 vih
->rcSource
.top
= height
;
234 vih
->rcSource
.bottom
= 0;
235 vih
->rcTarget
= vih
->rcSource
;
236 bih
->biSize
= sizeof(*bih
);
237 bih
->biWidth
= width
;
238 bih
->biHeight
= height
;
243 static gboolean
accept_caps_sink(GstPad
*pad
, GstCaps
*caps
)
245 GSTOutPin
*pin
= gst_pad_get_element_private(pad
);
248 const char *typename
;
251 TRACE("%p %p\n", pad
, caps
);
253 arg
= gst_caps_get_structure(caps
, 0);
254 typename
= gst_structure_get_name(arg
);
255 if (!strcmp(typename
, "audio/x-raw")) {
257 ERR("Setting audio caps on non-audio pad?\n");
260 ret
= amt_from_gst_caps_audio(caps
, &amt
);
264 } else if (!strcmp(typename
, "video/x-raw")) {
266 ERR("Setting video caps on non-video pad?\n");
269 ret
= amt_from_gst_caps_video(caps
, &amt
);
274 FIXME("Unhandled type \"%s\"\n", typename
);
279 static gboolean
setcaps_sink(GstPad
*pad
, GstCaps
*caps
)
281 GSTOutPin
*pin
= gst_pad_get_element_private(pad
);
282 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pin
.pinInfo
.pFilter
;
285 const char *typename
;
288 TRACE("%p %p\n", pad
, caps
);
290 arg
= gst_caps_get_structure(caps
, 0);
291 typename
= gst_structure_get_name(arg
);
292 if (!strcmp(typename
, "audio/x-raw")) {
294 ERR("Setting audio caps on non-audio pad?\n");
297 ret
= amt_from_gst_caps_audio(caps
, &amt
);
298 } else if (!strcmp(typename
, "video/x-raw")) {
300 ERR("Setting video caps on non-video pad?\n");
303 ret
= amt_from_gst_caps_video(caps
, &amt
);
305 This
->props
.cbBuffer
= max(This
->props
.cbBuffer
, ((VIDEOINFOHEADER
*)amt
.pbFormat
)->bmiHeader
.biSizeImage
);
307 FIXME("Unhandled type \"%s\"\n", typename
);
310 TRACE("Linking returned %i for %s\n", ret
, typename
);
313 FreeMediaType(pin
->pmt
);
318 static gboolean
query_sink(GstPad
*pad
, GstObject
*parent
, GstQuery
*query
)
320 switch (GST_QUERY_TYPE (query
)) {
321 case GST_QUERY_ACCEPT_CAPS
:
325 gst_query_parse_accept_caps(query
, &caps
);
326 res
= accept_caps_sink(pad
, caps
);
327 gst_query_set_accept_caps_result(query
, res
);
328 return TRUE
; /* FIXME */
331 return gst_pad_query_default (pad
, parent
, query
);
335 static gboolean
gst_base_src_perform_seek(GSTImpl
*This
, GstEvent
*event
)
339 GstFormat seek_format
;
341 GstSeekType cur_type
, stop_type
;
346 BOOL thread
= !!This
->push_thread
;
348 TRACE("%p %p\n", This
, event
);
350 gst_event_parse_seek(event
, &rate
, &seek_format
, &flags
,
351 &cur_type
, &cur
, &stop_type
, &stop
);
353 if (seek_format
!= GST_FORMAT_BYTES
) {
354 FIXME("Not handling other format %i\n", seek_format
);
358 flush
= flags
& GST_SEEK_FLAG_FLUSH
;
359 seqnum
= gst_event_get_seqnum(event
);
361 /* send flush start */
363 tevent
= gst_event_new_flush_start();
364 gst_event_set_seqnum(tevent
, seqnum
);
365 gst_pad_push_event(This
->my_src
, tevent
);
366 if (This
->pInputPin
.pReader
)
367 IAsyncReader_BeginFlush(This
->pInputPin
.pReader
);
369 gst_pad_set_active(This
->my_src
, 1);
372 This
->nextofs
= This
->start
= cur
;
374 /* and prepare to continue streaming */
376 tevent
= gst_event_new_flush_stop(TRUE
);
377 gst_event_set_seqnum(tevent
, seqnum
);
378 gst_pad_push_event(This
->my_src
, tevent
);
379 if (This
->pInputPin
.pReader
)
380 IAsyncReader_EndFlush(This
->pInputPin
.pReader
);
382 gst_pad_set_active(This
->my_src
, 1);
388 static gboolean
event_src(GstPad
*pad
, GstObject
*parent
, GstEvent
*event
)
390 GSTImpl
*This
= gst_pad_get_element_private(pad
);
392 TRACE("%p %p\n", pad
, event
);
394 switch (event
->type
) {
396 return gst_base_src_perform_seek(This
, event
);
397 case GST_EVENT_FLUSH_START
:
398 EnterCriticalSection(&This
->filter
.csFilter
);
399 if (This
->pInputPin
.pReader
)
400 IAsyncReader_BeginFlush(This
->pInputPin
.pReader
);
401 LeaveCriticalSection(&This
->filter
.csFilter
);
403 case GST_EVENT_FLUSH_STOP
:
404 EnterCriticalSection(&This
->filter
.csFilter
);
405 if (This
->pInputPin
.pReader
)
406 IAsyncReader_EndFlush(This
->pInputPin
.pReader
);
407 LeaveCriticalSection(&This
->filter
.csFilter
);
410 FIXME("%p (%u) stub\n", event
, event
->type
);
413 return gst_pad_event_default(pad
, parent
, event
);
418 static gboolean
event_sink(GstPad
*pad
, GstObject
*parent
, GstEvent
*event
)
420 GSTOutPin
*pin
= gst_pad_get_element_private(pad
);
422 TRACE("%p %p\n", pad
, event
);
424 switch (event
->type
) {
425 case GST_EVENT_SEGMENT
: {
426 gdouble rate
, applied_rate
;
428 const GstSegment
*segment
;
430 gst_event_parse_segment(event
, &segment
);
432 pos
= segment
->position
;
433 stop
= segment
->stop
;
434 rate
= segment
->rate
;
435 applied_rate
= segment
->applied_rate
;
437 if (segment
->format
!= GST_FORMAT_TIME
) {
438 FIXME("Ignoring new segment because of format %i\n", segment
->format
);
442 gst_segment_copy_into(segment
, pin
->segment
);
449 if (pin
->pin
.pin
.pConnectedTo
)
450 IPin_NewSegment(pin
->pin
.pin
.pConnectedTo
, pos
, stop
, rate
*applied_rate
);
455 if (pin
->pin
.pin
.pConnectedTo
)
456 IPin_EndOfStream(pin
->pin
.pin
.pConnectedTo
);
458 case GST_EVENT_FLUSH_START
:
459 if (((GSTImpl
*)pin
->pin
.pin
.pinInfo
.pFilter
)->ignore_flush
) {
460 /* gst-plugins-base prior to 1.7 contains a bug which causes
461 * our sink pins to receive a flush-start event when the
462 * decodebin changes from PAUSED to READY (including
463 * PLAYING->PAUSED->READY), but no matching flush-stop event is
464 * sent. See <gst-plugins-base.git:60bad4815db966a8e4). Here we
465 * unset the flushing flag to avoid the problem. */
466 TRACE("Working around gst <1.7 bug, ignoring FLUSH_START\n");
467 GST_PAD_UNSET_FLUSHING (pad
);
470 if (pin
->pin
.pin
.pConnectedTo
)
471 IPin_BeginFlush(pin
->pin
.pin
.pConnectedTo
);
473 case GST_EVENT_FLUSH_STOP
:
474 gst_segment_init(pin
->segment
, GST_FORMAT_TIME
);
475 if (pin
->pin
.pin
.pConnectedTo
)
476 IPin_EndFlush(pin
->pin
.pin
.pConnectedTo
);
478 case GST_EVENT_CAPS
: {
480 gst_event_parse_caps(event
, &caps
);
481 return setcaps_sink(pad
, caps
);
484 TRACE("%p stub %s\n", event
, gst_event_type_get_name(event
->type
));
485 return gst_pad_event_default(pad
, parent
, event
);
489 static void release_sample(void *data
)
492 ret
= IMediaSample_Release((IMediaSample
*)data
);
493 TRACE("Releasing %p returns %u\n", data
, ret
);
496 static DWORD CALLBACK
push_data(LPVOID iface
)
498 LONGLONG maxlen
, curlen
;
499 GSTImpl
*This
= iface
;
505 IAsyncReader_Length(This
->pInputPin
.pReader
, &maxlen
, &curlen
);
509 TRACE("Waiting..\n");
511 WaitForSingleObject(This
->event
, INFINITE
);
513 TRACE("Starting..\n");
515 REFERENCE_TIME tStart
, tStop
;
522 TRACE("pAlloc: %p\n", This
->pInputPin
.pAlloc
);
523 hr
= IMemAllocator_GetBuffer(This
->pInputPin
.pAlloc
, &buf
, NULL
, NULL
, 0);
527 if (This
->nextofs
>= maxlen
)
529 len
= IMediaSample_GetSize(buf
);
530 if (This
->nextofs
+ len
> maxlen
)
531 len
= maxlen
- This
->nextofs
;
533 tStart
= MEDIATIME_FROM_BYTES(This
->nextofs
);
534 tStop
= tStart
+ MEDIATIME_FROM_BYTES(len
);
535 IMediaSample_SetTime(buf
, &tStart
, &tStop
);
537 hr
= IAsyncReader_Request(This
->pInputPin
.pReader
, buf
, 0);
539 IMediaSample_Release(buf
);
542 This
->nextofs
+= len
;
543 hr
= IAsyncReader_WaitForNext(This
->pInputPin
.pReader
, -1, &buf
, &user
);
544 if (FAILED(hr
) || !buf
) {
546 IMediaSample_Release(buf
);
550 IMediaSample_GetPointer(buf
, &data
);
551 bufsize
= IMediaSample_GetActualDataLength(buf
);
552 gstbuf
= gst_buffer_new_wrapped_full(0, data
, bufsize
, 0, bufsize
, buf
, release_sample_wrapper
);
553 IMediaSample_AddRef(buf
);
554 gst_mini_object_set_qdata(GST_MINI_OBJECT(gstbuf
), g_quark_from_static_string(media_quark_string
), buf
, release_sample_wrapper
);
556 IMediaSample_Release(buf
);
559 gstbuf
->duration
= gstbuf
->pts
= -1;
560 ret
= gst_pad_push(This
->my_src
, gstbuf
);
564 ERR("Sending returned: %i\n", ret
);
565 if (ret
== GST_FLOW_ERROR
)
567 else if (ret
== GST_FLOW_FLUSHING
)
568 hr
= VFW_E_WRONG_STATE
;
573 gst_pad_push_event(This
->my_src
, gst_event_new_eos());
575 TRACE("Almost stopping.. %08x\n", hr
);
577 IAsyncReader_WaitForNext(This
->pInputPin
.pReader
, 0, &buf
, &user
);
579 IMediaSample_Release(buf
);
582 TRACE("Stopping.. %08x\n", hr
);
586 static HRESULT WINAPI
GST_OutPin_QueryAccept(IPin
*iface
, const AM_MEDIA_TYPE
*pmt
)
588 GSTOutPin
*pin
= (GSTOutPin
*)iface
;
589 FIXME("stub %p\n", pin
);
593 static GstFlowReturn
got_data_sink(GstPad
*pad
, GstObject
*parent
, GstBuffer
*buf
)
595 GSTOutPin
*pin
= gst_pad_get_element_private(pad
);
596 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pin
.pinInfo
.pFilter
;
599 IMediaSample
*sample
;
602 TRACE("%p %p\n", pad
, buf
);
605 gst_buffer_unref(buf
);
606 TRACE("Triggering %p %p\n", pad
, pin
->caps_event
);
607 SetEvent(pin
->caps_event
);
611 hr
= BaseOutputPinImpl_GetDeliveryBuffer(&pin
->pin
, &sample
, NULL
, NULL
, 0);
613 if (hr
== VFW_E_NOT_CONNECTED
) {
614 gst_buffer_unref(buf
);
615 return GST_FLOW_NOT_LINKED
;
619 gst_buffer_unref(buf
);
620 ERR("Could not get a delivery buffer (%x), returning GST_FLOW_FLUSHING\n", hr
);
621 return GST_FLOW_FLUSHING
;
624 gst_buffer_map(buf
, &info
, GST_MAP_READ
);
626 hr
= IMediaSample_SetActualDataLength(sample
, info
.size
);
628 WARN("SetActualDataLength failed: %08x\n", hr
);
629 return GST_FLOW_FLUSHING
;
632 IMediaSample_GetPointer(sample
, &ptr
);
634 memcpy(ptr
, info
.data
, info
.size
);
636 gst_buffer_unmap(buf
, &info
);
638 if (GST_BUFFER_PTS_IS_VALID(buf
)) {
639 REFERENCE_TIME rtStart
= gst_segment_to_running_time(pin
->segment
, GST_FORMAT_TIME
, buf
->pts
);
643 if (GST_BUFFER_DURATION_IS_VALID(buf
)) {
644 REFERENCE_TIME tStart
= buf
->pts
/ 100;
645 REFERENCE_TIME tStop
= (buf
->pts
+ buf
->duration
) / 100;
646 REFERENCE_TIME rtStop
;
647 rtStop
= gst_segment_to_running_time(pin
->segment
, GST_FORMAT_TIME
, buf
->pts
+ buf
->duration
);
650 TRACE("Current time on %p: %i to %i ms\n", pin
, (int)(rtStart
/ 10000), (int)(rtStop
/ 10000));
651 IMediaSample_SetTime(sample
, &rtStart
, rtStop
>= 0 ? &rtStop
: NULL
);
652 IMediaSample_SetMediaTime(sample
, &tStart
, &tStop
);
654 IMediaSample_SetTime(sample
, rtStart
>= 0 ? &rtStart
: NULL
, NULL
);
655 IMediaSample_SetMediaTime(sample
, NULL
, NULL
);
658 IMediaSample_SetTime(sample
, NULL
, NULL
);
659 IMediaSample_SetMediaTime(sample
, NULL
, NULL
);
662 IMediaSample_SetDiscontinuity(sample
, GST_BUFFER_FLAG_IS_SET(buf
, GST_BUFFER_FLAG_DISCONT
));
663 IMediaSample_SetPreroll(sample
, GST_BUFFER_FLAG_IS_SET(buf
, GST_BUFFER_FLAG_LIVE
));
664 IMediaSample_SetSyncPoint(sample
, !GST_BUFFER_FLAG_IS_SET(buf
, GST_BUFFER_FLAG_DELTA_UNIT
));
666 if (!pin
->pin
.pin
.pConnectedTo
)
667 hr
= VFW_E_NOT_CONNECTED
;
669 hr
= IMemInputPin_Receive(pin
->pin
.pMemInputPin
, sample
);
671 TRACE("sending sample returned: %08x\n", hr
);
673 gst_buffer_unref(buf
);
674 IMediaSample_Release(sample
);
676 if (hr
== VFW_E_NOT_CONNECTED
)
677 return GST_FLOW_NOT_LINKED
;
680 return GST_FLOW_FLUSHING
;
685 static GstFlowReturn
request_buffer_src(GstPad
*pad
, GstObject
*parent
, guint64 ofs
, guint len
, GstBuffer
**buf
)
687 GSTImpl
*This
= gst_pad_get_element_private(pad
);
691 TRACE("%p %s %i %p\n", pad
, wine_dbgstr_longlong(ofs
), len
, buf
);
694 if (ofs
== (guint64
)-1)
695 ofs
= This
->nextpullofs
;
696 if (ofs
>= This
->filesize
) {
697 WARN("Reading past eof: %s, %u\n", wine_dbgstr_longlong(ofs
), len
);
700 if (len
+ ofs
> This
->filesize
)
701 len
= This
->filesize
- ofs
;
702 This
->nextpullofs
= ofs
+ len
;
704 *buf
= gst_buffer_new_and_alloc(len
);
705 gst_buffer_map(*buf
, &info
, GST_MAP_WRITE
);
706 hr
= IAsyncReader_SyncRead(This
->pInputPin
.pReader
, ofs
, len
, info
.data
);
707 gst_buffer_unmap(*buf
, &info
);
709 ERR("Returned %08x\n", hr
);
710 return GST_FLOW_ERROR
;
715 static DWORD CALLBACK
push_data_init(LPVOID iface
)
717 GSTImpl
*This
= iface
;
720 TRACE("Starting..\n");
723 GstFlowReturn ret
= request_buffer_src(This
->my_src
, NULL
, ofs
, 4096, &buf
);
725 ERR("Obtaining buffer returned: %i\n", ret
);
728 ret
= gst_pad_push(This
->my_src
, buf
);
731 TRACE("Sending returned: %i\n", ret
);
735 TRACE("Stopping..\n");
739 static void removed_decoded_pad(GstElement
*bin
, GstPad
*pad
, gpointer user
)
741 GSTImpl
*This
= (GSTImpl
*)user
;
745 TRACE("%p %p %p\n", This
, bin
, pad
);
747 EnterCriticalSection(&This
->filter
.csFilter
);
748 for (x
= 0; x
< This
->cStreams
; ++x
) {
749 if (This
->ppPins
[x
]->their_src
== pad
)
752 if (x
== This
->cStreams
)
754 pin
= This
->ppPins
[x
];
755 gst_pad_unlink(pin
->their_src
, pin
->my_sink
);
756 gst_object_unref(pin
->their_src
);
757 pin
->their_src
= NULL
;
759 TRACE("Removed %i/%i\n", x
, This
->cStreams
);
760 LeaveCriticalSection(&This
->filter
.csFilter
);
763 static void init_new_decoded_pad(GstElement
*bin
, GstPad
*pad
, GSTImpl
*This
)
767 const char *typename
;
769 AM_MEDIA_TYPE amt
= {{0}};
775 int isvid
= 0, isaud
= 0;
778 TRACE("%p %p %p\n", This
, bin
, pad
);
780 piOutput
.dir
= PINDIR_OUTPUT
;
781 piOutput
.pFilter
= (IBaseFilter
*)This
;
782 name
= gst_pad_get_name(pad
);
783 MultiByteToWideChar(CP_UNIXCP
, 0, name
, -1, piOutput
.achName
, sizeof(piOutput
.achName
) / sizeof(piOutput
.achName
[0]) - 1);
784 TRACE("Name: %s\n", name
);
785 strcpy(my_name
, "qz_sink_");
786 strcat(my_name
, name
);
788 piOutput
.achName
[sizeof(piOutput
.achName
) / sizeof(piOutput
.achName
[0]) - 1] = 0;
790 caps
= gst_pad_query_caps(pad
, NULL
);
791 caps
= gst_caps_make_writable(caps
);
792 arg
= gst_caps_get_structure(caps
, 0);
793 typename
= gst_structure_get_name(arg
);
795 mypad
= gst_pad_new(my_name
, GST_PAD_SINK
);
796 gst_pad_set_chain_function(mypad
, got_data_sink_wrapper
);
797 gst_pad_set_event_function(mypad
, event_sink_wrapper
);
798 gst_pad_set_query_function(mypad
, query_sink_wrapper
);
800 if (!strcmp(typename
, "audio/x-raw")) {
802 } else if (!strcmp(typename
, "video/x-raw")) {
805 FIXME("Unknown type \'%s\'\n", typename
);
809 hr
= GST_AddPin(This
, &piOutput
, &amt
);
815 pin
= This
->ppPins
[This
->cStreams
- 1];
816 gst_pad_set_element_private(mypad
, pin
);
817 pin
->my_sink
= mypad
;
821 gst_segment_init(pin
->segment
, GST_FORMAT_TIME
);
822 ret
= gst_pad_link(pad
, mypad
);
824 gst_pad_set_active(mypad
, 1);
826 TRACE("Linking: %i\n", ret
);
829 pin
->their_src
= pad
;
830 gst_object_ref(pin
->their_src
);
834 static void existing_new_pad(GstElement
*bin
, GstPad
*pad
, gpointer user
)
836 GSTImpl
*This
= (GSTImpl
*)user
;
839 TRACE("%p %p %p\n", This
, bin
, pad
);
841 if (gst_pad_is_linked(pad
))
844 /* Still holding our own lock */
846 init_new_decoded_pad(bin
, pad
, This
);
850 EnterCriticalSection(&This
->filter
.csFilter
);
851 for (x
= 0; x
< This
->cStreams
; ++x
) {
852 GSTOutPin
*pin
= This
->ppPins
[x
];
853 if (!pin
->their_src
) {
854 gst_segment_init(pin
->segment
, GST_FORMAT_TIME
);
855 if (gst_pad_link(pad
, pin
->my_sink
) >= 0) {
856 pin
->their_src
= pad
;
857 gst_object_ref(pin
->their_src
);
859 LeaveCriticalSection(&This
->filter
.csFilter
);
864 init_new_decoded_pad(bin
, pad
, This
);
865 LeaveCriticalSection(&This
->filter
.csFilter
);
868 static gboolean
query_function(GstPad
*pad
, GstObject
*parent
, GstQuery
*query
)
870 GSTImpl
*This
= gst_pad_get_element_private(pad
);
875 TRACE("%p %p %p\n", This
, pad
, query
);
877 switch (GST_QUERY_TYPE(query
)) {
878 case GST_QUERY_DURATION
:
879 gst_query_parse_duration (query
, &format
, NULL
);
880 if (format
== GST_FORMAT_PERCENT
) {
881 gst_query_set_duration (query
, GST_FORMAT_PERCENT
, GST_FORMAT_PERCENT_MAX
);
884 ret
= gst_pad_query_convert (pad
, GST_FORMAT_BYTES
, This
->filesize
, format
, &duration
);
885 gst_query_set_duration(query
, format
, duration
);
887 case GST_QUERY_SEEKING
:
888 gst_query_parse_seeking (query
, &format
, NULL
, NULL
, NULL
);
889 TRACE("Seeking %i %i\n", format
, GST_FORMAT_BYTES
);
890 if (format
!= GST_FORMAT_BYTES
)
892 gst_query_set_seeking(query
, GST_FORMAT_BYTES
, 1, 0, This
->filesize
);
894 case GST_QUERY_SCHEDULING
:
895 gst_query_set_scheduling(query
, GST_SCHEDULING_FLAG_SEEKABLE
, 1, -1, 0);
896 gst_query_add_scheduling_mode(query
, GST_PAD_MODE_PUSH
);
897 gst_query_add_scheduling_mode(query
, GST_PAD_MODE_PULL
);
900 TRACE("Unhandled query type: %s\n", GST_QUERY_TYPE_NAME(query
));
905 static gboolean
activate_push(GstPad
*pad
, gboolean activate
)
907 GSTImpl
*This
= gst_pad_get_element_private(pad
);
909 TRACE("%p %p %u\n", This
, pad
, activate
);
911 EnterCriticalSection(&This
->filter
.csFilter
);
913 TRACE("Deactivating\n");
915 IAsyncReader_BeginFlush(This
->pInputPin
.pReader
);
916 if (This
->push_thread
) {
917 WaitForSingleObject(This
->push_thread
, -1);
918 CloseHandle(This
->push_thread
);
919 This
->push_thread
= NULL
;
922 IAsyncReader_EndFlush(This
->pInputPin
.pReader
);
923 if (This
->filter
.state
== State_Stopped
)
924 This
->nextofs
= This
->start
;
925 } else if (!This
->push_thread
) {
926 TRACE("Activating\n");
928 This
->push_thread
= CreateThread(NULL
, 0, push_data_init
, This
, 0, NULL
);
930 This
->push_thread
= CreateThread(NULL
, 0, push_data
, This
, 0, NULL
);
932 LeaveCriticalSection(&This
->filter
.csFilter
);
936 static gboolean
activate_mode(GstPad
*pad
, GstObject
*parent
, GstPadMode mode
, gboolean activate
)
938 TRACE("%p %p 0x%x %u\n", pad
, parent
, mode
, activate
);
940 case GST_PAD_MODE_PULL
:
942 case GST_PAD_MODE_PUSH
:
943 return activate_push(pad
, activate
);
950 static void no_more_pads(GstElement
*decodebin
, gpointer user
)
952 GSTImpl
*This
= (GSTImpl
*)user
;
953 TRACE("%p %p\n", This
, decodebin
);
954 SetEvent(This
->event
);
957 static GstAutoplugSelectResult
autoplug_blacklist(GstElement
*bin
, GstPad
*pad
, GstCaps
*caps
, GstElementFactory
*fact
, gpointer user
)
959 const char *name
= gst_element_factory_get_longname(fact
);
961 if (strstr(name
, "Player protection")) {
962 WARN("Blacklisted a/52 decoder because it only works in Totem\n");
963 return GST_AUTOPLUG_SELECT_SKIP
;
965 if (!strcmp(name
, "Fluendo Hardware Accelerated Video Decoder")) {
966 WARN("Disabled video acceleration since it breaks in wine\n");
967 return GST_AUTOPLUG_SELECT_SKIP
;
969 TRACE("using \"%s\"\n", name
);
970 return GST_AUTOPLUG_SELECT_TRY
;
973 static GstBusSyncReply
watch_bus(GstBus
*bus
, GstMessage
*msg
, gpointer data
)
975 GSTImpl
*This
= data
;
977 gchar
*dbg_info
= NULL
;
979 TRACE("%p %p %p\n", This
, bus
, msg
);
981 if (GST_MESSAGE_TYPE(msg
) & GST_MESSAGE_ERROR
) {
982 gst_message_parse_error(msg
, &err
, &dbg_info
);
983 FIXME("%s: %s\n", GST_OBJECT_NAME(msg
->src
), err
->message
);
984 WARN("%s\n", dbg_info
);
985 SetEvent(This
->event
);
986 } else if (GST_MESSAGE_TYPE(msg
) & GST_MESSAGE_WARNING
) {
987 gst_message_parse_warning(msg
, &err
, &dbg_info
);
988 WARN("%s: %s\n", GST_OBJECT_NAME(msg
->src
), err
->message
);
989 WARN("%s\n", dbg_info
);
997 static void unknown_type(GstElement
*bin
, GstPad
*pad
, GstCaps
*caps
, gpointer user
)
999 gchar
*strcaps
= gst_caps_to_string(caps
);
1000 FIXME("Could not find a filter for caps: %s\n", strcaps
);
1004 static HRESULT
GST_Connect(GSTInPin
*pPin
, IPin
*pConnectPin
, ALLOCATOR_PROPERTIES
*props
)
1006 GSTImpl
*This
= (GSTImpl
*)pPin
->pin
.pinInfo
.pFilter
;
1009 LONGLONG avail
, duration
;
1010 GstStaticPadTemplate src_template
= GST_STATIC_PAD_TEMPLATE(
1014 GST_STATIC_CAPS_ANY
);
1016 TRACE("%p %p %p\n", pPin
, pConnectPin
, props
);
1018 This
->props
= *props
;
1019 IAsyncReader_Length(pPin
->pReader
, &This
->filesize
, &avail
);
1022 This
->bus
= gst_bus_new();
1023 gst_bus_set_sync_handler(This
->bus
, watch_bus_wrapper
, This
, NULL
);
1026 This
->gstfilter
= gst_element_factory_make("decodebin", NULL
);
1027 if (!This
->gstfilter
) {
1028 FIXME("Could not make source filter, are gstreamer-plugins-* installed for %u bits?\n",
1029 8 * (int)sizeof(void*));
1032 gst_element_set_bus(This
->gstfilter
, This
->bus
);
1033 g_signal_connect(This
->gstfilter
, "pad-added", G_CALLBACK(existing_new_pad_wrapper
), This
);
1034 g_signal_connect(This
->gstfilter
, "pad-removed", G_CALLBACK(removed_decoded_pad_wrapper
), This
);
1035 g_signal_connect(This
->gstfilter
, "autoplug-select", G_CALLBACK(autoplug_blacklist_wrapper
), This
);
1036 g_signal_connect(This
->gstfilter
, "unknown-type", G_CALLBACK(unknown_type_wrapper
), This
);
1038 This
->my_src
= gst_pad_new_from_static_template(&src_template
, "quartz-src");
1039 gst_pad_set_getrange_function(This
->my_src
, request_buffer_src_wrapper
);
1040 gst_pad_set_query_function(This
->my_src
, query_function_wrapper
);
1041 gst_pad_set_activatemode_function(This
->my_src
, activate_mode_wrapper
);
1042 gst_pad_set_event_function(This
->my_src
, event_src_wrapper
);
1043 gst_pad_set_element_private (This
->my_src
, This
);
1044 This
->their_sink
= gst_element_get_static_pad(This
->gstfilter
, "sink");
1046 g_signal_connect(This
->gstfilter
, "no-more-pads", G_CALLBACK(no_more_pads_wrapper
), This
);
1047 ret
= gst_pad_link(This
->my_src
, This
->their_sink
);
1049 ERR("Returns: %i\n", ret
);
1052 This
->start
= This
->nextofs
= This
->nextpullofs
= This
->stop
= 0;
1054 /* Add initial pins */
1055 This
->initial
= This
->discont
= TRUE
;
1056 ResetEvent(This
->event
);
1057 gst_element_set_state(This
->gstfilter
, GST_STATE_PLAYING
);
1058 WaitForSingleObject(This
->event
, -1);
1059 gst_element_get_state(This
->gstfilter
, NULL
, NULL
, -1);
1062 WARN("Ret: %i\n", ret
);
1064 } else if (!This
->cStreams
) {
1065 FIXME("GStreamer could not find any streams\n");
1068 gst_pad_query_duration(This
->ppPins
[0]->their_src
, GST_FORMAT_TIME
, &duration
);
1069 for (i
= 0; i
< This
->cStreams
; ++i
) {
1070 This
->ppPins
[i
]->seek
.llDuration
= This
->ppPins
[i
]->seek
.llStop
= duration
/ 100;
1071 This
->ppPins
[i
]->seek
.llCurrent
= 0;
1072 if (!This
->ppPins
[i
]->seek
.llDuration
)
1073 This
->ppPins
[i
]->seek
.dwCapabilities
= 0;
1074 WaitForSingleObject(This
->ppPins
[i
]->caps_event
, -1);
1078 *props
= This
->props
;
1080 This
->ignore_flush
= TRUE
;
1081 gst_element_set_state(This
->gstfilter
, GST_STATE_READY
);
1082 gst_element_get_state(This
->gstfilter
, NULL
, NULL
, -1);
1083 This
->ignore_flush
= FALSE
;
1085 This
->initial
= FALSE
;
1087 /* don't set active during test-play, as we don't want to push/pull data
1088 * from the source yet */
1089 gst_pad_set_active(This
->my_src
, 1);
1091 This
->nextofs
= This
->nextpullofs
= 0;
1095 static inline GSTOutPin
*impl_from_IMediaSeeking( IMediaSeeking
*iface
)
1097 return CONTAINING_RECORD(iface
, GSTOutPin
, seek
.IMediaSeeking_iface
);
1100 static IPin
* WINAPI
GST_GetPin(BaseFilter
*iface
, int pos
)
1102 GSTImpl
*This
= (GSTImpl
*)iface
;
1103 TRACE("%p: Asking for pos %x\n", This
, pos
);
1105 if (pos
> This
->cStreams
|| pos
< 0)
1109 IPin_AddRef((IPin
*)&This
->pInputPin
);
1110 return (IPin
*)&This
->pInputPin
;
1114 IPin_AddRef((IPin
*)This
->ppPins
[pos
- 1]);
1115 return (IPin
*)This
->ppPins
[pos
- 1];
1119 static LONG WINAPI
GST_GetPinCount(BaseFilter
*iface
)
1121 GSTImpl
*This
= (GSTImpl
*)iface
;
1122 TRACE("%p -> %u\n", This
, This
->cStreams
+ 1);
1123 return (This
->cStreams
+ 1);
1126 static const BaseFilterFuncTable BaseFuncTable
= {
1131 IUnknown
* CALLBACK
Gstreamer_Splitter_create(IUnknown
*pUnkOuter
, HRESULT
*phr
)
1133 IUnknown
*obj
= NULL
;
1137 TRACE("%p %p\n", pUnkOuter
, phr
);
1139 if (!Gstreamer_init())
1147 This
= CoTaskMemAlloc(sizeof(*This
));
1148 obj
= (IUnknown
*)This
;
1151 *phr
= E_OUTOFMEMORY
;
1155 BaseFilter_Init(&This
->filter
, &GST_Vtbl
, &CLSID_Gstreamer_Splitter
, (DWORD_PTR
)(__FILE__
": GSTImpl.csFilter"), &BaseFuncTable
);
1158 This
->ppPins
= NULL
;
1159 This
->push_thread
= NULL
;
1160 This
->event
= CreateEventW(NULL
, 0, 0, NULL
);
1163 piInput
= &This
->pInputPin
.pin
.pinInfo
;
1164 piInput
->dir
= PINDIR_INPUT
;
1165 piInput
->pFilter
= (IBaseFilter
*)This
;
1166 lstrcpynW(piInput
->achName
, wcsInputPinName
, sizeof(piInput
->achName
) / sizeof(piInput
->achName
[0]));
1167 This
->pInputPin
.pin
.IPin_iface
.lpVtbl
= &GST_InputPin_Vtbl
;
1168 This
->pInputPin
.pin
.refCount
= 1;
1169 This
->pInputPin
.pin
.pConnectedTo
= NULL
;
1170 This
->pInputPin
.pin
.pCritSec
= &This
->filter
.csFilter
;
1171 ZeroMemory(&This
->pInputPin
.pin
.mtCurrent
, sizeof(AM_MEDIA_TYPE
));
1174 TRACE("returning %p\n", obj
);
1179 static void GST_Destroy(GSTImpl
*This
)
1181 IPin
*connected
= NULL
;
1185 TRACE("Destroying %p\n", This
);
1187 CloseHandle(This
->event
);
1189 /* Don't need to clean up output pins, disconnecting input pin will do that */
1190 IPin_ConnectedTo((IPin
*)&This
->pInputPin
, &connected
);
1192 hr
= IPin_Disconnect(connected
);
1194 IPin_Release(connected
);
1195 hr
= IPin_Disconnect((IPin
*)&This
->pInputPin
);
1198 pinref
= IPin_Release((IPin
*)&This
->pInputPin
);
1200 /* Valgrind could find this, if I kill it here */
1201 ERR("pinref should be null, is %u, destroying anyway\n", pinref
);
1202 assert((LONG
)pinref
> 0);
1205 pinref
= IPin_Release((IPin
*)&This
->pInputPin
);
1208 gst_bus_set_sync_handler(This
->bus
, NULL
, NULL
, NULL
);
1209 gst_object_unref(This
->bus
);
1211 BaseFilter_Destroy(&This
->filter
);
1212 CoTaskMemFree(This
);
1215 static HRESULT WINAPI
GST_QueryInterface(IBaseFilter
*iface
, REFIID riid
, LPVOID
*ppv
)
1217 GSTImpl
*This
= (GSTImpl
*)iface
;
1219 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1223 if (IsEqualIID(riid
, &IID_IUnknown
))
1225 else if (IsEqualIID(riid
, &IID_IPersist
))
1227 else if (IsEqualIID(riid
, &IID_IMediaFilter
))
1229 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
1233 IUnknown_AddRef((IUnknown
*)(*ppv
));
1237 if (!IsEqualIID(riid
, &IID_IPin
) && !IsEqualIID(riid
, &IID_IVideoWindow
) &&
1238 !IsEqualIID(riid
, &IID_IAMFilterMiscFlags
))
1239 FIXME("No interface for %s!\n", debugstr_guid(riid
));
1241 return E_NOINTERFACE
;
1244 static ULONG WINAPI
GST_Release(IBaseFilter
*iface
)
1246 GSTImpl
*This
= (GSTImpl
*)iface
;
1247 ULONG refCount
= InterlockedDecrement(&This
->filter
.refCount
);
1249 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
1257 static HRESULT WINAPI
GST_Stop(IBaseFilter
*iface
)
1259 GSTImpl
*This
= (GSTImpl
*)iface
;
1261 TRACE("(%p)\n", This
);
1265 if (This
->gstfilter
) {
1266 This
->ignore_flush
= TRUE
;
1267 gst_element_set_state(This
->gstfilter
, GST_STATE_READY
);
1268 gst_element_get_state(This
->gstfilter
, NULL
, NULL
, -1);
1269 This
->ignore_flush
= FALSE
;
1274 static HRESULT WINAPI
GST_Pause(IBaseFilter
*iface
)
1277 GSTImpl
*This
= (GSTImpl
*)iface
;
1279 GstStateChangeReturn ret
;
1281 TRACE("(%p)\n", This
);
1283 if (!This
->gstfilter
)
1284 return VFW_E_NOT_CONNECTED
;
1288 gst_element_get_state(This
->gstfilter
, &now
, NULL
, -1);
1289 if (now
== GST_STATE_PAUSED
)
1291 if (now
!= GST_STATE_PLAYING
)
1292 hr
= IBaseFilter_Run(iface
, -1);
1295 ret
= gst_element_set_state(This
->gstfilter
, GST_STATE_PAUSED
);
1296 if (ret
== GST_STATE_CHANGE_ASYNC
)
1301 static HRESULT WINAPI
GST_Run(IBaseFilter
*iface
, REFERENCE_TIME tStart
)
1304 GSTImpl
*This
= (GSTImpl
*)iface
;
1307 HRESULT hr_any
= VFW_E_NOT_CONNECTED
;
1309 TRACE("(%p)->(%s)\n", This
, wine_dbgstr_longlong(tStart
));
1313 if (!This
->gstfilter
)
1314 return VFW_E_NOT_CONNECTED
;
1316 EnterCriticalSection(&This
->filter
.csFilter
);
1317 This
->filter
.rtStreamStart
= tStart
;
1318 LeaveCriticalSection(&This
->filter
.csFilter
);
1320 gst_element_get_state(This
->gstfilter
, &now
, NULL
, -1);
1321 if (now
== GST_STATE_PLAYING
)
1323 if (now
== GST_STATE_PAUSED
) {
1324 GstStateChangeReturn ret
;
1325 ret
= gst_element_set_state(This
->gstfilter
, GST_STATE_PLAYING
);
1326 if (ret
== GST_STATE_CHANGE_ASYNC
)
1331 EnterCriticalSection(&This
->filter
.csFilter
);
1332 gst_element_set_state(This
->gstfilter
, GST_STATE_PLAYING
);
1333 This
->filter
.rtStreamStart
= tStart
;
1335 for (i
= 0; i
< This
->cStreams
; i
++) {
1336 hr
= BaseOutputPinImpl_Active((BaseOutputPin
*)This
->ppPins
[i
]);
1337 if (SUCCEEDED(hr
)) {
1342 LeaveCriticalSection(&This
->filter
.csFilter
);
1347 static HRESULT WINAPI
GST_GetState(IBaseFilter
*iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
1349 GSTImpl
*This
= (GSTImpl
*)iface
;
1351 GstState now
, pending
;
1352 GstStateChangeReturn ret
;
1354 TRACE("(%p)->(%d, %p)\n", This
, dwMilliSecsTimeout
, pState
);
1358 if (!This
->gstfilter
) {
1359 *pState
= State_Stopped
;
1363 ret
= gst_element_get_state(This
->gstfilter
, &now
, &pending
, dwMilliSecsTimeout
== INFINITE
? -1 : dwMilliSecsTimeout
* 1000);
1365 if (ret
== GST_STATE_CHANGE_ASYNC
)
1366 hr
= VFW_S_STATE_INTERMEDIATE
;
1371 case GST_STATE_PAUSED
: *pState
= State_Paused
; return hr
;
1372 case GST_STATE_PLAYING
: *pState
= State_Running
; return hr
;
1373 default: *pState
= State_Stopped
; return hr
;
1377 static HRESULT WINAPI
GST_FindPin(IBaseFilter
*iface
, LPCWSTR Id
, IPin
**ppPin
)
1379 FIXME("(%p)->(%s,%p) stub\n", iface
, debugstr_w(Id
), ppPin
);
1383 static const IBaseFilterVtbl GST_Vtbl
= {
1385 BaseFilterImpl_AddRef
,
1387 BaseFilterImpl_GetClassID
,
1392 BaseFilterImpl_SetSyncSource
,
1393 BaseFilterImpl_GetSyncSource
,
1394 BaseFilterImpl_EnumPins
,
1396 BaseFilterImpl_QueryFilterInfo
,
1397 BaseFilterImpl_JoinFilterGraph
,
1398 BaseFilterImpl_QueryVendorInfo
1401 static HRESULT WINAPI
GST_ChangeCurrent(IMediaSeeking
*iface
)
1403 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1404 TRACE("(%p)\n", This
);
1408 static HRESULT WINAPI
GST_ChangeStop(IMediaSeeking
*iface
)
1410 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1411 TRACE("(%p)\n", This
);
1415 static HRESULT WINAPI
GST_ChangeRate(IMediaSeeking
*iface
)
1417 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1418 GstEvent
*ev
= gst_event_new_seek(This
->seek
.dRate
, GST_FORMAT_TIME
, 0, GST_SEEK_TYPE_NONE
, -1, GST_SEEK_TYPE_NONE
, -1);
1419 TRACE("(%p) New rate %g\n", This
, This
->seek
.dRate
);
1421 gst_pad_push_event(This
->my_sink
, ev
);
1425 static HRESULT WINAPI
GST_Seeking_QueryInterface(IMediaSeeking
*iface
, REFIID riid
, void **ppv
)
1427 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1428 return IUnknown_QueryInterface((IUnknown
*)This
, riid
, ppv
);
1431 static ULONG WINAPI
GST_Seeking_AddRef(IMediaSeeking
*iface
)
1433 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1434 return IUnknown_AddRef((IUnknown
*)This
);
1437 static ULONG WINAPI
GST_Seeking_Release(IMediaSeeking
*iface
)
1439 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1440 return IUnknown_Release((IUnknown
*)This
);
1443 static HRESULT WINAPI
GST_Seeking_GetCurrentPosition(IMediaSeeking
*iface
, REFERENCE_TIME
*pos
)
1445 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1447 TRACE("(%p)->(%p)\n", This
, pos
);
1454 if (!This
->their_src
) {
1455 *pos
= This
->seek
.llCurrent
;
1456 TRACE("Cached value\n");
1457 if (This
->seek
.llDuration
)
1463 if (!gst_pad_query_position(This
->their_src
, GST_FORMAT_TIME
, pos
)) {
1464 WARN("Could not query position\n");
1468 This
->seek
.llCurrent
= *pos
;
1472 static GstSeekType
type_from_flags(DWORD flags
)
1474 switch (flags
& AM_SEEKING_PositioningBitsMask
) {
1475 case AM_SEEKING_NoPositioning
:
1476 return GST_SEEK_TYPE_NONE
;
1477 case AM_SEEKING_AbsolutePositioning
:
1478 case AM_SEEKING_RelativePositioning
:
1479 return GST_SEEK_TYPE_SET
;
1480 case AM_SEEKING_IncrementalPositioning
:
1481 return GST_SEEK_TYPE_END
;
1483 return GST_SEEK_TYPE_NONE
;
1486 static HRESULT WINAPI
GST_Seeking_SetPositions(IMediaSeeking
*iface
,
1487 REFERENCE_TIME
*pCur
, DWORD curflags
, REFERENCE_TIME
*pStop
,
1491 GSTOutPin
*This
= impl_from_IMediaSeeking(iface
);
1493 GstSeekType curtype
, stoptype
;
1495 gint64 stop_pos
= 0, curr_pos
= 0;
1497 TRACE("(%p)->(%p, 0x%x, %p, 0x%x)\n", This
, pCur
, curflags
, pStop
, stopflags
);
1501 if (!This
->seek
.llDuration
)
1504 hr
= SourceSeekingImpl_SetPositions(iface
, pCur
, curflags
, pStop
, stopflags
);
1505 if (!This
->their_src
)
1508 curtype
= type_from_flags(curflags
);
1509 stoptype
= type_from_flags(stopflags
);
1510 if (curflags
& AM_SEEKING_SeekToKeyFrame
)
1511 f
|= GST_SEEK_FLAG_KEY_UNIT
;
1512 if (curflags
& AM_SEEKING_Segment
)
1513 f
|= GST_SEEK_FLAG_SEGMENT
;
1514 if (!(curflags
& AM_SEEKING_NoFlush
))
1515 f
|= GST_SEEK_FLAG_FLUSH
;
1517 if (((curflags
& AM_SEEKING_PositioningBitsMask
) == AM_SEEKING_RelativePositioning
) ||
1518 ((stopflags
& AM_SEEKING_PositioningBitsMask
) == AM_SEEKING_RelativePositioning
)) {
1520 gst_pad_query_position (This
->my_sink
, GST_FORMAT_TIME
, &tmp_pos
);
1521 if ((curflags
& AM_SEEKING_PositioningBitsMask
) == AM_SEEKING_RelativePositioning
)
1523 if ((stopflags
& AM_SEEKING_PositioningBitsMask
) == AM_SEEKING_RelativePositioning
)
1527 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);
1528 if (gst_pad_push_event(This
->my_sink
, e
))
1534 static const IMediaSeekingVtbl GST_Seeking_Vtbl
=
1536 GST_Seeking_QueryInterface
,
1538 GST_Seeking_Release
,
1539 SourceSeekingImpl_GetCapabilities
,
1540 SourceSeekingImpl_CheckCapabilities
,
1541 SourceSeekingImpl_IsFormatSupported
,
1542 SourceSeekingImpl_QueryPreferredFormat
,
1543 SourceSeekingImpl_GetTimeFormat
,
1544 SourceSeekingImpl_IsUsingTimeFormat
,
1545 SourceSeekingImpl_SetTimeFormat
,
1546 SourceSeekingImpl_GetDuration
,
1547 SourceSeekingImpl_GetStopPosition
,
1548 GST_Seeking_GetCurrentPosition
,
1549 SourceSeekingImpl_ConvertTimeFormat
,
1550 GST_Seeking_SetPositions
,
1551 SourceSeekingImpl_GetPositions
,
1552 SourceSeekingImpl_GetAvailable
,
1553 SourceSeekingImpl_SetRate
,
1554 SourceSeekingImpl_GetRate
,
1555 SourceSeekingImpl_GetPreroll
1558 static inline GSTOutPin
*impl_from_IQualityControl( IQualityControl
*iface
)
1560 return (GSTOutPin
*)CONTAINING_RECORD(iface
, GSTOutPin
, IQualityControl_iface
);
1563 static HRESULT WINAPI
GST_QualityControl_QueryInterface(IQualityControl
*iface
, REFIID riid
, void **ppv
)
1565 GSTOutPin
*pin
= impl_from_IQualityControl(iface
);
1566 return IPin_QueryInterface((IPin
*)pin
, riid
, ppv
);
1569 static ULONG WINAPI
GST_QualityControl_AddRef(IQualityControl
*iface
)
1571 GSTOutPin
*pin
= impl_from_IQualityControl(iface
);
1572 return IPin_AddRef((IPin
*)pin
);
1575 static ULONG WINAPI
GST_QualityControl_Release(IQualityControl
*iface
)
1577 GSTOutPin
*pin
= impl_from_IQualityControl(iface
);
1578 return IPin_Release((IPin
*)pin
);
1581 static HRESULT WINAPI
GST_QualityControl_Notify(IQualityControl
*iface
, IBaseFilter
*sender
, Quality qm
)
1583 GSTOutPin
*pin
= impl_from_IQualityControl(iface
);
1584 REFERENCE_TIME late
= qm
.Late
;
1585 TRACE("(%p)->(%p, qm)\n", pin
, sender
);
1587 if (qm
.Late
< 0 && -qm
.Late
> qm
.TimeStamp
)
1588 late
= -qm
.TimeStamp
;
1589 gst_pad_push_event(pin
->my_sink
, gst_event_new_qos(late
<= 0 ? GST_QOS_TYPE_OVERFLOW
: GST_QOS_TYPE_UNDERFLOW
, 1000./qm
.Proportion
, late
*100, qm
.TimeStamp
*100));
1593 static HRESULT WINAPI
GST_QualityControl_SetSink(IQualityControl
*iface
, IQualityControl
*tonotify
)
1595 GSTOutPin
*pin
= impl_from_IQualityControl(iface
);
1596 TRACE("(%p)->(%p)\n", pin
, pin
);
1601 static const IQualityControlVtbl GSTOutPin_QualityControl_Vtbl
= {
1602 GST_QualityControl_QueryInterface
,
1603 GST_QualityControl_AddRef
,
1604 GST_QualityControl_Release
,
1605 GST_QualityControl_Notify
,
1606 GST_QualityControl_SetSink
1609 static HRESULT WINAPI
GSTOutPin_QueryInterface(IPin
*iface
, REFIID riid
, void **ppv
)
1611 GSTOutPin
*This
= (GSTOutPin
*)iface
;
1613 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1617 if (IsEqualIID(riid
, &IID_IUnknown
))
1619 else if (IsEqualIID(riid
, &IID_IPin
))
1621 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
1623 else if (IsEqualIID(riid
, &IID_IQualityControl
))
1624 *ppv
= &This
->IQualityControl_iface
;
1627 IUnknown_AddRef((IUnknown
*)(*ppv
));
1630 FIXME("No interface for %s!\n", debugstr_guid(riid
));
1631 return E_NOINTERFACE
;
1634 static ULONG WINAPI
GSTOutPin_Release(IPin
*iface
)
1636 GSTOutPin
*This
= (GSTOutPin
*)iface
;
1637 ULONG refCount
= InterlockedDecrement(&This
->pin
.pin
.refCount
);
1639 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
1644 if (This
->their_src
) {
1645 gst_pad_unlink(This
->their_src
, This
->my_sink
);
1646 gst_object_unref(This
->their_src
);
1648 gst_object_unref(This
->my_sink
);
1649 CloseHandle(This
->caps_event
);
1650 DeleteMediaType(This
->pmt
);
1651 FreeMediaType(&This
->pin
.pin
.mtCurrent
);
1652 gst_segment_free(This
->segment
);
1654 gst_object_unref(This
->gstpool
);
1655 if (This
->pin
.pAllocator
)
1656 IMemAllocator_Release(This
->pin
.pAllocator
);
1657 CoTaskMemFree(This
);
1663 static HRESULT WINAPI
GSTOutPin_GetMediaType(BasePin
*iface
, int iPosition
, AM_MEDIA_TYPE
*pmt
)
1665 GSTOutPin
*This
= (GSTOutPin
*)iface
;
1667 TRACE("(%p)->(%i, %p)\n", This
, iPosition
, pmt
);
1670 return E_INVALIDARG
;
1673 return VFW_S_NO_MORE_ITEMS
;
1675 CopyMediaType(pmt
, This
->pmt
);
1680 static HRESULT WINAPI
GSTOutPin_DecideBufferSize(BaseOutputPin
*iface
, IMemAllocator
*pAlloc
, ALLOCATOR_PROPERTIES
*ppropInputRequest
)
1682 GSTOutPin
*This
= (GSTOutPin
*)iface
;
1683 TRACE("(%p)->(%p, %p)\n", This
, pAlloc
, ppropInputRequest
);
1688 static HRESULT WINAPI
GSTOutPin_DecideAllocator(BaseOutputPin
*iface
, IMemInputPin
*pPin
, IMemAllocator
**pAlloc
)
1691 GSTOutPin
*This
= (GSTOutPin
*)iface
;
1692 GSTImpl
*GSTfilter
= (GSTImpl
*)This
->pin
.pin
.pinInfo
.pFilter
;
1694 TRACE("(%p)->(%p, %p)\n", This
, pPin
, pAlloc
);
1697 if (GSTfilter
->pInputPin
.pAlloc
)
1699 hr
= IMemInputPin_NotifyAllocator(pPin
, GSTfilter
->pInputPin
.pAlloc
, FALSE
);
1702 *pAlloc
= GSTfilter
->pInputPin
.pAlloc
;
1703 IMemAllocator_AddRef(*pAlloc
);
1707 hr
= VFW_E_NO_ALLOCATOR
;
1712 static HRESULT WINAPI
GSTOutPin_BreakConnect(BaseOutputPin
*This
)
1716 TRACE("(%p)->()\n", This
);
1718 EnterCriticalSection(This
->pin
.pCritSec
);
1719 if (!This
->pin
.pConnectedTo
|| !This
->pMemInputPin
)
1720 hr
= VFW_E_NOT_CONNECTED
;
1723 hr
= IPin_Disconnect(This
->pin
.pConnectedTo
);
1724 IPin_Disconnect((IPin
*)This
);
1726 LeaveCriticalSection(This
->pin
.pCritSec
);
1731 static const IPinVtbl GST_OutputPin_Vtbl
= {
1732 GSTOutPin_QueryInterface
,
1735 BaseOutputPinImpl_Connect
,
1736 BaseOutputPinImpl_ReceiveConnection
,
1737 BaseOutputPinImpl_Disconnect
,
1738 BasePinImpl_ConnectedTo
,
1739 BasePinImpl_ConnectionMediaType
,
1740 BasePinImpl_QueryPinInfo
,
1741 BasePinImpl_QueryDirection
,
1742 BasePinImpl_QueryId
,
1743 GST_OutPin_QueryAccept
,
1744 BasePinImpl_EnumMediaTypes
,
1745 BasePinImpl_QueryInternalConnections
,
1746 BaseOutputPinImpl_EndOfStream
,
1747 BaseOutputPinImpl_BeginFlush
,
1748 BaseOutputPinImpl_EndFlush
,
1749 BasePinImpl_NewSegment
1752 static const BaseOutputPinFuncTable output_BaseOutputFuncTable
= {
1755 BaseOutputPinImpl_AttemptConnection
,
1756 BasePinImpl_GetMediaTypeVersion
,
1757 GSTOutPin_GetMediaType
1759 GSTOutPin_DecideBufferSize
,
1760 GSTOutPin_DecideAllocator
,
1761 GSTOutPin_BreakConnect
1764 static HRESULT
GST_AddPin(GSTImpl
*This
, const PIN_INFO
*piOutput
, const AM_MEDIA_TYPE
*amt
)
1767 This
->ppPins
= CoTaskMemRealloc(This
->ppPins
, (This
->cStreams
+ 1) * sizeof(IPin
*));
1769 hr
= BaseOutputPin_Construct(&GST_OutputPin_Vtbl
, sizeof(GSTOutPin
), piOutput
, &output_BaseOutputFuncTable
, &This
->filter
.csFilter
, (IPin
**)(This
->ppPins
+ This
->cStreams
));
1770 if (SUCCEEDED(hr
)) {
1771 GSTOutPin
*pin
= This
->ppPins
[This
->cStreams
];
1772 memset((char*)pin
+ sizeof(pin
->pin
), 0, sizeof(GSTOutPin
) - sizeof(pin
->pin
));
1773 pin
->pmt
= CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
));
1774 CopyMediaType(pin
->pmt
, amt
);
1775 pin
->pin
.pin
.pinInfo
.pFilter
= (LPVOID
)This
;
1776 pin
->caps_event
= CreateEventW(NULL
, 0, 0, NULL
);
1777 pin
->segment
= gst_segment_new();
1779 pin
->IQualityControl_iface
.lpVtbl
= &GSTOutPin_QualityControl_Vtbl
;
1780 SourceSeeking_Init(&pin
->seek
, &GST_Seeking_Vtbl
, GST_ChangeStop
, GST_ChangeCurrent
, GST_ChangeRate
, &This
->filter
.csFilter
);
1781 BaseFilterImpl_IncrementPinVersion((BaseFilter
*)This
);
1783 ERR("Failed with error %x\n", hr
);
1787 static HRESULT
GST_RemoveOutputPins(GSTImpl
*This
)
1791 GSTOutPin
**ppOldPins
= This
->ppPins
;
1793 TRACE("(%p)\n", This
);
1796 if (!This
->gstfilter
)
1798 gst_element_set_bus(This
->gstfilter
, NULL
);
1799 gst_element_set_state(This
->gstfilter
, GST_STATE_NULL
);
1800 gst_pad_unlink(This
->my_src
, This
->their_sink
);
1801 gst_object_unref(This
->my_src
);
1802 gst_object_unref(This
->their_sink
);
1803 This
->my_src
= This
->their_sink
= NULL
;
1805 for (i
= 0; i
< This
->cStreams
; i
++) {
1806 hr
= BaseOutputPinImpl_BreakConnect(&ppOldPins
[i
]->pin
);
1807 TRACE("Disconnect: %08x\n", hr
);
1808 IPin_Release((IPin
*)ppOldPins
[i
]);
1811 This
->ppPins
= NULL
;
1812 gst_object_unref(This
->gstfilter
);
1813 This
->gstfilter
= NULL
;
1814 BaseFilterImpl_IncrementPinVersion((BaseFilter
*)This
);
1815 CoTaskMemFree(ppOldPins
);
1819 static ULONG WINAPI
GSTInPin_Release(IPin
*iface
)
1821 GSTInPin
*This
= (GSTInPin
*)iface
;
1822 ULONG refCount
= InterlockedDecrement(&This
->pin
.refCount
);
1824 TRACE("(%p)->() Release from %d\n", iface
, refCount
+ 1);
1826 FreeMediaType(&This
->pin
.mtCurrent
);
1828 IMemAllocator_Release(This
->pAlloc
);
1829 This
->pAlloc
= NULL
;
1830 This
->pin
.IPin_iface
.lpVtbl
= NULL
;
1836 static HRESULT WINAPI
GSTInPin_ReceiveConnection(IPin
*iface
, IPin
*pReceivePin
, const AM_MEDIA_TYPE
*pmt
)
1838 PIN_DIRECTION pindirReceive
;
1840 GSTInPin
*This
= (GSTInPin
*)iface
;
1842 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, pReceivePin
, pmt
);
1843 dump_AM_MEDIA_TYPE(pmt
);
1847 EnterCriticalSection(This
->pin
.pCritSec
);
1848 if (!This
->pin
.pConnectedTo
) {
1849 ALLOCATOR_PROPERTIES props
;
1852 props
.cbBuffer
= 16384;
1856 if (SUCCEEDED(hr
) && IPin_QueryAccept(iface
, pmt
) != S_OK
)
1857 hr
= VFW_E_TYPE_NOT_ACCEPTED
;
1858 if (SUCCEEDED(hr
)) {
1859 IPin_QueryDirection(pReceivePin
, &pindirReceive
);
1860 if (pindirReceive
!= PINDIR_OUTPUT
) {
1861 ERR("Can't connect from non-output pin\n");
1862 hr
= VFW_E_INVALID_DIRECTION
;
1866 This
->pReader
= NULL
;
1867 This
->pAlloc
= NULL
;
1869 hr
= IPin_QueryInterface(pReceivePin
, &IID_IAsyncReader
, (LPVOID
*)&This
->pReader
);
1871 hr
= GST_Connect(This
, pReceivePin
, &props
);
1873 hr
= IAsyncReader_RequestAllocator(This
->pReader
, NULL
, &props
, &This
->pAlloc
);
1874 if (SUCCEEDED(hr
)) {
1875 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
1876 This
->pin
.pConnectedTo
= pReceivePin
;
1877 IPin_AddRef(pReceivePin
);
1878 hr
= IMemAllocator_Commit(This
->pAlloc
);
1879 SetEvent(((GSTImpl
*)This
->pin
.pinInfo
.pFilter
)->event
);
1881 GST_RemoveOutputPins((GSTImpl
*)This
->pin
.pinInfo
.pFilter
);
1883 IAsyncReader_Release(This
->pReader
);
1884 This
->pReader
= NULL
;
1886 IMemAllocator_Release(This
->pAlloc
);
1887 This
->pAlloc
= NULL
;
1889 TRACE("Size: %i\n", props
.cbBuffer
);
1891 hr
= VFW_E_ALREADY_CONNECTED
;
1892 LeaveCriticalSection(This
->pin
.pCritSec
);
1896 static HRESULT WINAPI
GSTInPin_Disconnect(IPin
*iface
)
1899 GSTInPin
*This
= (GSTInPin
*)iface
;
1902 TRACE("(%p)\n", This
);
1906 hr
= IBaseFilter_GetState(This
->pin
.pinInfo
.pFilter
, INFINITE
, &state
);
1907 EnterCriticalSection(This
->pin
.pCritSec
);
1908 if (This
->pin
.pConnectedTo
) {
1909 GSTImpl
*Parser
= (GSTImpl
*)This
->pin
.pinInfo
.pFilter
;
1911 if (SUCCEEDED(hr
) && state
== State_Stopped
) {
1912 IMemAllocator_Decommit(This
->pAlloc
);
1913 IPin_Disconnect(This
->pin
.pConnectedTo
);
1914 This
->pin
.pConnectedTo
= NULL
;
1915 hr
= GST_RemoveOutputPins(Parser
);
1917 hr
= VFW_E_NOT_STOPPED
;
1920 LeaveCriticalSection(This
->pin
.pCritSec
);
1924 static HRESULT WINAPI
GSTInPin_QueryAccept(IPin
*iface
, const AM_MEDIA_TYPE
*pmt
)
1926 GSTInPin
*This
= (GSTInPin
*)iface
;
1928 TRACE("(%p)->(%p)\n", This
, pmt
);
1929 dump_AM_MEDIA_TYPE(pmt
);
1931 if (IsEqualIID(&pmt
->majortype
, &MEDIATYPE_Stream
))
1936 static HRESULT WINAPI
GSTInPin_EndOfStream(IPin
*iface
)
1938 GSTInPin
*pin
= (GSTInPin
*)iface
;
1939 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pinInfo
.pFilter
;
1941 FIXME("Propagate message on %p\n", This
);
1945 static HRESULT WINAPI
GSTInPin_BeginFlush(IPin
*iface
)
1947 GSTInPin
*pin
= (GSTInPin
*)iface
;
1948 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pinInfo
.pFilter
;
1950 FIXME("Propagate message on %p\n", This
);
1954 static HRESULT WINAPI
GSTInPin_EndFlush(IPin
*iface
)
1956 GSTInPin
*pin
= (GSTInPin
*)iface
;
1957 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pinInfo
.pFilter
;
1959 FIXME("Propagate message on %p\n", This
);
1963 static HRESULT WINAPI
GSTInPin_NewSegment(IPin
*iface
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
1965 GSTInPin
*pin
= (GSTInPin
*)iface
;
1966 GSTImpl
*This
= (GSTImpl
*)pin
->pin
.pinInfo
.pFilter
;
1968 BasePinImpl_NewSegment(iface
, tStart
, tStop
, dRate
);
1969 FIXME("Propagate message on %p\n", This
);
1973 static HRESULT WINAPI
GSTInPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
1975 GSTInPin
*This
= (GSTInPin
*)iface
;
1977 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, debugstr_guid(riid
), ppv
);
1981 if (IsEqualIID(riid
, &IID_IUnknown
))
1983 else if (IsEqualIID(riid
, &IID_IPin
))
1985 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
1987 return IBaseFilter_QueryInterface(This
->pin
.pinInfo
.pFilter
, &IID_IMediaSeeking
, ppv
);
1992 IUnknown_AddRef((IUnknown
*)(*ppv
));
1996 FIXME("No interface for %s!\n", debugstr_guid(riid
));
1998 return E_NOINTERFACE
;
2001 static HRESULT WINAPI
GSTInPin_EnumMediaTypes(IPin
*iface
, IEnumMediaTypes
**ppEnum
)
2003 BasePin
*This
= (BasePin
*)iface
;
2005 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
2007 return EnumMediaTypes_Construct(This
, BasePinImpl_GetMediaType
, BasePinImpl_GetMediaTypeVersion
, ppEnum
);
2010 static const IPinVtbl GST_InputPin_Vtbl
= {
2011 GSTInPin_QueryInterface
,
2014 BaseInputPinImpl_Connect
,
2015 GSTInPin_ReceiveConnection
,
2016 GSTInPin_Disconnect
,
2017 BasePinImpl_ConnectedTo
,
2018 BasePinImpl_ConnectionMediaType
,
2019 BasePinImpl_QueryPinInfo
,
2020 BasePinImpl_QueryDirection
,
2021 BasePinImpl_QueryId
,
2022 GSTInPin_QueryAccept
,
2023 GSTInPin_EnumMediaTypes
,
2024 BasePinImpl_QueryInternalConnections
,
2025 GSTInPin_EndOfStream
,
2026 GSTInPin_BeginFlush
,
2031 pthread_mutex_t cb_list_lock
= PTHREAD_MUTEX_INITIALIZER
;
2032 pthread_cond_t cb_list_cond
= PTHREAD_COND_INITIALIZER
;
2033 struct list cb_list
= LIST_INIT(cb_list
);
2035 void CALLBACK
perform_cb(TP_CALLBACK_INSTANCE
*instance
, void *user
)
2037 struct cb_data
*cbdata
= user
;
2039 TRACE("got cb type: 0x%x\n", cbdata
->type
);
2041 switch(cbdata
->type
)
2045 struct watch_bus_data
*data
= &cbdata
->u
.watch_bus_data
;
2046 cbdata
->u
.watch_bus_data
.ret
= watch_bus(data
->bus
, data
->msg
, data
->user
);
2049 case EXISTING_NEW_PAD
:
2051 struct existing_new_pad_data
*data
= &cbdata
->u
.existing_new_pad_data
;
2052 existing_new_pad(data
->bin
, data
->pad
, data
->user
);
2055 case QUERY_FUNCTION
:
2057 struct query_function_data
*data
= &cbdata
->u
.query_function_data
;
2058 cbdata
->u
.query_function_data
.ret
= query_function(data
->pad
, data
->parent
, data
->query
);
2063 struct activate_mode_data
*data
= &cbdata
->u
.activate_mode_data
;
2064 cbdata
->u
.activate_mode_data
.ret
= activate_mode(data
->pad
, data
->parent
, data
->mode
, data
->activate
);
2069 struct no_more_pads_data
*data
= &cbdata
->u
.no_more_pads_data
;
2070 no_more_pads(data
->decodebin
, data
->user
);
2073 case REQUEST_BUFFER_SRC
:
2075 struct request_buffer_src_data
*data
= &cbdata
->u
.request_buffer_src_data
;
2076 cbdata
->u
.request_buffer_src_data
.ret
= request_buffer_src(data
->pad
, data
->parent
,
2077 data
->ofs
, data
->len
, data
->buf
);
2082 struct event_src_data
*data
= &cbdata
->u
.event_src_data
;
2083 cbdata
->u
.event_src_data
.ret
= event_src(data
->pad
, data
->parent
, data
->event
);
2088 struct event_sink_data
*data
= &cbdata
->u
.event_sink_data
;
2089 cbdata
->u
.event_sink_data
.ret
= event_sink(data
->pad
, data
->parent
, data
->event
);
2092 case ACCEPT_CAPS_SINK
:
2094 struct accept_caps_sink_data
*data
= &cbdata
->u
.accept_caps_sink_data
;
2095 cbdata
->u
.accept_caps_sink_data
.ret
= accept_caps_sink(data
->pad
, data
->caps
);
2100 struct setcaps_sink_data
*data
= &cbdata
->u
.setcaps_sink_data
;
2101 cbdata
->u
.setcaps_sink_data
.ret
= setcaps_sink(data
->pad
, data
->caps
);
2106 struct got_data_sink_data
*data
= &cbdata
->u
.got_data_sink_data
;
2107 cbdata
->u
.got_data_sink_data
.ret
= got_data_sink(data
->pad
, data
->parent
, data
->buf
);
2112 struct got_data_data
*data
= &cbdata
->u
.got_data_data
;
2113 cbdata
->u
.got_data_data
.ret
= got_data(data
->pad
, data
->parent
, data
->buf
);
2116 case REMOVED_DECODED_PAD
:
2118 struct removed_decoded_pad_data
*data
= &cbdata
->u
.removed_decoded_pad_data
;
2119 removed_decoded_pad(data
->bin
, data
->pad
, data
->user
);
2122 case AUTOPLUG_BLACKLIST
:
2124 struct autoplug_blacklist_data
*data
= &cbdata
->u
.autoplug_blacklist_data
;
2125 cbdata
->u
.autoplug_blacklist_data
.ret
= autoplug_blacklist(data
->bin
,
2126 data
->pad
, data
->caps
, data
->fact
, data
->user
);
2131 struct unknown_type_data
*data
= &cbdata
->u
.unknown_type_data
;
2132 unknown_type(data
->bin
, data
->pad
, data
->caps
, data
->user
);
2135 case RELEASE_SAMPLE
:
2137 struct release_sample_data
*data
= &cbdata
->u
.release_sample_data
;
2138 release_sample(data
->data
);
2141 case TRANSFORM_PAD_ADDED
:
2143 struct transform_pad_added_data
*data
= &cbdata
->u
.transform_pad_added_data
;
2144 Gstreamer_transform_pad_added(data
->filter
, data
->pad
, data
->user
);
2149 struct query_sink_data
*data
= &cbdata
->u
.query_sink_data
;
2150 cbdata
->u
.query_sink_data
.ret
= query_sink(data
->pad
, data
->parent
,
2156 pthread_mutex_lock(&cbdata
->lock
);
2157 cbdata
->finished
= 1;
2158 pthread_cond_broadcast(&cbdata
->cond
);
2159 pthread_mutex_unlock(&cbdata
->lock
);
2162 static DWORD WINAPI
dispatch_thread(void *user
)
2164 struct cb_data
*cbdata
;
2166 pthread_mutex_lock(&cb_list_lock
);
2169 pthread_cond_wait(&cb_list_cond
, &cb_list_lock
);
2171 while(!list_empty(&cb_list
)){
2172 cbdata
= LIST_ENTRY(list_head(&cb_list
), struct cb_data
, entry
);
2173 list_remove(&cbdata
->entry
);
2175 TrySubmitThreadpoolCallback(&perform_cb
, cbdata
, NULL
);
2179 pthread_mutex_unlock(&cb_list_lock
);
2184 void start_dispatch_thread(void)
2186 pthread_key_create(&wine_gst_key
, NULL
);
2187 CloseHandle(CreateThread(NULL
, 0, &dispatch_thread
, NULL
, 0, NULL
));