Module: wine Branch: master Commit: fa323802925d6ab153a0577a4bc350f4d1ca7ccd URL: https://gitlab.winehq.org/wine/wine/-/commit/fa323802925d6ab153a0577a4bc350f...
Author: Zebediah Figura zfigura@codeweavers.com Date: Thu May 4 12:27:54 2023 -0500
qcap/audiorecord: Implement pin_get_media_type().
---
dlls/qcap/audiorecord.c | 69 ++++++++++++++++++++++++++++++++++++ dlls/qcap/tests/audiorecord.c | 82 +++++++++++++++++++++---------------------- 2 files changed, 109 insertions(+), 42 deletions(-)
diff --git a/dlls/qcap/audiorecord.c b/dlls/qcap/audiorecord.c index 40fde996479..7107f22851b 100644 --- a/dlls/qcap/audiorecord.c +++ b/dlls/qcap/audiorecord.c @@ -50,6 +50,74 @@ static HRESULT audio_record_source_query_interface(struct strmbase_pin *iface, R return S_OK; }
+static const struct +{ + unsigned int rate; + unsigned int depth; + unsigned int channels; +} +audio_formats[] = +{ + {44100, 16, 2}, + {44100, 16, 1}, + {32000, 16, 2}, + {32000, 16, 1}, + {22050, 16, 2}, + {22050, 16, 1}, + {11025, 16, 2}, + {11025, 16, 1}, + { 8000, 16, 2}, + { 8000, 16, 1}, + {44100, 8, 2}, + {44100, 8, 1}, + {22050, 8, 2}, + {22050, 8, 1}, + {11025, 8, 2}, + {11025, 8, 1}, + { 8000, 8, 2}, + { 8000, 8, 1}, + {48000, 16, 2}, + {48000, 16, 1}, + {96000, 16, 2}, + {96000, 16, 1}, +}; + +static HRESULT fill_media_type(unsigned int index, AM_MEDIA_TYPE *mt) +{ + WAVEFORMATEX *format; + + if (index >= ARRAY_SIZE(audio_formats)) + return VFW_S_NO_MORE_ITEMS; + + if (!(format = CoTaskMemAlloc(sizeof(*format)))) + return E_OUTOFMEMORY; + + memset(format, 0, sizeof(WAVEFORMATEX)); + format->wFormatTag = WAVE_FORMAT_PCM; + format->nChannels = audio_formats[index].channels; + format->nSamplesPerSec = audio_formats[index].rate; + format->wBitsPerSample = audio_formats[index].depth; + format->nBlockAlign = audio_formats[index].channels * audio_formats[index].depth / 8; + format->nAvgBytesPerSec = format->nBlockAlign * format->nSamplesPerSec; + + memset(mt, 0, sizeof(AM_MEDIA_TYPE)); + mt->majortype = MEDIATYPE_Audio; + mt->subtype = MEDIASUBTYPE_PCM; + mt->bFixedSizeSamples = TRUE; + mt->lSampleSize = format->nBlockAlign; + mt->formattype = FORMAT_WaveFormatEx; + mt->cbFormat = sizeof(WAVEFORMATEX); + mt->pbFormat = (BYTE *)format; + + return S_OK; +} + +static HRESULT audio_record_source_get_media_type(struct strmbase_pin *iface, + unsigned int index, AM_MEDIA_TYPE *mt) +{ + return fill_media_type(index, mt); +} + static HRESULT WINAPI audio_record_source_DecideBufferSize(struct strmbase_source *iface, IMemAllocator *allocator, ALLOCATOR_PROPERTIES *props) { @@ -60,6 +128,7 @@ static HRESULT WINAPI audio_record_source_DecideBufferSize(struct strmbase_sourc
static const struct strmbase_source_ops source_ops = { + .base.pin_get_media_type = audio_record_source_get_media_type, .base.pin_query_interface = audio_record_source_query_interface, .pfnAttemptConnection = BaseOutputPinImpl_AttemptConnection, .pfnDecideAllocator = BaseOutputPinImpl_DecideAllocator, diff --git a/dlls/qcap/tests/audiorecord.c b/dlls/qcap/tests/audiorecord.c index 89964100ab6..6d06a5417bd 100644 --- a/dlls/qcap/tests/audiorecord.c +++ b/dlls/qcap/tests/audiorecord.c @@ -386,50 +386,48 @@ static void test_media_types(IBaseFilter *filter) ok(hr == S_OK, "Got hr %#lx.\n", hr);
hr = IEnumMediaTypes_Next(enummt, 1, &pmt, NULL); - todo_wine ok(hr == S_OK, "Got hr %#lx.\n", hr); - if (hr == S_OK) + ok(hr == S_OK, "Got hr %#lx.\n", hr); + + pformat = (void *)pmt->pbFormat; + ok(pformat->nChannels == 2, "Got %u channels.\n", pformat->nChannels); + ok(pformat->wBitsPerSample == 16, "Got depth %u.\n", pformat->wBitsPerSample); + ok(pformat->nSamplesPerSec == 44100, "Got sample rate %lu.\n", pformat->nSamplesPerSec); + + do { pformat = (void *)pmt->pbFormat; - ok(pformat->nChannels == 2, "Got %u channels.\n", pformat->nChannels); - ok(pformat->wBitsPerSample == 16, "Got depth %u.\n", pformat->wBitsPerSample); - ok(pformat->nSamplesPerSec == 44100, "Got sample rate %lu.\n", pformat->nSamplesPerSec);
- do - { - pformat = (void *)pmt->pbFormat; - - ok(IsEqualGUID(&pmt->majortype, &MEDIATYPE_Audio), "Got major type %s.\n", - debugstr_guid(&pmt->majortype)); - ok(IsEqualGUID(&pmt->subtype, &MEDIASUBTYPE_PCM), "Got subtype %s\n", - debugstr_guid(&pmt->subtype)); - ok(pmt->bFixedSizeSamples == TRUE, "Got fixed size %d.\n", pmt->bFixedSizeSamples); - ok(!pmt->bTemporalCompression, "Got temporal compression %d.\n", pmt->bTemporalCompression); - ok(pmt->lSampleSize == pformat->nBlockAlign, "Got sample size %lu.\n", pmt->lSampleSize); - ok(IsEqualGUID(&pmt->formattype, &FORMAT_WaveFormatEx), "Got format type %s.\n", - debugstr_guid(&pmt->formattype)); - ok(!pmt->pUnk, "Got pUnk %p.\n", pmt->pUnk); - ok(pmt->cbFormat == sizeof(WAVEFORMATEX), "Got format size %lu.\n", pmt->cbFormat); - - ok(pformat->wFormatTag == WAVE_FORMAT_PCM, "Got format %#x.\n", pformat->wFormatTag); - ok(pformat->nChannels == 1 || pformat->nChannels == 2, "Got %u channels.\n", pformat->nChannels); - ok(pformat->wBitsPerSample == 8 || pformat->wBitsPerSample == 16, "Got depth %u.\n", pformat->wBitsPerSample); - ok(pformat->nBlockAlign == pformat->nChannels * pformat->wBitsPerSample / 8, - "Got block align %u.\n", pformat->nBlockAlign); - ok(pformat->nAvgBytesPerSec == pformat->nSamplesPerSec * pformat->nBlockAlign, - "Got %lu bytes per second.\n", pformat->nAvgBytesPerSec); - ok(!pformat->cbSize, "Got size %u.\n", pformat->cbSize); - - strmbase_dump_media_type(pmt); - - hr = IPin_QueryAccept(pin, pmt); - ok(hr == S_OK, "Got hr %#lx.\n", hr); - - CoTaskMemFree(pmt->pbFormat); - CoTaskMemFree(pmt); - - hr = IEnumMediaTypes_Next(enummt, 1, &pmt, NULL); - } while (hr == S_OK); - } + ok(IsEqualGUID(&pmt->majortype, &MEDIATYPE_Audio), "Got major type %s.\n", + debugstr_guid(&pmt->majortype)); + ok(IsEqualGUID(&pmt->subtype, &MEDIASUBTYPE_PCM), "Got subtype %s\n", + debugstr_guid(&pmt->subtype)); + ok(pmt->bFixedSizeSamples == TRUE, "Got fixed size %d.\n", pmt->bFixedSizeSamples); + ok(!pmt->bTemporalCompression, "Got temporal compression %d.\n", pmt->bTemporalCompression); + ok(pmt->lSampleSize == pformat->nBlockAlign, "Got sample size %lu.\n", pmt->lSampleSize); + ok(IsEqualGUID(&pmt->formattype, &FORMAT_WaveFormatEx), "Got format type %s.\n", + debugstr_guid(&pmt->formattype)); + ok(!pmt->pUnk, "Got pUnk %p.\n", pmt->pUnk); + ok(pmt->cbFormat == sizeof(WAVEFORMATEX), "Got format size %lu.\n", pmt->cbFormat); + + ok(pformat->wFormatTag == WAVE_FORMAT_PCM, "Got format %#x.\n", pformat->wFormatTag); + ok(pformat->nChannels == 1 || pformat->nChannels == 2, "Got %u channels.\n", pformat->nChannels); + ok(pformat->wBitsPerSample == 8 || pformat->wBitsPerSample == 16, "Got depth %u.\n", pformat->wBitsPerSample); + ok(pformat->nBlockAlign == pformat->nChannels * pformat->wBitsPerSample / 8, + "Got block align %u.\n", pformat->nBlockAlign); + ok(pformat->nAvgBytesPerSec == pformat->nSamplesPerSec * pformat->nBlockAlign, + "Got %lu bytes per second.\n", pformat->nAvgBytesPerSec); + ok(!pformat->cbSize, "Got size %u.\n", pformat->cbSize); + + strmbase_dump_media_type(pmt); + + hr = IPin_QueryAccept(pin, pmt); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + + CoTaskMemFree(pmt->pbFormat); + CoTaskMemFree(pmt); + + hr = IEnumMediaTypes_Next(enummt, 1, &pmt, NULL); + } while (hr == S_OK);
ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
@@ -522,7 +520,7 @@ static void test_stream_config(IBaseFilter *filter) hr = IAMStreamConfig_GetStreamCaps(config, count, &mt, (BYTE *)&caps); todo_wine ok(hr == S_FALSE, "Got hr %#lx.\n", hr); hr = IEnumMediaTypes_Next(enummt, 1, &mt2, NULL); - ok(hr == S_FALSE, "Got hr %#lx.\n", hr); + todo_wine ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
IEnumMediaTypes_Release(enummt);