2004-03-09 02:29:56 +01:00
|
|
|
/*
|
2019-08-30 05:49:27 +02:00
|
|
|
* Multimedia stream object
|
2004-03-09 02:29:56 +01:00
|
|
|
*
|
2012-03-14 21:51:20 +01:00
|
|
|
* Copyright 2004, 2012 Christian Costa
|
2006-06-24 21:08:58 +02:00
|
|
|
* Copyright 2006 Ivan Leo Puoti
|
2004-03-09 02:29:56 +01:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-03-09 02:29:56 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2004-03-09 02:29:56 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
|
|
|
|
#include "amstream_private.h"
|
|
|
|
|
2021-07-10 05:14:42 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream
|
|
|
|
{
|
2010-12-04 22:12:01 +01:00
|
|
|
IAMMultiMediaStream IAMMultiMediaStream_iface;
|
2005-07-11 15:21:17 +02:00
|
|
|
LONG ref;
|
2020-03-05 05:33:32 +01:00
|
|
|
IGraphBuilder *graph;
|
2012-03-14 21:51:27 +01:00
|
|
|
IMediaSeeking* media_seeking;
|
|
|
|
IMediaControl* media_control;
|
2019-08-29 03:24:33 +02:00
|
|
|
IMediaStreamFilter *filter;
|
2006-06-24 21:08:58 +02:00
|
|
|
IPin* ipin;
|
2020-03-05 05:33:36 +01:00
|
|
|
BOOL initialized;
|
2020-03-05 05:33:32 +01:00
|
|
|
STREAM_TYPE type;
|
2012-03-14 21:51:43 +01:00
|
|
|
OAEVENT event;
|
2020-11-17 18:48:23 +01:00
|
|
|
STREAM_STATE state;
|
2019-08-30 05:49:28 +02:00
|
|
|
};
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2019-08-30 05:49:28 +02:00
|
|
|
static inline struct multimedia_stream *impl_from_IAMMultiMediaStream(IAMMultiMediaStream *iface)
|
2010-12-04 22:12:01 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct multimedia_stream, IAMMultiMediaStream_iface);
|
2010-12-04 22:12:01 +01:00
|
|
|
}
|
|
|
|
|
2004-03-09 02:29:56 +01:00
|
|
|
/*** IUnknown methods ***/
|
2019-09-02 02:48:04 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_QueryInterface(IAMMultiMediaStream *iface,
|
|
|
|
REFIID riid, void **ppvObject)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream *This = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2008-12-14 19:07:32 +01:00
|
|
|
TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2005-11-01 19:06:03 +01:00
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
2010-04-05 20:30:09 +02:00
|
|
|
IsEqualGUID(riid, &IID_IMultiMediaStream) ||
|
2005-11-01 19:06:03 +01:00
|
|
|
IsEqualGUID(riid, &IID_IAMMultiMediaStream))
|
|
|
|
{
|
2012-08-19 17:11:05 +02:00
|
|
|
IAMMultiMediaStream_AddRef(iface);
|
|
|
|
*ppvObject = iface;
|
2005-11-01 19:06:03 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2005-11-01 19:06:03 +01:00
|
|
|
ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static ULONG WINAPI multimedia_stream_AddRef(IAMMultiMediaStream *iface)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream *This = impl_from_IAMMultiMediaStream(iface);
|
2005-11-01 19:06:03 +01:00
|
|
|
|
|
|
|
TRACE("(%p/%p)\n", iface, This);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2005-11-01 19:06:03 +01:00
|
|
|
return InterlockedIncrement(&This->ref);
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static ULONG WINAPI multimedia_stream_Release(IAMMultiMediaStream *iface)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream *This = impl_from_IAMMultiMediaStream(iface);
|
2005-11-01 19:06:03 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2005-11-01 19:06:03 +01:00
|
|
|
TRACE("(%p/%p)\n", iface, This);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2005-11-01 19:06:03 +01:00
|
|
|
if (!ref)
|
2012-03-12 19:55:04 +01:00
|
|
|
{
|
|
|
|
if (This->ipin)
|
|
|
|
IPin_Release(This->ipin);
|
2019-08-29 03:24:33 +02:00
|
|
|
IMediaStreamFilter_Release(This->filter);
|
2020-07-06 17:42:47 +02:00
|
|
|
IMediaStreamFilter_Release(This->filter);
|
2012-03-14 21:51:27 +01:00
|
|
|
if (This->media_seeking)
|
|
|
|
IMediaSeeking_Release(This->media_seeking);
|
|
|
|
if (This->media_control)
|
|
|
|
IMediaControl_Release(This->media_control);
|
2020-03-05 05:33:32 +01:00
|
|
|
if (This->graph)
|
|
|
|
IGraphBuilder_Release(This->graph);
|
2022-03-27 01:54:41 +01:00
|
|
|
free(This);
|
2012-03-12 19:55:04 +01:00
|
|
|
}
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2005-11-01 19:06:03 +01:00
|
|
|
return ref;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IMultiMediaStream methods ***/
|
2019-09-02 02:48:04 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_GetInformation(IAMMultiMediaStream *iface,
|
|
|
|
DWORD *pdwFlags, STREAM_TYPE *pStreamType)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream *This = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2008-12-14 19:07:32 +01:00
|
|
|
FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pdwFlags, pStreamType);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2005-11-01 19:06:03 +01:00
|
|
|
return E_NOTIMPL;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_GetMediaStream(IAMMultiMediaStream *iface,
|
2019-09-02 02:48:06 +02:00
|
|
|
REFMSPID id, IMediaStream **stream)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-09-02 02:48:06 +02:00
|
|
|
struct multimedia_stream *mmstream = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2019-09-02 02:48:06 +02:00
|
|
|
TRACE("mmstream %p, id %s, stream %p.\n", mmstream, debugstr_guid(id), stream);
|
2005-11-07 17:38:48 +01:00
|
|
|
|
2019-09-02 02:48:06 +02:00
|
|
|
return IMediaStreamFilter_GetMediaStream(mmstream->filter, id, stream);
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_EnumMediaStreams(IAMMultiMediaStream *iface,
|
2020-03-04 00:19:12 +01:00
|
|
|
LONG index, IMediaStream **stream)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2020-03-04 00:19:12 +01:00
|
|
|
struct multimedia_stream *mmstream = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2022-02-07 23:10:45 +01:00
|
|
|
TRACE("mmstream %p, index %ld, stream %p.\n", mmstream, index, stream);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2020-03-04 00:19:12 +01:00
|
|
|
return IMediaStreamFilter_EnumMediaStreams(mmstream->filter, index, stream);
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2020-11-17 18:48:23 +01:00
|
|
|
static HRESULT WINAPI multimedia_stream_GetState(IAMMultiMediaStream *iface, STREAM_STATE *state)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2020-11-17 18:48:23 +01:00
|
|
|
struct multimedia_stream *mmstream = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2020-11-17 18:48:23 +01:00
|
|
|
TRACE("mmstream %p, state %p.\n", mmstream, state);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2020-11-17 18:48:23 +01:00
|
|
|
*state = mmstream->state;
|
|
|
|
|
|
|
|
return S_OK;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_SetState(IAMMultiMediaStream *iface, STREAM_STATE new_state)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream *This = impl_from_IAMMultiMediaStream(iface);
|
2012-04-03 07:53:50 +02:00
|
|
|
HRESULT hr = E_INVALIDARG;
|
2005-11-01 19:06:03 +01:00
|
|
|
|
2012-04-03 07:53:50 +02:00
|
|
|
TRACE("(%p/%p)->(%u)\n", This, iface, new_state);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2012-04-04 21:18:00 +02:00
|
|
|
if (new_state == STREAMSTATE_RUN)
|
2020-07-21 17:50:06 +02:00
|
|
|
{
|
2012-04-03 07:53:50 +02:00
|
|
|
hr = IMediaControl_Run(This->media_control);
|
2020-07-21 17:50:06 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2020-10-29 05:40:56 +01:00
|
|
|
{
|
|
|
|
FILTER_STATE state;
|
|
|
|
IMediaControl_GetState(This->media_control, INFINITE, (OAFilterState *)&state);
|
2020-07-21 17:50:06 +02:00
|
|
|
hr = S_OK;
|
2020-10-29 05:40:56 +01:00
|
|
|
}
|
2020-07-21 17:50:06 +02:00
|
|
|
}
|
2012-04-04 21:18:00 +02:00
|
|
|
else if (new_state == STREAMSTATE_STOP)
|
2012-04-03 07:53:50 +02:00
|
|
|
hr = IMediaControl_Stop(This->media_control);
|
|
|
|
|
2020-11-17 18:48:23 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
This->state = new_state;
|
|
|
|
|
2012-04-03 07:53:50 +02:00
|
|
|
return hr;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2020-11-17 18:48:24 +01:00
|
|
|
static HRESULT WINAPI multimedia_stream_GetTime(IAMMultiMediaStream *iface, STREAM_TIME *time)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2020-11-17 18:48:24 +01:00
|
|
|
struct multimedia_stream *stream = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2020-11-17 18:48:24 +01:00
|
|
|
TRACE("stream %p, time %p.\n", stream, time);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2020-11-17 18:48:24 +01:00
|
|
|
return IMediaStreamFilter_GetCurrentStreamTime(stream->filter, time);
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2020-07-28 23:14:00 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_GetDuration(IAMMultiMediaStream *iface, STREAM_TIME *duration)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2020-07-28 23:14:00 +02:00
|
|
|
struct multimedia_stream *mmstream = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2020-07-28 23:14:00 +02:00
|
|
|
TRACE("mmstream %p, duration %p.\n", mmstream, duration);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2020-07-28 23:14:00 +02:00
|
|
|
if (!mmstream->media_seeking)
|
|
|
|
return E_NOINTERFACE;
|
2020-08-06 20:32:31 +02:00
|
|
|
|
|
|
|
if (IMediaSeeking_GetDuration(mmstream->media_seeking, duration) != S_OK)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
return S_OK;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_Seek(IAMMultiMediaStream *iface, STREAM_TIME seek_time)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream *This = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2012-04-03 07:53:43 +02:00
|
|
|
TRACE("(%p/%p)->(%s)\n", This, iface, wine_dbgstr_longlong(seek_time));
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2012-04-03 07:53:43 +02:00
|
|
|
return IMediaSeeking_SetPositions(This->media_seeking, &seek_time, AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2021-04-21 07:53:32 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_GetEndOfStream(IAMMultiMediaStream *iface, HANDLE *eos)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2021-04-21 07:53:32 +02:00
|
|
|
struct multimedia_stream *mmstream = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2021-04-21 07:53:32 +02:00
|
|
|
TRACE("mmstream %p, eos %p.\n", mmstream, eos);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2021-04-21 07:53:32 +02:00
|
|
|
if (!eos)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*eos = (HANDLE)mmstream->event;
|
|
|
|
|
|
|
|
return S_OK;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2020-03-05 05:33:32 +01:00
|
|
|
static HRESULT create_graph(struct multimedia_stream *mmstream, IGraphBuilder *graph)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2020-03-05 05:33:32 +01:00
|
|
|
IMediaEventEx *eventsrc;
|
|
|
|
HRESULT hr;
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2020-03-05 05:33:32 +01:00
|
|
|
if (graph)
|
|
|
|
IGraphBuilder_AddRef(mmstream->graph = graph);
|
|
|
|
else if (FAILED(hr = CoCreateInstance(&CLSID_FilterGraph, NULL,
|
|
|
|
CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (void **)&mmstream->graph)))
|
|
|
|
return hr;
|
2005-11-07 17:38:48 +01:00
|
|
|
|
2020-03-05 05:33:32 +01:00
|
|
|
hr = IGraphBuilder_QueryInterface(mmstream->graph, &IID_IMediaSeeking, (void **)&mmstream->media_seeking);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IGraphBuilder_QueryInterface(mmstream->graph, &IID_IMediaControl, (void **)&mmstream->media_control);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IGraphBuilder_AddFilter(mmstream->graph, (IBaseFilter *)mmstream->filter, L"MediaStreamFilter");
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IGraphBuilder_QueryInterface(mmstream->graph, &IID_IMediaEventEx, (void **)&eventsrc);
|
2005-11-07 17:38:48 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2020-03-05 05:33:32 +01:00
|
|
|
hr = IMediaEventEx_GetEventHandle(eventsrc, &mmstream->event);
|
2012-03-14 21:51:35 +01:00
|
|
|
if (SUCCEEDED(hr))
|
2020-03-05 05:33:32 +01:00
|
|
|
hr = IMediaEventEx_SetNotifyFlags(eventsrc, AM_MEDIAEVENT_NONOTIFY);
|
|
|
|
IMediaEventEx_Release(eventsrc);
|
2012-03-14 21:51:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2020-03-05 05:33:32 +01:00
|
|
|
if (mmstream->media_seeking)
|
|
|
|
IMediaSeeking_Release(mmstream->media_seeking);
|
|
|
|
mmstream->media_seeking = NULL;
|
|
|
|
if (mmstream->media_control)
|
|
|
|
IMediaControl_Release(mmstream->media_control);
|
|
|
|
mmstream->media_control = NULL;
|
|
|
|
if (mmstream->graph)
|
|
|
|
IGraphBuilder_Release(mmstream->graph);
|
|
|
|
mmstream->graph = NULL;
|
2005-11-07 17:38:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2020-03-05 05:33:32 +01:00
|
|
|
static HRESULT WINAPI multimedia_stream_Initialize(IAMMultiMediaStream *iface,
|
|
|
|
STREAM_TYPE type, DWORD flags, IGraphBuilder *graph)
|
|
|
|
{
|
|
|
|
struct multimedia_stream *mmstream = impl_from_IAMMultiMediaStream(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-07 23:10:45 +01:00
|
|
|
TRACE("mmstream %p, type %u, flags %#lx, graph %p.\n", mmstream, type, flags, graph);
|
2020-03-05 05:33:32 +01:00
|
|
|
|
2020-03-05 05:33:35 +01:00
|
|
|
if (graph && mmstream->graph)
|
|
|
|
{
|
|
|
|
WARN("Graph already initialized, returning E_INVALIDARG.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2020-03-05 05:33:36 +01:00
|
|
|
if (mmstream->initialized && type != mmstream->type)
|
|
|
|
{
|
|
|
|
WARN("Attempt to change type from %u, returning E_INVALIDARG.\n", mmstream->type);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2020-03-05 05:33:34 +01:00
|
|
|
if (graph && FAILED(hr = create_graph(mmstream, graph)))
|
2020-03-05 05:33:32 +01:00
|
|
|
return hr;
|
|
|
|
|
|
|
|
mmstream->type = type;
|
2020-03-05 05:33:36 +01:00
|
|
|
mmstream->initialized = TRUE;
|
2020-03-05 05:33:32 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-05 05:33:31 +01:00
|
|
|
static HRESULT WINAPI multimedia_stream_GetFilterGraph(IAMMultiMediaStream *iface, IGraphBuilder **graph)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2020-03-05 05:33:31 +01:00
|
|
|
struct multimedia_stream *mmstream = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2020-03-05 05:33:31 +01:00
|
|
|
TRACE("mmstream %p, graph %p.\n", mmstream, graph);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2020-03-05 05:33:31 +01:00
|
|
|
if (!graph)
|
2009-03-25 22:55:03 +01:00
|
|
|
return E_POINTER;
|
|
|
|
|
2020-03-05 05:33:32 +01:00
|
|
|
if (mmstream->graph)
|
|
|
|
IGraphBuilder_AddRef(*graph = mmstream->graph);
|
2009-03-25 22:55:03 +01:00
|
|
|
else
|
2020-03-05 05:33:31 +01:00
|
|
|
*graph = NULL;
|
2009-03-25 22:55:03 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_GetFilter(IAMMultiMediaStream *iface,
|
|
|
|
IMediaStreamFilter **filter)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream *mmstream = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2019-08-29 03:24:33 +02:00
|
|
|
TRACE("mmstream %p, filter %p.\n", mmstream, filter);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2019-08-29 03:24:33 +02:00
|
|
|
if (!filter)
|
2012-03-26 10:10:13 +02:00
|
|
|
return E_POINTER;
|
|
|
|
|
2019-08-29 03:24:33 +02:00
|
|
|
IMediaStreamFilter_AddRef(*filter = mmstream->filter);
|
2012-03-26 10:10:13 +02:00
|
|
|
|
2015-06-20 22:34:58 +02:00
|
|
|
return S_OK;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2020-03-27 17:54:29 +01:00
|
|
|
static void add_stream(struct multimedia_stream *mmstream, IAMMediaStream *stream, IMediaStream **ret_stream)
|
|
|
|
{
|
|
|
|
IMediaStreamFilter_AddMediaStream(mmstream->filter, stream);
|
2020-05-27 21:05:50 +02:00
|
|
|
IAMMediaStream_JoinAMMultiMediaStream(stream, &mmstream->IAMMultiMediaStream_iface);
|
2020-03-27 17:54:29 +01:00
|
|
|
if (ret_stream)
|
|
|
|
{
|
|
|
|
*ret_stream = (IMediaStream *)stream;
|
|
|
|
IMediaStream_AddRef(*ret_stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_AddMediaStream(IAMMultiMediaStream *iface,
|
2019-09-02 02:48:07 +02:00
|
|
|
IUnknown *stream_object, const MSPID *PurposeId, DWORD dwFlags, IMediaStream **ret_stream)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream *This = impl_from_IAMMultiMediaStream(iface);
|
2005-11-07 17:38:48 +01:00
|
|
|
HRESULT hr;
|
2015-06-20 22:34:58 +02:00
|
|
|
IAMMediaStream* pStream;
|
2020-03-04 00:19:13 +01:00
|
|
|
IMediaStream *stream;
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2022-02-07 23:10:45 +01:00
|
|
|
TRACE("mmstream %p, stream_object %p, id %s, flags %#lx, ret_stream %p.\n",
|
2019-09-02 02:48:07 +02:00
|
|
|
This, stream_object, debugstr_guid(PurposeId), dwFlags, ret_stream);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2020-03-04 00:19:13 +01:00
|
|
|
if (IMediaStreamFilter_GetMediaStream(This->filter, PurposeId, &stream) == S_OK)
|
|
|
|
{
|
|
|
|
IMediaStream_Release(stream);
|
|
|
|
return MS_E_PURPOSEID;
|
|
|
|
}
|
|
|
|
|
2020-03-05 05:33:32 +01:00
|
|
|
if (!This->graph && FAILED(hr = create_graph(This, NULL)))
|
|
|
|
return hr;
|
|
|
|
|
2012-03-26 10:10:05 +02:00
|
|
|
if (dwFlags & AMMSF_ADDDEFAULTRENDERER)
|
|
|
|
{
|
2020-03-04 00:19:15 +01:00
|
|
|
IBaseFilter *dsound_render;
|
|
|
|
|
2020-03-04 00:19:16 +01:00
|
|
|
if (ret_stream)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2020-03-04 00:19:15 +01:00
|
|
|
if (!IsEqualGUID(PurposeId, &MSPID_PrimaryAudio))
|
2012-03-26 10:10:05 +02:00
|
|
|
{
|
2020-03-04 00:19:15 +01:00
|
|
|
WARN("AMMSF_ADDDEFAULTRENDERER requested with id %s, returning MS_E_PURPOSEID.\n", debugstr_guid(PurposeId));
|
2012-03-26 10:10:05 +02:00
|
|
|
return MS_E_PURPOSEID;
|
|
|
|
}
|
|
|
|
|
2020-03-04 00:19:15 +01:00
|
|
|
if (SUCCEEDED(hr = CoCreateInstance(&CLSID_DSoundRender, NULL,
|
|
|
|
CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (void **)&dsound_render)))
|
|
|
|
{
|
2020-03-05 05:33:32 +01:00
|
|
|
hr = IGraphBuilder_AddFilter(This->graph, dsound_render, NULL);
|
2020-03-04 00:19:15 +01:00
|
|
|
IBaseFilter_Release(dsound_render);
|
2012-03-26 10:10:05 +02:00
|
|
|
}
|
2020-03-04 00:19:15 +01:00
|
|
|
return hr;
|
2012-03-26 10:10:05 +02:00
|
|
|
}
|
2012-03-26 10:09:57 +02:00
|
|
|
|
2020-03-27 17:54:29 +01:00
|
|
|
if (stream_object)
|
|
|
|
{
|
|
|
|
hr = IUnknown_QueryInterface(stream_object, &IID_IAMMediaStream, (void **)&pStream);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
MSPID stream_id;
|
|
|
|
hr = IAMMediaStream_GetInformation(pStream, &stream_id, NULL);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(PurposeId, &stream_id))
|
|
|
|
{
|
|
|
|
add_stream(This, pStream, ret_stream);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = MS_E_PURPOSEID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IAMMediaStream_Release(pStream);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-23 21:44:19 +02:00
|
|
|
if (IsEqualGUID(PurposeId, &MSPID_PrimaryVideo))
|
2020-05-27 21:05:50 +02:00
|
|
|
hr = ddraw_stream_create(NULL, (void **)&pStream);
|
2020-03-27 17:54:29 +01:00
|
|
|
else if (IsEqualGUID(PurposeId, &MSPID_PrimaryAudio))
|
2020-05-27 21:05:50 +02:00
|
|
|
hr = audio_stream_create(NULL, (void **)&pStream);
|
2020-03-27 17:54:29 +01:00
|
|
|
else
|
|
|
|
return MS_E_PURPOSEID;
|
2005-11-07 17:38:48 +01:00
|
|
|
|
2020-05-27 21:05:50 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IAMMediaStream_Initialize(pStream, stream_object, dwFlags, PurposeId, This->type);
|
|
|
|
if (FAILED(hr))
|
2012-03-27 23:46:03 +02:00
|
|
|
{
|
2020-03-27 17:54:29 +01:00
|
|
|
IAMMediaStream_Release(pStream);
|
2020-05-27 21:05:50 +02:00
|
|
|
return hr;
|
2012-03-27 23:46:03 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:05:50 +02:00
|
|
|
add_stream(This, pStream, ret_stream);
|
|
|
|
IAMMediaStream_Release(pStream);
|
|
|
|
|
|
|
|
return S_OK;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_OpenFile(IAMMultiMediaStream *iface,
|
|
|
|
const WCHAR *filename, DWORD flags)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream *This = impl_from_IAMMultiMediaStream(iface);
|
2012-03-14 21:50:56 +01:00
|
|
|
HRESULT ret = S_OK;
|
|
|
|
IBaseFilter *BaseFilter = NULL;
|
|
|
|
IEnumPins *EnumPins = NULL;
|
2006-06-24 21:08:58 +02:00
|
|
|
IPin *ipin;
|
|
|
|
PIN_DIRECTION pin_direction;
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2022-02-07 23:10:45 +01:00
|
|
|
TRACE("(%p/%p)->(%s,%lx)\n", This, iface, debugstr_w(filename), flags);
|
2012-10-12 07:15:58 +02:00
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
return E_POINTER;
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2012-03-12 19:54:39 +01:00
|
|
|
/* If Initialize was not called before, we do it here */
|
2020-03-05 05:33:32 +01:00
|
|
|
if (!This->graph)
|
2020-03-05 05:33:33 +01:00
|
|
|
{
|
2012-03-12 19:54:39 +01:00
|
|
|
ret = IAMMultiMediaStream_Initialize(iface, STREAMTYPE_READ, 0, NULL);
|
2020-03-05 05:33:33 +01:00
|
|
|
if (SUCCEEDED(ret))
|
|
|
|
ret = create_graph(This, NULL);
|
|
|
|
}
|
2012-03-12 19:54:39 +01:00
|
|
|
|
2012-03-14 21:50:56 +01:00
|
|
|
if (SUCCEEDED(ret))
|
2020-03-05 05:33:32 +01:00
|
|
|
ret = IGraphBuilder_AddSourceFilter(This->graph, filename, L"Source", &BaseFilter);
|
2012-03-12 19:54:56 +01:00
|
|
|
|
2012-03-14 21:50:56 +01:00
|
|
|
if (SUCCEEDED(ret))
|
|
|
|
ret = IBaseFilter_EnumPins(BaseFilter, &EnumPins);
|
|
|
|
|
|
|
|
if (SUCCEEDED(ret))
|
|
|
|
ret = IEnumPins_Next(EnumPins, 1, &ipin, NULL);
|
2006-06-24 21:08:58 +02:00
|
|
|
|
2012-03-14 21:50:56 +01:00
|
|
|
if (SUCCEEDED(ret))
|
2006-06-24 21:08:58 +02:00
|
|
|
{
|
|
|
|
ret = IPin_QueryDirection(ipin, &pin_direction);
|
2012-03-12 19:54:56 +01:00
|
|
|
if (ret == S_OK && pin_direction == PINDIR_OUTPUT)
|
2006-06-24 21:08:58 +02:00
|
|
|
This->ipin = ipin;
|
|
|
|
}
|
|
|
|
|
2012-10-12 07:16:06 +02:00
|
|
|
if (SUCCEEDED(ret) && !(flags & AMMSF_NORENDER))
|
2020-08-06 20:32:30 +02:00
|
|
|
{
|
|
|
|
IFilterGraph2 *graph;
|
|
|
|
|
|
|
|
if (SUCCEEDED(ret = IGraphBuilder_QueryInterface(This->graph, &IID_IFilterGraph2, (void **)&graph)))
|
|
|
|
{
|
2021-07-01 12:42:30 +02:00
|
|
|
DWORD renderflags = (flags & AMMSF_RENDERALLSTREAMS) ? 0 : AM_RENDEREX_RENDERTOEXISTINGRENDERERS;
|
|
|
|
|
|
|
|
ret = IFilterGraph2_RenderEx(graph, This->ipin, renderflags, NULL);
|
2020-08-06 20:32:30 +02:00
|
|
|
if (ret == VFW_E_CANNOT_RENDER) ret = VFW_E_CANNOT_CONNECT;
|
|
|
|
else if (ret == VFW_S_PARTIAL_RENDER) ret = S_OK;
|
2021-07-01 12:42:30 +02:00
|
|
|
|
2020-08-06 20:32:30 +02:00
|
|
|
IFilterGraph2_Release(graph);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-07 23:10:45 +01:00
|
|
|
FIXME("Failed to get IFilterGraph2 interface, hr %#lx.\n", ret);
|
2020-08-06 20:32:30 +02:00
|
|
|
ret = IGraphBuilder_Render(This->graph, This->ipin);
|
|
|
|
}
|
|
|
|
}
|
2012-10-12 07:16:06 +02:00
|
|
|
|
2020-10-29 05:40:57 +01:00
|
|
|
if (SUCCEEDED(ret) && (flags & AMMSF_NOCLOCK))
|
|
|
|
{
|
|
|
|
IMediaFilter *media_filter;
|
|
|
|
|
|
|
|
if (SUCCEEDED(ret = IGraphBuilder_QueryInterface(This->graph, &IID_IMediaFilter, (void **)&media_filter)))
|
|
|
|
{
|
|
|
|
ret = IMediaFilter_SetSyncSource(media_filter, NULL);
|
|
|
|
IMediaFilter_Release(media_filter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-03 21:28:16 +02:00
|
|
|
IMediaStreamFilter_SupportSeeking(This->filter, This->type == STREAMTYPE_READ);
|
|
|
|
|
2020-07-21 17:50:07 +02:00
|
|
|
if (SUCCEEDED(ret) && (flags & AMMSF_RUN))
|
|
|
|
ret = IAMMultiMediaStream_SetState(iface, STREAMSTATE_RUN);
|
|
|
|
|
2012-03-14 21:50:56 +01:00
|
|
|
if (EnumPins)
|
|
|
|
IEnumPins_Release(EnumPins);
|
|
|
|
if (BaseFilter)
|
|
|
|
IBaseFilter_Release(BaseFilter);
|
2006-06-24 21:08:58 +02:00
|
|
|
return ret;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_OpenMoniker(IAMMultiMediaStream *iface,
|
|
|
|
IBindCtx *pCtx, IMoniker *pMoniker, DWORD dwFlags)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream *This = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2022-02-07 23:10:45 +01:00
|
|
|
FIXME("(%p/%p)->(%p,%p,%lx) stub!\n", This, iface, pCtx, pMoniker, dwFlags);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2005-11-01 19:06:03 +01:00
|
|
|
return E_NOTIMPL;
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static HRESULT WINAPI multimedia_stream_Render(IAMMultiMediaStream *iface, DWORD dwFlags)
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-08-30 05:49:28 +02:00
|
|
|
struct multimedia_stream *This = impl_from_IAMMultiMediaStream(iface);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2022-02-07 23:10:45 +01:00
|
|
|
FIXME("(%p/%p)->(%lx) partial stub!\n", This, iface, dwFlags);
|
2004-03-09 02:29:56 +01:00
|
|
|
|
2006-06-24 21:08:58 +02:00
|
|
|
if(dwFlags != AMMSF_NOCLOCK)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2020-03-05 05:33:32 +01:00
|
|
|
return IGraphBuilder_Render(This->graph, This->ipin);
|
2004-03-09 02:29:56 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:04 +02:00
|
|
|
static const IAMMultiMediaStreamVtbl multimedia_stream_vtbl =
|
2004-03-09 02:29:56 +01:00
|
|
|
{
|
2019-09-02 02:48:04 +02:00
|
|
|
multimedia_stream_QueryInterface,
|
|
|
|
multimedia_stream_AddRef,
|
|
|
|
multimedia_stream_Release,
|
|
|
|
multimedia_stream_GetInformation,
|
|
|
|
multimedia_stream_GetMediaStream,
|
|
|
|
multimedia_stream_EnumMediaStreams,
|
|
|
|
multimedia_stream_GetState,
|
|
|
|
multimedia_stream_SetState,
|
|
|
|
multimedia_stream_GetTime,
|
|
|
|
multimedia_stream_GetDuration,
|
|
|
|
multimedia_stream_Seek,
|
|
|
|
multimedia_stream_GetEndOfStream,
|
|
|
|
multimedia_stream_Initialize,
|
|
|
|
multimedia_stream_GetFilterGraph,
|
|
|
|
multimedia_stream_GetFilter,
|
|
|
|
multimedia_stream_AddMediaStream,
|
|
|
|
multimedia_stream_OpenFile,
|
|
|
|
multimedia_stream_OpenMoniker,
|
|
|
|
multimedia_stream_Render
|
2004-03-09 02:29:56 +01:00
|
|
|
};
|
2019-09-02 02:48:05 +02:00
|
|
|
|
|
|
|
HRESULT multimedia_stream_create(IUnknown *outer, void **out)
|
|
|
|
{
|
|
|
|
struct multimedia_stream *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (outer)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
2022-03-27 01:54:41 +01:00
|
|
|
if (!(object = calloc(1, sizeof(*object))))
|
2019-09-02 02:48:05 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->IAMMultiMediaStream_iface.lpVtbl = &multimedia_stream_vtbl;
|
|
|
|
object->ref = 1;
|
|
|
|
|
|
|
|
if (FAILED(hr = CoCreateInstance(&CLSID_MediaStreamFilter, NULL,
|
|
|
|
CLSCTX_INPROC_SERVER, &IID_IMediaStreamFilter, (void **)&object->filter)))
|
|
|
|
{
|
2022-02-07 23:10:45 +01:00
|
|
|
ERR("Failed to create stream filter, hr %#lx.\n", hr);
|
2022-03-27 01:54:41 +01:00
|
|
|
free(object);
|
2019-09-02 02:48:05 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-07-06 17:42:47 +02:00
|
|
|
/* The stream takes an additional reference to the filter. */
|
|
|
|
IMediaStreamFilter_AddRef(object->filter);
|
|
|
|
|
2019-09-02 02:48:05 +02:00
|
|
|
TRACE("Created multimedia stream %p.\n", object);
|
|
|
|
*out = &object->IAMMultiMediaStream_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|