Signed-off-by: Anton Baskanov baskanov@gmail.com --- v2: - Protect access to stream data by the stream's critical section - Use strmbase to implement the test pin and filter. - Use IGraphBuilder::ConnectDirect to connect the pins in the test - Use IGraphBuilder::Disconnect to disconnect the pins in tests the test - Use memset instead of manual assignment of debug pattern in the test - Check that all references are released at the end of the test - Improve test trace messages --- dlls/amstream/audiostream.c | 15 +++- dlls/amstream/tests/Makefile.in | 2 +- dlls/amstream/tests/amstream.c | 152 ++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+), 3 deletions(-)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index 2875e1f59b..e4161fa3e6 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -499,13 +499,24 @@ static HRESULT WINAPI audio_IAudioMediaStream_GetFormat(IAudioMediaStream *iface { struct audio_stream *This = impl_from_IAudioMediaStream(iface);
- FIXME("(%p/%p)->(%p) stub!\n", iface, This, wave_format_current); + TRACE("(%p/%p)->(%p)\n", iface, This, wave_format_current);
if (!wave_format_current) return E_POINTER;
- return MS_E_NOSTREAM; + EnterCriticalSection(&This->cs);
+ if (!This->peer) + { + LeaveCriticalSection(&This->cs); + return MS_E_NOSTREAM; + } + + *wave_format_current = *(WAVEFORMATEX *)This->mt.pbFormat; + + LeaveCriticalSection(&This->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 3a1a269fea..81eaed3c15 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 6497dde91c..1d1b7deb3f 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}"; @@ -2293,6 +2294,155 @@ 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) +{ + IAMMultiMediaStream *mmstream = create_ammultimediastream(); + IGraphBuilder *graph = NULL; + struct testfilter source; + IMediaStream *stream = NULL; + IAudioMediaStream *audio_stream = NULL; + IPin *pin = NULL; + WAVEFORMATEX stream_format = {0}; + WAVEFORMATEX media_type_format = {0}; + AM_MEDIA_TYPE media_type = {0}; + HRESULT hr; + ULONG ref; + + 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 = IAudioMediaStream_GetFormat(audio_stream, NULL); + ok(hr == E_POINTER, "Got hr %#x.\n", hr); + + hr = IAudioMediaStream_GetFormat(audio_stream, &stream_format); + ok(hr == MS_E_NOSTREAM, "Got hr %#x.\n", hr); + + media_type_format.wFormatTag = WAVE_FORMAT_PCM; + media_type_format.nChannels = 2; + media_type_format.nSamplesPerSec = 44100; + media_type_format.nAvgBytesPerSec = 176400; + media_type_format.nBlockAlign = 4; + media_type_format.wBitsPerSample = 16; + media_type_format.cbSize = 0; + + media_type.majortype = MEDIATYPE_Audio; + media_type.subtype = MEDIASUBTYPE_PCM; + media_type.bFixedSizeSamples = TRUE; + media_type.bTemporalCompression = FALSE; + media_type.lSampleSize = 2; + media_type.formattype = FORMAT_WaveFormatEx; + media_type.pUnk = NULL; + media_type.cbFormat = sizeof(media_type_format); + media_type.pbFormat = (BYTE *)&media_type_format; + + hr = IGraphBuilder_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &media_type); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + memset(&stream_format, 0xcc, sizeof(stream_format)); + hr = IAudioMediaStream_GetFormat(audio_stream, &stream_format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(stream_format.wFormatTag == WAVE_FORMAT_PCM, "Got wFormatTag %u\n", stream_format.wFormatTag); + ok(stream_format.nChannels == 2, "Got nChannels %u\n", stream_format.nChannels); + ok(stream_format.nSamplesPerSec == 44100, "Got nSamplesPerSec %u\n", stream_format.nSamplesPerSec); + ok(stream_format.nAvgBytesPerSec == 176400, "Got nAvgBytesPerSec %u\n", stream_format.nAvgBytesPerSec); + ok(stream_format.nBlockAlign == 4, "Got nBlockAlign %u\n", stream_format.nBlockAlign); + ok(stream_format.wBitsPerSample == 16, "Got wBitsPerSample %u\n", stream_format.wBitsPerSample); + ok(stream_format.cbSize == 0, "Got cbSize %u\n", stream_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, &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 +2476,7 @@ START_TEST(amstream) test_audiodata_get_format(); test_audiodata_set_format();
+ test_audiostream_get_format(); + CoUninitialize(); }
Signed-off-by: Anton Baskanov baskanov@gmail.com --- v2: - Get rid of is_format_compatible - Use memcmp to compare the formats - Add a test for formats with different cbSize - Protect access to stream data by the stream's critical section - Add a test that show that GetFormat still fails after SetFormat is called - Check that all references are released at the end of the test --- dlls/amstream/audiostream.c | 27 ++++- dlls/amstream/tests/amstream.c | 176 +++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+), 2 deletions(-)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index e4161fa3e6..169f86316d 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) @@ -522,10 +523,32 @@ static HRESULT WINAPI audio_IAudioMediaStream_GetFormat(IAudioMediaStream *iface static HRESULT WINAPI audio_IAudioMediaStream_SetFormat(IAudioMediaStream *iface, const WAVEFORMATEX *wave_format) { struct audio_stream *This = impl_from_IAudioMediaStream(iface); + const WAVEFORMATEX *ref_format;
- FIXME("(%p/%p)->(%p) stub!\n", iface, This, wave_format); + TRACE("(%p/%p)->(%p)\n", iface, This, wave_format);
- return E_NOTIMPL; + if (!wave_format) + return E_POINTER; + + if (wave_format->wFormatTag != WAVE_FORMAT_PCM) + return E_INVALIDARG; + + EnterCriticalSection(&This->cs); + + ref_format = This->peer ? (WAVEFORMATEX *)This->mt.pbFormat : &This->format; + + if (ref_format->wFormatTag == WAVE_FORMAT_PCM && + memcmp(wave_format, ref_format, sizeof(WAVEFORMATEX)) != 0) + { + LeaveCriticalSection(&This->cs); + return E_INVALIDARG; + } + + This->format = *wave_format; + + LeaveCriticalSection(&This->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 1d1b7deb3f..75bde0fba7 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -2443,6 +2443,181 @@ static void test_audiostream_get_format(void) ok(!ref, "Got outstanding refcount %d.\n", ref); }
+static void check_audiostream_format(const WAVEFORMATEX *format, HRESULT expected_hr) +{ + IAMMultiMediaStream *mmstream = create_ammultimediastream(); + IMediaStream *stream = NULL; + IAudioMediaStream *audio_stream = NULL; + 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); + ok(hr == expected_hr, "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); +} + +static void test_audiostream_set_format(void) +{ + IAMMultiMediaStream *mmstream; + IGraphBuilder *graph = NULL; + struct testfilter source; + IMediaStream *stream = NULL; + IAudioMediaStream *audio_stream = NULL; + IPin *pin = NULL; + WAVEFORMATPCMEX valid_format = {{0}}; + WAVEFORMATPCMEX format; + AM_MEDIA_TYPE valid_media_type = {0}; + HRESULT hr; + ULONG ref; + + valid_format.Format.wFormatTag = WAVE_FORMAT_PCM; + valid_format.Format.nChannels = 2; + valid_format.Format.nSamplesPerSec = 44100; + valid_format.Format.nAvgBytesPerSec = 176400; + valid_format.Format.nBlockAlign = 4; + valid_format.Format.wBitsPerSample = 16; + valid_format.Format.cbSize = 0; + + valid_media_type.majortype = MEDIATYPE_Audio; + valid_media_type.subtype = MEDIASUBTYPE_PCM; + valid_media_type.bFixedSizeSamples = TRUE; + valid_media_type.bTemporalCompression = FALSE; + valid_media_type.lSampleSize = 2; + valid_media_type.formattype = FORMAT_WaveFormatEx; + valid_media_type.pUnk = NULL; + valid_media_type.cbFormat = sizeof(WAVEFORMATEX); + valid_media_type.pbFormat = (BYTE *)&valid_format; + + check_audiostream_format(&valid_format.Format, S_OK); + check_audiostream_format(NULL, E_POINTER); + + format = valid_format; + format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; + format.Format.cbSize = 22; + format.Samples.wValidBitsPerSample = 16; + format.dwChannelMask = KSAUDIO_SPEAKER_STEREO; + format.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + check_audiostream_format(&format.Format, E_INVALIDARG); + + format = valid_format; + format.Format.nBlockAlign = 1; + check_audiostream_format(&format.Format, S_OK); + + format = valid_format; + format.Format.nAvgBytesPerSec = 1234; + check_audiostream_format(&format.Format, S_OK); + + 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.Format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAudioMediaStream_GetFormat(audio_stream, &format.Format); + ok(hr == MS_E_NOSTREAM, "Got hr %#x.\n", hr); + + format = valid_format; + format.Format.nChannels = 1; + hr = IAudioMediaStream_SetFormat(audio_stream, &format.Format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + format = valid_format; + format.Format.nSamplesPerSec = 11025; + hr = IAudioMediaStream_SetFormat(audio_stream, &format.Format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + format = valid_format; + format.Format.nAvgBytesPerSec = 1234; + hr = IAudioMediaStream_SetFormat(audio_stream, &format.Format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + format = valid_format; + format.Format.nBlockAlign = 1; + hr = IAudioMediaStream_SetFormat(audio_stream, &format.Format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + format = valid_format; + format.Format.wBitsPerSample = 8; + hr = IAudioMediaStream_SetFormat(audio_stream, &format.Format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + format = valid_format; + format.Format.cbSize = 1; + hr = IAudioMediaStream_SetFormat(audio_stream, &format.Format); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + hr = IAudioMediaStream_SetFormat(audio_stream, &valid_format.Format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + IAudioMediaStream_Release(audio_stream); + IMediaStream_Release(stream); + IAMMultiMediaStream_Release(mmstream); + + 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_media_type); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + format = valid_format; + format.Format.nChannels = 1; + hr = IAudioMediaStream_SetFormat(audio_stream, &format.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.Format.nChannels = 1; + hr = IAudioMediaStream_SetFormat(audio_stream, &format.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; @@ -2477,6 +2652,7 @@ START_TEST(amstream) test_audiodata_set_format();
test_audiostream_get_format(); + test_audiostream_set_format();
CoUninitialize(); }
Signed-off-by: Anton Baskanov baskanov@gmail.com --- v2: - Move input argument check out of critical section - Use memcmp to compare formats - Check that all references are released at the end of the test --- dlls/amstream/audiostream.c | 17 ++++ dlls/amstream/tests/amstream.c | 159 +++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index 169f86316d..17a1c3d38c 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -737,6 +737,16 @@ 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->pbFormat || 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) @@ -753,6 +763,13 @@ static HRESULT WINAPI audio_sink_ReceiveConnection(IPin *iface, IPin *peer, cons return VFW_E_INVALID_DIRECTION; }
+ if (stream->format.wFormatTag == WAVE_FORMAT_PCM && + memcmp(mt->pbFormat, &stream->format, sizeof(WAVEFORMATEX)) != 0) + { + 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 75bde0fba7..5d383652ad 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -2618,6 +2618,164 @@ static void test_audiostream_set_format(void) ok(!ref, "Got outstanding refcount %d.\n", ref); }
+static void check_audiostream_media_type(const AM_MEDIA_TYPE *media_type, HRESULT expected_hr) +{ + IAMMultiMediaStream *mmstream = create_ammultimediastream(); + IGraphBuilder *graph = NULL; + struct testfilter source; + IMediaStream *stream = NULL; + IPin *pin = NULL; + HRESULT hr; + ULONG ref; + + 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_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 = IPin_ReceiveConnection(pin, &source.source.pin.IPin_iface, media_type); + ok(hr == expected_hr, "Got hr %#x.\n", hr); + + if (SUCCEEDED(hr)) + { + hr = IPin_Disconnect(pin); + 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); + 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); +} + +static void test_audiostream_receive_connection(void) +{ + IAMMultiMediaStream *mmstream; + IGraphBuilder *graph = NULL; + struct testfilter source; + IMediaStream *stream = NULL; + IAudioMediaStream *audio_stream = NULL; + IPin *pin = NULL; + WAVEFORMATPCMEX valid_format = {0}; + WAVEFORMATPCMEX format; + AM_MEDIA_TYPE valid_media_type = {0}; + AM_MEDIA_TYPE media_type; + HRESULT hr; + ULONG ref; + + valid_format.Format.wFormatTag = WAVE_FORMAT_PCM; + valid_format.Format.nChannels = 2; + valid_format.Format.nSamplesPerSec = 44100; + valid_format.Format.nAvgBytesPerSec = 176400; + valid_format.Format.nBlockAlign = 4; + valid_format.Format.wBitsPerSample = 16; + valid_format.Format.cbSize = 0; + + valid_media_type.majortype = MEDIATYPE_Audio; + valid_media_type.subtype = MEDIASUBTYPE_PCM; + valid_media_type.bFixedSizeSamples = TRUE; + valid_media_type.bTemporalCompression = FALSE; + valid_media_type.lSampleSize = 2; + valid_media_type.formattype = FORMAT_WaveFormatEx; + valid_media_type.pUnk = NULL; + valid_media_type.cbFormat = sizeof(WAVEFORMATEX); + valid_media_type.pbFormat = (BYTE *)&valid_format; + + check_audiostream_media_type(&valid_media_type, S_OK); + + media_type = valid_media_type; + media_type.majortype = GUID_NULL; + check_audiostream_media_type(&media_type, VFW_E_TYPE_NOT_ACCEPTED); + + media_type = valid_media_type; + media_type.subtype = MEDIASUBTYPE_RGB24; + check_audiostream_media_type(&media_type, S_OK); + + media_type = valid_media_type; + media_type.formattype = GUID_NULL; + check_audiostream_media_type(&media_type, VFW_E_TYPE_NOT_ACCEPTED); + + media_type = valid_media_type; + media_type.cbFormat = sizeof(WAVEFORMATEX) - 1; + check_audiostream_media_type(&media_type, VFW_E_TYPE_NOT_ACCEPTED); + + format = valid_format; + format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; + format.Format.cbSize = 22; + format.Samples.wValidBitsPerSample = 16; + format.dwChannelMask = KSAUDIO_SPEAKER_STEREO; + format.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + media_type = valid_media_type; + media_type.cbFormat = sizeof(format); + media_type.pbFormat = (BYTE *)&format; + check_audiostream_media_type(&media_type, E_INVALIDARG); + + 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 = IAudioMediaStream_SetFormat(audio_stream, &valid_format.Format); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + format = valid_format; + format.Format.nChannels = 1; + media_type = valid_media_type; + media_type.pbFormat = (BYTE *)&format; + hr = IPin_ReceiveConnection(pin, &source.source.pin.IPin_iface, &media_type); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + hr = IPin_ReceiveConnection(pin, &source.source.pin.IPin_iface, &valid_media_type); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IPin_Disconnect(pin); + 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; @@ -2653,6 +2811,7 @@ START_TEST(amstream)
test_audiostream_get_format(); test_audiostream_set_format(); + test_audiostream_receive_connection();
CoUninitialize(); }