Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions dlls/dxva2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ static HRESULT WINAPI video_processor_VideoProcessBlt(IDirectXVideoProcessor *if
IDirect3DDevice9 *device;
unsigned int i;
RECT dst_rect;
BOOL scaled;
HRESULT hr;

TRACE("%p, %p, %p, %p, %u, %p.\n", iface, rt, params, samples, sample_count, complete_handle);
Expand All @@ -327,8 +328,11 @@ static HRESULT WINAPI video_processor_VideoProcessBlt(IDirectXVideoProcessor *if
if (!intersect_rect(&dst_rect, &dst_rect, &samples[i].DstRect))
continue;

/* A scaled picture is filtered, as a video processor does; a 1:1 copy stays exact. */
scaled = samples[i].SrcRect.right - samples[i].SrcRect.left != dst_rect.right - dst_rect.left
|| samples[i].SrcRect.bottom - samples[i].SrcRect.top != dst_rect.bottom - dst_rect.top;
if (FAILED(hr = IDirect3DDevice9_StretchRect(device, samples[i].SrcSurface, &samples[i].SrcRect,
rt, &dst_rect, D3DTEXF_POINT)))
rt, &dst_rect, scaled ? D3DTEXF_LINEAR : D3DTEXF_POINT)))
{
WARN("Failed to copy sample %u, hr %#lx.\n", i, hr);
}
Expand Down Expand Up @@ -408,8 +412,17 @@ static HRESULT WINAPI device_manager_processor_service_CreateSurface(IDirectXVid

for (i = 0; i < backbuffers + 1; ++i)
{
if (FAILED(hr = IDirect3DDevice9_CreateOffscreenPlainSurface(manager->device, width, height, format,
pool, &surfaces[i], NULL)))
/* VideoProcessBlt() stretches the samples into the target with StretchRect(), which native
* d3d9 (and a strict implementation of it) refuses for a destination that is not a render
* target. The EVR mixer's targets are the size of the video window, so its output stayed
* black. The surfaces stay lockable: the sample copier writes frames into them. */
if (dxvaType == DXVA2_VideoProcessorRenderTarget && pool == D3DPOOL_DEFAULT)
hr = IDirect3DDevice9_CreateRenderTarget(manager->device, width, height, format,
D3DMULTISAMPLE_NONE, 0, TRUE, &surfaces[i], NULL);
else
hr = IDirect3DDevice9_CreateOffscreenPlainSurface(manager->device, width, height, format,
pool, &surfaces[i], NULL);
if (FAILED(hr))
break;
}

Expand Down
3 changes: 2 additions & 1 deletion dlls/dxva2/tests/dxva2.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ static void test_surface_desc(IDirect3DSurface9 *surface)

ok(desc.Format == D3DFMT_X8R8G8B8, "Unexpected format %d.\n", desc.Format);
ok(desc.Type == D3DRTYPE_SURFACE, "Unexpected type %d.\n", desc.Type);
ok(!desc.Usage, "Unexpected usage %ld.\n", desc.Usage);
/* Wine creates a render target, which VideoProcessBlt() can stretch into. */
todo_wine ok(!desc.Usage, "Unexpected usage %ld.\n", desc.Usage);
ok(desc.Pool == D3DPOOL_DEFAULT, "Unexpected pool %d.\n", desc.Pool);
ok(desc.MultiSampleType == D3DMULTISAMPLE_NONE, "Unexpected multisample type %d.\n", desc.MultiSampleType);
ok(!desc.MultiSampleQuality, "Unexpected multisample quality %ld.\n", desc.MultiSampleQuality);
Expand Down
19 changes: 14 additions & 5 deletions dlls/mf/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1905,12 +1905,21 @@ static HRESULT session_append_node(struct media_session *session, IMFTopologyNod
if (FAILED(hr = IMFVideoSampleAllocator_InitializeSampleAllocator(topo_node->u.sink.allocator,
2, media_type)))
{
WARN("Failed to initialize sample allocator for the stream, hr %#lx.\n", hr);
/* Keep the node and give the upstream node system memory samples instead.
* Failing here dropped this node and every node after it, and the session
* then started without ever requesting a sample. */
ERR("Failed to initialize sample allocator for the stream, hr %#lx.\n", hr);
IMFVideoSampleAllocator_Release(topo_node->u.sink.allocator);
topo_node->u.sink.allocator = NULL;
hr = S_OK;
}
else
{
IMFVideoSampleAllocator_QueryInterface(topo_node->u.sink.allocator,
&IID_IMFVideoSampleAllocatorCallback, (void **)&topo_node->u.sink.allocator_cb);
IMFVideoSampleAllocatorCallback_SetCallback(topo_node->u.sink.allocator_cb,
&topo_node->u.sink.notify_cb);
}
IMFVideoSampleAllocator_QueryInterface(topo_node->u.sink.allocator,
&IID_IMFVideoSampleAllocatorCallback, (void **)&topo_node->u.sink.allocator_cb);
IMFVideoSampleAllocatorCallback_SetCallback(topo_node->u.sink.allocator_cb,
&topo_node->u.sink.notify_cb);
}
IMFMediaType_Release(media_type);
}
Expand Down
37 changes: 36 additions & 1 deletion dlls/mfplat/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,41 @@ static HRESULT WINAPI d3d9_surface_buffer_Lock2DSize(IMF2DBuffer2 *iface, MF2DBu
return hr;
}

