2020-06-30 15:34:00 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Nikolay Sivov
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "evr.h"
|
|
|
|
#include "d3d9.h"
|
|
|
|
#include "mfapi.h"
|
|
|
|
#include "mferror.h"
|
2020-10-01 14:59:33 +02:00
|
|
|
#include "dxva2api.h"
|
2020-06-30 15:34:00 +02:00
|
|
|
|
|
|
|
#include "evr_classes.h"
|
|
|
|
#include "evr_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(evr);
|
|
|
|
|
2021-10-28 16:33:19 +02:00
|
|
|
/*
|
|
|
|
Initial state represents just created object, presenter never returns to this state.
|
|
|
|
Shutdown state is entered on ReleaseServicePointers(), terminal state.
|
|
|
|
Started/stopped/paused states are controlled by clock state changes.
|
|
|
|
*/
|
|
|
|
|
2020-07-01 14:55:43 +02:00
|
|
|
enum presenter_state
|
|
|
|
{
|
2021-10-28 16:33:19 +02:00
|
|
|
PRESENTER_STATE_INITIAL = 0,
|
|
|
|
PRESENTER_STATE_SHUT_DOWN,
|
2020-07-01 14:55:43 +02:00
|
|
|
PRESENTER_STATE_STARTED,
|
|
|
|
PRESENTER_STATE_STOPPED,
|
|
|
|
PRESENTER_STATE_PAUSED,
|
|
|
|
};
|
|
|
|
|
2020-11-10 11:07:19 +01:00
|
|
|
enum presenter_flags
|
|
|
|
{
|
|
|
|
PRESENTER_MIXER_HAS_INPUT = 0x1,
|
|
|
|
};
|
|
|
|
|
2020-11-05 16:37:23 +01:00
|
|
|
enum streaming_thread_message
|
|
|
|
{
|
|
|
|
EVRM_STOP = WM_USER,
|
2020-11-17 11:41:40 +01:00
|
|
|
EVRM_PRESENT = WM_USER + 1,
|
|
|
|
EVRM_PROCESS_INPUT = WM_USER + 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sample_queue
|
|
|
|
{
|
|
|
|
IMFSample **samples;
|
|
|
|
unsigned int size;
|
|
|
|
unsigned int used;
|
|
|
|
unsigned int front;
|
|
|
|
unsigned int back;
|
2022-02-01 16:59:07 +01:00
|
|
|
IMFSample *last_presented;
|
2020-11-05 16:37:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct streaming_thread
|
|
|
|
{
|
|
|
|
HANDLE hthread;
|
|
|
|
HANDLE ready_event;
|
|
|
|
DWORD tid;
|
2020-11-17 11:41:40 +01:00
|
|
|
struct sample_queue queue;
|
2020-11-05 16:37:23 +01:00
|
|
|
};
|
|
|
|
|
2020-06-30 15:34:00 +02:00
|
|
|
struct video_presenter
|
|
|
|
{
|
|
|
|
IMFVideoPresenter IMFVideoPresenter_iface;
|
2020-06-30 15:34:01 +02:00
|
|
|
IMFVideoDeviceID IMFVideoDeviceID_iface;
|
2020-06-30 15:34:02 +02:00
|
|
|
IMFTopologyServiceLookupClient IMFTopologyServiceLookupClient_iface;
|
2020-06-30 15:34:04 +02:00
|
|
|
IMFVideoDisplayControl IMFVideoDisplayControl_iface;
|
2020-07-01 14:55:42 +02:00
|
|
|
IMFRateSupport IMFRateSupport_iface;
|
2020-10-01 14:59:32 +02:00
|
|
|
IMFGetService IMFGetService_iface;
|
2020-10-22 13:02:48 +02:00
|
|
|
IMFVideoPositionMapper IMFVideoPositionMapper_iface;
|
2020-11-13 13:31:31 +01:00
|
|
|
IQualProp IQualProp_iface;
|
2020-11-13 13:31:33 +01:00
|
|
|
IMFQualityAdvise IMFQualityAdvise_iface;
|
2021-04-16 15:15:57 +02:00
|
|
|
IMFQualityAdviseLimits IMFQualityAdviseLimits_iface;
|
2020-11-17 11:41:38 +01:00
|
|
|
IDirect3DDeviceManager9 IDirect3DDeviceManager9_iface;
|
2020-11-10 11:07:21 +01:00
|
|
|
IMFVideoSampleAllocatorNotify allocator_cb;
|
2020-06-30 15:34:00 +02:00
|
|
|
IUnknown IUnknown_inner;
|
|
|
|
IUnknown *outer_unk;
|
|
|
|
LONG refcount;
|
2020-07-01 14:55:43 +02:00
|
|
|
|
2020-07-01 14:55:44 +02:00
|
|
|
IMFTransform *mixer;
|
|
|
|
IMFClock *clock;
|
|
|
|
IMediaEventSink *event_sink;
|
|
|
|
|
2020-10-01 14:59:33 +02:00
|
|
|
IDirect3DDeviceManager9 *device_manager;
|
2020-11-13 13:31:32 +01:00
|
|
|
IDirect3DSwapChain9 *swapchain;
|
|
|
|
HANDLE hdevice;
|
|
|
|
|
2020-11-10 11:07:18 +01:00
|
|
|
IMFVideoSampleAllocator *allocator;
|
2020-11-05 16:37:23 +01:00
|
|
|
struct streaming_thread thread;
|
2020-11-17 11:41:40 +01:00
|
|
|
unsigned int allocator_capacity;
|
2020-11-05 16:37:24 +01:00
|
|
|
IMFMediaType *media_type;
|
2020-11-17 11:41:40 +01:00
|
|
|
LONGLONG frame_time_threshold;
|
2020-10-01 14:59:33 +02:00
|
|
|
UINT reset_token;
|
2020-10-02 13:01:11 +02:00
|
|
|
HWND video_window;
|
2020-10-02 13:01:12 +02:00
|
|
|
MFVideoNormalizedRect src_rect;
|
|
|
|
RECT dst_rect;
|
2020-10-06 13:48:57 +02:00
|
|
|
DWORD rendering_prefs;
|
2020-10-07 10:40:20 +02:00
|
|
|
SIZE native_size;
|
|
|
|
SIZE native_ratio;
|
2020-10-07 10:40:22 +02:00
|
|
|
unsigned int ar_mode;
|
2020-07-01 14:55:43 +02:00
|
|
|
unsigned int state;
|
2020-11-10 11:07:19 +01:00
|
|
|
unsigned int flags;
|
2021-11-03 16:21:07 +01:00
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
int presented;
|
2022-02-01 16:59:07 +01:00
|
|
|
LONGLONG sampletime;
|
2021-11-03 16:21:07 +01:00
|
|
|
} frame_stats;
|
|
|
|
|
2020-07-01 14:55:43 +02:00
|
|
|
CRITICAL_SECTION cs;
|
2020-06-30 15:34:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct video_presenter *impl_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IUnknown_inner);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct video_presenter *impl_from_IMFVideoPresenter(IMFVideoPresenter *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:34:01 +02:00
|
|
|
static struct video_presenter *impl_from_IMFVideoDeviceID(IMFVideoDeviceID *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IMFVideoDeviceID_iface);
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:34:02 +02:00
|
|
|
static struct video_presenter *impl_from_IMFTopologyServiceLookupClient(IMFTopologyServiceLookupClient *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IMFTopologyServiceLookupClient_iface);
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:34:04 +02:00
|
|
|
static struct video_presenter *impl_from_IMFVideoDisplayControl(IMFVideoDisplayControl *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IMFVideoDisplayControl_iface);
|
|
|
|
}
|
|
|
|
|
2020-07-01 14:55:42 +02:00
|
|
|
static struct video_presenter *impl_from_IMFRateSupport(IMFRateSupport *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IMFRateSupport_iface);
|
|
|
|
}
|
|
|
|
|
2020-10-01 14:59:32 +02:00
|
|
|
static struct video_presenter *impl_from_IMFGetService(IMFGetService *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IMFGetService_iface);
|
|
|
|
}
|
|
|
|
|
2020-10-22 13:02:48 +02:00
|
|
|
static struct video_presenter *impl_from_IMFVideoPositionMapper(IMFVideoPositionMapper *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IMFVideoPositionMapper_iface);
|
|
|
|
}
|
|
|
|
|
2020-11-10 11:07:21 +01:00
|
|
|
static struct video_presenter *impl_from_IMFVideoSampleAllocatorNotify(IMFVideoSampleAllocatorNotify *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, allocator_cb);
|
|
|
|
}
|
|
|
|
|
2020-11-13 13:31:31 +01:00
|
|
|
static struct video_presenter *impl_from_IQualProp(IQualProp *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IQualProp_iface);
|
|
|
|
}
|
|
|
|
|
2020-11-13 13:31:33 +01:00
|
|
|
static struct video_presenter *impl_from_IMFQualityAdvise(IMFQualityAdvise *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IMFQualityAdvise_iface);
|
|
|
|
}
|
|
|
|
|
2021-04-16 15:15:57 +02:00
|
|
|
static struct video_presenter *impl_from_IMFQualityAdviseLimits(IMFQualityAdviseLimits *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IMFQualityAdviseLimits_iface);
|
|
|
|
}
|
|
|
|
|
2020-11-17 11:41:38 +01:00
|
|
|
static struct video_presenter *impl_from_IDirect3DDeviceManager9(IDirect3DDeviceManager9 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct video_presenter, IDirect3DDeviceManager9_iface);
|
|
|
|
}
|
|
|
|
|
2020-11-10 11:07:20 +01:00
|
|
|
static void video_presenter_notify_renderer(struct video_presenter *presenter,
|
|
|
|
LONG event, LONG_PTR param1, LONG_PTR param2)
|
|
|
|
{
|
|
|
|
if (presenter->event_sink)
|
|
|
|
IMediaEventSink_Notify(presenter->event_sink, event, param1, param2);
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:40:21 +02:00
|
|
|
static unsigned int get_gcd(unsigned int a, unsigned int b)
|
|
|
|
{
|
|
|
|
unsigned int m;
|
|
|
|
|
|
|
|
while (b)
|
|
|
|
{
|
|
|
|
m = a % b;
|
|
|
|
a = b;
|
|
|
|
b = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2020-11-13 13:31:32 +01:00
|
|
|
static HRESULT video_presenter_get_device(struct video_presenter *presenter, IDirect3DDevice9 **device)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!presenter->hdevice)
|
|
|
|
{
|
|
|
|
if (FAILED(hr = IDirect3DDeviceManager9_OpenDeviceHandle(presenter->device_manager, &presenter->hdevice)))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IDirect3DDeviceManager9_LockDevice(presenter->device_manager, presenter->hdevice, device, TRUE);
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:40:21 +02:00
|
|
|
static void video_presenter_get_native_video_size(struct video_presenter *presenter)
|
|
|
|
{
|
|
|
|
IMFMediaType *media_type;
|
|
|
|
UINT64 frame_size = 0;
|
|
|
|
|
|
|
|
memset(&presenter->native_size, 0, sizeof(presenter->native_size));
|
|
|
|
memset(&presenter->native_ratio, 0, sizeof(presenter->native_ratio));
|
|
|
|
|
|
|
|
if (!presenter->mixer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (FAILED(IMFTransform_GetInputCurrentType(presenter->mixer, 0, &media_type)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (SUCCEEDED(IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &frame_size)))
|
|
|
|
{
|
|
|
|
unsigned int gcd;
|
|
|
|
|
|
|
|
presenter->native_size.cx = frame_size >> 32;
|
|
|
|
presenter->native_size.cy = frame_size;
|
|
|
|
|
|
|
|
if ((gcd = get_gcd(presenter->native_size.cx, presenter->native_size.cy)))
|
|
|
|
{
|
|
|
|
presenter->native_ratio.cx = presenter->native_size.cx / gcd;
|
|
|
|
presenter->native_ratio.cy = presenter->native_size.cy / gcd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IMFMediaType_Release(media_type);
|
|
|
|
}
|
|
|
|
|
2020-11-10 11:07:21 +01:00
|
|
|
/* It is important this is called to reset callback too to break circular referencing,
|
|
|
|
when allocator keeps a reference of its container, that created it. */
|
|
|
|
static void video_presenter_set_allocator_callback(struct video_presenter *presenter,
|
|
|
|
IMFVideoSampleAllocatorNotify *notify_cb)
|
|
|
|
{
|
|
|
|
IMFVideoSampleAllocatorCallback *cb;
|
|
|
|
|
|
|
|
IMFVideoSampleAllocator_QueryInterface(presenter->allocator, &IID_IMFVideoSampleAllocatorCallback, (void **)&cb);
|
|
|
|
IMFVideoSampleAllocatorCallback_SetCallback(cb, notify_cb);
|
|
|
|
IMFVideoSampleAllocatorCallback_Release(cb);
|
|
|
|
}
|
|
|
|
|
2020-11-05 16:37:24 +01:00
|
|
|
static void video_presenter_reset_media_type(struct video_presenter *presenter)
|
|
|
|
{
|
|
|
|
if (presenter->media_type)
|
|
|
|
IMFMediaType_Release(presenter->media_type);
|
|
|
|
presenter->media_type = NULL;
|
|
|
|
|
2021-10-29 14:30:26 +02:00
|
|
|
if (presenter->allocator)
|
|
|
|
{
|
|
|
|
IMFVideoSampleAllocator_UninitializeSampleAllocator(presenter->allocator);
|
|
|
|
video_presenter_set_allocator_callback(presenter, NULL);
|
|
|
|
}
|
2020-11-05 16:37:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT video_presenter_set_media_type(struct video_presenter *presenter, IMFMediaType *media_type)
|
|
|
|
{
|
2022-01-31 15:26:07 +01:00
|
|
|
DWORD flags;
|
2020-11-10 11:07:18 +01:00
|
|
|
HRESULT hr;
|
2020-11-05 16:37:24 +01:00
|
|
|
|
|
|
|
if (!media_type)
|
|
|
|
{
|
|
|
|
video_presenter_reset_media_type(presenter);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (presenter->media_type && IMFMediaType_IsEqual(presenter->media_type, media_type, &flags) == S_OK)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
video_presenter_reset_media_type(presenter);
|
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
if (SUCCEEDED(hr = IMFVideoSampleAllocator_InitializeSampleAllocator(presenter->allocator,
|
|
|
|
presenter->allocator_capacity, media_type)))
|
2020-11-10 11:07:18 +01:00
|
|
|
{
|
2020-11-17 11:41:40 +01:00
|
|
|
MFRatio ratio;
|
|
|
|
UINT64 rate, frametime;
|
|
|
|
|
2020-11-10 11:07:18 +01:00
|
|
|
presenter->media_type = media_type;
|
|
|
|
IMFMediaType_AddRef(presenter->media_type);
|
2020-11-17 11:41:40 +01:00
|
|
|
|
|
|
|
if (SUCCEEDED(IMFMediaType_GetUINT64(presenter->media_type, &MF_MT_FRAME_RATE, &rate)))
|
|
|
|
{
|
|
|
|
ratio.Denominator = rate;
|
|
|
|
ratio.Numerator = rate >> 32;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ratio.Denominator = 1;
|
|
|
|
ratio.Numerator = 30;
|
|
|
|
}
|
|
|
|
|
|
|
|
MFFrameRateToAverageTimePerFrame(ratio.Numerator, ratio.Denominator, &frametime);
|
|
|
|
presenter->frame_time_threshold = frametime / 4;
|
2020-11-10 11:07:18 +01:00
|
|
|
}
|
|
|
|
else
|
2022-02-01 16:59:06 +01:00
|
|
|
WARN("Failed to initialize sample allocator, hr %#lx.\n", hr);
|
2020-11-05 16:37:24 +01:00
|
|
|
|
2020-11-10 11:07:18 +01:00
|
|
|
return hr;
|
2020-11-05 16:37:24 +01:00
|
|
|
}
|
|
|
|
|
2021-04-19 15:03:06 +02:00
|
|
|
static HRESULT video_presenter_configure_output_type(struct video_presenter *presenter, const MFVideoArea *aperture,
|
|
|
|
IMFMediaType *media_type)
|
|
|
|
{
|
2021-04-19 15:03:07 +02:00
|
|
|
GUID subtype;
|
|
|
|
LONG stride;
|
2022-01-31 15:26:07 +01:00
|
|
|
DWORD size;
|
2021-04-19 15:03:06 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_SIZE, (UINT64)aperture->Area.cx << 32 | aperture->Area.cy);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMFMediaType_SetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (UINT8 *)aperture, sizeof(*aperture));
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMFMediaType_SetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (UINT8 *)aperture, sizeof(*aperture));
|
|
|
|
|
2021-04-19 15:03:07 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &subtype);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = MFGetStrideForBitmapInfoHeader(subtype.Data1, aperture->Area.cx, &stride);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = MFGetPlaneSize(subtype.Data1, aperture->Area.cx, aperture->Area.cy, &size);
|
|
|
|
if (SUCCEEDED(hr))
|
2021-05-31 12:31:14 +02:00
|
|
|
hr = IMFMediaType_SetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, abs(stride));
|
2021-04-19 15:03:07 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2021-05-31 12:31:13 +02:00
|
|
|
hr = IMFMediaType_SetUINT32(media_type, &MF_MT_SAMPLE_SIZE, size);
|
2021-04-19 15:03:07 +02:00
|
|
|
}
|
|
|
|
|
2021-04-19 15:03:06 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:40:21 +02:00
|
|
|
static HRESULT video_presenter_invalidate_media_type(struct video_presenter *presenter)
|
|
|
|
{
|
2020-11-24 16:12:45 +01:00
|
|
|
IMFMediaType *media_type, *candidate_type;
|
2021-04-19 15:03:06 +02:00
|
|
|
MFVideoArea aperture = {{ 0 }};
|
2020-10-30 14:50:44 +01:00
|
|
|
unsigned int idx = 0;
|
2020-11-24 16:12:45 +01:00
|
|
|
RECT rect;
|
2020-10-30 14:50:44 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2021-10-27 16:23:04 +02:00
|
|
|
if (!presenter->mixer)
|
|
|
|
return MF_E_TRANSFORM_TYPE_NOT_SET;
|
|
|
|
|
2020-11-24 16:12:45 +01:00
|
|
|
if (FAILED(hr = MFCreateMediaType(&media_type)))
|
|
|
|
return hr;
|
|
|
|
|
2020-10-07 10:40:21 +02:00
|
|
|
video_presenter_get_native_video_size(presenter);
|
|
|
|
|
2020-11-24 16:12:45 +01:00
|
|
|
rect = presenter->dst_rect;
|
|
|
|
if (rect.left == 0 && rect.right == 0 && rect.bottom == 0 && rect.top == 0)
|
|
|
|
{
|
|
|
|
rect.right = presenter->native_size.cx;
|
|
|
|
rect.bottom = presenter->native_size.cy;
|
|
|
|
}
|
|
|
|
|
|
|
|
aperture.Area.cx = rect.right - rect.left;
|
|
|
|
aperture.Area.cy = rect.bottom - rect.top;
|
|
|
|
|
|
|
|
while (SUCCEEDED(hr = IMFTransform_GetOutputAvailableType(presenter->mixer, 0, idx++, &candidate_type)))
|
2020-10-30 14:50:44 +01:00
|
|
|
{
|
|
|
|
/* FIXME: check that d3d device supports this format */
|
|
|
|
|
2020-11-24 16:12:45 +01:00
|
|
|
if (FAILED(hr = IMFMediaType_CopyAllItems(candidate_type, (IMFAttributes *)media_type)))
|
2022-02-01 16:59:06 +01:00
|
|
|
WARN("Failed to clone a media type, hr %#lx.\n", hr);
|
2020-11-24 16:12:45 +01:00
|
|
|
IMFMediaType_Release(candidate_type);
|
|
|
|
|
2021-04-19 15:03:06 +02:00
|
|
|
hr = video_presenter_configure_output_type(presenter, &aperture, media_type);
|
2020-10-30 14:50:44 +01:00
|
|
|
|
2021-04-19 15:03:06 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMFTransform_SetOutputType(presenter->mixer, 0, media_type, MFT_SET_TYPE_TEST_ONLY);
|
2020-10-30 14:50:44 +01:00
|
|
|
|
2020-11-05 16:37:24 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = video_presenter_set_media_type(presenter, media_type);
|
2020-10-30 14:50:44 +01:00
|
|
|
|
2020-11-10 11:07:18 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMFTransform_SetOutputType(presenter->mixer, 0, media_type, 0);
|
|
|
|
|
2020-11-05 16:37:24 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
break;
|
2020-10-30 14:50:44 +01:00
|
|
|
}
|
|
|
|
|
2020-11-24 16:12:45 +01:00
|
|
|
IMFMediaType_Release(media_type);
|
|
|
|
|
2020-10-30 14:50:44 +01:00
|
|
|
return hr;
|
2020-10-07 10:40:21 +02:00
|
|
|
}
|
|
|
|
|
2021-04-19 15:03:09 +02:00
|
|
|
static HRESULT video_presenter_sample_queue_init(struct video_presenter *presenter)
|
2020-11-05 16:37:23 +01:00
|
|
|
{
|
2020-11-17 11:41:40 +01:00
|
|
|
struct sample_queue *queue = &presenter->thread.queue;
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
if (queue->size)
|
2021-04-19 15:03:09 +02:00
|
|
|
return S_OK;
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
memset(queue, 0, sizeof(*queue));
|
2021-04-19 15:03:09 +02:00
|
|
|
if (!(queue->samples = calloc(presenter->allocator_capacity, sizeof(*queue->samples))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
queue->size = presenter->allocator_capacity;
|
|
|
|
queue->back = queue->size - 1;
|
2021-04-19 15:03:09 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2020-11-17 11:41:40 +01:00
|
|
|
}
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
static void video_presenter_sample_queue_push(struct video_presenter *presenter, IMFSample *sample)
|
|
|
|
{
|
|
|
|
struct sample_queue *queue = &presenter->thread.queue;
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
if (queue->used != queue->size)
|
2020-11-05 16:37:23 +01:00
|
|
|
{
|
2020-11-17 11:41:40 +01:00
|
|
|
queue->back = (queue->back + 1) % queue->size;
|
|
|
|
queue->samples[queue->back] = sample;
|
|
|
|
queue->used++;
|
|
|
|
IMFSample_AddRef(sample);
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
}
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
static BOOL video_presenter_sample_queue_pop(struct video_presenter *presenter, IMFSample **sample)
|
|
|
|
{
|
|
|
|
struct sample_queue *queue = &presenter->thread.queue;
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
if (queue->used)
|
|
|
|
{
|
|
|
|
*sample = queue->samples[queue->front];
|
|
|
|
queue->front = (queue->front + 1) % queue->size;
|
|
|
|
queue->used--;
|
2020-11-05 16:37:23 +01:00
|
|
|
}
|
2020-11-17 11:41:40 +01:00
|
|
|
else
|
|
|
|
*sample = NULL;
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
return *sample != NULL;
|
2020-11-05 16:37:23 +01:00
|
|
|
}
|
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
static HRESULT video_presenter_get_sample_surface(IMFSample *sample, IDirect3DSurface9 **surface)
|
2020-11-05 16:37:23 +01:00
|
|
|
{
|
2020-11-17 11:41:40 +01:00
|
|
|
IMFMediaBuffer *buffer;
|
|
|
|
IMFGetService *gs;
|
|
|
|
HRESULT hr;
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
if (FAILED(hr = IMFSample_GetBufferByIndex(sample, 0, &buffer)))
|
|
|
|
return hr;
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFGetService, (void **)&gs);
|
|
|
|
IMFMediaBuffer_Release(buffer);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IMFGetService_GetService(gs, &MR_BUFFER_SERVICE, &IID_IDirect3DSurface9, (void **)surface);
|
|
|
|
IMFGetService_Release(gs);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void video_presenter_sample_present(struct video_presenter *presenter, IMFSample *sample)
|
|
|
|
{
|
|
|
|
IDirect3DSurface9 *surface, *backbuffer;
|
|
|
|
IDirect3DDevice9 *device;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!presenter->swapchain)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (FAILED(hr = video_presenter_get_sample_surface(sample, &surface)))
|
2020-11-05 16:37:23 +01:00
|
|
|
{
|
2022-02-01 16:59:06 +01:00
|
|
|
WARN("Failed to get sample surface, hr %#lx.\n", hr);
|
2020-11-17 11:41:40 +01:00
|
|
|
return;
|
2020-11-05 16:37:23 +01:00
|
|
|
}
|
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
if (FAILED(hr = IDirect3DSwapChain9_GetBackBuffer(presenter->swapchain, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer)))
|
|
|
|
{
|
2022-02-01 16:59:06 +01:00
|
|
|
WARN("Failed to get a backbuffer, hr %#lx.\n", hr);
|
2020-11-17 11:41:40 +01:00
|
|
|
IDirect3DSurface9_Release(surface);
|
|
|
|
return;
|
|
|
|
}
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
IDirect3DSwapChain9_GetDevice(presenter->swapchain, &device);
|
|
|
|
IDirect3DDevice9_StretchRect(device, surface, NULL, backbuffer, NULL, D3DTEXF_POINT);
|
2020-11-24 16:12:46 +01:00
|
|
|
|
2021-11-08 12:57:02 +01:00
|
|
|
IDirect3DSwapChain9_Present(presenter->swapchain, NULL, NULL, NULL, NULL, 0);
|
2021-11-03 16:21:07 +01:00
|
|
|
presenter->frame_stats.presented++;
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2022-02-01 16:59:07 +01:00
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
if (presenter->thread.queue.last_presented)
|
|
|
|
IMFSample_Release(presenter->thread.queue.last_presented);
|
|
|
|
presenter->thread.queue.last_presented = sample;
|
|
|
|
IMFSample_AddRef(presenter->thread.queue.last_presented);
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
IDirect3DDevice9_Release(device);
|
|
|
|
IDirect3DSurface9_Release(backbuffer);
|
|
|
|
IDirect3DSurface9_Release(surface);
|
2020-11-05 16:37:23 +01:00
|
|
|
}
|
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
static void video_presenter_check_queue(struct video_presenter *presenter,
|
|
|
|
unsigned int *next_wait)
|
2020-11-05 16:37:23 +01:00
|
|
|
{
|
2020-11-17 11:41:40 +01:00
|
|
|
LONGLONG pts, clocktime, delta;
|
|
|
|
unsigned int wait = 0;
|
|
|
|
IMFSample *sample;
|
|
|
|
MFTIME systime;
|
2021-04-19 15:03:08 +02:00
|
|
|
BOOL present;
|
2020-11-17 11:41:40 +01:00
|
|
|
HRESULT hr;
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
while (video_presenter_sample_queue_pop(presenter, &sample))
|
|
|
|
{
|
2021-04-19 15:03:08 +02:00
|
|
|
present = TRUE;
|
2020-11-17 11:41:40 +01:00
|
|
|
wait = 0;
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
if (presenter->clock)
|
|
|
|
{
|
|
|
|
pts = clocktime = 0;
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
hr = IMFSample_GetSampleTime(sample, &pts);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMFClock_GetCorrelatedTime(presenter->clock, 0, &clocktime, &systime);
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
delta = pts - clocktime;
|
|
|
|
if (delta > 3 * presenter->frame_time_threshold)
|
|
|
|
{
|
|
|
|
/* Convert 100ns -> msec */
|
|
|
|
wait = (delta - 3 * presenter->frame_time_threshold) / 100000;
|
|
|
|
present = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2020-11-05 16:37:23 +01:00
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
if (present)
|
|
|
|
video_presenter_sample_present(presenter, sample);
|
|
|
|
else
|
|
|
|
video_presenter_sample_queue_push(presenter, sample);
|
|
|
|
|
|
|
|
IMFSample_Release(sample);
|
|
|
|
|
|
|
|
if (wait > 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wait)
|
|
|
|
wait = INFINITE;
|
|
|
|
|
|
|
|
*next_wait = wait;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void video_presenter_schedule_sample(struct video_presenter *presenter, IMFSample *sample)
|
|
|
|
{
|
|
|
|
if (!presenter->thread.tid)
|
|
|
|
{
|
|
|
|
WARN("Streaming thread hasn't been started.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (presenter->clock)
|
|
|
|
{
|
|
|
|
video_presenter_sample_queue_push(presenter, sample);
|
|
|
|
PostThreadMessageW(presenter->thread.tid, EVRM_PRESENT, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
video_presenter_sample_present(presenter, sample);
|
|
|
|
}
|
2020-11-05 16:37:23 +01:00
|
|
|
}
|
|
|
|
|
2020-11-10 11:07:19 +01:00
|
|
|
static HRESULT video_presenter_process_input(struct video_presenter *presenter)
|
|
|
|
{
|
|
|
|
MFT_OUTPUT_DATA_BUFFER buffer;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
IMFSample *sample;
|
|
|
|
DWORD status;
|
|
|
|
|
2021-10-28 16:33:19 +02:00
|
|
|
if (presenter->state == PRESENTER_STATE_SHUT_DOWN)
|
|
|
|
return MF_E_SHUTDOWN;
|
|
|
|
|
2020-11-10 11:07:19 +01:00
|
|
|
if (!presenter->media_type)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
while (hr == S_OK)
|
|
|
|
{
|
2020-11-10 11:07:20 +01:00
|
|
|
LONGLONG mixing_started, mixing_finished;
|
|
|
|
MFTIME systime;
|
|
|
|
|
2020-11-10 11:07:19 +01:00
|
|
|
if (!(presenter->flags & PRESENTER_MIXER_HAS_INPUT))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (FAILED(hr = IMFVideoSampleAllocator_AllocateSample(presenter->allocator, &sample)))
|
|
|
|
{
|
2022-02-01 16:59:06 +01:00
|
|
|
WARN("Failed to allocate a sample, hr %#lx.\n", hr);
|
2020-11-10 11:07:19 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&buffer, 0, sizeof(buffer));
|
|
|
|
buffer.pSample = sample;
|
|
|
|
|
2020-11-10 11:07:20 +01:00
|
|
|
if (presenter->clock)
|
|
|
|
IMFClock_GetCorrelatedTime(presenter->clock, 0, &mixing_started, &systime);
|
|
|
|
|
2020-11-10 11:07:19 +01:00
|
|
|
if (FAILED(hr = IMFTransform_ProcessOutput(presenter->mixer, 0, 1, &buffer, &status)))
|
|
|
|
{
|
|
|
|
/* FIXME: failure path probably needs to handle some errors specifically */
|
|
|
|
presenter->flags &= ~PRESENTER_MIXER_HAS_INPUT;
|
|
|
|
IMFSample_Release(sample);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-10 11:07:20 +01:00
|
|
|
if (presenter->clock)
|
|
|
|
{
|
|
|
|
LONGLONG latency;
|
|
|
|
|
|
|
|
IMFClock_GetCorrelatedTime(presenter->clock, 0, &mixing_finished, &systime);
|
|
|
|
latency = mixing_finished - mixing_started;
|
|
|
|
video_presenter_notify_renderer(presenter, EC_PROCESSING_LATENCY, (LONG_PTR)&latency, 0);
|
|
|
|
}
|
|
|
|
|
2020-11-10 11:07:19 +01:00
|
|
|
if (buffer.pEvents)
|
|
|
|
IMFCollection_Release(buffer.pEvents);
|
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
video_presenter_schedule_sample(presenter, sample);
|
|
|
|
|
2020-11-10 11:07:19 +01:00
|
|
|
IMFSample_Release(sample);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
static DWORD CALLBACK video_presenter_streaming_thread(void *arg)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = arg;
|
|
|
|
unsigned int wait = INFINITE;
|
|
|
|
BOOL stop_thread = FALSE;
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
PeekMessageW(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
|
|
|
|
|
|
|
|
SetEvent(presenter->thread.ready_event);
|
|
|
|
|
|
|
|
while (!stop_thread)
|
|
|
|
{
|
|
|
|
if (MsgWaitForMultipleObjects(0, NULL, FALSE, wait, QS_POSTMESSAGE) == WAIT_TIMEOUT)
|
|
|
|
video_presenter_check_queue(presenter, &wait);
|
|
|
|
|
|
|
|
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
BOOL peek = TRUE;
|
|
|
|
|
|
|
|
switch (msg.message)
|
|
|
|
{
|
|
|
|
case EVRM_STOP:
|
|
|
|
stop_thread = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EVRM_PRESENT:
|
|
|
|
if (peek)
|
|
|
|
{
|
|
|
|
video_presenter_check_queue(presenter, &wait);
|
|
|
|
peek = wait != INFINITE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EVRM_PROCESS_INPUT:
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
video_presenter_process_input(presenter);
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT video_presenter_start_streaming(struct video_presenter *presenter)
|
|
|
|
{
|
2021-04-19 15:03:09 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2021-10-28 16:33:19 +02:00
|
|
|
if (presenter->state == PRESENTER_STATE_SHUT_DOWN)
|
|
|
|
return MF_E_SHUTDOWN;
|
|
|
|
|
2020-11-17 11:41:40 +01:00
|
|
|
if (presenter->thread.hthread)
|
|
|
|
return S_OK;
|
|
|
|
|
2021-04-19 15:03:09 +02:00
|
|
|
if (FAILED(hr = video_presenter_sample_queue_init(presenter)))
|
|
|
|
return hr;
|
2020-11-17 11:41:40 +01:00
|
|
|
|
|
|
|
if (!(presenter->thread.ready_event = CreateEventW(NULL, FALSE, FALSE, NULL)))
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
|
|
|
if (!(presenter->thread.hthread = CreateThread(NULL, 0, video_presenter_streaming_thread,
|
|
|
|
presenter, 0, &presenter->thread.tid)))
|
|
|
|
{
|
|
|
|
WARN("Failed to create streaming thread.\n");
|
|
|
|
CloseHandle(presenter->thread.ready_event);
|
|
|
|
presenter->thread.ready_event = NULL;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
video_presenter_set_allocator_callback(presenter, &presenter->allocator_cb);
|
|
|
|
|
|
|
|
WaitForSingleObject(presenter->thread.ready_event, INFINITE);
|
|
|
|
CloseHandle(presenter->thread.ready_event);
|
|
|
|
presenter->thread.ready_event = NULL;
|
|
|
|
|
2022-02-01 16:59:06 +01:00
|
|
|
TRACE("Started streaming thread, tid %#lx.\n", presenter->thread.tid);
|
2020-11-17 11:41:40 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT video_presenter_end_streaming(struct video_presenter *presenter)
|
|
|
|
{
|
|
|
|
if (!presenter->thread.hthread)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
PostThreadMessageW(presenter->thread.tid, EVRM_STOP, 0, 0);
|
|
|
|
|
|
|
|
WaitForSingleObject(presenter->thread.hthread, INFINITE);
|
|
|
|
CloseHandle(presenter->thread.hthread);
|
|
|
|
|
2022-02-01 16:59:06 +01:00
|
|
|
TRACE("Terminated streaming thread tid %#lx.\n", presenter->thread.tid);
|
2020-11-17 11:41:40 +01:00
|
|
|
|
2022-02-01 16:59:07 +01:00
|
|
|
if (presenter->thread.queue.last_presented)
|
|
|
|
IMFSample_Release(presenter->thread.queue.last_presented);
|
2020-11-17 11:41:40 +01:00
|
|
|
memset(&presenter->thread, 0, sizeof(presenter->thread));
|
|
|
|
video_presenter_set_allocator_callback(presenter, NULL);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:34:00 +02:00
|
|
|
static HRESULT WINAPI video_presenter_inner_QueryInterface(IUnknown *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IUnknown(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
}
|
|
|
|
else if (IsEqualIID(riid, &IID_IMFClockStateSink)
|
|
|
|
|| IsEqualIID(riid, &IID_IMFVideoPresenter))
|
|
|
|
{
|
|
|
|
*obj = &presenter->IMFVideoPresenter_iface;
|
|
|
|
}
|
2020-06-30 15:34:01 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFVideoDeviceID))
|
|
|
|
{
|
|
|
|
*obj = &presenter->IMFVideoDeviceID_iface;
|
|
|
|
}
|
2020-06-30 15:34:02 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFTopologyServiceLookupClient))
|
|
|
|
{
|
|
|
|
*obj = &presenter->IMFTopologyServiceLookupClient_iface;
|
|
|
|
}
|
2020-06-30 15:34:04 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFVideoDisplayControl))
|
|
|
|
{
|
|
|
|
*obj = &presenter->IMFVideoDisplayControl_iface;
|
|
|
|
}
|
2020-07-01 14:55:42 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFRateSupport))
|
|
|
|
{
|
|
|
|
*obj = &presenter->IMFRateSupport_iface;
|
|
|
|
}
|
2020-10-01 14:59:32 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFGetService))
|
|
|
|
{
|
|
|
|
*obj = &presenter->IMFGetService_iface;
|
|
|
|
}
|
2020-10-22 13:02:48 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFVideoPositionMapper))
|
|
|
|
{
|
|
|
|
*obj = &presenter->IMFVideoPositionMapper_iface;
|
|
|
|
}
|
2020-11-13 13:31:31 +01:00
|
|
|
else if (IsEqualIID(riid, &IID_IQualProp))
|
|
|
|
{
|
|
|
|
*obj = &presenter->IQualProp_iface;
|
|
|
|
}
|
2020-11-13 13:31:33 +01:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFQualityAdvise))
|
|
|
|
{
|
|
|
|
*obj = &presenter->IMFQualityAdvise_iface;
|
|
|
|
}
|
2021-04-16 15:15:57 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFQualityAdviseLimits))
|
|
|
|
{
|
|
|
|
*obj = &presenter->IMFQualityAdviseLimits_iface;
|
|
|
|
}
|
2020-11-17 11:41:38 +01:00
|
|
|
else if (IsEqualIID(riid, &IID_IDirect3DDeviceManager9))
|
|
|
|
{
|
|
|
|
*obj = &presenter->IDirect3DDeviceManager9_iface;
|
|
|
|
}
|
2020-06-30 15:34:00 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Unimplemented interface %s.\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*obj);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_inner_AddRef(IUnknown *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IUnknown(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&presenter->refcount);
|
|
|
|
|
2022-02-01 16:59:06 +01:00
|
|
|
TRACE("%p, refcount %lu.\n", iface, refcount);
|
2020-06-30 15:34:00 +02:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2020-07-01 14:55:44 +02:00
|
|
|
static void video_presenter_clear_container(struct video_presenter *presenter)
|
|
|
|
{
|
|
|
|
if (presenter->clock)
|
|
|
|
IMFClock_Release(presenter->clock);
|
|
|
|
if (presenter->mixer)
|
|
|
|
IMFTransform_Release(presenter->mixer);
|
|
|
|
if (presenter->event_sink)
|
|
|
|
IMediaEventSink_Release(presenter->event_sink);
|
|
|
|
presenter->clock = NULL;
|
|
|
|
presenter->mixer = NULL;
|
|
|
|
presenter->event_sink = NULL;
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:34:00 +02:00
|
|
|
static ULONG WINAPI video_presenter_inner_Release(IUnknown *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IUnknown(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&presenter->refcount);
|
|
|
|
|
2022-02-01 16:59:06 +01:00
|
|
|
TRACE("%p, refcount %lu.\n", iface, refcount);
|
2020-06-30 15:34:00 +02:00
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2020-11-05 16:37:23 +01:00
|
|
|
video_presenter_end_streaming(presenter);
|
2020-07-01 14:55:44 +02:00
|
|
|
video_presenter_clear_container(presenter);
|
2020-11-10 11:07:18 +01:00
|
|
|
video_presenter_reset_media_type(presenter);
|
2020-07-01 14:55:43 +02:00
|
|
|
DeleteCriticalSection(&presenter->cs);
|
2020-11-13 13:31:32 +01:00
|
|
|
if (presenter->swapchain)
|
|
|
|
IDirect3DSwapChain9_Release(presenter->swapchain);
|
2020-10-01 14:59:33 +02:00
|
|
|
if (presenter->device_manager)
|
2020-11-13 13:31:32 +01:00
|
|
|
{
|
|
|
|
IDirect3DDeviceManager9_CloseDeviceHandle(presenter->device_manager, presenter->hdevice);
|
2020-10-01 14:59:33 +02:00
|
|
|
IDirect3DDeviceManager9_Release(presenter->device_manager);
|
2020-11-13 13:31:32 +01:00
|
|
|
}
|
2020-11-10 11:07:18 +01:00
|
|
|
if (presenter->allocator)
|
|
|
|
IMFVideoSampleAllocator_Release(presenter->allocator);
|
2021-04-08 11:18:11 +02:00
|
|
|
free(presenter);
|
2020-06-30 15:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IUnknownVtbl video_presenter_inner_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_inner_QueryInterface,
|
|
|
|
video_presenter_inner_AddRef,
|
|
|
|
video_presenter_inner_Release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_QueryInterface(IMFVideoPresenter *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPresenter(iface);
|
|
|
|
return IUnknown_QueryInterface(presenter->outer_unk, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_AddRef(IMFVideoPresenter *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPresenter(iface);
|
|
|
|
return IUnknown_AddRef(presenter->outer_unk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_Release(IMFVideoPresenter *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPresenter(iface);
|
|
|
|
return IUnknown_Release(presenter->outer_unk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_OnClockStart(IMFVideoPresenter *iface, MFTIME systime, LONGLONG offset)
|
|
|
|
{
|
2020-07-01 14:55:43 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPresenter(iface);
|
2020-06-30 15:34:00 +02:00
|
|
|
|
2020-07-01 14:55:43 +02:00
|
|
|
TRACE("%p, %s, %s.\n", iface, debugstr_time(systime), wine_dbgstr_longlong(offset));
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
presenter->state = PRESENTER_STATE_STARTED;
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return S_OK;
|
2020-06-30 15:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_OnClockStop(IMFVideoPresenter *iface, MFTIME systime)
|
|
|
|
{
|
2020-07-01 14:55:43 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPresenter(iface);
|
2020-06-30 15:34:00 +02:00
|
|
|
|
2020-07-01 14:55:43 +02:00
|
|
|
TRACE("%p, %s.\n", iface, debugstr_time(systime));
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
presenter->state = PRESENTER_STATE_STOPPED;
|
2021-11-03 16:21:07 +01:00
|
|
|
presenter->frame_stats.presented = 0;
|
2020-07-01 14:55:43 +02:00
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return S_OK;
|
2020-06-30 15:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_OnClockPause(IMFVideoPresenter *iface, MFTIME systime)
|
|
|
|
{
|
2020-07-01 14:55:43 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPresenter(iface);
|
2020-06-30 15:34:00 +02:00
|
|
|
|
2020-07-01 14:55:43 +02:00
|
|
|
TRACE("%p, %s.\n", iface, debugstr_time(systime));
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
presenter->state = PRESENTER_STATE_PAUSED;
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return S_OK;
|
2020-06-30 15:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_OnClockRestart(IMFVideoPresenter *iface, MFTIME systime)
|
|
|
|
{
|
2020-07-01 14:55:43 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPresenter(iface);
|
2020-06-30 15:34:00 +02:00
|
|
|
|
2020-07-01 14:55:43 +02:00
|
|
|
TRACE("%p, %s.\n", iface, debugstr_time(systime));
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
presenter->state = PRESENTER_STATE_STARTED;
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return S_OK;
|
2020-06-30 15:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_OnClockSetRate(IMFVideoPresenter *iface, MFTIME systime, float rate)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %f.\n", iface, debugstr_time(systime), rate);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_ProcessMessage(IMFVideoPresenter *iface, MFVP_MESSAGE_TYPE message, ULONG_PTR param)
|
|
|
|
{
|
2020-10-07 10:40:21 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPresenter(iface);
|
|
|
|
HRESULT hr;
|
2020-06-30 15:34:00 +02:00
|
|
|
|
2022-02-01 16:59:06 +01:00
|
|
|
TRACE("%p, %d, %Iu.\n", iface, message, param);
|
2020-10-07 10:40:21 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case MFVP_MESSAGE_INVALIDATEMEDIATYPE:
|
2021-10-28 16:33:19 +02:00
|
|
|
if (presenter->state == PRESENTER_STATE_SHUT_DOWN)
|
|
|
|
hr = MF_E_SHUTDOWN;
|
|
|
|
else if (!presenter->mixer)
|
|
|
|
hr = MF_E_INVALIDREQUEST;
|
|
|
|
else
|
|
|
|
hr = video_presenter_invalidate_media_type(presenter);
|
2020-10-07 10:40:21 +02:00
|
|
|
break;
|
2020-11-05 16:37:23 +01:00
|
|
|
case MFVP_MESSAGE_BEGINSTREAMING:
|
|
|
|
hr = video_presenter_start_streaming(presenter);
|
|
|
|
break;
|
|
|
|
case MFVP_MESSAGE_ENDSTREAMING:
|
|
|
|
hr = video_presenter_end_streaming(presenter);
|
|
|
|
break;
|
2020-11-10 11:07:19 +01:00
|
|
|
case MFVP_MESSAGE_PROCESSINPUTNOTIFY:
|
|
|
|
presenter->flags |= PRESENTER_MIXER_HAS_INPUT;
|
|
|
|
hr = video_presenter_process_input(presenter);
|
|
|
|
break;
|
2020-10-07 10:40:21 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unsupported message %u.\n", message);
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return hr;
|
2020-06-30 15:34:00 +02:00
|
|
|
}
|
|
|
|
|
2020-11-05 16:37:24 +01:00
|
|
|
static HRESULT WINAPI video_presenter_GetCurrentMediaType(IMFVideoPresenter *iface,
|
|
|
|
IMFVideoMediaType **media_type)
|
2020-06-30 15:34:00 +02:00
|
|
|
{
|
2020-11-05 16:37:24 +01:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPresenter(iface);
|
|
|
|
HRESULT hr;
|
2020-06-30 15:34:00 +02:00
|
|
|
|
2020-11-05 16:37:24 +01:00
|
|
|
TRACE("%p, %p.\n", iface, media_type);
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
if (presenter->state == PRESENTER_STATE_SHUT_DOWN)
|
|
|
|
hr = MF_E_SHUTDOWN;
|
|
|
|
else if (!presenter->media_type)
|
|
|
|
hr = MF_E_NOT_INITIALIZED;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = IMFMediaType_QueryInterface(presenter->media_type, &IID_IMFVideoMediaType,
|
|
|
|
(void **)media_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return hr;
|
2020-06-30 15:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFVideoPresenterVtbl video_presenter_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_QueryInterface,
|
|
|
|
video_presenter_AddRef,
|
|
|
|
video_presenter_Release,
|
|
|
|
video_presenter_OnClockStart,
|
|
|
|
video_presenter_OnClockStop,
|
|
|
|
video_presenter_OnClockPause,
|
|
|
|
video_presenter_OnClockRestart,
|
|
|
|
video_presenter_OnClockSetRate,
|
|
|
|
video_presenter_ProcessMessage,
|
|
|
|
video_presenter_GetCurrentMediaType,
|
|
|
|
};
|
|
|
|
|
2020-06-30 15:34:01 +02:00
|
|
|
static HRESULT WINAPI video_presenter_device_id_QueryInterface(IMFVideoDeviceID *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDeviceID(iface);
|
|
|
|
return IMFVideoPresenter_QueryInterface(&presenter->IMFVideoPresenter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_device_id_AddRef(IMFVideoDeviceID *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDeviceID(iface);
|
|
|
|
return IMFVideoPresenter_AddRef(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_device_id_Release(IMFVideoDeviceID *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDeviceID(iface);
|
|
|
|
return IMFVideoPresenter_Release(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_device_id_GetDeviceID(IMFVideoDeviceID *iface, IID *device_id)
|
|
|
|
{
|
|
|
|
TRACE("%p, %p.\n", iface, device_id);
|
|
|
|
|
|
|
|
if (!device_id)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
memcpy(device_id, &IID_IDirect3DDevice9, sizeof(*device_id));
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFVideoDeviceIDVtbl video_presenter_device_id_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_device_id_QueryInterface,
|
|
|
|
video_presenter_device_id_AddRef,
|
|
|
|
video_presenter_device_id_Release,
|
|
|
|
video_presenter_device_id_GetDeviceID,
|
|
|
|
};
|
|
|
|
|
2020-06-30 15:34:02 +02:00
|
|
|
static HRESULT WINAPI video_presenter_service_client_QueryInterface(IMFTopologyServiceLookupClient *iface,
|
|
|
|
REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFTopologyServiceLookupClient(iface);
|
|
|
|
return IMFVideoPresenter_QueryInterface(&presenter->IMFVideoPresenter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_service_client_AddRef(IMFTopologyServiceLookupClient *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFTopologyServiceLookupClient(iface);
|
|
|
|
return IMFVideoPresenter_AddRef(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_service_client_Release(IMFTopologyServiceLookupClient *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFTopologyServiceLookupClient(iface);
|
|
|
|
return IMFVideoPresenter_Release(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
2020-10-05 14:26:44 +02:00
|
|
|
static void video_presenter_set_mixer_rect(struct video_presenter *presenter)
|
|
|
|
{
|
|
|
|
IMFAttributes *attributes;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!presenter->mixer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (SUCCEEDED(IMFTransform_GetAttributes(presenter->mixer, &attributes)))
|
|
|
|
{
|
|
|
|
if (FAILED(hr = IMFAttributes_SetBlob(attributes, &VIDEO_ZOOM_RECT, (const UINT8 *)&presenter->src_rect,
|
|
|
|
sizeof(presenter->src_rect))))
|
|
|
|
{
|
2022-02-01 16:59:06 +01:00
|
|
|
WARN("Failed to set zoom rectangle attribute, hr %#lx.\n", hr);
|
2020-10-05 14:26:44 +02:00
|
|
|
}
|
|
|
|
IMFAttributes_Release(attributes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 14:26:40 +02:00
|
|
|
static HRESULT video_presenter_attach_mixer(struct video_presenter *presenter, IMFTopologyServiceLookup *service_lookup)
|
|
|
|
{
|
|
|
|
IMFVideoDeviceID *device_id;
|
|
|
|
GUID id = { 0 };
|
2022-01-31 15:26:07 +01:00
|
|
|
DWORD count;
|
2020-10-05 14:26:40 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
count = 1;
|
|
|
|
if (FAILED(hr = IMFTopologyServiceLookup_LookupService(service_lookup, MF_SERVICE_LOOKUP_GLOBAL, 0,
|
|
|
|
&MR_VIDEO_MIXER_SERVICE, &IID_IMFTransform, (void **)&presenter->mixer, &count)))
|
|
|
|
{
|
2022-02-01 16:59:06 +01:00
|
|
|
WARN("Failed to get mixer interface, hr %#lx.\n", hr);
|
2020-10-05 14:26:40 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = IMFTransform_QueryInterface(presenter->mixer, &IID_IMFVideoDeviceID, (void **)&device_id)))
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(hr = IMFVideoDeviceID_GetDeviceID(device_id, &id)))
|
|
|
|
{
|
|
|
|
if (!IsEqualGUID(&id, &IID_IDirect3DDevice9))
|
|
|
|
hr = MF_E_INVALIDREQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMFVideoDeviceID_Release(device_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IMFTransform_Release(presenter->mixer);
|
|
|
|
presenter->mixer = NULL;
|
|
|
|
}
|
|
|
|
|
2020-10-05 14:26:44 +02:00
|
|
|
video_presenter_set_mixer_rect(presenter);
|
2020-10-07 10:40:20 +02:00
|
|
|
video_presenter_get_native_video_size(presenter);
|
2020-10-05 14:26:44 +02:00
|
|
|
|
2020-10-05 14:26:40 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:34:02 +02:00
|
|
|
static HRESULT WINAPI video_presenter_service_client_InitServicePointers(IMFTopologyServiceLookupClient *iface,
|
|
|
|
IMFTopologyServiceLookup *service_lookup)
|
|
|
|
{
|
2020-07-01 14:55:44 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFTopologyServiceLookupClient(iface);
|
|
|
|
HRESULT hr = S_OK;
|
2022-01-31 15:26:07 +01:00
|
|
|
DWORD count;
|
2020-06-30 15:34:02 +02:00
|
|
|
|
2020-07-01 14:55:44 +02:00
|
|
|
TRACE("%p, %p.\n", iface, service_lookup);
|
|
|
|
|
|
|
|
if (!service_lookup)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
if (presenter->state == PRESENTER_STATE_STARTED ||
|
|
|
|
presenter->state == PRESENTER_STATE_PAUSED)
|
|
|
|
{
|
|
|
|
hr = MF_E_INVALIDREQUEST;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
video_presenter_clear_container(presenter);
|
|
|
|
|
|
|
|
count = 1;
|
|
|
|
IMFTopologyServiceLookup_LookupService(service_lookup, MF_SERVICE_LOOKUP_GLOBAL, 0,
|
|
|
|
&MR_VIDEO_RENDER_SERVICE, &IID_IMFClock, (void **)&presenter->clock, &count);
|
|
|
|
|
2020-10-05 14:26:40 +02:00
|
|
|
hr = video_presenter_attach_mixer(presenter, service_lookup);
|
2020-07-01 14:55:44 +02:00
|
|
|
|
2020-10-05 14:26:40 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2020-07-01 14:55:44 +02:00
|
|
|
{
|
2020-10-05 14:26:40 +02:00
|
|
|
count = 1;
|
|
|
|
if (FAILED(hr = IMFTopologyServiceLookup_LookupService(service_lookup, MF_SERVICE_LOOKUP_GLOBAL, 0,
|
|
|
|
&MR_VIDEO_RENDER_SERVICE, &IID_IMediaEventSink, (void **)&presenter->event_sink, &count)))
|
|
|
|
{
|
2022-02-01 16:59:06 +01:00
|
|
|
WARN("Failed to get renderer event sink, hr %#lx.\n", hr);
|
2020-10-05 14:26:40 +02:00
|
|
|
}
|
2020-07-01 14:55:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
presenter->state = PRESENTER_STATE_STOPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return hr;
|
2020-06-30 15:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_service_client_ReleaseServicePointers(IMFTopologyServiceLookupClient *iface)
|
|
|
|
{
|
2020-07-01 14:55:43 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFTopologyServiceLookupClient(iface);
|
2020-06-30 15:34:02 +02:00
|
|
|
|
2020-07-01 14:55:43 +02:00
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
2020-07-01 14:55:44 +02:00
|
|
|
|
2020-07-01 14:55:43 +02:00
|
|
|
presenter->state = PRESENTER_STATE_SHUT_DOWN;
|
2020-07-01 14:55:44 +02:00
|
|
|
video_presenter_clear_container(presenter);
|
|
|
|
|
2020-07-01 14:55:43 +02:00
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return S_OK;
|
2020-06-30 15:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFTopologyServiceLookupClientVtbl video_presenter_service_client_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_service_client_QueryInterface,
|
|
|
|
video_presenter_service_client_AddRef,
|
|
|
|
video_presenter_service_client_Release,
|
|
|
|
video_presenter_service_client_InitServicePointers,
|
|
|
|
video_presenter_service_client_ReleaseServicePointers,
|
|
|
|
};
|
|
|
|
|
2020-06-30 15:34:04 +02:00
|
|
|
static HRESULT WINAPI video_presenter_control_QueryInterface(IMFVideoDisplayControl *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
|
|
|
return IMFVideoPresenter_QueryInterface(&presenter->IMFVideoPresenter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_control_AddRef(IMFVideoDisplayControl *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
|
|
|
return IMFVideoPresenter_AddRef(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_control_Release(IMFVideoDisplayControl *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
|
|
|
return IMFVideoPresenter_Release(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_GetNativeVideoSize(IMFVideoDisplayControl *iface, SIZE *video_size,
|
|
|
|
SIZE *aspect_ratio)
|
|
|
|
{
|
2020-10-07 10:40:20 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
2021-10-28 16:33:19 +02:00
|
|
|
HRESULT hr = S_OK;
|
2020-06-30 15:34:04 +02:00
|
|
|
|
2020-10-07 10:40:20 +02:00
|
|
|
TRACE("%p, %p, %p.\n", iface, video_size, aspect_ratio);
|
|
|
|
|
|
|
|
if (!video_size && !aspect_ratio)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
2021-10-28 16:33:19 +02:00
|
|
|
|
|
|
|
if (presenter->state == PRESENTER_STATE_SHUT_DOWN)
|
|
|
|
hr = MF_E_SHUTDOWN;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (video_size)
|
|
|
|
*video_size = presenter->native_size;
|
|
|
|
if (aspect_ratio)
|
|
|
|
*aspect_ratio = presenter->native_ratio;
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:40:20 +02:00
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
2021-10-28 16:33:19 +02:00
|
|
|
return hr;
|
2020-06-30 15:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_GetIdealVideoSize(IMFVideoDisplayControl *iface, SIZE *min_size,
|
|
|
|
SIZE *max_size)
|
|
|
|
{
|
2021-10-28 16:33:19 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
2020-06-30 15:34:04 +02:00
|
|
|
FIXME("%p, %p, %p.\n", iface, min_size, max_size);
|
|
|
|
|
2021-10-28 16:33:19 +02:00
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
if (presenter->state == PRESENTER_STATE_SHUT_DOWN)
|
|
|
|
hr = MF_E_SHUTDOWN;
|
|
|
|
else
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return hr;
|
2020-06-30 15:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_SetVideoPosition(IMFVideoDisplayControl *iface,
|
2020-10-02 13:01:12 +02:00
|
|
|
const MFVideoNormalizedRect *src_rect, const RECT *dst_rect)
|
2020-06-30 15:34:04 +02:00
|
|
|
{
|
2020-10-02 13:01:12 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
2020-10-05 14:26:43 +02:00
|
|
|
HRESULT hr = S_OK;
|
2020-06-30 15:34:04 +02:00
|
|
|
|
2021-10-25 12:05:33 +02:00
|
|
|
TRACE("%p, %s, %s.\n", iface, debugstr_normalized_rect(src_rect), wine_dbgstr_rect(dst_rect));
|
2020-10-02 13:01:12 +02:00
|
|
|
|
|
|
|
if (!src_rect && !dst_rect)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (src_rect && (src_rect->left < 0.0f || src_rect->top < 0.0f ||
|
2020-10-05 14:26:42 +02:00
|
|
|
src_rect->right > 1.0f || src_rect->bottom > 1.0f ||
|
|
|
|
src_rect->left > src_rect->right ||
|
|
|
|
src_rect->top > src_rect->bottom))
|
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dst_rect && (dst_rect->left > dst_rect->right ||
|
|
|
|
dst_rect->top > dst_rect->bottom))
|
2020-10-02 13:01:12 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
2020-10-05 14:26:43 +02:00
|
|
|
if (!presenter->video_window)
|
|
|
|
hr = E_POINTER;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (src_rect)
|
2020-10-05 14:26:44 +02:00
|
|
|
{
|
|
|
|
if (memcmp(&presenter->src_rect, src_rect, sizeof(*src_rect)))
|
|
|
|
{
|
|
|
|
presenter->src_rect = *src_rect;
|
|
|
|
video_presenter_set_mixer_rect(presenter);
|
|
|
|
}
|
|
|
|
}
|
2021-10-26 18:58:31 +02:00
|
|
|
if (dst_rect && !EqualRect(dst_rect, &presenter->dst_rect))
|
|
|
|
{
|
2020-10-05 14:26:43 +02:00
|
|
|
presenter->dst_rect = *dst_rect;
|
2021-10-26 18:58:31 +02:00
|
|
|
hr = video_presenter_invalidate_media_type(presenter);
|
|
|
|
/* Mixer's input type hasn't been configured yet, this is not an error. */
|
|
|
|
if (hr == MF_E_TRANSFORM_TYPE_NOT_SET) hr = S_OK;
|
|
|
|
/* FIXME: trigger repaint */
|
|
|
|
}
|
2020-10-05 14:26:43 +02:00
|
|
|
}
|
2020-10-02 13:01:12 +02:00
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
2020-10-05 14:26:43 +02:00
|
|
|
return hr;
|
2020-06-30 15:34:04 +02:00
|
|
|
}
|
|
|
|
|
2020-10-02 13:01:12 +02:00
|
|
|
static HRESULT WINAPI video_presenter_control_GetVideoPosition(IMFVideoDisplayControl *iface, MFVideoNormalizedRect *src_rect,
|
|
|
|
RECT *dst_rect)
|
2020-06-30 15:34:04 +02:00
|
|
|
{
|
2020-10-02 13:01:12 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
2020-06-30 15:34:04 +02:00
|
|
|
|
2020-10-02 13:01:12 +02:00
|
|
|
TRACE("%p, %p, %p.\n", iface, src_rect, dst_rect);
|
|
|
|
|
|
|
|
if (!src_rect || !dst_rect)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
*src_rect = presenter->src_rect;
|
|
|
|
*dst_rect = presenter->dst_rect;
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return S_OK;
|
2020-06-30 15:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_SetAspectRatioMode(IMFVideoDisplayControl *iface, DWORD mode)
|
|
|
|
{
|
2020-10-07 10:40:22 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
2020-06-30 15:34:04 +02:00
|
|
|
|
2022-02-01 16:59:06 +01:00
|
|
|
TRACE("%p, %#lx.\n", iface, mode);
|
2020-10-07 10:40:22 +02:00
|
|
|
|
|
|
|
if (mode & ~MFVideoARMode_Mask)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
presenter->ar_mode = mode;
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return S_OK;
|
2020-06-30 15:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_GetAspectRatioMode(IMFVideoDisplayControl *iface, DWORD *mode)
|
|
|
|
{
|
2020-10-07 10:40:22 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
2020-06-30 15:34:04 +02:00
|
|
|
|
2020-10-07 10:40:22 +02:00
|
|
|
TRACE("%p, %p.\n", iface, mode);
|
|
|
|
|
|
|
|
if (!mode)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
*mode = presenter->ar_mode;
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return S_OK;
|
2020-06-30 15:34:04 +02:00
|
|
|
}
|
|
|
|
|
2020-11-13 13:31:32 +01:00
|
|
|
static HRESULT video_presenter_create_swapchain(struct video_presenter *presenter)
|
|
|
|
{
|
|
|
|
D3DPRESENT_PARAMETERS present_params = { 0 };
|
|
|
|
IDirect3DDevice9 *d3d_device;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = video_presenter_get_device(presenter, &d3d_device)))
|
|
|
|
{
|
|
|
|
present_params.hDeviceWindow = presenter->video_window;
|
|
|
|
present_params.Windowed = TRUE;
|
|
|
|
present_params.SwapEffect = D3DSWAPEFFECT_COPY;
|
|
|
|
present_params.Flags = D3DPRESENTFLAG_VIDEO;
|
|
|
|
present_params.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
|
|
|
hr = IDirect3DDevice9_CreateAdditionalSwapChain(d3d_device, &present_params, &presenter->swapchain);
|
|
|
|
|
|
|
|
IDirect3DDevice9_Release(d3d_device);
|
|
|
|
IDirect3DDeviceManager9_UnlockDevice(presenter->device_manager, presenter->hdevice, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:34:04 +02:00
|
|
|
static HRESULT WINAPI video_presenter_control_SetVideoWindow(IMFVideoDisplayControl *iface, HWND window)
|
|
|
|
{
|
2020-10-02 13:01:11 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
2020-11-13 13:31:32 +01:00
|
|
|
HRESULT hr = S_OK;
|
2020-06-30 15:34:04 +02:00
|
|
|
|
2020-10-02 13:01:11 +02:00
|
|
|
TRACE("%p, %p.\n", iface, window);
|
|
|
|
|
2020-10-06 13:48:59 +02:00
|
|
|
if (!IsWindow(window))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2020-10-02 13:01:11 +02:00
|
|
|
EnterCriticalSection(&presenter->cs);
|
2020-11-13 13:31:32 +01:00
|
|
|
if (presenter->video_window != window)
|
|
|
|
{
|
|
|
|
if (presenter->swapchain)
|
|
|
|
IDirect3DSwapChain9_Release(presenter->swapchain);
|
|
|
|
presenter->video_window = window;
|
|
|
|
hr = video_presenter_create_swapchain(presenter);
|
|
|
|
}
|
2020-10-02 13:01:11 +02:00
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
2020-11-13 13:31:32 +01:00
|
|
|
return hr;
|
2020-06-30 15:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_GetVideoWindow(IMFVideoDisplayControl *iface, HWND *window)
|
|
|
|
{
|
2020-10-02 13:01:11 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
2020-06-30 15:34:04 +02:00
|
|
|
|
2020-10-02 13:01:11 +02:00
|
|
|
TRACE("%p, %p.\n", iface, window);
|
|
|
|
|
2020-10-06 13:48:58 +02:00
|
|
|
if (!window)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
2020-10-02 13:01:11 +02:00
|
|
|
*window = presenter->video_window;
|
2020-10-06 13:48:58 +02:00
|
|
|
LeaveCriticalSection(&presenter->cs);
|
2020-10-02 13:01:11 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2020-06-30 15:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_RepaintVideo(IMFVideoDisplayControl *iface)
|
|
|
|
{
|
2021-10-28 16:33:19 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
2020-06-30 15:34:04 +02:00
|
|
|
FIXME("%p.\n", iface);
|
|
|
|
|
2021-10-28 16:33:19 +02:00
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
if (presenter->state == PRESENTER_STATE_SHUT_DOWN)
|
|
|
|
hr = MF_E_SHUTDOWN;
|
|
|
|
else
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return hr;
|
2020-06-30 15:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_GetCurrentImage(IMFVideoDisplayControl *iface, BITMAPINFOHEADER *header,
|
|
|
|
BYTE **dib, DWORD *dib_size, LONGLONG *timestamp)
|
|
|
|
{
|
2022-02-01 16:59:07 +01:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
|
|
|
IDirect3DSurface9 *readback = NULL, *surface;
|
|
|
|
D3DSURFACE_DESC surface_desc;
|
|
|
|
D3DLOCKED_RECT mapped_rect;
|
|
|
|
IDirect3DDevice9 *device;
|
|
|
|
IMFSample *sample;
|
|
|
|
LONG stride;
|
|
|
|
HRESULT hr;
|
2020-06-30 15:34:04 +02:00
|
|
|
|
2022-02-01 16:59:07 +01:00
|
|
|
TRACE("%p, %p, %p, %p, %p.\n", iface, header, dib, dib_size, timestamp);
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
sample = presenter->thread.queue.last_presented;
|
|
|
|
presenter->thread.queue.last_presented = NULL;
|
|
|
|
|
|
|
|
if (!presenter->swapchain || !sample)
|
|
|
|
{
|
|
|
|
hr = MF_E_INVALIDREQUEST;
|
|
|
|
}
|
|
|
|
else if (SUCCEEDED(hr = video_presenter_get_sample_surface(sample, &surface)))
|
|
|
|
{
|
|
|
|
IDirect3DSwapChain9_GetDevice(presenter->swapchain, &device);
|
|
|
|
IDirect3DSurface9_GetDesc(surface, &surface_desc);
|
|
|
|
|
|
|
|
if (surface_desc.Format != D3DFMT_X8R8G8B8)
|
|
|
|
{
|
|
|
|
FIXME("Unexpected surface format %d.\n", surface_desc.Format);
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (FAILED(hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, surface_desc.Width,
|
|
|
|
surface_desc.Height, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &readback, NULL)))
|
|
|
|
{
|
|
|
|
WARN("Failed to create readback surface, hr %#lx.\n", hr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IDirect3DDevice9_GetRenderTargetData(device, surface, readback);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
MFGetStrideForBitmapInfoHeader(D3DFMT_X8R8G8B8, surface_desc.Width, &stride);
|
|
|
|
*dib_size = abs(stride) * surface_desc.Height;
|
|
|
|
if (!(*dib = CoTaskMemAlloc(*dib_size)))
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(hr = IDirect3DSurface9_LockRect(readback, &mapped_rect, NULL, D3DLOCK_READONLY)))
|
|
|
|
{
|
|
|
|
memcpy(*dib, mapped_rect.pBits, *dib_size);
|
|
|
|
IDirect3DSurface9_UnlockRect(readback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(header, 0, sizeof(*header));
|
|
|
|
header->biSize = sizeof(*header);
|
|
|
|
header->biWidth = surface_desc.Width;
|
|
|
|
header->biHeight = surface_desc.Height;
|
|
|
|
header->biPlanes = 1;
|
|
|
|
header->biBitCount = 32;
|
|
|
|
header->biSizeImage = *dib_size;
|
|
|
|
IMFSample_GetSampleTime(sample, timestamp);
|
|
|
|
|
|
|
|
if (readback)
|
|
|
|
IDirect3DSurface9_Release(readback);
|
|
|
|
IDirect3DSurface9_Release(surface);
|
|
|
|
|
|
|
|
IDirect3DDevice9_Release(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sample)
|
|
|
|
IMFSample_Release(sample);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return hr;
|
2020-06-30 15:34:04 +02:00
|
|
|
}
|
|
|
|
|
2020-10-02 13:01:13 +02:00
|
|
|
static HRESULT WINAPI video_presenter_control_SetBorderColor(IMFVideoDisplayControl *iface, COLORREF color)
|
|
|
|
{
|
2022-02-01 16:59:06 +01:00
|
|
|
FIXME("%p, %#lx.\n", iface, color);
|
2020-10-02 13:01:13 +02:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_GetBorderColor(IMFVideoDisplayControl *iface, COLORREF *color)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, color);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_SetRenderingPrefs(IMFVideoDisplayControl *iface, DWORD flags)
|
|
|
|
{
|
2022-02-01 16:59:06 +01:00
|
|
|
FIXME("%p, %#lx.\n", iface, flags);
|
2020-10-02 13:01:13 +02:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_GetRenderingPrefs(IMFVideoDisplayControl *iface, DWORD *flags)
|
|
|
|
{
|
2020-10-06 13:48:57 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoDisplayControl(iface);
|
2020-10-02 13:01:13 +02:00
|
|
|
|
2020-10-06 13:48:57 +02:00
|
|
|
TRACE("%p, %p.\n", iface, flags);
|
|
|
|
|
|
|
|
if (!flags)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
*flags = presenter->rendering_prefs;
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return S_OK;
|
2020-10-02 13:01:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_SetFullscreen(IMFVideoDisplayControl *iface, BOOL fullscreen)
|
|
|
|
{
|
|
|
|
FIXME("%p, %d.\n", iface, fullscreen);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_control_GetFullscreen(IMFVideoDisplayControl *iface, BOOL *fullscreen)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, fullscreen);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:34:04 +02:00
|
|
|
static const IMFVideoDisplayControlVtbl video_presenter_control_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_control_QueryInterface,
|
|
|
|
video_presenter_control_AddRef,
|
|
|
|
video_presenter_control_Release,
|
|
|
|
video_presenter_control_GetNativeVideoSize,
|
|
|
|
video_presenter_control_GetIdealVideoSize,
|
|
|
|
video_presenter_control_SetVideoPosition,
|
|
|
|
video_presenter_control_GetVideoPosition,
|
|
|
|
video_presenter_control_SetAspectRatioMode,
|
|
|
|
video_presenter_control_GetAspectRatioMode,
|
|
|
|
video_presenter_control_SetVideoWindow,
|
|
|
|
video_presenter_control_GetVideoWindow,
|
|
|
|
video_presenter_control_RepaintVideo,
|
|
|
|
video_presenter_control_GetCurrentImage,
|
2020-10-02 13:01:13 +02:00
|
|
|
video_presenter_control_SetBorderColor,
|
|
|
|
video_presenter_control_GetBorderColor,
|
|
|
|
video_presenter_control_SetRenderingPrefs,
|
|
|
|
video_presenter_control_GetRenderingPrefs,
|
|
|
|
video_presenter_control_SetFullscreen,
|
|
|
|
video_presenter_control_GetFullscreen,
|
2020-06-30 15:34:04 +02:00
|
|
|
};
|
|
|
|
|
2020-07-01 14:55:42 +02:00
|
|
|
static HRESULT WINAPI video_presenter_rate_support_QueryInterface(IMFRateSupport *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFRateSupport(iface);
|
|
|
|
return IMFVideoPresenter_QueryInterface(&presenter->IMFVideoPresenter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_rate_support_AddRef(IMFRateSupport *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFRateSupport(iface);
|
|
|
|
return IMFVideoPresenter_AddRef(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_rate_support_Release(IMFRateSupport *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFRateSupport(iface);
|
|
|
|
return IMFVideoPresenter_Release(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_rate_support_GetSlowestRate(IMFRateSupport *iface, MFRATE_DIRECTION direction,
|
|
|
|
BOOL thin, float *rate)
|
|
|
|
{
|
|
|
|
TRACE("%p, %d, %d, %p.\n", iface, direction, thin, rate);
|
|
|
|
|
|
|
|
*rate = 0.0f;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_rate_support_GetFastestRate(IMFRateSupport *iface, MFRATE_DIRECTION direction,
|
|
|
|
BOOL thin, float *rate)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_rate_support_IsRateSupported(IMFRateSupport *iface, BOOL thin, float rate,
|
|
|
|
float *nearest_supported_rate)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFRateSupportVtbl video_presenter_rate_support_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_rate_support_QueryInterface,
|
|
|
|
video_presenter_rate_support_AddRef,
|
|
|
|
video_presenter_rate_support_Release,
|
|
|
|
video_presenter_rate_support_GetSlowestRate,
|
|
|
|
video_presenter_rate_support_GetFastestRate,
|
|
|
|
video_presenter_rate_support_IsRateSupported,
|
|
|
|
};
|
|
|
|
|
2020-10-01 14:59:32 +02:00
|
|
|
static HRESULT WINAPI video_presenter_getservice_QueryInterface(IMFGetService *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFGetService(iface);
|
|
|
|
return IMFVideoPresenter_QueryInterface(&presenter->IMFVideoPresenter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_getservice_AddRef(IMFGetService *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFGetService(iface);
|
|
|
|
return IMFVideoPresenter_AddRef(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_getservice_Release(IMFGetService *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFGetService(iface);
|
|
|
|
return IMFVideoPresenter_Release(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_getservice_GetService(IMFGetService *iface, REFGUID service, REFIID riid, void **obj)
|
|
|
|
{
|
2020-10-01 14:59:33 +02:00
|
|
|
struct video_presenter *presenter = impl_from_IMFGetService(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %s, %s, %p.\n", iface, debugstr_guid(service), debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualGUID(&MR_VIDEO_ACCELERATION_SERVICE, service))
|
|
|
|
return IDirect3DDeviceManager9_QueryInterface(presenter->device_manager, riid, obj);
|
|
|
|
|
2020-10-02 13:01:10 +02:00
|
|
|
if (IsEqualGUID(&MR_VIDEO_RENDER_SERVICE, service))
|
2020-11-16 15:50:23 +01:00
|
|
|
return IMFVideoPresenter_QueryInterface(&presenter->IMFVideoPresenter_iface, riid, obj);
|
2020-10-02 13:01:10 +02:00
|
|
|
|
2020-10-01 14:59:33 +02:00
|
|
|
FIXME("Unimplemented service %s.\n", debugstr_guid(service));
|
2020-10-01 14:59:32 +02:00
|
|
|
|
2020-11-17 11:41:37 +01:00
|
|
|
return MF_E_UNSUPPORTED_SERVICE;
|
2020-10-01 14:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFGetServiceVtbl video_presenter_getservice_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_getservice_QueryInterface,
|
|
|
|
video_presenter_getservice_AddRef,
|
|
|
|
video_presenter_getservice_Release,
|
|
|
|
video_presenter_getservice_GetService,
|
|
|
|
};
|
|
|
|
|
2020-10-22 13:02:48 +02:00
|
|
|
static HRESULT WINAPI video_presenter_position_mapper_QueryInterface(IMFVideoPositionMapper *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPositionMapper(iface);
|
|
|
|
return IMFVideoPresenter_QueryInterface(&presenter->IMFVideoPresenter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_position_mapper_AddRef(IMFVideoPositionMapper *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPositionMapper(iface);
|
|
|
|
return IMFVideoPresenter_AddRef(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_position_mapper_Release(IMFVideoPositionMapper *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoPositionMapper(iface);
|
|
|
|
return IMFVideoPresenter_Release(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_position_mapper_MapOutputCoordinateToInputStream(IMFVideoPositionMapper *iface,
|
|
|
|
float x_out, float y_out, DWORD output_stream, DWORD input_stream, float *x_in, float *y_in)
|
|
|
|
{
|
2022-02-01 16:59:06 +01:00
|
|
|
FIXME("%p, %f, %f, %lu, %lu, %p, %p.\n", iface, x_out, y_out, output_stream, input_stream, x_in, y_in);
|
2020-10-22 13:02:48 +02:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFVideoPositionMapperVtbl video_presenter_position_mapper_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_position_mapper_QueryInterface,
|
|
|
|
video_presenter_position_mapper_AddRef,
|
|
|
|
video_presenter_position_mapper_Release,
|
|
|
|
video_presenter_position_mapper_MapOutputCoordinateToInputStream,
|
|
|
|
};
|
|
|
|
|
2020-11-10 11:07:21 +01:00
|
|
|
static HRESULT WINAPI video_presenter_allocator_cb_QueryInterface(IMFVideoSampleAllocatorNotify *iface,
|
|
|
|
REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, &IID_IMFVideoSampleAllocatorNotify) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IMFVideoSampleAllocatorNotify_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unsupported interface %s.\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_allocator_cb_AddRef(IMFVideoSampleAllocatorNotify *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoSampleAllocatorNotify(iface);
|
|
|
|
return IMFVideoPresenter_AddRef(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_allocator_cb_Release(IMFVideoSampleAllocatorNotify *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoSampleAllocatorNotify(iface);
|
|
|
|
return IMFVideoPresenter_Release(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_allocator_cb_NotifyRelease(IMFVideoSampleAllocatorNotify *iface)
|
|
|
|
{
|
2020-11-17 11:41:40 +01:00
|
|
|
struct video_presenter *presenter = impl_from_IMFVideoSampleAllocatorNotify(iface);
|
|
|
|
|
|
|
|
/* Release notification is executed under allocator lock, instead of processing samples here
|
|
|
|
notify streaming thread. */
|
|
|
|
PostThreadMessageW(presenter->thread.tid, EVRM_PROCESS_INPUT, 0, 0);
|
|
|
|
|
|
|
|
return S_OK;
|
2020-11-10 11:07:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFVideoSampleAllocatorNotifyVtbl video_presenter_allocator_cb_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_allocator_cb_QueryInterface,
|
|
|
|
video_presenter_allocator_cb_AddRef,
|
|
|
|
video_presenter_allocator_cb_Release,
|
|
|
|
video_presenter_allocator_cb_NotifyRelease,
|
|
|
|
};
|
|
|
|
|
2020-11-13 13:31:31 +01:00
|
|
|
static HRESULT WINAPI video_presenter_qualprop_QueryInterface(IQualProp *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IQualProp(iface);
|
|
|
|
return IMFVideoPresenter_QueryInterface(&presenter->IMFVideoPresenter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_qualprop_AddRef(IQualProp *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IQualProp(iface);
|
|
|
|
return IMFVideoPresenter_AddRef(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_qualprop_Release(IQualProp *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IQualProp(iface);
|
|
|
|
return IMFVideoPresenter_Release(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_qualprop_get_FramesDroppedInRenderer(IQualProp *iface, int *frames)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p stub.\n", iface, frames);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_qualprop_get_FramesDrawn(IQualProp *iface, int *frames)
|
|
|
|
{
|
2021-11-03 16:21:07 +01:00
|
|
|
struct video_presenter *presenter = impl_from_IQualProp(iface);
|
|
|
|
HRESULT hr = S_OK;
|
2020-11-13 13:31:31 +01:00
|
|
|
|
2021-11-03 16:21:07 +01:00
|
|
|
TRACE("%p, %p.\n", iface, frames);
|
|
|
|
|
|
|
|
EnterCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
switch (presenter->state)
|
|
|
|
{
|
|
|
|
case PRESENTER_STATE_STARTED:
|
|
|
|
case PRESENTER_STATE_PAUSED:
|
|
|
|
if (frames) *frames = presenter->frame_stats.presented;
|
|
|
|
else hr = E_POINTER;
|
2021-11-08 12:57:03 +01:00
|
|
|
break;
|
2021-11-03 16:21:07 +01:00
|
|
|
default:
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&presenter->cs);
|
|
|
|
|
|
|
|
return hr;
|
2020-11-13 13:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_qualprop_get_AvgFrameRate(IQualProp *iface, int *avg_frame_rate)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p stub.\n", iface, avg_frame_rate);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_qualprop_get_Jitter(IQualProp *iface, int *jitter)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p stub.\n", iface, jitter);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_qualprop_get_AvgSyncOffset(IQualProp *iface, int *offset)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p stub.\n", iface, offset);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_qualprop_get_DevSyncOffset(IQualProp *iface, int *devoffset)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p stub.\n", iface, devoffset);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IQualPropVtbl video_presenter_qualprop_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_qualprop_QueryInterface,
|
|
|
|
video_presenter_qualprop_AddRef,
|
|
|
|
video_presenter_qualprop_Release,
|
|
|
|
video_presenter_qualprop_get_FramesDroppedInRenderer,
|
|
|
|
video_presenter_qualprop_get_FramesDrawn,
|
|
|
|
video_presenter_qualprop_get_AvgFrameRate,
|
|
|
|
video_presenter_qualprop_get_Jitter,
|
|
|
|
video_presenter_qualprop_get_AvgSyncOffset,
|
|
|
|
video_presenter_qualprop_get_DevSyncOffset,
|
|
|
|
};
|
|
|
|
|
2020-11-13 13:31:33 +01:00
|
|
|
static HRESULT WINAPI video_presenter_quality_advise_QueryInterface(IMFQualityAdvise *iface, REFIID riid, void **out)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFQualityAdvise(iface);
|
|
|
|
return IMFVideoPresenter_QueryInterface(&presenter->IMFVideoPresenter_iface, riid, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_quality_advise_AddRef(IMFQualityAdvise *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFQualityAdvise(iface);
|
|
|
|
return IMFVideoPresenter_AddRef(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_quality_advise_Release(IMFQualityAdvise *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFQualityAdvise(iface);
|
|
|
|
return IMFVideoPresenter_Release(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_quality_advise_SetDropMode(IMFQualityAdvise *iface,
|
|
|
|
MF_QUALITY_DROP_MODE mode)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u.\n", iface, mode);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_quality_advise_SetQualityLevel(IMFQualityAdvise *iface,
|
|
|
|
MF_QUALITY_LEVEL level)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u.\n", iface, level);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_quality_advise_GetDropMode(IMFQualityAdvise *iface,
|
|
|
|
MF_QUALITY_DROP_MODE *mode)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, mode);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_quality_advise_GetQualityLevel(IMFQualityAdvise *iface,
|
|
|
|
MF_QUALITY_LEVEL *level)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, level);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_quality_advise_DropTime(IMFQualityAdvise *iface, LONGLONG interval)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s.\n", iface, wine_dbgstr_longlong(interval));
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFQualityAdviseVtbl video_presenter_quality_advise_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_quality_advise_QueryInterface,
|
|
|
|
video_presenter_quality_advise_AddRef,
|
|
|
|
video_presenter_quality_advise_Release,
|
|
|
|
video_presenter_quality_advise_SetDropMode,
|
|
|
|
video_presenter_quality_advise_SetQualityLevel,
|
|
|
|
video_presenter_quality_advise_GetDropMode,
|
|
|
|
video_presenter_quality_advise_GetQualityLevel,
|
|
|
|
video_presenter_quality_advise_DropTime,
|
|
|
|
};
|
|
|
|
|
2020-11-17 11:41:38 +01:00
|
|
|
static HRESULT WINAPI video_presenter_device_manager_QueryInterface(IDirect3DDeviceManager9 *iface,
|
|
|
|
REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IDirect3DDeviceManager9(iface);
|
|
|
|
return IMFVideoPresenter_QueryInterface(&presenter->IMFVideoPresenter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_device_manager_AddRef(IDirect3DDeviceManager9 *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IDirect3DDeviceManager9(iface);
|
|
|
|
return IMFVideoPresenter_AddRef(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_device_manager_Release(IDirect3DDeviceManager9 *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IDirect3DDeviceManager9(iface);
|
|
|
|
return IMFVideoPresenter_Release(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_device_manager_ResetDevice(IDirect3DDeviceManager9 *iface,
|
|
|
|
IDirect3DDevice9 *device, UINT token)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IDirect3DDeviceManager9(iface);
|
|
|
|
return IDirect3DDeviceManager9_ResetDevice(presenter->device_manager, device, token);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_device_manager_OpenDeviceHandle(IDirect3DDeviceManager9 *iface, HANDLE *hdevice)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IDirect3DDeviceManager9(iface);
|
|
|
|
return IDirect3DDeviceManager9_OpenDeviceHandle(presenter->device_manager, hdevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_device_manager_CloseDeviceHandle(IDirect3DDeviceManager9 *iface, HANDLE hdevice)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IDirect3DDeviceManager9(iface);
|
|
|
|
return IDirect3DDeviceManager9_CloseDeviceHandle(presenter->device_manager, hdevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_device_manager_TestDevice(IDirect3DDeviceManager9 *iface, HANDLE hdevice)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IDirect3DDeviceManager9(iface);
|
|
|
|
return IDirect3DDeviceManager9_TestDevice(presenter->device_manager, hdevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_device_manager_LockDevice(IDirect3DDeviceManager9 *iface, HANDLE hdevice,
|
|
|
|
IDirect3DDevice9 **device, BOOL block)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IDirect3DDeviceManager9(iface);
|
|
|
|
return IDirect3DDeviceManager9_LockDevice(presenter->device_manager, hdevice, device, block);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_device_manager_UnlockDevice(IDirect3DDeviceManager9 *iface, HANDLE hdevice,
|
|
|
|
BOOL savestate)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IDirect3DDeviceManager9(iface);
|
|
|
|
return IDirect3DDeviceManager9_UnlockDevice(presenter->device_manager, hdevice, savestate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_device_manager_GetVideoService(IDirect3DDeviceManager9 *iface, HANDLE hdevice,
|
|
|
|
REFIID riid, void **service)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IDirect3DDeviceManager9(iface);
|
|
|
|
return IDirect3DDeviceManager9_GetVideoService(presenter->device_manager, hdevice, riid, service);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IDirect3DDeviceManager9Vtbl video_presenter_device_manager_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_device_manager_QueryInterface,
|
|
|
|
video_presenter_device_manager_AddRef,
|
|
|
|
video_presenter_device_manager_Release,
|
|
|
|
video_presenter_device_manager_ResetDevice,
|
|
|
|
video_presenter_device_manager_OpenDeviceHandle,
|
|
|
|
video_presenter_device_manager_CloseDeviceHandle,
|
|
|
|
video_presenter_device_manager_TestDevice,
|
|
|
|
video_presenter_device_manager_LockDevice,
|
|
|
|
video_presenter_device_manager_UnlockDevice,
|
|
|
|
video_presenter_device_manager_GetVideoService,
|
|
|
|
};
|
|
|
|
|
2021-04-16 15:15:57 +02:00
|
|
|
static HRESULT WINAPI video_presenter_qa_limits_QueryInterface(IMFQualityAdviseLimits *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFQualityAdviseLimits(iface);
|
|
|
|
return IMFVideoPresenter_QueryInterface(&presenter->IMFVideoPresenter_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_qa_limits_AddRef(IMFQualityAdviseLimits *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFQualityAdviseLimits(iface);
|
|
|
|
return IMFVideoPresenter_AddRef(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI video_presenter_qa_limits_Release(IMFQualityAdviseLimits *iface)
|
|
|
|
{
|
|
|
|
struct video_presenter *presenter = impl_from_IMFQualityAdviseLimits(iface);
|
|
|
|
return IMFVideoPresenter_Release(&presenter->IMFVideoPresenter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_qa_limits_GetMaximumDropMode(IMFQualityAdviseLimits *iface, MF_QUALITY_DROP_MODE *mode)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, mode);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI video_presenter_qa_limits_GetMinimumQualityLevel(IMFQualityAdviseLimits *iface, MF_QUALITY_LEVEL *level)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, level);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFQualityAdviseLimitsVtbl video_presenter_qa_limits_vtbl =
|
|
|
|
{
|
|
|
|
video_presenter_qa_limits_QueryInterface,
|
|
|
|
video_presenter_qa_limits_AddRef,
|
|
|
|
video_presenter_qa_limits_Release,
|
|
|
|
video_presenter_qa_limits_GetMaximumDropMode,
|
|
|
|
video_presenter_qa_limits_GetMinimumQualityLevel,
|
|
|
|
};
|
|
|
|
|
2020-06-30 15:34:00 +02:00
|
|
|
HRESULT WINAPI MFCreateVideoPresenter(IUnknown *owner, REFIID riid_device, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
TRACE("%p, %s, %s, %p.\n", owner, debugstr_guid(riid_device), debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
|
|
|
|
if (!IsEqualIID(riid_device, &IID_IDirect3DDevice9))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
return CoCreateInstance(&CLSID_MFVideoPresenter9, owner, CLSCTX_INPROC_SERVER, riid, obj);
|
|
|
|
}
|
|
|
|
|
2020-10-02 13:01:09 +02:00
|
|
|
static HRESULT video_presenter_init_d3d(struct video_presenter *presenter)
|
|
|
|
{
|
|
|
|
D3DPRESENT_PARAMETERS present_params = { 0 };
|
|
|
|
IDirect3DDevice9 *device;
|
|
|
|
IDirect3D9 *d3d;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
|
|
|
|
|
|
|
present_params.BackBufferCount = 1;
|
|
|
|
present_params.SwapEffect = D3DSWAPEFFECT_COPY;
|
|
|
|
present_params.hDeviceWindow = GetDesktopWindow();
|
|
|
|
present_params.Windowed = TRUE;
|
|
|
|
present_params.Flags = D3DPRESENTFLAG_VIDEO;
|
|
|
|
present_params.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
|
|
|
hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, GetDesktopWindow(),
|
2021-04-16 15:15:58 +02:00
|
|
|
D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_params, &device);
|
2020-10-02 13:01:09 +02:00
|
|
|
|
|
|
|
IDirect3D9_Release(d3d);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-01 16:59:06 +01:00
|
|
|
WARN("Failed to create d3d device, hr %#lx.\n", hr);
|
2020-10-02 13:01:09 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDirect3DDeviceManager9_ResetDevice(presenter->device_manager, device, presenter->reset_token);
|
|
|
|
IDirect3DDevice9_Release(device);
|
|
|
|
if (FAILED(hr))
|
2022-02-01 16:59:06 +01:00
|
|
|
WARN("Failed to set new device for the manager, hr %#lx.\n", hr);
|
2020-10-02 13:01:09 +02:00
|
|
|
|
2020-11-10 11:07:18 +01:00
|
|
|
if (SUCCEEDED(hr = MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocator, (void **)&presenter->allocator)))
|
|
|
|
{
|
|
|
|
hr = IMFVideoSampleAllocator_SetDirectXManager(presenter->allocator, (IUnknown *)presenter->device_manager);
|
|
|
|
}
|
|
|
|
|
2020-10-02 13:01:09 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:34:00 +02:00
|
|
|
HRESULT evr_presenter_create(IUnknown *outer, void **out)
|
|
|
|
{
|
|
|
|
struct video_presenter *object;
|
2020-10-01 14:59:33 +02:00
|
|
|
HRESULT hr;
|
2020-06-30 15:34:00 +02:00
|
|
|
|
2020-10-02 13:01:09 +02:00
|
|
|
*out = NULL;
|
|
|
|
|
2021-04-08 11:18:11 +02:00
|
|
|
if (!(object = calloc(1, sizeof(*object))))
|
2020-06-30 15:34:00 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->IMFVideoPresenter_iface.lpVtbl = &video_presenter_vtbl;
|
2020-06-30 15:34:01 +02:00
|
|
|
object->IMFVideoDeviceID_iface.lpVtbl = &video_presenter_device_id_vtbl;
|
2020-06-30 15:34:02 +02:00
|
|
|
object->IMFTopologyServiceLookupClient_iface.lpVtbl = &video_presenter_service_client_vtbl;
|
2020-06-30 15:34:04 +02:00
|
|
|
object->IMFVideoDisplayControl_iface.lpVtbl = &video_presenter_control_vtbl;
|
2020-07-01 14:55:42 +02:00
|
|
|
object->IMFRateSupport_iface.lpVtbl = &video_presenter_rate_support_vtbl;
|
2020-10-01 14:59:32 +02:00
|
|
|
object->IMFGetService_iface.lpVtbl = &video_presenter_getservice_vtbl;
|
2020-10-22 13:02:48 +02:00
|
|
|
object->IMFVideoPositionMapper_iface.lpVtbl = &video_presenter_position_mapper_vtbl;
|
2020-11-13 13:31:31 +01:00
|
|
|
object->IQualProp_iface.lpVtbl = &video_presenter_qualprop_vtbl;
|
2020-11-13 13:31:33 +01:00
|
|
|
object->IMFQualityAdvise_iface.lpVtbl = &video_presenter_quality_advise_vtbl;
|
2021-04-16 15:15:57 +02:00
|
|
|
object->IMFQualityAdviseLimits_iface.lpVtbl = &video_presenter_qa_limits_vtbl;
|
2020-11-10 11:07:21 +01:00
|
|
|
object->allocator_cb.lpVtbl = &video_presenter_allocator_cb_vtbl;
|
2020-06-30 15:34:00 +02:00
|
|
|
object->IUnknown_inner.lpVtbl = &video_presenter_inner_vtbl;
|
2020-11-17 11:41:38 +01:00
|
|
|
object->IDirect3DDeviceManager9_iface.lpVtbl = &video_presenter_device_manager_vtbl;
|
2020-06-30 15:34:00 +02:00
|
|
|
object->outer_unk = outer ? outer : &object->IUnknown_inner;
|
|
|
|
object->refcount = 1;
|
2020-10-02 13:01:12 +02:00
|
|
|
object->src_rect.right = object->src_rect.bottom = 1.0f;
|
2020-10-07 10:40:22 +02:00
|
|
|
object->ar_mode = MFVideoARMode_PreservePicture | MFVideoARMode_PreservePixel;
|
2020-11-17 11:41:40 +01:00
|
|
|
object->allocator_capacity = 3;
|
2020-07-01 14:55:43 +02:00
|
|
|
InitializeCriticalSection(&object->cs);
|
2020-06-30 15:34:00 +02:00
|
|
|
|
2020-10-01 14:59:33 +02:00
|
|
|
if (FAILED(hr = DXVA2CreateDirect3DDeviceManager9(&object->reset_token, &object->device_manager)))
|
2020-11-09 13:02:44 +01:00
|
|
|
goto failed;
|
2020-10-01 14:59:33 +02:00
|
|
|
|
2020-10-02 13:01:09 +02:00
|
|
|
if (FAILED(hr = video_presenter_init_d3d(object)))
|
2021-10-29 14:30:26 +02:00
|
|
|
{
|
2022-02-01 16:59:06 +01:00
|
|
|
WARN("Failed to initialize d3d device, hr %#lx.\n", hr);
|
2020-11-09 13:02:44 +01:00
|
|
|
goto failed;
|
2021-10-29 14:30:26 +02:00
|
|
|
}
|
2020-06-30 15:34:00 +02:00
|
|
|
|
2020-11-09 13:02:44 +01:00
|
|
|
*out = &object->IUnknown_inner;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
|
|
|
|
IUnknown_Release(&object->IUnknown_inner);
|
2020-10-02 13:01:09 +02:00
|
|
|
|
|
|
|
return hr;
|
2020-06-30 15:34:00 +02:00
|
|
|
}
|