2 * GStreamer wrapper filter
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/app/gstappsink.h>
26 #include <gst/app/gstappsrc.h>
27 #include <gst/app/gstappbuffer.h>
29 #include "gst_private.h"
30 #include "gst_guids.h"
46 #include "wine/unicode.h"
47 #include "wine/debug.h"
50 DEFINE_GUID(WMMEDIASUBTYPE_MP3, 0x00000055, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
52 WINE_DEFAULT_DEBUG_CHANNEL(gstreamer);
59 static const IBaseFilterVtbl GSTTf_Vtbl;
61 static gboolean match_element(GstPluginFeature *feature, gpointer gdata) {
62 struct typeinfo *data = (struct typeinfo*)gdata;
63 GstElementFactory *factory;
66 if (!GST_IS_ELEMENT_FACTORY(feature))
68 factory = GST_ELEMENT_FACTORY(feature);
69 if (!strstr(gst_element_factory_get_klass(factory), data->type))
71 for (list = gst_element_factory_get_static_pad_templates(factory); list; list = list->next) {
72 GstStaticPadTemplate *pad = (GstStaticPadTemplate*)list->data;
75 if (pad->direction != GST_PAD_SINK)
77 caps = gst_static_caps_get(&pad->static_caps);
78 ret = gst_caps_is_always_compatible(caps, data->caps);
86 static const char *Gstreamer_FindMatch(const char *strcaps)
91 GstElementFactory *bestfactory = NULL;
92 GstCaps *caps = gst_caps_from_string(strcaps);
95 data.type = "Decoder";
96 copy = gst_default_registry_feature_filter(match_element, 0, &data);
97 for (list = copy; list; list = list->next) {
98 GstElementFactory *factory = (GstElementFactory*)list->data;
100 rank = gst_plugin_feature_get_rank(GST_PLUGIN_FEATURE(factory));
101 if (rank > bestrank || !bestrank) {
103 bestfactory = factory;
106 gst_caps_unref(caps);
110 FIXME("Could not find plugin for %s\n", strcaps);
113 return gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(bestfactory));
116 typedef struct GstTfImpl {
118 IUnknown *seekthru_unk;
119 const char *gstreamer_name;
121 GstPad *my_src, *my_sink, *their_src, *their_sink;
125 static HRESULT WINAPI Gstreamer_transform_ProcessBegin(TransformFilter *iface) {
126 GstTfImpl *This = (GstTfImpl*)iface;
129 ret = gst_element_set_state(This->filter, GST_STATE_PLAYING);
130 TRACE("Returned: %i\n", ret);
134 static HRESULT WINAPI Gstreamer_transform_DecideBufferSize(TransformFilter *tf, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
136 GstTfImpl *This = (GstTfImpl*)tf;
137 ALLOCATOR_PROPERTIES actual;
139 if (!ppropInputRequest->cbAlign)
140 ppropInputRequest->cbAlign = 1;
142 ppropInputRequest->cbBuffer = This->cbBuffer;
144 if (!ppropInputRequest->cBuffers)
145 ppropInputRequest->cBuffers = 1;
147 return IMemAllocator_SetProperties(pAlloc, ppropInputRequest, &actual);
150 static void release_sample(void *data) {
151 TRACE("Releasing %p\n", data);
152 IMediaSample_Release((IMediaSample *)data);
155 static GstFlowReturn got_data(GstPad *pad, GstBuffer *buf) {
156 GstTfImpl *This = gst_pad_get_element_private(pad);
157 IMediaSample *sample = GST_APP_BUFFER(buf)->priv;
158 REFERENCE_TIME tStart, tStop;
161 if (GST_BUFFER_TIMESTAMP_IS_VALID(buf) &&
162 GST_BUFFER_DURATION_IS_VALID(buf)) {
163 tStart = buf->timestamp / 100;
164 tStop = tStart + buf->duration / 100;
165 IMediaSample_SetTime(sample, &tStart, &tStop);
168 IMediaSample_SetTime(sample, NULL, NULL);
169 if (GST_BUFFER_OFFSET_IS_VALID(buf) &&
170 GST_BUFFER_OFFSET_END_IS_VALID(buf)) {
171 tStart = buf->offset / 100;
172 tStop = buf->offset_end / 100;
173 IMediaSample_SetMediaTime(sample, &tStart, &tStop);
176 IMediaSample_SetMediaTime(sample, NULL, NULL);
178 IMediaSample_SetDiscontinuity(sample, GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_DISCONT));
179 IMediaSample_SetPreroll(sample, GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_PREROLL));
180 IMediaSample_SetSyncPoint(sample, !GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_DELTA_UNIT));
182 hr = BaseOutputPinImpl_Deliver((BaseOutputPin*)This->tf.ppPins[1], sample);
183 gst_buffer_unref(buf);
185 return GST_FLOW_WRONG_STATE;
187 return GST_FLOW_RESEND;
191 static GstFlowReturn request_buffer(GstPad *pad, guint64 ofs, guint size, GstCaps *caps, GstBuffer **buf) {
192 GstTfImpl *This = gst_pad_get_element_private(pad);
193 IMediaSample *sample;
196 TRACE("Requesting buffer\n");
198 hr = BaseOutputPinImpl_GetDeliveryBuffer((BaseOutputPin*)This->tf.ppPins[1], &sample, NULL, NULL, 0);
200 ERR("Could not get output buffer: %08x\n", hr);
201 return GST_FLOW_WRONG_STATE;
203 IMediaSample_SetActualDataLength(sample, size);
204 IMediaSample_GetPointer(sample, &ptr);
205 *buf = gst_app_buffer_new(ptr, size, release_sample, sample);
208 IMediaSample_Release(sample);
209 ERR("Out of memory\n");
210 return GST_FLOW_ERROR;
213 caps = gst_pad_get_caps_reffed(This->my_sink);
214 gst_buffer_set_caps(*buf, caps);
218 static HRESULT WINAPI Gstreamer_transform_ProcessData(TransformFilter *iface, IMediaSample *sample) {
219 GstTfImpl *This = (GstTfImpl*)iface;
220 REFERENCE_TIME tStart, tStop;
225 TRACE("Reading %p\n", sample);
227 EnterCriticalSection(&This->tf.filter.csFilter);
228 IMediaSample_GetPointer(sample, &data);
229 buf = gst_app_buffer_new(data, IMediaSample_GetActualDataLength(sample), release_sample, sample);
231 LeaveCriticalSection(&This->tf.filter.csFilter);
234 gst_buffer_set_caps(buf, gst_pad_get_caps_reffed(This->my_src));
235 IMediaSample_AddRef(sample);
236 buf->duration = buf->timestamp = -1;
237 hr = IMediaSample_GetTime(sample, &tStart, &tStop);
239 buf->timestamp = tStart * 100;
241 buf->duration = (tStop - tStart)*100;
243 if (IMediaSample_GetMediaTime(sample, &tStart, &tStop) == S_OK) {
244 buf->offset = tStart * 100;
245 buf->offset_end = tStop * 100;
247 if (IMediaSample_IsDiscontinuity(sample) == S_OK)
248 GST_BUFFER_FLAG_SET(buf, GST_BUFFER_FLAG_DISCONT);
249 if (IMediaSample_IsPreroll(sample) == S_OK)
250 GST_BUFFER_FLAG_SET(buf, GST_BUFFER_FLAG_PREROLL);
251 if (IMediaSample_IsSyncPoint(sample) != S_OK)
252 GST_BUFFER_FLAG_SET(buf, GST_BUFFER_FLAG_DELTA_UNIT);
253 LeaveCriticalSection(&This->tf.filter.csFilter);
254 ret = gst_pad_push(This->my_src, buf);
256 WARN("Sending returned: %i\n", ret);
257 if (ret == GST_FLOW_ERROR)
259 if (ret == GST_FLOW_WRONG_STATE)
260 return VFW_E_WRONG_STATE;
261 if (ret == GST_FLOW_RESEND)
266 static HRESULT WINAPI Gstreamer_transform_ProcessEnd(TransformFilter *iface) {
267 GstTfImpl *This = (GstTfImpl*)iface;
270 ret = gst_element_set_state(This->filter, GST_STATE_PAUSED);
271 TRACE("Returned: %i\n", ret);
275 static void Gstreamer_transform_pad_added(GstElement *filter, GstPad *pad, GstTfImpl *This)
278 if (!GST_PAD_IS_SRC(pad))
281 ret = gst_pad_link(pad, This->my_sink);
283 WARN("Failed to link with %i\n", ret);
284 This->their_src = pad;
286 gst_pad_set_active(pad, TRUE);
287 gst_pad_set_active(This->my_sink, TRUE);
290 static HRESULT Gstreamer_transform_ConnectInput(GstTfImpl *This, const AM_MEDIA_TYPE *amt, GstCaps *capsin, GstCaps *capsout) {
292 int done = 0, found = 0, ret;
294 This->filter = gst_element_factory_make(This->gstreamer_name, NULL);
296 FIXME("Could not make %s filter\n", This->gstreamer_name);
299 This->my_src = gst_pad_new(NULL, GST_PAD_SRC);
300 gst_pad_set_element_private (This->my_src, This);
302 This->my_sink = gst_pad_new(NULL, GST_PAD_SINK);
303 gst_pad_set_chain_function(This->my_sink, got_data);
304 gst_pad_set_bufferalloc_function(This->my_sink, request_buffer);
305 gst_pad_set_element_private (This->my_sink, This);
307 ret = gst_pad_set_caps(This->my_src, capsin);
309 WARN("Failed to set caps on own source with %i\n", ret);
313 ret = gst_pad_set_caps(This->my_sink, capsout);
315 WARN("Failed to set caps on own sink with %i\n", ret);
319 it = gst_element_iterate_sink_pads(This->filter);
323 switch (gst_iterator_next(it, &item)) {
324 case GST_ITERATOR_RESYNC:
325 gst_iterator_resync (it);
327 case GST_ITERATOR_OK:
328 This->their_sink = item;
329 case GST_ITERATOR_ERROR:
330 case GST_ITERATOR_DONE:
335 gst_iterator_free(it);
336 if (!This->their_sink) {
337 ERR("Could not find sink on filter %s\n", This->gstreamer_name);
341 it = gst_element_iterate_src_pads(This->filter);
342 gst_iterator_resync(it);
347 switch (gst_iterator_next(it, &item)) {
348 case GST_ITERATOR_RESYNC:
349 gst_iterator_resync (it);
351 case GST_ITERATOR_OK:
352 This->their_src = item;
353 case GST_ITERATOR_ERROR:
354 case GST_ITERATOR_DONE:
359 gst_iterator_free(it);
360 found = !!This->their_src;
362 g_signal_connect(This->filter, "pad-added", G_CALLBACK(Gstreamer_transform_pad_added), This);
363 ret = gst_pad_link(This->my_src, This->their_sink);
365 WARN("Failed to link with %i\n", ret);
370 Gstreamer_transform_pad_added(This->filter, This->their_src, This);
372 if (!gst_pad_is_linked(This->my_sink))
375 TRACE("Connected\n");
379 static HRESULT WINAPI Gstreamer_transform_Cleanup(TransformFilter *tf, PIN_DIRECTION dir) {
380 GstTfImpl *This = (GstTfImpl*)tf;
382 if (dir == PINDIR_INPUT)
385 gst_element_set_state(This->filter, GST_STATE_NULL);
386 gst_object_unref(This->filter);
390 gst_pad_unlink(This->my_src, This->their_sink);
391 gst_object_unref(This->my_src);
394 gst_pad_unlink(This->their_src, This->my_sink);
395 gst_object_unref(This->my_sink);
397 This->my_sink = This->my_src = This->their_sink = This->their_src = NULL;
398 FIXME("%p stub\n", This);
403 static HRESULT WINAPI Gstreamer_transform_EndOfStream(TransformFilter *iface) {
404 GstTfImpl *This = (GstTfImpl*)iface;
407 gst_pad_push_event(This->my_src, gst_event_new_eos());
411 static HRESULT WINAPI Gstreamer_transform_BeginFlush(TransformFilter *iface) {
412 GstTfImpl *This = (GstTfImpl*)iface;
415 gst_pad_push_event(This->my_src, gst_event_new_flush_start());
419 static HRESULT WINAPI Gstreamer_transform_EndFlush(TransformFilter *iface) {
420 GstTfImpl *This = (GstTfImpl*)iface;
423 gst_pad_push_event(This->my_src, gst_event_new_flush_stop());
427 static HRESULT WINAPI Gstreamer_transform_NewSegment(TransformFilter *iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {
428 GstTfImpl *This = (GstTfImpl*)iface;
431 gst_pad_push_event(This->my_src, gst_event_new_new_segment_full(1,
432 1.0, dRate, GST_FORMAT_TIME, 0, tStop <= tStart ? -1 : tStop * 100, tStart*100));
436 static HRESULT WINAPI Gstreamer_transform_QOS(TransformFilter *iface, IBaseFilter *sender, Quality qm) {
437 GstTfImpl *This = (GstTfImpl*)iface;
438 gst_pad_push_event(This->my_sink, gst_event_new_qos(1000. / qm.Proportion, qm.Late * 100, qm.TimeStamp * 100));
439 return QualityControlImpl_Notify((IQualityControl*)&iface->qcimpl, sender, qm);
442 static HRESULT Gstreamer_transform_create(IUnknown *punkout, const CLSID *clsid, const char *name, const TransformFilterFuncTable *vtbl, void **obj)
446 if (FAILED(TransformFilter_Construct(&GSTTf_Vtbl, sizeof(GstTfImpl), clsid, vtbl, (IBaseFilter**)&This)))
447 return E_OUTOFMEMORY;
450 ISeekingPassThru *passthru;
451 CoCreateInstance(&CLSID_SeekingPassThru, (IUnknown*)This, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&This->seekthru_unk);
452 IUnknown_QueryInterface(This->seekthru_unk, &IID_ISeekingPassThru, (void**)&passthru);
453 ISeekingPassThru_Init(passthru, FALSE, (IPin*)This->tf.ppPins[0]);
454 ISeekingPassThru_Release(passthru);
457 This->gstreamer_name = name;
463 static HRESULT WINAPI Gstreamer_Mp3_QueryConnect(TransformFilter *iface, const AM_MEDIA_TYPE *amt) {
464 GstTfImpl *This = (GstTfImpl*)iface;
465 TRACE("%p %p\n", This, amt);
466 dump_AM_MEDIA_TYPE(amt);
468 if ( (!IsEqualGUID(&amt->majortype, &MEDIATYPE_Audio) &&
469 !IsEqualGUID(&amt->majortype, &MEDIATYPE_Stream)) ||
470 (!IsEqualGUID(&amt->subtype, &MEDIASUBTYPE_MPEG1AudioPayload) &&
471 !IsEqualGUID(&amt->subtype, &WMMEDIASUBTYPE_MP3))
472 || !IsEqualGUID(&amt->formattype, &FORMAT_WaveFormatEx))
478 static HRESULT WINAPI Gstreamer_Mp3_SetMediaType(TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE *amt) {
479 GstTfImpl *This = (GstTfImpl*)tf;
480 GstCaps *capsin, *capsout;
481 AM_MEDIA_TYPE *outpmt = &This->tf.pmt;
482 WAVEFORMATEX *wfx, *wfxin;
486 if (dir != PINDIR_INPUT)
489 if (Gstreamer_Mp3_QueryConnect(&This->tf, amt) == S_FALSE || !amt->pbFormat)
490 return VFW_E_TYPE_NOT_ACCEPTED;
492 wfxin = (WAVEFORMATEX*)amt->pbFormat;
493 switch (wfxin->wFormatTag) {
494 case WAVE_FORMAT_MPEGLAYER3:
497 case WAVE_FORMAT_MPEG: {
498 MPEG1WAVEFORMAT *mpgformat = (MPEG1WAVEFORMAT*)wfxin;
499 layer = mpgformat->fwHeadLayer;
503 FIXME("Unhandled tag %x\n", wfxin->wFormatTag);
507 FreeMediaType(outpmt);
508 CopyMediaType(outpmt, amt);
510 outpmt->subtype = MEDIASUBTYPE_PCM;
511 outpmt->formattype = FORMAT_WaveFormatEx;
512 outpmt->cbFormat = sizeof(*wfx);
513 CoTaskMemFree(outpmt->pbFormat);
514 wfx = CoTaskMemAlloc(outpmt->cbFormat);
515 outpmt->pbFormat = (BYTE*)wfx;
516 wfx->wFormatTag = WAVE_FORMAT_PCM;
517 wfx->wBitsPerSample = 16;
518 wfx->nSamplesPerSec = wfxin->nSamplesPerSec;
519 wfx->nChannels = wfxin->nChannels;
520 wfx->nBlockAlign = wfx->wBitsPerSample * wfx->nChannels / 8;
522 wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign;
524 capsin = gst_caps_new_simple("audio/mpeg",
525 "mpegversion", G_TYPE_INT, 1,
526 "layer", G_TYPE_INT, layer,
527 "rate", G_TYPE_INT, wfx->nSamplesPerSec,
528 "channels", G_TYPE_INT, wfx->nChannels,
530 capsout = gst_caps_new_simple("audio/x-raw-int",
531 "endianness", G_TYPE_INT, 1234,
532 "signed", G_TYPE_BOOLEAN, 1,
533 "width", G_TYPE_INT, 16,
534 "depth", G_TYPE_INT, 16,
535 "rate", G_TYPE_INT, wfx->nSamplesPerSec,
536 "channels", G_TYPE_INT, wfx->nChannels,
539 hr = Gstreamer_transform_ConnectInput(This, amt, capsin, capsout);
540 gst_caps_unref(capsin);
541 gst_caps_unref(capsout);
543 This->cbBuffer = wfx->nAvgBytesPerSec / 4;
548 static HRESULT WINAPI Gstreamer_Mp3_ConnectInput(TransformFilter *tf, PIN_DIRECTION dir, IPin *pin)
553 static const TransformFilterFuncTable Gstreamer_Mp3_vtbl = {
554 Gstreamer_transform_DecideBufferSize,
555 Gstreamer_transform_ProcessBegin,
556 Gstreamer_transform_ProcessData,
557 Gstreamer_transform_ProcessEnd,
558 Gstreamer_Mp3_QueryConnect,
559 Gstreamer_Mp3_SetMediaType,
560 Gstreamer_Mp3_ConnectInput,
561 Gstreamer_transform_Cleanup,
562 Gstreamer_transform_EndOfStream,
563 Gstreamer_transform_BeginFlush,
564 Gstreamer_transform_EndFlush,
565 Gstreamer_transform_NewSegment,
566 Gstreamer_transform_QOS
569 IUnknown * CALLBACK Gstreamer_Mp3_create(IUnknown *punkout, HRESULT *phr)
572 IUnknown *obj = NULL;
573 if (!Gstreamer_init())
578 plugin = Gstreamer_FindMatch("audio/mpeg, mpegversion=(int) 1");
584 *phr = Gstreamer_transform_create(punkout, &CLSID_Gstreamer_Mp3, plugin, &Gstreamer_Mp3_vtbl, (LPVOID*)&obj);
588 static HRESULT WINAPI Gstreamer_YUV_QueryConnect(TransformFilter *iface, const AM_MEDIA_TYPE *amt) {
589 GstTfImpl *This = (GstTfImpl*)iface;
590 TRACE("%p %p\n", This, amt);
591 dump_AM_MEDIA_TYPE(amt);
593 if (!IsEqualGUID(&amt->majortype, &MEDIATYPE_Video) ||
594 (!IsEqualGUID(&amt->formattype, &FORMAT_VideoInfo) &&
595 !IsEqualGUID(&amt->formattype, &FORMAT_VideoInfo2)))
597 if (memcmp(&amt->subtype.Data2, &MEDIATYPE_Video.Data2, sizeof(GUID) - sizeof(amt->subtype.Data1)))
599 switch (amt->subtype.Data1) {
600 case mmioFOURCC('I','4','2','0'):
601 case mmioFOURCC('Y','V','1','2'):
602 case mmioFOURCC('N','V','1','2'):
603 case mmioFOURCC('N','V','2','1'):
604 case mmioFOURCC('Y','U','Y','2'):
605 case mmioFOURCC('Y','V','Y','U'):
608 WARN("Unhandled fourcc %s\n", debugstr_an((char*)&amt->subtype.Data1, 4));
613 static HRESULT WINAPI Gstreamer_YUV_ConnectInput(TransformFilter *tf, PIN_DIRECTION dir, IPin *pin)
618 static HRESULT WINAPI Gstreamer_YUV_SetMediaType(TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE *amt) {
619 GstTfImpl *This = (GstTfImpl*)tf;
620 GstCaps *capsin, *capsout;
621 AM_MEDIA_TYPE *outpmt = &This->tf.pmt;
626 if (dir != PINDIR_INPUT)
629 if (Gstreamer_YUV_QueryConnect(&This->tf, amt) == S_FALSE || !amt->pbFormat)
632 FreeMediaType(outpmt);
633 CopyMediaType(outpmt, amt);
635 if (IsEqualGUID(&amt->formattype, &FORMAT_VideoInfo)) {
636 VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*)outpmt->pbFormat;
637 avgtime = vih->AvgTimePerFrame;
638 width = vih->bmiHeader.biWidth;
639 height = vih->bmiHeader.biHeight;
640 if ((LONG)vih->bmiHeader.biHeight > 0)
641 vih->bmiHeader.biHeight = -vih->bmiHeader.biHeight;
642 vih->bmiHeader.biBitCount = 24;
643 vih->bmiHeader.biCompression = BI_RGB;
645 VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2*)outpmt->pbFormat;
646 avgtime = vih->AvgTimePerFrame;
647 width = vih->bmiHeader.biWidth;
648 height = vih->bmiHeader.biHeight;
649 if ((LONG)vih->bmiHeader.biHeight > 0)
650 vih->bmiHeader.biHeight = -vih->bmiHeader.biHeight;
651 vih->bmiHeader.biBitCount = 24;
652 vih->bmiHeader.biCompression = BI_RGB;
655 avgtime = 10000000 / 30;
657 outpmt->subtype = MEDIASUBTYPE_RGB24;
659 capsin = gst_caps_new_simple("video/x-raw-yuv",
660 "format", GST_TYPE_FOURCC, amt->subtype.Data1,
661 "width", G_TYPE_INT, width,
662 "height", G_TYPE_INT, height,
663 "framerate", GST_TYPE_FRACTION, 10000000, avgtime,
665 capsout = gst_caps_new_simple("video/x-raw-rgb",
666 "endianness", G_TYPE_INT, 4321,
667 "width", G_TYPE_INT, width,
668 "height", G_TYPE_INT, height,
669 "framerate", GST_TYPE_FRACTION, 10000000, avgtime,
670 "bpp", G_TYPE_INT, 24,
671 "depth", G_TYPE_INT, 24,
672 "red_mask", G_TYPE_INT, 0xff,
673 "green_mask", G_TYPE_INT, 0xff00,
674 "blue_mask", G_TYPE_INT, 0xff0000,
677 hr = Gstreamer_transform_ConnectInput(This, amt, capsin, capsout);
678 gst_caps_unref(capsin);
679 gst_caps_unref(capsout);
681 This->cbBuffer = width * height * 4;
685 static const TransformFilterFuncTable Gstreamer_YUV_vtbl = {
686 Gstreamer_transform_DecideBufferSize,
687 Gstreamer_transform_ProcessBegin,
688 Gstreamer_transform_ProcessData,
689 Gstreamer_transform_ProcessEnd,
690 Gstreamer_YUV_QueryConnect,
691 Gstreamer_YUV_SetMediaType,
692 Gstreamer_YUV_ConnectInput,
693 Gstreamer_transform_Cleanup,
694 Gstreamer_transform_EndOfStream,
695 Gstreamer_transform_BeginFlush,
696 Gstreamer_transform_EndFlush,
697 Gstreamer_transform_NewSegment,
698 Gstreamer_transform_QOS
701 IUnknown * CALLBACK Gstreamer_YUV_create(IUnknown *punkout, HRESULT *phr)
703 IUnknown *obj = NULL;
704 if (!Gstreamer_init())
709 *phr = Gstreamer_transform_create(punkout, &CLSID_Gstreamer_YUV, "ffmpegcolorspace", &Gstreamer_YUV_vtbl, (LPVOID*)&obj);
713 static HRESULT WINAPI Gstreamer_AudioConvert_QueryConnect(TransformFilter *iface, const AM_MEDIA_TYPE *amt) {
714 GstTfImpl *This = (GstTfImpl*)iface;
715 TRACE("%p %p\n", This, amt);
716 dump_AM_MEDIA_TYPE(amt);
718 if (!IsEqualGUID(&amt->majortype, &MEDIATYPE_Audio) ||
719 !IsEqualGUID(&amt->subtype, &MEDIASUBTYPE_PCM) ||
720 !IsEqualGUID(&amt->formattype, &FORMAT_WaveFormatEx))
725 static HRESULT WINAPI Gstreamer_AudioConvert_ConnectInput(TransformFilter *tf, PIN_DIRECTION dir, IPin *pin)
730 static HRESULT WINAPI Gstreamer_AudioConvert_SetMediaType(TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE *amt) {
731 GstTfImpl *This = (GstTfImpl*)tf;
732 GstCaps *capsin, *capsout;
733 AM_MEDIA_TYPE *outpmt = &This->tf.pmt;
735 WAVEFORMATEX *outwfe;
736 WAVEFORMATEXTENSIBLE *outwfx;
738 int inisfloat = 0, indepth;
740 if (dir != PINDIR_INPUT)
743 if (Gstreamer_AudioConvert_QueryConnect(&This->tf, amt) == S_FALSE || !amt->pbFormat)
746 FreeMediaType(outpmt);
749 outpmt->cbFormat = sizeof(WAVEFORMATEXTENSIBLE);
750 outpmt->pbFormat = CoTaskMemAlloc(outpmt->cbFormat);
752 inwfe = (WAVEFORMATEX*)amt->pbFormat;
753 indepth = inwfe->wBitsPerSample;
754 if (inwfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
755 WAVEFORMATEXTENSIBLE *inwfx = (WAVEFORMATEXTENSIBLE*)inwfe;
756 inisfloat = IsEqualGUID(&inwfx->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
757 if (inwfx->Samples.wValidBitsPerSample)
758 indepth = inwfx->Samples.wValidBitsPerSample;
761 capsin = gst_caps_new_simple(inisfloat ? "audio/x-raw-float" : "audio/x-raw-int",
762 "endianness", G_TYPE_INT, 1234,
763 "width", G_TYPE_INT, inwfe->wBitsPerSample,
764 "depth", G_TYPE_INT, indepth,
765 "channels", G_TYPE_INT, inwfe->nChannels,
766 "rate", G_TYPE_INT, inwfe->nSamplesPerSec,
769 outwfe = (WAVEFORMATEX*)outpmt->pbFormat;
770 outwfx = (WAVEFORMATEXTENSIBLE*)outwfe;
771 outwfe->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
772 outwfe->nChannels = 2;
773 outwfe->nSamplesPerSec = inwfe->nSamplesPerSec;
774 outwfe->wBitsPerSample = 16;
775 outwfe->nBlockAlign = outwfe->nChannels * outwfe->wBitsPerSample / 8;
776 outwfe->nAvgBytesPerSec = outwfe->nBlockAlign * outwfe->nSamplesPerSec;
777 outwfe->cbSize = sizeof(*outwfx) - sizeof(*outwfe);
778 outwfx->Samples.wValidBitsPerSample = outwfe->wBitsPerSample;
779 outwfx->dwChannelMask = SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT;
780 outwfx->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
782 capsout = gst_caps_new_simple("audio/x-raw-int",
783 "endianness", G_TYPE_INT, 1234,
784 "width", G_TYPE_INT, outwfe->wBitsPerSample,
785 "depth", G_TYPE_INT, outwfx->Samples.wValidBitsPerSample,
786 "channels", G_TYPE_INT, outwfe->nChannels,
787 "rate", G_TYPE_INT, outwfe->nSamplesPerSec,
790 hr = Gstreamer_transform_ConnectInput(This, amt, capsin, capsout);
792 gst_caps_unref(capsin);
793 gst_caps_unref(capsout);
795 This->cbBuffer = inwfe->nAvgBytesPerSec;
799 static const TransformFilterFuncTable Gstreamer_AudioConvert_vtbl = {
800 Gstreamer_transform_DecideBufferSize,
801 Gstreamer_transform_ProcessBegin,
802 Gstreamer_transform_ProcessData,
803 Gstreamer_transform_ProcessEnd,
804 Gstreamer_AudioConvert_QueryConnect,
805 Gstreamer_AudioConvert_SetMediaType,
806 Gstreamer_AudioConvert_ConnectInput,
807 Gstreamer_transform_Cleanup,
808 Gstreamer_transform_EndOfStream,
809 Gstreamer_transform_BeginFlush,
810 Gstreamer_transform_EndFlush,
811 Gstreamer_transform_NewSegment,
812 Gstreamer_transform_QOS
815 IUnknown * CALLBACK Gstreamer_AudioConvert_create(IUnknown *punkout, HRESULT *phr)
817 IUnknown *obj = NULL;
818 if (!Gstreamer_init())
823 *phr = Gstreamer_transform_create(punkout, &CLSID_Gstreamer_AudioConvert, "audioconvert", &Gstreamer_AudioConvert_vtbl, (LPVOID*)&obj);
827 HRESULT WINAPI GSTTf_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
830 GstTfImpl *This = (GstTfImpl*)iface;
831 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppv);
833 if (IsEqualIID(riid, &IID_IMediaSeeking))
834 return IUnknown_QueryInterface(This->seekthru_unk, riid, ppv);
836 hr = TransformFilterImpl_QueryInterface(iface, riid, ppv);
841 static const IBaseFilterVtbl GSTTf_Vtbl =
843 GSTTf_QueryInterface,
844 BaseFilterImpl_AddRef,
845 TransformFilterImpl_Release,
846 BaseFilterImpl_GetClassID,
847 TransformFilterImpl_Stop,
848 TransformFilterImpl_Pause,
849 TransformFilterImpl_Run,
850 BaseFilterImpl_GetState,
851 BaseFilterImpl_SetSyncSource,
852 BaseFilterImpl_GetSyncSource,
853 BaseFilterImpl_EnumPins,
854 TransformFilterImpl_FindPin,
855 BaseFilterImpl_QueryFilterInfo,
856 BaseFilterImpl_JoinFilterGraph,
857 BaseFilterImpl_QueryVendorInfo