[PATCH 3/7] winegstreamer: Use a union in struct sample to keep API pointers.

Rémi Bernon wine at gitlab.winehq.org
Fri Jun 10 02:53:38 CDT 2022


From: Rémi Bernon <rbernon at codeweavers.com>

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/winegstreamer/wg_sample.c | 64 +++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 17 deletions(-)

diff --git a/dlls/winegstreamer/wg_sample.c b/dlls/winegstreamer/wg_sample.c
index b7fd9a002a5..017ec706f50 100644
--- a/dlls/winegstreamer/wg_sample.c
+++ b/dlls/winegstreamer/wg_sample.c
@@ -34,10 +34,22 @@ struct wg_sample_queue
 
 struct sample
 {
-    IMFSample *sample;
-    IMFMediaBuffer *media_buffer;
     struct wg_sample wg_sample;
     struct list entry;
+
+    enum wg_sample_type
+    {
+        WG_SAMPLE_TYPE_MF = 1,
+    } type;
+
+    union
+    {
+        struct
+        {
+            IMFSample *sample;
+            IMFMediaBuffer *buffer;
+        } mf;
+    } u;
 };
 
 HRESULT wg_sample_create_mf(IMFSample *mf_sample, struct wg_sample **out)
@@ -49,23 +61,24 @@ HRESULT wg_sample_create_mf(IMFSample *mf_sample, struct wg_sample **out)
 
     if (!(sample = calloc(1, sizeof(*sample))))
         return E_OUTOFMEMORY;
-    if (FAILED(hr = IMFSample_ConvertToContiguousBuffer(mf_sample, &sample->media_buffer)))
+    if (FAILED(hr = IMFSample_ConvertToContiguousBuffer(mf_sample, &sample->u.mf.buffer)))
         goto fail;
-    if (FAILED(hr = IMFMediaBuffer_Lock(sample->media_buffer, &buffer, &max_length, &current_length)))
+    if (FAILED(hr = IMFMediaBuffer_Lock(sample->u.mf.buffer, &buffer, &max_length, &current_length)))
         goto fail;
 
-    IMFSample_AddRef((sample->sample = mf_sample));
+    IMFSample_AddRef((sample->u.mf.sample = mf_sample));
     sample->wg_sample.data = buffer;
     sample->wg_sample.size = current_length;
     sample->wg_sample.max_size = max_length;
+    sample->type = WG_SAMPLE_TYPE_MF;
 
     *out = &sample->wg_sample;
     TRACE("Created wg_sample %p for MF sample %p.\n", *out, mf_sample);
     return S_OK;
 
 fail:
-    if (sample->media_buffer)
-        IMFMediaBuffer_Release(sample->media_buffer);
+    if (sample->u.mf.buffer)
+        IMFMediaBuffer_Release(sample->u.mf.buffer);
     free(sample);
     return hr;
 }
@@ -80,9 +93,20 @@ void wg_sample_release(struct wg_sample *wg_sample)
         return;
     }
 
-    IMFMediaBuffer_Unlock(sample->media_buffer);
-    IMFMediaBuffer_Release(sample->media_buffer);
-    IMFSample_Release(sample->sample);
+    switch (sample->type)
+    {
+        case WG_SAMPLE_TYPE_MF:
+            TRACE("wg_sample %p\n", wg_sample);
+
+            IMFMediaBuffer_Unlock(sample->u.mf.buffer);
+            IMFMediaBuffer_Release(sample->u.mf.buffer);
+            IMFSample_Release(sample->u.mf.sample);
+            break;
+
+        default:
+            FIXME("Unknown wg_sample %p, type %u\n", wg_sample, sample->type);
+            break;
+    }
 
     free(sample);
 }
@@ -161,17 +185,20 @@ HRESULT wg_transform_push_mf(struct wg_transform *transform, struct wg_sample *w
     UINT32 value;
     HRESULT hr;
 
-    if (SUCCEEDED(IMFSample_GetSampleTime(sample->sample, &time)))
+    if (sample->type != WG_SAMPLE_TYPE_MF)
+        return E_INVALIDARG;
+
+    if (SUCCEEDED(IMFSample_GetSampleTime(sample->u.mf.sample, &time)))
     {
         sample->wg_sample.flags |= WG_SAMPLE_FLAG_HAS_PTS;
         sample->wg_sample.pts = time;
     }
-    if (SUCCEEDED(IMFSample_GetSampleDuration(sample->sample, &duration)))
+    if (SUCCEEDED(IMFSample_GetSampleDuration(sample->u.mf.sample, &duration)))
     {
         sample->wg_sample.flags |= WG_SAMPLE_FLAG_HAS_DURATION;
         sample->wg_sample.duration = duration;
     }
-    if (SUCCEEDED(IMFSample_GetUINT32(sample->sample, &MFSampleExtension_CleanPoint, &value)) && value)
+    if (SUCCEEDED(IMFSample_GetUINT32(sample->u.mf.sample, &MFSampleExtension_CleanPoint, &value)) && value)
         sample->wg_sample.flags |= WG_SAMPLE_FLAG_SYNC_POINT;
 
     wg_sample_queue_begin_append(queue, wg_sample);
@@ -187,17 +214,20 @@ HRESULT wg_transform_read_mf(struct wg_transform *transform, struct wg_sample *w
     struct sample *sample = CONTAINING_RECORD(wg_sample, struct sample, wg_sample);
     HRESULT hr;
 
+    if (sample->type != WG_SAMPLE_TYPE_MF)
+        return E_INVALIDARG;
+
     if (FAILED(hr = wg_transform_read_data(transform, wg_sample, format)))
         return hr;
 
-    IMFMediaBuffer_SetCurrentLength(sample->media_buffer, wg_sample->size);
+    IMFMediaBuffer_SetCurrentLength(sample->u.mf.buffer, wg_sample->size);
 
     if (wg_sample->flags & WG_SAMPLE_FLAG_HAS_PTS)
-        IMFSample_SetSampleTime(sample->sample, wg_sample->pts);
+        IMFSample_SetSampleTime(sample->u.mf.sample, wg_sample->pts);
     if (wg_sample->flags & WG_SAMPLE_FLAG_HAS_DURATION)
-        IMFSample_SetSampleDuration(sample->sample, wg_sample->duration);
+        IMFSample_SetSampleDuration(sample->u.mf.sample, wg_sample->duration);
     if (wg_sample->flags & WG_SAMPLE_FLAG_SYNC_POINT)
-        IMFSample_SetUINT32(sample->sample, &MFSampleExtension_CleanPoint, 1);
+        IMFSample_SetUINT32(sample->u.mf.sample, &MFSampleExtension_CleanPoint, 1);
 
     return S_OK;
 }
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/220



More information about the wine-devel mailing list