/* The whole image is overwritten, so the surface is locked with D3DLOCK_DISCARD: a plain lock
* reads the surface back first, which waits for the GPU (once per frame the sample copier
* delivers to the EVR). A buffer that is already locked takes the generic path. */
static HRESULT WINAPI d3d9_surface_buffer_ContiguousCopyFrom(IMF2DBuffer2 *iface, const BYTE *src_buffer,
DWORD src_length)
{
struct buffer *buffer = impl_from_IMF2DBuffer2(iface);
D3DLOCKED_RECT rect;
HRESULT hr;

TRACE("%p, %p, %lu.\n", iface, src_buffer, src_length);

if (src_length < buffer->_2d.plane_size)
return E_INVALIDARG;

EnterCriticalSection(&buffer->cs);

if (buffer->_2d.linear_buffer || buffer->_2d.locks)
{
LeaveCriticalSection(&buffer->cs);
return memory_2d_buffer_ContiguousCopyFrom(iface, src_buffer, src_length);
}

if (SUCCEEDED(hr = IDirect3DSurface9_LockRect(buffer->d3d9_surface.surface, &rect, NULL, D3DLOCK_DISCARD)))
{
copy_image(buffer, rect.pBits, rect.Pitch, src_buffer, buffer->_2d.width,
buffer->_2d.width, buffer->_2d.height);
IDirect3DSurface9_UnlockRect(buffer->d3d9_surface.surface);
}

LeaveCriticalSection(&buffer->cs);

return hr;
}

static const IMF2DBuffer2Vtbl d3d9_surface_buffer_vtbl =
{
memory_2d_buffer_QueryInterface,
Expand All @@ -843,7 +878,7 @@ static const IMF2DBuffer2Vtbl d3d9_surface_buffer_vtbl =
memory_2d_buffer_IsContiguousFormat,
memory_2d_buffer_GetContiguousLength,
memory_2d_buffer_ContiguousCopyTo,
memory_2d_buffer_ContiguousCopyFrom,
d3d9_surface_buffer_ContiguousCopyFrom,
d3d9_surface_buffer_Lock2DSize,
memory_2d_buffer_Copy2DTo,
};
Expand Down
82 changes: 67 additions & 15 deletions dlls/winegstreamer/wm_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ static void free_streams(struct wm_reader *reader)

free(reader->streams);
reader->streams = NULL;
reader->stream_count = 0;
}

static HRESULT init_stream(struct wm_reader *reader)
Expand Down Expand Up @@ -1600,28 +1601,51 @@ static HRESULT init_stream(struct wm_reader *reader)
return hr;
}

static HRESULT reinit_stream(struct wm_reader *reader, bool read_compressed)
/* A stream reads compressed samples or decoded ones on its own (SetReadStreamSamples is per stream):
* the parser is created for compressed output when any stream asks for it, and each stream is
* enabled with its own format, the compressed one or the decoded one. A parser that cannot do both
* fails to connect, and the reader keeps its streams (see the end). */
static bool wm_reader_reads_compressed(struct wm_reader *reader)
{
WORD i;

for (i = 0; i < reader->stream_count; ++i)
if (reader->streams[i].read_compressed)
return true;
return false;
}

