Skip to content

armgit / soju

Public Imported from GitHub
0

Play Windows games on Apple Silicon Macs. Free, open-source app that installs the official Battle.net, Steam, Epic and GOG launchers and lists your games in one library.

7.8 KB
Raw Blame
From 164af86dd770f975cdff3e09884f14ebc14b856b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Bernon?= <[email protected]>
Date: Mon, 4 Mar 2024 09:54:09 +0100
Subject: [PATCH] mfreadwrite/reader: Rely on the video processor sample
 allocator.

CW-Bug-Id: #20833
---
 dlls/mfreadwrite/reader.c | 143 --------------------------------------
 1 file changed, 143 deletions(-)

diff --git a/dlls/mfreadwrite/reader.c b/dlls/mfreadwrite/reader.c
index 19e1bf6b1f93..fcb8d8dec949 100644
--- a/dlls/mfreadwrite/reader.c
+++ b/dlls/mfreadwrite/reader.c
@@ -89,7 +89,6 @@ struct media_stream
     IMFMediaStream *stream;
     IMFMediaType *current;
     struct list transforms;
-    IMFVideoSampleAllocatorEx *allocator;
     IMFTransform *transform_service;
     DWORD id;
     unsigned int index;
@@ -232,8 +231,6 @@ static void media_stream_destroy(struct media_stream *stream)
         IMFMediaStream_Release(stream->stream);
     if (stream->current)
         IMFMediaType_Release(stream->current);
-    if (stream->allocator)
-        IMFVideoSampleAllocatorEx_Release(stream->allocator);
 }
 
 static ULONG source_reader_release(struct source_reader *reader)
@@ -429,39 +426,6 @@ static void source_reader_response_ready(struct source_reader *reader, struct st
     stream->requests--;
 }
 
