From: Anton Baskanov baskanov@gmail.com
Signed-off-by: Anton Baskanov baskanov@gmail.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- v3: Resent with stylistic changes.
dlls/amstream/audiostream.c | 21 +++-- dlls/amstream/tests/Makefile.in | 2 +- dlls/amstream/tests/amstream.c | 155 ++++++++++++++++++++++++++++++-- 3 files changed, 166 insertions(+), 12 deletions(-)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index 2875e1f59b7..544f70a75cd 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -495,17 +495,28 @@ static HRESULT WINAPI audio_IAudioMediaStream_SendEndOfStream(IAudioMediaStream }
/*** IAudioMediaStream methods ***/ -static HRESULT WINAPI audio_IAudioMediaStream_GetFormat(IAudioMediaStream *iface, WAVEFORMATEX *wave_format_current) +static HRESULT WINAPI audio_IAudioMediaStream_GetFormat(IAudioMediaStream *iface, WAVEFORMATEX *format) { - struct audio_stream *This = impl_from_IAudioMediaStream(iface); + struct audio_stream *stream = impl_from_IAudioMediaStream(iface);
- FIXME("(%p/%p)->(%p) stub!\n", iface, This, wave_format_current); + TRACE("stream %p, format %p.\n", stream, format);
- if (!wave_format_current) + if (!format) return E_POINTER;
- return MS_E_NOSTREAM; + EnterCriticalSection(&stream->cs);
+ if (!stream->peer) + { + LeaveCriticalSection(&stream->cs); + return MS_E_NOSTREAM; + } + + *format = *(WAVEFORMATEX *)stream->mt.pbFormat; + + LeaveCriticalSection(&stream->cs); + + return S_OK; }
static HRESULT WINAPI audio_IAudioMediaStream_SetFormat(IAudioMediaStream *iface, const WAVEFORMATEX *wave_format) diff --git a/dlls/amstream/tests/Makefile.in b/dlls/amstream/tests/Makefile.in index 3a1a269feae..81eaed3c152 100644 --- a/dlls/amstream/tests/Makefile.in +++ b/dlls/amstream/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = amstream.dll -IMPORTS = strmiids uuid ddraw ole32 user32 +IMPORTS = strmbase strmiids uuid ddraw ole32 user32
C_SRCS = \ amstream.c diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index 6497dde91c3..743dbb99cc0 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -27,6 +27,7 @@ #include "ks.h" #include "initguid.h" #include "ksmedia.h" +#include "wine/strmbase.h"
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}"; @@ -987,16 +988,10 @@ static void test_media_streams(void) if (SUCCEEDED(hr)) { IAudioData* audio_data = NULL; - WAVEFORMATEX format;
hr = CoCreateInstance(&CLSID_AMAudioData, NULL, CLSCTX_INPROC_SERVER, &IID_IAudioData, (void **)&audio_data); ok(hr == S_OK, "CoCreateInstance returned: %x\n", hr);
- hr = IAudioMediaStream_GetFormat(audio_media_stream, NULL); - ok(hr == E_POINTER, "IAudioMediaStream_GetFormat returned: %x\n", hr); - hr = IAudioMediaStream_GetFormat(audio_media_stream, &format); - ok(hr == MS_E_NOSTREAM, "IAudioMediaStream_GetFormat returned: %x\n", hr); - hr = IAudioMediaStream_CreateSample(audio_media_stream, NULL, 0, &audio_sample); ok(hr == E_POINTER, "IAudioMediaStream_CreateSample returned: %x\n", hr); hr = IAudioMediaStream_CreateSample(audio_media_stream, audio_data, 0, &audio_sample); @@ -2293,6 +2288,152 @@ out_unknown: IUnknown_Release(unknown); }
+struct testfilter +{ + struct strmbase_filter filter; + struct strmbase_source source; +}; + +static inline struct testfilter *impl_from_BaseFilter(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_BaseFilter(iface); + if (!index) + return &filter->source.pin; + return NULL; +} + +static void testfilter_destroy(struct strmbase_filter *iface) +{ + struct testfilter *filter = impl_from_BaseFilter(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 testsource_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt) +{ + return S_OK; +} + +static HRESULT WINAPI testsource_DecideAllocator(struct strmbase_source *iface, + IMemInputPin *peer, IMemAllocator **allocator) +{ + return S_OK; +} + +static const struct strmbase_source_ops testsource_ops = +{ + .base.pin_query_accept = testsource_query_accept, + .base.pin_get_media_type = strmbase_pin_get_media_type, + .pfnAttemptConnection = BaseOutputPinImpl_AttemptConnection, + .pfnDecideAllocator = testsource_DecideAllocator, +}; + +static void testfilter_init(struct testfilter *filter) +{ + static const GUID clsid = {0xabacab}; + strmbase_filter_init(&filter->filter, NULL, &clsid, &testfilter_ops); + strmbase_source_init(&filter->source, &filter->filter, L"", &testsource_ops); +} + +static void test_audiostream_get_format(void) +{ + static const WAVEFORMATEX pin_format = + { + .wFormatTag = WAVE_FORMAT_PCM, + .nChannels = 2, + .nSamplesPerSec = 44100, + .wBitsPerSample = 16, + .nBlockAlign = 4, + .nAvgBytesPerSec = 4 * 44100, + }; + AM_MEDIA_TYPE mt = + { + .majortype = MEDIATYPE_Audio, + .subtype = MEDIASUBTYPE_PCM, + .formattype = FORMAT_WaveFormatEx, + .cbFormat = sizeof(WAVEFORMATEX), + .pbFormat = (BYTE *)&pin_format, + }; + IAMMultiMediaStream *mmstream = create_ammultimediastream(); + IAudioMediaStream *audio_stream; + struct testfilter source; + IGraphBuilder *graph; + IMediaStream *stream; + WAVEFORMATEX format; + HRESULT hr; + ULONG ref; + IPin *pin; + + hr = IAMMultiMediaStream_Initialize(mmstream, STREAMTYPE_READ, 0, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAMMultiMediaStream_AddMediaStream(mmstream, NULL, &MSPID_PrimaryAudio, 0, &stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMediaStream_QueryInterface(stream, &IID_IAudioMediaStream, (void **)&audio_stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMediaStream_QueryInterface(stream, &IID_IPin, (void **)&pin); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAMMultiMediaStream_GetFilterGraph(mmstream, &graph); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!!graph, "Expected non-NULL graph.\n"); + + testfilter_init(&source); + + hr = IGraphBuilder_AddFilter(graph, &source.filter.IBaseFilter_iface, L"source"); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAudioMediaStream_GetFormat(audio_stream, NULL); + ok(hr == E_POINTER, "Got hr %#x.\n", hr); + + hr = IAudioMediaStream_GetFormat(audio_stream, &format); + ok(hr == MS_E_NOSTREAM, "Got hr %#x.\n", hr); + + hr = IGraphBuilder_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + memset(&format, 0xcc, sizeof(format)); + hr = IAudioMediaStream_GetFormat(audio_stream, &format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(format.wFormatTag == WAVE_FORMAT_PCM, "Got tag %#x.\n", format.wFormatTag); + ok(format.nChannels == 2, "Got %u channels.\n", format.nChannels); + ok(format.nSamplesPerSec == 44100, "Got sample rate %u.\n", format.nSamplesPerSec); + ok(format.nAvgBytesPerSec == 176400, "Got %u bytes/sec.\n", format.nAvgBytesPerSec); + ok(format.nBlockAlign == 4, "Got alignment %u.\n", format.nBlockAlign); + ok(format.wBitsPerSample == 16, "Got %u bits/sample.\n", format.wBitsPerSample); + ok(!format.cbSize, "Got extra size %u.\n", format.cbSize); + + hr = IGraphBuilder_Disconnect(graph, pin); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IGraphBuilder_Disconnect(graph, &source.source.pin.IPin_iface); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAudioMediaStream_GetFormat(audio_stream, &format); + ok(hr == MS_E_NOSTREAM, "Got hr %#x.\n", hr); + + ref = IAMMultiMediaStream_Release(mmstream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IGraphBuilder_Release(graph); + ok(!ref, "Got outstanding refcount %d.\n", ref); + IPin_Release(pin); + IAudioMediaStream_Release(audio_stream); + ref = IMediaStream_Release(stream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(&source.filter.IBaseFilter_iface); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + START_TEST(amstream) { HANDLE file; @@ -2326,5 +2467,7 @@ START_TEST(amstream) test_audiodata_get_format(); test_audiodata_set_format();
+ test_audiostream_get_format(); + CoUninitialize(); }
From: Anton Baskanov baskanov@gmail.com
Signed-off-by: Anton Baskanov baskanov@gmail.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- v3: Resent with stylistic changes. Also, remove some irrelevant AM_MEDIA_TYPE elements.
dlls/amstream/audiostream.c | 28 ++++- dlls/amstream/tests/amstream.c | 184 +++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+), 4 deletions(-)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index 544f70a75cd..ca4e1635664 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -183,6 +183,7 @@ struct audio_stream IPin *peer; IMemAllocator *allocator; AM_MEDIA_TYPE mt; + WAVEFORMATEX format; };
static inline struct audio_stream *impl_from_IAMMediaStream(IAMMediaStream *iface) @@ -519,13 +520,32 @@ static HRESULT WINAPI audio_IAudioMediaStream_GetFormat(IAudioMediaStream *iface return S_OK; }
-static HRESULT WINAPI audio_IAudioMediaStream_SetFormat(IAudioMediaStream *iface, const WAVEFORMATEX *wave_format) +static HRESULT WINAPI audio_IAudioMediaStream_SetFormat(IAudioMediaStream *iface, const WAVEFORMATEX *format) { - struct audio_stream *This = impl_from_IAudioMediaStream(iface); + struct audio_stream *stream = impl_from_IAudioMediaStream(iface);
- FIXME("(%p/%p)->(%p) stub!\n", iface, This, wave_format); + TRACE("stream %p, format %p.\n", stream, format);
- return E_NOTIMPL; + if (!format) + return E_POINTER; + + if (format->wFormatTag != WAVE_FORMAT_PCM) + return E_INVALIDARG; + + EnterCriticalSection(&stream->cs); + + if ((stream->peer && memcmp(format, stream->mt.pbFormat, sizeof(WAVEFORMATEX))) + || (stream->format.wFormatTag && memcmp(format, &stream->format, sizeof(WAVEFORMATEX)))) + { + LeaveCriticalSection(&stream->cs); + return E_INVALIDARG; + } + + stream->format = *format; + + LeaveCriticalSection(&stream->cs); + + return S_OK; }
static HRESULT WINAPI audio_IAudioMediaStream_CreateSample(IAudioMediaStream *iface, IAudioData *audio_data, diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index 743dbb99cc0..b11a353b037 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -2434,6 +2434,189 @@ static void test_audiostream_get_format(void) ok(!ref, "Got outstanding refcount %d.\n", ref); }
+static HRESULT set_audiostream_format(const WAVEFORMATEX *format) +{ + IAMMultiMediaStream *mmstream = create_ammultimediastream(); + IAudioMediaStream *audio_stream; + IMediaStream *stream; + HRESULT hr; + ULONG ref; + + hr = IAMMultiMediaStream_AddMediaStream(mmstream, NULL, &MSPID_PrimaryAudio, 0, &stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMediaStream_QueryInterface(stream, &IID_IAudioMediaStream, (void **)&audio_stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAudioMediaStream_SetFormat(audio_stream, format); + + ref = IAMMultiMediaStream_Release(mmstream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + IAudioMediaStream_Release(audio_stream); + ref = IMediaStream_Release(stream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + + return hr; +} + +static void test_audiostream_set_format(void) +{ + static const WAVEFORMATEX valid_format = + { + .wFormatTag = WAVE_FORMAT_PCM, + .nChannels = 2, + .nSamplesPerSec = 44100, + .wBitsPerSample = 16, + .nBlockAlign = 4, + .nAvgBytesPerSec = 4 * 44100, + }; + + const AM_MEDIA_TYPE mt = + { + .majortype = MEDIATYPE_Audio, + .subtype = MEDIASUBTYPE_PCM, + .formattype = FORMAT_WaveFormatEx, + .cbFormat = sizeof(WAVEFORMATEX), + .pbFormat = (BYTE *)&valid_format, + }; + + WAVEFORMATEXTENSIBLE extensible_format; + IAudioMediaStream *audio_stream; + IAMMultiMediaStream *mmstream; + struct testfilter source; + IGraphBuilder *graph; + IMediaStream *stream; + WAVEFORMATEX format; + HRESULT hr; + ULONG ref; + IPin *pin; + + hr = set_audiostream_format(&valid_format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = set_audiostream_format(NULL); + ok(hr == E_POINTER, "Got hr %#x.\n", hr); + + extensible_format.Format = valid_format; + extensible_format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; + extensible_format.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX); + extensible_format.Samples.wValidBitsPerSample = valid_format.wBitsPerSample; + extensible_format.dwChannelMask = KSAUDIO_SPEAKER_STEREO; + extensible_format.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + hr = set_audiostream_format(&extensible_format.Format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + format = valid_format; + format.nBlockAlign = 1; + hr = set_audiostream_format(&format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + format = valid_format; + format.nAvgBytesPerSec = 1234; + hr = set_audiostream_format(&format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + mmstream = create_ammultimediastream(); + + hr = IAMMultiMediaStream_AddMediaStream(mmstream, NULL, &MSPID_PrimaryAudio, 0, &stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMediaStream_QueryInterface(stream, &IID_IAudioMediaStream, (void **)&audio_stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAudioMediaStream_SetFormat(audio_stream, &valid_format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAudioMediaStream_GetFormat(audio_stream, &format); + ok(hr == MS_E_NOSTREAM, "Got hr %#x.\n", hr); + + format = valid_format; + format.nChannels = 1; + hr = IAudioMediaStream_SetFormat(audio_stream, &format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + format = valid_format; + format.nSamplesPerSec = 11025; + hr = IAudioMediaStream_SetFormat(audio_stream, &format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + format = valid_format; + format.nAvgBytesPerSec = 1234; + hr = IAudioMediaStream_SetFormat(audio_stream, &format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + format = valid_format; + format.nBlockAlign = 1; + hr = IAudioMediaStream_SetFormat(audio_stream, &format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + format = valid_format; + format.wBitsPerSample = 8; + hr = IAudioMediaStream_SetFormat(audio_stream, &format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + format = valid_format; + format.cbSize = 1; + hr = IAudioMediaStream_SetFormat(audio_stream, &format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + hr = IAudioMediaStream_SetFormat(audio_stream, &valid_format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + ref = IAMMultiMediaStream_Release(mmstream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + IAudioMediaStream_Release(audio_stream); + ref = IMediaStream_Release(stream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + + mmstream = create_ammultimediastream(); + + hr = IAMMultiMediaStream_Initialize(mmstream, STREAMTYPE_READ, 0, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAMMultiMediaStream_AddMediaStream(mmstream, NULL, &MSPID_PrimaryAudio, 0, &stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMediaStream_QueryInterface(stream, &IID_IAudioMediaStream, (void **)&audio_stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMediaStream_QueryInterface(stream, &IID_IPin, (void **)&pin); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAMMultiMediaStream_GetFilterGraph(mmstream, &graph); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!!graph, "Expected non-NULL graph.\n"); + + testfilter_init(&source); + + hr = IGraphBuilder_AddFilter(graph, &source.filter.IBaseFilter_iface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IGraphBuilder_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + format = valid_format; + format.nChannels = 1; + hr = IAudioMediaStream_SetFormat(audio_stream, &format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + hr = IGraphBuilder_Disconnect(graph, pin); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IGraphBuilder_Disconnect(graph, &source.source.pin.IPin_iface); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + format = valid_format; + format.nChannels = 1; + hr = IAudioMediaStream_SetFormat(audio_stream, &format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + ref = IAMMultiMediaStream_Release(mmstream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IGraphBuilder_Release(graph); + ok(!ref, "Got outstanding refcount %d.\n", ref); + IPin_Release(pin); + IAudioMediaStream_Release(audio_stream); + ref = IMediaStream_Release(stream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(&source.filter.IBaseFilter_iface); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + START_TEST(amstream) { HANDLE file; @@ -2468,6 +2651,7 @@ START_TEST(amstream) test_audiodata_set_format();
test_audiostream_get_format(); + test_audiostream_set_format();
CoUninitialize(); }
From: Anton Baskanov baskanov@gmail.com
Signed-off-by: Anton Baskanov baskanov@gmail.com Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- v3: Resent with stylistic changes. Also, get rid of check_audiostream_media_type(), as we can safely try to connect the stream pin multiple times.
dlls/amstream/audiostream.c | 14 ++++ dlls/amstream/tests/amstream.c | 116 +++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index ca4e1635664..1f9aed7338c 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -734,6 +734,14 @@ static HRESULT WINAPI audio_sink_ReceiveConnection(IPin *iface, IPin *peer, cons
TRACE("stream %p, peer %p, mt %p.\n", stream, peer, mt);
+ if (!IsEqualGUID(&mt->majortype, &MEDIATYPE_Audio) + || !IsEqualGUID(&mt->formattype, &FORMAT_WaveFormatEx) + || mt->cbFormat < sizeof(WAVEFORMATEX)) + return VFW_E_TYPE_NOT_ACCEPTED; + + if (((const WAVEFORMATEX *)mt->pbFormat)->wFormatTag != WAVE_FORMAT_PCM) + return E_INVALIDARG; + EnterCriticalSection(&stream->cs);
if (stream->peer) @@ -750,6 +758,12 @@ static HRESULT WINAPI audio_sink_ReceiveConnection(IPin *iface, IPin *peer, cons return VFW_E_INVALID_DIRECTION; }
+ if (stream->format.wFormatTag && memcmp(mt->pbFormat, &stream->format, sizeof(WAVEFORMATEX))) + { + LeaveCriticalSection(&stream->cs); + return E_INVALIDARG; + } + CopyMediaType(&stream->mt, mt); IPin_AddRef(stream->peer = peer);
diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index b11a353b037..80fb138a901 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -2617,6 +2617,121 @@ static void test_audiostream_set_format(void) ok(!ref, "Got outstanding refcount %d.\n", ref); }
+static void test_audiostream_receive_connection(void) +{ + static const WAVEFORMATEX valid_format = + { + .wFormatTag = WAVE_FORMAT_PCM, + .nChannels = 2, + .nSamplesPerSec = 44100, + .wBitsPerSample = 16, + .nBlockAlign = 4, + .nAvgBytesPerSec = 4 * 44100, + }; + + const AM_MEDIA_TYPE valid_mt = + { + .majortype = MEDIATYPE_Audio, + .subtype = MEDIASUBTYPE_PCM, + .formattype = FORMAT_WaveFormatEx, + .cbFormat = sizeof(WAVEFORMATEX), + .pbFormat = (BYTE *)&valid_format, + }; + + WAVEFORMATEXTENSIBLE extensible_format; + IAudioMediaStream *audio_stream; + IAMMultiMediaStream *mmstream; + struct testfilter source; + IGraphBuilder *graph; + IMediaStream *stream; + WAVEFORMATEX format; + AM_MEDIA_TYPE mt; + HRESULT hr; + ULONG ref; + IPin *pin; + + mmstream = create_ammultimediastream(); + hr = IAMMultiMediaStream_Initialize(mmstream, STREAMTYPE_READ, 0, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IAMMultiMediaStream_AddMediaStream(mmstream, NULL, &MSPID_PrimaryAudio, 0, &stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMediaStream_QueryInterface(stream, &IID_IAudioMediaStream, (void **)&audio_stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMediaStream_QueryInterface(stream, &IID_IPin, (void **)&pin); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IAMMultiMediaStream_GetFilterGraph(mmstream, &graph); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(graph != NULL, "Expected non-null graph\n"); + testfilter_init(&source); + hr = IGraphBuilder_AddFilter(graph, &source.filter.IBaseFilter_iface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IGraphBuilder_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &valid_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IGraphBuilder_Disconnect(graph, pin); + IGraphBuilder_Disconnect(graph, &source.source.pin.IPin_iface); + + mt = valid_mt; + mt.majortype = GUID_NULL; + hr = IPin_ReceiveConnection(pin, &source.source.pin.IPin_iface, &mt); + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + + mt = valid_mt; + mt.subtype = MEDIASUBTYPE_RGB24; + hr = IGraphBuilder_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IGraphBuilder_Disconnect(graph, pin); + IGraphBuilder_Disconnect(graph, &source.source.pin.IPin_iface); + + mt = valid_mt; + mt.formattype = GUID_NULL; + hr = IPin_ReceiveConnection(pin, &source.source.pin.IPin_iface, &mt); + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + + mt = valid_mt; + mt.cbFormat = sizeof(WAVEFORMATEX) - 1; + hr = IGraphBuilder_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &mt); + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + + extensible_format.Format = valid_format; + extensible_format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; + extensible_format.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX); + extensible_format.Samples.wValidBitsPerSample = valid_format.wBitsPerSample; + extensible_format.dwChannelMask = KSAUDIO_SPEAKER_STEREO; + extensible_format.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + mt = valid_mt; + mt.cbFormat = sizeof(extensible_format); + mt.pbFormat = (BYTE *)&extensible_format; + hr = IGraphBuilder_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &mt); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + hr = IAudioMediaStream_SetFormat(audio_stream, &valid_format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + format = valid_format; + format.nChannels = 1; + mt = valid_mt; + mt.pbFormat = (BYTE *)&format; + hr = IGraphBuilder_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &mt); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + hr = IGraphBuilder_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &valid_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IGraphBuilder_Disconnect(graph, pin); + IGraphBuilder_Disconnect(graph, &source.source.pin.IPin_iface); + + ref = IAMMultiMediaStream_Release(mmstream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IGraphBuilder_Release(graph); + ok(!ref, "Got outstanding refcount %d.\n", ref); + IPin_Release(pin); + IAudioMediaStream_Release(audio_stream); + ref = IMediaStream_Release(stream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(&source.filter.IBaseFilter_iface); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + START_TEST(amstream) { HANDLE file; @@ -2652,6 +2767,7 @@ START_TEST(amstream)
test_audiostream_get_format(); test_audiostream_set_format(); + test_audiostream_receive_connection();
CoUninitialize(); }