Signed-off-by: Anton Baskanov baskanov@gmail.com --- dlls/amstream/audiostream.c | 50 +++++++++++- dlls/amstream/tests/amstream.c | 135 +++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+), 3 deletions(-)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index c018dabf9d..dbac8c8ee8 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -29,13 +29,18 @@ static const WCHAR sink_id[] = L"I{A35FF56B-9FDA-11D0-8FDF-00C04FD9189D}";
enum queued_event_type { - QET_END_OF_STREAM + QET_END_OF_STREAM, + QET_SAMPLE };
struct queued_event { struct list entry; enum queued_event_type type; + IMediaSample *sample; + DWORD length; + BYTE *pointer; + DWORD position; };
struct audio_stream @@ -71,6 +76,8 @@ typedef struct { static void remove_queued_event(struct queued_event *event) { list_remove(&event->entry); + if (event->sample) + IMediaSample_Release(event->sample); HeapFree(GetProcessHeap(), 0, event); }
@@ -1090,8 +1097,45 @@ static HRESULT WINAPI audio_meminput_GetAllocatorRequirements(IMemInputPin *ifac
static HRESULT WINAPI audio_meminput_Receive(IMemInputPin *iface, IMediaSample *sample) { - FIXME("iface %p, sample %p, stub!\n", iface, sample); - return E_NOTIMPL; + struct audio_stream *stream = impl_from_IMemInputPin(iface); + struct queued_event *event; + BYTE *pointer; + HRESULT hr; + + TRACE("(%p)->(%p)\n", stream, sample); + + EnterCriticalSection(&stream->cs); + + if (stream->state == State_Stopped) + { + LeaveCriticalSection(&stream->cs); + return VFW_E_WRONG_STATE; + } + + hr = IMediaSample_GetPointer(sample, &pointer); + if (FAILED(hr)) + { + LeaveCriticalSection(&stream->cs); + return hr; + } + + event = calloc(1, sizeof(*event)); + if (!event) + { + LeaveCriticalSection(&stream->cs); + return E_OUTOFMEMORY; + } + + event->type = QET_SAMPLE; + event->length = IMediaSample_GetActualDataLength(sample); + event->pointer = pointer; + event->sample = sample; + IMediaSample_AddRef(event->sample); + list_add_tail(&stream->event_queue, &event->entry); + + LeaveCriticalSection(&stream->cs); + + return S_OK; }
static HRESULT WINAPI audio_meminput_ReceiveMultiple(IMemInputPin *iface, diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index 2ac492bc3c..2582d3c69d 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -2904,6 +2904,140 @@ void test_audiostream_end_of_stream(void) ok(!ref, "Got outstanding refcount %d.\n", ref); }
+static void test_audiostream_receive(void) +{ + static const WAVEFORMATEX format = + { + .wFormatTag = WAVE_FORMAT_PCM, + .nChannels = 1, + .nSamplesPerSec = 11025, + .wBitsPerSample = 16, + .nBlockAlign = 2, + .nAvgBytesPerSec = 2 * 11025, + }; + + const AM_MEDIA_TYPE mt = + { + .majortype = MEDIATYPE_Audio, + .subtype = MEDIASUBTYPE_PCM, + .formattype = FORMAT_WaveFormatEx, + .cbFormat = sizeof(WAVEFORMATEX), + .pbFormat = (BYTE *)&format, + }; + + ALLOCATOR_PROPERTIES properties = + { + .cBuffers = 3, + .cbBuffer = 16, + .cbAlign = 1, + }; + + IAMMultiMediaStream *mmstream = create_ammultimediastream(); + ALLOCATOR_PROPERTIES actual; + struct testfilter source; + IMemAllocator *allocator; + IGraphBuilder *graph; + IMediaStream *stream; + IMediaSample *sample1; + IMediaSample *sample2; + IMediaSample *sample3; + 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_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 = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER, &IID_IMemAllocator, (void **)&allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMemAllocator_SetProperties(allocator, &properties, &actual); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMemAllocator_Commit(allocator); + 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); + + hr = IMemAllocator_GetBuffer(allocator, &sample1, NULL, NULL, 0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMemInputPin_Receive(source.source.pMemInputPin, sample1); + ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr); + ref = IMediaSample_Release(sample1); + ok(!ref, "Got outstanding refcount %d.\n", ref); + + hr = IAMMultiMediaStream_SetState(mmstream, STREAMSTATE_RUN); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMemAllocator_GetBuffer(allocator, &sample1, NULL, NULL, 0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMemInputPin_Receive(source.source.pMemInputPin, sample1); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IMediaSample_AddRef(sample1); + ref = IMediaSample_Release(sample1); + ok(ref == 2, "Got outstanding refcount %d.\n", ref); + + hr = IMemAllocator_GetBuffer(allocator, &sample2, NULL, NULL, 0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMemInputPin_Receive(source.source.pMemInputPin, sample2); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IMediaSample_AddRef(sample2); + ref = IMediaSample_Release(sample2); + ok(ref == 2, "Got outstanding refcount %d.\n", ref); + + hr = IPin_EndOfStream(pin); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMemAllocator_GetBuffer(allocator, &sample3, NULL, NULL, 0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMemInputPin_Receive(source.source.pMemInputPin, sample3); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IMediaSample_AddRef(sample3); + ref = IMediaSample_Release(sample3); + ok(ref == 2, "Got outstanding refcount %d.\n", ref); + + hr = IAMMultiMediaStream_SetState(mmstream, STREAMSTATE_STOP); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + ref = IMediaSample_Release(sample1); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IMediaSample_Release(sample2); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IMediaSample_Release(sample3); + ok(!ref, "Got outstanding refcount %d.\n", ref); + + hr = IMemAllocator_GetBuffer(allocator, &sample1, NULL, NULL, 0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMemInputPin_Receive(source.source.pMemInputPin, sample1); + ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr); + ref = IMediaSample_Release(sample1); + ok(!ref, "Got outstanding refcount %d.\n", ref); + + IGraphBuilder_Disconnect(graph, pin); + IGraphBuilder_Disconnect(graph, &source.source.pin.IPin_iface); + + hr = IMemAllocator_Decommit(allocator); + 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 = IMemAllocator_Release(allocator); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + void test_mediastreamfilter_get_state(void) { IAMMultiMediaStream *mmstream = create_ammultimediastream(); @@ -3077,6 +3211,7 @@ START_TEST(amstream) test_audiostream_receive_connection(); test_audiostream_set_state(); test_audiostream_end_of_stream(); + test_audiostream_receive();
test_mediastreamfilter_get_state(); test_mediastreamfilter_stop_pause_run();