-static void source_reader_copy_sample_buffer(IMFSample *src, IMFSample *dst)
-{
-    IMFMediaBuffer *buffer;
-    LONGLONG time;
-    DWORD flags;
-    HRESULT hr;
-
-    IMFSample_CopyAllItems(src, (IMFAttributes *)dst);
-
-    IMFSample_SetSampleDuration(dst, 0);
-    IMFSample_SetSampleTime(dst, 0);
-    IMFSample_SetSampleFlags(dst, 0);
-
-    if (SUCCEEDED(IMFSample_GetSampleDuration(src, &time)))
-        IMFSample_SetSampleDuration(dst, time);
-
-    if (SUCCEEDED(IMFSample_GetSampleTime(src, &time)))
-        IMFSample_SetSampleTime(dst, time);
-
-    if (SUCCEEDED(IMFSample_GetSampleFlags(src, &flags)))
-        IMFSample_SetSampleFlags(dst, flags);
-
-    if (SUCCEEDED(IMFSample_ConvertToContiguousBuffer(src, NULL)))
-    {
-        if (SUCCEEDED(IMFSample_GetBufferByIndex(dst, 0, &buffer)))
-        {
-            if (FAILED(hr = IMFSample_CopyToBuffer(src, buffer)))
-                WARN("Failed to copy a buffer, hr %#lx.\n", hr);
-            IMFMediaBuffer_Release(buffer);
-        }
-    }
-}
-
 static HRESULT source_reader_queue_response(struct source_reader *reader, struct media_stream *stream, HRESULT status,
         DWORD stream_flags, LONGLONG timestamp, IMFSample *sample)
 {
@@ -1219,8 +1183,6 @@ static struct stream_response * media_stream_detach_response(struct source_reade
 static struct stream_response *media_stream_pop_response(struct source_reader *reader, struct media_stream *stream)
 {
     struct stream_response *response;
-    IMFSample *sample;
-    HRESULT hr;
 
     LIST_FOR_EACH_ENTRY(response, &reader->responses, struct stream_response, entry)
     {
@@ -1229,26 +1191,6 @@ static struct stream_response *media_stream_pop_response(struct source_reader *r
 
         if (!stream) stream = &reader->streams[response->stream_index];
 
-        if (response->sample && stream->allocator)
-        {
-            /* Return allocation error to the caller, while keeping original response sample in for later. */
-            if (SUCCEEDED(hr = IMFVideoSampleAllocatorEx_AllocateSample(stream->allocator, &sample)))
-            {
-                source_reader_copy_sample_buffer(response->sample, sample);
-                IMFSample_Release(response->sample);
-                response->sample = sample;
-            }
-            else
-            {
-                if (!(response = calloc(1, sizeof(*response))))
-                    return NULL;
-
-                response->status = hr;
-                response->stream_flags = MF_SOURCE_READERF_ERROR;
-                return response;
-            }
-        }
-
         return media_stream_detach_response(reader, response);
     }
 
@@ -1661,7 +1603,6 @@ static ULONG WINAPI src_reader_Release(IMFSourceReaderEx *iface)
 {
     struct source_reader *reader = impl_from_IMFSourceReaderEx(iface);
     ULONG refcount = InterlockedDecrement(&reader->public_refcount);
-    unsigned int i;
 
     TRACE("%p, refcount %lu.\n", iface, refcount);
 
@@ -1681,23 +1622,6 @@ static ULONG WINAPI src_reader_Release(IMFSourceReaderEx *iface)
             LeaveCriticalSection(&reader->cs);
         }
 
-        for (i = 0; i < reader->stream_count; ++i)
-        {
-            struct media_stream *stream = &reader->streams[i];
-            IMFVideoSampleAllocatorCallback *callback;
-
-            if (!stream->allocator)
-                continue;
-
-            if (SUCCEEDED(IMFVideoSampleAllocatorEx_QueryInterface(stream->allocator, &IID_IMFVideoSampleAllocatorCallback,
-                    (void **)&callback)))
-            {
-                IMFVideoSampleAllocatorCallback_SetCallback(callback, NULL);
-                IMFVideoSampleAllocatorCallback_Release(callback);
-            }
-        }
-
-        MFUnlockWorkQueue(reader->queue);
         source_reader_release(reader);
     }
 
@@ -1948,71 +1872,6 @@ static HRESULT source_reader_set_compatible_media_type(struct source_reader *rea
     return type_set ? S_OK : S_FALSE;
 }
 
-static HRESULT source_reader_create_sample_allocator_attributes(const struct source_reader *reader,
-        IMFAttributes **attributes)
-{
-    UINT32 shared = 0, shared_without_mutex = 0;
-    HRESULT hr;
-
-    if (FAILED(hr = MFCreateAttributes(attributes, 1)))
-        return hr;
-
-    IMFAttributes_GetUINT32(reader->attributes, &MF_SA_D3D11_SHARED, &shared);
-    IMFAttributes_GetUINT32(reader->attributes, &MF_SA_D3D11_SHARED_WITHOUT_MUTEX, &shared_without_mutex);
-
-    if (shared_without_mutex)
-        hr = IMFAttributes_SetUINT32(*attributes, &MF_SA_D3D11_SHARED_WITHOUT_MUTEX, TRUE);
-    else if (shared)
-        hr = IMFAttributes_SetUINT32(*attributes, &MF_SA_D3D11_SHARED, TRUE);
-
-    return hr;
-}
-
-static HRESULT source_reader_setup_sample_allocator(struct source_reader *reader, unsigned int index)
-{
-    struct media_stream *stream = &reader->streams[index];
-    IMFAttributes *attributes = NULL;
-    GUID major = { 0 };
-    HRESULT hr;
-
-    IMFMediaType_GetMajorType(stream->current, &major);
-    if (!IsEqualGUID(&major, &MFMediaType_Video))
-        return S_OK;
-
-    if (!(reader->flags & SOURCE_READER_HAS_DEVICE_MANAGER))
-        return S_OK;
-
-    if (!stream->allocator)
-    {
-        if (FAILED(hr = MFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocatorEx, (void **)&stream->allocator)))
-        {
-            WARN("Failed to create sample allocator, hr %#lx.\n", hr);
-            return hr;
-        }
-    }
-
-    IMFVideoSampleAllocatorEx_UninitializeSampleAllocator(stream->allocator);
-    if (FAILED(hr = IMFVideoSampleAllocatorEx_SetDirectXManager(stream->allocator, reader->device_manager)))
-    {
-        WARN("Failed to set device manager, hr %#lx.\n", hr);
-        return hr;
-    }
-
-    if (FAILED(hr = source_reader_create_sample_allocator_attributes(reader, &attributes)))
-        WARN("Failed to create allocator attributes, hr %#lx.\n", hr);
-
-    if (FAILED(hr = IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(stream->allocator, 2, 8,
-            attributes, stream->current)))
-    {
-        WARN("Failed to initialize sample allocator, hr %#lx.\n", hr);
-    }
-
-    if (attributes)
-        IMFAttributes_Release(attributes);
-
-    return hr;
-}
-
 static BOOL source_reader_allow_video_processor(struct source_reader *reader, BOOL *advanced)
 {
     UINT32 value;
@@ -2265,8 +2124,6 @@ static HRESULT WINAPI src_reader_SetCurrentMediaType(IMFSourceReaderEx *iface, D
     hr = source_reader_set_compatible_media_type(reader, index, type);
     if (hr == S_FALSE)
         hr = source_reader_create_decoder_for_stream(reader, index, type);
-    if (SUCCEEDED(hr))
-        hr = source_reader_setup_sample_allocator(reader, index);
 
     LeaveCriticalSection(&reader->cs);