[PATCH v4 5/5] quartz/avidec: Don't determine the source format from the sink format.

Zebediah Figura z.figura12 at gmail.com
Tue Mar 24 10:44:49 CDT 2020


Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 dlls/quartz/avidec.c       | 61 ++++++++++++--------------------------
 dlls/quartz/tests/avidec.c |  5 +---
 2 files changed, 20 insertions(+), 46 deletions(-)

diff --git a/dlls/quartz/avidec.c b/dlls/quartz/avidec.c
index 7edad0fc04c..97566679068 100644
--- a/dlls/quartz/avidec.c
+++ b/dlls/quartz/avidec.c
@@ -49,7 +49,6 @@ typedef struct AVIDecImpl
 
     HIC hvid;
     BITMAPINFOHEADER* pBihIn;
-    BITMAPINFOHEADER* pBihOut;
     REFERENCE_TIME late;
 } AVIDecImpl;
 
@@ -100,6 +99,7 @@ static int AVIDec_DropSample(AVIDecImpl *This, REFERENCE_TIME tStart) {
 static HRESULT WINAPI avi_decompressor_sink_Receive(struct strmbase_sink *iface, IMediaSample *pSample)
 {
     AVIDecImpl *This = impl_from_strmbase_filter(iface->pin.filter);
+    VIDEOINFOHEADER *source_format;
     HRESULT hr;
     DWORD res;
     IMediaSample* pOutSample = NULL;
@@ -120,6 +120,8 @@ static HRESULT WINAPI avi_decompressor_sink_Receive(struct strmbase_sink *iface,
         return VFW_E_NOT_CONNECTED;
     }
 
+    source_format = (VIDEOINFOHEADER *)This->source.pin.mt.pbFormat;
+
     if (This->filter.state == State_Stopped)
         return VFW_E_WRONG_STATE;
 
@@ -161,8 +163,9 @@ static HRESULT WINAPI avi_decompressor_sink_Receive(struct strmbase_sink *iface,
         return hr;
     }
     cbDstStream = IMediaSample_GetSize(pOutSample);
-    if (cbDstStream < This->pBihOut->biSizeImage) {
-        ERR("Sample size is too small %d < %d\n", cbDstStream, This->pBihOut->biSizeImage);
+    if (cbDstStream < source_format->bmiHeader.biSizeImage)
+    {
+        ERR("Sample size is too small (%u < %u).\n", cbDstStream, source_format->bmiHeader.biSizeImage);
         IMediaSample_Release(pOutSample);
         LeaveCriticalSection(&This->stream_cs);
         return E_FAIL;
@@ -176,7 +179,7 @@ static HRESULT WINAPI avi_decompressor_sink_Receive(struct strmbase_sink *iface,
     if (hr == S_OK && AVIDec_DropSample(This, tStart))
         flags |= ICDECOMPRESS_HURRYUP;
 
-    res = ICDecompress(This->hvid, flags, This->pBihIn, pbSrcStream, This->pBihOut, pbDstStream);
+    res = ICDecompress(This->hvid, flags, This->pBihIn, pbSrcStream, &source_format->bmiHeader, pbDstStream);
     if (res != ICERR_OK)
         ERR("Error occurred during the decompression (%x)\n", res);
 
@@ -187,7 +190,7 @@ static HRESULT WINAPI avi_decompressor_sink_Receive(struct strmbase_sink *iface,
         return S_OK;
     }
 
-    IMediaSample_SetActualDataLength(pOutSample, This->pBihOut->biSizeImage);
+    IMediaSample_SetActualDataLength(pOutSample, source_format->bmiHeader.biSizeImage);
 
     IMediaSample_SetPreroll(pOutSample, (IMediaSample_IsPreroll(pSample) == S_OK));
     IMediaSample_SetDiscontinuity(pOutSample, (IMediaSample_IsDiscontinuity(pSample) == S_OK));
@@ -238,22 +241,8 @@ static HRESULT avi_decompressor_sink_connect(struct strmbase_sink *iface, IPin *
         if (This->hvid)
         {
             DWORD bih_size;
-            DWORD output_depth = bmi->biBitCount;
             DWORD result;
 
-            switch(bmi->biBitCount)
-            {
-                case 32:
-                case 24:
-                case 16:
-                case 8:
-                    break;
-                default:
-                    WARN("Non standard input depth %d, forced output depth to 32\n", bmi->biBitCount);
-                    output_depth = 32;
-                    break;
-            }
-
             /* Copy bitmap header from media type to 1 for input and 1 for output */
             bih_size = bmi->biSize + bmi->biClrUsed * 4;
             This->pBihIn = CoTaskMemAlloc(bih_size);
@@ -262,25 +251,12 @@ static HRESULT avi_decompressor_sink_connect(struct strmbase_sink *iface, IPin *
                 hr = E_OUTOFMEMORY;
                 goto failed;
             }
-            This->pBihOut = CoTaskMemAlloc(bih_size);
-            if (!This->pBihOut)
-            {
-                hr = E_OUTOFMEMORY;
-                goto failed;
-            }
             memcpy(This->pBihIn, bmi, bih_size);
-            memcpy(This->pBihOut, bmi, bih_size);
-
-            /* Update output format as non compressed bitmap */
-            This->pBihOut->biCompression = 0;
-            This->pBihOut->biBitCount = output_depth;
-            This->pBihOut->biSizeImage = This->pBihOut->biWidth * This->pBihOut->biHeight * This->pBihOut->biBitCount / 8;
-            TRACE("Size: %u\n", This->pBihIn->biSize);
-            result = ICDecompressQuery(This->hvid, This->pBihIn, This->pBihOut);
-            if (result != ICERR_OK)
+
+            if ((result = ICDecompressQuery(This->hvid, This->pBihIn, NULL)))
             {
-                ERR("Unable to found a suitable output format (%d)\n", result);
-                goto failed;
+                WARN("No decompressor found, error %d.\n", result);
+                return VFW_E_TYPE_NOT_ACCEPTED;
             }
 
             TRACE("Connection accepted\n");
@@ -302,10 +278,8 @@ static void avi_decompressor_sink_disconnect(struct strmbase_sink *iface)
     if (filter->hvid)
         ICClose(filter->hvid);
     CoTaskMemFree(filter->pBihIn);
-    CoTaskMemFree(filter->pBihOut);
     filter->hvid = NULL;
     filter->pBihIn = NULL;
-    filter->pBihOut = NULL;
 }
 
 static const struct strmbase_sink_ops sink_ops =
@@ -434,6 +408,7 @@ static HRESULT avi_decompressor_source_get_media_type(struct strmbase_pin *iface
         mt->cbFormat = offsetof(VIDEOINFOHEADER, bmiHeader) + size;
         if (!(format = CoTaskMemAlloc(mt->cbFormat)))
             return E_OUTOFMEMORY;
+        memset(format, 0, mt->cbFormat);
 
         format->rcSource = sink_format->rcSource;
         format->rcTarget = sink_format->rcTarget;
@@ -464,14 +439,14 @@ static HRESULT avi_decompressor_source_get_media_type(struct strmbase_pin *iface
 static HRESULT WINAPI avi_decompressor_source_DecideBufferSize(struct strmbase_source *iface,
         IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
 {
-    AVIDecImpl *pAVI = impl_from_strmbase_filter(iface->pin.filter);
+    const VIDEOINFOHEADER *source_format = (VIDEOINFOHEADER *)iface->pin.mt.pbFormat;
     ALLOCATOR_PROPERTIES actual;
 
     if (!ppropInputRequest->cbAlign)
         ppropInputRequest->cbAlign = 1;
 
-    if (ppropInputRequest->cbBuffer < pAVI->pBihOut->biSizeImage)
-            ppropInputRequest->cbBuffer = pAVI->pBihOut->biSizeImage;
+    if (ppropInputRequest->cbBuffer < source_format->bmiHeader.biSizeImage)
+        ppropInputRequest->cbBuffer = source_format->bmiHeader.biSizeImage;
 
     if (!ppropInputRequest->cBuffers)
         ppropInputRequest->cBuffers = 1;
@@ -586,11 +561,13 @@ static void avi_decompressor_destroy(struct strmbase_filter *iface)
 static HRESULT avi_decompressor_init_stream(struct strmbase_filter *iface)
 {
     AVIDecImpl *filter = impl_from_strmbase_filter(iface);
+    VIDEOINFOHEADER *source_format;
     LRESULT res;
 
     filter->late = -1;
 
-    if ((res = ICDecompressBegin(filter->hvid, filter->pBihIn, filter->pBihOut)))
+    source_format = (VIDEOINFOHEADER *)filter->sink.pin.mt.pbFormat;
+    if ((res = ICDecompressBegin(filter->hvid, filter->pBihIn, &source_format->bmiHeader)))
     {
         ERR("ICDecompressBegin() failed, error %ld.\n", res);
         return E_FAIL;
diff --git a/dlls/quartz/tests/avidec.c b/dlls/quartz/tests/avidec.c
index 1d435d157f0..7b38561c011 100644
--- a/dlls/quartz/tests/avidec.c
+++ b/dlls/quartz/tests/avidec.c
@@ -963,9 +963,7 @@ static void test_connect_pin(void)
     req_mt.subtype = test_subtype;
 
     hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &req_mt);
-    todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
-    if (hr != S_OK)
-        goto out;
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
 
     hr = IPin_ConnectedTo(sink, &peer);
     ok(hr == S_OK, "Got hr %#x.\n", hr);
@@ -1176,7 +1174,6 @@ static void test_connect_pin(void)
     ok(testsource.source.pin.peer == sink, "Got peer %p.\n", testsource.source.pin.peer);
     IFilterGraph2_Disconnect(graph, &testsource.source.pin.IPin_iface);
 
-out:
     IMemInputPin_Release(meminput);
     IPin_Release(sink);
     IPin_Release(source);
-- 
2.25.1




More information about the wine-devel mailing list