2010-10-26 18:39:15 +02:00
|
|
|
/*
|
|
|
|
* GStreamer splitter + decoder, adapted from parser.c
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include "gst_private.h"
|
|
|
|
#include "gst_guids.h"
|
2016-01-12 20:35:04 +01:00
|
|
|
#include "gst_cbs.h"
|
2010-10-26 18:39:15 +02:00
|
|
|
|
|
|
|
#include "vfwmsgs.h"
|
|
|
|
#include "amvideo.h"
|
|
|
|
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "dvdmedia.h"
|
|
|
|
#include "mmreg.h"
|
|
|
|
#include "ks.h"
|
|
|
|
#include "initguid.h"
|
2020-01-25 02:55:09 +01:00
|
|
|
#include "wmcodecdsp.h"
|
2010-10-26 18:39:15 +02:00
|
|
|
#include "ksmedia.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(gstreamer);
|
|
|
|
|
2019-12-23 16:44:31 +01:00
|
|
|
static const GUID MEDIASUBTYPE_CVID = {mmioFOURCC('c','v','i','d'), 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
|
|
|
|
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux
|
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter filter;
|
2019-09-21 00:35:05 +02:00
|
|
|
IAMStreamSelect IAMStreamSelect_iface;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2019-12-11 04:53:34 +01:00
|
|
|
struct strmbase_sink sink;
|
2019-09-08 20:55:04 +02:00
|
|
|
IAsyncReader *reader;
|
2020-01-24 16:55:58 +01:00
|
|
|
|
|
|
|
struct gstdemux_source **sources;
|
2020-01-24 16:55:59 +01:00
|
|
|
unsigned int source_count;
|
2020-01-24 16:56:00 +01:00
|
|
|
BOOL enum_sink_first;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
|
|
|
LONGLONG filesize;
|
|
|
|
|
2019-09-08 20:55:05 +02:00
|
|
|
BOOL initial, ignore_flush;
|
2016-05-12 21:27:04 +02:00
|
|
|
GstElement *container;
|
2010-10-26 18:39:15 +02:00
|
|
|
GstPad *my_src, *their_sink;
|
|
|
|
GstBus *bus;
|
|
|
|
guint64 start, nextofs, nextpullofs, stop;
|
2020-01-02 03:28:41 +01:00
|
|
|
HANDLE no_more_pads_event, duration_event, error_event;
|
2010-10-26 18:40:57 +02:00
|
|
|
|
|
|
|
HANDLE push_thread;
|
2019-09-19 04:37:02 +02:00
|
|
|
|
|
|
|
BOOL (*init_gst)(struct gstdemux *filter);
|
2020-01-24 16:56:02 +01:00
|
|
|
HRESULT (*source_query_accept)(struct gstdemux_source *pin, const AM_MEDIA_TYPE *mt);
|
2020-01-25 02:55:08 +01:00
|
|
|
HRESULT (*source_get_media_type)(struct gstdemux_source *pin, unsigned int index, AM_MEDIA_TYPE *mt);
|
2019-09-12 21:28:28 +02:00
|
|
|
};
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source
|
|
|
|
{
|
2019-09-12 21:28:25 +02:00
|
|
|
struct strmbase_source pin;
|
2012-04-02 14:52:15 +02:00
|
|
|
IQualityControl IQualityControl_iface;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2020-01-28 02:06:55 +01:00
|
|
|
GstPad *their_src, *post_sink, *post_src, *my_sink;
|
2020-03-27 06:54:28 +01:00
|
|
|
GstElement *flip;
|
2020-06-13 17:34:22 +02:00
|
|
|
HANDLE caps_event, eos_event;
|
2010-11-07 15:02:51 +01:00
|
|
|
GstSegment *segment;
|
2010-11-09 23:42:47 +01:00
|
|
|
SourceSeeking seek;
|
2010-10-26 18:39:15 +02:00
|
|
|
};
|
|
|
|
|
2019-09-12 21:28:28 +02:00
|
|
|
static inline struct gstdemux *impl_from_strmbase_filter(struct strmbase_filter *iface)
|
2019-09-06 02:02:15 +02:00
|
|
|
{
|
2019-09-12 21:28:28 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct gstdemux, filter);
|
2019-09-06 02:02:15 +02:00
|
|
|
}
|
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};
|
|
|
|
static const IMediaSeekingVtbl GST_Seeking_Vtbl;
|
2010-11-09 23:42:48 +01:00
|
|
|
static const IQualityControlVtbl GSTOutPin_QualityControl_Vtbl;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2019-09-19 04:37:01 +02:00
|
|
|
static struct gstdemux_source *create_pin(struct gstdemux *filter, const WCHAR *name);
|
2019-09-12 21:28:28 +02:00
|
|
|
static HRESULT GST_RemoveOutputPins(struct gstdemux *This);
|
2010-10-26 18:40:41 +02:00
|
|
|
static HRESULT WINAPI GST_ChangeCurrent(IMediaSeeking *iface);
|
|
|
|
static HRESULT WINAPI GST_ChangeStop(IMediaSeeking *iface);
|
|
|
|
static HRESULT WINAPI GST_ChangeRate(IMediaSeeking *iface);
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2020-06-30 03:14:06 +02:00
|
|
|
static gboolean amt_from_gst_audio_info(const GstAudioInfo *info, AM_MEDIA_TYPE *amt)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2010-10-26 18:39:55 +02:00
|
|
|
WAVEFORMATEXTENSIBLE *wfe;
|
|
|
|
WAVEFORMATEX *wfx;
|
2016-11-29 06:35:52 +01:00
|
|
|
gint32 depth, bpp;
|
2010-10-26 18:39:55 +02:00
|
|
|
|
2020-03-16 20:40:13 +01:00
|
|
|
wfe = CoTaskMemAlloc(sizeof(*wfe));
|
2010-10-26 18:39:55 +02:00
|
|
|
wfx = (WAVEFORMATEX*)wfe;
|
|
|
|
amt->majortype = MEDIATYPE_Audio;
|
|
|
|
amt->subtype = MEDIASUBTYPE_PCM;
|
|
|
|
amt->formattype = FORMAT_WaveFormatEx;
|
|
|
|
amt->pbFormat = (BYTE*)wfe;
|
|
|
|
amt->cbFormat = sizeof(*wfe);
|
2019-09-17 02:29:44 +02:00
|
|
|
amt->bFixedSizeSamples = TRUE;
|
2019-09-17 02:29:45 +02:00
|
|
|
amt->bTemporalCompression = FALSE;
|
2010-10-26 18:39:55 +02:00
|
|
|
amt->pUnk = NULL;
|
|
|
|
|
|
|
|
wfx->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
|
2016-01-14 20:23:04 +01:00
|
|
|
|
2020-06-30 03:14:06 +02:00
|
|
|
wfx->nChannels = info->channels;
|
|
|
|
wfx->nSamplesPerSec = info->rate;
|
|
|
|
depth = GST_AUDIO_INFO_WIDTH(info);
|
|
|
|
bpp = GST_AUDIO_INFO_DEPTH(info);
|
2016-01-14 20:23:04 +01:00
|
|
|
|
2010-10-26 18:39:55 +02:00
|
|
|
if (!depth || depth > 32 || depth % 8)
|
|
|
|
depth = bpp;
|
|
|
|
else if (!bpp)
|
|
|
|
bpp = depth;
|
|
|
|
wfe->Samples.wValidBitsPerSample = depth;
|
|
|
|
wfx->wBitsPerSample = bpp;
|
|
|
|
wfx->cbSize = sizeof(*wfe)-sizeof(*wfx);
|
|
|
|
switch (wfx->nChannels) {
|
|
|
|
case 1: wfe->dwChannelMask = KSAUDIO_SPEAKER_MONO; break;
|
|
|
|
case 2: wfe->dwChannelMask = KSAUDIO_SPEAKER_STEREO; break;
|
|
|
|
case 4: wfe->dwChannelMask = KSAUDIO_SPEAKER_SURROUND; break;
|
|
|
|
case 5: wfe->dwChannelMask = (KSAUDIO_SPEAKER_5POINT1 & ~SPEAKER_LOW_FREQUENCY); break;
|
|
|
|
case 6: wfe->dwChannelMask = KSAUDIO_SPEAKER_5POINT1; break;
|
|
|
|
case 8: wfe->dwChannelMask = KSAUDIO_SPEAKER_7POINT1; break;
|
|
|
|
default:
|
|
|
|
wfe->dwChannelMask = 0;
|
|
|
|
}
|
2020-06-30 03:14:06 +02:00
|
|
|
if (GST_AUDIO_INFO_IS_FLOAT(info))
|
|
|
|
{
|
2020-01-28 02:06:53 +01:00
|
|
|
amt->subtype = MEDIASUBTYPE_IEEE_FLOAT;
|
2010-10-26 18:39:55 +02:00
|
|
|
wfe->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
|
2011-09-13 15:32:31 +02:00
|
|
|
} else {
|
2010-10-26 18:39:55 +02:00
|
|
|
wfe->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
|
2011-09-13 15:32:31 +02:00
|
|
|
if (wfx->nChannels <= 2 && bpp <= 16 && depth == bpp) {
|
|
|
|
wfx->wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
wfx->cbSize = 0;
|
2019-09-17 02:29:46 +02:00
|
|
|
amt->cbFormat = sizeof(WAVEFORMATEX);
|
2011-09-13 15:32:31 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-17 02:29:43 +02:00
|
|
|
amt->lSampleSize = wfx->nBlockAlign = wfx->nChannels * wfx->wBitsPerSample/8;
|
2010-10-26 18:39:55 +02:00
|
|
|
wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign;
|
2013-11-09 11:03:41 +01:00
|
|
|
return TRUE;
|
2010-10-26 18:39:55 +02:00
|
|
|
}
|
|
|
|
|
2020-03-16 20:40:15 +01:00
|
|
|
static gboolean amt_from_gst_video_info(const GstVideoInfo *info, AM_MEDIA_TYPE *amt)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2020-10-06 20:04:57 +02:00
|
|
|
VIDEOINFO *vih;
|
2016-11-16 06:41:49 +01:00
|
|
|
BITMAPINFOHEADER *bih;
|
2020-03-16 20:40:14 +01:00
|
|
|
gint32 width, height;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2020-03-16 20:40:15 +01:00
|
|
|
width = GST_VIDEO_INFO_WIDTH(info);
|
|
|
|
height = GST_VIDEO_INFO_HEIGHT(info);
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2020-03-16 20:40:13 +01:00
|
|
|
vih = CoTaskMemAlloc(sizeof(*vih));
|
2016-11-16 06:41:49 +01:00
|
|
|
bih = &vih->bmiHeader;
|
|
|
|
|
2010-10-26 18:39:36 +02:00
|
|
|
amt->formattype = FORMAT_VideoInfo;
|
|
|
|
amt->pbFormat = (BYTE*)vih;
|
2020-10-06 20:04:57 +02:00
|
|
|
amt->cbFormat = sizeof(VIDEOINFOHEADER);
|
2019-09-20 01:59:35 +02:00
|
|
|
amt->bFixedSizeSamples = FALSE;
|
|
|
|
amt->bTemporalCompression = TRUE;
|
2019-09-20 01:59:36 +02:00
|
|
|
amt->lSampleSize = 1;
|
2010-10-26 18:39:36 +02:00
|
|
|
amt->pUnk = NULL;
|
|
|
|
ZeroMemory(vih, sizeof(*vih));
|
|
|
|
amt->majortype = MEDIATYPE_Video;
|
2019-09-14 19:43:27 +02:00
|
|
|
|
2020-03-16 20:40:15 +01:00
|
|
|
if (GST_VIDEO_INFO_IS_RGB(info))
|
2019-09-14 19:43:27 +02:00
|
|
|
{
|
2020-10-06 20:04:57 +02:00
|
|
|
bih->biCompression = BI_RGB;
|
2020-03-16 20:40:15 +01:00
|
|
|
switch (GST_VIDEO_INFO_FORMAT(info))
|
2019-09-14 19:43:27 +02:00
|
|
|
{
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
amt->subtype = MEDIASUBTYPE_ARGB32;
|
|
|
|
bih->biBitCount = 32;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
amt->subtype = MEDIASUBTYPE_RGB32;
|
|
|
|
bih->biBitCount = 32;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
|
|
|
amt->subtype = MEDIASUBTYPE_RGB24;
|
|
|
|
bih->biBitCount = 24;
|
|
|
|
break;
|
2020-10-06 20:04:56 +02:00
|
|
|
case GST_VIDEO_FORMAT_RGB16:
|
2019-09-14 19:43:27 +02:00
|
|
|
amt->subtype = MEDIASUBTYPE_RGB565;
|
2020-10-06 20:04:57 +02:00
|
|
|
amt->cbFormat = offsetof(VIDEOINFO, u.dwBitMasks[3]);
|
|
|
|
vih->u.dwBitMasks[iRED] = 0xf800;
|
|
|
|
vih->u.dwBitMasks[iGREEN] = 0x07e0;
|
|
|
|
vih->u.dwBitMasks[iBLUE] = 0x001f;
|
2019-09-14 19:43:27 +02:00
|
|
|
bih->biBitCount = 16;
|
2020-10-06 20:04:57 +02:00
|
|
|
bih->biCompression = BI_BITFIELDS;
|
2019-09-14 19:43:27 +02:00
|
|
|
break;
|
2020-10-06 20:04:56 +02:00
|
|
|
case GST_VIDEO_FORMAT_RGB15:
|
2019-09-14 19:43:27 +02:00
|
|
|
amt->subtype = MEDIASUBTYPE_RGB555;
|
|
|
|
bih->biBitCount = 16;
|
|
|
|
break;
|
|
|
|
default:
|
2020-06-30 03:14:06 +02:00
|
|
|
WARN("Cannot convert %s to a DirectShow type.\n", GST_VIDEO_INFO_NAME(info));
|
2020-03-16 20:40:13 +01:00
|
|
|
CoTaskMemFree(vih);
|
2019-09-14 19:43:27 +02:00
|
|
|
return FALSE;
|
2010-10-26 18:39:36 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
amt->subtype = MEDIATYPE_Video;
|
2020-03-16 20:40:15 +01:00
|
|
|
if (!(amt->subtype.Data1 = gst_video_format_to_fourcc(GST_VIDEO_INFO_FORMAT(info))))
|
2020-03-16 20:40:14 +01:00
|
|
|
{
|
2020-03-16 20:40:13 +01:00
|
|
|
CoTaskMemFree(vih);
|
2013-11-09 11:03:41 +01:00
|
|
|
return FALSE;
|
2016-11-16 06:41:49 +01:00
|
|
|
}
|
2010-10-26 18:39:36 +02:00
|
|
|
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'):
|
|
|
|
bih->biBitCount = 12; break;
|
|
|
|
case mmioFOURCC('Y','U','Y','2'):
|
|
|
|
case mmioFOURCC('Y','V','Y','U'):
|
2020-03-27 06:54:29 +01:00
|
|
|
case mmioFOURCC('U','Y','V','Y'):
|
2010-10-26 18:39:36 +02:00
|
|
|
bih->biBitCount = 16; break;
|
|
|
|
}
|
|
|
|
bih->biCompression = amt->subtype.Data1;
|
|
|
|
}
|
2020-03-16 20:40:16 +01:00
|
|
|
bih->biSizeImage = GST_VIDEO_INFO_SIZE(info);
|
2020-03-16 20:40:14 +01:00
|
|
|
if ((vih->AvgTimePerFrame = (REFERENCE_TIME)MulDiv(10000000,
|
2020-03-16 20:40:15 +01:00
|
|
|
GST_VIDEO_INFO_FPS_D(info), GST_VIDEO_INFO_FPS_N(info))) == -1)
|
2017-01-25 15:02:20 +01:00
|
|
|
vih->AvgTimePerFrame = 0; /* zero division or integer overflow */
|
2010-10-26 18:39:36 +02:00
|
|
|
bih->biSize = sizeof(*bih);
|
|
|
|
bih->biWidth = width;
|
|
|
|
bih->biHeight = height;
|
|
|
|
bih->biPlanes = 1;
|
2013-11-09 11:03:41 +01:00
|
|
|
return TRUE;
|
2010-10-26 18:39:36 +02:00
|
|
|
}
|
|
|
|
|
2019-09-21 00:35:05 +02:00
|
|
|
static gboolean amt_from_gst_caps_audio_mpeg(const GstCaps *caps, AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
GstStructure *structure = gst_caps_get_structure(caps, 0);
|
|
|
|
gint layer, channels, rate;
|
|
|
|
|
|
|
|
mt->majortype = MEDIATYPE_Audio;
|
|
|
|
mt->subtype = MEDIASUBTYPE_MPEG1AudioPayload;
|
|
|
|
mt->bFixedSizeSamples = FALSE;
|
|
|
|
mt->bTemporalCompression = FALSE;
|
|
|
|
mt->lSampleSize = 0;
|
|
|
|
mt->formattype = FORMAT_WaveFormatEx;
|
|
|
|
mt->pUnk = NULL;
|
|
|
|
|
|
|
|
if (!gst_structure_get_int(structure, "layer", &layer))
|
|
|
|
{
|
|
|
|
WARN("Missing 'layer' value.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!gst_structure_get_int(structure, "channels", &channels))
|
|
|
|
{
|
|
|
|
WARN("Missing 'channels' value.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!gst_structure_get_int(structure, "rate", &rate))
|
|
|
|
{
|
|
|
|
WARN("Missing 'rate' value.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layer == 3)
|
|
|
|
{
|
|
|
|
MPEGLAYER3WAVEFORMAT *wfx = CoTaskMemAlloc(sizeof(*wfx));
|
|
|
|
memset(wfx, 0, sizeof(*wfx));
|
|
|
|
|
|
|
|
mt->subtype.Data1 = WAVE_FORMAT_MPEGLAYER3;
|
|
|
|
mt->cbFormat = sizeof(*wfx);
|
|
|
|
mt->pbFormat = (BYTE *)wfx;
|
|
|
|
wfx->wfx.wFormatTag = WAVE_FORMAT_MPEGLAYER3;
|
|
|
|
wfx->wfx.nChannels = channels;
|
|
|
|
wfx->wfx.nSamplesPerSec = rate;
|
|
|
|
/* FIXME: We can't get most of the MPEG data from the caps. We may have
|
|
|
|
* to manually parse the header. */
|
|
|
|
wfx->wfx.cbSize = sizeof(*wfx) - sizeof(WAVEFORMATEX);
|
|
|
|
wfx->wID = MPEGLAYER3_ID_MPEG;
|
|
|
|
wfx->fdwFlags = MPEGLAYER3_FLAG_PADDING_ON;
|
|
|
|
wfx->nFramesPerBlock = 1;
|
|
|
|
wfx->nCodecDelay = 1393;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MPEG1WAVEFORMAT *wfx = CoTaskMemAlloc(sizeof(*wfx));
|
|
|
|
memset(wfx, 0, sizeof(*wfx));
|
|
|
|
|
|
|
|
mt->subtype.Data1 = WAVE_FORMAT_MPEG;
|
|
|
|
mt->cbFormat = sizeof(*wfx);
|
|
|
|
mt->pbFormat = (BYTE *)wfx;
|
|
|
|
wfx->wfx.wFormatTag = WAVE_FORMAT_MPEG;
|
|
|
|
wfx->wfx.nChannels = channels;
|
|
|
|
wfx->wfx.nSamplesPerSec = rate;
|
|
|
|
wfx->wfx.cbSize = sizeof(*wfx) - sizeof(WAVEFORMATEX);
|
|
|
|
wfx->fwHeadLayer = layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-09-14 19:43:28 +02:00
|
|
|
static gboolean amt_from_gst_caps(const GstCaps *caps, AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
const char *type = gst_structure_get_name(gst_caps_get_structure(caps, 0));
|
2019-12-23 16:44:31 +01:00
|
|
|
GstStructure *structure = gst_caps_get_structure(caps, 0);
|
2019-09-14 19:43:28 +02:00
|
|
|
|
2020-06-30 03:14:06 +02:00
|
|
|
memset(mt, 0, sizeof(AM_MEDIA_TYPE));
|
|
|
|
|
2019-09-14 19:43:28 +02:00
|
|
|
if (!strcmp(type, "audio/x-raw"))
|
2020-06-30 03:14:06 +02:00
|
|
|
{
|
|
|
|
GstAudioInfo info;
|
|
|
|
|
|
|
|
if (!(gst_audio_info_from_caps(&info, caps)))
|
|
|
|
return FALSE;
|
|
|
|
return amt_from_gst_audio_info(&info, mt);
|
|
|
|
}
|
2019-09-14 19:43:28 +02:00
|
|
|
else if (!strcmp(type, "video/x-raw"))
|
2020-03-16 20:40:15 +01:00
|
|
|
{
|
|
|
|
GstVideoInfo info;
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps(&info, caps))
|
|
|
|
return FALSE;
|
|
|
|
return amt_from_gst_video_info(&info, mt);
|
|
|
|
}
|
2019-09-21 00:35:05 +02:00
|
|
|
else if (!strcmp(type, "audio/mpeg"))
|
|
|
|
return amt_from_gst_caps_audio_mpeg(caps, mt);
|
2019-12-23 16:44:31 +01:00
|
|
|
else if (!strcmp(type, "video/x-cinepak"))
|
|
|
|
{
|
|
|
|
VIDEOINFOHEADER *vih;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
mt->majortype = MEDIATYPE_Video;
|
|
|
|
mt->subtype = MEDIASUBTYPE_CVID;
|
|
|
|
mt->bTemporalCompression = TRUE;
|
|
|
|
mt->lSampleSize = 1;
|
|
|
|
mt->formattype = FORMAT_VideoInfo;
|
|
|
|
if (!(vih = CoTaskMemAlloc(sizeof(VIDEOINFOHEADER))))
|
|
|
|
return FALSE;
|
|
|
|
mt->cbFormat = sizeof(VIDEOINFOHEADER);
|
|
|
|
mt->pbFormat = (BYTE *)vih;
|
|
|
|
|
|
|
|
memset(vih, 0, sizeof(VIDEOINFOHEADER));
|
|
|
|
vih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
if (gst_structure_get_int(structure, "width", &i))
|
|
|
|
vih->bmiHeader.biWidth = i;
|
|
|
|
if (gst_structure_get_int(structure, "height", &i))
|
|
|
|
vih->bmiHeader.biHeight = i;
|
|
|
|
vih->bmiHeader.biPlanes = 1;
|
|
|
|
/* Both ffmpeg's encoder and a Cinepak file seen in the wild report
|
|
|
|
* 24 bpp. ffmpeg sets biSizeImage as below; others may be smaller, but
|
|
|
|
* as long as every sample fits into our allocator, we're fine. */
|
|
|
|
vih->bmiHeader.biBitCount = 24;
|
|
|
|
vih->bmiHeader.biCompression = mmioFOURCC('c','v','i','d');
|
|
|
|
vih->bmiHeader.biSizeImage = vih->bmiHeader.biWidth
|
|
|
|
* vih->bmiHeader.biHeight * vih->bmiHeader.biBitCount / 8;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-09-14 19:43:28 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Unhandled type %s.\n", debugstr_a(type));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-25 02:55:09 +01:00
|
|
|
static GstCaps *amt_to_gst_caps_video(const AM_MEDIA_TYPE *mt)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2020-01-25 02:55:09 +01:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const GUID *subtype;
|
|
|
|
GstVideoFormat format;
|
|
|
|
}
|
|
|
|
format_map[] =
|
|
|
|
{
|
|
|
|
{&MEDIASUBTYPE_ARGB32, GST_VIDEO_FORMAT_BGRA},
|
|
|
|
{&MEDIASUBTYPE_RGB32, GST_VIDEO_FORMAT_BGRx},
|
|
|
|
{&MEDIASUBTYPE_RGB24, GST_VIDEO_FORMAT_BGR},
|
2020-10-06 20:04:56 +02:00
|
|
|
{&MEDIASUBTYPE_RGB565, GST_VIDEO_FORMAT_RGB16},
|
|
|
|
{&MEDIASUBTYPE_RGB555, GST_VIDEO_FORMAT_RGB15},
|
2020-01-25 02:55:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const VIDEOINFOHEADER *vih = (VIDEOINFOHEADER *)mt->pbFormat;
|
|
|
|
GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
|
|
|
|
GstVideoInfo info;
|
|
|
|
unsigned int i;
|
|
|
|
GstCaps *caps;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2020-04-06 02:43:35 +02:00
|
|
|
if (!IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo)
|
|
|
|
|| mt->cbFormat < sizeof(VIDEOINFOHEADER) || !mt->pbFormat)
|
|
|
|
return NULL;
|
|
|
|
|
2020-01-25 02:55:09 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(format_map); ++i)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(&mt->subtype, format_map[i].subtype))
|
|
|
|
{
|
|
|
|
format = format_map[i].format;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
format = gst_video_format_from_fourcc(vih->bmiHeader.biCompression);
|
|
|
|
|
|
|
|
if (format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
{
|
|
|
|
FIXME("Unknown video format (subtype %s, compression %#x).\n",
|
|
|
|
debugstr_guid(&mt->subtype), vih->bmiHeader.biCompression);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-08-01 21:17:35 +02:00
|
|
|
gst_video_info_set_format(&info, format, vih->bmiHeader.biWidth, vih->bmiHeader.biHeight);
|
2020-01-25 02:55:09 +01:00
|
|
|
if ((caps = gst_video_info_to_caps(&info)))
|
|
|
|
{
|
2020-03-26 18:04:31 +01:00
|
|
|
/* Clear some fields that shouldn't prevent us from connecting. */
|
2020-01-25 02:55:09 +01:00
|
|
|
for (i = 0; i < gst_caps_get_size(caps); ++i)
|
2020-03-26 18:04:31 +01:00
|
|
|
{
|
2020-06-19 04:50:41 +02:00
|
|
|
gst_structure_remove_fields(gst_caps_get_structure(caps, i),
|
|
|
|
"framerate", "pixel-aspect-ratio", "colorimetry", "chroma-site", NULL);
|
2020-03-26 18:04:31 +01:00
|
|
|
}
|
2020-01-25 02:55:09 +01:00
|
|
|
}
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *amt_to_gst_caps_audio(const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
const WAVEFORMATEX *wfx = (WAVEFORMATEX *)mt->pbFormat;
|
|
|
|
GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
|
|
|
|
GstAudioInfo info;
|
|
|
|
|
2020-04-06 02:43:35 +02:00
|
|
|
if (!IsEqualGUID(&mt->formattype, &FORMAT_WaveFormatEx)
|
|
|
|
|| mt->cbFormat < sizeof(WAVEFORMATEX) || !mt->pbFormat)
|
|
|
|
return NULL;
|
|
|
|
|
2020-01-25 02:55:09 +01:00
|
|
|
if (IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_PCM))
|
|
|
|
format = gst_audio_format_build_integer(wfx->wBitsPerSample != 8,
|
|
|
|
G_LITTLE_ENDIAN, wfx->wBitsPerSample, wfx->wBitsPerSample);
|
|
|
|
else if (IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_IEEE_FLOAT))
|
|
|
|
{
|
|
|
|
if (wfx->wBitsPerSample == 32)
|
|
|
|
format = GST_AUDIO_FORMAT_F32LE;
|
|
|
|
else if (wfx->wBitsPerSample == 64)
|
|
|
|
format = GST_AUDIO_FORMAT_F64LE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format == GST_AUDIO_FORMAT_UNKNOWN)
|
|
|
|
{
|
|
|
|
FIXME("Unknown audio format (subtype %s, depth %u).\n",
|
|
|
|
debugstr_guid(&mt->subtype), wfx->wBitsPerSample);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_audio_info_set_format(&info, format, wfx->nSamplesPerSec, wfx->nChannels, NULL);
|
|
|
|
return gst_audio_info_to_caps(&info);
|
|
|
|
}
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2020-01-25 02:55:09 +01:00
|
|
|
static GstCaps *amt_to_gst_caps(const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(&mt->majortype, &MEDIATYPE_Video))
|
|
|
|
return amt_to_gst_caps_video(mt);
|
|
|
|
else if (IsEqualGUID(&mt->majortype, &MEDIATYPE_Audio))
|
|
|
|
return amt_to_gst_caps_audio(mt);
|
|
|
|
|
|
|
|
FIXME("Unknown major type %s.\n", debugstr_guid(&mt->majortype));
|
|
|
|
return NULL;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
static gboolean query_sink(GstPad *pad, GstObject *parent, GstQuery *query)
|
|
|
|
{
|
2020-01-25 02:55:09 +01:00
|
|
|
struct gstdemux_source *pin = gst_pad_get_element_private(pad);
|
|
|
|
|
|
|
|
TRACE("pin %p, type \"%s\".\n", pin, gst_query_type_get_name(query->type));
|
|
|
|
|
|
|
|
switch (query->type)
|
|
|
|
{
|
|
|
|
case GST_QUERY_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps, *filter, *temp;
|
|
|
|
|
|
|
|
gst_query_parse_caps(query, &filter);
|
|
|
|
|
|
|
|
if (pin->pin.pin.peer)
|
|
|
|
caps = amt_to_gst_caps(&pin->pin.pin.mt);
|
|
|
|
else
|
|
|
|
caps = gst_caps_new_any();
|
|
|
|
if (!caps)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (filter)
|
|
|
|
{
|
|
|
|
temp = gst_caps_intersect(caps, filter);
|
|
|
|
gst_caps_unref(caps);
|
|
|
|
caps = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_query_set_caps_result(query, caps);
|
|
|
|
gst_caps_unref(caps);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-01-14 20:23:04 +01:00
|
|
|
case GST_QUERY_ACCEPT_CAPS:
|
|
|
|
{
|
2020-01-25 02:55:09 +01:00
|
|
|
gboolean ret = TRUE;
|
|
|
|
AM_MEDIA_TYPE mt;
|
2016-01-14 20:23:04 +01:00
|
|
|
GstCaps *caps;
|
2020-01-25 02:55:09 +01:00
|
|
|
|
|
|
|
if (!pin->pin.pin.peer)
|
|
|
|
{
|
|
|
|
gst_query_set_accept_caps_result(query, TRUE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_query_parse_accept_caps(query, &caps);
|
2020-01-25 02:55:09 +01:00
|
|
|
if (!amt_from_gst_caps(caps, &mt))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!IsEqualGUID(&mt.majortype, &pin->pin.pin.mt.majortype)
|
|
|
|
|| !IsEqualGUID(&mt.subtype, &pin->pin.pin.mt.subtype)
|
|
|
|
|| !IsEqualGUID(&mt.formattype, &pin->pin.pin.mt.formattype))
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
if (IsEqualGUID(&mt.majortype, &MEDIATYPE_Video))
|
|
|
|
{
|
|
|
|
const VIDEOINFOHEADER *req_vih = (VIDEOINFOHEADER *)mt.pbFormat;
|
|
|
|
const VIDEOINFOHEADER *our_vih = (VIDEOINFOHEADER *)pin->pin.pin.mt.pbFormat;
|
|
|
|
|
|
|
|
if (req_vih->bmiHeader.biWidth != our_vih->bmiHeader.biWidth
|
|
|
|
|| req_vih->bmiHeader.biHeight != our_vih->bmiHeader.biHeight
|
|
|
|
|| req_vih->bmiHeader.biBitCount != our_vih->bmiHeader.biBitCount
|
|
|
|
|| req_vih->bmiHeader.biCompression != our_vih->bmiHeader.biCompression)
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else if (IsEqualGUID(&mt.majortype, &MEDIATYPE_Audio))
|
|
|
|
{
|
|
|
|
const WAVEFORMATEX *req_wfx = (WAVEFORMATEX *)mt.pbFormat;
|
|
|
|
const WAVEFORMATEX *our_wfx = (WAVEFORMATEX *)pin->pin.pin.mt.pbFormat;
|
|
|
|
|
|
|
|
if (req_wfx->nChannels != our_wfx->nChannels
|
|
|
|
|| req_wfx->nSamplesPerSec != our_wfx->nSamplesPerSec
|
|
|
|
|| req_wfx->wBitsPerSample != our_wfx->wBitsPerSample)
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeMediaType(&mt);
|
|
|
|
|
|
|
|
if (!ret && WARN_ON(gstreamer))
|
|
|
|
{
|
|
|
|
gchar *str = gst_caps_to_string(caps);
|
|
|
|
WARN("Rejecting caps \"%s\".\n", debugstr_a(str));
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_query_set_accept_caps_result(query, ret);
|
|
|
|
return TRUE;
|
2016-01-14 20:23:04 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return gst_pad_query_default (pad, parent, query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:28 +02:00
|
|
|
static gboolean gst_base_src_perform_seek(struct gstdemux *This, GstEvent *event)
|
2010-10-26 18:39:15 +02:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
gdouble rate;
|
|
|
|
GstFormat seek_format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType cur_type, stop_type;
|
|
|
|
gint64 cur, stop;
|
|
|
|
gboolean flush;
|
|
|
|
guint32 seqnum;
|
|
|
|
GstEvent *tevent;
|
2010-10-26 18:40:57 +02:00
|
|
|
BOOL thread = !!This->push_thread;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
|
|
|
gst_event_parse_seek(event, &rate, &seek_format, &flags,
|
|
|
|
&cur_type, &cur, &stop_type, &stop);
|
|
|
|
|
2019-09-14 19:43:26 +02:00
|
|
|
if (seek_format != GST_FORMAT_BYTES)
|
|
|
|
{
|
|
|
|
FIXME("Unhandled format \"%s\".\n", gst_format_get_name(seek_format));
|
2013-11-09 11:03:41 +01:00
|
|
|
return FALSE;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
flush = flags & GST_SEEK_FLAG_FLUSH;
|
|
|
|
seqnum = gst_event_get_seqnum(event);
|
|
|
|
|
|
|
|
/* send flush start */
|
|
|
|
if (flush) {
|
|
|
|
tevent = gst_event_new_flush_start();
|
|
|
|
gst_event_set_seqnum(tevent, seqnum);
|
|
|
|
gst_pad_push_event(This->my_src, tevent);
|
2019-09-08 20:55:04 +02:00
|
|
|
if (This->reader)
|
|
|
|
IAsyncReader_BeginFlush(This->reader);
|
2010-10-26 18:40:57 +02:00
|
|
|
if (thread)
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_pad_set_active(This->my_src, 1);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 21:43:44 +01:00
|
|
|
This->nextofs = This->start = cur;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
|
|
|
/* and prepare to continue streaming */
|
|
|
|
if (flush) {
|
2016-01-14 20:23:04 +01:00
|
|
|
tevent = gst_event_new_flush_stop(TRUE);
|
2010-10-26 18:39:15 +02:00
|
|
|
gst_event_set_seqnum(tevent, seqnum);
|
|
|
|
gst_pad_push_event(This->my_src, tevent);
|
2019-09-08 20:55:04 +02:00
|
|
|
if (This->reader)
|
|
|
|
IAsyncReader_EndFlush(This->reader);
|
2010-10-26 18:40:57 +02:00
|
|
|
if (thread)
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_pad_set_active(This->my_src, 1);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
static gboolean event_src(GstPad *pad, GstObject *parent, GstEvent *event)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux *This = gst_pad_get_element_private(pad);
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2019-09-14 19:43:26 +02:00
|
|
|
TRACE("filter %p, type \"%s\".\n", This, GST_EVENT_TYPE_NAME(event));
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
switch (event->type) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
return gst_base_src_perform_seek(This, event);
|
|
|
|
case GST_EVENT_FLUSH_START:
|
|
|
|
EnterCriticalSection(&This->filter.csFilter);
|
2019-09-08 20:55:04 +02:00
|
|
|
if (This->reader)
|
|
|
|
IAsyncReader_BeginFlush(This->reader);
|
2010-10-26 18:39:15 +02:00
|
|
|
LeaveCriticalSection(&This->filter.csFilter);
|
|
|
|
break;
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
EnterCriticalSection(&This->filter.csFilter);
|
2019-09-08 20:55:04 +02:00
|
|
|
if (This->reader)
|
|
|
|
IAsyncReader_EndFlush(This->reader);
|
2010-10-26 18:39:15 +02:00
|
|
|
LeaveCriticalSection(&This->filter.csFilter);
|
|
|
|
break;
|
|
|
|
default:
|
2019-09-14 19:43:26 +02:00
|
|
|
WARN("Ignoring \"%s\" event.\n", GST_EVENT_TYPE_NAME(event));
|
2010-12-10 16:06:58 +01:00
|
|
|
case GST_EVENT_TAG:
|
|
|
|
case GST_EVENT_QOS:
|
2019-09-08 20:55:06 +02:00
|
|
|
case GST_EVENT_RECONFIGURE:
|
2016-01-14 20:23:04 +01:00
|
|
|
return gst_pad_event_default(pad, parent, event);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
2013-11-09 11:03:41 +01:00
|
|
|
return TRUE;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
static gboolean event_sink(GstPad *pad, GstObject *parent, GstEvent *event)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *pin = gst_pad_get_element_private(pad);
|
2020-06-30 03:14:06 +02:00
|
|
|
gboolean ret;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2019-09-14 19:43:26 +02:00
|
|
|
TRACE("pin %p, type \"%s\".\n", pin, GST_EVENT_TYPE_NAME(event));
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
switch (event->type) {
|
2016-01-14 20:23:04 +01:00
|
|
|
case GST_EVENT_SEGMENT: {
|
2010-10-26 18:39:15 +02:00
|
|
|
gdouble rate, applied_rate;
|
2016-01-14 20:23:04 +01:00
|
|
|
gint64 stop, pos;
|
|
|
|
const GstSegment *segment;
|
|
|
|
|
|
|
|
gst_event_parse_segment(event, &segment);
|
|
|
|
|
|
|
|
pos = segment->position;
|
|
|
|
stop = segment->stop;
|
|
|
|
rate = segment->rate;
|
|
|
|
applied_rate = segment->applied_rate;
|
|
|
|
|
2019-09-14 19:43:26 +02:00
|
|
|
if (segment->format != GST_FORMAT_TIME)
|
|
|
|
{
|
|
|
|
FIXME("Unhandled format \"%s\".\n", gst_format_get_name(segment->format));
|
2013-11-09 11:03:41 +01:00
|
|
|
return TRUE;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
2016-01-14 20:23:04 +01:00
|
|
|
|
|
|
|
gst_segment_copy_into(segment, pin->segment);
|
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
pos /= 100;
|
2016-01-14 20:23:04 +01:00
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
if (stop > 0)
|
|
|
|
stop /= 100;
|
2016-01-14 20:23:04 +01:00
|
|
|
|
2019-09-27 04:40:53 +02:00
|
|
|
if (pin->pin.pin.peer)
|
|
|
|
IPin_NewSegment(pin->pin.pin.peer, pos, stop, rate*applied_rate);
|
2016-01-14 20:23:04 +01:00
|
|
|
|
2013-11-09 11:03:41 +01:00
|
|
|
return TRUE;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
case GST_EVENT_EOS:
|
2019-09-27 04:40:53 +02:00
|
|
|
if (pin->pin.pin.peer)
|
|
|
|
IPin_EndOfStream(pin->pin.pin.peer);
|
2020-06-13 17:34:22 +02:00
|
|
|
else
|
|
|
|
SetEvent(pin->eos_event);
|
2013-11-09 11:03:41 +01:00
|
|
|
return TRUE;
|
2010-10-26 18:39:15 +02:00
|
|
|
case GST_EVENT_FLUSH_START:
|
2019-09-06 02:02:15 +02:00
|
|
|
if (impl_from_strmbase_filter(pin->pin.pin.filter)->ignore_flush) {
|
2016-01-14 20:23:04 +01:00
|
|
|
/* gst-plugins-base prior to 1.7 contains a bug which causes
|
|
|
|
* our sink pins to receive a flush-start event when the
|
|
|
|
* decodebin changes from PAUSED to READY (including
|
|
|
|
* PLAYING->PAUSED->READY), but no matching flush-stop event is
|
|
|
|
* sent. See <gst-plugins-base.git:60bad4815db966a8e4). Here we
|
|
|
|
* unset the flushing flag to avoid the problem. */
|
|
|
|
TRACE("Working around gst <1.7 bug, ignoring FLUSH_START\n");
|
|
|
|
GST_PAD_UNSET_FLUSHING (pad);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-09-27 04:40:53 +02:00
|
|
|
if (pin->pin.pin.peer)
|
|
|
|
IPin_BeginFlush(pin->pin.pin.peer);
|
2013-11-09 11:03:41 +01:00
|
|
|
return TRUE;
|
2010-10-26 18:39:15 +02:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2010-11-11 14:03:27 +01:00
|
|
|
gst_segment_init(pin->segment, GST_FORMAT_TIME);
|
2019-09-27 04:40:53 +02:00
|
|
|
if (pin->pin.pin.peer)
|
|
|
|
IPin_EndFlush(pin->pin.pin.peer);
|
2013-11-09 11:03:41 +01:00
|
|
|
return TRUE;
|
2020-06-30 03:14:06 +02:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
ret = gst_pad_event_default(pad, parent, event);
|
|
|
|
SetEvent(pin->caps_event);
|
|
|
|
return ret;
|
2010-10-26 18:39:15 +02:00
|
|
|
default:
|
2019-09-14 19:43:26 +02:00
|
|
|
WARN("Ignoring \"%s\" event.\n", GST_EVENT_TYPE_NAME(event));
|
2016-01-14 20:23:04 +01:00
|
|
|
return gst_pad_event_default(pad, parent, event);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static DWORD CALLBACK push_data(LPVOID iface)
|
|
|
|
{
|
2010-11-07 16:13:55 +01:00
|
|
|
LONGLONG maxlen, curlen;
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux *This = iface;
|
2020-02-14 05:55:55 +01:00
|
|
|
GstMapInfo mapping;
|
|
|
|
GstBuffer *buffer;
|
2010-10-26 18:40:57 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2020-02-14 05:55:55 +01:00
|
|
|
if (!(buffer = gst_buffer_new_allocate(NULL, 16384, NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate memory.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-20 03:49:20 +01:00
|
|
|
IBaseFilter_AddRef(&This->filter.IBaseFilter_iface);
|
|
|
|
|
2010-11-11 23:23:00 +01:00
|
|
|
if (!This->stop)
|
2019-09-08 20:55:04 +02:00
|
|
|
IAsyncReader_Length(This->reader, &maxlen, &curlen);
|
2010-11-11 23:23:00 +01:00
|
|
|
else
|
|
|
|
maxlen = This->stop;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2010-10-26 18:40:57 +02:00
|
|
|
TRACE("Starting..\n");
|
|
|
|
for (;;) {
|
|
|
|
ULONG len;
|
|
|
|
int ret;
|
|
|
|
|
2010-11-07 16:13:55 +01:00
|
|
|
if (This->nextofs >= maxlen)
|
|
|
|
break;
|
2020-02-14 05:55:55 +01:00
|
|
|
len = min(16384, maxlen - This->nextofs);
|
2010-10-26 18:40:57 +02:00
|
|
|
|
2020-02-14 05:55:55 +01:00
|
|
|
if (!gst_buffer_map_range(buffer, -1, len, &mapping, GST_MAP_WRITE))
|
|
|
|
{
|
|
|
|
ERR("Failed to map buffer.\n");
|
2010-10-26 18:40:57 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-02-14 05:55:55 +01:00
|
|
|
hr = IAsyncReader_SyncRead(This->reader, This->nextofs, len, mapping.data);
|
|
|
|
gst_buffer_unmap(buffer, &mapping);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
ERR("Failed to read data, hr %#x.\n", hr);
|
2010-10-26 18:40:57 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-14 05:55:55 +01:00
|
|
|
This->nextofs += len;
|
|
|
|
|
|
|
|
buffer->duration = buffer->pts = -1;
|
|
|
|
ret = gst_pad_push(This->my_src, buffer);
|
2010-10-26 18:40:57 +02:00
|
|
|
if (ret >= 0)
|
|
|
|
hr = S_OK;
|
|
|
|
else
|
|
|
|
ERR("Sending returned: %i\n", ret);
|
|
|
|
if (ret == GST_FLOW_ERROR)
|
|
|
|
hr = E_FAIL;
|
2016-01-14 20:23:04 +01:00
|
|
|
else if (ret == GST_FLOW_FLUSHING)
|
2010-10-26 18:40:57 +02:00
|
|
|
hr = VFW_E_WRONG_STATE;
|
|
|
|
if (hr != S_OK)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-14 05:55:55 +01:00
|
|
|
gst_buffer_unref(buffer);
|
2010-11-07 16:13:55 +01:00
|
|
|
|
2020-02-14 05:55:55 +01:00
|
|
|
gst_pad_push_event(This->my_src, gst_event_new_eos());
|
2010-10-26 18:40:57 +02:00
|
|
|
|
|
|
|
TRACE("Stopping.. %08x\n", hr);
|
2017-12-20 03:49:20 +01:00
|
|
|
|
|
|
|
IBaseFilter_Release(&This->filter.IBaseFilter_iface);
|
|
|
|
|
2010-10-26 18:40:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
static GstFlowReturn got_data_sink(GstPad *pad, GstObject *parent, GstBuffer *buf)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *pin = gst_pad_get_element_private(pad);
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux *This = impl_from_strmbase_filter(pin->pin.pin.filter);
|
2010-10-26 18:39:15 +02:00
|
|
|
HRESULT hr;
|
2016-01-14 20:23:04 +01:00
|
|
|
BYTE *ptr = NULL;
|
|
|
|
IMediaSample *sample;
|
|
|
|
GstMapInfo info;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("%p %p\n", pad, buf);
|
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
if (This->initial) {
|
|
|
|
gst_buffer_unref(buf);
|
2016-01-14 20:23:04 +01:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = BaseOutputPinImpl_GetDeliveryBuffer(&pin->pin, &sample, NULL, NULL, 0);
|
|
|
|
|
|
|
|
if (hr == VFW_E_NOT_CONNECTED) {
|
|
|
|
gst_buffer_unref(buf);
|
2010-10-26 18:39:15 +02:00
|
|
|
return GST_FLOW_NOT_LINKED;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
gst_buffer_unref(buf);
|
|
|
|
ERR("Could not get a delivery buffer (%x), returning GST_FLOW_FLUSHING\n", hr);
|
|
|
|
return GST_FLOW_FLUSHING;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_buffer_map(buf, &info, GST_MAP_READ);
|
|
|
|
|
|
|
|
hr = IMediaSample_SetActualDataLength(sample, info.size);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("SetActualDataLength failed: %08x\n", hr);
|
|
|
|
return GST_FLOW_FLUSHING;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
IMediaSample_GetPointer(sample, &ptr);
|
|
|
|
|
|
|
|
memcpy(ptr, info.data, info.size);
|
|
|
|
|
|
|
|
gst_buffer_unmap(buf, &info);
|
|
|
|
|
|
|
|
if (GST_BUFFER_PTS_IS_VALID(buf)) {
|
|
|
|
REFERENCE_TIME rtStart = gst_segment_to_running_time(pin->segment, GST_FORMAT_TIME, buf->pts);
|
2010-11-07 15:02:51 +01:00
|
|
|
if (rtStart >= 0)
|
|
|
|
rtStart /= 100;
|
|
|
|
|
|
|
|
if (GST_BUFFER_DURATION_IS_VALID(buf)) {
|
2016-01-14 20:23:04 +01:00
|
|
|
REFERENCE_TIME tStart = buf->pts / 100;
|
|
|
|
REFERENCE_TIME tStop = (buf->pts + buf->duration) / 100;
|
2010-11-07 15:02:51 +01:00
|
|
|
REFERENCE_TIME rtStop;
|
2016-01-14 20:23:04 +01:00
|
|
|
rtStop = gst_segment_to_running_time(pin->segment, GST_FORMAT_TIME, buf->pts + buf->duration);
|
2010-11-07 15:02:51 +01:00
|
|
|
if (rtStop >= 0)
|
|
|
|
rtStop /= 100;
|
2010-11-09 23:42:47 +01:00
|
|
|
TRACE("Current time on %p: %i to %i ms\n", pin, (int)(rtStart / 10000), (int)(rtStop / 10000));
|
2010-11-07 15:02:51 +01:00
|
|
|
IMediaSample_SetTime(sample, &rtStart, rtStop >= 0 ? &rtStop : NULL);
|
|
|
|
IMediaSample_SetMediaTime(sample, &tStart, &tStop);
|
|
|
|
} else {
|
|
|
|
IMediaSample_SetTime(sample, rtStart >= 0 ? &rtStart : NULL, NULL);
|
|
|
|
IMediaSample_SetMediaTime(sample, NULL, NULL);
|
|
|
|
}
|
|
|
|
} else {
|
2010-10-26 18:39:15 +02:00
|
|
|
IMediaSample_SetTime(sample, NULL, NULL);
|
2010-11-07 15:02:51 +01:00
|
|
|
IMediaSample_SetMediaTime(sample, NULL, NULL);
|
|
|
|
}
|
2010-10-26 18:39:15 +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-26 18:39:15 +02:00
|
|
|
IMediaSample_SetSyncPoint(sample, !GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_DELTA_UNIT));
|
|
|
|
|
2019-09-27 04:40:53 +02:00
|
|
|
if (!pin->pin.pin.peer)
|
2010-10-26 18:39:15 +02:00
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
else
|
|
|
|
hr = IMemInputPin_Receive(pin->pin.pMemInputPin, sample);
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
TRACE("sending sample returned: %08x\n", hr);
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_buffer_unref(buf);
|
|
|
|
IMediaSample_Release(sample);
|
2010-10-26 18:39:15 +02:00
|
|
|
|
|
|
|
if (hr == VFW_E_NOT_CONNECTED)
|
|
|
|
return GST_FLOW_NOT_LINKED;
|
2016-01-14 20:23:04 +01:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
return GST_FLOW_FLUSHING;
|
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2020-09-25 05:22:55 +02:00
|
|
|
static GstFlowReturn request_buffer_src(GstPad *pad, GstObject *parent, guint64 ofs, guint len, GstBuffer **buffer)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux *This = gst_pad_get_element_private(pad);
|
2020-09-25 05:22:55 +02:00
|
|
|
GstBuffer *new_buffer = NULL;
|
2016-01-14 20:23:04 +01:00
|
|
|
HRESULT hr;
|
|
|
|
GstMapInfo info;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2020-09-25 05:22:55 +02:00
|
|
|
TRACE("pad %p, offset %s, length %u, buffer %p.\n", pad, wine_dbgstr_longlong(ofs), len, *buffer);
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2017-02-23 03:44:48 +01:00
|
|
|
if (ofs == GST_BUFFER_OFFSET_NONE)
|
2010-10-26 18:39:15 +02:00
|
|
|
ofs = This->nextpullofs;
|
|
|
|
if (ofs >= This->filesize) {
|
|
|
|
WARN("Reading past eof: %s, %u\n", wine_dbgstr_longlong(ofs), len);
|
2016-01-14 20:23:04 +01:00
|
|
|
return GST_FLOW_EOS;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
if (len + ofs > This->filesize)
|
|
|
|
len = This->filesize - ofs;
|
|
|
|
This->nextpullofs = ofs + len;
|
|
|
|
|
2020-09-25 05:22:55 +02:00
|
|
|
if (!*buffer)
|
|
|
|
*buffer = new_buffer = gst_buffer_new_and_alloc(len);
|
|
|
|
gst_buffer_map(*buffer, &info, GST_MAP_WRITE);
|
2019-09-08 20:55:04 +02:00
|
|
|
hr = IAsyncReader_SyncRead(This->reader, ofs, len, info.data);
|
2020-09-25 05:22:55 +02:00
|
|
|
gst_buffer_unmap(*buffer, &info);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Failed to read data, hr %#x.\n", hr);
|
|
|
|
if (new_buffer)
|
|
|
|
gst_buffer_unref(new_buffer);
|
2016-01-14 20:23:04 +01:00
|
|
|
return GST_FLOW_ERROR;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
2016-05-19 16:14:51 +02:00
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
return GST_FLOW_OK;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static DWORD CALLBACK push_data_init(LPVOID iface)
|
|
|
|
{
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux *This = iface;
|
2010-10-26 18:40:57 +02:00
|
|
|
DWORD64 ofs = 0;
|
|
|
|
|
|
|
|
TRACE("Starting..\n");
|
|
|
|
for (;;) {
|
|
|
|
GstBuffer *buf;
|
2016-01-14 20:23:04 +01:00
|
|
|
GstFlowReturn ret = request_buffer_src(This->my_src, NULL, ofs, 4096, &buf);
|
2010-10-26 18:40:57 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
ERR("Obtaining buffer returned: %i\n", ret);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = gst_pad_push(This->my_src, buf);
|
|
|
|
ofs += 4096;
|
|
|
|
if (ret)
|
|
|
|
TRACE("Sending returned: %i\n", ret);
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TRACE("Stopping..\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static void removed_decoded_pad(GstElement *bin, GstPad *pad, gpointer user)
|
|
|
|
{
|
2020-01-24 16:55:59 +01:00
|
|
|
struct gstdemux *filter = user;
|
|
|
|
unsigned int i;
|
|
|
|
char *name;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
TRACE("filter %p, bin %p, pad %p.\n", filter, bin, pad);
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
for (i = 0; i < filter->source_count; ++i)
|
2019-12-03 17:14:50 +01:00
|
|
|
{
|
2020-01-24 16:55:59 +01:00
|
|
|
struct gstdemux_source *pin = filter->sources[i];
|
2016-05-12 21:27:04 +02:00
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
if (pin->their_src == pad)
|
|
|
|
{
|
2020-01-28 02:06:55 +01:00
|
|
|
if (pin->post_sink)
|
|
|
|
gst_pad_unlink(pin->their_src, pin->post_sink);
|
2020-01-24 16:55:59 +01:00
|
|
|
else
|
|
|
|
gst_pad_unlink(pin->their_src, pin->my_sink);
|
|
|
|
gst_object_unref(pin->their_src);
|
|
|
|
pin->their_src = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-05-12 21:27:04 +02:00
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
name = gst_pad_get_name(pad);
|
|
|
|
WARN("No pin matching pad %s found.\n", debugstr_a(name));
|
|
|
|
g_free(name);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:28 +02:00
|
|
|
static void init_new_decoded_pad(GstElement *bin, GstPad *pad, struct gstdemux *This)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-20 01:59:38 +02:00
|
|
|
static const WCHAR formatW[] = {'S','t','r','e','a','m',' ','%','0','2','u',0};
|
2010-10-26 18:39:15 +02:00
|
|
|
const char *typename;
|
|
|
|
char *name;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstStructure *arg;
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *pin;
|
2010-10-26 18:39:36 +02:00
|
|
|
int ret;
|
2019-09-06 02:02:15 +02:00
|
|
|
WCHAR nameW[128];
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
TRACE("%p %p %p\n", This, bin, pad);
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
sprintfW(nameW, formatW, This->source_count);
|
2019-09-20 01:59:38 +02:00
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
name = gst_pad_get_name(pad);
|
|
|
|
TRACE("Name: %s\n", name);
|
|
|
|
g_free(name);
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
caps = gst_pad_query_caps(pad, NULL);
|
|
|
|
caps = gst_caps_make_writable(caps);
|
2010-10-26 18:39:15 +02:00
|
|
|
arg = gst_caps_get_structure(caps, 0);
|
|
|
|
typename = gst_structure_get_name(arg);
|
|
|
|
|
2019-09-19 04:37:01 +02:00
|
|
|
if (!(pin = create_pin(This, nameW)))
|
2019-09-05 02:43:19 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to allocate memory.\n");
|
2020-05-12 15:34:09 +02:00
|
|
|
goto out;
|
2010-10-26 18:39:36 +02:00
|
|
|
}
|
2016-01-14 20:23:04 +01:00
|
|
|
|
2019-09-08 20:55:03 +02:00
|
|
|
if (!strcmp(typename, "video/x-raw"))
|
|
|
|
{
|
2020-10-06 20:04:58 +02:00
|
|
|
GstElement *deinterlace, *vconv, *flip, *vconv2;
|
2020-07-01 19:10:01 +02:00
|
|
|
|
|
|
|
/* DirectShow can express interlaced video, but downstream filters can't
|
|
|
|
* necessarily consume it. In particular, the video renderer can't. */
|
|
|
|
if (!(deinterlace = gst_element_factory_make("deinterlace", NULL)))
|
|
|
|
{
|
2020-07-06 22:41:01 +02:00
|
|
|
ERR("Failed to create deinterlace, are %u-bit GStreamer \"good\" plugins installed?\n",
|
2020-07-01 19:10:01 +02:00
|
|
|
8 * (int)sizeof(void *));
|
|
|
|
goto out;
|
|
|
|
}
|
2020-01-28 02:06:55 +01:00
|
|
|
|
|
|
|
/* decodebin considers many YUV formats to be "raw", but some quartz
|
|
|
|
* filters can't handle those. Also, videoflip can't handle all "raw"
|
|
|
|
* formats either. Add a videoconvert to swap color spaces. */
|
|
|
|
if (!(vconv = gst_element_factory_make("videoconvert", NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create videoconvert, are %u-bit GStreamer \"base\" plugins installed?\n",
|
|
|
|
8 * (int)sizeof(void *));
|
2020-05-12 15:34:09 +02:00
|
|
|
goto out;
|
2016-07-17 06:58:21 +02:00
|
|
|
}
|
|
|
|
|
2020-06-23 00:56:04 +02:00
|
|
|
/* Avoid expensive color matrix conversions. */
|
|
|
|
gst_util_set_object_arg(G_OBJECT(vconv), "matrix-mode", "none");
|
|
|
|
|
2020-03-27 06:54:28 +01:00
|
|
|
/* GStreamer outputs RGB video top-down, but DirectShow expects bottom-up. */
|
2020-01-28 02:06:55 +01:00
|
|
|
if (!(flip = gst_element_factory_make("videoflip", NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create videoflip, are %u-bit GStreamer \"good\" plugins installed?\n",
|
|
|
|
8 * (int)sizeof(void *));
|
2020-05-12 15:34:09 +02:00
|
|
|
goto out;
|
2016-05-12 21:27:04 +02:00
|
|
|
}
|
|
|
|
|
2020-10-06 20:04:58 +02:00
|
|
|
/* videoflip does not support 15 and 16-bit RGB so add a second videoconvert
|
|
|
|
* to do the final conversion. */
|
|
|
|
if (!(vconv2 = gst_element_factory_make("videoconvert", NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create videoconvert, are %u-bit GStreamer \"base\" plugins installed?\n",
|
|
|
|
8 * (int)sizeof(void *));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Avoid expensive color matrix conversions. */
|
|
|
|
gst_util_set_object_arg(G_OBJECT(vconv2), "matrix-mode", "none");
|
|
|
|
|
2020-07-01 19:10:01 +02:00
|
|
|
/* The bin takes ownership of these elements. */
|
|
|
|
gst_bin_add(GST_BIN(This->container), deinterlace);
|
|
|
|
gst_element_sync_state_with_parent(deinterlace);
|
|
|
|
gst_bin_add(GST_BIN(This->container), vconv);
|
2016-07-17 06:58:21 +02:00
|
|
|
gst_element_sync_state_with_parent(vconv);
|
2020-07-01 19:10:01 +02:00
|
|
|
gst_bin_add(GST_BIN(This->container), flip);
|
2020-01-28 02:06:55 +01:00
|
|
|
gst_element_sync_state_with_parent(flip);
|
2020-10-06 20:04:58 +02:00
|
|
|
gst_bin_add(GST_BIN(This->container), vconv2);
|
|
|
|
gst_element_sync_state_with_parent(vconv2);
|
2016-05-12 21:27:04 +02:00
|
|
|
|
2020-07-01 19:10:01 +02:00
|
|
|
gst_element_link(deinterlace, vconv);
|
2020-01-28 02:06:55 +01:00
|
|
|
gst_element_link(vconv, flip);
|
2020-10-06 20:04:58 +02:00
|
|
|
gst_element_link(flip, vconv2);
|
2016-07-17 06:58:21 +02:00
|
|
|
|
2020-07-01 19:10:01 +02:00
|
|
|
pin->post_sink = gst_element_get_static_pad(deinterlace, "sink");
|
2020-10-06 20:04:58 +02:00
|
|
|
pin->post_src = gst_element_get_static_pad(vconv2, "src");
|
2020-03-27 06:54:28 +01:00
|
|
|
pin->flip = flip;
|
2020-01-28 02:06:55 +01:00
|
|
|
}
|
|
|
|
else if (!strcmp(typename, "audio/x-raw"))
|
|
|
|
{
|
|
|
|
GstElement *convert;
|
2016-05-12 21:27:04 +02:00
|
|
|
|
2020-01-28 02:06:55 +01:00
|
|
|
/* Currently our dsound can't handle 64-bit formats or all
|
|
|
|
* surround-sound configurations. Native dsound can't always handle
|
|
|
|
* 64-bit formats either. Add an audioconvert to allow changing bit
|
|
|
|
* depth and channel count. */
|
|
|
|
if (!(convert = gst_element_factory_make("audioconvert", NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create audioconvert, are %u-bit GStreamer \"base\" plugins installed?\n",
|
|
|
|
8 * (int)sizeof(void *));
|
2020-05-12 15:34:09 +02:00
|
|
|
goto out;
|
2016-05-12 21:27:04 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 02:06:55 +01:00
|
|
|
gst_bin_add(GST_BIN(This->container), convert);
|
|
|
|
gst_element_sync_state_with_parent(convert);
|
|
|
|
|
|
|
|
pin->post_sink = gst_element_get_static_pad(convert, "sink");
|
|
|
|
pin->post_src = gst_element_get_static_pad(convert, "src");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pin->post_sink)
|
|
|
|
{
|
|
|
|
if ((ret = gst_pad_link(pad, pin->post_sink)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to link decodebin source pad to post-processing elements, error %s.\n",
|
|
|
|
gst_pad_link_get_name(ret));
|
|
|
|
gst_object_unref(pin->post_sink);
|
|
|
|
pin->post_sink = NULL;
|
2020-05-12 15:34:09 +02:00
|
|
|
goto out;
|
2016-05-12 21:27:04 +02:00
|
|
|
}
|
|
|
|
|
2020-01-28 02:06:55 +01:00
|
|
|
if ((ret = gst_pad_link(pin->post_src, pin->my_sink)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to link post-processing elements to our sink pad, error %s.\n",
|
|
|
|
gst_pad_link_get_name(ret));
|
|
|
|
gst_object_unref(pin->post_src);
|
|
|
|
pin->post_src = NULL;
|
|
|
|
gst_object_unref(pin->post_sink);
|
|
|
|
pin->post_sink = NULL;
|
2020-05-12 15:34:09 +02:00
|
|
|
goto out;
|
2016-05-12 21:27:04 +02:00
|
|
|
}
|
2020-01-28 02:06:55 +01:00
|
|
|
}
|
|
|
|
else if ((ret = gst_pad_link(pad, pin->my_sink)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to link decodebin source pad to our sink pad, error %s.\n",
|
|
|
|
gst_pad_link_get_name(ret));
|
2020-05-12 15:34:09 +02:00
|
|
|
goto out;
|
2020-01-28 02:06:55 +01:00
|
|
|
}
|
2016-01-14 20:23:04 +01:00
|
|
|
|
2019-09-19 04:37:01 +02:00
|
|
|
gst_pad_set_active(pin->my_sink, 1);
|
2020-01-28 02:06:55 +01:00
|
|
|
gst_object_ref(pin->their_src = pad);
|
2020-05-12 15:34:09 +02:00
|
|
|
out:
|
|
|
|
gst_caps_unref(caps);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
static void existing_new_pad(GstElement *bin, GstPad *pad, gpointer user)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux *This = user;
|
2020-01-24 16:55:59 +01:00
|
|
|
unsigned int i;
|
|
|
|
int ret;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
TRACE("%p %p %p\n", This, bin, pad);
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
if (gst_pad_is_linked(pad))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Still holding our own lock */
|
|
|
|
if (This->initial) {
|
2016-01-14 20:23:04 +01:00
|
|
|
init_new_decoded_pad(bin, pad, This);
|
2010-10-26 18:39:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
for (i = 0; i < This->source_count; ++i)
|
|
|
|
{
|
|
|
|
struct gstdemux_source *pin = This->sources[i];
|
2010-10-26 18:39:15 +02:00
|
|
|
if (!pin->their_src) {
|
2010-11-11 14:03:27 +01:00
|
|
|
gst_segment_init(pin->segment, GST_FORMAT_TIME);
|
2016-05-12 21:27:04 +02:00
|
|
|
|
2020-01-28 02:06:55 +01:00
|
|
|
if (pin->post_sink)
|
|
|
|
ret = gst_pad_link(pad, pin->post_sink);
|
2016-05-12 21:27:04 +02:00
|
|
|
else
|
|
|
|
ret = gst_pad_link(pad, pin->my_sink);
|
|
|
|
|
|
|
|
if (ret >= 0) {
|
2010-10-26 18:39:15 +02:00
|
|
|
pin->their_src = pad;
|
|
|
|
gst_object_ref(pin->their_src);
|
|
|
|
TRACE("Relinked\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-14 20:23:04 +01:00
|
|
|
init_new_decoded_pad(bin, pad, This);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
static gboolean query_function(GstPad *pad, GstObject *parent, GstQuery *query)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux *This = gst_pad_get_element_private(pad);
|
2010-10-26 18:39:15 +02:00
|
|
|
GstFormat format;
|
|
|
|
|
2019-09-14 19:43:26 +02:00
|
|
|
TRACE("filter %p, type %s.\n", This, GST_QUERY_TYPE_NAME(query));
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
switch (GST_QUERY_TYPE(query)) {
|
|
|
|
case GST_QUERY_DURATION:
|
2020-06-10 22:52:55 +02:00
|
|
|
gst_query_parse_duration(query, &format, NULL);
|
|
|
|
if (format == GST_FORMAT_PERCENT)
|
|
|
|
{
|
|
|
|
gst_query_set_duration(query, GST_FORMAT_PERCENT, GST_FORMAT_PERCENT_MAX);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (format == GST_FORMAT_BYTES)
|
|
|
|
{
|
|
|
|
gst_query_set_duration(query, GST_FORMAT_BYTES, This->filesize);
|
2013-11-09 11:03:41 +01:00
|
|
|
return TRUE;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
2020-06-10 22:52:55 +02:00
|
|
|
return FALSE;
|
2010-10-26 18:39:15 +02:00
|
|
|
case GST_QUERY_SEEKING:
|
|
|
|
gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
|
|
|
|
if (format != GST_FORMAT_BYTES)
|
2019-09-14 19:43:26 +02:00
|
|
|
{
|
|
|
|
WARN("Cannot seek using format \"%s\".\n", gst_format_get_name(format));
|
2013-11-09 11:03:41 +01:00
|
|
|
return FALSE;
|
2019-09-14 19:43:26 +02:00
|
|
|
}
|
2010-10-26 18:39:15 +02:00
|
|
|
gst_query_set_seeking(query, GST_FORMAT_BYTES, 1, 0, This->filesize);
|
2013-11-09 11:03:41 +01:00
|
|
|
return TRUE;
|
2016-01-14 20:23:04 +01:00
|
|
|
case GST_QUERY_SCHEDULING:
|
|
|
|
gst_query_set_scheduling(query, GST_SCHEDULING_FLAG_SEEKABLE, 1, -1, 0);
|
|
|
|
gst_query_add_scheduling_mode(query, GST_PAD_MODE_PUSH);
|
|
|
|
gst_query_add_scheduling_mode(query, GST_PAD_MODE_PULL);
|
|
|
|
return TRUE;
|
2010-10-26 18:39:15 +02:00
|
|
|
default:
|
2019-09-14 19:43:26 +02:00
|
|
|
WARN("Unhandled query type %s.\n", GST_QUERY_TYPE_NAME(query));
|
2013-11-09 11:03:41 +01:00
|
|
|
return FALSE;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static gboolean activate_push(GstPad *pad, gboolean activate)
|
|
|
|
{
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux *This = gst_pad_get_element_private(pad);
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2010-10-26 18:40:57 +02:00
|
|
|
EnterCriticalSection(&This->filter.csFilter);
|
|
|
|
if (!activate) {
|
|
|
|
TRACE("Deactivating\n");
|
2010-11-12 21:43:44 +01:00
|
|
|
if (!This->initial)
|
2019-09-08 20:55:04 +02:00
|
|
|
IAsyncReader_BeginFlush(This->reader);
|
2010-10-26 18:40:57 +02:00
|
|
|
if (This->push_thread) {
|
|
|
|
WaitForSingleObject(This->push_thread, -1);
|
|
|
|
CloseHandle(This->push_thread);
|
|
|
|
This->push_thread = NULL;
|
|
|
|
}
|
2010-11-12 21:43:44 +01:00
|
|
|
if (!This->initial)
|
2019-09-08 20:55:04 +02:00
|
|
|
IAsyncReader_EndFlush(This->reader);
|
2010-11-11 23:23:00 +01:00
|
|
|
if (This->filter.state == State_Stopped)
|
|
|
|
This->nextofs = This->start;
|
2010-10-26 18:40:57 +02:00
|
|
|
} else if (!This->push_thread) {
|
|
|
|
TRACE("Activating\n");
|
|
|
|
if (This->initial)
|
|
|
|
This->push_thread = CreateThread(NULL, 0, push_data_init, This, 0, NULL);
|
|
|
|
else
|
|
|
|
This->push_thread = CreateThread(NULL, 0, push_data, This, 0, NULL);
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->filter.csFilter);
|
2013-11-09 11:03:41 +01:00
|
|
|
return TRUE;
|
2010-10-26 18:40:57 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
static gboolean activate_mode(GstPad *pad, GstObject *parent, GstPadMode mode, gboolean activate)
|
|
|
|
{
|
2019-09-14 19:43:26 +02:00
|
|
|
struct gstdemux *filter = gst_pad_get_element_private(pad);
|
|
|
|
|
|
|
|
TRACE("%s source pad for filter %p in %s mode.\n",
|
|
|
|
activate ? "Activating" : "Deactivating", filter, gst_pad_mode_get_name(mode));
|
|
|
|
|
2016-01-14 20:23:04 +01:00
|
|
|
switch (mode) {
|
|
|
|
case GST_PAD_MODE_PULL:
|
|
|
|
return TRUE;
|
|
|
|
case GST_PAD_MODE_PUSH:
|
|
|
|
return activate_push(pad, activate);
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static void no_more_pads(GstElement *decodebin, gpointer user)
|
|
|
|
{
|
2019-09-14 19:43:26 +02:00
|
|
|
struct gstdemux *filter = user;
|
|
|
|
TRACE("filter %p.\n", filter);
|
|
|
|
SetEvent(filter->no_more_pads_event);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static GstAutoplugSelectResult autoplug_blacklist(GstElement *bin, GstPad *pad, GstCaps *caps, GstElementFactory *fact, gpointer user)
|
|
|
|
{
|
2010-10-26 18:39:15 +02:00
|
|
|
const char *name = gst_element_factory_get_longname(fact);
|
|
|
|
|
|
|
|
if (strstr(name, "Player protection")) {
|
|
|
|
WARN("Blacklisted a/52 decoder because it only works in Totem\n");
|
|
|
|
return GST_AUTOPLUG_SELECT_SKIP;
|
|
|
|
}
|
|
|
|
if (!strcmp(name, "Fluendo Hardware Accelerated Video Decoder")) {
|
|
|
|
WARN("Disabled video acceleration since it breaks in wine\n");
|
|
|
|
return GST_AUTOPLUG_SELECT_SKIP;
|
|
|
|
}
|
|
|
|
TRACE("using \"%s\"\n", name);
|
|
|
|
return GST_AUTOPLUG_SELECT_TRY;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static GstBusSyncReply watch_bus(GstBus *bus, GstMessage *msg, gpointer data)
|
|
|
|
{
|
2019-09-21 00:35:05 +02:00
|
|
|
struct gstdemux *filter = data;
|
2010-11-10 13:52:11 +01:00
|
|
|
GError *err = NULL;
|
|
|
|
gchar *dbg_info = NULL;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2019-09-21 00:35:05 +02:00
|
|
|
TRACE("filter %p, message type %s.\n", filter, GST_MESSAGE_TYPE_NAME(msg));
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2019-09-21 00:35:05 +02:00
|
|
|
switch (msg->type)
|
|
|
|
{
|
|
|
|
case GST_MESSAGE_ERROR:
|
2010-11-10 13:52:11 +01:00
|
|
|
gst_message_parse_error(msg, &err, &dbg_info);
|
2018-02-22 16:06:17 +01:00
|
|
|
ERR("%s: %s\n", GST_OBJECT_NAME(msg->src), err->message);
|
|
|
|
ERR("%s\n", dbg_info);
|
2019-09-21 00:35:05 +02:00
|
|
|
g_error_free(err);
|
|
|
|
g_free(dbg_info);
|
2020-01-02 03:28:41 +01:00
|
|
|
SetEvent(filter->error_event);
|
2019-09-21 00:35:05 +02:00
|
|
|
break;
|
|
|
|
case GST_MESSAGE_WARNING:
|
2010-11-10 13:52:11 +01:00
|
|
|
gst_message_parse_warning(msg, &err, &dbg_info);
|
|
|
|
WARN("%s: %s\n", GST_OBJECT_NAME(msg->src), err->message);
|
|
|
|
WARN("%s\n", dbg_info);
|
2016-11-29 06:35:53 +01:00
|
|
|
g_error_free(err);
|
2019-09-21 00:35:05 +02:00
|
|
|
g_free(dbg_info);
|
|
|
|
break;
|
|
|
|
case GST_MESSAGE_DURATION_CHANGED:
|
|
|
|
SetEvent(filter->duration_event);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-09-10 01:00:58 +02:00
|
|
|
gst_message_unref(msg);
|
2010-11-10 13:52:11 +01:00
|
|
|
return GST_BUS_DROP;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static void unknown_type(GstElement *bin, GstPad *pad, GstCaps *caps, gpointer user)
|
|
|
|
{
|
2010-11-10 13:52:11 +01:00
|
|
|
gchar *strcaps = gst_caps_to_string(caps);
|
2018-07-05 14:18:03 +02:00
|
|
|
ERR("Could not find a filter for caps: %s\n", debugstr_a(strcaps));
|
2010-11-10 13:52:11 +01:00
|
|
|
g_free(strcaps);
|
|
|
|
}
|
|
|
|
|
2020-02-14 05:55:56 +01:00
|
|
|
static HRESULT GST_Connect(struct gstdemux *This, IPin *pConnectPin)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-19 04:37:02 +02:00
|
|
|
LONGLONG avail;
|
2010-10-26 18:39:15 +02:00
|
|
|
GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE(
|
|
|
|
"quartz_src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
2019-09-08 20:55:04 +02:00
|
|
|
IAsyncReader_Length(This->reader, &This->filesize, &avail);
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2010-11-10 13:52:11 +01:00
|
|
|
if (!This->bus) {
|
|
|
|
This->bus = gst_bus_new();
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_bus_set_sync_handler(This->bus, watch_bus_wrapper, This, NULL);
|
2010-11-10 13:52:11 +01:00
|
|
|
}
|
|
|
|
|
2016-05-12 21:27:04 +02:00
|
|
|
This->container = gst_bin_new(NULL);
|
2016-07-17 06:58:19 +02:00
|
|
|
gst_element_set_bus(This->container, This->bus);
|
2016-05-12 21:27:04 +02:00
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
This->my_src = gst_pad_new_from_static_template(&src_template, "quartz-src");
|
2016-01-12 20:35:04 +01:00
|
|
|
gst_pad_set_getrange_function(This->my_src, request_buffer_src_wrapper);
|
|
|
|
gst_pad_set_query_function(This->my_src, query_function_wrapper);
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_pad_set_activatemode_function(This->my_src, activate_mode_wrapper);
|
2016-01-12 20:35:04 +01:00
|
|
|
gst_pad_set_event_function(This->my_src, event_src_wrapper);
|
2010-10-26 18:39:15 +02:00
|
|
|
gst_pad_set_element_private (This->my_src, This);
|
|
|
|
|
2010-11-11 23:23:00 +01:00
|
|
|
This->start = This->nextofs = This->nextpullofs = This->stop = 0;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2019-09-08 20:55:05 +02:00
|
|
|
This->initial = TRUE;
|
2019-09-19 04:37:02 +02:00
|
|
|
if (!This->init_gst(This))
|
2018-02-22 16:06:13 +01:00
|
|
|
return E_FAIL;
|
2013-11-09 11:03:41 +01:00
|
|
|
This->initial = FALSE;
|
2016-01-14 20:23:04 +01:00
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
This->nextofs = This->nextpullofs = 0;
|
2018-02-22 16:06:13 +01:00
|
|
|
return S_OK;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 22:52:57 +02:00
|
|
|
static LONGLONG query_duration(GstPad *pad)
|
|
|
|
{
|
|
|
|
gint64 duration, byte_length;
|
|
|
|
|
|
|
|
if (gst_pad_query_duration(pad, GST_FORMAT_TIME, &duration))
|
|
|
|
return duration / 100;
|
|
|
|
|
|
|
|
WARN("Failed to query time duration; trying to convert from byte length.\n");
|
|
|
|
|
|
|
|
/* To accurately get a duration for the stream, we want to only consider the
|
|
|
|
* length of that stream. Hence, query for the pad duration, instead of
|
|
|
|
* using the file duration. */
|
|
|
|
if (gst_pad_query_duration(pad, GST_FORMAT_BYTES, &byte_length)
|
|
|
|
&& gst_pad_query_convert(pad, GST_FORMAT_BYTES, byte_length, GST_FORMAT_TIME, &duration))
|
|
|
|
return duration / 100;
|
|
|
|
|
|
|
|
ERR("Failed to query duration.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:29 +02:00
|
|
|
static inline struct gstdemux_source *impl_from_IMediaSeeking(IMediaSeeking *iface)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct gstdemux_source, seek.IMediaSeeking_iface);
|
2010-10-26 18:40:41 +02:00
|
|
|
}
|
|
|
|
|
2019-11-23 04:13:59 +01:00
|
|
|
static struct strmbase_pin *gstdemux_get_pin(struct strmbase_filter *base, unsigned int index)
|
2010-10-26 18:39:15 +02:00
|
|
|
{
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux *filter = impl_from_strmbase_filter(base);
|
2016-08-25 22:16:09 +02:00
|
|
|
|
2020-01-24 16:56:00 +01:00
|
|
|
if (filter->enum_sink_first)
|
|
|
|
{
|
|
|
|
if (!index)
|
|
|
|
return &filter->sink.pin;
|
|
|
|
else if (index <= filter->source_count)
|
|
|
|
return &filter->sources[index - 1]->pin.pin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (index < filter->source_count)
|
|
|
|
return &filter->sources[index]->pin.pin;
|
|
|
|
else if (index == filter->source_count)
|
|
|
|
return &filter->sink.pin;
|
|
|
|
}
|
2019-06-11 16:42:16 +02:00
|
|
|
return NULL;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static void gstdemux_destroy(struct strmbase_filter *iface)
|
2019-05-25 22:21:24 +02:00
|
|
|
{
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux *filter = impl_from_strmbase_filter(iface);
|
2019-05-25 22:21:24 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
CloseHandle(filter->no_more_pads_event);
|
2019-09-21 00:35:05 +02:00
|
|
|
CloseHandle(filter->duration_event);
|
2020-01-02 03:28:41 +01:00
|
|
|
CloseHandle(filter->error_event);
|
2019-05-25 22:21:24 +02:00
|
|
|
|
|
|
|
/* Don't need to clean up output pins, disconnecting input pin will do that */
|
2019-12-11 04:53:34 +01:00
|
|
|
if (filter->sink.pin.peer)
|
2019-05-25 22:21:24 +02:00
|
|
|
{
|
2019-12-11 04:53:34 +01:00
|
|
|
hr = IPin_Disconnect(filter->sink.pin.peer);
|
2019-05-25 22:21:24 +02:00
|
|
|
assert(hr == S_OK);
|
2019-12-11 04:53:34 +01:00
|
|
|
hr = IPin_Disconnect(&filter->sink.pin.IPin_iface);
|
2019-05-25 22:21:24 +02:00
|
|
|
assert(hr == S_OK);
|
|
|
|
}
|
|
|
|
|
2019-09-08 20:55:04 +02:00
|
|
|
if (filter->reader)
|
|
|
|
IAsyncReader_Release(filter->reader);
|
|
|
|
filter->reader = NULL;
|
2019-06-18 03:41:57 +02:00
|
|
|
|
2019-05-25 22:21:24 +02:00
|
|
|
if (filter->bus)
|
|
|
|
{
|
|
|
|
gst_bus_set_sync_handler(filter->bus, NULL, NULL, NULL);
|
|
|
|
gst_object_unref(filter->bus);
|
|
|
|
}
|
2019-12-11 04:53:34 +01:00
|
|
|
strmbase_sink_cleanup(&filter->sink);
|
2019-05-25 22:21:24 +02:00
|
|
|
strmbase_filter_cleanup(&filter->filter);
|
2019-09-10 03:36:15 +02:00
|
|
|
heap_free(filter);
|
2019-05-25 22:21:24 +02:00
|
|
|
}
|
|
|
|
|
2019-12-03 17:14:52 +01:00
|
|
|
static HRESULT gstdemux_init_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
|
|
|
struct gstdemux *filter = impl_from_strmbase_filter(iface);
|
2020-02-28 03:40:37 +01:00
|
|
|
const SourceSeeking *seeking;
|
2019-12-03 17:14:52 +01:00
|
|
|
GstStateChangeReturn ret;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (!filter->container)
|
2020-11-17 18:37:51 +01:00
|
|
|
return S_OK;
|
2019-12-03 17:14:52 +01:00
|
|
|
|
2020-06-08 20:00:55 +02:00
|
|
|
for (i = 0; i < filter->source_count; ++i)
|
|
|
|
{
|
2020-11-17 18:37:52 +01:00
|
|
|
HRESULT hr;
|
2020-06-08 20:00:55 +02:00
|
|
|
|
2020-11-17 18:37:52 +01:00
|
|
|
if (filter->sources[i]->pin.pin.peer && FAILED(hr = IMemAllocator_Commit(filter->sources[i]->pin.pAllocator)))
|
|
|
|
ERR("Failed to commit allocator, hr %#x.\n", hr);
|
|
|
|
}
|
2020-06-08 20:00:55 +02:00
|
|
|
|
2019-12-03 17:14:52 +01:00
|
|
|
if (filter->no_more_pads_event)
|
|
|
|
ResetEvent(filter->no_more_pads_event);
|
|
|
|
|
|
|
|
if ((ret = gst_element_set_state(filter->container, GST_STATE_PAUSED)) == GST_STATE_CHANGE_FAILURE)
|
|
|
|
{
|
|
|
|
ERR("Failed to pause stream.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure that all of our pads are connected before returning, lest we
|
|
|
|
* e.g. try to seek and fail. */
|
|
|
|
if (filter->no_more_pads_event)
|
|
|
|
WaitForSingleObject(filter->no_more_pads_event, INFINITE);
|
|
|
|
|
2020-02-28 03:40:37 +01:00
|
|
|
seeking = &filter->sources[0]->seek;
|
|
|
|
|
|
|
|
/* GStreamer can't seek while stopped, and it resets position to the
|
|
|
|
* beginning of the stream every time it is stopped. */
|
|
|
|
if (seeking->llCurrent)
|
|
|
|
{
|
|
|
|
GstSeekType stop_type = GST_SEEK_TYPE_NONE;
|
|
|
|
|
|
|
|
if (seeking->llStop && seeking->llStop != seeking->llDuration)
|
|
|
|
stop_type = GST_SEEK_TYPE_SET;
|
|
|
|
|
|
|
|
gst_pad_push_event(filter->sources[0]->my_sink, gst_event_new_seek(
|
|
|
|
seeking->dRate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
|
|
|
|
GST_SEEK_TYPE_SET, seeking->llCurrent * 100,
|
|
|
|
stop_type, seeking->llStop * 100));
|
|
|
|
}
|
|
|
|
|
2020-11-17 18:37:52 +01:00
|
|
|
return S_OK;
|
2019-12-03 17:14:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT gstdemux_start_stream(struct strmbase_filter *iface, REFERENCE_TIME time)
|
|
|
|
{
|
|
|
|
struct gstdemux *filter = impl_from_strmbase_filter(iface);
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
if (!filter->container)
|
2020-11-17 18:37:51 +01:00
|
|
|
return S_OK;
|
2019-12-03 17:14:52 +01:00
|
|
|
|
|
|
|
if ((ret = gst_element_set_state(filter->container, GST_STATE_PLAYING)) == GST_STATE_CHANGE_FAILURE)
|
|
|
|
{
|
|
|
|
ERR("Failed to play stream.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
else if (ret == GST_STATE_CHANGE_ASYNC)
|
|
|
|
return S_FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT gstdemux_stop_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
|
|
|
struct gstdemux *filter = impl_from_strmbase_filter(iface);
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
if (!filter->container)
|
2020-11-17 18:37:51 +01:00
|
|
|
return S_OK;
|
2019-12-03 17:14:52 +01:00
|
|
|
|
|
|
|
if ((ret = gst_element_set_state(filter->container, GST_STATE_PAUSED)) == GST_STATE_CHANGE_FAILURE)
|
|
|
|
{
|
|
|
|
ERR("Failed to pause stream.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
else if (ret == GST_STATE_CHANGE_ASYNC)
|
|
|
|
return S_FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT gstdemux_cleanup_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
|
|
|
struct gstdemux *filter = impl_from_strmbase_filter(iface);
|
|
|
|
GstStateChangeReturn ret;
|
2020-02-20 03:44:52 +01:00
|
|
|
unsigned int i;
|
2019-12-03 17:14:52 +01:00
|
|
|
|
|
|
|
if (!filter->container)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
filter->ignore_flush = TRUE;
|
|
|
|
if ((ret = gst_element_set_state(filter->container, GST_STATE_READY)) == GST_STATE_CHANGE_FAILURE)
|
|
|
|
{
|
|
|
|
ERR("Failed to pause stream.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
gst_element_get_state(filter->container, NULL, NULL, GST_CLOCK_TIME_NONE);
|
|
|
|
filter->ignore_flush = FALSE;
|
|
|
|
|
2020-02-20 03:44:52 +01:00
|
|
|
for (i = 0; i < filter->source_count; ++i)
|
|
|
|
{
|
|
|
|
if (filter->sources[i]->pin.pin.peer)
|
|
|
|
IMemAllocator_Decommit(filter->sources[i]->pin.pAllocator);
|
|
|
|
}
|
|
|
|
|
2019-12-03 17:14:52 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT gstdemux_wait_state(struct strmbase_filter *iface, DWORD timeout)
|
|
|
|
{
|
|
|
|
struct gstdemux *filter = impl_from_strmbase_filter(iface);
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
if (!filter->container)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
ret = gst_element_get_state(filter->container, NULL, NULL,
|
2019-12-04 05:03:27 +01:00
|
|
|
timeout == INFINITE ? GST_CLOCK_TIME_NONE : timeout * 1000000);
|
2019-12-03 17:14:52 +01:00
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
{
|
|
|
|
ERR("Failed to get state.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
else if (ret == GST_STATE_CHANGE_ASYNC)
|
|
|
|
return VFW_S_STATE_INTERMEDIATE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:29 +02:00
|
|
|
static const struct strmbase_filter_ops filter_ops =
|
|
|
|
{
|
2019-05-24 00:06:31 +02:00
|
|
|
.filter_get_pin = gstdemux_get_pin,
|
2019-05-25 22:21:24 +02:00
|
|
|
.filter_destroy = gstdemux_destroy,
|
2019-12-03 17:14:52 +01:00
|
|
|
.filter_init_stream = gstdemux_init_stream,
|
|
|
|
.filter_start_stream = gstdemux_start_stream,
|
|
|
|
.filter_stop_stream = gstdemux_stop_stream,
|
|
|
|
.filter_cleanup_stream = gstdemux_cleanup_stream,
|
|
|
|
.filter_wait_state = gstdemux_wait_state,
|
2010-10-26 18:39:15 +02:00
|
|
|
};
|
|
|
|
|
2019-12-11 04:53:35 +01:00
|
|
|
static inline struct gstdemux *impl_from_strmbase_sink(struct strmbase_sink *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct gstdemux, sink);
|
|
|
|
}
|
|
|
|
|
2019-09-25 02:10:10 +02:00
|
|
|
static HRESULT sink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
2019-09-12 21:28:27 +02:00
|
|
|
{
|
|
|
|
if (IsEqualGUID(&mt->majortype, &MEDIATYPE_Stream))
|
|
|
|
return S_OK;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2019-12-11 04:53:35 +01:00
|
|
|
static HRESULT gstdemux_sink_connect(struct strmbase_sink *iface, IPin *peer, const AM_MEDIA_TYPE *pmt)
|
|
|
|
{
|
|
|
|
struct gstdemux *filter = impl_from_strmbase_sink(iface);
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
mark_wine_thread();
|
|
|
|
|
|
|
|
filter->reader = NULL;
|
|
|
|
if (FAILED(hr = IPin_QueryInterface(peer, &IID_IAsyncReader, (void **)&filter->reader)))
|
|
|
|
return hr;
|
|
|
|
|
2020-02-14 05:55:56 +01:00
|
|
|
if (FAILED(hr = GST_Connect(filter, peer)))
|
2019-12-11 04:53:35 +01:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
err:
|
|
|
|
GST_RemoveOutputPins(filter);
|
|
|
|
IAsyncReader_Release(filter->reader);
|
2019-12-16 00:29:12 +01:00
|
|
|
filter->reader = NULL;
|
2019-12-11 04:53:35 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gstdemux_sink_disconnect(struct strmbase_sink *iface)
|
|
|
|
{
|
|
|
|
struct gstdemux *filter = impl_from_strmbase_sink(iface);
|
|
|
|
|
|
|
|
mark_wine_thread();
|
|
|
|
|
|
|
|
GST_RemoveOutputPins(filter);
|
2020-07-24 02:29:22 +02:00
|
|
|
|
|
|
|
IAsyncReader_Release(filter->reader);
|
|
|
|
filter->reader = NULL;
|
2019-12-11 04:53:35 +01:00
|
|
|
}
|
|
|
|
|
2019-12-11 04:53:34 +01:00
|
|
|
static const struct strmbase_sink_ops sink_ops =
|
2019-09-12 21:28:27 +02:00
|
|
|
{
|
2019-12-11 04:53:34 +01:00
|
|
|
.base.pin_query_accept = sink_query_accept,
|
2019-12-11 04:53:35 +01:00
|
|
|
.sink_connect = gstdemux_sink_connect,
|
|
|
|
.sink_disconnect = gstdemux_sink_disconnect,
|
2019-09-12 21:28:27 +02:00
|
|
|
};
|
|
|
|
|
2019-09-19 04:37:02 +02:00
|
|
|
static BOOL gstdecoder_init_gst(struct gstdemux *filter)
|
|
|
|
{
|
|
|
|
GstElement *element = gst_element_factory_make("decodebin", NULL);
|
|
|
|
unsigned int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!element)
|
|
|
|
{
|
|
|
|
ERR("Failed to create decodebin; are %u-bit GStreamer \"base\" plugins installed?\n",
|
|
|
|
8 * (int)sizeof(void*));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_bin_add(GST_BIN(filter->container), element);
|
|
|
|
|
|
|
|
g_signal_connect(element, "pad-added", G_CALLBACK(existing_new_pad_wrapper), filter);
|
|
|
|
g_signal_connect(element, "pad-removed", G_CALLBACK(removed_decoded_pad_wrapper), filter);
|
|
|
|
g_signal_connect(element, "autoplug-select", G_CALLBACK(autoplug_blacklist_wrapper), filter);
|
|
|
|
g_signal_connect(element, "unknown-type", G_CALLBACK(unknown_type_wrapper), filter);
|
|
|
|
g_signal_connect(element, "no-more-pads", G_CALLBACK(no_more_pads_wrapper), filter);
|
|
|
|
|
|
|
|
filter->their_sink = gst_element_get_static_pad(element, "sink");
|
|
|
|
ResetEvent(filter->no_more_pads_event);
|
|
|
|
|
|
|
|
if ((ret = gst_pad_link(filter->my_src, filter->their_sink)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to link pads, error %d.\n", ret);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_state(filter->container, GST_STATE_PLAYING);
|
|
|
|
ret = gst_element_get_state(filter->container, NULL, NULL, -1);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
{
|
|
|
|
ERR("Failed to play stream.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitForSingleObject(filter->no_more_pads_event, INFINITE);
|
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
for (i = 0; i < filter->source_count; ++i)
|
2019-09-19 04:37:02 +02:00
|
|
|
{
|
2020-01-24 16:55:58 +01:00
|
|
|
struct gstdemux_source *pin = filter->sources[i];
|
2020-01-02 03:28:41 +01:00
|
|
|
const HANDLE events[2] = {pin->caps_event, filter->error_event};
|
2019-09-19 04:37:02 +02:00
|
|
|
|
2020-06-10 22:52:57 +02:00
|
|
|
pin->seek.llDuration = pin->seek.llStop = query_duration(pin->their_src);
|
2019-09-19 04:37:02 +02:00
|
|
|
pin->seek.llCurrent = 0;
|
2020-01-02 03:28:41 +01:00
|
|
|
if (WaitForMultipleObjects(2, events, FALSE, INFINITE))
|
|
|
|
return FALSE;
|
2019-09-19 04:37:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
filter->ignore_flush = TRUE;
|
|
|
|
gst_element_set_state(filter->container, GST_STATE_READY);
|
|
|
|
gst_element_get_state(filter->container, NULL, NULL, -1);
|
|
|
|
filter->ignore_flush = FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:56:02 +01:00
|
|
|
static HRESULT gstdecoder_source_query_accept(struct gstdemux_source *pin, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-01-25 02:55:09 +01:00
|
|
|
/* At least make sure we can convert it to GstCaps. */
|
|
|
|
GstCaps *caps = amt_to_gst_caps(mt);
|
|
|
|
|
|
|
|
if (!caps)
|
|
|
|
return S_FALSE;
|
|
|
|
gst_caps_unref(caps);
|
2020-01-24 16:56:02 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-01-25 02:55:08 +01:00
|
|
|
static HRESULT gstdecoder_source_get_media_type(struct gstdemux_source *pin,
|
|
|
|
unsigned int index, AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-06-30 03:14:06 +02:00
|
|
|
GstCaps *caps = gst_pad_get_current_caps(pin->my_sink);
|
|
|
|
const GstStructure *structure;
|
|
|
|
const char *type;
|
|
|
|
|
2020-03-16 20:40:15 +01:00
|
|
|
static const GstVideoFormat video_formats[] =
|
2020-01-25 02:55:09 +01:00
|
|
|
{
|
2020-06-23 00:56:03 +02:00
|
|
|
/* Try to prefer YUV formats over RGB ones. Most decoders output in the
|
|
|
|
* YUV color space, and it's generally much less expensive for
|
|
|
|
* videoconvert to do YUV -> YUV transformations. */
|
2020-03-16 20:40:15 +01:00
|
|
|
GST_VIDEO_FORMAT_AYUV,
|
|
|
|
GST_VIDEO_FORMAT_I420,
|
|
|
|
GST_VIDEO_FORMAT_YV12,
|
|
|
|
GST_VIDEO_FORMAT_YUY2,
|
|
|
|
GST_VIDEO_FORMAT_UYVY,
|
|
|
|
GST_VIDEO_FORMAT_YVYU,
|
|
|
|
GST_VIDEO_FORMAT_NV12,
|
2020-06-23 00:56:03 +02:00
|
|
|
GST_VIDEO_FORMAT_BGRA,
|
|
|
|
GST_VIDEO_FORMAT_BGRx,
|
|
|
|
GST_VIDEO_FORMAT_BGR,
|
2020-10-06 20:04:59 +02:00
|
|
|
GST_VIDEO_FORMAT_RGB16,
|
|
|
|
GST_VIDEO_FORMAT_RGB15,
|
2020-01-25 02:55:09 +01:00
|
|
|
};
|
|
|
|
|
2020-06-30 03:14:06 +02:00
|
|
|
assert(caps); /* We shouldn't be able to get here if caps haven't been set. */
|
|
|
|
structure = gst_caps_get_structure(caps, 0);
|
|
|
|
type = gst_structure_get_name(structure);
|
|
|
|
|
|
|
|
memset(mt, 0, sizeof(AM_MEDIA_TYPE));
|
|
|
|
|
|
|
|
if (amt_from_gst_caps(caps, mt))
|
2020-01-25 02:55:09 +01:00
|
|
|
{
|
2020-06-30 03:14:06 +02:00
|
|
|
if (!index--)
|
|
|
|
{
|
|
|
|
gst_caps_unref(caps);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2020-08-29 19:37:36 +02:00
|
|
|
FreeMediaType(mt);
|
2020-01-25 02:55:09 +01:00
|
|
|
}
|
2020-06-30 03:14:06 +02:00
|
|
|
|
|
|
|
if (!strcmp(type, "video/x-raw") && index < ARRAY_SIZE(video_formats))
|
2020-01-25 02:55:09 +01:00
|
|
|
{
|
2020-07-24 02:29:21 +02:00
|
|
|
gint width, height, fps_n, fps_d;
|
2020-03-16 20:40:15 +01:00
|
|
|
GstVideoInfo info;
|
2020-01-25 02:55:09 +01:00
|
|
|
|
2020-06-30 03:14:06 +02:00
|
|
|
gst_caps_unref(caps);
|
|
|
|
gst_structure_get_int(structure, "width", &width);
|
|
|
|
gst_structure_get_int(structure, "height", &height);
|
|
|
|
gst_video_info_set_format(&info, video_formats[index], width, height);
|
2020-07-24 02:29:21 +02:00
|
|
|
if (gst_structure_get_fraction(structure, "framerate", &fps_n, &fps_d) && fps_n)
|
|
|
|
{
|
|
|
|
info.fps_n = fps_n;
|
|
|
|
info.fps_d = fps_d;
|
|
|
|
}
|
2020-03-16 20:40:15 +01:00
|
|
|
if (!amt_from_gst_video_info(&info, mt))
|
|
|
|
return E_OUTOFMEMORY;
|
2020-01-25 02:55:09 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2020-06-30 03:14:06 +02:00
|
|
|
else if (!strcmp(type, "audio/x-raw") && !index)
|
|
|
|
{
|
|
|
|
GstAudioInfo info;
|
|
|
|
gint rate;
|
|
|
|
|
|
|
|
gst_caps_unref(caps);
|
|
|
|
gst_structure_get_int(structure, "rate", &rate);
|
|
|
|
gst_audio_info_set_format(&info, GST_AUDIO_FORMAT_S16LE, rate, 2, NULL);
|
|
|
|
if (!amt_from_gst_audio_info(&info, mt))
|
|
|
|
return E_OUTOFMEMORY;
|
2020-01-28 02:06:56 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2020-01-25 02:55:09 +01:00
|
|
|
|
2020-06-30 03:14:06 +02:00
|
|
|
gst_caps_unref(caps);
|
2020-01-25 02:55:09 +01:00
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
2020-01-25 02:55:08 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 20:05:09 +01:00
|
|
|
HRESULT gstdemux_create(IUnknown *outer, IUnknown **out)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-12 21:28:28 +02:00
|
|
|
struct gstdemux *object;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2019-03-26 06:57:33 +01:00
|
|
|
if (!init_gstreamer())
|
2020-03-08 20:05:09 +01:00
|
|
|
return E_FAIL;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
|
|
|
|
2019-09-10 03:36:15 +02:00
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2020-03-08 20:05:09 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
strmbase_filter_init(&object->filter, outer, &CLSID_Gstreamer_Splitter, &filter_ops);
|
2019-12-13 04:24:39 +01:00
|
|
|
strmbase_sink_init(&object->sink, &object->filter, wcsInputPinName, &sink_ops, NULL);
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2019-09-10 03:36:15 +02:00
|
|
|
object->no_more_pads_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2020-01-02 03:28:41 +01:00
|
|
|
object->error_event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2019-09-19 04:37:02 +02:00
|
|
|
object->init_gst = gstdecoder_init_gst;
|
2020-01-24 16:56:02 +01:00
|
|
|
object->source_query_accept = gstdecoder_source_query_accept;
|
2020-01-25 02:55:08 +01:00
|
|
|
object->source_get_media_type = gstdecoder_source_get_media_type;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2019-09-10 03:36:15 +02:00
|
|
|
TRACE("Created GStreamer demuxer %p.\n", object);
|
2020-03-08 20:05:09 +01:00
|
|
|
*out = &object->filter.IUnknown_inner;
|
|
|
|
return S_OK;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2019-09-21 00:35:05 +02:00
|
|
|
static struct gstdemux *impl_from_IAMStreamSelect(IAMStreamSelect *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct gstdemux, IAMStreamSelect_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI stream_select_QueryInterface(IAMStreamSelect *iface, REFIID iid, void **out)
|
|
|
|
{
|
|
|
|
struct gstdemux *filter = impl_from_IAMStreamSelect(iface);
|
|
|
|
return IUnknown_QueryInterface(filter->filter.outer_unk, iid, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI stream_select_AddRef(IAMStreamSelect *iface)
|
|
|
|
{
|
|
|
|
struct gstdemux *filter = impl_from_IAMStreamSelect(iface);
|
|
|
|
return IUnknown_AddRef(filter->filter.outer_unk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI stream_select_Release(IAMStreamSelect *iface)
|
|
|
|
{
|
|
|
|
struct gstdemux *filter = impl_from_IAMStreamSelect(iface);
|
|
|
|
return IUnknown_Release(filter->filter.outer_unk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI stream_select_Count(IAMStreamSelect *iface, DWORD *count)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, count %p, stub!\n", iface, count);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI stream_select_Info(IAMStreamSelect *iface, LONG index,
|
|
|
|
AM_MEDIA_TYPE **mt, DWORD *flags, LCID *lcid, DWORD *group, WCHAR **name,
|
|
|
|
IUnknown **object, IUnknown **unknown)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, index %d, mt %p, flags %p, lcid %p, group %p, name %p, object %p, unknown %p, stub!\n",
|
|
|
|
iface, index, mt, flags, lcid, group, name, object, unknown);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI stream_select_Enable(IAMStreamSelect *iface, LONG index, DWORD flags)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, index %d, flags %#x, stub!\n", iface, index, flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IAMStreamSelectVtbl stream_select_vtbl =
|
|
|
|
{
|
|
|
|
stream_select_QueryInterface,
|
|
|
|
stream_select_AddRef,
|
|
|
|
stream_select_Release,
|
|
|
|
stream_select_Count,
|
|
|
|
stream_select_Info,
|
|
|
|
stream_select_Enable,
|
|
|
|
};
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI GST_ChangeCurrent(IMediaSeeking *iface)
|
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *This = impl_from_IMediaSeeking(iface);
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("(%p)\n", This);
|
2010-10-26 18:40:41 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI GST_ChangeStop(IMediaSeeking *iface)
|
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *This = impl_from_IMediaSeeking(iface);
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("(%p)\n", This);
|
2010-10-26 18:40:41 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI GST_ChangeRate(IMediaSeeking *iface)
|
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *This = impl_from_IMediaSeeking(iface);
|
2010-11-09 23:42:47 +01:00
|
|
|
GstEvent *ev = gst_event_new_seek(This->seek.dRate, GST_FORMAT_TIME, 0, GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_NONE, -1);
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("(%p) New rate %g\n", This, This->seek.dRate);
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
2010-11-09 23:42:47 +01:00
|
|
|
gst_pad_push_event(This->my_sink, ev);
|
2010-10-26 18:40:41 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI GST_Seeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *This = impl_from_IMediaSeeking(iface);
|
2016-08-25 22:16:09 +02:00
|
|
|
return IPin_QueryInterface(&This->pin.pin.IPin_iface, riid, ppv);
|
2010-10-26 18:40:41 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static ULONG WINAPI GST_Seeking_AddRef(IMediaSeeking *iface)
|
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *This = impl_from_IMediaSeeking(iface);
|
2016-08-25 22:16:09 +02:00
|
|
|
return IPin_AddRef(&This->pin.pin.IPin_iface);
|
2010-10-26 18:40:41 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static ULONG WINAPI GST_Seeking_Release(IMediaSeeking *iface)
|
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *This = impl_from_IMediaSeeking(iface);
|
2016-08-25 22:16:09 +02:00
|
|
|
return IPin_Release(&This->pin.pin.IPin_iface);
|
2010-10-26 18:40:41 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:22:11 +01:00
|
|
|
static HRESULT WINAPI GST_Seeking_SetPositions(IMediaSeeking *iface,
|
2020-11-21 22:25:00 +01:00
|
|
|
LONGLONG *current, DWORD current_flags, LONGLONG *stop, DWORD stop_flags)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2020-11-21 22:25:00 +01:00
|
|
|
GstSeekType current_type = GST_SEEK_TYPE_SET, stop_type = GST_SEEK_TYPE_SET;
|
|
|
|
struct gstdemux_source *pin = impl_from_IMediaSeeking(iface);
|
|
|
|
GstSeekFlags flags = 0;
|
2010-11-11 23:23:00 +01:00
|
|
|
|
2020-11-21 22:25:00 +01:00
|
|
|
TRACE("pin %p, current %s, current_flags %#x, stop %s, stop_flags %#x.\n",
|
|
|
|
pin, current ? debugstr_time(*current) : "<null>", current_flags,
|
|
|
|
stop ? debugstr_time(*stop) : "<null>", stop_flags);
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
|
|
|
|
2020-11-21 22:25:00 +01:00
|
|
|
SourceSeekingImpl_SetPositions(iface, current, current_flags, stop, stop_flags);
|
|
|
|
if (pin->pin.pin.filter->state == State_Stopped)
|
2010-11-11 23:23:00 +01:00
|
|
|
return S_OK;
|
2020-11-21 22:25:00 +01:00
|
|
|
|
|
|
|
if (current_flags & AM_SEEKING_SeekToKeyFrame)
|
|
|
|
flags |= GST_SEEK_FLAG_KEY_UNIT;
|
|
|
|
if (current_flags & AM_SEEKING_Segment)
|
|
|
|
flags |= GST_SEEK_FLAG_SEGMENT;
|
|
|
|
if (!(current_flags & AM_SEEKING_NoFlush))
|
|
|
|
flags |= GST_SEEK_FLAG_FLUSH;
|
|
|
|
|
|
|
|
if ((current_flags & AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning)
|
|
|
|
current_type = GST_SEEK_TYPE_NONE;
|
|
|
|
if ((stop_flags & AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning)
|
|
|
|
stop_type = GST_SEEK_TYPE_NONE;
|
|
|
|
|
|
|
|
if (!gst_pad_push_event(pin->my_sink, gst_event_new_seek(pin->seek.dRate, GST_FORMAT_TIME, flags,
|
|
|
|
current_type, pin->seek.llCurrent * 100, stop_type, pin->seek.llStop * 100)))
|
|
|
|
{
|
|
|
|
ERR("Failed to seek (current %s, stop %s).\n",
|
|
|
|
debugstr_time(pin->seek.llCurrent), debugstr_time(pin->seek.llStop));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
return S_OK;
|
2010-11-11 23:23:00 +01:00
|
|
|
}
|
|
|
|
|
2010-10-26 18:40:41 +02:00
|
|
|
static const IMediaSeekingVtbl GST_Seeking_Vtbl =
|
|
|
|
{
|
|
|
|
GST_Seeking_QueryInterface,
|
|
|
|
GST_Seeking_AddRef,
|
|
|
|
GST_Seeking_Release,
|
|
|
|
SourceSeekingImpl_GetCapabilities,
|
|
|
|
SourceSeekingImpl_CheckCapabilities,
|
|
|
|
SourceSeekingImpl_IsFormatSupported,
|
|
|
|
SourceSeekingImpl_QueryPreferredFormat,
|
|
|
|
SourceSeekingImpl_GetTimeFormat,
|
|
|
|
SourceSeekingImpl_IsUsingTimeFormat,
|
|
|
|
SourceSeekingImpl_SetTimeFormat,
|
|
|
|
SourceSeekingImpl_GetDuration,
|
|
|
|
SourceSeekingImpl_GetStopPosition,
|
2020-11-21 22:24:59 +01:00
|
|
|
SourceSeekingImpl_GetCurrentPosition,
|
2010-10-26 18:40:41 +02:00
|
|
|
SourceSeekingImpl_ConvertTimeFormat,
|
2010-11-11 23:23:00 +01:00
|
|
|
GST_Seeking_SetPositions,
|
2010-10-26 18:40:41 +02:00
|
|
|
SourceSeekingImpl_GetPositions,
|
|
|
|
SourceSeekingImpl_GetAvailable,
|
|
|
|
SourceSeekingImpl_SetRate,
|
|
|
|
SourceSeekingImpl_GetRate,
|
|
|
|
SourceSeekingImpl_GetPreroll
|
|
|
|
};
|
|
|
|
|
2019-09-12 21:28:29 +02:00
|
|
|
static inline struct gstdemux_source *impl_from_IQualityControl( IQualityControl *iface )
|
2012-04-02 14:52:15 +02:00
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct gstdemux_source, IQualityControl_iface);
|
2012-04-02 14:52:15 +02:00
|
|
|
}
|
|
|
|
|
2012-11-22 18:38:51 +01:00
|
|
|
static HRESULT WINAPI GST_QualityControl_QueryInterface(IQualityControl *iface, REFIID riid, void **ppv)
|
2012-04-02 14:52:15 +02:00
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *pin = impl_from_IQualityControl(iface);
|
2016-08-25 22:16:09 +02:00
|
|
|
return IPin_QueryInterface(&pin->pin.pin.IPin_iface, riid, ppv);
|
2012-04-02 14:52:15 +02:00
|
|
|
}
|
|
|
|
|
2012-11-22 18:38:51 +01:00
|
|
|
static ULONG WINAPI GST_QualityControl_AddRef(IQualityControl *iface)
|
2012-04-02 14:52:15 +02:00
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *pin = impl_from_IQualityControl(iface);
|
2016-08-25 22:16:09 +02:00
|
|
|
return IPin_AddRef(&pin->pin.pin.IPin_iface);
|
2012-04-02 14:52:15 +02:00
|
|
|
}
|
|
|
|
|
2012-11-22 18:38:51 +01:00
|
|
|
static ULONG WINAPI GST_QualityControl_Release(IQualityControl *iface)
|
2012-04-02 14:52:15 +02:00
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *pin = impl_from_IQualityControl(iface);
|
2016-08-25 22:16:09 +02:00
|
|
|
return IPin_Release(&pin->pin.pin.IPin_iface);
|
2012-04-02 14:52:15 +02:00
|
|
|
}
|
|
|
|
|
2020-10-22 18:10:17 +02:00
|
|
|
static HRESULT WINAPI GST_QualityControl_Notify(IQualityControl *iface, IBaseFilter *sender, Quality q)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *pin = impl_from_IQualityControl(iface);
|
2020-03-17 03:28:25 +01:00
|
|
|
GstQOSType type = GST_QOS_TYPE_OVERFLOW;
|
2020-03-17 03:28:26 +01:00
|
|
|
GstClockTime timestamp;
|
|
|
|
GstClockTimeDiff diff;
|
2020-10-22 18:10:17 +02:00
|
|
|
GstEvent *event;
|
2016-05-19 16:14:48 +02:00
|
|
|
|
2020-10-22 18:10:17 +02:00
|
|
|
TRACE("pin %p, sender %p, type %s, proportion %u, late %s, timestamp %s.\n",
|
|
|
|
pin, sender, q.Type == Famine ? "Famine" : "Flood", q.Proportion,
|
|
|
|
debugstr_time(q.Late), debugstr_time(q.TimeStamp));
|
2016-05-19 16:14:48 +02:00
|
|
|
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
2016-05-19 16:14:48 +02:00
|
|
|
|
2020-10-22 18:10:17 +02:00
|
|
|
/* GST_QOS_TYPE_OVERFLOW is also used for buffers that arrive on time, but
|
2020-03-17 03:28:25 +01:00
|
|
|
* DirectShow filters might use Famine, so check that there actually is an
|
|
|
|
* underrun. */
|
2020-10-22 18:10:17 +02:00
|
|
|
if (q.Type == Famine && q.Proportion < 1000)
|
2020-03-17 03:28:25 +01:00
|
|
|
type = GST_QOS_TYPE_UNDERFLOW;
|
|
|
|
|
2020-03-17 03:28:26 +01:00
|
|
|
/* DirectShow filters sometimes pass negative timestamps (Audiosurf uses the
|
|
|
|
* current time instead of the time of the last buffer). GstClockTime is
|
|
|
|
* unsigned, so clamp it to 0. */
|
2020-10-22 18:10:17 +02:00
|
|
|
timestamp = max(q.TimeStamp * 100, 0);
|
2020-03-17 03:28:26 +01:00
|
|
|
|
|
|
|
/* The documentation specifies that timestamp + diff must be nonnegative. */
|
2020-10-22 18:10:17 +02:00
|
|
|
diff = q.Late * 100;
|
2020-10-22 18:10:16 +02:00
|
|
|
if (diff < 0 && timestamp < (GstClockTime)-diff)
|
2020-03-17 03:28:26 +01:00
|
|
|
diff = -timestamp;
|
|
|
|
|
2020-10-22 18:10:17 +02:00
|
|
|
/* DirectShow "Proportion" describes what percentage of buffers the upstream
|
|
|
|
* filter should keep (i.e. dropping the rest). If frames are late, the
|
|
|
|
* proportion will be less than 1. For example, a proportion of 500 means
|
|
|
|
* that the element should drop half of its frames, essentially because
|
|
|
|
* frames are taking twice as long as they should to arrive.
|
|
|
|
*
|
|
|
|
* GStreamer "proportion" is the inverse of this; it describes how much
|
|
|
|
* faster the upstream element should produce frames. I.e. if frames are
|
|
|
|
* taking twice as long as they should to arrive, we want the frames to be
|
|
|
|
* decoded twice as fast, and so we pass 2.0 to GStreamer. */
|
|
|
|
|
|
|
|
if (!q.Proportion)
|
|
|
|
{
|
|
|
|
WARN("Ignoring quality message with zero proportion.\n");
|
|
|
|
return S_OK;
|
2016-05-19 16:14:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-22 18:10:17 +02:00
|
|
|
if (!(event = gst_event_new_qos(type, 1000.0 / q.Proportion, diff, timestamp)))
|
|
|
|
ERR("Failed to create QOS event.\n");
|
|
|
|
|
|
|
|
gst_pad_push_event(pin->my_sink, event);
|
2016-05-19 16:14:48 +02:00
|
|
|
|
2010-11-09 23:42:48 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-22 18:38:51 +01:00
|
|
|
static HRESULT WINAPI GST_QualityControl_SetSink(IQualityControl *iface, IQualityControl *tonotify)
|
2012-04-02 14:52:15 +02:00
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *pin = impl_from_IQualityControl(iface);
|
2016-01-14 20:22:11 +01:00
|
|
|
TRACE("(%p)->(%p)\n", pin, pin);
|
2012-04-02 14:52:15 +02:00
|
|
|
/* Do nothing */
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-09 23:42:48 +01:00
|
|
|
static const IQualityControlVtbl GSTOutPin_QualityControl_Vtbl = {
|
2012-04-02 14:52:15 +02:00
|
|
|
GST_QualityControl_QueryInterface,
|
|
|
|
GST_QualityControl_AddRef,
|
|
|
|
GST_QualityControl_Release,
|
2010-11-09 23:42:48 +01:00
|
|
|
GST_QualityControl_Notify,
|
2012-04-02 14:52:15 +02:00
|
|
|
GST_QualityControl_SetSink
|
2010-11-09 23:42:48 +01:00
|
|
|
};
|
|
|
|
|
2019-09-12 21:28:29 +02:00
|
|
|
static inline struct gstdemux_source *impl_source_from_IPin(IPin *iface)
|
2019-05-14 05:17:58 +02:00
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct gstdemux_source, pin.pin.IPin_iface);
|
2019-05-14 05:17:58 +02:00
|
|
|
}
|
|
|
|
|
2019-12-08 05:20:33 +01:00
|
|
|
static HRESULT source_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-12-08 05:20:33 +01:00
|
|
|
struct gstdemux_source *pin = impl_source_from_IPin(&iface->IPin_iface);
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2019-12-08 05:20:33 +01:00
|
|
|
if (IsEqualGUID(iid, &IID_IMediaSeeking))
|
|
|
|
*out = &pin->seek.IMediaSeeking_iface;
|
|
|
|
else if (IsEqualGUID(iid, &IID_IQualityControl))
|
|
|
|
*out = &pin->IQualityControl_iface;
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2019-12-08 05:20:33 +01:00
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2020-01-24 16:56:02 +01:00
|
|
|
static HRESULT source_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
2018-05-04 06:47:13 +02:00
|
|
|
{
|
2020-01-24 16:56:02 +01:00
|
|
|
struct gstdemux_source *pin = impl_source_from_IPin(&iface->IPin_iface);
|
|
|
|
struct gstdemux *filter = impl_from_strmbase_filter(iface->filter);
|
|
|
|
return filter->source_query_accept(pin, mt);
|
2018-05-04 06:47:13 +02:00
|
|
|
}
|
|
|
|
|
2020-01-25 02:55:08 +01:00
|
|
|
static HRESULT source_get_media_type(struct strmbase_pin *iface, unsigned int index, AM_MEDIA_TYPE *mt)
|
2010-10-26 18:39:15 +02:00
|
|
|
{
|
2020-01-25 02:55:08 +01:00
|
|
|
struct gstdemux_source *pin = impl_source_from_IPin(&iface->IPin_iface);
|
|
|
|
struct gstdemux *filter = impl_from_strmbase_filter(iface->filter);
|
|
|
|
return filter->source_get_media_type(pin, index, mt);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:25 +02:00
|
|
|
static HRESULT WINAPI GSTOutPin_DecideBufferSize(struct strmbase_source *iface,
|
2020-02-14 05:55:56 +01:00
|
|
|
IMemAllocator *allocator, ALLOCATOR_PROPERTIES *props)
|
2010-10-26 18:39:15 +02:00
|
|
|
{
|
2020-02-14 05:55:56 +01:00
|
|
|
struct gstdemux_source *pin = impl_source_from_IPin(&iface->pin.IPin_iface);
|
|
|
|
unsigned int buffer_size = 16384;
|
|
|
|
ALLOCATOR_PROPERTIES ret_props;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2020-02-14 05:55:56 +01:00
|
|
|
if (IsEqualGUID(&pin->pin.pin.mt.formattype, &FORMAT_VideoInfo))
|
2013-01-17 06:38:12 +01:00
|
|
|
{
|
2020-02-14 05:55:56 +01:00
|
|
|
VIDEOINFOHEADER *format = (VIDEOINFOHEADER *)pin->pin.pin.mt.pbFormat;
|
|
|
|
buffer_size = format->bmiHeader.biSizeImage;
|
2020-03-27 06:54:28 +01:00
|
|
|
|
|
|
|
gst_util_set_object_arg(G_OBJECT(pin->flip), "method",
|
2020-10-06 20:04:57 +02:00
|
|
|
(format->bmiHeader.biCompression == BI_RGB
|
|
|
|
|| format->bmiHeader.biCompression == BI_BITFIELDS) ? "vertical-flip" : "none");
|
2020-02-14 05:55:56 +01:00
|
|
|
}
|
2020-02-28 03:40:38 +01:00
|
|
|
else if (IsEqualGUID(&pin->pin.pin.mt.formattype, &FORMAT_WaveFormatEx)
|
|
|
|
&& (IsEqualGUID(&pin->pin.pin.mt.subtype, &MEDIASUBTYPE_PCM)
|
|
|
|
|| IsEqualGUID(&pin->pin.pin.mt.subtype, &MEDIASUBTYPE_IEEE_FLOAT)))
|
2020-02-14 05:55:56 +01:00
|
|
|
{
|
|
|
|
WAVEFORMATEX *format = (WAVEFORMATEX *)pin->pin.pin.mt.pbFormat;
|
|
|
|
buffer_size = format->nAvgBytesPerSec;
|
2013-01-17 06:38:12 +01:00
|
|
|
}
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2020-02-14 05:55:56 +01:00
|
|
|
props->cBuffers = max(props->cBuffers, 1);
|
|
|
|
props->cbBuffer = max(props->cbBuffer, buffer_size);
|
|
|
|
props->cbAlign = max(props->cbAlign, 1);
|
|
|
|
return IMemAllocator_SetProperties(allocator, props, &ret_props);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:29 +02:00
|
|
|
static void free_source_pin(struct gstdemux_source *pin)
|
2010-10-26 18:39:15 +02:00
|
|
|
{
|
2019-09-27 04:40:53 +02:00
|
|
|
if (pin->pin.pin.peer)
|
2010-10-26 18:39:15 +02:00
|
|
|
{
|
2019-06-18 03:41:58 +02:00
|
|
|
if (SUCCEEDED(IMemAllocator_Decommit(pin->pin.pAllocator)))
|
2019-09-27 04:40:53 +02:00
|
|
|
IPin_Disconnect(pin->pin.pin.peer);
|
2019-06-18 03:41:58 +02:00
|
|
|
IPin_Disconnect(&pin->pin.pin.IPin_iface);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2019-06-18 03:41:58 +02:00
|
|
|
if (pin->their_src)
|
|
|
|
{
|
2020-01-28 02:06:55 +01:00
|
|
|
if (pin->post_sink)
|
2019-06-18 03:41:58 +02:00
|
|
|
{
|
2020-01-28 02:06:55 +01:00
|
|
|
gst_pad_unlink(pin->their_src, pin->post_sink);
|
|
|
|
gst_pad_unlink(pin->post_src, pin->my_sink);
|
|
|
|
gst_object_unref(pin->post_src);
|
|
|
|
gst_object_unref(pin->post_sink);
|
|
|
|
pin->post_src = pin->post_sink = NULL;
|
2019-06-18 03:41:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
gst_pad_unlink(pin->their_src, pin->my_sink);
|
|
|
|
gst_object_unref(pin->their_src);
|
|
|
|
}
|
|
|
|
gst_object_unref(pin->my_sink);
|
|
|
|
CloseHandle(pin->caps_event);
|
2020-06-13 17:34:22 +02:00
|
|
|
CloseHandle(pin->eos_event);
|
2019-06-18 03:41:58 +02:00
|
|
|
gst_segment_free(pin->segment);
|
2019-09-05 02:43:19 +02:00
|
|
|
|
2019-12-03 17:14:49 +01:00
|
|
|
strmbase_seeking_cleanup(&pin->seek);
|
2019-09-05 02:43:19 +02:00
|
|
|
strmbase_source_cleanup(&pin->pin);
|
|
|
|
heap_free(pin);
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:26 +02:00
|
|
|
static const struct strmbase_source_ops source_ops =
|
|
|
|
{
|
2019-12-08 05:20:33 +01:00
|
|
|
.base.pin_query_interface = source_query_interface,
|
2019-09-25 02:10:10 +02:00
|
|
|
.base.pin_query_accept = source_query_accept,
|
2019-09-25 02:10:11 +02:00
|
|
|
.base.pin_get_media_type = source_get_media_type,
|
2019-09-25 02:10:10 +02:00
|
|
|
.pfnAttemptConnection = BaseOutputPinImpl_AttemptConnection,
|
2020-02-14 05:55:56 +01:00
|
|
|
.pfnDecideAllocator = BaseOutputPinImpl_DecideAllocator,
|
2019-09-25 02:10:10 +02:00
|
|
|
.pfnDecideBufferSize = GSTOutPin_DecideBufferSize,
|
2010-10-26 18:39:15 +02:00
|
|
|
};
|
|
|
|
|
2019-09-19 04:37:01 +02:00
|
|
|
static struct gstdemux_source *create_pin(struct gstdemux *filter, const WCHAR *name)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2019-09-12 21:28:29 +02:00
|
|
|
struct gstdemux_source *pin, **new_array;
|
2019-09-19 04:37:01 +02:00
|
|
|
char pad_name[19];
|
2019-09-05 02:43:19 +02:00
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
if (!(new_array = heap_realloc(filter->sources, (filter->source_count + 1) * sizeof(*new_array))))
|
2019-09-19 04:37:01 +02:00
|
|
|
return NULL;
|
2020-01-24 16:55:58 +01:00
|
|
|
filter->sources = new_array;
|
2019-09-05 02:43:19 +02:00
|
|
|
|
|
|
|
if (!(pin = heap_alloc_zero(sizeof(*pin))))
|
2019-09-19 04:37:01 +02:00
|
|
|
return NULL;
|
2019-09-05 02:43:19 +02:00
|
|
|
|
2019-12-08 05:20:38 +01:00
|
|
|
strmbase_source_init(&pin->pin, &filter->filter, name, &source_ops);
|
2019-09-05 02:43:19 +02:00
|
|
|
pin->caps_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2020-06-13 17:34:22 +02:00
|
|
|
pin->eos_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2019-09-05 02:43:19 +02:00
|
|
|
pin->segment = gst_segment_new();
|
2019-09-19 04:37:01 +02:00
|
|
|
gst_segment_init(pin->segment, GST_FORMAT_TIME);
|
2019-09-05 02:43:19 +02:00
|
|
|
pin->IQualityControl_iface.lpVtbl = &GSTOutPin_QualityControl_Vtbl;
|
2019-12-03 17:14:49 +01:00
|
|
|
strmbase_seeking_init(&pin->seek, &GST_Seeking_Vtbl, GST_ChangeStop,
|
|
|
|
GST_ChangeCurrent, GST_ChangeRate);
|
2019-09-05 02:43:19 +02:00
|
|
|
BaseFilterImpl_IncrementPinVersion(&filter->filter);
|
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
sprintf(pad_name, "qz_sink_%u", filter->source_count);
|
2019-09-19 04:37:01 +02:00
|
|
|
pin->my_sink = gst_pad_new(pad_name, GST_PAD_SINK);
|
|
|
|
gst_pad_set_element_private(pin->my_sink, pin);
|
|
|
|
gst_pad_set_chain_function(pin->my_sink, got_data_sink_wrapper);
|
|
|
|
gst_pad_set_event_function(pin->my_sink, event_sink_wrapper);
|
|
|
|
gst_pad_set_query_function(pin->my_sink, query_sink_wrapper);
|
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
filter->sources[filter->source_count++] = pin;
|
2019-09-19 04:37:01 +02:00
|
|
|
return pin;
|
2010-10-26 18:39:15 +02:00
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:28 +02:00
|
|
|
static HRESULT GST_RemoveOutputPins(struct gstdemux *This)
|
2016-01-14 20:22:11 +01:00
|
|
|
{
|
2020-01-24 16:55:59 +01:00
|
|
|
unsigned int i;
|
2016-01-14 20:22:11 +01:00
|
|
|
|
2010-10-26 18:39:15 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2016-01-12 20:35:04 +01:00
|
|
|
mark_wine_thread();
|
2010-10-26 18:39:15 +02:00
|
|
|
|
2016-05-12 21:27:04 +02:00
|
|
|
if (!This->container)
|
2010-11-07 16:13:55 +01:00
|
|
|
return S_OK;
|
2016-05-12 21:27:04 +02:00
|
|
|
gst_element_set_state(This->container, GST_STATE_NULL);
|
2010-10-26 18:39:15 +02:00
|
|
|
gst_pad_unlink(This->my_src, This->their_sink);
|
2010-11-17 13:25:51 +01:00
|
|
|
gst_object_unref(This->my_src);
|
2016-01-14 20:23:04 +01:00
|
|
|
gst_object_unref(This->their_sink);
|
2010-10-26 18:39:15 +02:00
|
|
|
This->my_src = This->their_sink = NULL;
|
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
for (i = 0; i < This->source_count; ++i)
|
2020-01-24 16:55:58 +01:00
|
|
|
free_source_pin(This->sources[i]);
|
2019-06-18 03:41:58 +02:00
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
This->source_count = 0;
|
2020-01-24 16:55:58 +01:00
|
|
|
heap_free(This->sources);
|
|
|
|
This->sources = NULL;
|
2016-07-17 06:58:19 +02:00
|
|
|
gst_element_set_bus(This->container, NULL);
|
2016-05-12 21:27:04 +02:00
|
|
|
gst_object_unref(This->container);
|
|
|
|
This->container = NULL;
|
2016-08-25 22:16:09 +02:00
|
|
|
BaseFilterImpl_IncrementPinVersion(&This->filter);
|
2010-10-26 18:39:15 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-20 21:00:23 +01:00
|
|
|
void perform_cb_gstdemux(struct cb_data *cbdata)
|
2016-01-12 20:35:04 +01:00
|
|
|
{
|
|
|
|
switch(cbdata->type)
|
|
|
|
{
|
|
|
|
case WATCH_BUS:
|
|
|
|
{
|
|
|
|
struct watch_bus_data *data = &cbdata->u.watch_bus_data;
|
|
|
|
cbdata->u.watch_bus_data.ret = watch_bus(data->bus, data->msg, data->user);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EXISTING_NEW_PAD:
|
|
|
|
{
|
2020-03-20 20:54:09 +01:00
|
|
|
struct pad_added_data *data = &cbdata->u.pad_added_data;
|
|
|
|
existing_new_pad(data->element, data->pad, data->user);
|
2016-01-12 20:35:04 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QUERY_FUNCTION:
|
|
|
|
{
|
|
|
|
struct query_function_data *data = &cbdata->u.query_function_data;
|
2016-01-14 20:23:04 +01:00
|
|
|
cbdata->u.query_function_data.ret = query_function(data->pad, data->parent, data->query);
|
2016-01-12 20:35:04 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-01-14 20:23:04 +01:00
|
|
|
case ACTIVATE_MODE:
|
2016-01-12 20:35:04 +01:00
|
|
|
{
|
2016-01-14 20:23:04 +01:00
|
|
|
struct activate_mode_data *data = &cbdata->u.activate_mode_data;
|
|
|
|
cbdata->u.activate_mode_data.ret = activate_mode(data->pad, data->parent, data->mode, data->activate);
|
2016-01-12 20:35:04 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NO_MORE_PADS:
|
|
|
|
{
|
|
|
|
struct no_more_pads_data *data = &cbdata->u.no_more_pads_data;
|
2020-03-20 20:54:09 +01:00
|
|
|
no_more_pads(data->element, data->user);
|
2016-01-12 20:35:04 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REQUEST_BUFFER_SRC:
|
|
|
|
{
|
2020-03-20 20:54:09 +01:00
|
|
|
struct getrange_data *data = &cbdata->u.getrange_data;
|
|
|
|
cbdata->u.getrange_data.ret = request_buffer_src(data->pad, data->parent,
|
2016-01-12 20:35:04 +01:00
|
|
|
data->ofs, data->len, data->buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EVENT_SRC:
|
|
|
|
{
|
|
|
|
struct event_src_data *data = &cbdata->u.event_src_data;
|
2016-01-14 20:23:04 +01:00
|
|
|
cbdata->u.event_src_data.ret = event_src(data->pad, data->parent, data->event);
|
2016-01-12 20:35:04 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EVENT_SINK:
|
|
|
|
{
|
|
|
|
struct event_sink_data *data = &cbdata->u.event_sink_data;
|
2016-01-14 20:23:04 +01:00
|
|
|
cbdata->u.event_sink_data.ret = event_sink(data->pad, data->parent, data->event);
|
2016-01-12 20:35:04 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GOT_DATA_SINK:
|
|
|
|
{
|
|
|
|
struct got_data_sink_data *data = &cbdata->u.got_data_sink_data;
|
2016-01-14 20:23:04 +01:00
|
|
|
cbdata->u.got_data_sink_data.ret = got_data_sink(data->pad, data->parent, data->buf);
|
2016-01-12 20:35:04 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REMOVED_DECODED_PAD:
|
|
|
|
{
|
2020-03-20 20:54:09 +01:00
|
|
|
struct pad_removed_data *data = &cbdata->u.pad_removed_data;
|
|
|
|
removed_decoded_pad(data->element, data->pad, data->user);
|
2016-01-12 20:35:04 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AUTOPLUG_BLACKLIST:
|
|
|
|
{
|
|
|
|
struct autoplug_blacklist_data *data = &cbdata->u.autoplug_blacklist_data;
|
|
|
|
cbdata->u.autoplug_blacklist_data.ret = autoplug_blacklist(data->bin,
|
|
|
|
data->pad, data->caps, data->fact, data->user);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case UNKNOWN_TYPE:
|
|
|
|
{
|
|
|
|
struct unknown_type_data *data = &cbdata->u.unknown_type_data;
|
|
|
|
unknown_type(data->bin, data->pad, data->caps, data->user);
|
|
|
|
break;
|
|
|
|
}
|
2016-01-14 20:23:04 +01:00
|
|
|
case QUERY_SINK:
|
|
|
|
{
|
|
|
|
struct query_sink_data *data = &cbdata->u.query_sink_data;
|
|
|
|
cbdata->u.query_sink_data.ret = query_sink(data->pad, data->parent,
|
|
|
|
data->query);
|
|
|
|
break;
|
|
|
|
}
|
2020-03-20 21:00:23 +01:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
assert(0);
|
2016-01-12 20:35:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-19 04:37:03 +02:00
|
|
|
|
2020-01-24 16:56:02 +01:00
|
|
|
static BOOL compare_media_types(const AM_MEDIA_TYPE *a, const AM_MEDIA_TYPE *b)
|
|
|
|
{
|
|
|
|
return IsEqualGUID(&a->majortype, &b->majortype)
|
|
|
|
&& IsEqualGUID(&a->subtype, &b->subtype)
|
|
|
|
&& IsEqualGUID(&a->formattype, &b->formattype)
|
|
|
|
&& a->cbFormat == b->cbFormat
|
|
|
|
&& !memcmp(a->pbFormat, b->pbFormat, a->cbFormat);
|
|
|
|
}
|
|
|
|
|
2019-09-25 02:10:10 +02:00
|
|
|
static HRESULT wave_parser_sink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
2019-09-19 04:37:03 +02:00
|
|
|
{
|
|
|
|
if (!IsEqualGUID(&mt->majortype, &MEDIATYPE_Stream))
|
|
|
|
return S_FALSE;
|
|
|
|
if (IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_WAVE))
|
|
|
|
return S_OK;
|
|
|
|
if (IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_AU) || IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_AIFF))
|
|
|
|
FIXME("AU and AIFF files are not yet supported.\n");
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2019-12-11 04:53:34 +01:00
|
|
|
static const struct strmbase_sink_ops wave_parser_sink_ops =
|
2019-09-19 04:37:03 +02:00
|
|
|
{
|
2019-12-11 04:53:34 +01:00
|
|
|
.base.pin_query_accept = wave_parser_sink_query_accept,
|
2019-12-11 04:53:35 +01:00
|
|
|
.sink_connect = gstdemux_sink_connect,
|
|
|
|
.sink_disconnect = gstdemux_sink_disconnect,
|
2019-09-19 04:37:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL wave_parser_init_gst(struct gstdemux *filter)
|
|
|
|
{
|
|
|
|
static const WCHAR source_name[] = {'o','u','t','p','u','t',0};
|
|
|
|
struct gstdemux_source *pin;
|
|
|
|
GstElement *element;
|
2020-01-02 03:28:41 +01:00
|
|
|
HANDLE events[2];
|
2019-09-19 04:37:03 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(element = gst_element_factory_make("wavparse", NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create wavparse; are %u-bit GStreamer \"good\" plugins installed?\n",
|
|
|
|
8 * (int)sizeof(void*));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_bin_add(GST_BIN(filter->container), element);
|
|
|
|
|
|
|
|
filter->their_sink = gst_element_get_static_pad(element, "sink");
|
|
|
|
if ((ret = gst_pad_link(filter->my_src, filter->their_sink)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to link sink pads, error %d.\n", ret);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(pin = create_pin(filter, source_name)))
|
|
|
|
return FALSE;
|
|
|
|
pin->their_src = gst_element_get_static_pad(element, "src");
|
|
|
|
gst_object_ref(pin->their_src);
|
|
|
|
if ((ret = gst_pad_link(pin->their_src, pin->my_sink)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to link source pads, error %d.\n", ret);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_pad_set_active(pin->my_sink, 1);
|
|
|
|
gst_element_set_state(filter->container, GST_STATE_PAUSED);
|
|
|
|
ret = gst_element_get_state(filter->container, NULL, NULL, -1);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
{
|
|
|
|
ERR("Failed to play stream.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-06-10 22:52:57 +02:00
|
|
|
pin->seek.llDuration = pin->seek.llStop = query_duration(pin->their_src);
|
2019-09-19 04:37:03 +02:00
|
|
|
pin->seek.llCurrent = 0;
|
|
|
|
|
2020-01-02 03:28:41 +01:00
|
|
|
events[0] = pin->caps_event;
|
|
|
|
events[1] = filter->error_event;
|
|
|
|
if (WaitForMultipleObjects(2, events, FALSE, INFINITE))
|
|
|
|
return FALSE;
|
2019-09-19 04:37:03 +02:00
|
|
|
|
|
|
|
filter->ignore_flush = TRUE;
|
|
|
|
gst_element_set_state(filter->container, GST_STATE_READY);
|
|
|
|
gst_element_get_state(filter->container, NULL, NULL, -1);
|
|
|
|
filter->ignore_flush = FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-06-30 03:14:06 +02:00
|
|
|
static gboolean get_source_amt(const struct gstdemux_source *pin, AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
GstCaps *caps = gst_pad_get_current_caps(pin->my_sink);
|
|
|
|
gboolean ret = amt_from_gst_caps(caps, mt);
|
|
|
|
gst_caps_unref(caps);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:56:02 +01:00
|
|
|
static HRESULT wave_parser_source_query_accept(struct gstdemux_source *pin, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-06-30 03:14:06 +02:00
|
|
|
AM_MEDIA_TYPE pad_mt;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!get_source_amt(pin, &pad_mt))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
hr = compare_media_types(mt, &pad_mt) ? S_OK : S_FALSE;
|
|
|
|
FreeMediaType(&pad_mt);
|
|
|
|
return hr;
|
2020-01-24 16:56:02 +01:00
|
|
|
}
|
|
|
|
|
2020-01-25 02:55:08 +01:00
|
|
|
static HRESULT wave_parser_source_get_media_type(struct gstdemux_source *pin,
|
|
|
|
unsigned int index, AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
if (index > 0)
|
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
2020-06-30 03:14:06 +02:00
|
|
|
if (!get_source_amt(pin, mt))
|
|
|
|
return E_OUTOFMEMORY;
|
2020-01-25 02:55:08 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-08 20:05:09 +01:00
|
|
|
HRESULT wave_parser_create(IUnknown *outer, IUnknown **out)
|
2019-09-19 04:37:03 +02:00
|
|
|
{
|
|
|
|
static const WCHAR sink_name[] = {'i','n','p','u','t',' ','p','i','n',0};
|
|
|
|
struct gstdemux *object;
|
|
|
|
|
|
|
|
if (!init_gstreamer())
|
2020-03-08 20:05:09 +01:00
|
|
|
return E_FAIL;
|
2019-09-19 04:37:03 +02:00
|
|
|
|
|
|
|
mark_wine_thread();
|
|
|
|
|
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2020-03-08 20:05:09 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2019-09-19 04:37:03 +02:00
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
strmbase_filter_init(&object->filter, outer, &CLSID_WAVEParser, &filter_ops);
|
2019-12-13 04:24:39 +01:00
|
|
|
strmbase_sink_init(&object->sink, &object->filter, sink_name, &wave_parser_sink_ops, NULL);
|
2019-09-19 04:37:03 +02:00
|
|
|
object->init_gst = wave_parser_init_gst;
|
2020-01-02 03:28:41 +01:00
|
|
|
object->error_event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2020-01-24 16:56:02 +01:00
|
|
|
object->source_query_accept = wave_parser_source_query_accept;
|
2020-01-25 02:55:08 +01:00
|
|
|
object->source_get_media_type = wave_parser_source_get_media_type;
|
2019-09-19 04:37:03 +02:00
|
|
|
|
|
|
|
TRACE("Created WAVE parser %p.\n", object);
|
2020-03-08 20:05:09 +01:00
|
|
|
*out = &object->filter.IUnknown_inner;
|
|
|
|
return S_OK;
|
2019-09-19 04:37:03 +02:00
|
|
|
}
|
2019-09-20 01:59:38 +02:00
|
|
|
|
2019-09-25 02:10:10 +02:00
|
|
|
static HRESULT avi_splitter_sink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
2019-09-20 01:59:38 +02:00
|
|
|
{
|
|
|
|
if (IsEqualGUID(&mt->majortype, &MEDIATYPE_Stream)
|
|
|
|
&& IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_Avi))
|
|
|
|
return S_OK;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2019-12-11 04:53:34 +01:00
|
|
|
static const struct strmbase_sink_ops avi_splitter_sink_ops =
|
2019-09-20 01:59:38 +02:00
|
|
|
{
|
2019-12-11 04:53:34 +01:00
|
|
|
.base.pin_query_accept = avi_splitter_sink_query_accept,
|
2019-12-11 04:53:35 +01:00
|
|
|
.sink_connect = gstdemux_sink_connect,
|
|
|
|
.sink_disconnect = gstdemux_sink_disconnect,
|
2019-09-20 01:59:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL avi_splitter_init_gst(struct gstdemux *filter)
|
|
|
|
{
|
|
|
|
GstElement *element = gst_element_factory_make("avidemux", NULL);
|
|
|
|
unsigned int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!element)
|
|
|
|
{
|
|
|
|
ERR("Failed to create avidemux; are %u-bit GStreamer \"good\" plugins installed?\n",
|
|
|
|
8 * (int)sizeof(void*));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_bin_add(GST_BIN(filter->container), element);
|
|
|
|
|
|
|
|
g_signal_connect(element, "pad-added", G_CALLBACK(existing_new_pad_wrapper), filter);
|
|
|
|
g_signal_connect(element, "pad-removed", G_CALLBACK(removed_decoded_pad_wrapper), filter);
|
|
|
|
g_signal_connect(element, "no-more-pads", G_CALLBACK(no_more_pads_wrapper), filter);
|
|
|
|
|
|
|
|
filter->their_sink = gst_element_get_static_pad(element, "sink");
|
|
|
|
ResetEvent(filter->no_more_pads_event);
|
|
|
|
|
|
|
|
if ((ret = gst_pad_link(filter->my_src, filter->their_sink)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to link pads, error %d.\n", ret);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_state(filter->container, GST_STATE_PLAYING);
|
|
|
|
ret = gst_element_get_state(filter->container, NULL, NULL, -1);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
{
|
|
|
|
ERR("Failed to play stream.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitForSingleObject(filter->no_more_pads_event, INFINITE);
|
|
|
|
|
2020-01-24 16:55:59 +01:00
|
|
|
for (i = 0; i < filter->source_count; ++i)
|
2019-09-20 01:59:38 +02:00
|
|
|
{
|
2020-01-24 16:55:58 +01:00
|
|
|
struct gstdemux_source *pin = filter->sources[i];
|
2020-01-02 03:28:41 +01:00
|
|
|
const HANDLE events[2] = {pin->caps_event, filter->error_event};
|
2019-09-20 01:59:38 +02:00
|
|
|
|
2020-06-10 22:52:57 +02:00
|
|
|
pin->seek.llDuration = pin->seek.llStop = query_duration(pin->their_src);
|
2019-09-20 01:59:38 +02:00
|
|
|
pin->seek.llCurrent = 0;
|
2020-01-02 03:28:41 +01:00
|
|
|
if (WaitForMultipleObjects(2, events, FALSE, INFINITE))
|
|
|
|
return FALSE;
|
2019-09-20 01:59:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
filter->ignore_flush = TRUE;
|
|
|
|
gst_element_set_state(filter->container, GST_STATE_READY);
|
|
|
|
gst_element_get_state(filter->container, NULL, NULL, -1);
|
|
|
|
filter->ignore_flush = FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:56:02 +01:00
|
|
|
static HRESULT avi_splitter_source_query_accept(struct gstdemux_source *pin, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-06-30 03:14:06 +02:00
|
|
|
AM_MEDIA_TYPE pad_mt;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!get_source_amt(pin, &pad_mt))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
hr = compare_media_types(mt, &pad_mt) ? S_OK : S_FALSE;
|
|
|
|
FreeMediaType(&pad_mt);
|
|
|
|
return hr;
|
2020-01-24 16:56:02 +01:00
|
|
|
}
|
|
|
|
|
2020-01-25 02:55:08 +01:00
|
|
|
static HRESULT avi_splitter_source_get_media_type(struct gstdemux_source *pin,
|
|
|
|
unsigned int index, AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
if (index > 0)
|
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
2020-06-30 03:14:06 +02:00
|
|
|
if (!get_source_amt(pin, mt))
|
|
|
|
return E_OUTOFMEMORY;
|
2020-01-25 02:55:08 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-08 20:05:09 +01:00
|
|
|
HRESULT avi_splitter_create(IUnknown *outer, IUnknown **out)
|
2019-09-20 01:59:38 +02:00
|
|
|
{
|
|
|
|
static const WCHAR sink_name[] = {'i','n','p','u','t',' ','p','i','n',0};
|
|
|
|
struct gstdemux *object;
|
|
|
|
|
|
|
|
if (!init_gstreamer())
|
2020-03-08 20:05:09 +01:00
|
|
|
return E_FAIL;
|
2019-09-20 01:59:38 +02:00
|
|
|
|
|
|
|
mark_wine_thread();
|
|
|
|
|
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2020-03-08 20:05:09 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2019-09-20 01:59:38 +02:00
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
strmbase_filter_init(&object->filter, outer, &CLSID_AviSplitter, &filter_ops);
|
2019-12-13 04:24:39 +01:00
|
|
|
strmbase_sink_init(&object->sink, &object->filter, sink_name, &avi_splitter_sink_ops, NULL);
|
2019-09-20 01:59:38 +02:00
|
|
|
object->no_more_pads_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2020-01-02 03:28:41 +01:00
|
|
|
object->error_event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2019-09-20 01:59:38 +02:00
|
|
|
object->init_gst = avi_splitter_init_gst;
|
2020-01-24 16:56:02 +01:00
|
|
|
object->source_query_accept = avi_splitter_source_query_accept;
|
2020-01-25 02:55:08 +01:00
|
|
|
object->source_get_media_type = avi_splitter_source_get_media_type;
|
2019-09-20 01:59:38 +02:00
|
|
|
|
|
|
|
TRACE("Created AVI splitter %p.\n", object);
|
2020-03-08 20:05:09 +01:00
|
|
|
*out = &object->filter.IUnknown_inner;
|
|
|
|
return S_OK;
|
2019-09-20 01:59:38 +02:00
|
|
|
}
|
2019-09-21 00:35:05 +02:00
|
|
|
|
2019-09-25 02:10:10 +02:00
|
|
|
static HRESULT mpeg_splitter_sink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
2019-09-21 00:35:05 +02:00
|
|
|
{
|
|
|
|
if (!IsEqualGUID(&mt->majortype, &MEDIATYPE_Stream))
|
|
|
|
return S_FALSE;
|
|
|
|
if (IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_MPEG1Audio))
|
|
|
|
return S_OK;
|
|
|
|
if (IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_MPEG1Video)
|
|
|
|
|| IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_MPEG1System)
|
|
|
|
|| IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_MPEG1VideoCD))
|
|
|
|
FIXME("Unsupported subtype %s.\n", wine_dbgstr_guid(&mt->subtype));
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2019-12-11 04:53:34 +01:00
|
|
|
static const struct strmbase_sink_ops mpeg_splitter_sink_ops =
|
2019-09-21 00:35:05 +02:00
|
|
|
{
|
2019-12-11 04:53:34 +01:00
|
|
|
.base.pin_query_accept = mpeg_splitter_sink_query_accept,
|
2019-12-11 04:53:35 +01:00
|
|
|
.sink_connect = gstdemux_sink_connect,
|
|
|
|
.sink_disconnect = gstdemux_sink_disconnect,
|
2019-09-21 00:35:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL mpeg_splitter_init_gst(struct gstdemux *filter)
|
|
|
|
{
|
|
|
|
static const WCHAR source_name[] = {'A','u','d','i','o',0};
|
|
|
|
struct gstdemux_source *pin;
|
|
|
|
GstElement *element;
|
2020-06-13 17:34:22 +02:00
|
|
|
HANDLE events[3];
|
|
|
|
DWORD res;
|
2019-09-21 00:35:05 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(element = gst_element_factory_make("mpegaudioparse", NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create mpegaudioparse; are %u-bit GStreamer \"good\" plugins installed?\n",
|
|
|
|
8 * (int)sizeof(void*));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_bin_add(GST_BIN(filter->container), element);
|
|
|
|
|
|
|
|
filter->their_sink = gst_element_get_static_pad(element, "sink");
|
|
|
|
if ((ret = gst_pad_link(filter->my_src, filter->their_sink)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to link sink pads, error %d.\n", ret);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(pin = create_pin(filter, source_name)))
|
|
|
|
return FALSE;
|
|
|
|
gst_object_ref(pin->their_src = gst_element_get_static_pad(element, "src"));
|
|
|
|
if ((ret = gst_pad_link(pin->their_src, pin->my_sink)) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to link source pads, error %d.\n", ret);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_pad_set_active(pin->my_sink, 1);
|
|
|
|
gst_element_set_state(filter->container, GST_STATE_PAUSED);
|
|
|
|
ret = gst_element_get_state(filter->container, NULL, NULL, -1);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
{
|
|
|
|
ERR("Failed to play stream.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-01-02 03:28:41 +01:00
|
|
|
events[0] = filter->duration_event;
|
|
|
|
events[1] = filter->error_event;
|
2020-06-13 17:34:22 +02:00
|
|
|
events[2] = pin->eos_event;
|
|
|
|
res = WaitForMultipleObjects(3, events, FALSE, INFINITE);
|
|
|
|
if (res == 1)
|
2020-01-02 03:28:41 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2020-06-10 22:52:57 +02:00
|
|
|
pin->seek.llDuration = pin->seek.llStop = query_duration(pin->their_src);
|
2019-09-21 00:35:05 +02:00
|
|
|
pin->seek.llCurrent = 0;
|
|
|
|
|
2020-01-02 03:28:41 +01:00
|
|
|
events[0] = pin->caps_event;
|
|
|
|
if (WaitForMultipleObjects(2, events, FALSE, INFINITE))
|
|
|
|
return FALSE;
|
2019-09-21 00:35:05 +02:00
|
|
|
|
|
|
|
filter->ignore_flush = TRUE;
|
|
|
|
gst_element_set_state(filter->container, GST_STATE_READY);
|
|
|
|
gst_element_get_state(filter->container, NULL, NULL, -1);
|
|
|
|
filter->ignore_flush = FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:56:02 +01:00
|
|
|
static HRESULT mpeg_splitter_source_query_accept(struct gstdemux_source *pin, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-06-30 03:14:06 +02:00
|
|
|
AM_MEDIA_TYPE pad_mt;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!get_source_amt(pin, &pad_mt))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
hr = compare_media_types(mt, &pad_mt) ? S_OK : S_FALSE;
|
|
|
|
FreeMediaType(&pad_mt);
|
|
|
|
return hr;
|
2020-01-24 16:56:02 +01:00
|
|
|
}
|
|
|
|
|
2020-01-25 02:55:08 +01:00
|
|
|
static HRESULT mpeg_splitter_source_get_media_type(struct gstdemux_source *pin,
|
|
|
|
unsigned int index, AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
if (index > 0)
|
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
2020-06-30 03:14:06 +02:00
|
|
|
if (!get_source_amt(pin, mt))
|
|
|
|
return E_OUTOFMEMORY;
|
2020-01-25 02:55:08 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-21 00:35:05 +02:00
|
|
|
static HRESULT mpeg_splitter_query_interface(struct strmbase_filter *iface, REFIID iid, void **out)
|
|
|
|
{
|
|
|
|
struct gstdemux *filter = impl_from_strmbase_filter(iface);
|
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_IAMStreamSelect))
|
|
|
|
{
|
|
|
|
*out = &filter->IAMStreamSelect_iface;
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct strmbase_filter_ops mpeg_splitter_ops =
|
|
|
|
{
|
|
|
|
.filter_query_interface = mpeg_splitter_query_interface,
|
|
|
|
.filter_get_pin = gstdemux_get_pin,
|
|
|
|
.filter_destroy = gstdemux_destroy,
|
2019-12-03 17:14:52 +01:00
|
|
|
.filter_init_stream = gstdemux_init_stream,
|
|
|
|
.filter_start_stream = gstdemux_start_stream,
|
|
|
|
.filter_stop_stream = gstdemux_stop_stream,
|
|
|
|
.filter_cleanup_stream = gstdemux_cleanup_stream,
|
|
|
|
.filter_wait_state = gstdemux_wait_state,
|
2019-09-21 00:35:05 +02:00
|
|
|
};
|
|
|
|
|
2020-03-08 20:05:09 +01:00
|
|
|
HRESULT mpeg_splitter_create(IUnknown *outer, IUnknown **out)
|
2019-09-21 00:35:05 +02:00
|
|
|
{
|
|
|
|
static const WCHAR sink_name[] = {'I','n','p','u','t',0};
|
|
|
|
struct gstdemux *object;
|
|
|
|
|
|
|
|
if (!init_gstreamer())
|
2020-03-08 20:05:09 +01:00
|
|
|
return E_FAIL;
|
2019-09-21 00:35:05 +02:00
|
|
|
|
|
|
|
mark_wine_thread();
|
|
|
|
|
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2020-03-08 20:05:09 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2019-09-21 00:35:05 +02:00
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
strmbase_filter_init(&object->filter, outer, &CLSID_MPEG1Splitter, &mpeg_splitter_ops);
|
2019-12-13 04:24:39 +01:00
|
|
|
strmbase_sink_init(&object->sink, &object->filter, sink_name, &mpeg_splitter_sink_ops, NULL);
|
2019-09-21 00:35:05 +02:00
|
|
|
object->IAMStreamSelect_iface.lpVtbl = &stream_select_vtbl;
|
|
|
|
|
|
|
|
object->duration_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2020-01-02 03:28:41 +01:00
|
|
|
object->error_event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2019-09-21 00:35:05 +02:00
|
|
|
object->init_gst = mpeg_splitter_init_gst;
|
2020-01-24 16:56:02 +01:00
|
|
|
object->source_query_accept = mpeg_splitter_source_query_accept;
|
2020-01-25 02:55:08 +01:00
|
|
|
object->source_get_media_type = mpeg_splitter_source_get_media_type;
|
2020-01-24 16:56:00 +01:00
|
|
|
object->enum_sink_first = TRUE;
|
2019-09-21 00:35:05 +02:00
|
|
|
|
|
|
|
TRACE("Created MPEG-1 splitter %p.\n", object);
|
2020-03-08 20:05:09 +01:00
|
|
|
*out = &object->filter.IUnknown_inner;
|
|
|
|
return S_OK;
|
2019-09-21 00:35:05 +02:00
|
|
|
}
|