2019-02-25 08:14:47 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Nikolay Sivov 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
|
|
|
|
*/
|
|
|
|
|
2021-04-01 22:22:57 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2019-02-25 08:14:47 +01:00
|
|
|
#include <stdarg.h>
|
2021-04-13 08:03:28 +02:00
|
|
|
#include <assert.h>
|
2019-02-25 08:14:47 +01:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2021-04-05 08:10:58 +02:00
|
|
|
#include "mfapi.h"
|
2019-04-22 17:13:38 +02:00
|
|
|
#include "mfplay.h"
|
2021-04-07 10:07:06 +02:00
|
|
|
#include "mferror.h"
|
2019-04-22 17:13:38 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2021-04-13 08:03:28 +02:00
|
|
|
#include "initguid.h"
|
|
|
|
|
2019-04-22 17:13:38 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
|
2019-02-25 08:14:47 +01:00
|
|
|
|
2021-04-13 08:03:28 +02:00
|
|
|
DEFINE_GUID(_MF_TOPO_MEDIA_ITEM, 0x6c1bb4df, 0x59ba, 0x4020, 0x85, 0x0c, 0x35, 0x79, 0xa2, 0x7a, 0xe2, 0x51);
|
2021-04-20 11:06:01 +02:00
|
|
|
DEFINE_GUID(_MF_CUSTOM_SINK, 0x7c1bb4df, 0x59ba, 0x4020, 0x85, 0x0c, 0x35, 0x79, 0xa2, 0x7a, 0xe2, 0x51);
|
2021-04-13 08:03:28 +02:00
|
|
|
|
2021-04-06 09:25:32 +02:00
|
|
|
static const WCHAR eventclassW[] = L"MediaPlayerEventCallbackClass";
|
|
|
|
|
2021-04-05 08:10:58 +02:00
|
|
|
static LONG startup_refcount;
|
2021-04-06 09:25:32 +02:00
|
|
|
static HINSTANCE mfplay_instance;
|
2021-04-05 08:10:58 +02:00
|
|
|
|
|
|
|
static void platform_startup(void)
|
|
|
|
{
|
|
|
|
if (InterlockedIncrement(&startup_refcount) == 1)
|
|
|
|
MFStartup(MF_VERSION, MFSTARTUP_FULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void platform_shutdown(void)
|
|
|
|
{
|
|
|
|
if (InterlockedDecrement(&startup_refcount) == 0)
|
|
|
|
MFShutdown();
|
|
|
|
}
|
|
|
|
|
2021-04-05 08:11:00 +02:00
|
|
|
struct media_item
|
|
|
|
{
|
|
|
|
IMFPMediaItem IMFPMediaItem_iface;
|
|
|
|
LONG refcount;
|
|
|
|
IMFPMediaPlayer *player;
|
|
|
|
IMFMediaSource *source;
|
2021-04-06 09:25:26 +02:00
|
|
|
IMFPresentationDescriptor *pd;
|
2021-04-05 08:11:00 +02:00
|
|
|
DWORD_PTR user_data;
|
2021-04-07 10:07:06 +02:00
|
|
|
WCHAR *url;
|
2021-04-16 14:36:08 +02:00
|
|
|
IUnknown *object;
|
2021-06-21 10:43:13 +02:00
|
|
|
LONGLONG start_position;
|
|
|
|
LONGLONG stop_position;
|
2021-04-05 08:11:00 +02:00
|
|
|
};
|
|
|
|
|
2021-04-01 22:22:57 +02:00
|
|
|
struct media_player
|
|
|
|
{
|
|
|
|
IMFPMediaPlayer IMFPMediaPlayer_iface;
|
2021-04-05 08:10:59 +02:00
|
|
|
IPropertyStore IPropertyStore_iface;
|
2021-04-05 08:11:00 +02:00
|
|
|
IMFAsyncCallback resolver_callback;
|
2021-04-06 09:25:31 +02:00
|
|
|
IMFAsyncCallback events_callback;
|
2021-04-07 10:07:00 +02:00
|
|
|
IMFAsyncCallback session_events_callback;
|
2021-04-01 22:22:57 +02:00
|
|
|
LONG refcount;
|
2021-04-05 08:10:57 +02:00
|
|
|
IMFPMediaPlayerCallback *callback;
|
2021-04-05 08:10:59 +02:00
|
|
|
IPropertyStore *propstore;
|
2021-04-05 08:11:00 +02:00
|
|
|
IMFSourceResolver *resolver;
|
2021-04-07 10:07:00 +02:00
|
|
|
IMFMediaSession *session;
|
2021-04-13 08:03:30 +02:00
|
|
|
IMFPMediaItem *item;
|
2021-04-06 09:25:31 +02:00
|
|
|
MFP_CREATION_OPTIONS options;
|
2021-04-07 10:07:01 +02:00
|
|
|
MFP_MEDIAPLAYER_STATE state;
|
2021-04-06 09:25:32 +02:00
|
|
|
HWND event_window;
|
2021-04-07 10:06:59 +02:00
|
|
|
HWND output_window;
|
2021-04-07 10:07:01 +02:00
|
|
|
CRITICAL_SECTION cs;
|
2021-04-06 09:25:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct generic_event
|
|
|
|
{
|
|
|
|
MFP_EVENT_HEADER header;
|
|
|
|
IMFPMediaItem *item;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct media_event
|
|
|
|
{
|
|
|
|
IUnknown IUnknown_iface;
|
|
|
|
LONG refcount;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
MFP_EVENT_HEADER header;
|
|
|
|
struct generic_event generic;
|
|
|
|
MFP_PLAY_EVENT play;
|
|
|
|
MFP_PAUSE_EVENT pause;
|
|
|
|
MFP_STOP_EVENT stop;
|
|
|
|
MFP_POSITION_SET_EVENT position_set;
|
|
|
|
MFP_RATE_SET_EVENT rate_set;
|
|
|
|
MFP_MEDIAITEM_CREATED_EVENT item_created;
|
|
|
|
MFP_MEDIAITEM_SET_EVENT item_set;
|
|
|
|
MFP_MEDIAITEM_CLEARED_EVENT item_cleared;
|
|
|
|
MFP_MF_EVENT event;
|
|
|
|
MFP_ERROR_EVENT error;
|
|
|
|
MFP_PLAYBACK_ENDED_EVENT ended;
|
|
|
|
MFP_ACQUIRE_USER_CREDENTIAL_EVENT acquire_creds;
|
|
|
|
} u;
|
2021-04-01 22:22:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct media_player *impl_from_IMFPMediaPlayer(IMFPMediaPlayer *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct media_player, IMFPMediaPlayer_iface);
|
|
|
|
}
|
|
|
|
|
2021-04-05 08:10:59 +02:00
|
|
|
static struct media_player *impl_from_IPropertyStore(IPropertyStore *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct media_player, IPropertyStore_iface);
|
|
|
|
}
|
|
|
|
|
2021-04-05 08:11:00 +02:00
|
|
|
static struct media_player *impl_from_resolver_IMFAsyncCallback(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct media_player, resolver_callback);
|
|
|
|
}
|
|
|
|
|
2021-04-06 09:25:31 +02:00
|
|
|
static struct media_player *impl_from_events_IMFAsyncCallback(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct media_player, events_callback);
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:07:00 +02:00
|
|
|
static struct media_player *impl_from_session_events_IMFAsyncCallback(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct media_player, session_events_callback);
|
|
|
|
}
|
|
|
|
|
2021-04-05 08:11:00 +02:00
|
|
|
static struct media_item *impl_from_IMFPMediaItem(IMFPMediaItem *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct media_item, IMFPMediaItem_iface);
|
|
|
|
}
|
|
|
|
|
2021-04-06 09:25:31 +02:00
|
|
|
static struct media_event *impl_event_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct media_event, IUnknown_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_event_QueryInterface(IUnknown *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_event_AddRef(IUnknown *iface)
|
|
|
|
{
|
|
|
|
struct media_event *event = impl_event_from_IUnknown(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&event->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_event_Release(IUnknown *iface)
|
|
|
|
{
|
|
|
|
struct media_event *event = impl_event_from_IUnknown(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&event->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
if (event->u.header.pMediaPlayer)
|
|
|
|
IMFPMediaPlayer_Release(event->u.header.pMediaPlayer);
|
|
|
|
if (event->u.header.pPropertyStore)
|
|
|
|
IPropertyStore_Release(event->u.header.pPropertyStore);
|
|
|
|
|
|
|
|
switch (event->u.header.eEventType)
|
|
|
|
{
|
|
|
|
/* Most types share same layout. */
|
|
|
|
case MFP_EVENT_TYPE_PLAY:
|
|
|
|
case MFP_EVENT_TYPE_PAUSE:
|
|
|
|
case MFP_EVENT_TYPE_STOP:
|
|
|
|
case MFP_EVENT_TYPE_POSITION_SET:
|
|
|
|
case MFP_EVENT_TYPE_RATE_SET:
|
|
|
|
case MFP_EVENT_TYPE_MEDIAITEM_CREATED:
|
|
|
|
case MFP_EVENT_TYPE_MEDIAITEM_SET:
|
|
|
|
case MFP_EVENT_TYPE_FRAME_STEP:
|
|
|
|
case MFP_EVENT_TYPE_MEDIAITEM_CLEARED:
|
|
|
|
case MFP_EVENT_TYPE_PLAYBACK_ENDED:
|
|
|
|
if (event->u.generic.item)
|
|
|
|
IMFPMediaItem_Release(event->u.generic.item);
|
|
|
|
break;
|
|
|
|
case MFP_EVENT_TYPE_MF:
|
|
|
|
if (event->u.event.pMFMediaEvent)
|
|
|
|
IMFMediaEvent_Release(event->u.event.pMFMediaEvent);
|
|
|
|
if (event->u.event.pMediaItem)
|
|
|
|
IMFPMediaItem_Release(event->u.event.pMediaItem);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported event %u.\n", event->u.header.eEventType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:07:07 +02:00
|
|
|
free(event);
|
2021-04-06 09:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IUnknownVtbl media_event_vtbl =
|
|
|
|
{
|
|
|
|
media_event_QueryInterface,
|
|
|
|
media_event_AddRef,
|
|
|
|
media_event_Release,
|
|
|
|
};
|
|
|
|
|
2021-04-07 10:07:01 +02:00
|
|
|
static HRESULT media_event_create(struct media_player *player, MFP_EVENT_TYPE event_type,
|
2021-04-13 08:03:30 +02:00
|
|
|
HRESULT hr, IMFPMediaItem *item, struct media_event **event)
|
2021-04-06 09:25:31 +02:00
|
|
|
{
|
|
|
|
struct media_event *object;
|
|
|
|
|
2021-04-07 10:07:07 +02:00
|
|
|
if (!(object = calloc(1, sizeof(*object))))
|
2021-04-06 09:25:31 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->IUnknown_iface.lpVtbl = &media_event_vtbl;
|
|
|
|
object->refcount = 1;
|
|
|
|
object->u.header.eEventType = event_type;
|
|
|
|
object->u.header.hrEvent = hr;
|
2021-04-07 10:07:01 +02:00
|
|
|
object->u.header.pMediaPlayer = &player->IMFPMediaPlayer_iface;
|
2021-04-06 09:25:31 +02:00
|
|
|
IMFPMediaPlayer_AddRef(object->u.header.pMediaPlayer);
|
2021-04-07 10:07:01 +02:00
|
|
|
object->u.header.eState = player->state;
|
2021-04-13 08:03:30 +02:00
|
|
|
switch (event_type)
|
|
|
|
{
|
|
|
|
case MFP_EVENT_TYPE_PLAY:
|
|
|
|
case MFP_EVENT_TYPE_PAUSE:
|
|
|
|
case MFP_EVENT_TYPE_STOP:
|
|
|
|
case MFP_EVENT_TYPE_POSITION_SET:
|
|
|
|
case MFP_EVENT_TYPE_RATE_SET:
|
|
|
|
case MFP_EVENT_TYPE_MEDIAITEM_CREATED:
|
|
|
|
case MFP_EVENT_TYPE_MEDIAITEM_SET:
|
|
|
|
case MFP_EVENT_TYPE_FRAME_STEP:
|
|
|
|
case MFP_EVENT_TYPE_MEDIAITEM_CLEARED:
|
|
|
|
case MFP_EVENT_TYPE_PLAYBACK_ENDED:
|
|
|
|
object->u.generic.item = item;
|
|
|
|
if (object->u.generic.item)
|
|
|
|
IMFPMediaItem_AddRef(object->u.generic.item);
|
|
|
|
break;
|
|
|
|
case MFP_EVENT_TYPE_MF:
|
|
|
|
object->u.event.pMediaItem = item;
|
|
|
|
if (object->u.event.pMediaItem)
|
|
|
|
IMFPMediaItem_AddRef(object->u.event.pMediaItem);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2021-04-06 09:25:31 +02:00
|
|
|
/* FIXME: set properties for some events? */
|
|
|
|
|
|
|
|
*event = object;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-04-06 09:25:32 +02:00
|
|
|
static LRESULT WINAPI media_player_event_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
|
|
|
struct media_event *event = (void *)lparam;
|
|
|
|
struct media_player *player;
|
|
|
|
|
|
|
|
if (msg == WM_USER)
|
|
|
|
{
|
|
|
|
player = impl_from_IMFPMediaPlayer(event->u.header.pMediaPlayer);
|
|
|
|
if (player->callback)
|
|
|
|
IMFPMediaPlayerCallback_OnMediaPlayerEvent(player->callback, &event->u.header);
|
|
|
|
IUnknown_Release(&event->IUnknown_iface);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProcW(hwnd, msg, wparam, lparam);
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:07:01 +02:00
|
|
|
static void media_player_set_state(struct media_player *player, MFP_MEDIAPLAYER_STATE state)
|
|
|
|
{
|
|
|
|
if (player->state != MFP_MEDIAPLAYER_STATE_SHUTDOWN)
|
|
|
|
{
|
|
|
|
if (state == MFP_MEDIAPLAYER_STATE_SHUTDOWN)
|
|
|
|
IMFMediaSession_Shutdown(player->session);
|
|
|
|
player->state = state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-05 08:11:00 +02:00
|
|
|
static HRESULT WINAPI media_item_QueryInterface(IMFPMediaItem *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IMFPMediaItem) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IMFPMediaItem_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unsupported interface %s.\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_item_AddRef(IMFPMediaItem *iface)
|
|
|
|
{
|
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&item->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_item_Release(IMFPMediaItem *iface)
|
|
|
|
{
|
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&item->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
if (item->player)
|
|
|
|
IMFPMediaPlayer_Release(item->player);
|
|
|
|
if (item->source)
|
|
|
|
IMFMediaSource_Release(item->source);
|
2021-04-06 09:25:26 +02:00
|
|
|
if (item->pd)
|
|
|
|
IMFPresentationDescriptor_Release(item->pd);
|
2021-04-16 14:36:08 +02:00
|
|
|
if (item->object)
|
|
|
|
IUnknown_Release(item->object);
|
2021-04-07 10:07:06 +02:00
|
|
|
free(item->url);
|
2021-04-07 10:07:07 +02:00
|
|
|
free(item);
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_GetMediaPlayer(IMFPMediaItem *iface,
|
|
|
|
IMFPMediaPlayer **player)
|
|
|
|
{
|
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p.\n", iface, player);
|
|
|
|
|
|
|
|
*player = item->player;
|
|
|
|
IMFPMediaPlayer_AddRef(*player);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_GetURL(IMFPMediaItem *iface, LPWSTR *url)
|
|
|
|
{
|
2021-04-07 10:07:06 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-07 10:07:06 +02:00
|
|
|
TRACE("%p, %p.\n", iface, url);
|
|
|
|
|
|
|
|
if (!item->url)
|
|
|
|
return MF_E_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!(*url = CoTaskMemAlloc((wcslen(item->url) + 1) * sizeof(*item->url))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
wcscpy(*url, item->url);
|
|
|
|
|
|
|
|
return S_OK;
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 14:36:08 +02:00
|
|
|
static HRESULT WINAPI media_item_GetObject(IMFPMediaItem *iface, IUnknown **object)
|
2021-04-05 08:11:00 +02:00
|
|
|
{
|
2021-04-16 14:36:08 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-16 14:36:08 +02:00
|
|
|
TRACE("%p, %p.\n", iface, object);
|
|
|
|
|
|
|
|
if (!item->object)
|
|
|
|
return MF_E_NOT_FOUND;
|
|
|
|
|
|
|
|
*object = item->object;
|
|
|
|
IUnknown_AddRef(*object);
|
|
|
|
|
|
|
|
return S_OK;
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_GetUserData(IMFPMediaItem *iface, DWORD_PTR *user_data)
|
|
|
|
{
|
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p.\n", iface, user_data);
|
|
|
|
|
|
|
|
*user_data = item->user_data;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_SetUserData(IMFPMediaItem *iface, DWORD_PTR user_data)
|
|
|
|
{
|
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %lx.\n", iface, user_data);
|
|
|
|
|
|
|
|
item->user_data = user_data;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-06-21 10:43:13 +02:00
|
|
|
static HRESULT media_item_set_position(const GUID *format, const PROPVARIANT *position, LARGE_INTEGER *ret)
|
|
|
|
{
|
|
|
|
ret->QuadPart = 0;
|
|
|
|
|
|
|
|
if (format && !IsEqualGUID(format, &MFP_POSITIONTYPE_100NS))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if ((format != NULL) ^ (position != NULL))
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (position && position->vt != VT_EMPTY && position->vt != VT_I8)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if ((!format && !position) || position->vt == VT_EMPTY)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (position->hVal.QuadPart == 0)
|
|
|
|
return MF_E_OUT_OF_RANGE;
|
|
|
|
|
|
|
|
ret->QuadPart = position->hVal.QuadPart;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void media_item_get_position(LONGLONG value, GUID *format, PROPVARIANT *position)
|
|
|
|
{
|
|
|
|
if (!format)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memcpy(format, &MFP_POSITIONTYPE_100NS, sizeof(*format));
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
position->vt = VT_I8;
|
|
|
|
position->hVal.QuadPart = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-05 08:11:00 +02:00
|
|
|
static HRESULT WINAPI media_item_GetStartStopPosition(IMFPMediaItem *iface, GUID *start_format,
|
|
|
|
PROPVARIANT *start_position, GUID *stop_format, PROPVARIANT *stop_position)
|
|
|
|
{
|
2021-06-21 10:43:13 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p, %p, %p, %p.\n", iface, start_format, start_position, stop_format, stop_position);
|
|
|
|
|
|
|
|
if (start_position)
|
|
|
|
start_position->vt = VT_EMPTY;
|
|
|
|
if (stop_position)
|
|
|
|
stop_position->vt = VT_EMPTY;
|
|
|
|
|
|
|
|
if (((start_format != NULL) ^ (start_position != NULL)) ||
|
|
|
|
((stop_format != NULL) ^ (stop_position != NULL)))
|
|
|
|
{
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
media_item_get_position(item->start_position, start_format, start_position);
|
|
|
|
media_item_get_position(item->stop_position, stop_format, stop_position);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-06-21 10:43:13 +02:00
|
|
|
return S_OK;
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_SetStartStopPosition(IMFPMediaItem *iface, const GUID *start_format,
|
|
|
|
const PROPVARIANT *start_position, const GUID *stop_format, const PROPVARIANT *stop_position)
|
|
|
|
{
|
2021-06-21 10:43:13 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
|
|
|
LARGE_INTEGER start, stop;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %s, %p, %s, %p.\n", iface, debugstr_guid(start_format), start_position,
|
2021-04-05 08:11:00 +02:00
|
|
|
debugstr_guid(stop_format), stop_position);
|
|
|
|
|
2021-06-21 10:43:13 +02:00
|
|
|
hr = media_item_set_position(start_format, start_position, &start);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = media_item_set_position(stop_format, stop_position, &stop);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (start.QuadPart > stop.QuadPart)
|
|
|
|
return MF_E_OUT_OF_RANGE;
|
|
|
|
|
|
|
|
item->start_position = start.QuadPart;
|
|
|
|
item->stop_position = stop.QuadPart;
|
|
|
|
|
|
|
|
return hr;
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
2021-04-21 11:29:44 +02:00
|
|
|
static HRESULT media_item_get_stream_type(IMFStreamDescriptor *sd, GUID *major)
|
|
|
|
{
|
|
|
|
IMFMediaTypeHandler *handler;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = IMFStreamDescriptor_GetMediaTypeHandler(sd, &handler)))
|
|
|
|
{
|
|
|
|
hr = IMFMediaTypeHandler_GetMajorType(handler, major);
|
|
|
|
IMFMediaTypeHandler_Release(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT media_item_has_stream(struct media_item *item, const GUID *major, BOOL *has_stream, BOOL *is_selected)
|
|
|
|
{
|
|
|
|
IMFStreamDescriptor *sd;
|
|
|
|
unsigned int idx = 0;
|
|
|
|
BOOL selected;
|
|
|
|
GUID guid;
|
|
|
|
|
|
|
|
*has_stream = *is_selected = FALSE;
|
|
|
|
|
|
|
|
while (SUCCEEDED(IMFPresentationDescriptor_GetStreamDescriptorByIndex(item->pd, idx++, &selected, &sd)))
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(media_item_get_stream_type(sd, &guid)) && IsEqualGUID(&guid, major))
|
|
|
|
{
|
|
|
|
*has_stream = TRUE;
|
|
|
|
*is_selected = selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMFStreamDescriptor_Release(sd);
|
|
|
|
|
|
|
|
if (*has_stream && *is_selected)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-04-05 08:11:00 +02:00
|
|
|
static HRESULT WINAPI media_item_HasVideo(IMFPMediaItem *iface, BOOL *has_video, BOOL *selected)
|
|
|
|
{
|
2021-04-21 11:29:44 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-21 11:29:44 +02:00
|
|
|
TRACE("%p, %p, %p.\n", iface, has_video, selected);
|
|
|
|
|
|
|
|
return media_item_has_stream(item, &MFMediaType_Video, has_video, selected);
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_HasAudio(IMFPMediaItem *iface, BOOL *has_audio, BOOL *selected)
|
|
|
|
{
|
2021-04-21 11:29:44 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-21 11:29:44 +02:00
|
|
|
TRACE("%p, %p, %p.\n", iface, has_audio, selected);
|
|
|
|
|
|
|
|
return media_item_has_stream(item, &MFMediaType_Audio, has_audio, selected);
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_IsProtected(IMFPMediaItem *iface, BOOL *protected)
|
|
|
|
{
|
2021-04-06 09:25:28 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-06 09:25:28 +02:00
|
|
|
TRACE("%p, %p.\n", iface, protected);
|
|
|
|
|
|
|
|
*protected = MFRequireProtectedEnvironment(item->pd) == S_OK;
|
|
|
|
|
|
|
|
return S_OK;
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_GetDuration(IMFPMediaItem *iface, REFGUID format, PROPVARIANT *value)
|
|
|
|
{
|
2021-04-07 10:07:03 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-07 10:07:03 +02:00
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(format), value);
|
|
|
|
|
|
|
|
return IMFPresentationDescriptor_GetItem(item->pd, &MF_PD_DURATION, value);
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_GetNumberOfStreams(IMFPMediaItem *iface, DWORD *count)
|
|
|
|
{
|
2021-04-06 09:25:27 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-06 09:25:27 +02:00
|
|
|
TRACE("%p, %p.\n", iface, count);
|
|
|
|
|
|
|
|
return IMFPresentationDescriptor_GetStreamDescriptorCount(item->pd, count);
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 09:25:27 +02:00
|
|
|
static HRESULT WINAPI media_item_GetStreamSelection(IMFPMediaItem *iface, DWORD index, BOOL *selected)
|
2021-04-05 08:11:00 +02:00
|
|
|
{
|
2021-04-06 09:25:27 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
|
|
|
IMFStreamDescriptor *sd;
|
|
|
|
HRESULT hr;
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-06 09:25:27 +02:00
|
|
|
TRACE("%p, %u, %p.\n", iface, index, selected);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = IMFPresentationDescriptor_GetStreamDescriptorByIndex(item->pd, index, selected, &sd)))
|
|
|
|
IMFStreamDescriptor_Release(sd);
|
|
|
|
|
|
|
|
return hr;
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 09:25:27 +02:00
|
|
|
static HRESULT WINAPI media_item_SetStreamSelection(IMFPMediaItem *iface, DWORD index, BOOL select)
|
2021-04-05 08:11:00 +02:00
|
|
|
{
|
2021-04-06 09:25:27 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-06 09:25:27 +02:00
|
|
|
TRACE("%p, %u, %d.\n", iface, index, select);
|
|
|
|
|
|
|
|
return select ? IMFPresentationDescriptor_SelectStream(item->pd, index) :
|
|
|
|
IMFPresentationDescriptor_DeselectStream(item->pd, index);
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_GetStreamAttribute(IMFPMediaItem *iface, DWORD index, REFGUID key,
|
|
|
|
PROPVARIANT *value)
|
|
|
|
{
|
2021-04-06 09:25:27 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
|
|
|
IMFStreamDescriptor *sd;
|
|
|
|
BOOL selected;
|
|
|
|
HRESULT hr;
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-06 09:25:27 +02:00
|
|
|
TRACE("%p, %u, %s, %p.\n", iface, index, debugstr_guid(key), value);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = IMFPresentationDescriptor_GetStreamDescriptorByIndex(item->pd, index, &selected, &sd)))
|
|
|
|
{
|
|
|
|
hr = IMFStreamDescriptor_GetItem(sd, key, value);
|
|
|
|
IMFStreamDescriptor_Release(sd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_GetPresentationAttribute(IMFPMediaItem *iface, REFGUID key,
|
|
|
|
PROPVARIANT *value)
|
|
|
|
{
|
2021-04-06 09:25:27 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-06 09:25:27 +02:00
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(key), value);
|
|
|
|
|
|
|
|
return IMFPresentationDescriptor_GetItem(item->pd, key, value);
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_GetCharacteristics(IMFPMediaItem *iface, MFP_MEDIAITEM_CHARACTERISTICS *flags)
|
|
|
|
{
|
2021-04-06 09:25:29 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
|
|
|
HRESULT hr;
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-06 09:25:29 +02:00
|
|
|
TRACE("%p, %p.\n", iface, flags);
|
|
|
|
|
|
|
|
*flags = 0;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = IMFMediaSource_GetCharacteristics(item->source, flags)))
|
|
|
|
{
|
|
|
|
*flags &= (MFP_MEDIAITEM_IS_LIVE | MFP_MEDIAITEM_CAN_SEEK |
|
|
|
|
MFP_MEDIAITEM_CAN_PAUSE | MFP_MEDIAITEM_HAS_SLOW_SEEK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_SetStreamSink(IMFPMediaItem *iface, DWORD index, IUnknown *sink)
|
|
|
|
{
|
2021-04-20 11:06:01 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
|
|
|
IMFStreamDescriptor *sd;
|
|
|
|
IUnknown *sink_object;
|
|
|
|
BOOL selected;
|
|
|
|
HRESULT hr;
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-20 11:06:01 +02:00
|
|
|
TRACE("%p, %u, %p.\n", iface, index, sink);
|
|
|
|
|
|
|
|
if (FAILED(hr = IMFPresentationDescriptor_GetStreamDescriptorByIndex(item->pd, index, &selected, &sd)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (sink)
|
|
|
|
{
|
|
|
|
if (FAILED(hr = IUnknown_QueryInterface(sink, &IID_IMFStreamSink, (void **)&sink_object)))
|
|
|
|
hr = IUnknown_QueryInterface(sink, &IID_IMFActivate, (void **)&sink_object);
|
|
|
|
|
|
|
|
if (sink_object)
|
|
|
|
{
|
|
|
|
hr = IMFStreamDescriptor_SetUnknown(sd, &_MF_CUSTOM_SINK, sink_object);
|
|
|
|
IUnknown_Release(sink_object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
IMFStreamDescriptor_DeleteItem(sd, &_MF_CUSTOM_SINK);
|
|
|
|
|
|
|
|
IMFStreamDescriptor_Release(sd);
|
|
|
|
|
|
|
|
return hr;
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_item_GetMetadata(IMFPMediaItem *iface, IPropertyStore **metadata)
|
|
|
|
{
|
2021-04-07 10:07:05 +02:00
|
|
|
struct media_item *item = impl_from_IMFPMediaItem(iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-07 10:07:05 +02:00
|
|
|
TRACE("%p, %p.\n", iface, metadata);
|
|
|
|
|
|
|
|
return MFGetService((IUnknown *)item->source, &MF_PROPERTY_HANDLER_SERVICE,
|
|
|
|
&IID_IPropertyStore, (void **)&metadata);
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFPMediaItemVtbl media_item_vtbl =
|
|
|
|
{
|
|
|
|
media_item_QueryInterface,
|
|
|
|
media_item_AddRef,
|
|
|
|
media_item_Release,
|
|
|
|
media_item_GetMediaPlayer,
|
|
|
|
media_item_GetURL,
|
|
|
|
media_item_GetObject,
|
|
|
|
media_item_GetUserData,
|
|
|
|
media_item_SetUserData,
|
|
|
|
media_item_GetStartStopPosition,
|
|
|
|
media_item_SetStartStopPosition,
|
|
|
|
media_item_HasVideo,
|
|
|
|
media_item_HasAudio,
|
|
|
|
media_item_IsProtected,
|
|
|
|
media_item_GetDuration,
|
|
|
|
media_item_GetNumberOfStreams,
|
|
|
|
media_item_GetStreamSelection,
|
|
|
|
media_item_SetStreamSelection,
|
|
|
|
media_item_GetStreamAttribute,
|
|
|
|
media_item_GetPresentationAttribute,
|
|
|
|
media_item_GetCharacteristics,
|
|
|
|
media_item_SetStreamSink,
|
|
|
|
media_item_GetMetadata,
|
|
|
|
};
|
|
|
|
|
2021-04-13 08:03:28 +02:00
|
|
|
static struct media_item *unsafe_impl_from_IMFPMediaItem(IMFPMediaItem *iface)
|
|
|
|
{
|
|
|
|
if (!iface)
|
|
|
|
return NULL;
|
|
|
|
assert(iface->lpVtbl == (IMFPMediaItemVtbl *)&media_item_vtbl);
|
|
|
|
return CONTAINING_RECORD(iface, struct media_item, IMFPMediaItem_iface);
|
|
|
|
}
|
|
|
|
|
2021-04-05 08:11:00 +02:00
|
|
|
static HRESULT create_media_item(IMFPMediaPlayer *player, DWORD_PTR user_data, struct media_item **item)
|
|
|
|
{
|
|
|
|
struct media_item *object;
|
|
|
|
|
2021-04-07 10:07:07 +02:00
|
|
|
if (!(object = calloc(1, sizeof(*object))))
|
2021-04-05 08:11:00 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->IMFPMediaItem_iface.lpVtbl = &media_item_vtbl;
|
|
|
|
object->refcount = 1;
|
|
|
|
object->user_data = user_data;
|
|
|
|
object->player = player;
|
|
|
|
IMFPMediaPlayer_AddRef(object->player);
|
|
|
|
|
|
|
|
*item = object;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT media_item_set_source(struct media_item *item, IUnknown *object)
|
|
|
|
{
|
2021-04-06 09:25:26 +02:00
|
|
|
IMFPresentationDescriptor *pd;
|
|
|
|
IMFMediaSource *source;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (FAILED(hr = IUnknown_QueryInterface(object, &IID_IMFMediaSource, (void **)&source)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (FAILED(hr = IMFMediaSource_CreatePresentationDescriptor(source, &pd)))
|
|
|
|
{
|
|
|
|
WARN("Failed to get presentation descriptor, hr %#x.\n", hr);
|
|
|
|
IMFMediaSource_Release(source);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
item->source = source;
|
|
|
|
item->pd = pd;
|
|
|
|
|
|
|
|
return hr;
|
2021-04-05 08:11:00 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 09:25:31 +02:00
|
|
|
static void media_player_queue_event(struct media_player *player, struct media_event *event)
|
|
|
|
{
|
|
|
|
if (player->options & MFP_OPTION_FREE_THREADED_CALLBACK)
|
|
|
|
{
|
|
|
|
MFPutWorkItem(MFASYNC_CALLBACK_QUEUE_MULTITHREADED, &player->events_callback, &event->IUnknown_iface);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-06 09:25:32 +02:00
|
|
|
IUnknown_AddRef(&event->IUnknown_iface);
|
|
|
|
PostMessageW(player->event_window, WM_USER, 0, (LPARAM)event);
|
2021-04-06 09:25:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-01 22:22:57 +02:00
|
|
|
static HRESULT WINAPI media_player_QueryInterface(IMFPMediaPlayer *iface, REFIID riid, void **obj)
|
|
|
|
{
|
2021-04-05 08:10:59 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
|
2021-04-01 22:22:57 +02:00
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IMFPMediaPlayer) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
2021-04-05 08:10:59 +02:00
|
|
|
*obj = &player->IMFPMediaPlayer_iface;
|
|
|
|
}
|
|
|
|
else if (IsEqualIID(riid, &IID_IPropertyStore))
|
|
|
|
{
|
|
|
|
*obj = &player->IPropertyStore_iface;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
2021-04-05 08:10:59 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Unsupported interface %s.\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-05 08:10:59 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-05 08:10:59 +02:00
|
|
|
IUnknown_AddRef((IUnknown *)*obj);
|
|
|
|
return S_OK;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_player_AddRef(IMFPMediaPlayer *iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&player->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_player_Release(IMFPMediaPlayer *iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&player->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
2021-04-05 08:10:57 +02:00
|
|
|
{
|
|
|
|
if (player->callback)
|
|
|
|
IMFPMediaPlayerCallback_Release(player->callback);
|
2021-04-05 08:10:59 +02:00
|
|
|
if (player->propstore)
|
|
|
|
IPropertyStore_Release(player->propstore);
|
2021-04-05 08:11:00 +02:00
|
|
|
if (player->resolver)
|
|
|
|
IMFSourceResolver_Release(player->resolver);
|
2021-04-07 10:07:00 +02:00
|
|
|
if (player->session)
|
|
|
|
IMFMediaSession_Release(player->session);
|
2021-04-06 09:25:32 +02:00
|
|
|
DestroyWindow(player->event_window);
|
2021-04-07 10:07:01 +02:00
|
|
|
DeleteCriticalSection(&player->cs);
|
2021-04-07 10:07:07 +02:00
|
|
|
free(player);
|
2021-04-05 08:10:58 +02:00
|
|
|
|
|
|
|
platform_shutdown();
|
2021-04-05 08:10:57 +02:00
|
|
|
}
|
2021-04-01 22:22:57 +02:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_Play(IMFPMediaPlayer *iface)
|
|
|
|
{
|
2021-04-07 10:07:02 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
PROPVARIANT pos;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-07 10:07:02 +02:00
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
pos.vt = VT_EMPTY;
|
|
|
|
return IMFMediaSession_Start(player->session, &GUID_NULL, &pos);
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_Pause(IMFPMediaPlayer *iface)
|
|
|
|
{
|
2021-04-07 10:07:02 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-07 10:07:02 +02:00
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
return IMFMediaSession_Pause(player->session);
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_Stop(IMFPMediaPlayer *iface)
|
|
|
|
{
|
2021-04-07 10:07:02 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-07 10:07:02 +02:00
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
return IMFMediaSession_Stop(player->session);
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_FrameStep(IMFPMediaPlayer *iface)
|
|
|
|
{
|
|
|
|
FIXME("%p.\n", iface);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_SetPosition(IMFPMediaPlayer *iface, REFGUID postype, const PROPVARIANT *position)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %p.\n", iface, debugstr_guid(postype), position);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetPosition(IMFPMediaPlayer *iface, REFGUID postype, PROPVARIANT *position)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %p.\n", iface, debugstr_guid(postype), position);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetDuration(IMFPMediaPlayer *iface, REFGUID postype, PROPVARIANT *position)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %p.\n", iface, debugstr_guid(postype), position);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_SetRate(IMFPMediaPlayer *iface, float rate)
|
|
|
|
{
|
|
|
|
FIXME("%p, %f.\n", iface, rate);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetRate(IMFPMediaPlayer *iface, float *rate)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, rate);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:07:04 +02:00
|
|
|
static HRESULT WINAPI media_player_GetSupportedRates(IMFPMediaPlayer *iface, BOOL forward,
|
|
|
|
float *slowest_rate, float *fastest_rate)
|
2021-04-01 22:22:57 +02:00
|
|
|
{
|
2021-04-07 10:07:04 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
IMFRateSupport *rs;
|
|
|
|
HRESULT hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-07 10:07:04 +02:00
|
|
|
TRACE("%p, %d, %p, %p.\n", iface, forward, slowest_rate, fastest_rate);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = MFGetService((IUnknown *)player->session, &MF_RATE_CONTROL_SERVICE, &IID_IMFRateSupport, (void **)&rs)))
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(hr = IMFRateSupport_GetSlowestRate(rs, forward ? MFRATE_FORWARD : MFRATE_REVERSE, FALSE, slowest_rate)))
|
|
|
|
hr = IMFRateSupport_GetFastestRate(rs, forward ? MFRATE_FORWARD : MFRATE_REVERSE, FALSE, fastest_rate);
|
|
|
|
IMFRateSupport_Release(rs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetState(IMFPMediaPlayer *iface, MFP_MEDIAPLAYER_STATE *state)
|
|
|
|
{
|
2021-04-07 10:07:01 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-07 10:07:01 +02:00
|
|
|
TRACE("%p, %p.\n", iface, state);
|
|
|
|
|
|
|
|
*state = player->state;
|
|
|
|
|
|
|
|
return S_OK;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-13 08:03:31 +02:00
|
|
|
static HRESULT media_player_create_item_from_url(struct media_player *player,
|
2021-04-05 08:11:00 +02:00
|
|
|
const WCHAR *url, BOOL sync, DWORD_PTR user_data, IMFPMediaItem **ret)
|
2021-04-01 22:22:57 +02:00
|
|
|
{
|
2021-04-05 08:11:00 +02:00
|
|
|
struct media_item *item;
|
|
|
|
MF_OBJECT_TYPE obj_type;
|
|
|
|
IUnknown *object;
|
|
|
|
HRESULT hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-13 08:03:31 +02:00
|
|
|
*ret = NULL;
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-13 08:03:31 +02:00
|
|
|
if (FAILED(hr = create_media_item(&player->IMFPMediaPlayer_iface, user_data, &item)))
|
2021-04-05 08:11:00 +02:00
|
|
|
return hr;
|
|
|
|
|
2021-04-07 10:07:06 +02:00
|
|
|
if (url && !(item->url = wcsdup(url)))
|
|
|
|
{
|
|
|
|
IMFPMediaItem_Release(&item->IMFPMediaItem_iface);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2021-04-05 08:11:00 +02:00
|
|
|
if (sync)
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(hr = IMFSourceResolver_CreateObjectFromURL(player->resolver, url, MF_RESOLUTION_MEDIASOURCE,
|
|
|
|
player->propstore, &obj_type, &object)))
|
|
|
|
{
|
|
|
|
hr = media_item_set_source(item, object);
|
|
|
|
IUnknown_Release(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2021-04-13 08:03:33 +02:00
|
|
|
{
|
2021-04-05 08:11:00 +02:00
|
|
|
*ret = &item->IMFPMediaItem_iface;
|
2021-04-13 08:03:33 +02:00
|
|
|
IMFPMediaItem_AddRef(*ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMFPMediaItem_Release(&item->IMFPMediaItem_iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = IMFSourceResolver_BeginCreateObjectFromURL(player->resolver, url, MF_RESOLUTION_MEDIASOURCE,
|
|
|
|
player->propstore, NULL, &player->resolver_callback, (IUnknown *)&item->IMFPMediaItem_iface);
|
|
|
|
|
|
|
|
IMFPMediaItem_Release(&item->IMFPMediaItem_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-13 08:03:31 +02:00
|
|
|
static HRESULT WINAPI media_player_CreateMediaItemFromURL(IMFPMediaPlayer *iface,
|
2021-04-16 14:36:08 +02:00
|
|
|
const WCHAR *url, BOOL sync, DWORD_PTR user_data, IMFPMediaItem **item)
|
2021-04-13 08:03:31 +02:00
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
2021-04-16 14:36:08 +02:00
|
|
|
TRACE("%p, %s, %d, %lx, %p.\n", iface, debugstr_w(url), sync, user_data, item);
|
2021-04-13 08:03:31 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(&player->cs);
|
|
|
|
if (player->state == MFP_MEDIAPLAYER_STATE_SHUTDOWN)
|
|
|
|
hr = MF_E_SHUTDOWN;
|
|
|
|
else
|
2021-04-16 14:36:08 +02:00
|
|
|
hr = media_player_create_item_from_url(player, url, sync, user_data, item);
|
2021-04-13 08:03:31 +02:00
|
|
|
LeaveCriticalSection(&player->cs);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-04-16 14:36:08 +02:00
|
|
|
static HRESULT media_player_create_item_from_object(struct media_player *player,
|
|
|
|
IUnknown *object, BOOL sync, DWORD_PTR user_data, IMFPMediaItem **ret)
|
|
|
|
{
|
|
|
|
struct media_item *item;
|
|
|
|
MF_OBJECT_TYPE obj_type;
|
|
|
|
HRESULT hr;
|
|
|
|
IMFByteStream *stream = NULL;
|
|
|
|
IMFMediaSource *source = NULL;
|
|
|
|
|
|
|
|
*ret = NULL;
|
|
|
|
|
|
|
|
if (FAILED(hr = create_media_item(&player->IMFPMediaPlayer_iface, user_data, &item)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
item->object = object;
|
|
|
|
IUnknown_AddRef(item->object);
|
|
|
|
|
|
|
|
if (FAILED(IUnknown_QueryInterface(object, &IID_IMFMediaSource, (void **)&source)))
|
|
|
|
IUnknown_QueryInterface(object, &IID_IMFByteStream, (void **)&stream);
|
|
|
|
|
|
|
|
if (!source && !stream)
|
|
|
|
{
|
|
|
|
WARN("Unsupported object type.\n");
|
|
|
|
IMFPMediaItem_Release(&item->IMFPMediaItem_iface);
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sync)
|
|
|
|
{
|
|
|
|
if (stream)
|
|
|
|
hr = IMFSourceResolver_CreateObjectFromByteStream(player->resolver, stream, NULL,
|
|
|
|
MF_RESOLUTION_MEDIASOURCE, player->propstore, &obj_type, &object);
|
|
|
|
else
|
|
|
|
IUnknown_AddRef(object);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = media_item_set_source(item, object);
|
|
|
|
|
|
|
|
IUnknown_Release(object);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
*ret = &item->IMFPMediaItem_iface;
|
|
|
|
IMFPMediaItem_AddRef(*ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMFPMediaItem_Release(&item->IMFPMediaItem_iface);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (stream)
|
|
|
|
{
|
|
|
|
hr = IMFSourceResolver_BeginCreateObjectFromByteStream(player->resolver, stream, NULL, MF_RESOLUTION_MEDIASOURCE,
|
|
|
|
player->propstore, NULL, &player->resolver_callback, (IUnknown *)&item->IMFPMediaItem_iface);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Resolver callback will check again if item's object is a source. */
|
|
|
|
hr = MFPutWorkItem(MFASYNC_CALLBACK_QUEUE_MULTITHREADED, &player->resolver_callback,
|
|
|
|
(IUnknown *)&item->IMFPMediaItem_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMFPMediaItem_Release(&item->IMFPMediaItem_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source)
|
|
|
|
IMFMediaSource_Release(source);
|
|
|
|
if (stream)
|
|
|
|
IMFByteStream_Release(stream);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-04-01 22:22:57 +02:00
|
|
|
static HRESULT WINAPI media_player_CreateMediaItemFromObject(IMFPMediaPlayer *iface,
|
|
|
|
IUnknown *object, BOOL sync, DWORD_PTR user_data, IMFPMediaItem **item)
|
|
|
|
{
|
2021-04-16 14:36:08 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
HRESULT hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-16 14:36:08 +02:00
|
|
|
TRACE("%p, %p, %d, %lx, %p.\n", iface, object, sync, user_data, item);
|
|
|
|
|
|
|
|
EnterCriticalSection(&player->cs);
|
|
|
|
if (player->state == MFP_MEDIAPLAYER_STATE_SHUTDOWN)
|
|
|
|
hr = MF_E_SHUTDOWN;
|
|
|
|
else
|
|
|
|
hr = media_player_create_item_from_object(player, object, sync, user_data, item);
|
|
|
|
LeaveCriticalSection(&player->cs);
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-21 11:29:42 +02:00
|
|
|
static HRESULT media_item_create_source_node(struct media_item *item, IMFStreamDescriptor *sd,
|
|
|
|
IMFTopologyNode **node)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, node)))
|
|
|
|
{
|
|
|
|
IMFTopologyNode_SetUnknown(*node, &MF_TOPONODE_SOURCE, (IUnknown *)item->source);
|
|
|
|
IMFTopologyNode_SetUnknown(*node, &MF_TOPONODE_PRESENTATION_DESCRIPTOR, (IUnknown *)item->pd);
|
|
|
|
IMFTopologyNode_SetUnknown(*node, &MF_TOPONODE_STREAM_DESCRIPTOR, (IUnknown *)sd);
|
2021-06-21 10:43:14 +02:00
|
|
|
if (item->start_position)
|
|
|
|
IMFTopologyNode_SetUINT64(*node, &MF_TOPONODE_MEDIASTART, item->start_position);
|
|
|
|
if (item->stop_position)
|
|
|
|
IMFTopologyNode_SetUINT64(*node, &MF_TOPONODE_MEDIASTOP, item->stop_position);
|
2021-04-21 11:29:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT media_item_create_sink_node(IUnknown *sink, IMFTopologyNode **node)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = MFCreateTopologyNode(MF_TOPOLOGY_OUTPUT_NODE, node)))
|
|
|
|
IMFTopologyNode_SetObject(*node, sink);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-04-13 08:03:28 +02:00
|
|
|
static HRESULT media_item_create_topology(struct media_player *player, struct media_item *item, IMFTopology **out)
|
|
|
|
{
|
|
|
|
IMFTopologyNode *src_node, *sink_node;
|
2021-04-21 11:29:43 +02:00
|
|
|
BOOL selected, video_added = FALSE;
|
2021-04-13 08:03:28 +02:00
|
|
|
IMFStreamDescriptor *sd;
|
|
|
|
IMFTopology *topology;
|
|
|
|
unsigned int idx;
|
2021-04-21 11:29:42 +02:00
|
|
|
IUnknown *sink;
|
2021-04-13 08:03:28 +02:00
|
|
|
HRESULT hr;
|
|
|
|
GUID major;
|
|
|
|
|
|
|
|
if (FAILED(hr = MFCreateTopology(&topology)))
|
|
|
|
return hr;
|
|
|
|
|
2021-04-21 11:29:42 +02:00
|
|
|
/* Set up branches for all selected streams. */
|
2021-04-13 08:03:28 +02:00
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
while (SUCCEEDED(IMFPresentationDescriptor_GetStreamDescriptorByIndex(item->pd, idx++, &selected, &sd)))
|
|
|
|
{
|
2021-04-21 11:29:43 +02:00
|
|
|
if (!selected || FAILED(media_item_get_stream_type(sd, &major)))
|
2021-04-13 08:03:28 +02:00
|
|
|
{
|
2021-04-21 11:29:42 +02:00
|
|
|
IMFStreamDescriptor_Release(sd);
|
|
|
|
continue;
|
|
|
|
}
|
2021-04-13 08:03:28 +02:00
|
|
|
|
2021-04-21 11:29:42 +02:00
|
|
|
sink = NULL;
|
2021-04-13 08:03:28 +02:00
|
|
|
|
2021-04-21 11:29:42 +02:00
|
|
|
if (SUCCEEDED(IMFStreamDescriptor_GetUnknown(sd, &_MF_CUSTOM_SINK, &IID_IUnknown, (void **)&sink)))
|
|
|
|
{
|
|
|
|
/* User sink is attached as-is. */
|
|
|
|
}
|
2021-04-21 11:29:43 +02:00
|
|
|
else if (IsEqualGUID(&major, &MFMediaType_Audio))
|
2021-04-21 11:29:42 +02:00
|
|
|
{
|
|
|
|
if (FAILED(hr = MFCreateAudioRendererActivate((IMFActivate **)&sink)))
|
|
|
|
WARN("Failed to create SAR activation object, hr %#x.\n", hr);
|
|
|
|
}
|
2021-04-21 11:29:43 +02:00
|
|
|
else if (IsEqualGUID(&major, &MFMediaType_Video) && player->output_window && !video_added)
|
|
|
|
{
|
|
|
|
if (FAILED(hr = MFCreateVideoRendererActivate(player->output_window, (IMFActivate **)&sink)))
|
|
|
|
WARN("Failed to create EVR activation object, hr %#x.\n", hr);
|
|
|
|
video_added = SUCCEEDED(hr);
|
|
|
|
}
|
2021-04-13 08:03:28 +02:00
|
|
|
|
2021-04-21 11:29:42 +02:00
|
|
|
if (sink)
|
|
|
|
{
|
|
|
|
hr = media_item_create_source_node(item, sd, &src_node);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = media_item_create_sink_node(sink, &sink_node);
|
2021-04-13 08:03:28 +02:00
|
|
|
|
2021-04-21 11:29:42 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
IMFTopology_AddNode(topology, src_node);
|
|
|
|
IMFTopology_AddNode(topology, sink_node);
|
2021-04-13 08:03:28 +02:00
|
|
|
IMFTopologyNode_ConnectOutput(src_node, 0, sink_node, 0);
|
2021-04-21 11:29:42 +02:00
|
|
|
}
|
2021-04-13 08:03:28 +02:00
|
|
|
|
|
|
|
if (src_node)
|
|
|
|
IMFTopologyNode_Release(src_node);
|
|
|
|
if (sink_node)
|
|
|
|
IMFTopologyNode_Release(sink_node);
|
2021-04-21 11:29:42 +02:00
|
|
|
|
|
|
|
IUnknown_Release(sink);
|
2021-04-13 08:03:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IMFStreamDescriptor_Release(sd);
|
|
|
|
}
|
|
|
|
|
2021-05-28 15:17:06 +02:00
|
|
|
IMFTopology_SetUINT32(topology, &MF_TOPOLOGY_ENUMERATE_SOURCE_TYPES, TRUE);
|
|
|
|
|
2021-04-13 08:03:28 +02:00
|
|
|
*out = topology;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_SetMediaItem(IMFPMediaPlayer *iface, IMFPMediaItem *item_iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
struct media_item *item = unsafe_impl_from_IMFPMediaItem(item_iface);
|
|
|
|
IMFTopology *topology;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %p.\n", iface, item_iface);
|
|
|
|
|
|
|
|
if (item->player != iface)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (FAILED(hr = media_item_create_topology(player, item, &topology)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
IMFTopology_SetUnknown(topology, &_MF_TOPO_MEDIA_ITEM, (IUnknown *)item_iface);
|
|
|
|
hr = IMFMediaSession_SetTopology(player->session, MFSESSION_SETTOPOLOGY_IMMEDIATE, topology);
|
|
|
|
IMFTopology_Release(topology);
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_ClearMediaItem(IMFPMediaPlayer *iface)
|
|
|
|
{
|
2021-04-13 08:03:30 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-13 08:03:30 +02:00
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
return IMFMediaSession_SetTopology(player->session, MFSESSION_SETTOPOLOGY_CLEAR_CURRENT, NULL);
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetMediaItem(IMFPMediaPlayer *iface, IMFPMediaItem **item)
|
|
|
|
{
|
2021-04-13 08:03:30 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
HRESULT hr = S_OK;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-13 08:03:30 +02:00
|
|
|
TRACE("%p, %p.\n", iface, item);
|
|
|
|
|
|
|
|
if (!item)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
EnterCriticalSection(&player->cs);
|
2021-04-13 08:03:32 +02:00
|
|
|
if (player->state == MFP_MEDIAPLAYER_STATE_SHUTDOWN)
|
|
|
|
hr = MF_E_SHUTDOWN;
|
|
|
|
else if (!player->item)
|
2021-04-13 08:03:30 +02:00
|
|
|
hr = MF_E_NOT_FOUND;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*item = player->item;
|
|
|
|
IMFPMediaItem_AddRef(player->item);
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&player->cs);
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetVolume(IMFPMediaPlayer *iface, float *volume)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, volume);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_SetVolume(IMFPMediaPlayer *iface, float volume)
|
|
|
|
{
|
|
|
|
FIXME("%p, %.8e.\n", iface, volume);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetBalance(IMFPMediaPlayer *iface, float *balance)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, balance);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_SetBalance(IMFPMediaPlayer *iface, float balance)
|
|
|
|
{
|
|
|
|
FIXME("%p, %.8e.\n", iface, balance);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetMute(IMFPMediaPlayer *iface, BOOL *mute)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, mute);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_SetMute(IMFPMediaPlayer *iface, BOOL mute)
|
|
|
|
{
|
|
|
|
FIXME("%p, %d.\n", iface, mute);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetNativeVideoSize(IMFPMediaPlayer *iface,
|
|
|
|
SIZE *video, SIZE *arvideo)
|
|
|
|
{
|
2021-04-21 11:29:49 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
IMFVideoDisplayControl *display_control;
|
|
|
|
HRESULT hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-21 11:29:49 +02:00
|
|
|
TRACE("%p, %p, %p.\n", iface, video, arvideo);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = MFGetService((IUnknown *)player->session, &MR_VIDEO_RENDER_SERVICE,
|
|
|
|
&IID_IMFVideoDisplayControl, (void **)&display_control)))
|
|
|
|
{
|
|
|
|
hr = IMFVideoDisplayControl_GetNativeVideoSize(display_control, video, arvideo);
|
|
|
|
IMFVideoDisplayControl_Release(display_control);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetIdealVideoSize(IMFPMediaPlayer *iface,
|
|
|
|
SIZE *min_size, SIZE *max_size)
|
|
|
|
{
|
2021-04-21 11:29:45 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
IMFVideoDisplayControl *display_control;
|
|
|
|
HRESULT hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-21 11:29:45 +02:00
|
|
|
TRACE("%p, %p, %p.\n", iface, min_size, max_size);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = MFGetService((IUnknown *)player->session, &MR_VIDEO_RENDER_SERVICE,
|
|
|
|
&IID_IMFVideoDisplayControl, (void **)&display_control)))
|
|
|
|
{
|
|
|
|
hr = IMFVideoDisplayControl_GetIdealVideoSize(display_control, min_size, max_size);
|
|
|
|
IMFVideoDisplayControl_Release(display_control);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_SetVideoSourceRect(IMFPMediaPlayer *iface,
|
|
|
|
MFVideoNormalizedRect const *rect)
|
|
|
|
{
|
2021-04-21 11:29:46 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
IMFVideoDisplayControl *display_control;
|
|
|
|
HRESULT hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-21 11:29:46 +02:00
|
|
|
TRACE("%p, %p.\n", iface, rect);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = MFGetService((IUnknown *)player->session, &MR_VIDEO_RENDER_SERVICE,
|
|
|
|
&IID_IMFVideoDisplayControl, (void **)&display_control)))
|
|
|
|
{
|
|
|
|
hr = IMFVideoDisplayControl_SetVideoPosition(display_control, rect, NULL);
|
|
|
|
IMFVideoDisplayControl_Release(display_control);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetVideoSourceRect(IMFPMediaPlayer *iface,
|
|
|
|
MFVideoNormalizedRect *rect)
|
|
|
|
{
|
2021-04-21 11:29:46 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
IMFVideoDisplayControl *display_control;
|
|
|
|
HRESULT hr;
|
|
|
|
RECT dest;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-21 11:29:46 +02:00
|
|
|
TRACE("%p, %p.\n", iface, rect);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = MFGetService((IUnknown *)player->session, &MR_VIDEO_RENDER_SERVICE,
|
|
|
|
&IID_IMFVideoDisplayControl, (void **)&display_control)))
|
|
|
|
{
|
|
|
|
hr = IMFVideoDisplayControl_GetVideoPosition(display_control, rect, &dest);
|
|
|
|
IMFVideoDisplayControl_Release(display_control);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_SetAspectRatioMode(IMFPMediaPlayer *iface, DWORD mode)
|
|
|
|
{
|
2021-04-21 11:29:47 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
IMFVideoDisplayControl *display_control;
|
|
|
|
HRESULT hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-21 11:29:47 +02:00
|
|
|
TRACE("%p, %u.\n", iface, mode);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = MFGetService((IUnknown *)player->session, &MR_VIDEO_RENDER_SERVICE,
|
|
|
|
&IID_IMFVideoDisplayControl, (void **)&display_control)))
|
|
|
|
{
|
|
|
|
hr = IMFVideoDisplayControl_SetAspectRatioMode(display_control, mode);
|
|
|
|
IMFVideoDisplayControl_Release(display_control);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetAspectRatioMode(IMFPMediaPlayer *iface,
|
|
|
|
DWORD *mode)
|
|
|
|
{
|
2021-04-21 11:29:47 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
IMFVideoDisplayControl *display_control;
|
|
|
|
HRESULT hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-21 11:29:47 +02:00
|
|
|
TRACE("%p, %p.\n", iface, mode);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = MFGetService((IUnknown *)player->session, &MR_VIDEO_RENDER_SERVICE,
|
|
|
|
&IID_IMFVideoDisplayControl, (void **)&display_control)))
|
|
|
|
{
|
|
|
|
hr = IMFVideoDisplayControl_GetAspectRatioMode(display_control, mode);
|
|
|
|
IMFVideoDisplayControl_Release(display_control);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 10:06:59 +02:00
|
|
|
static HRESULT WINAPI media_player_GetVideoWindow(IMFPMediaPlayer *iface, HWND *window)
|
2021-04-01 22:22:57 +02:00
|
|
|
{
|
2021-04-07 10:06:59 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-07 10:06:59 +02:00
|
|
|
TRACE("%p, %p.\n", iface, window);
|
|
|
|
|
|
|
|
*window = player->output_window;
|
|
|
|
|
|
|
|
return S_OK;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_UpdateVideo(IMFPMediaPlayer *iface)
|
|
|
|
{
|
|
|
|
FIXME("%p.\n", iface);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_SetBorderColor(IMFPMediaPlayer *iface, COLORREF color)
|
|
|
|
{
|
2021-04-21 11:29:48 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
IMFVideoDisplayControl *display_control;
|
|
|
|
HRESULT hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-21 11:29:48 +02:00
|
|
|
TRACE("%p, %#x.\n", iface, color);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = MFGetService((IUnknown *)player->session, &MR_VIDEO_RENDER_SERVICE,
|
|
|
|
&IID_IMFVideoDisplayControl, (void **)&display_control)))
|
|
|
|
{
|
|
|
|
hr = IMFVideoDisplayControl_SetBorderColor(display_control, color);
|
|
|
|
IMFVideoDisplayControl_Release(display_control);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_GetBorderColor(IMFPMediaPlayer *iface, COLORREF *color)
|
|
|
|
{
|
2021-04-21 11:29:48 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
|
|
|
IMFVideoDisplayControl *display_control;
|
|
|
|
HRESULT hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-21 11:29:48 +02:00
|
|
|
TRACE("%p, %p.\n", iface, color);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = MFGetService((IUnknown *)player->session, &MR_VIDEO_RENDER_SERVICE,
|
|
|
|
&IID_IMFVideoDisplayControl, (void **)&display_control)))
|
|
|
|
{
|
|
|
|
hr = IMFVideoDisplayControl_GetBorderColor(display_control, color);
|
|
|
|
IMFVideoDisplayControl_Release(display_control);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_InsertEffect(IMFPMediaPlayer *iface, IUnknown *effect,
|
|
|
|
BOOL optional)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p, %d.\n", iface, effect, optional);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_RemoveEffect(IMFPMediaPlayer *iface, IUnknown *effect)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, effect);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_RemoveAllEffects(IMFPMediaPlayer *iface)
|
|
|
|
{
|
|
|
|
FIXME("%p.\n", iface);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_Shutdown(IMFPMediaPlayer *iface)
|
|
|
|
{
|
2021-04-07 10:07:01 +02:00
|
|
|
struct media_player *player = impl_from_IMFPMediaPlayer(iface);
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-04-07 10:07:01 +02:00
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
EnterCriticalSection(&player->cs);
|
|
|
|
media_player_set_state(player, MFP_MEDIAPLAYER_STATE_SHUTDOWN);
|
2021-04-13 08:03:30 +02:00
|
|
|
if (player->item)
|
|
|
|
{
|
|
|
|
IMFPMediaItem_Release(player->item);
|
|
|
|
player->item = NULL;
|
|
|
|
}
|
2021-04-07 10:07:01 +02:00
|
|
|
LeaveCriticalSection(&player->cs);
|
|
|
|
|
|
|
|
return S_OK;
|
2021-04-01 22:22:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFPMediaPlayerVtbl media_player_vtbl =
|
|
|
|
{
|
|
|
|
media_player_QueryInterface,
|
|
|
|
media_player_AddRef,
|
|
|
|
media_player_Release,
|
|
|
|
media_player_Play,
|
|
|
|
media_player_Pause,
|
|
|
|
media_player_Stop,
|
|
|
|
media_player_FrameStep,
|
|
|
|
media_player_SetPosition,
|
|
|
|
media_player_GetPosition,
|
|
|
|
media_player_GetDuration,
|
|
|
|
media_player_SetRate,
|
|
|
|
media_player_GetRate,
|
|
|
|
media_player_GetSupportedRates,
|
|
|
|
media_player_GetState,
|
|
|
|
media_player_CreateMediaItemFromURL,
|
|
|
|
media_player_CreateMediaItemFromObject,
|
|
|
|
media_player_SetMediaItem,
|
|
|
|
media_player_ClearMediaItem,
|
|
|
|
media_player_GetMediaItem,
|
|
|
|
media_player_GetVolume,
|
|
|
|
media_player_SetVolume,
|
|
|
|
media_player_GetBalance,
|
|
|
|
media_player_SetBalance,
|
|
|
|
media_player_GetMute,
|
|
|
|
media_player_SetMute,
|
|
|
|
media_player_GetNativeVideoSize,
|
|
|
|
media_player_GetIdealVideoSize,
|
|
|
|
media_player_SetVideoSourceRect,
|
|
|
|
media_player_GetVideoSourceRect,
|
|
|
|
media_player_SetAspectRatioMode,
|
|
|
|
media_player_GetAspectRatioMode,
|
|
|
|
media_player_GetVideoWindow,
|
|
|
|
media_player_UpdateVideo,
|
|
|
|
media_player_SetBorderColor,
|
|
|
|
media_player_GetBorderColor,
|
|
|
|
media_player_InsertEffect,
|
|
|
|
media_player_RemoveEffect,
|
|
|
|
media_player_RemoveAllEffects,
|
|
|
|
media_player_Shutdown,
|
|
|
|
};
|
|
|
|
|
2021-04-05 08:10:59 +02:00
|
|
|
static HRESULT WINAPI media_player_propstore_QueryInterface(IPropertyStore *iface,
|
|
|
|
REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IPropertyStore(iface);
|
|
|
|
return IMFPMediaPlayer_QueryInterface(&player->IMFPMediaPlayer_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_player_propstore_AddRef(IPropertyStore *iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IPropertyStore(iface);
|
|
|
|
return IMFPMediaPlayer_AddRef(&player->IMFPMediaPlayer_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_player_propstore_Release(IPropertyStore *iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IPropertyStore(iface);
|
|
|
|
return IMFPMediaPlayer_Release(&player->IMFPMediaPlayer_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_propstore_GetCount(IPropertyStore *iface, DWORD *count)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IPropertyStore(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p.\n", iface, count);
|
|
|
|
|
|
|
|
return IPropertyStore_GetCount(player->propstore, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_propstore_GetAt(IPropertyStore *iface, DWORD prop, PROPERTYKEY *key)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IPropertyStore(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %u, %p.\n", iface, prop, key);
|
|
|
|
|
|
|
|
return IPropertyStore_GetAt(player->propstore, prop, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_propstore_GetValue(IPropertyStore *iface, REFPROPERTYKEY key, PROPVARIANT *value)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IPropertyStore(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p, %p.\n", iface, key, value);
|
|
|
|
|
|
|
|
return IPropertyStore_GetValue(player->propstore, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_propstore_SetValue(IPropertyStore *iface, REFPROPERTYKEY key, REFPROPVARIANT value)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IPropertyStore(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p, %p.\n", iface, key, value);
|
|
|
|
|
|
|
|
return IPropertyStore_SetValue(player->propstore, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_propstore_Commit(IPropertyStore *iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_IPropertyStore(iface);
|
|
|
|
|
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
return IPropertyStore_Commit(player->propstore);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IPropertyStoreVtbl media_player_propstore_vtbl =
|
|
|
|
{
|
|
|
|
media_player_propstore_QueryInterface,
|
|
|
|
media_player_propstore_AddRef,
|
|
|
|
media_player_propstore_Release,
|
|
|
|
media_player_propstore_GetCount,
|
|
|
|
media_player_propstore_GetAt,
|
|
|
|
media_player_propstore_GetValue,
|
|
|
|
media_player_propstore_SetValue,
|
|
|
|
media_player_propstore_Commit,
|
|
|
|
};
|
|
|
|
|
2021-04-06 09:25:31 +02:00
|
|
|
static HRESULT WINAPI media_player_callback_QueryInterface(IMFAsyncCallback *iface,
|
2021-04-05 08:11:00 +02:00
|
|
|
REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, &IID_IMFAsyncCallback) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IMFAsyncCallback_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_player_resolver_callback_AddRef(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_resolver_IMFAsyncCallback(iface);
|
|
|
|
return IMFPMediaPlayer_AddRef(&player->IMFPMediaPlayer_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_player_resolver_callback_Release(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_resolver_IMFAsyncCallback(iface);
|
|
|
|
return IMFPMediaPlayer_Release(&player->IMFPMediaPlayer_iface);
|
|
|
|
}
|
|
|
|
|
2021-04-06 09:25:31 +02:00
|
|
|
static HRESULT WINAPI media_player_callback_GetParameters(IMFAsyncCallback *iface, DWORD *flags,
|
2021-04-05 08:11:00 +02:00
|
|
|
DWORD *queue)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_resolver_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_resolver_IMFAsyncCallback(iface);
|
2021-04-06 09:25:31 +02:00
|
|
|
struct media_event *event;
|
2021-04-05 08:11:00 +02:00
|
|
|
IUnknown *object, *state;
|
|
|
|
MF_OBJECT_TYPE obj_type;
|
2021-04-06 09:25:31 +02:00
|
|
|
struct media_item *item;
|
2021-04-05 08:11:00 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (FAILED(IMFAsyncResult_GetState(result, &state)))
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
item = impl_from_IMFPMediaItem((IMFPMediaItem *)state);
|
|
|
|
|
2021-04-16 14:36:08 +02:00
|
|
|
if (item->object)
|
|
|
|
{
|
|
|
|
if (FAILED(hr = IUnknown_QueryInterface(item->object, &IID_IMFMediaSource, (void **)&object)))
|
|
|
|
hr = IMFSourceResolver_EndCreateObjectFromByteStream(player->resolver, result, &obj_type, &object);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = IMFSourceResolver_EndCreateObjectFromURL(player->resolver, result, &obj_type, &object);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2021-04-05 08:11:00 +02:00
|
|
|
{
|
|
|
|
hr = media_item_set_source(item, object);
|
|
|
|
IUnknown_Release(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
WARN("Failed to set media source, hr %#x.\n", hr);
|
|
|
|
|
2021-04-13 08:03:30 +02:00
|
|
|
if (FAILED(media_event_create(player, MFP_EVENT_TYPE_MEDIAITEM_CREATED, hr,
|
|
|
|
&item->IMFPMediaItem_iface, &event)))
|
2021-04-06 09:25:31 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to create event object.\n");
|
|
|
|
IUnknown_Release(state);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
event->u.item_created.dwUserData = item->user_data;
|
|
|
|
|
|
|
|
media_player_queue_event(player, event);
|
2021-04-05 08:11:00 +02:00
|
|
|
|
2021-04-06 09:25:31 +02:00
|
|
|
IUnknown_Release(&event->IUnknown_iface);
|
2021-04-05 08:11:00 +02:00
|
|
|
IUnknown_Release(state);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFAsyncCallbackVtbl media_player_resolver_callback_vtbl =
|
|
|
|
{
|
2021-04-06 09:25:31 +02:00
|
|
|
media_player_callback_QueryInterface,
|
2021-04-05 08:11:00 +02:00
|
|
|
media_player_resolver_callback_AddRef,
|
|
|
|
media_player_resolver_callback_Release,
|
2021-04-06 09:25:31 +02:00
|
|
|
media_player_callback_GetParameters,
|
2021-04-05 08:11:00 +02:00
|
|
|
media_player_resolver_callback_Invoke,
|
|
|
|
};
|
|
|
|
|
2021-04-06 09:25:31 +02:00
|
|
|
static ULONG WINAPI media_player_events_callback_AddRef(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_events_IMFAsyncCallback(iface);
|
|
|
|
return IMFPMediaPlayer_AddRef(&player->IMFPMediaPlayer_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_player_events_callback_Release(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_events_IMFAsyncCallback(iface);
|
|
|
|
return IMFPMediaPlayer_Release(&player->IMFPMediaPlayer_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI media_player_events_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_events_IMFAsyncCallback(iface);
|
|
|
|
struct media_event *event;
|
|
|
|
IUnknown *state;
|
|
|
|
|
|
|
|
if (FAILED(IMFAsyncResult_GetState(result, &state)))
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
event = impl_event_from_IUnknown(state);
|
|
|
|
|
|
|
|
if (player->callback)
|
|
|
|
IMFPMediaPlayerCallback_OnMediaPlayerEvent(player->callback, &event->u.header);
|
|
|
|
|
|
|
|
IUnknown_Release(state);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFAsyncCallbackVtbl media_player_events_callback_vtbl =
|
|
|
|
{
|
|
|
|
media_player_callback_QueryInterface,
|
|
|
|
media_player_events_callback_AddRef,
|
|
|
|
media_player_events_callback_Release,
|
|
|
|
media_player_callback_GetParameters,
|
|
|
|
media_player_events_callback_Invoke,
|
|
|
|
};
|
|
|
|
|
2021-04-07 10:07:00 +02:00
|
|
|
static ULONG WINAPI media_player_session_events_callback_AddRef(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_session_events_IMFAsyncCallback(iface);
|
|
|
|
return IMFPMediaPlayer_AddRef(&player->IMFPMediaPlayer_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI media_player_session_events_callback_Release(IMFAsyncCallback *iface)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_session_events_IMFAsyncCallback(iface);
|
|
|
|
return IMFPMediaPlayer_Release(&player->IMFPMediaPlayer_iface);
|
|
|
|
}
|
|
|
|
|
2021-04-13 08:03:30 +02:00
|
|
|
static void media_player_change_state(struct media_player *player, MFP_MEDIAPLAYER_STATE state,
|
|
|
|
HRESULT event_status, struct media_event **event)
|
|
|
|
{
|
|
|
|
MFP_EVENT_TYPE event_type;
|
|
|
|
|
|
|
|
EnterCriticalSection(&player->cs);
|
|
|
|
|
|
|
|
if (state == MFP_MEDIAPLAYER_STATE_PLAYING)
|
|
|
|
event_type = MFP_EVENT_TYPE_PLAY;
|
|
|
|
else if (state == MFP_MEDIAPLAYER_STATE_PAUSED)
|
|
|
|
event_type = MFP_EVENT_TYPE_PAUSE;
|
|
|
|
else
|
|
|
|
event_type = MFP_EVENT_TYPE_STOP;
|
|
|
|
|
|
|
|
media_player_set_state(player, state);
|
|
|
|
media_event_create(player, event_type, event_status, player->item, event);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&player->cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void media_player_set_item(struct media_player *player, IMFTopology *topology, HRESULT event_status,
|
|
|
|
struct media_event **event)
|
|
|
|
{
|
|
|
|
IMFPMediaItem *item;
|
|
|
|
|
|
|
|
if (FAILED(IMFTopology_GetUnknown(topology, &_MF_TOPO_MEDIA_ITEM, &IID_IMFPMediaItem, (void **)&item)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
EnterCriticalSection(&player->cs);
|
|
|
|
|
|
|
|
if (player->item)
|
|
|
|
IMFPMediaItem_Release(player->item);
|
|
|
|
player->item = item;
|
|
|
|
IMFPMediaItem_AddRef(player->item);
|
|
|
|
|
|
|
|
media_event_create(player, MFP_EVENT_TYPE_MEDIAITEM_SET, event_status, item, event);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&player->cs);
|
|
|
|
|
|
|
|
IMFPMediaItem_Release(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void media_player_clear_item(struct media_player *player, HRESULT event_status,
|
|
|
|
struct media_event **event)
|
|
|
|
{
|
|
|
|
IMFPMediaItem *item;
|
|
|
|
|
|
|
|
EnterCriticalSection(&player->cs);
|
|
|
|
|
|
|
|
item = player->item;
|
|
|
|
player->item = NULL;
|
|
|
|
|
|
|
|
media_event_create(player, MFP_EVENT_TYPE_MEDIAITEM_SET, event_status, item, event);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&player->cs);
|
|
|
|
}
|
|
|
|
|
2021-04-13 08:03:34 +02:00
|
|
|
static void media_player_create_forward_event(struct media_player *player, HRESULT event_status, IMFMediaEvent *session_event,
|
|
|
|
struct media_event **event)
|
|
|
|
{
|
|
|
|
EnterCriticalSection(&player->cs);
|
|
|
|
|
|
|
|
if (SUCCEEDED(media_event_create(player, MFP_EVENT_TYPE_MF, event_status, player->item, event)))
|
|
|
|
{
|
|
|
|
IMFMediaEvent_GetType(session_event, &(*event)->u.event.MFEventType);
|
|
|
|
(*event)->u.event.pMFMediaEvent = session_event;
|
|
|
|
IMFMediaEvent_AddRef((*event)->u.event.pMFMediaEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&player->cs);
|
|
|
|
}
|
|
|
|
|
2021-04-20 11:06:00 +02:00
|
|
|
static void media_player_create_playback_ended_event(struct media_player *player, HRESULT event_status,
|
|
|
|
struct media_event **event)
|
|
|
|
{
|
|
|
|
EnterCriticalSection(&player->cs);
|
|
|
|
|
|
|
|
if (SUCCEEDED(media_event_create(player, MFP_EVENT_TYPE_PLAYBACK_ENDED, event_status, player->item, event)))
|
|
|
|
{
|
|
|
|
if (player->item)
|
|
|
|
IMFPMediaItem_Release(player->item);
|
|
|
|
player->item = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&player->cs);
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:07:00 +02:00
|
|
|
static HRESULT WINAPI media_player_session_events_callback_Invoke(IMFAsyncCallback *iface,
|
|
|
|
IMFAsyncResult *result)
|
|
|
|
{
|
|
|
|
struct media_player *player = impl_from_session_events_IMFAsyncCallback(iface);
|
2021-04-07 10:07:01 +02:00
|
|
|
MediaEventType session_event_type = MEUnknown;
|
|
|
|
struct media_event *event = NULL;
|
|
|
|
IMFMediaEvent *session_event;
|
|
|
|
MFP_MEDIAPLAYER_STATE state;
|
|
|
|
HRESULT hr, event_status;
|
2021-04-13 08:03:28 +02:00
|
|
|
IMFTopology *topology;
|
2021-04-20 11:06:00 +02:00
|
|
|
unsigned int status;
|
2021-04-13 08:03:30 +02:00
|
|
|
PROPVARIANT value;
|
2021-04-07 10:07:01 +02:00
|
|
|
|
|
|
|
if (FAILED(hr = IMFMediaSession_EndGetEvent(player->session, result, &session_event)))
|
2021-04-07 10:07:00 +02:00
|
|
|
return S_OK;
|
|
|
|
|
2021-04-07 10:07:01 +02:00
|
|
|
IMFMediaEvent_GetType(session_event, &session_event_type);
|
|
|
|
IMFMediaEvent_GetStatus(session_event, &event_status);
|
|
|
|
|
|
|
|
switch (session_event_type)
|
|
|
|
{
|
|
|
|
case MESessionStarted:
|
|
|
|
case MESessionStopped:
|
|
|
|
case MESessionPaused:
|
2021-04-13 08:03:30 +02:00
|
|
|
|
2021-04-07 10:07:01 +02:00
|
|
|
if (session_event_type == MESessionStarted)
|
|
|
|
state = MFP_MEDIAPLAYER_STATE_PLAYING;
|
2021-04-13 08:03:30 +02:00
|
|
|
else if (session_event_type == MESessionPaused)
|
2021-04-07 10:07:01 +02:00
|
|
|
state = MFP_MEDIAPLAYER_STATE_PAUSED;
|
2021-04-13 08:03:30 +02:00
|
|
|
else
|
|
|
|
state = MFP_MEDIAPLAYER_STATE_STOPPED;
|
2021-04-07 10:07:01 +02:00
|
|
|
|
2021-04-13 08:03:30 +02:00
|
|
|
media_player_change_state(player, state, event_status, &event);
|
2021-04-13 08:03:28 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MESessionTopologySet:
|
|
|
|
|
2021-04-13 08:03:30 +02:00
|
|
|
value.vt = VT_EMPTY;
|
|
|
|
if (SUCCEEDED(IMFMediaEvent_GetValue(session_event, &value)))
|
|
|
|
{
|
|
|
|
if (value.vt == VT_EMPTY)
|
|
|
|
{
|
|
|
|
media_player_clear_item(player, event_status, &event);
|
|
|
|
}
|
|
|
|
else if (value.vt == VT_UNKNOWN && value.punkVal &&
|
|
|
|
SUCCEEDED(IUnknown_QueryInterface(value.punkVal, &IID_IMFTopology, (void **)&topology)))
|
|
|
|
{
|
|
|
|
media_player_set_item(player, topology, event_status, &event);
|
|
|
|
IMFTopology_Release(topology);
|
|
|
|
}
|
|
|
|
PropVariantClear(&value);
|
|
|
|
}
|
2021-04-07 10:07:01 +02:00
|
|
|
|
|
|
|
break;
|
2021-04-13 08:03:34 +02:00
|
|
|
|
2021-04-20 11:06:00 +02:00
|
|
|
case MESessionTopologyStatus:
|
|
|
|
|
|
|
|
if (SUCCEEDED(IMFMediaEvent_GetUINT32(session_event, &MF_EVENT_TOPOLOGY_STATUS, &status)) &&
|
|
|
|
status == MF_TOPOSTATUS_ENDED)
|
|
|
|
{
|
|
|
|
media_player_create_playback_ended_event(player, event_status, &event);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-04-13 08:03:34 +02:00
|
|
|
case MEBufferingStarted:
|
|
|
|
case MEBufferingStopped:
|
|
|
|
case MEExtendedType:
|
|
|
|
case MEReconnectStart:
|
|
|
|
case MEReconnectEnd:
|
|
|
|
case MERendererEvent:
|
|
|
|
case MEStreamSinkFormatChanged:
|
|
|
|
|
|
|
|
media_player_create_forward_event(player, event_status, session_event, &event);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-04-16 14:36:07 +02:00
|
|
|
case MEError:
|
|
|
|
|
|
|
|
media_event_create(player, MFP_EVENT_TYPE_ERROR, event_status, NULL, &event);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-04-07 10:07:01 +02:00
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event)
|
2021-04-13 08:03:30 +02:00
|
|
|
{
|
|
|
|
media_player_queue_event(player, event);
|
2021-04-07 10:07:01 +02:00
|
|
|
IUnknown_Release(&event->IUnknown_iface);
|
2021-04-13 08:03:30 +02:00
|
|
|
}
|
2021-04-07 10:07:01 +02:00
|
|
|
|
2021-04-07 10:07:00 +02:00
|
|
|
IMFMediaSession_BeginGetEvent(player->session, &player->session_events_callback, NULL);
|
2021-04-07 10:07:01 +02:00
|
|
|
IMFMediaEvent_Release(session_event);
|
2021-04-07 10:07:00 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFAsyncCallbackVtbl media_player_session_events_callback_vtbl =
|
|
|
|
{
|
|
|
|
media_player_callback_QueryInterface,
|
|
|
|
media_player_session_events_callback_AddRef,
|
|
|
|
media_player_session_events_callback_Release,
|
|
|
|
media_player_callback_GetParameters,
|
|
|
|
media_player_session_events_callback_Invoke,
|
|
|
|
};
|
|
|
|
|
2021-06-18 18:28:53 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* MFPCreateMediaPlayer (mfplay.@)
|
|
|
|
*/
|
2019-04-22 17:13:38 +02:00
|
|
|
HRESULT WINAPI MFPCreateMediaPlayer(const WCHAR *url, BOOL start_playback, MFP_CREATION_OPTIONS options,
|
2021-04-07 10:06:59 +02:00
|
|
|
IMFPMediaPlayerCallback *callback, HWND window, IMFPMediaPlayer **player)
|
2019-04-22 17:13:38 +02:00
|
|
|
{
|
2021-04-01 22:22:57 +02:00
|
|
|
struct media_player *object;
|
2021-06-18 18:28:53 +02:00
|
|
|
IMFPMediaItem *item;
|
2021-04-05 08:10:59 +02:00
|
|
|
HRESULT hr;
|
2019-04-22 17:13:38 +02:00
|
|
|
|
2021-04-07 10:06:59 +02:00
|
|
|
TRACE("%s, %d, %#x, %p, %p, %p.\n", debugstr_w(url), start_playback, options, callback, window, player);
|
2021-04-01 22:22:57 +02:00
|
|
|
|
2021-06-18 18:28:53 +02:00
|
|
|
if (!player)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*player = NULL;
|
|
|
|
|
|
|
|
if (!url && start_playback)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2021-04-07 10:07:07 +02:00
|
|
|
if (!(object = calloc(1, sizeof(*object))))
|
2021-04-01 22:22:57 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2021-04-05 08:10:59 +02:00
|
|
|
platform_startup();
|
|
|
|
|
2021-04-01 22:22:57 +02:00
|
|
|
object->IMFPMediaPlayer_iface.lpVtbl = &media_player_vtbl;
|
2021-04-05 08:10:59 +02:00
|
|
|
object->IPropertyStore_iface.lpVtbl = &media_player_propstore_vtbl;
|
2021-04-05 08:11:00 +02:00
|
|
|
object->resolver_callback.lpVtbl = &media_player_resolver_callback_vtbl;
|
2021-04-06 09:25:31 +02:00
|
|
|
object->events_callback.lpVtbl = &media_player_events_callback_vtbl;
|
2021-04-07 10:07:00 +02:00
|
|
|
object->session_events_callback.lpVtbl = &media_player_session_events_callback_vtbl;
|
2021-04-01 22:22:57 +02:00
|
|
|
object->refcount = 1;
|
2021-04-05 08:10:57 +02:00
|
|
|
object->callback = callback;
|
|
|
|
if (object->callback)
|
|
|
|
IMFPMediaPlayerCallback_AddRef(object->callback);
|
2021-04-07 10:06:59 +02:00
|
|
|
object->options = options;
|
|
|
|
object->output_window = window;
|
2021-04-07 10:07:01 +02:00
|
|
|
InitializeCriticalSection(&object->cs);
|
2021-04-05 08:10:59 +02:00
|
|
|
if (FAILED(hr = CreatePropertyStore(&object->propstore)))
|
|
|
|
goto failed;
|
2021-04-05 08:11:00 +02:00
|
|
|
if (FAILED(hr = MFCreateSourceResolver(&object->resolver)))
|
|
|
|
goto failed;
|
2021-04-07 10:07:00 +02:00
|
|
|
if (FAILED(hr = MFCreateMediaSession(NULL, &object->session)))
|
|
|
|
goto failed;
|
|
|
|
if (FAILED(hr = IMFMediaSession_BeginGetEvent(object->session, &object->session_events_callback, NULL)))
|
|
|
|
goto failed;
|
2021-04-06 09:25:32 +02:00
|
|
|
if (!(object->options & MFP_OPTION_FREE_THREADED_CALLBACK))
|
|
|
|
{
|
|
|
|
object->event_window = CreateWindowW(eventclassW, NULL, 0, 0, 0, 0, 0, HWND_MESSAGE,
|
|
|
|
0, mfplay_instance, NULL);
|
|
|
|
}
|
2021-04-05 08:10:58 +02:00
|
|
|
|
2021-06-18 18:28:53 +02:00
|
|
|
if (url)
|
|
|
|
{
|
|
|
|
if (FAILED(hr = media_player_create_item_from_url(object, url, TRUE, 0, &item)))
|
|
|
|
{
|
|
|
|
WARN("Failed to create media item, hr %#x.\n", hr);
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IMFPMediaPlayer_SetMediaItem(&object->IMFPMediaPlayer_iface, item);
|
|
|
|
IMFPMediaItem_Release(item);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to set media item, hr %#x.\n", hr);
|
|
|
|
goto failed;
|
|
|
|
}
|
2021-06-18 18:28:54 +02:00
|
|
|
|
|
|
|
if (start_playback)
|
|
|
|
IMFPMediaPlayer_Play(&object->IMFPMediaPlayer_iface);
|
2021-06-18 18:28:53 +02:00
|
|
|
}
|
|
|
|
|
2021-04-01 22:22:57 +02:00
|
|
|
*player = &object->IMFPMediaPlayer_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
2021-04-05 08:10:59 +02:00
|
|
|
|
|
|
|
failed:
|
|
|
|
|
|
|
|
IMFPMediaPlayer_Release(&object->IMFPMediaPlayer_iface);
|
|
|
|
|
|
|
|
return hr;
|
2019-04-22 17:13:38 +02:00
|
|
|
}
|
2021-04-06 09:25:32 +02:00
|
|
|
|
|
|
|
static void media_player_register_window_class(void)
|
|
|
|
{
|
|
|
|
WNDCLASSW cls = { 0 };
|
|
|
|
|
|
|
|
cls.lpfnWndProc = media_player_event_proc;
|
|
|
|
cls.hInstance = mfplay_instance;
|
|
|
|
cls.lpszClassName = eventclassW;
|
|
|
|
|
|
|
|
RegisterClassW(&cls);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, void *reserved)
|
|
|
|
{
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
mfplay_instance = instance;
|
|
|
|
DisableThreadLibraryCalls(instance);
|
|
|
|
media_player_register_window_class();
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
if (reserved) break;
|
|
|
|
UnregisterClassW(eventclassW, instance);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|