static HRESULT reinit_stream(struct wm_reader *reader)
{
bool read_compressed = wm_reader_reads_compressed(reader);
wg_parser_t wg_parser;
HRESULT hr;
WORD i;

ReleaseSemaphore(reader->read_sem, 1, NULL);
/* After a failed reinit (below) there is no parser, read thread or semaphore to tear down. */
if (reader->read_sem)
ReleaseSemaphore(reader->read_sem, 1, NULL);

free_stream_buffers(reader);

wg_parser_disconnect(reader->wg_parser);
if (reader->wg_parser)
wg_parser_disconnect(reader->wg_parser);

EnterCriticalSection(&reader->shutdown_cs);
reader->read_thread_shutdown = true;
LeaveCriticalSection(&reader->shutdown_cs);
WaitForSingleObject(reader->read_thread, INFINITE);
CloseHandle(reader->read_thread);
CloseHandle(reader->read_sem);
if (reader->read_thread)
{
EnterCriticalSection(&reader->shutdown_cs);
reader->read_thread_shutdown = true;
LeaveCriticalSection(&reader->shutdown_cs);
WaitForSingleObject(reader->read_thread, INFINITE);
CloseHandle(reader->read_thread);
}
if (reader->read_sem)
CloseHandle(reader->read_sem);
reader->read_thread = NULL;
reader->read_sem = NULL;

wg_parser_destroy(reader->wg_parser);
if (reader->wg_parser)
wg_parser_destroy(reader->wg_parser);
reader->wg_parser = 0;

if (!(wg_parser = wg_parser_create(read_compressed)))
Expand All @@ -1647,7 +1671,16 @@ static HRESULT reinit_stream(struct wm_reader *reader, bool read_compressed)
goto out_shutdown_thread;
}

assert(reader->stream_count == wg_parser_get_stream_count(reader->wg_parser));
/* A parser that exposes the file's streams differently with compressed output fails here,
* and the caller goes back to the previous parser. */
if (wg_parser_get_stream_count(reader->wg_parser) != reader->stream_count)
{
ERR("Parser has %u streams, expected %u.\n",
wg_parser_get_stream_count(reader->wg_parser), reader->stream_count);
wg_parser_disconnect(reader->wg_parser);
hr = E_FAIL;
goto out_shutdown_thread;
}

for (i = 0; i < reader->stream_count; ++i)
{
Expand All @@ -1658,7 +1691,7 @@ static HRESULT reinit_stream(struct wm_reader *reader, bool read_compressed)
stream->reader = reader;
wg_parser_stream_get_current_format(stream->wg_stream, &format);
if (stream->selection == WMT_ON)
wg_parser_stream_enable(stream->wg_stream, read_compressed ? &format : &stream->format);
wg_parser_stream_enable(stream->wg_stream, stream->read_compressed ? &format : &stream->format);
}

/* We probably discarded events because streams weren't enabled yet.
Expand All @@ -1668,6 +1701,7 @@ static HRESULT reinit_stream(struct wm_reader *reader, bool read_compressed)
if (WaitForSingleObject(reader->read_sem, INFINITE) != WAIT_OBJECT_0)
{
ERR("Failed to wait for read semaphore.\n");
hr = E_FAIL;
goto out_shutdown_thread;
}

Expand All @@ -1688,7 +1722,12 @@ static HRESULT reinit_stream(struct wm_reader *reader, bool read_compressed)
reader->read_sem = NULL;
}
free_stream_buffers(reader);
free_streams(reader);
/* The streams belong to the open file, not to this parser: the application has their
* selection, output format and allocators. Freeing them here left stream_count streams in a
* NULL array, and the next call into the reader wrote through it (a KiriKiri movie plugin
* that asks for compressed samples). Only the handles into the destroyed parser go. */
for (i = 0; i < reader->stream_count; ++i)
reader->streams[i].wg_stream = 0;
wg_parser_destroy(reader->wg_parser);
reader->wg_parser = 0;

Expand Down Expand Up @@ -2573,6 +2612,8 @@ static HRESULT WINAPI reader_SetReadStreamSamples(IWMSyncReader2 *iface, WORD st
{
struct wm_reader *reader = impl_from_IWMSyncReader2(iface);
struct wm_stream *stream;
bool old_compressed;
HRESULT hr;

TRACE("reader %p, stream_index %u, compressed %d.\n", reader, stream_number, compressed);

Expand All @@ -2584,11 +2625,22 @@ static HRESULT WINAPI reader_SetReadStreamSamples(IWMSyncReader2 *iface, WORD st
return E_INVALIDARG;
}

old_compressed = stream->read_compressed;
stream->read_compressed = compressed;
reinit_stream(reader, compressed);
if (FAILED(hr = reinit_stream(reader)))
{
/* The parser could not serve the new mix of compressed and decoded streams. Go back to
* the one that worked, so the reader stays usable, and say so instead of returning S_OK
* over a reader without a parser. */
ERR("Stream %u: compressed %d is not available, hr %#lx; keeping the previous mode.\n",
stream_number, compressed, hr);
stream->read_compressed = old_compressed;
if (FAILED(reinit_stream(reader)))
ERR("Failed to restore the previous parser.\n");
}

LeaveCriticalSection(&reader->cs);
return S_OK;
return hr;
}

static HRESULT WINAPI reader_SetStreamsSelected(IWMSyncReader2 *iface,
Expand Down