2010-10-27 20:14:06 +02:00
|
|
|
/*
|
|
|
|
* GStreamer wrapper filter
|
|
|
|
*
|
|
|
|
* Copyright 2010 Maarten Lankhorst for CodeWeavers
|
|
|
|
* Copyright 2010 Aric Stewart for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/video/video.h>
|
|
|
|
#include <gst/audio/audio.h>
|
2010-10-27 20:14:06 +02:00
|
|
|
|
|
|
|
#include "gst_private.h"
|
|
|
|
#include "gst_guids.h"
|
2016-01-12 20:35:04 +01:00
|
|
|
#include "gst_cbs.h"
|
2010-10-27 20:14:06 +02:00
|
|
|
|
|
|
|
#include "uuids.h"
|
|
|
|
#include "mmreg.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "dshow.h"
|
|
|
|
#include "strmif.h"
|
|
|
|
#include "vfwmsgs.h"
|
|
|
|
#include "dvdmedia.h"
|
|
|
|
#include "ks.h"
|
|
|
|
#include "ksmedia.h"
|
|
|
|
#include "msacm.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "initguid.h"
|
2010-10-28 21:42:29 +02:00
|
|
|
DEFINE_GUID(WMMEDIASUBTYPE_MP3, 0x00000055, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
|
2010-10-27 20:14:06 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(gstreamer);
|
|
|
|
|
|
|
|
struct typeinfo {
|
|
|
|
GstCaps *caps;
|
|
|
|
const char *type;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const IBaseFilterVtbl GSTTf_Vtbl;
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static gboolean match_element(GstPluginFeature *feature, gpointer gdata)
|
|
|
|
{
|
2010-10-27 20:14:06 +02:00
|
|
|
struct typeinfo *data = (struct typeinfo*)gdata;
|
|
|
|
GstElementFactory *factory;
|
|
|
|
const GList *list;
|
|
|
|
|
|
|
|
if (!GST_IS_ELEMENT_FACTORY(feature))
|
|
|
|
return FALSE;
|
|
|
|
factory = GST_ELEMENT_FACTORY(feature);
|
|
|
|
if (!strstr(gst_element_factory_get_klass(factory), data->type))
|
|
|
|
return FALSE;
|
|
|
|
for (list = gst_element_factory_get_static_pad_templates(factory); list; list = list->next) {
|
|
|
|
GstStaticPadTemplate *pad = (GstStaticPadTemplate*)list->data;
|
|
|
|
GstCaps *caps;
|
|
|
|
gboolean ret;
|
|
|
|
if (pad->direction != GST_PAD_SINK)
|
|
|
|
continue;
|
|
|
|
caps = gst_static_caps_get(&pad->static_caps);
|
|
|
|
ret = gst_caps_is_always_compatible(caps, data->caps);
|
|
|
|
gst_caps_unref(caps);
|
|
|
|
if (ret)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *Gstreamer_FindMatch(const char *strcaps)
|
|
|
|
{
|
|
|
|
struct typeinfo data;
|
|
|
|
GList *list, *copy;
|
|
|
|
guint bestrank = 0;
|
|
|
|
GstElementFactory *bestfactory = NULL;
|
|
|
|
GstCaps *caps = gst_caps_from_string(strcaps);
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%s\n", strcaps);
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
data.caps = caps;
|
|
|
|
data.type = "Decoder";
|
2016-01-14 20:23:04 +01:00
|
|
|
copy = gst_registry_feature_filter(gst_registry_get(), match_element, 0, &data);
|
2010-10-27 20:14:06 +02:00
|
|
|
for (list = copy; list; list = list->next) {
|
|
|
|
GstElementFactory *factory = (GstElementFactory*)list->data;
|
|
|
|
guint rank;
|
|
|
|
rank = gst_plugin_feature_get_rank(GST_PLUGIN_FEATURE(factory));
|
|
|
|
if (rank > bestrank || !bestrank) {
|
|
|
|
bestrank = rank;
|
|
|
|
bestfactory = factory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_caps_unref(caps);
|
|
|
|
g_list_free(copy);
|
|
|
|
|
|
|
|
if (!bestfactory) {
|
|
|
|
FIXME("Could not find plugin for %s\n", strcaps);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(bestfactory));
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct GstTfImpl {
|
|
|
|
TransformFilter tf;
|
|
|
|
const char *gstreamer_name;
|
|
|
|
GstElement *filter;
|
|
|
|
GstPad *my_src, *my_sink, *their_src, *their_sink;
|
|
|
|
LONG cbBuffer;
|
|
|
|
} GstTfImpl;
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_transform_ProcessBegin(TransformFilter *iface)
|
|
|
|
{
|
2010-10-27 20:14:06 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)iface;
|
|
|
|
int ret;
|
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
ret = gst_element_set_state(This->filter, GST_STATE_PLAYING);
|
|
|
|
TRACE("Returned: %i\n", ret);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Gstreamer_transform_DecideBufferSize(TransformFilter *tf, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
|
|
|
|
{
|
|
|
|
GstTfImpl *This = (GstTfImpl*)tf;
|
|
|
|
ALLOCATOR_PROPERTIES actual;
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p, %p, %p\n", This, pAlloc, ppropInputRequest);
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
if (!ppropInputRequest->cbAlign)
|
|
|
|
ppropInputRequest->cbAlign = 1;
|
|
|
|
|
|
|
|
ppropInputRequest->cbBuffer = This->cbBuffer;
|
|
|
|
|
2010-11-11 23:22:58 +01:00
|
|
|
if (ppropInputRequest->cBuffers < 2)
|
|
|
|
ppropInputRequest->cBuffers = 2;
|
2010-10-27 20:14:06 +02:00
|
|
|
|
|
|
|
return IMemAllocator_SetProperties(pAlloc, ppropInputRequest, &actual);
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
GstFlowReturn got_data(GstPad *pad, GstObject *parent, GstBuffer *buf)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2010-10-27 20:14:06 +02:00
|
|
|
GstTfImpl *This = gst_pad_get_element_private(pad);
|
2016-01-14 20:23:04 +01:00
|
|
|
IMediaSample *sample = (IMediaSample *) gst_mini_object_get_qdata(GST_MINI_OBJECT(buf), g_quark_from_static_string(media_quark_string));
|
2010-10-27 20:14:06 +02:00
|
|
|
REFERENCE_TIME tStart, tStop;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p, %p\n", pad, buf);
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
if(!sample){
|
|
|
|
GstMapInfo info;
|
|
|
|
BYTE *ptr;
|
|
|
|
|
|
|
|
gst_buffer_map(buf, &info, GST_MAP_READ);
|
|
|
|
|
|
|
|
hr = BaseOutputPinImpl_GetDeliveryBuffer((BaseOutputPin*)This->tf.ppPins[1], &sample, NULL, NULL, 0);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
ERR("Could not get output buffer: %08x\n", hr);
|
|
|
|
return GST_FLOW_FLUSHING;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMediaSample_SetActualDataLength(sample, info.size);
|
|
|
|
|
|
|
|
IMediaSample_GetPointer(sample, &ptr);
|
|
|
|
|
|
|
|
memcpy(ptr, info.data, info.size);
|
|
|
|
|
|
|
|
gst_buffer_unmap(buf, &info);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_BUFFER_PTS_IS_VALID(buf) &&
|
2010-10-27 20:14:06 +02:00
|
|
|
GST_BUFFER_DURATION_IS_VALID(buf)) {
|
2016-01-14 20:23:04 +01:00
|
|
|
tStart = buf->pts / 100;
|
2010-10-27 20:14:06 +02:00
|
|
|
tStop = tStart + buf->duration / 100;
|
|
|
|
IMediaSample_SetTime(sample, &tStart, &tStop);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
IMediaSample_SetTime(sample, NULL, NULL);
|
2010-11-07 15:02:50 +01:00
|
|
|
if (GST_BUFFER_OFFSET_IS_VALID(buf) &&
|
|
|
|
GST_BUFFER_OFFSET_END_IS_VALID(buf)) {
|
|
|
|
tStart = buf->offset / 100;
|
|
|
|
tStop = buf->offset_end / 100;
|
|
|
|
IMediaSample_SetMediaTime(sample, &tStart, &tStop);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
IMediaSample_SetMediaTime(sample, NULL, NULL);
|
2010-10-27 20:14:06 +02:00
|
|
|
|
|
|
|
IMediaSample_SetDiscontinuity(sample, GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_DISCONT));
|
2016-01-14 20:23:04 +01:00
|
|
|
IMediaSample_SetPreroll(sample, GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_LIVE));
|
2010-10-27 20:14:06 +02:00
|
|
|
IMediaSample_SetSyncPoint(sample, !GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_DELTA_UNIT));
|
2016-01-14 20:23:04 +01:00
|
|
|
IMediaSample_SetActualDataLength(sample, gst_buffer_get_size(buf));
|
2010-10-27 20:14:06 +02:00
|
|
|
|
|
|
|
hr = BaseOutputPinImpl_Deliver((BaseOutputPin*)This->tf.ppPins[1], sample);
|
2016-01-14 20:23:04 +01:00
|
|
|
IMediaSample_Release(sample);
|
2010-10-27 20:14:06 +02:00
|
|
|
gst_buffer_unref(buf);
|
|
|
|
if (FAILED(hr))
|
2016-01-14 20:23:04 +01:00
|
|
|
return GST_FLOW_FLUSHING;
|
2010-10-27 20:14:06 +02:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_transform_ProcessData(TransformFilter *iface, IMediaSample *sample)
|
|
|
|
{
|
2010-10-27 20:14:06 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)iface;
|
|
|
|
REFERENCE_TIME tStart, tStop;
|
|
|
|
BYTE *data;
|
|
|
|
GstBuffer *buf;
|
|
|
|
HRESULT hr;
|
2016-01-14 20:23:04 +01:00
|
|
|
DWORD bufsize;
|
2010-10-27 20:14:06 +02:00
|
|
|
int ret;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
|
|
|
TRACE("%p, %p\n", This, sample);
|
2010-10-27 20:14:06 +02:00
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
|
|
|
|
2012-01-23 04:45:14 +01:00
|
|
|
EnterCriticalSection(&This->tf.csReceive);
|
2010-10-27 20:14:06 +02:00
|
|
|
IMediaSample_GetPointer(sample, &data);
|
2016-01-14 20:23:04 +01:00
|
|
|
|
|
|
|
IMediaSample_AddRef(sample);
|
|
|
|
bufsize = IMediaSample_GetActualDataLength(sample);
|
|
|
|
buf = gst_buffer_new_wrapped_full(0, data, bufsize, 0, bufsize, sample, release_sample_wrapper);
|
2010-10-27 20:14:06 +02:00
|
|
|
if (!buf) {
|
2016-01-14 20:23:04 +01:00
|
|
|
IMediaSample_Release(sample);
|
2012-01-23 04:45:14 +01:00
|
|
|
LeaveCriticalSection(&This->tf.csReceive);
|
2010-10-27 20:14:06 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2016-01-14 20:23:04 +01:00
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
IMediaSample_AddRef(sample);
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_mini_object_set_qdata(GST_MINI_OBJECT(buf), g_quark_from_static_string(media_quark_string), sample, release_sample_wrapper);
|
|
|
|
|
|
|
|
buf->duration = buf->pts = -1;
|
2010-10-27 20:14:06 +02:00
|
|
|
hr = IMediaSample_GetTime(sample, &tStart, &tStop);
|
|
|
|
if (SUCCEEDED(hr)) {
|
2016-01-14 20:23:04 +01:00
|
|
|
buf->pts = tStart * 100;
|
2010-10-27 20:14:06 +02:00
|
|
|
if (hr == S_OK)
|
|
|
|
buf->duration = (tStop - tStart)*100;
|
|
|
|
}
|
2010-11-07 15:02:50 +01:00
|
|
|
if (IMediaSample_GetMediaTime(sample, &tStart, &tStop) == S_OK) {
|
|
|
|
buf->offset = tStart * 100;
|
|
|
|
buf->offset_end = tStop * 100;
|
|
|
|
}
|
2010-10-27 20:14:06 +02:00
|
|
|
if (IMediaSample_IsDiscontinuity(sample) == S_OK)
|
|
|
|
GST_BUFFER_FLAG_SET(buf, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
if (IMediaSample_IsPreroll(sample) == S_OK)
|
2016-01-14 20:23:04 +01:00
|
|
|
GST_BUFFER_FLAG_SET(buf, GST_BUFFER_FLAG_LIVE);
|
2010-10-27 20:14:06 +02:00
|
|
|
if (IMediaSample_IsSyncPoint(sample) != S_OK)
|
|
|
|
GST_BUFFER_FLAG_SET(buf, GST_BUFFER_FLAG_DELTA_UNIT);
|
2012-01-23 04:45:14 +01:00
|
|
|
LeaveCriticalSection(&This->tf.csReceive);
|
2010-10-27 20:14:06 +02:00
|
|
|
ret = gst_pad_push(This->my_src, buf);
|
|
|
|
if (ret)
|
|
|
|
WARN("Sending returned: %i\n", ret);
|
2016-01-14 20:23:04 +01:00
|
|
|
if (ret == GST_FLOW_FLUSHING)
|
2010-10-27 20:14:06 +02:00
|
|
|
return VFW_E_WRONG_STATE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_transform_ProcessEnd(TransformFilter *iface)
|
|
|
|
{
|
2010-10-27 20:14:06 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)iface;
|
|
|
|
int ret;
|
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
|
|
|
|
2012-01-23 04:45:14 +01:00
|
|
|
LeaveCriticalSection(&This->tf.csReceive);
|
2010-11-10 23:22:45 +01:00
|
|
|
ret = gst_element_set_state(This->filter, GST_STATE_READY);
|
2012-01-23 04:45:14 +01:00
|
|
|
EnterCriticalSection(&This->tf.csReceive);
|
2010-10-27 20:14:06 +02:00
|
|
|
TRACE("Returned: %i\n", ret);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
void Gstreamer_transform_pad_added(GstElement *filter, GstPad *pad, gpointer user)
|
2010-10-27 20:14:06 +02:00
|
|
|
{
|
2016-01-12 20:35:04 +01:00
|
|
|
GstTfImpl *This = (GstTfImpl*)user;
|
2010-10-27 20:14:06 +02:00
|
|
|
int ret;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
|
|
|
TRACE("%p %p %p\n", This, filter, pad);
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
if (!GST_PAD_IS_SRC(pad))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ret = gst_pad_link(pad, This->my_sink);
|
|
|
|
if (ret < 0)
|
|
|
|
WARN("Failed to link with %i\n", ret);
|
|
|
|
This->their_src = pad;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT Gstreamer_transform_ConnectInput(GstTfImpl *This, const AM_MEDIA_TYPE *amt, GstCaps *capsin, GstCaps *capsout)
|
|
|
|
{
|
2010-10-27 20:14:06 +02:00
|
|
|
GstIterator *it;
|
2013-10-10 21:52:43 +02:00
|
|
|
BOOL done = FALSE, found = FALSE;
|
|
|
|
int ret;
|
2010-10-27 20:14:06 +02:00
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p %p %p %p\n", This, amt, capsin, capsout);
|
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
This->filter = gst_element_factory_make(This->gstreamer_name, NULL);
|
|
|
|
if (!This->filter) {
|
|
|
|
FIXME("Could not make %s filter\n", This->gstreamer_name);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2016-01-14 20:23:04 +01:00
|
|
|
This->my_src = gst_pad_new("yuvsrc", GST_PAD_SRC);
|
2010-10-27 20:14:06 +02:00
|
|
|
gst_pad_set_element_private (This->my_src, This);
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_pad_set_active(This->my_src, 1);
|
2010-10-27 20:14:06 +02:00
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
This->my_sink = gst_pad_new("yuvsink", GST_PAD_SINK);
|
2016-01-12 20:35:04 +01:00
|
|
|
gst_pad_set_chain_function(This->my_sink, got_data_wrapper);
|
2010-10-27 20:14:06 +02:00
|
|
|
gst_pad_set_element_private (This->my_sink, This);
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_pad_set_active(This->my_sink, 1);
|
2010-10-27 20:14:06 +02:00
|
|
|
|
|
|
|
it = gst_element_iterate_sink_pads(This->filter);
|
|
|
|
while (!done) {
|
2016-01-14 20:23:04 +01:00
|
|
|
GValue item = {0};
|
2010-10-27 20:14:06 +02:00
|
|
|
|
|
|
|
switch (gst_iterator_next(it, &item)) {
|
|
|
|
case GST_ITERATOR_RESYNC:
|
|
|
|
gst_iterator_resync (it);
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_OK:
|
2016-01-14 20:23:04 +01:00
|
|
|
This->their_sink = g_value_get_object(&item);
|
|
|
|
gst_object_ref(This->their_sink);
|
|
|
|
g_value_reset(&item);
|
2010-10-27 20:14:06 +02:00
|
|
|
case GST_ITERATOR_ERROR:
|
|
|
|
case GST_ITERATOR_DONE:
|
2013-10-10 21:52:43 +02:00
|
|
|
done = TRUE;
|
2010-10-27 20:14:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_iterator_free(it);
|
|
|
|
if (!This->their_sink) {
|
|
|
|
ERR("Could not find sink on filter %s\n", This->gstreamer_name);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
it = gst_element_iterate_src_pads(This->filter);
|
|
|
|
gst_iterator_resync(it);
|
2013-10-10 21:52:43 +02:00
|
|
|
done = FALSE;
|
2010-10-27 20:14:06 +02:00
|
|
|
while (!done) {
|
2016-01-14 20:23:04 +01:00
|
|
|
GValue item = {0};
|
2010-10-27 20:14:06 +02:00
|
|
|
|
|
|
|
switch (gst_iterator_next(it, &item)) {
|
|
|
|
case GST_ITERATOR_RESYNC:
|
|
|
|
gst_iterator_resync (it);
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_OK:
|
2016-01-14 20:23:04 +01:00
|
|
|
This->their_src = g_value_get_object(&item);
|
|
|
|
gst_object_ref(This->their_src);
|
|
|
|
g_value_reset(&item);
|
2010-10-27 20:14:06 +02:00
|
|
|
case GST_ITERATOR_ERROR:
|
|
|
|
case GST_ITERATOR_DONE:
|
2013-10-10 21:52:43 +02:00
|
|
|
done = TRUE;
|
2010-10-27 20:14:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_iterator_free(it);
|
|
|
|
found = !!This->their_src;
|
|
|
|
if (!found)
|
2016-01-12 20:35:04 +01:00
|
|
|
g_signal_connect(This->filter, "pad-added", G_CALLBACK(Gstreamer_transform_pad_added_wrapper), This);
|
2010-10-27 20:14:06 +02:00
|
|
|
ret = gst_pad_link(This->my_src, This->their_sink);
|
|
|
|
if (ret < 0) {
|
|
|
|
WARN("Failed to link with %i\n", ret);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
ret = gst_pad_set_caps(This->my_src, capsin);
|
|
|
|
if (ret < 0) {
|
|
|
|
WARN("Failed to set caps on own source with %i\n", ret);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
if (found)
|
|
|
|
Gstreamer_transform_pad_added(This->filter, This->their_src, This);
|
|
|
|
|
|
|
|
if (!gst_pad_is_linked(This->my_sink))
|
|
|
|
return E_FAIL;
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
ret = gst_pad_set_caps(This->my_sink, capsout);
|
|
|
|
if (ret < 0) {
|
|
|
|
WARN("Failed to set caps on own sink with %i\n", ret);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
TRACE("Connected\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_transform_Cleanup(TransformFilter *tf, PIN_DIRECTION dir)
|
|
|
|
{
|
2010-10-27 20:14:06 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)tf;
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p 0x%x\n", This, dir);
|
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
if (dir == PINDIR_INPUT)
|
|
|
|
{
|
|
|
|
if (This->filter) {
|
|
|
|
gst_element_set_state(This->filter, GST_STATE_NULL);
|
|
|
|
gst_object_unref(This->filter);
|
|
|
|
}
|
|
|
|
This->filter = NULL;
|
|
|
|
if (This->my_src) {
|
|
|
|
gst_pad_unlink(This->my_src, This->their_sink);
|
|
|
|
gst_object_unref(This->my_src);
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_object_unref(This->their_sink);
|
2010-10-27 20:14:06 +02:00
|
|
|
}
|
|
|
|
if (This->my_sink) {
|
|
|
|
gst_pad_unlink(This->their_src, This->my_sink);
|
|
|
|
gst_object_unref(This->my_sink);
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_object_unref(This->their_src);
|
2010-10-27 20:14:06 +02:00
|
|
|
}
|
|
|
|
This->my_sink = This->my_src = This->their_sink = This->their_src = NULL;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_transform_EndOfStream(TransformFilter *iface)
|
|
|
|
{
|
2010-10-27 20:14:06 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)iface;
|
|
|
|
TRACE("%p\n", This);
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
2010-10-27 20:14:06 +02:00
|
|
|
|
|
|
|
gst_pad_push_event(This->my_src, gst_event_new_eos());
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_transform_BeginFlush(TransformFilter *iface)
|
|
|
|
{
|
2010-10-27 20:14:06 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)iface;
|
|
|
|
TRACE("%p\n", This);
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
2010-10-27 20:14:06 +02:00
|
|
|
|
|
|
|
gst_pad_push_event(This->my_src, gst_event_new_flush_start());
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_transform_EndFlush(TransformFilter *iface)
|
|
|
|
{
|
2010-10-27 20:14:06 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)iface;
|
|
|
|
TRACE("%p\n", This);
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
2010-10-27 20:14:06 +02:00
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_pad_push_event(This->my_src, gst_event_new_flush_stop(TRUE));
|
2010-10-27 20:14:06 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_transform_NewSegment(TransformFilter *iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
|
|
|
|
{
|
2010-10-27 20:14:06 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)iface;
|
2016-01-14 20:23:04 +01:00
|
|
|
const GstSegment segment = { GST_SEGMENT_FLAG_NONE, 1.0, dRate, GST_FORMAT_TIME, 0, 0, 0, tStop <= tStart ? -1 : tStop * 100, 0, tStart*100, -1 };
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
TRACE("%p\n", This);
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
2010-10-27 20:14:06 +02:00
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_pad_push_event(This->my_src, gst_event_new_segment(&segment));
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_transform_QOS(TransformFilter *iface, IBaseFilter *sender, Quality qm)
|
|
|
|
{
|
2010-11-09 23:42:46 +01:00
|
|
|
GstTfImpl *This = (GstTfImpl*)iface;
|
2010-11-24 18:23:56 +01:00
|
|
|
REFERENCE_TIME late = qm.Late;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
|
|
|
TRACE("%p %p qm\n", This, sender);
|
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2010-11-24 18:23:56 +01:00
|
|
|
if (qm.Late < 0 && -qm.Late > qm.TimeStamp)
|
|
|
|
late = -qm.TimeStamp;
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_pad_push_event(This->my_sink, gst_event_new_qos(late <= 0 ? GST_QOS_TYPE_OVERFLOW : GST_QOS_TYPE_UNDERFLOW, 1000. / qm.Proportion, late * 100, qm.TimeStamp * 100));
|
2012-04-02 14:52:15 +02:00
|
|
|
return TransformFilterImpl_Notify(iface, sender, qm);
|
2010-11-09 23:42:46 +01:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT Gstreamer_transform_create(IUnknown *punkouter, const CLSID *clsid, const char *name, const TransformFilterFuncTable *vtbl, void **obj)
|
2010-10-27 20:14:06 +02:00
|
|
|
{
|
|
|
|
GstTfImpl *This;
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p, %p, %p, %p, %p\n", punkouter, clsid, name, vtbl, obj);
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
if (FAILED(TransformFilter_Construct(&GSTTf_Vtbl, sizeof(GstTfImpl), clsid, vtbl, (IBaseFilter**)&This)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->gstreamer_name = name;
|
|
|
|
*obj = This;
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("returning %p\n", This);
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_Mp3_QueryConnect(TransformFilter *iface, const AM_MEDIA_TYPE *amt)
|
|
|
|
{
|
2010-10-28 21:42:29 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)iface;
|
|
|
|
TRACE("%p %p\n", This, amt);
|
|
|
|
dump_AM_MEDIA_TYPE(amt);
|
|
|
|
|
|
|
|
if ( (!IsEqualGUID(&amt->majortype, &MEDIATYPE_Audio) &&
|
|
|
|
!IsEqualGUID(&amt->majortype, &MEDIATYPE_Stream)) ||
|
|
|
|
(!IsEqualGUID(&amt->subtype, &MEDIASUBTYPE_MPEG1AudioPayload) &&
|
|
|
|
!IsEqualGUID(&amt->subtype, &WMMEDIASUBTYPE_MP3))
|
2016-01-14 20:23:04 +01:00
|
|
|
|| !IsEqualGUID(&amt->formattype, &FORMAT_WaveFormatEx)){
|
2010-10-28 21:42:29 +02:00
|
|
|
return S_FALSE;
|
2016-01-14 20:23:04 +01:00
|
|
|
}
|
2010-10-28 21:42:29 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_Mp3_SetMediaType(TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE *amt)
|
|
|
|
{
|
2010-10-28 21:42:29 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)tf;
|
|
|
|
GstCaps *capsin, *capsout;
|
|
|
|
AM_MEDIA_TYPE *outpmt = &This->tf.pmt;
|
|
|
|
WAVEFORMATEX *wfx, *wfxin;
|
|
|
|
HRESULT hr;
|
|
|
|
int layer;
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p 0x%x %p\n", This, dir, amt);
|
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
|
|
|
|
2010-10-28 21:42:29 +02:00
|
|
|
if (dir != PINDIR_INPUT)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (Gstreamer_Mp3_QueryConnect(&This->tf, amt) == S_FALSE || !amt->pbFormat)
|
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
|
|
|
|
|
|
|
wfxin = (WAVEFORMATEX*)amt->pbFormat;
|
|
|
|
switch (wfxin->wFormatTag) {
|
|
|
|
case WAVE_FORMAT_MPEGLAYER3:
|
|
|
|
layer = 3;
|
|
|
|
break;
|
|
|
|
case WAVE_FORMAT_MPEG: {
|
|
|
|
MPEG1WAVEFORMAT *mpgformat = (MPEG1WAVEFORMAT*)wfxin;
|
|
|
|
layer = mpgformat->fwHeadLayer;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled tag %x\n", wfxin->wFormatTag);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeMediaType(outpmt);
|
|
|
|
CopyMediaType(outpmt, amt);
|
|
|
|
|
|
|
|
outpmt->subtype = MEDIASUBTYPE_PCM;
|
|
|
|
outpmt->formattype = FORMAT_WaveFormatEx;
|
|
|
|
outpmt->cbFormat = sizeof(*wfx);
|
|
|
|
CoTaskMemFree(outpmt->pbFormat);
|
|
|
|
wfx = CoTaskMemAlloc(outpmt->cbFormat);
|
|
|
|
outpmt->pbFormat = (BYTE*)wfx;
|
|
|
|
wfx->wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
wfx->wBitsPerSample = 16;
|
|
|
|
wfx->nSamplesPerSec = wfxin->nSamplesPerSec;
|
|
|
|
wfx->nChannels = wfxin->nChannels;
|
|
|
|
wfx->nBlockAlign = wfx->wBitsPerSample * wfx->nChannels / 8;
|
|
|
|
wfx->cbSize = 0;
|
|
|
|
wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign;
|
|
|
|
|
|
|
|
capsin = gst_caps_new_simple("audio/mpeg",
|
|
|
|
"mpegversion", G_TYPE_INT, 1,
|
|
|
|
"layer", G_TYPE_INT, layer,
|
|
|
|
"rate", G_TYPE_INT, wfx->nSamplesPerSec,
|
|
|
|
"channels", G_TYPE_INT, wfx->nChannels,
|
|
|
|
NULL);
|
2016-01-14 20:23:04 +01:00
|
|
|
capsout = gst_caps_new_simple("audio/x-raw",
|
|
|
|
"format", G_TYPE_STRING, "S16LE"
|
2010-10-28 21:42:29 +02:00
|
|
|
"rate", G_TYPE_INT, wfx->nSamplesPerSec,
|
|
|
|
"channels", G_TYPE_INT, wfx->nChannels,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
hr = Gstreamer_transform_ConnectInput(This, amt, capsin, capsout);
|
|
|
|
gst_caps_unref(capsin);
|
|
|
|
gst_caps_unref(capsout);
|
|
|
|
|
|
|
|
This->cbBuffer = wfx->nAvgBytesPerSec / 4;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Gstreamer_Mp3_ConnectInput(TransformFilter *tf, PIN_DIRECTION dir, IPin *pin)
|
|
|
|
{
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p 0x%x %p\n", tf, dir, pin);
|
2010-10-28 21:42:29 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TransformFilterFuncTable Gstreamer_Mp3_vtbl = {
|
|
|
|
Gstreamer_transform_DecideBufferSize,
|
|
|
|
Gstreamer_transform_ProcessBegin,
|
|
|
|
Gstreamer_transform_ProcessData,
|
|
|
|
Gstreamer_transform_ProcessEnd,
|
|
|
|
Gstreamer_Mp3_QueryConnect,
|
|
|
|
Gstreamer_Mp3_SetMediaType,
|
|
|
|
Gstreamer_Mp3_ConnectInput,
|
|
|
|
Gstreamer_transform_Cleanup,
|
|
|
|
Gstreamer_transform_EndOfStream,
|
|
|
|
Gstreamer_transform_BeginFlush,
|
|
|
|
Gstreamer_transform_EndFlush,
|
2010-11-09 23:42:46 +01:00
|
|
|
Gstreamer_transform_NewSegment,
|
|
|
|
Gstreamer_transform_QOS
|
2010-10-28 21:42:29 +02:00
|
|
|
};
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
IUnknown * CALLBACK Gstreamer_Mp3_create(IUnknown *punkouter, HRESULT *phr)
|
2010-10-28 21:42:29 +02:00
|
|
|
{
|
|
|
|
const char *plugin;
|
|
|
|
IUnknown *obj = NULL;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
|
|
|
TRACE("%p %p\n", punkouter, phr);
|
|
|
|
|
2010-10-28 21:42:29 +02:00
|
|
|
if (!Gstreamer_init())
|
|
|
|
{
|
|
|
|
*phr = E_FAIL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2010-10-28 21:42:29 +02:00
|
|
|
plugin = Gstreamer_FindMatch("audio/mpeg, mpegversion=(int) 1");
|
|
|
|
if (!plugin)
|
|
|
|
{
|
|
|
|
*phr = E_FAIL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-14 20:22:11 +01:00
|
|
|
|
|
|
|
*phr = Gstreamer_transform_create(punkouter, &CLSID_Gstreamer_Mp3, plugin, &Gstreamer_Mp3_vtbl, (LPVOID*)&obj);
|
|
|
|
|
|
|
|
TRACE("returning %p\n", obj);
|
|
|
|
|
2010-10-28 21:42:29 +02:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_YUV_QueryConnect(TransformFilter *iface, const AM_MEDIA_TYPE *amt)
|
|
|
|
{
|
2010-10-27 20:14:15 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)iface;
|
|
|
|
TRACE("%p %p\n", This, amt);
|
|
|
|
dump_AM_MEDIA_TYPE(amt);
|
|
|
|
|
|
|
|
if (!IsEqualGUID(&amt->majortype, &MEDIATYPE_Video) ||
|
|
|
|
(!IsEqualGUID(&amt->formattype, &FORMAT_VideoInfo) &&
|
|
|
|
!IsEqualGUID(&amt->formattype, &FORMAT_VideoInfo2)))
|
|
|
|
return S_FALSE;
|
|
|
|
if (memcmp(&amt->subtype.Data2, &MEDIATYPE_Video.Data2, sizeof(GUID) - sizeof(amt->subtype.Data1)))
|
|
|
|
return S_FALSE;
|
|
|
|
switch (amt->subtype.Data1) {
|
|
|
|
case mmioFOURCC('I','4','2','0'):
|
|
|
|
case mmioFOURCC('Y','V','1','2'):
|
|
|
|
case mmioFOURCC('N','V','1','2'):
|
|
|
|
case mmioFOURCC('N','V','2','1'):
|
|
|
|
case mmioFOURCC('Y','U','Y','2'):
|
|
|
|
case mmioFOURCC('Y','V','Y','U'):
|
|
|
|
return S_OK;
|
|
|
|
default:
|
|
|
|
WARN("Unhandled fourcc %s\n", debugstr_an((char*)&amt->subtype.Data1, 4));
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Gstreamer_YUV_ConnectInput(TransformFilter *tf, PIN_DIRECTION dir, IPin *pin)
|
|
|
|
{
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p 0x%x %p\n", tf, dir, pin);
|
2010-10-27 20:14:15 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_YUV_SetMediaType(TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE *amt)
|
|
|
|
{
|
2010-10-27 20:14:15 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)tf;
|
|
|
|
GstCaps *capsin, *capsout;
|
|
|
|
AM_MEDIA_TYPE *outpmt = &This->tf.pmt;
|
|
|
|
HRESULT hr;
|
|
|
|
int avgtime;
|
2012-01-24 15:15:52 +01:00
|
|
|
LONG width, height;
|
2010-10-27 20:14:15 +02:00
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p 0x%x %p\n", This, dir, amt);
|
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
|
|
|
|
2010-10-27 20:14:15 +02:00
|
|
|
if (dir != PINDIR_INPUT)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (Gstreamer_YUV_QueryConnect(&This->tf, amt) == S_FALSE || !amt->pbFormat)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
FreeMediaType(outpmt);
|
|
|
|
CopyMediaType(outpmt, amt);
|
|
|
|
|
|
|
|
if (IsEqualGUID(&amt->formattype, &FORMAT_VideoInfo)) {
|
|
|
|
VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*)outpmt->pbFormat;
|
|
|
|
avgtime = vih->AvgTimePerFrame;
|
|
|
|
width = vih->bmiHeader.biWidth;
|
|
|
|
height = vih->bmiHeader.biHeight;
|
2012-01-24 15:15:52 +01:00
|
|
|
if (vih->bmiHeader.biHeight > 0)
|
2010-10-27 20:14:15 +02:00
|
|
|
vih->bmiHeader.biHeight = -vih->bmiHeader.biHeight;
|
|
|
|
vih->bmiHeader.biBitCount = 24;
|
|
|
|
vih->bmiHeader.biCompression = BI_RGB;
|
2012-01-24 15:15:52 +01:00
|
|
|
vih->bmiHeader.biSizeImage = width * abs(height) * 3;
|
2010-10-27 20:14:15 +02:00
|
|
|
} else {
|
|
|
|
VIDEOINFOHEADER2 *vih = (VIDEOINFOHEADER2*)outpmt->pbFormat;
|
|
|
|
avgtime = vih->AvgTimePerFrame;
|
|
|
|
width = vih->bmiHeader.biWidth;
|
|
|
|
height = vih->bmiHeader.biHeight;
|
2012-01-24 15:15:52 +01:00
|
|
|
if (vih->bmiHeader.biHeight > 0)
|
2010-10-27 20:14:15 +02:00
|
|
|
vih->bmiHeader.biHeight = -vih->bmiHeader.biHeight;
|
|
|
|
vih->bmiHeader.biBitCount = 24;
|
|
|
|
vih->bmiHeader.biCompression = BI_RGB;
|
2012-01-24 15:15:52 +01:00
|
|
|
vih->bmiHeader.biSizeImage = width * abs(height) * 3;
|
2010-10-27 20:14:15 +02:00
|
|
|
}
|
|
|
|
if (!avgtime)
|
|
|
|
avgtime = 10000000 / 30;
|
|
|
|
|
|
|
|
outpmt->subtype = MEDIASUBTYPE_RGB24;
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
capsin = gst_caps_new_simple("video/x-raw",
|
|
|
|
"format", G_TYPE_STRING,
|
|
|
|
gst_video_format_to_string(
|
|
|
|
gst_video_format_from_fourcc(amt->subtype.Data1)),
|
2010-10-27 20:14:15 +02:00
|
|
|
"width", G_TYPE_INT, width,
|
|
|
|
"height", G_TYPE_INT, height,
|
|
|
|
"framerate", GST_TYPE_FRACTION, 10000000, avgtime,
|
|
|
|
NULL);
|
2016-01-14 20:23:04 +01:00
|
|
|
capsout = gst_caps_new_simple("video/x-raw",
|
|
|
|
"format", G_TYPE_STRING, "BGR",
|
2010-10-27 20:14:15 +02:00
|
|
|
"width", G_TYPE_INT, width,
|
|
|
|
"height", G_TYPE_INT, height,
|
|
|
|
"framerate", GST_TYPE_FRACTION, 10000000, avgtime,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
hr = Gstreamer_transform_ConnectInput(This, amt, capsin, capsout);
|
|
|
|
gst_caps_unref(capsin);
|
|
|
|
gst_caps_unref(capsout);
|
|
|
|
|
|
|
|
This->cbBuffer = width * height * 4;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TransformFilterFuncTable Gstreamer_YUV_vtbl = {
|
|
|
|
Gstreamer_transform_DecideBufferSize,
|
|
|
|
Gstreamer_transform_ProcessBegin,
|
|
|
|
Gstreamer_transform_ProcessData,
|
|
|
|
Gstreamer_transform_ProcessEnd,
|
|
|
|
Gstreamer_YUV_QueryConnect,
|
|
|
|
Gstreamer_YUV_SetMediaType,
|
|
|
|
Gstreamer_YUV_ConnectInput,
|
|
|
|
Gstreamer_transform_Cleanup,
|
|
|
|
Gstreamer_transform_EndOfStream,
|
|
|
|
Gstreamer_transform_BeginFlush,
|
|
|
|
Gstreamer_transform_EndFlush,
|
2010-11-09 23:42:46 +01:00
|
|
|
Gstreamer_transform_NewSegment,
|
|
|
|
Gstreamer_transform_QOS
|
2010-10-27 20:14:15 +02:00
|
|
|
};
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
IUnknown * CALLBACK Gstreamer_YUV_create(IUnknown *punkouter, HRESULT *phr)
|
2010-10-27 20:14:15 +02:00
|
|
|
{
|
|
|
|
IUnknown *obj = NULL;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
|
|
|
TRACE("%p %p\n", punkouter, phr);
|
|
|
|
|
2010-10-27 20:14:15 +02:00
|
|
|
if (!Gstreamer_init())
|
|
|
|
{
|
|
|
|
*phr = E_FAIL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
*phr = Gstreamer_transform_create(punkouter, &CLSID_Gstreamer_YUV, "videoconvert", &Gstreamer_YUV_vtbl, (LPVOID*)&obj);
|
2016-01-14 20:22:11 +01:00
|
|
|
|
|
|
|
TRACE("returning %p\n", obj);
|
|
|
|
|
2010-10-27 20:14:15 +02:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_AudioConvert_QueryConnect(TransformFilter *iface, const AM_MEDIA_TYPE *amt)
|
|
|
|
{
|
2010-10-28 21:42:33 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)iface;
|
|
|
|
TRACE("%p %p\n", This, amt);
|
|
|
|
dump_AM_MEDIA_TYPE(amt);
|
|
|
|
|
|
|
|
if (!IsEqualGUID(&amt->majortype, &MEDIATYPE_Audio) ||
|
|
|
|
!IsEqualGUID(&amt->subtype, &MEDIASUBTYPE_PCM) ||
|
|
|
|
!IsEqualGUID(&amt->formattype, &FORMAT_WaveFormatEx))
|
|
|
|
return S_FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Gstreamer_AudioConvert_ConnectInput(TransformFilter *tf, PIN_DIRECTION dir, IPin *pin)
|
|
|
|
{
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p 0x%x %p\n", tf, dir, pin);
|
2010-10-28 21:42:33 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI Gstreamer_AudioConvert_SetMediaType(TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE *amt)
|
|
|
|
{
|
2010-10-28 21:42:33 +02:00
|
|
|
GstTfImpl *This = (GstTfImpl*)tf;
|
|
|
|
GstCaps *capsin, *capsout;
|
|
|
|
AM_MEDIA_TYPE *outpmt = &This->tf.pmt;
|
|
|
|
WAVEFORMATEX *inwfe;
|
|
|
|
WAVEFORMATEX *outwfe;
|
|
|
|
WAVEFORMATEXTENSIBLE *outwfx;
|
2016-01-14 20:23:04 +01:00
|
|
|
GstAudioFormat format;
|
2010-10-28 21:42:33 +02:00
|
|
|
HRESULT hr;
|
2013-10-10 21:52:43 +02:00
|
|
|
BOOL inisfloat = FALSE;
|
|
|
|
int indepth;
|
2010-10-28 21:42:33 +02:00
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p 0x%x %p\n", This, dir, amt);
|
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
|
|
|
|
2010-10-28 21:42:33 +02:00
|
|
|
if (dir != PINDIR_INPUT)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (Gstreamer_AudioConvert_QueryConnect(&This->tf, amt) == S_FALSE || !amt->pbFormat)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
FreeMediaType(outpmt);
|
|
|
|
*outpmt = *amt;
|
|
|
|
outpmt->pUnk = NULL;
|
|
|
|
outpmt->cbFormat = sizeof(WAVEFORMATEXTENSIBLE);
|
|
|
|
outpmt->pbFormat = CoTaskMemAlloc(outpmt->cbFormat);
|
|
|
|
|
|
|
|
inwfe = (WAVEFORMATEX*)amt->pbFormat;
|
|
|
|
indepth = inwfe->wBitsPerSample;
|
|
|
|
if (inwfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
|
|
|
|
WAVEFORMATEXTENSIBLE *inwfx = (WAVEFORMATEXTENSIBLE*)inwfe;
|
|
|
|
inisfloat = IsEqualGUID(&inwfx->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
|
|
|
|
if (inwfx->Samples.wValidBitsPerSample)
|
|
|
|
indepth = inwfx->Samples.wValidBitsPerSample;
|
2016-02-19 21:11:53 +01:00
|
|
|
} else if (inwfe->wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
|
|
|
|
inisfloat = TRUE;
|
|
|
|
|
|
|
|
if (inisfloat)
|
|
|
|
format = inwfe->wBitsPerSample == 64 ? GST_AUDIO_FORMAT_F64LE : GST_AUDIO_FORMAT_F32LE;
|
|
|
|
else
|
2016-03-02 11:17:14 +01:00
|
|
|
format = gst_audio_format_build_integer(inwfe->wBitsPerSample != 8, G_LITTLE_ENDIAN,
|
|
|
|
inwfe->wBitsPerSample, indepth);
|
2010-10-28 21:42:33 +02:00
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
capsin = gst_caps_new_simple("audio/x-raw",
|
|
|
|
"format", G_TYPE_STRING, gst_audio_format_to_string(format),
|
2010-10-28 21:42:33 +02:00
|
|
|
"channels", G_TYPE_INT, inwfe->nChannels,
|
|
|
|
"rate", G_TYPE_INT, inwfe->nSamplesPerSec,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
outwfe = (WAVEFORMATEX*)outpmt->pbFormat;
|
|
|
|
outwfx = (WAVEFORMATEXTENSIBLE*)outwfe;
|
|
|
|
outwfe->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
|
|
|
|
outwfe->nChannels = 2;
|
|
|
|
outwfe->nSamplesPerSec = inwfe->nSamplesPerSec;
|
|
|
|
outwfe->wBitsPerSample = 16;
|
|
|
|
outwfe->nBlockAlign = outwfe->nChannels * outwfe->wBitsPerSample / 8;
|
|
|
|
outwfe->nAvgBytesPerSec = outwfe->nBlockAlign * outwfe->nSamplesPerSec;
|
|
|
|
outwfe->cbSize = sizeof(*outwfx) - sizeof(*outwfe);
|
|
|
|
outwfx->Samples.wValidBitsPerSample = outwfe->wBitsPerSample;
|
|
|
|
outwfx->dwChannelMask = SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT;
|
|
|
|
outwfx->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
capsout = gst_caps_new_simple("audio/x-raw",
|
|
|
|
"format", G_TYPE_STRING, "S16LE",
|
2010-10-28 21:42:33 +02:00
|
|
|
"channels", G_TYPE_INT, outwfe->nChannels,
|
|
|
|
"rate", G_TYPE_INT, outwfe->nSamplesPerSec,
|
|
|
|
NULL);
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
|
2010-10-28 21:42:33 +02:00
|
|
|
hr = Gstreamer_transform_ConnectInput(This, amt, capsin, capsout);
|
|
|
|
gst_caps_unref(capsin);
|
|
|
|
gst_caps_unref(capsout);
|
|
|
|
|
|
|
|
This->cbBuffer = inwfe->nAvgBytesPerSec;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TransformFilterFuncTable Gstreamer_AudioConvert_vtbl = {
|
|
|
|
Gstreamer_transform_DecideBufferSize,
|
|
|
|
Gstreamer_transform_ProcessBegin,
|
|
|
|
Gstreamer_transform_ProcessData,
|
|
|
|
Gstreamer_transform_ProcessEnd,
|
|
|
|
Gstreamer_AudioConvert_QueryConnect,
|
|
|
|
Gstreamer_AudioConvert_SetMediaType,
|
|
|
|
Gstreamer_AudioConvert_ConnectInput,
|
|
|
|
Gstreamer_transform_Cleanup,
|
|
|
|
Gstreamer_transform_EndOfStream,
|
|
|
|
Gstreamer_transform_BeginFlush,
|
|
|
|
Gstreamer_transform_EndFlush,
|
2010-11-09 23:42:46 +01:00
|
|
|
Gstreamer_transform_NewSegment,
|
|
|
|
Gstreamer_transform_QOS
|
2010-10-28 21:42:33 +02:00
|
|
|
};
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
IUnknown * CALLBACK Gstreamer_AudioConvert_create(IUnknown *punkouter, HRESULT *phr)
|
2010-10-28 21:42:33 +02:00
|
|
|
{
|
|
|
|
IUnknown *obj = NULL;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
|
|
|
TRACE("%p %p\n", punkouter, phr);
|
|
|
|
|
2010-10-28 21:42:33 +02:00
|
|
|
if (!Gstreamer_init())
|
|
|
|
{
|
|
|
|
*phr = E_FAIL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-14 20:22:11 +01:00
|
|
|
|
|
|
|
*phr = Gstreamer_transform_create(punkouter, &CLSID_Gstreamer_AudioConvert, "audioconvert", &Gstreamer_AudioConvert_vtbl, (LPVOID*)&obj);
|
|
|
|
|
|
|
|
TRACE("returning %p\n", obj);
|
|
|
|
|
2010-10-28 21:42:33 +02:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2010-10-27 20:14:06 +02:00
|
|
|
static const IBaseFilterVtbl GSTTf_Vtbl =
|
|
|
|
{
|
2013-03-04 12:21:19 +01:00
|
|
|
TransformFilterImpl_QueryInterface,
|
2010-10-27 20:14:06 +02:00
|
|
|
BaseFilterImpl_AddRef,
|
|
|
|
TransformFilterImpl_Release,
|
|
|
|
BaseFilterImpl_GetClassID,
|
|
|
|
TransformFilterImpl_Stop,
|
|
|
|
TransformFilterImpl_Pause,
|
|
|
|
TransformFilterImpl_Run,
|
|
|
|
BaseFilterImpl_GetState,
|
|
|
|
BaseFilterImpl_SetSyncSource,
|
|
|
|
BaseFilterImpl_GetSyncSource,
|
|
|
|
BaseFilterImpl_EnumPins,
|
|
|
|
TransformFilterImpl_FindPin,
|
|
|
|
BaseFilterImpl_QueryFilterInfo,
|
|
|
|
BaseFilterImpl_JoinFilterGraph,
|
|
|
|
BaseFilterImpl_QueryVendorInfo
|
|
|
|
};
|