[PATCH v2 1/5] amstream: Implement AMDirectDrawStream::GetFormat.

Zebediah Figura z.figura12 at gmail.com
Wed Sep 9 16:03:51 CDT 2020


On 9/9/20 2:58 PM, Anton Baskanov wrote:
> On Tuesday, 8 September 2020 23:37:31 +07 you wrote:
>> On 9/5/20 1:04 PM, Anton Baskanov wrote:
>>> Signed-off-by: Anton Baskanov <baskanov at gmail.com>
>>> ---
>>>
>>>  dlls/amstream/ddrawstream.c    |  98 ++++++++++-
>>>  dlls/amstream/tests/amstream.c | 306 +++++++++++++++++++++++++++++++++
>>>  2 files changed, 396 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/dlls/amstream/ddrawstream.c b/dlls/amstream/ddrawstream.c
>>> index 0d3f2d0d4b8..eb8e35b5ac4 100644
>>> --- a/dlls/amstream/ddrawstream.c
>>> +++ b/dlls/amstream/ddrawstream.c
>>> @@ -47,6 +47,7 @@ struct ddraw_stream
>>>
>>>      IPin *peer;
>>>      IMemAllocator *allocator;
>>>      AM_MEDIA_TYPE mt;
>>>
>>> +    DDSURFACEDESC format;
>>>
>>>  };
>>>  
>>>  static HRESULT ddrawstreamsample_create(struct ddraw_stream *parent,
>>>  IDirectDrawSurface *surface,> 
>>> @@ -363,11 +364,40 @@ static HRESULT WINAPI
>>> ddraw_IDirectDrawMediaStream_GetFormat(IDirectDrawMediaStr> 
>>>          DDSURFACEDESC *current_format, IDirectDrawPalette **palette,
>>>          DDSURFACEDESC *desired_format, DWORD *flags)
>>>  
>>>  {
>>>
>>> -    FIXME("(%p)->(%p,%p,%p,%p) stub!\n", iface, current_format, palette,
>>> desired_format, -            flags);
>>> +    struct ddraw_stream *stream =
>>> impl_from_IDirectDrawMediaStream(iface);
>>> +
>>> +    TRACE("stream %p, current_format %p, palette %p, desired_format %p,
>>> flags %p.\n", stream, current_format, palette, +           
>>> desired_format, flags);
>>>
>>> -    return MS_E_NOSTREAM;
>>> +    EnterCriticalSection(&stream->cs);
>>> +
>>> +    if (!stream->peer)
>>> +    {
>>> +        LeaveCriticalSection(&stream->cs);
>>> +        return MS_E_NOSTREAM;
>>> +    }
>>>
>>> +    if (current_format)
>>> +    {
>>> +        *current_format = stream->format;
>>> +        current_format->dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
>>> +    }
>>> +
>>> +    if (palette)
>>> +        *palette = NULL;
>>> +
>>> +    if (desired_format)
>>> +    {
>>> +        *desired_format = stream->format;
>>> +        desired_format->dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
>>> +    }
>>> +
>>> +    if (flags)
>>> +        *flags = 0;
>>> +
>>> +    LeaveCriticalSection(&stream->cs);
>>> +
>>> +    return S_OK;
>>>
>>>  }
>>>  
>>>  static HRESULT WINAPI
>>>  ddraw_IDirectDrawMediaStream_SetFormat(IDirectDrawMediaStream *iface,> 
>>> @@ -637,8 +667,12 @@ static HRESULT WINAPI ddraw_sink_Connect(IPin *iface,
>>> IPin *peer, const AM_MEDIA> 
>>>  static HRESULT WINAPI ddraw_sink_ReceiveConnection(IPin *iface, IPin
>>>  *peer, const AM_MEDIA_TYPE *mt) {
>>>
>>> +    const VIDEOINFOHEADER *video_info = (const VIDEOINFOHEADER
>>> *)mt->pbFormat; +    DDPIXELFORMAT pixel_format =
>>> {sizeof(DDPIXELFORMAT)};
>>>
>>>      struct ddraw_stream *stream = impl_from_IPin(iface);
>>>      PIN_DIRECTION dir;
>>>
>>> +    DWORD width;
>>> +    DWORD height;
>>>
>>>      TRACE("stream %p, peer %p, mt %p.\n", stream, peer, mt);
>>>
>>> @@ -651,17 +685,54 @@ static HRESULT WINAPI
>>> ddraw_sink_ReceiveConnection(IPin *iface, IPin *peer, cons> 
>>>      }
>>>      
>>>      if (!IsEqualGUID(&mt->majortype, &MEDIATYPE_Video)
>>>
>>> -            || (!IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_RGB8)
>>> -                && !IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_RGB24)
>>> -                && !IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_RGB32)
>>> -                && !IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_RGB555)
>>> -                && !IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_RGB565))
>>>
>>>              || !IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo))
>>>      
>>>      {
>>>      
>>>          LeaveCriticalSection(&stream->cs);
>>>          return VFW_E_TYPE_NOT_ACCEPTED;
>>>      
>>>      }
>>>
>>> +    width = video_info->bmiHeader.biWidth;
>>> +    height = abs(video_info->bmiHeader.biHeight);
>>> +    pixel_format.dwFlags = DDPF_RGB;
>>> +    if (IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_RGB8))
>>> +    {
>>> +        pixel_format.dwFlags |= DDPF_PALETTEINDEXED8;
>>> +        pixel_format.u1.dwRGBBitCount = 8;
>>> +    }
>>> +    else if (IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_RGB555))
>>> +    {
>>> +        pixel_format.u1.dwRGBBitCount = 16;
>>> +        pixel_format.u2.dwRBitMask = 0x7c00;
>>> +        pixel_format.u3.dwGBitMask = 0x03e0;
>>> +        pixel_format.u4.dwBBitMask = 0x001f;
>>> +    }
>>> +    else if (IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_RGB565))
>>> +    {
>>> +        pixel_format.u1.dwRGBBitCount = 16;
>>> +        pixel_format.u2.dwRBitMask = 0xf800;
>>> +        pixel_format.u3.dwGBitMask = 0x07e0;
>>> +        pixel_format.u4.dwBBitMask = 0x001f;
>>> +    }
>>> +    else if (IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_RGB24))
>>> +    {
>>> +        pixel_format.u1.dwRGBBitCount = 24;
>>> +        pixel_format.u2.dwRBitMask = 0xff0000;
>>> +        pixel_format.u3.dwGBitMask = 0x00ff00;
>>> +        pixel_format.u4.dwBBitMask = 0x0000ff;
>>> +    }
>>> +    else if (IsEqualGUID(&mt->subtype, &MEDIASUBTYPE_RGB32))
>>> +    {
>>> +        pixel_format.u1.dwRGBBitCount = 32;
>>> +        pixel_format.u2.dwRBitMask = 0xff0000;
>>> +        pixel_format.u3.dwGBitMask = 0x00ff00;
>>> +        pixel_format.u4.dwBBitMask = 0x0000ff;
>>> +    }
>>> +    else
>>> +    {
>>> +        LeaveCriticalSection(&stream->cs);
>>> +        return VFW_E_TYPE_NOT_ACCEPTED;
>>> +    }
>>> +
>>>
>>>      IPin_QueryDirection(peer, &dir);
>>>      if (dir != PINDIR_OUTPUT)
>>>      {
>>>
>>> @@ -673,6 +744,11 @@ static HRESULT WINAPI
>>> ddraw_sink_ReceiveConnection(IPin *iface, IPin *peer, cons> 
>>>      CopyMediaType(&stream->mt, mt);
>>>      IPin_AddRef(stream->peer = peer);
>>>
>>> +    stream->format.dwWidth = width;
>>> +    stream->format.dwHeight = height;
>>> +    if (!(stream->format.dwFlags & DDSD_PIXELFORMAT))
>>> +        stream->format.ddpfPixelFormat = pixel_format;
>>> +
>>>
>>>      LeaveCriticalSection(&stream->cs);
>>>      
>>>      return S_OK;
>>>
>>> @@ -981,6 +1057,12 @@ HRESULT ddraw_stream_create(IUnknown *outer, void
>>> **out)> 
>>>      object->IPin_iface.lpVtbl = &ddraw_sink_vtbl;
>>>      object->ref = 1;
>>>
>>> +    object->format.dwSize = sizeof(DDSURFACEDESC);
>>> +    object->format.dwFlags = DDSD_CAPS;
>>> +    object->format.dwWidth = 100;
>>> +    object->format.dwHeight = 100;
>>> +    object->format.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY |
>>> DDSCAPS_OFFSCREENPLAIN; +
>>>
>>>      InitializeCriticalSection(&object->cs);
>>>      
>>>      TRACE("Created ddraw stream %p.\n", object);
>>>
>>> diff --git a/dlls/amstream/tests/amstream.c
>>> b/dlls/amstream/tests/amstream.c index f4c033a1807..2a69ff60fc3 100644
>>> --- a/dlls/amstream/tests/amstream.c
>>> +++ b/dlls/amstream/tests/amstream.c
>>> @@ -51,6 +51,164 @@ static const AM_MEDIA_TYPE audio_mt =
>>>
>>>      .pbFormat = (BYTE *)&audio_format,
>>>  
>>>  };
>>>
>>> +static const VIDEOINFO rgb8_video_info =
>>> +{
>>> +    .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
>>> +    .bmiHeader.biWidth = 333,
>>> +    .bmiHeader.biHeight = -444,
>>> +    .bmiHeader.biPlanes = 1,
>>> +    .bmiHeader.biBitCount = 8,
>>> +    .bmiHeader.biCompression = BI_RGB,
>>> +};
>>> +
>>> +static const VIDEOINFO rgb555_video_info =
>>> +{
>>> +    .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
>>> +    .bmiHeader.biWidth = 333,
>>> +    .bmiHeader.biHeight = -444,
>>> +    .bmiHeader.biPlanes = 1,
>>> +    .bmiHeader.biBitCount = 16,
>>> +    .bmiHeader.biCompression = BI_RGB,
>>> +};
>>> +
>>> +static const VIDEOINFO rgb565_video_info =
>>> +{
>>> +    .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
>>> +    .bmiHeader.biWidth = 333,
>>> +    .bmiHeader.biHeight = -444,
>>> +    .bmiHeader.biPlanes = 1,
>>> +    .bmiHeader.biBitCount = 16,
>>> +    .bmiHeader.biCompression = BI_BITFIELDS,
>>> +    .dwBitMasks = {0xff0000, 0x00ff00, 0x0000ff},
>>
>> I think this is a mistake for {0xf800, 0x07e0, 0x001f}, right?
>>
>>> +};
>>> +
>>> +static const VIDEOINFO rgb24_video_info =
>>> +{
>>> +    .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
>>> +    .bmiHeader.biWidth = 333,
>>> +    .bmiHeader.biHeight = -444,
>>> +    .bmiHeader.biPlanes = 1,
>>> +    .bmiHeader.biBitCount = 24,
>>> +    .bmiHeader.biCompression = BI_RGB,
>>> +};
>>> +
>>> +static const VIDEOINFO rgb32_video_info =
>>> +{
>>> +    .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
>>> +    .bmiHeader.biWidth = 333,
>>> +    .bmiHeader.biHeight = -444,
>>> +    .bmiHeader.biPlanes = 1,
>>> +    .bmiHeader.biBitCount = 32,
>>> +    .bmiHeader.biCompression = BI_RGB,
>>> +};
>>> +
>>> +static const AM_MEDIA_TYPE rgb8_mt =
>>> +{
>>> +    /* MEDIATYPE_Video, MEDIASUBTYPE_RGB8, FORMAT_VideoInfo */
>>> +    .majortype = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa,
>>> 0x00, 0x38, 0x9b, 0x71}}, +    .subtype = {0xe436eb7a, 0x524f, 0x11ce,
>>> {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}}, +    .formattype =
>>> {0x05589f80, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59,
>>> 0x5a}}, +    .cbFormat = sizeof(VIDEOINFO),
>>> +    .pbFormat = (BYTE *)&rgb8_video_info,
>>> +};
>>> +
>>> +static const AM_MEDIA_TYPE rgb555_mt =
>>> +{
>>> +    /* MEDIATYPE_Video, MEDIASUBTYPE_RGB555, FORMAT_VideoInfo */
>>> +    .majortype = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa,
>>> 0x00, 0x38, 0x9b, 0x71}}, +    .subtype = {0xe436eb7c, 0x524f, 0x11ce,
>>> {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}}, +    .formattype =
>>> {0x05589f80, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59,
>>> 0x5a}}, +    .cbFormat = sizeof(VIDEOINFO),
>>> +    .pbFormat = (BYTE *)&rgb555_video_info,
>>> +};
>>> +
>>> +static const AM_MEDIA_TYPE rgb565_mt =
>>> +{
>>> +    /* MEDIATYPE_Video, MEDIASUBTYPE_RGB565, FORMAT_VideoInfo */
>>> +    .majortype = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa,
>>> 0x00, 0x38, 0x9b, 0x71}}, +    .subtype = {0xe436eb7b, 0x524f, 0x11ce,
>>> {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}}, +    .formattype =
>>> {0x05589f80, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59,
>>> 0x5a}}, +    .cbFormat = sizeof(VIDEOINFO),
>>> +    .pbFormat = (BYTE *)&rgb565_video_info,
>>> +};
>>> +
>>> +static const AM_MEDIA_TYPE rgb24_mt =
>>> +{
>>> +    /* MEDIATYPE_Video, MEDIASUBTYPE_RGB24, FORMAT_VideoInfo */
>>> +    .majortype = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa,
>>> 0x00, 0x38, 0x9b, 0x71}}, +    .subtype = {0xe436eb7d, 0x524f, 0x11ce,
>>> {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}}, +    .formattype =
>>> {0x05589f80, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59,
>>> 0x5a}}, +    .cbFormat = sizeof(VIDEOINFO),
>>> +    .pbFormat = (BYTE *)&rgb24_video_info,
>>> +};
>>> +
>>> +static const AM_MEDIA_TYPE rgb32_mt =
>>> +{
>>> +    /* MEDIATYPE_Video, MEDIASUBTYPE_RGB32, FORMAT_VideoInfo */
>>> +    .majortype = {0x73646976, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa,
>>> 0x00, 0x38, 0x9b, 0x71}}, +    .subtype = {0xe436eb7e, 0x524f, 0x11ce,
>>> {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}}, +    .formattype =
>>> {0x05589f80, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59,
>>> 0x5a}}, +    .cbFormat = sizeof(VIDEOINFO),
>>> +    .pbFormat = (BYTE *)&rgb32_video_info,
>>> +};
>>> +
>>> +static const DDSURFACEDESC rgb8_format =
>>> +{
>>> +    .dwSize = sizeof(DDSURFACEDESC),
>>> +    .dwFlags = DDSD_PIXELFORMAT,
>>> +    .ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT),
>>> +    .ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8,
>>> +    .ddpfPixelFormat.dwRGBBitCount = 8,
>>> +};
>>> +
>>> +static const DDSURFACEDESC rgb555_format =
>>> +{
>>> +    .dwSize = sizeof(DDSURFACEDESC),
>>> +    .dwFlags = DDSD_PIXELFORMAT,
>>> +    .ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT),
>>> +    .ddpfPixelFormat.dwFlags = DDPF_RGB,
>>> +    .ddpfPixelFormat.dwRGBBitCount = 16,
>>> +    .ddpfPixelFormat.dwRBitMask = 0x7c00,
>>> +    .ddpfPixelFormat.dwGBitMask = 0x03e0,
>>> +    .ddpfPixelFormat.dwBBitMask = 0x001f,
>>> +};
>>> +
>>> +static const DDSURFACEDESC rgb565_format =
>>> +{
>>> +    .dwSize = sizeof(DDSURFACEDESC),
>>> +    .dwFlags = DDSD_PIXELFORMAT,
>>> +    .ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT),
>>> +    .ddpfPixelFormat.dwFlags = DDPF_RGB,
>>> +    .ddpfPixelFormat.dwRGBBitCount = 16,
>>> +    .ddpfPixelFormat.dwRBitMask = 0xf800,
>>> +    .ddpfPixelFormat.dwGBitMask = 0x07e0,
>>> +    .ddpfPixelFormat.dwBBitMask = 0x001f,
>>> +};
>>> +
>>> +static const DDSURFACEDESC rgb24_format =
>>> +{
>>> +    .dwSize = sizeof(DDSURFACEDESC),
>>> +    .dwFlags = DDSD_PIXELFORMAT,
>>> +    .ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT),
>>> +    .ddpfPixelFormat.dwFlags = DDPF_RGB,
>>> +    .ddpfPixelFormat.dwRGBBitCount = 24,
>>> +    .ddpfPixelFormat.dwRBitMask = 0xff0000,
>>> +    .ddpfPixelFormat.dwGBitMask = 0x00ff00,
>>> +    .ddpfPixelFormat.dwBBitMask = 0x0000ff,
>>> +};
>>> +
>>> +static const DDSURFACEDESC rgb32_format =
>>> +{
>>> +    .dwSize = sizeof(DDSURFACEDESC),
>>> +    .dwFlags = DDSD_PIXELFORMAT,
>>> +    .ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT),
>>> +    .ddpfPixelFormat.dwFlags = DDPF_RGB,
>>> +    .ddpfPixelFormat.dwRGBBitCount = 32,
>>> +    .ddpfPixelFormat.dwRBitMask = 0xff0000,
>>> +    .ddpfPixelFormat.dwGBitMask = 0x00ff00,
>>> +    .ddpfPixelFormat.dwBBitMask = 0x0000ff,
>>> +};
>>> +
>>>
>>>  static const WCHAR primary_video_sink_id[] =
>>>  L"I{A35FF56A-9FDA-11D0-8FDF-00C04FD9189D}"; static const WCHAR
>>>  primary_audio_sink_id[] = L"I{A35FF56B-9FDA-11D0-8FDF-00C04FD9189D}";> 
>>> @@ -4474,6 +4632,153 @@ static void test_ddrawstream_initialize(void)
>>>
>>>      ok(!ref, "Got outstanding refcount %d.\n", ref);
>>>  
>>>  }
>>>
>>> +#define check_ddrawstream_get_format(a,b,c)
>>> check_ddrawstream_get_format_(__LINE__,a,b,c) +static void
>>> check_ddrawstream_get_format_(int line, IDirectDrawMediaStream *stream, +
>>>        const AM_MEDIA_TYPE *mt, const DDSURFACEDESC *expected_format) +{
>>> +    const DDPIXELFORMAT *expected_pf = &expected_format->ddpfPixelFormat;
>>> +    DDSURFACEDESC current_format;
>>> +    DDSURFACEDESC desired_format;
>>> +    struct testfilter source;
>>> +    FILTER_INFO filter_info;
>>> +    PIN_INFO pin_info;
>>> +    DWORD flags;
>>> +    HRESULT hr;
>>> +    IPin *pin;
>>> +
>>> +    hr = IDirectDrawMediaStream_QueryInterface(stream, &IID_IPin, (void
>>> **)&pin); +    ok_(__FILE__, line)(hr == S_OK, "Got hr %#x.\n", hr);
>>> +    hr = IPin_QueryPinInfo(pin, &pin_info);
>>> +    ok_(__FILE__, line)(hr == S_OK, "Got hr %#x.\n", hr);
>>> +    hr = IBaseFilter_QueryFilterInfo(pin_info.pFilter, &filter_info);
>>> +    ok_(__FILE__, line)(hr == S_OK, "Got hr %#x.\n", hr);
>>> +
>>> +    testfilter_init(&source);
>>> +
>>> +    hr = IFilterGraph_AddFilter(filter_info.pGraph,
>>> &source.filter.IBaseFilter_iface, L"source"); +    ok_(__FILE__, line)(hr
>>> == S_OK, "Got hr %#x.\n", hr);
>>> +
>>> +    hr = IFilterGraph_ConnectDirect(filter_info.pGraph,
>>> &source.source.pin.IPin_iface, pin, mt); +    ok_(__FILE__, line)(hr ==
>>> S_OK, "Got hr %#x.\n", hr);
>>> +
>>> +    hr = IDirectDrawMediaStream_GetFormat(stream, NULL, NULL, NULL,
>>> NULL);
>>> +    ok_(__FILE__, line)(hr == S_OK, "Got hr %#x.\n", hr);
>>> +
>>> +    memset(&current_format, 0xcc, sizeof(current_format));
>>> +    current_format.dwSize = sizeof(current_format);
>>> +    memset(&desired_format, 0xcc, sizeof(desired_format));
>>> +    desired_format.dwSize = sizeof(desired_format);
>>> +    flags = 0xdeadbeef;
>>> +    hr = IDirectDrawMediaStream_GetFormat(stream, &current_format, NULL,
>>> &desired_format, &flags); +    ok_(__FILE__, line)(hr == S_OK, "Got hr
>>> %#x.\n", hr);
>>> +    ok_(__FILE__, line)(current_format.dwFlags == (DDSD_WIDTH |
>>> DDSD_HEIGHT | DDSD_CAPS), +            "Got current format flags %#x.\n",
>>> current_format.dwFlags); +    ok_(__FILE__, line)(current_format.dwWidth
>>> == 333, "Got current format width %u.\n", current_format.dwWidth); +   
>>> ok_(__FILE__, line)(current_format.dwHeight == 444, "Got current format
>>> height %u.\n", current_format.dwHeight); +    ok_(__FILE__,
>>> line)(current_format.ddpfPixelFormat.dwSize == sizeof(DDPIXELFORMAT), +  
>>>          "Got current format size %u.\n",
>>> current_format.ddpfPixelFormat.dwSize); +    ok_(__FILE__,
>>> line)(current_format.ddpfPixelFormat.dwFlags == expected_pf->dwFlags, +  
>>>          "Got current format flags %#x.\n",
>>> current_format.ddpfPixelFormat.dwFlags); +    ok_(__FILE__,
>>> line)(current_format.ddpfPixelFormat.dwRGBBitCount ==
>>> expected_pf->dwRGBBitCount, +            "Got current format rgb bit
>>> count %u.\n", current_format.ddpfPixelFormat.dwRGBBitCount); +   
>>> ok_(__FILE__, line)(current_format.ddpfPixelFormat.dwRBitMask ==
>>> expected_pf->dwRBitMask, +            "Got current format r bit mask
>>> %#x.\n", current_format.ddpfPixelFormat.dwRBitMask); +    ok_(__FILE__,
>>> line)(current_format.ddpfPixelFormat.dwGBitMask ==
>>> expected_pf->dwGBitMask, +            "Got current format g bit mask
>>> %#x.\n", current_format.ddpfPixelFormat.dwGBitMask); +    ok_(__FILE__,
>>> line)(current_format.ddpfPixelFormat.dwBBitMask ==
>>> expected_pf->dwBBitMask, +            "Got current format b bit mask
>>> %#x.\n", current_format.ddpfPixelFormat.dwBBitMask); +    ok_(__FILE__,
>>> line)(current_format.ddsCaps.dwCaps == (DDSCAPS_OFFSCREENPLAIN |
>>> DDSCAPS_SYSTEMMEMORY), +            "Got current format caps %#x.\n",
>>> current_format.ddsCaps.dwCaps); +    ok_(__FILE__,
>>> line)(desired_format.dwFlags == (DDSD_WIDTH | DDSD_HEIGHT), +           
>>> "Got desired format flags %#x.\n", desired_format.dwFlags); +   
>>> ok_(__FILE__, line)(desired_format.dwWidth == 333, "Got desired format
>>> width %u.\n", desired_format.dwWidth); +    ok_(__FILE__,
>>> line)(desired_format.dwHeight == 444, "Got desired format height %u.\n",
>>> desired_format.dwHeight); +    ok_(__FILE__,
>>> line)(desired_format.ddpfPixelFormat.dwSize == sizeof(DDPIXELFORMAT), +  
>>>          "Got desired format size %u.\n",
>>> desired_format.ddpfPixelFormat.dwSize); +    ok_(__FILE__,
>>> line)(desired_format.ddpfPixelFormat.dwFlags == expected_pf->dwFlags, +  
>>>          "Got desired format flags %#x.\n",
>>> desired_format.ddpfPixelFormat.dwFlags); +    ok_(__FILE__,
>>> line)(desired_format.ddpfPixelFormat.dwRGBBitCount ==
>>> expected_pf->dwRGBBitCount, +            "Got desired format rgb bit
>>> count %u.\n", desired_format.ddpfPixelFormat.dwRGBBitCount); +   
>>> ok_(__FILE__, line)(desired_format.ddpfPixelFormat.dwRBitMask ==
>>> expected_pf->dwRBitMask, +            "Got desired format r bit mask
>>> %#x.\n", desired_format.ddpfPixelFormat.dwRBitMask); +    ok_(__FILE__,
>>> line)(desired_format.ddpfPixelFormat.dwGBitMask ==
>>> expected_pf->dwGBitMask, +            "Got desired format g bit mask
>>> %#x.\n", desired_format.ddpfPixelFormat.dwGBitMask); +    ok_(__FILE__,
>>> line)(desired_format.ddpfPixelFormat.dwBBitMask ==
>>> expected_pf->dwBBitMask, +            "Got desired format b bit mask
>>> %#x.\n", desired_format.ddpfPixelFormat.dwBBitMask); +    ok_(__FILE__,
>>> line)(desired_format.ddsCaps.dwCaps == (DDSCAPS_OFFSCREENPLAIN |
>>> DDSCAPS_SYSTEMMEMORY), +            "Got desired format caps %#x.\n",
>>> desired_format.ddsCaps.dwCaps); +    ok_(__FILE__, line)(flags == 0, "Got
>>> flags %#x.\n", flags);
>>
>> I'd be fine with signing off on the patch as-is (with that rgb565 error
>> fixed, probably), but as just a suggestion, you might try building the
>> expected DDSURFACEDESC as a local variable and then just performing a
>> memcmp(). That helps test all members at once, simplifies the code, and
>> makes it (I think) quite a lot more readable. Of course, the downside is
>> that you don't know what doesn't match if the test fails, but I'm
>> inclined to call it worthwhile.
> 
> Changed to memcmp. I also had to change the way the format is returned in 
> ::GetFormat: the native implementation only assigns flags, width, height, 
> pixel format, and caps, leaving other fields unchanged.

Looks good, thanks.

(I do feel like this is one of those cases where it actually is a good
idea to zealously match native behaviour, knowing that the application
may or may not draw conclusions from struct members but also might do
something like modify the struct and then pass it straight to ddraw,
which by nature is pretty strict about its parameters.)

> 
>>
>>> +
>>> +    hr = IFilterGraph_Disconnect(filter_info.pGraph,
>>> &source.source.pin.IPin_iface); +    ok_(__FILE__, line)(hr == S_OK, "Got
>>> hr %#x.\n", hr);
>>> +    hr = IFilterGraph_Disconnect(filter_info.pGraph, pin);
>>> +    ok_(__FILE__, line)(hr == S_OK, "Got hr %#x.\n", hr);
>>> +
>>> +    hr = IFilterGraph_RemoveFilter(filter_info.pGraph,
>>> &source.filter.IBaseFilter_iface); +    ok_(__FILE__, line)(hr == S_OK,
>>> "Got hr %#x.\n", hr);
>>> +
>>> +    IFilterGraph_Release(filter_info.pGraph);
>>> +    IBaseFilter_Release(pin_info.pFilter);
>>> +    IPin_Release(pin);
>>> +}
>>> +
>>> +static void test_ddrawstream_get_format(void)
>>> +{
>>> +    IAMMultiMediaStream *mmstream = create_ammultimediastream();
>>> +    IDirectDrawMediaStream *ddraw_stream;
>>> +    DDSURFACEDESC current_format;
>>> +    DDSURFACEDESC desired_format;
>>> +    IDirectDrawPalette *palette;
>>> +    IMediaStream *stream;
>>> +    VIDEOINFO video_info;
>>> +    AM_MEDIA_TYPE mt;
>>> +    DWORD flags;
>>> +    HRESULT hr;
>>> +    ULONG ref;
>>> +
>>> +    hr = IAMMultiMediaStream_AddMediaStream(mmstream, NULL,
>>> &MSPID_PrimaryVideo, 0, &stream); +    ok(hr == S_OK, "Got hr %#x.\n",
>>> hr);
>>> +    hr = IMediaStream_QueryInterface(stream, &IID_IDirectDrawMediaStream,
>>> (void **)&ddraw_stream); +    ok(hr == S_OK, "Got hr %#x.\n", hr);
>>> +
>>> +    current_format.dwSize = sizeof(current_format);
>>> +    desired_format.dwSize = sizeof(desired_format);
>>> +    hr = IDirectDrawMediaStream_GetFormat(ddraw_stream, &current_format,
>>> &palette, &desired_format, &flags); +    ok(hr == MS_E_NOSTREAM, "Got hr
>>> %#x.\n", hr);
>>> +
>>> +    video_info = rgb32_video_info;
>>> +    video_info.rcSource.right = 222;
>>> +    video_info.rcSource.bottom = 333;
>>> +    video_info.rcTarget.right = 444;
>>> +    video_info.rcTarget.bottom = 666;
>>> +    mt = rgb32_mt;
>>> +    mt.pbFormat = (BYTE *)&video_info;
>>> +    check_ddrawstream_get_format(ddraw_stream, &mt, &rgb32_format);
>>> +
>>> +    video_info = rgb32_video_info;
>>> +    video_info.bmiHeader.biHeight = 444;
>>> +    mt = rgb32_mt;
>>> +    mt.pbFormat = (BYTE *)&video_info;
>>> +    check_ddrawstream_get_format(ddraw_stream, &mt, &rgb32_format);
>>> +
>>> +    check_ddrawstream_get_format(ddraw_stream, &rgb8_mt, &rgb8_format);
>>> +    check_ddrawstream_get_format(ddraw_stream, &rgb555_mt,
>>> &rgb555_format); +    check_ddrawstream_get_format(ddraw_stream,
>>> &rgb565_mt, &rgb565_format); +   
>>> check_ddrawstream_get_format(ddraw_stream, &rgb24_mt, &rgb24_format); +  
>>>  check_ddrawstream_get_format(ddraw_stream, &rgb32_mt, &rgb32_format);
>> Again, fine with the patch as is, but as an alternative you might use
>> non-static-const local variables; it could make the translation a bit
>> clearer. I could go either way with this, so your call ;-)
> 
> Sorry, I don't quite understand your suggestion. Could you please provide more 
> details? I've sent v3 without this improvement for now. I'll make another 
> version with this improvement if you think it's worthwhile.

Sorry, to clarify, something like:

    DDSURFACEDESC desc =
    {
        .dwSize = sizeof(DDSURFACEDESC),
        .dwFlags = DDSD_PIXELFORMAT,
        .ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT),
    };
    VIDEOINFO vi =
    {
        .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
        .bmiHeader.biWidth = 333,
        .bmiHeader.biHeight = -444,
        .bmiHeader.biPlanes = 1,
    };
    AM_MEDIA_TYPE mt =
    {
        .majortype = MEDIATYPE_Video,
        .formattype = FORMAT_VideoInfo,
        .cbFormat = sizeof(vi),
        .pbFormat = (BYTE *)&vi;
    };

    desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
    desc.ddpfPixelFormat.dwRGBBitCount = 16;
    desc.ddpfPixelFormat.dwRBitMask = 0xf800;
    desc.ddpfPixelFormat.dwGBitMask = 0x07e0;
    desc.ddpfPixelFormat.dwBBitMask = 0x001f;
    mt.subtype = MEDIASUBTPYE_RGB565;
    vi.biBitCount = 16;
    vi.biCompression = BI_BITFIELDS;
    check_ddrawstream_get_format(ddraw_stream, &mt, &desc);

    desc.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
    desc.ddpfPixelFormat.dwRGBBitCount = 8;
    mt.subtype = MEDIASUBTPYE_RGB8;
    vi.biBitCount = 8;
    vi.biCompression = BI_RGB;
    check_ddrawstream_get_format(ddraw_stream, &mt, &desc);

Which, granted, is still a lot of code; it saves a bit of duplication at
the expense of adding some more. It puts the two sides of the mapping
right next to each other, but it's also not unreadable as it is. Anyway,
it's more than a little quibbling ;-)

> 
>>
>>> +
>>> +    current_format.dwSize = sizeof(current_format);
>>> +    desired_format.dwSize = sizeof(desired_format);
>>> +    hr = IDirectDrawMediaStream_GetFormat(ddraw_stream, &current_format,
>>> &palette, &desired_format, &flags); +    ok(hr == MS_E_NOSTREAM, "Got hr
>>> %#x.\n", hr);
>>> +
>>> +    ref = IAMMultiMediaStream_Release(mmstream);
>>> +    ok(!ref, "Got outstanding refcount %d.\n", ref);
>>> +    IDirectDrawMediaStream_Release(ddraw_stream);
>>> +    ref = IMediaStream_Release(stream);
>>> +    ok(!ref, "Got outstanding refcount %d.\n", ref);
>>> +}
>>> +
>>>
>>>  static void check_ammediastream_join_am_multi_media_stream(const CLSID
>>>  *clsid) {
>>>  
>>>      IAMMultiMediaStream *mmstream = create_ammultimediastream();
>>>
>>> @@ -5936,6 +6241,7 @@ START_TEST(amstream)
>>>
>>>      test_ddrawstream_getsetdirectdraw();
>>>      test_ddrawstream_receive_connection();
>>>      test_ddrawstream_create_sample();
>>>
>>> +    test_ddrawstream_get_format();
>>>
>>>      test_ddrawstreamsample_get_media_stream();
> 
> 
> 
> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20200909/a620ff72/attachment-0001.sig>


More information about the wine-devel mailing list