forked from Mirrors/wine-wine
amstream: Reject incompatible media types in AMAudioStream::ReceiveConnection.
Signed-off-by: Anton Baskanov <baskanov@gmail.com> Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>feature/deterministic
parent
bbf0a93e4e
commit
5b94633aa3
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue