[PATCH 4/5] quartz/tests: Add tests for MPEG audio decoder sink connection.
Anton Baskanov
baskanov at gmail.com
Wed Apr 27 01:42:21 CDT 2022
Signed-off-by: Anton Baskanov <baskanov at gmail.com>
---
dlls/quartz/tests/mpegaudio.c | 304 ++++++++++++++++++++++++++++++++++
1 file changed, 304 insertions(+)
diff --git a/dlls/quartz/tests/mpegaudio.c b/dlls/quartz/tests/mpegaudio.c
index 84297884a6d..defd65eaa62 100644
--- a/dlls/quartz/tests/mpegaudio.c
+++ b/dlls/quartz/tests/mpegaudio.c
@@ -22,6 +22,9 @@
#define COBJMACROS
#include "dshow.h"
#include "mmreg.h"
+#include "ks.h"
+#include "ksmedia.h"
+#include "wine/strmbase.h"
#include "wine/test.h"
static const MPEG1WAVEFORMAT mp1_format =
@@ -127,6 +130,28 @@ static const AM_MEDIA_TYPE mp3_mt1 =
.pbFormat = (BYTE *)&mp3_format1,
};
+static const WAVEFORMATEX pcm8_format =
+{
+ .wFormatTag = WAVE_FORMAT_PCM,
+ .nChannels = 1,
+ .nSamplesPerSec = 32000,
+ .wBitsPerSample = 8,
+ .nBlockAlign = 1,
+ .nAvgBytesPerSec = 32000,
+};
+
+static const AM_MEDIA_TYPE pcm8_mt =
+{
+ /* MEDIATYPE_Audio, MEDIASUBTYPE_PCM, FORMAT_WaveFormatEx */
+ .majortype = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}},
+ .subtype = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}},
+ .bFixedSizeSamples = TRUE,
+ .lSampleSize = 1,
+ .formattype = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}},
+ .cbFormat = sizeof(WAVEFORMATEX),
+ .pbFormat = (BYTE *)&pcm8_format,
+};
+
static const WAVEFORMATEX pcm16_format =
{
.wFormatTag = WAVE_FORMAT_PCM,
@@ -149,6 +174,99 @@ static const AM_MEDIA_TYPE pcm16_mt =
.pbFormat = (BYTE *)&pcm16_format,
};
+static const WAVEFORMATEX pcm16_stereo_format =
+{
+ .wFormatTag = WAVE_FORMAT_PCM,
+ .nChannels = 2,
+ .nSamplesPerSec = 32000,
+ .wBitsPerSample = 16,
+ .nBlockAlign = 4,
+ .nAvgBytesPerSec = 128000,
+};
+
+static const AM_MEDIA_TYPE pcm16_stereo_mt =
+{
+ /* MEDIATYPE_Audio, MEDIASUBTYPE_PCM, FORMAT_WaveFormatEx */
+ .majortype = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}},
+ .subtype = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}},
+ .bFixedSizeSamples = TRUE,
+ .lSampleSize = 4,
+ .formattype = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}},
+ .cbFormat = sizeof(WAVEFORMATEX),
+ .pbFormat = (BYTE *)&pcm16_stereo_format,
+};
+
+static const WAVEFORMATEX pcm16_16khz_format =
+{
+ .wFormatTag = WAVE_FORMAT_PCM,
+ .nChannels = 1,
+ .nSamplesPerSec = 16000,
+ .wBitsPerSample = 16,
+ .nBlockAlign = 2,
+ .nAvgBytesPerSec = 32000,
+};
+
+static const AM_MEDIA_TYPE pcm16_16khz_mt =
+{
+ /* MEDIATYPE_Audio, MEDIASUBTYPE_PCM, FORMAT_WaveFormatEx */
+ .majortype = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}},
+ .subtype = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}},
+ .bFixedSizeSamples = TRUE,
+ .lSampleSize = 2,
+ .formattype = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}},
+ .cbFormat = sizeof(WAVEFORMATEX),
+ .pbFormat = (BYTE *)&pcm16_16khz_format,
+};
+
+static const WAVEFORMATEX pcm24_format =
+{
+ .wFormatTag = WAVE_FORMAT_PCM,
+ .nChannels = 1,
+ .nSamplesPerSec = 32000,
+ .wBitsPerSample = 24,
+ .nBlockAlign = 3,
+ .nAvgBytesPerSec = 96000,
+};
+
+static const AM_MEDIA_TYPE pcm24_mt =
+{
+ /* MEDIATYPE_Audio, MEDIASUBTYPE_PCM, FORMAT_WaveFormatEx */
+ .majortype = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}},
+ .subtype = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}},
+ .bFixedSizeSamples = TRUE,
+ .lSampleSize = 3,
+ .formattype = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}},
+ .cbFormat = sizeof(WAVEFORMATEX),
+ .pbFormat = (BYTE *)&pcm24_format,
+};
+
+static const WAVEFORMATEXTENSIBLE pcm16ex_format =
+{
+ .Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE,
+ .Format.nChannels = 1,
+ .Format.nSamplesPerSec = 32000,
+ .Format.wBitsPerSample = 16,
+ .Format.nBlockAlign = 2,
+ .Format.nAvgBytesPerSec = 64000,
+ .Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX),
+ .Samples.wValidBitsPerSample = 16,
+ .dwChannelMask = KSAUDIO_SPEAKER_STEREO,
+ /* KSDATAFORMAT_SUBTYPE_PCM */
+ .SubFormat = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}},
+};
+
+static const AM_MEDIA_TYPE pcm16ex_mt =
+{
+ /* MEDIATYPE_Audio, MEDIASUBTYPE_PCM, FORMAT_WaveFormatEx */
+ .majortype = {0x73647561, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}},
+ .subtype = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}},
+ .bFixedSizeSamples = TRUE,
+ .lSampleSize = 2,
+ .formattype = {0x05589f81, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}},
+ .cbFormat = sizeof(WAVEFORMATEXTENSIBLE),
+ .pbFormat = (BYTE *)&pcm16ex_format,
+};
+
static IBaseFilter *create_mpeg_audio_codec(void)
{
IBaseFilter *filter = NULL;
@@ -158,6 +276,12 @@ static IBaseFilter *create_mpeg_audio_codec(void)
return filter;
}
+static inline BOOL compare_media_types(const AM_MEDIA_TYPE *a, const AM_MEDIA_TYPE *b)
+{
+ return !memcmp(a, b, offsetof(AM_MEDIA_TYPE, pbFormat))
+ && !memcmp(a->pbFormat, b->pbFormat, a->cbFormat);
+}
+
static ULONG get_refcount(void *iface)
{
IUnknown *unknown = iface;
@@ -792,6 +916,185 @@ static void test_media_types(void)
ok(!ref, "Got outstanding refcount %ld.\n", ref);
}
+struct testfilter
+{
+ struct strmbase_filter filter;
+ struct strmbase_source source;
+ const AM_MEDIA_TYPE *mt;
+};
+
+static inline struct testfilter *impl_from_strmbase_filter(struct strmbase_filter *iface)
+{
+ return CONTAINING_RECORD(iface, struct testfilter, filter);
+}
+
+static struct strmbase_pin *testfilter_get_pin(struct strmbase_filter *iface, unsigned int index)
+{
+ struct testfilter *filter = impl_from_strmbase_filter(iface);
+ if (!index)
+ return &filter->source.pin;
+ return NULL;
+}
+
+static void testfilter_destroy(struct strmbase_filter *iface)
+{
+ struct testfilter *filter = impl_from_strmbase_filter(iface);
+ strmbase_source_cleanup(&filter->source);
+ strmbase_filter_cleanup(&filter->filter);
+}
+
+static const struct strmbase_filter_ops testfilter_ops =
+{
+ .filter_get_pin = testfilter_get_pin,
+ .filter_destroy = testfilter_destroy,
+};
+
+static HRESULT WINAPI testsource_DecideAllocator(struct strmbase_source *iface,
+ IMemInputPin *peer, IMemAllocator **allocator)
+{
+ return S_OK;
+}
+
+static const struct strmbase_source_ops testsource_ops =
+{
+ .pfnAttemptConnection = BaseOutputPinImpl_AttemptConnection,
+ .pfnDecideAllocator = testsource_DecideAllocator,
+};
+
+static void testfilter_init(struct testfilter *filter)
+{
+ static const GUID clsid = {0xabacab};
+ memset(filter, 0, sizeof(*filter));
+ strmbase_filter_init(&filter->filter, NULL, &clsid, &testfilter_ops);
+ strmbase_source_init(&filter->source, &filter->filter, L"source", &testsource_ops);
+}
+
+static void test_connect_pin(void)
+{
+ IBaseFilter *filter = create_mpeg_audio_codec();
+ struct testfilter testsource;
+ IPin *sink, *source, *peer;
+ WAVEFORMATEX req_format;
+ IMediaControl *control;
+ IMemInputPin *meminput;
+ AM_MEDIA_TYPE req_mt;
+ IFilterGraph2 *graph;
+ AM_MEDIA_TYPE mt;
+ HRESULT hr;
+ ULONG ref;
+
+ CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
+ &IID_IFilterGraph2, (void **)&graph);
+ testfilter_init(&testsource);
+ IFilterGraph2_AddFilter(graph, &testsource.filter.IBaseFilter_iface, L"source");
+ IFilterGraph2_AddFilter(graph, filter, L"MPEG audio decoder");
+ IBaseFilter_FindPin(filter, L"In", &sink);
+ IBaseFilter_FindPin(filter, L"Out", &source);
+ IPin_QueryInterface(sink, &IID_IMemInputPin, (void **)&meminput);
+ IFilterGraph2_QueryInterface(graph, &IID_IMediaControl, (void **)&control);
+
+ /* Test sink connection. */
+
+ peer = (IPin *)0xdeadbeef;
+ hr = IPin_ConnectedTo(sink, &peer);
+ ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#lx.\n", hr);
+ ok(!peer, "Got peer %p.\n", peer);
+
+ hr = IPin_ConnectionMediaType(sink, &mt);
+ ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#lx.\n", hr);
+
+ hr = IMediaControl_Pause(control);
+ ok(hr == S_OK, "Got hr %#lx.\n", hr);
+ hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &mp1_mt);
+ ok(hr == VFW_E_NOT_STOPPED, "Got hr %#lx.\n", hr);
+ hr = IMediaControl_Stop(control);
+ ok(hr == S_OK, "Got hr %#lx.\n", hr);
+
+ req_mt = mp1_mt;
+ req_mt.subtype = MEDIASUBTYPE_PCM;
+ hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &req_mt);
+ ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#lx.\n", hr);
+
+ hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &mp1_mt);
+ ok(hr == S_OK, "Got hr %#lx.\n", hr);
+
+ hr = IPin_ConnectedTo(sink, &peer);
+ ok(hr == S_OK, "Got hr %#lx.\n", hr);
+ ok(peer == &testsource.source.pin.IPin_iface, "Got peer %p.\n", peer);
+ IPin_Release(peer);
+
+ hr = IPin_ConnectionMediaType(sink, &mt);
+ ok(hr == S_OK, "Got hr %#lx.\n", hr);
+ ok(compare_media_types(&mt, &mp1_mt), "Media types didn't match.\n");
+ ok(compare_media_types(&testsource.source.pin.mt, &mp1_mt), "Media types didn't match.\n");
+ FreeMediaType(&mt);
+
+ hr = IPin_QueryAccept(source, &pcm16_mt);
+ ok(hr == S_OK, "Got hr %#lx.\n", hr);
+
+ hr = IPin_QueryAccept(source, &pcm8_mt);
+ ok(hr == S_OK, "Got hr %#lx.\n", hr);
+
+ req_mt = pcm16_mt;
+ req_mt.majortype = GUID_NULL;
+ hr = IPin_QueryAccept(source, &req_mt);
+ todo_wine ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
+
+ req_mt = pcm16_mt;
+ req_mt.subtype = GUID_NULL;
+ hr = IPin_QueryAccept(source, &req_mt);
+ todo_wine ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
+
+ req_mt = pcm16_mt;
+ req_mt.formattype = GUID_NULL;
+ hr = IPin_QueryAccept(source, &req_mt);
+ todo_wine ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
+
+ hr = IPin_QueryAccept(source, &pcm16_stereo_mt);
+ todo_wine ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
+
+ hr = IPin_QueryAccept(source, &pcm16_16khz_mt);
+ todo_wine ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
+
+ hr = IPin_QueryAccept(source, &pcm24_mt);
+ todo_wine ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
+
+ hr = IPin_QueryAccept(source, &pcm16ex_mt);
+ todo_wine ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
+
+ req_format = pcm16_format;
+ req_format.nBlockAlign = 333;
+ req_mt = pcm16_mt;
+ req_mt.pbFormat = (BYTE *)&req_format;
+ hr = IPin_QueryAccept(source, &req_mt);
+ todo_wine ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
+
+ req_format = pcm16_format;
+ req_format.nAvgBytesPerSec = 333;
+ req_mt = pcm16_mt;
+ req_mt.pbFormat = (BYTE *)&req_format;
+ hr = IPin_QueryAccept(source, &req_mt);
+ todo_wine ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
+
+ hr = IMediaControl_Pause(control);
+ ok(hr == S_OK, "Got hr %#lx.\n", hr);
+ hr = IFilterGraph2_Disconnect(graph, sink);
+ ok(hr == VFW_E_NOT_STOPPED, "Got hr %#lx.\n", hr);
+ hr = IMediaControl_Stop(control);
+ ok(hr == S_OK, "Got hr %#lx.\n", hr);
+
+ IMemInputPin_Release(meminput);
+ IPin_Release(sink);
+ IPin_Release(source);
+ IMediaControl_Release(control);
+ ref = IFilterGraph2_Release(graph);
+ ok(!ref, "Got outstanding refcount %ld.\n", ref);
+ ref = IBaseFilter_Release(filter);
+ ok(!ref, "Got outstanding refcount %ld.\n", ref);
+ ref = IBaseFilter_Release(&testsource.filter.IBaseFilter_iface);
+ ok(!ref, "Got outstanding refcount %ld.\n", ref);
+}
+
START_TEST(mpegaudio)
{
CoInitialize(NULL);
@@ -804,6 +1107,7 @@ START_TEST(mpegaudio)
test_pin_info();
test_enum_media_types();
test_media_types();
+ test_connect_pin();
CoUninitialize();
}
--
2.34.1
More information about the wine-devel
mailing list