Add support for the MFAudioFormat_Float subtype in MFCreateWaveFormatExFromMFMediaType.
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/mfplat/mediatype.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/dlls/mfplat/mediatype.c b/dlls/mfplat/mediatype.c index c8028b2a46f..4904dbb566f 100644 --- a/dlls/mfplat/mediatype.c +++ b/dlls/mfplat/mediatype.c @@ -2884,7 +2884,7 @@ HRESULT WINAPI MFCreateWaveFormatExFromMFMediaType(IMFMediaType *mediatype, WAVE if (!IsEqualGUID(&major, &MFMediaType_Audio)) return E_INVALIDARG;
- if (!IsEqualGUID(&subtype, &MFAudioFormat_PCM)) + if (!IsEqualGUID(&subtype, &MFAudioFormat_PCM) && !IsEqualGUID(&subtype, &MFAudioFormat_Float)) { FIXME("Unsupported audio format %s.\n", debugstr_guid(&subtype)); return E_NOTIMPL; @@ -2908,7 +2908,12 @@ HRESULT WINAPI MFCreateWaveFormatExFromMFMediaType(IMFMediaType *mediatype, WAVE
memset(format, 0, *size);
- format->wFormatTag = format_ext ? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_PCM; + if (format_ext) + format->wFormatTag = WAVE_FORMAT_EXTENSIBLE; + else if (IsEqualGUID(&subtype, &MFAudioFormat_Float)) + format->wFormatTag = WAVE_FORMAT_IEEE_FLOAT; + else + format->wFormatTag = WAVE_FORMAT_PCM;
if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_NUM_CHANNELS, &value))) format->nChannels = value;
Add test for MFAudioFormat_Float subtype being passed to MFCreateWaveFormatExFromMFMediaType.
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/mfplat/tests/mfplat.c | 87 ++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 37 deletions(-)
diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index fd9a27d599c..4b96b7620ed 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -4240,10 +4240,20 @@ static void test_wrapped_media_type(void)
static void test_MFCreateWaveFormatExFromMFMediaType(void) { + static const struct wave_fmt_test + { + const GUID *subtype; + WORD format_tag; + } + wave_fmt_tests[] = + { + { &MFAudioFormat_PCM, WAVE_FORMAT_PCM, }, + { &MFAudioFormat_Float, WAVE_FORMAT_IEEE_FLOAT, }, + }; WAVEFORMATEXTENSIBLE *format_ext; IMFMediaType *mediatype; WAVEFORMATEX *format; - UINT32 size; + UINT32 size, i; HRESULT hr;
hr = MFCreateMediaType(&mediatype); @@ -4261,45 +4271,48 @@ static void test_MFCreateWaveFormatExFromMFMediaType(void) hr = IMFMediaType_SetGUID(mediatype, &MF_MT_SUBTYPE, &MFMediaType_Video); ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr);
- /* Audio/PCM */ hr = IMFMediaType_SetGUID(mediatype, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio); ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr); - hr = IMFMediaType_SetGUID(mediatype, &MF_MT_SUBTYPE, &MFAudioFormat_PCM); - ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr);
- hr = MFCreateWaveFormatExFromMFMediaType(mediatype, &format, &size, MFWaveFormatExConvertFlag_Normal); - ok(hr == S_OK, "Failed to create format, hr %#x.\n", hr); - ok(format != NULL, "Expected format structure.\n"); - ok(size == sizeof(*format), "Unexpected size %u.\n", size); - ok(format->wFormatTag == WAVE_FORMAT_PCM, "Unexpected tag.\n"); - ok(format->nChannels == 0, "Unexpected number of channels, %u.\n", format->nChannels); - ok(format->nSamplesPerSec == 0, "Unexpected sample rate, %u.\n", format->nSamplesPerSec); - ok(format->nAvgBytesPerSec == 0, "Unexpected average data rate rate, %u.\n", format->nAvgBytesPerSec); - ok(format->nBlockAlign == 0, "Unexpected alignment, %u.\n", format->nBlockAlign); - ok(format->wBitsPerSample == 0, "Unexpected sample size, %u.\n", format->wBitsPerSample); - ok(format->cbSize == 0, "Unexpected size field, %u.\n", format->cbSize); - CoTaskMemFree(format); - - hr = MFCreateWaveFormatExFromMFMediaType(mediatype, (WAVEFORMATEX **)&format_ext, &size, - MFWaveFormatExConvertFlag_ForceExtensible); - ok(hr == S_OK, "Failed to create format, hr %#x.\n", hr); - ok(format_ext != NULL, "Expected format structure.\n"); - ok(size == sizeof(*format_ext), "Unexpected size %u.\n", size); - ok(format_ext->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "Unexpected tag.\n"); - ok(format_ext->Format.nChannels == 0, "Unexpected number of channels, %u.\n", format_ext->Format.nChannels); - ok(format_ext->Format.nSamplesPerSec == 0, "Unexpected sample rate, %u.\n", format_ext->Format.nSamplesPerSec); - ok(format_ext->Format.nAvgBytesPerSec == 0, "Unexpected average data rate rate, %u.\n", - format_ext->Format.nAvgBytesPerSec); - ok(format_ext->Format.nBlockAlign == 0, "Unexpected alignment, %u.\n", format_ext->Format.nBlockAlign); - ok(format_ext->Format.wBitsPerSample == 0, "Unexpected sample size, %u.\n", format_ext->Format.wBitsPerSample); - ok(format_ext->Format.cbSize == sizeof(*format_ext) - sizeof(format_ext->Format), "Unexpected size field, %u.\n", - format_ext->Format.cbSize); - CoTaskMemFree(format_ext); - - hr = MFCreateWaveFormatExFromMFMediaType(mediatype, &format, &size, MFWaveFormatExConvertFlag_ForceExtensible + 1); - ok(hr == S_OK, "Failed to create format, hr %#x.\n", hr); - ok(size == sizeof(*format), "Unexpected size %u.\n", size); - CoTaskMemFree(format); + for (i = 0; i < ARRAY_SIZE(wave_fmt_tests); ++i) + { + hr = IMFMediaType_SetGUID(mediatype, &MF_MT_SUBTYPE, wave_fmt_tests[i].subtype); + ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr); + + hr = MFCreateWaveFormatExFromMFMediaType(mediatype, &format, &size, MFWaveFormatExConvertFlag_Normal); + ok(hr == S_OK, "Failed to create format, hr %#x.\n", hr); + ok(format != NULL, "Expected format structure.\n"); + ok(size == sizeof(*format), "Unexpected size %u.\n", size); + ok(format->wFormatTag == wave_fmt_tests[i].format_tag, "Expected tag %u, got %u.\n", wave_fmt_tests[i].format_tag, format->wFormatTag); + ok(format->nChannels == 0, "Unexpected number of channels, %u.\n", format->nChannels); + ok(format->nSamplesPerSec == 0, "Unexpected sample rate, %u.\n", format->nSamplesPerSec); + ok(format->nAvgBytesPerSec == 0, "Unexpected average data rate rate, %u.\n", format->nAvgBytesPerSec); + ok(format->nBlockAlign == 0, "Unexpected alignment, %u.\n", format->nBlockAlign); + ok(format->wBitsPerSample == 0, "Unexpected sample size, %u.\n", format->wBitsPerSample); + ok(format->cbSize == 0, "Unexpected size field, %u.\n", format->cbSize); + CoTaskMemFree(format); + + hr = MFCreateWaveFormatExFromMFMediaType(mediatype, (WAVEFORMATEX **)&format_ext, &size, + MFWaveFormatExConvertFlag_ForceExtensible); + ok(hr == S_OK, "Failed to create format, hr %#x.\n", hr); + ok(format_ext != NULL, "Expected format structure.\n"); + ok(size == sizeof(*format_ext), "Unexpected size %u.\n", size); + ok(format_ext->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "Unexpected tag.\n"); + ok(format_ext->Format.nChannels == 0, "Unexpected number of channels, %u.\n", format_ext->Format.nChannels); + ok(format_ext->Format.nSamplesPerSec == 0, "Unexpected sample rate, %u.\n", format_ext->Format.nSamplesPerSec); + ok(format_ext->Format.nAvgBytesPerSec == 0, "Unexpected average data rate rate, %u.\n", + format_ext->Format.nAvgBytesPerSec); + ok(format_ext->Format.nBlockAlign == 0, "Unexpected alignment, %u.\n", format_ext->Format.nBlockAlign); + ok(format_ext->Format.wBitsPerSample == 0, "Unexpected sample size, %u.\n", format_ext->Format.wBitsPerSample); + ok(format_ext->Format.cbSize == sizeof(*format_ext) - sizeof(format_ext->Format), "Unexpected size field, %u.\n", + format_ext->Format.cbSize); + CoTaskMemFree(format_ext); + + hr = MFCreateWaveFormatExFromMFMediaType(mediatype, &format, &size, MFWaveFormatExConvertFlag_ForceExtensible + 1); + ok(hr == S_OK, "Failed to create format, hr %#x.\n", hr); + ok(size == sizeof(*format), "Unexpected size %u.\n", size); + CoTaskMemFree(format); + }
IMFMediaType_Release(mediatype); }
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/mfplat/mediatype.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/dlls/mfplat/mediatype.c b/dlls/mfplat/mediatype.c index 4904dbb566f..36747cae5ca 100644 --- a/dlls/mfplat/mediatype.c +++ b/dlls/mfplat/mediatype.c @@ -41,6 +41,7 @@ struct media_type IMFVideoMediaType IMFVideoMediaType_iface; IMFAudioMediaType IMFAudioMediaType_iface; MFVIDEOFORMAT *video_format; + WAVEFORMATEX *audio_format; };
struct stream_desc @@ -1048,7 +1049,18 @@ static ULONG WINAPI audio_mediatype_AddRef(IMFAudioMediaType *iface) static ULONG WINAPI audio_mediatype_Release(IMFAudioMediaType *iface) { struct media_type *media_type = impl_from_IMFAudioMediaType(iface); - return IMFMediaType_Release(&media_type->IMFMediaType_iface); + ULONG refcount = InterlockedDecrement(&media_type->attributes.ref); + + TRACE("%p, refcount %u.\n", iface, refcount); + + if (!refcount) + { + clear_attributes_object(&media_type->attributes); + CoTaskMemFree(media_type->audio_format); + heap_free(media_type); + } + + return refcount; }
static HRESULT WINAPI audio_mediatype_GetItem(IMFAudioMediaType *iface, REFGUID key, PROPVARIANT *value) @@ -1368,9 +1380,18 @@ static HRESULT WINAPI audio_mediatype_FreeRepresentation(IMFAudioMediaType *ifac
static const WAVEFORMATEX * WINAPI audio_mediatype_GetAudioFormat(IMFAudioMediaType *iface) { - FIXME("%p.\n", iface); + struct media_type *media_type = impl_from_IMFAudioMediaType(iface); + unsigned int size; + HRESULT hr; + + TRACE("%p.\n", iface); + + CoTaskMemFree(media_type->audio_format); + if (FAILED(hr = MFCreateWaveFormatExFromMFMediaType((IMFMediaType *)iface, &media_type->audio_format, &size, + MFWaveFormatExConvertFlag_Normal))) + WARN("Failed to create wave format description, hr %#x.\n", hr);
- return NULL; + return media_type->audio_format; }
static const IMFAudioMediaTypeVtbl audiomediatypevtbl =
On 4/21/21 4:58 AM, Connor McAdams wrote:
Signed-off-by: Connor McAdams cmcadams@codeweavers.com
dlls/mfplat/mediatype.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/dlls/mfplat/mediatype.c b/dlls/mfplat/mediatype.c index 4904dbb566f..36747cae5ca 100644 --- a/dlls/mfplat/mediatype.c +++ b/dlls/mfplat/mediatype.c @@ -41,6 +41,7 @@ struct media_type IMFVideoMediaType IMFVideoMediaType_iface; IMFAudioMediaType IMFAudioMediaType_iface; MFVIDEOFORMAT *video_format;
- WAVEFORMATEX *audio_format;
};
struct stream_desc @@ -1048,7 +1049,18 @@ static ULONG WINAPI audio_mediatype_AddRef(IMFAudioMediaType *iface) static ULONG WINAPI audio_mediatype_Release(IMFAudioMediaType *iface) { struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
- return IMFMediaType_Release(&media_type->IMFMediaType_iface);
- ULONG refcount = InterlockedDecrement(&media_type->attributes.ref);
- TRACE("%p, refcount %u.\n", iface, refcount);
- if (!refcount)
- {
clear_attributes_object(&media_type->attributes);
CoTaskMemFree(media_type->audio_format);
heap_free(media_type);
- }
- return refcount;
}
This should go to the main Release(), together with currently leaked video_format.
static HRESULT WINAPI audio_mediatype_GetItem(IMFAudioMediaType *iface, REFGUID key, PROPVARIANT *value) @@ -1368,9 +1380,18 @@ static HRESULT WINAPI audio_mediatype_FreeRepresentation(IMFAudioMediaType *ifac
static const WAVEFORMATEX * WINAPI audio_mediatype_GetAudioFormat(IMFAudioMediaType *iface) {
- FIXME("%p.\n", iface);
- struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
- unsigned int size;
- HRESULT hr;
- TRACE("%p.\n", iface);
- CoTaskMemFree(media_type->audio_format);
- if (FAILED(hr = MFCreateWaveFormatExFromMFMediaType((IMFMediaType *)iface, &media_type->audio_format, &size,
MFWaveFormatExConvertFlag_Normal)))
WARN("Failed to create wave format description, hr %#x.\n", hr);
- return NULL;
- return media_type->audio_format;
}
static const IMFAudioMediaTypeVtbl audiomediatypevtbl =