From: Anton Baskanov Subject: [PATCH 3/3] amstream: Implement AMAudioStream::NewSegment. Message-Id: <20200617181831.22202-3-baskanov@gmail.com> Date: Thu, 18 Jun 2020 01:18:31 +0700 In-Reply-To: <20200617181831.22202-1-baskanov@gmail.com> References: <20200617181831.22202-1-baskanov@gmail.com> Signed-off-by: Anton Baskanov --- dlls/amstream/audiostream.c | 20 ++++-- dlls/amstream/tests/amstream.c | 119 +++++++++++++++++++++++++++++++-- 2 files changed, 130 insertions(+), 9 deletions(-) diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index a985cfd50e..3c74f6bb64 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -57,6 +57,7 @@ struct audio_stream AM_MEDIA_TYPE mt; WAVEFORMATEX format; FILTER_STATE state; + REFERENCE_TIME segment_start; BOOL eos; BOOL flushing; struct list receive_queue; @@ -1159,9 +1160,18 @@ static HRESULT WINAPI audio_sink_EndFlush(IPin *iface) static HRESULT WINAPI audio_sink_NewSegment(IPin *iface, REFERENCE_TIME start, REFERENCE_TIME stop, double rate) { - FIXME("iface %p, start %s, stop %s, rate %0.16e, stub!\n", - iface, wine_dbgstr_longlong(start), wine_dbgstr_longlong(stop), rate); - return E_NOTIMPL; + struct audio_stream *stream = impl_from_IPin(iface); + + TRACE("stream %p, start %s, stop %s, rate %0.16e\n", + stream, wine_dbgstr_longlong(start), wine_dbgstr_longlong(stop), rate); + + EnterCriticalSection(&stream->cs); + + stream->segment_start = start; + + LeaveCriticalSection(&stream->cs); + + return S_OK; } static const IPinVtbl audio_sink_vtbl = @@ -1292,8 +1302,8 @@ static HRESULT WINAPI audio_meminput_Receive(IMemInputPin *iface, IMediaSample * receive->length = IMediaSample_GetActualDataLength(sample); receive->pointer = pointer; receive->sample = sample; - receive->start_time = start_time; - receive->end_time = end_time; + receive->start_time = start_time + stream->segment_start; + receive->end_time = end_time + stream->segment_start; IMediaSample_AddRef(receive->sample); list_add_tail(&stream->receive_queue, &receive->entry); diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index d12441fc2e..88f34811c8 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -3428,10 +3428,6 @@ static void test_audiostream_begin_flush_end_flush(void) ok(!ref, "Got outstanding refcount %d.\n", ref); } -static void CALLBACK apc_func(ULONG_PTR param) -{ -} - static IMediaSample *audiostream_allocate_sample(struct testfilter *source, const BYTE *input_data, DWORD input_length) { IMediaSample *sample; @@ -3452,6 +3448,120 @@ static IMediaSample *audiostream_allocate_sample(struct testfilter *source, cons return sample; } +static void test_audiostream_new_segment(void) +{ + IAMMultiMediaStream *mmstream = create_ammultimediastream(); + static const BYTE test_data[8] = { 0 }; + IAudioStreamSample *stream_sample; + IAudioMediaStream *audio_stream; + IMemInputPin *mem_input_pin; + IMediaSample *media_sample; + struct testfilter source; + IAudioData *audio_data; + STREAM_TIME start_time; + STREAM_TIME end_time; + IGraphBuilder *graph; + IMediaStream *stream; + 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 = IMediaStream_QueryInterface(stream, &IID_IMemInputPin, (void **)&mem_input_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_AMAudioData, NULL, CLSCTX_INPROC_SERVER, &IID_IAudioData, (void **)&audio_data); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IAudioMediaStream_CreateSample(audio_stream, audio_data, 0, &stream_sample); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IAudioData_SetBuffer(audio_data, 5, NULL, 0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IGraphBuilder_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &audio_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IAMMultiMediaStream_SetState(mmstream, STREAMSTATE_RUN); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IPin_NewSegment(pin, 11111111, 22222222, 1.0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + media_sample = audiostream_allocate_sample(&source, test_data, 5); + start_time = 12345678; + end_time = 23456789; + hr = IMediaSample_SetTime(media_sample, &start_time, &end_time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMemInputPin_Receive(mem_input_pin, media_sample); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IMediaSample_Release(media_sample); + + hr = IAudioStreamSample_Update(stream_sample, 0, NULL, NULL, 0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + start_time = 0xdeadbeefdeadbeef; + end_time = 0xdeadbeefdeadbeef; + hr = IAudioStreamSample_GetSampleTimes(stream_sample, &start_time, &end_time, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(start_time == 23456789, "Got start time %s.\n", wine_dbgstr_longlong(start_time)); + ok(end_time == 23459057, "Got end time %s.\n", wine_dbgstr_longlong(end_time)); + + hr = IPin_NewSegment(pin, 11111111, 22222222, 2.0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + media_sample = audiostream_allocate_sample(&source, test_data, 5); + start_time = 12345678; + end_time = 23456789; + hr = IMediaSample_SetTime(media_sample, &start_time, &end_time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMemInputPin_Receive(mem_input_pin, media_sample); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IMediaSample_Release(media_sample); + + hr = IAudioStreamSample_Update(stream_sample, 0, NULL, NULL, 0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + start_time = 0xdeadbeefdeadbeef; + end_time = 0xdeadbeefdeadbeef; + hr = IAudioStreamSample_GetSampleTimes(stream_sample, &start_time, &end_time, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(start_time == 23456789, "Got start time %s.\n", wine_dbgstr_longlong(start_time)); + ok(end_time == 23459057, "Got end time %s.\n", wine_dbgstr_longlong(end_time)); + + hr = IAMMultiMediaStream_SetState(mmstream, STREAMSTATE_STOP); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IGraphBuilder_Disconnect(graph, pin); + IGraphBuilder_Disconnect(graph, &source.source.pin.IPin_iface); + + ref = IAudioStreamSample_Release(stream_sample); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IAudioData_Release(audio_data); + ok(!ref, "Got outstanding refcount %d.\n", ref); + 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); + IMemInputPin_Release(mem_input_pin); + IAudioMediaStream_Release(audio_stream); + ref = IMediaStream_Release(stream); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + +static void CALLBACK apc_func(ULONG_PTR param) +{ +} + static IPin *audiostream_pin; static IMemInputPin *audiostream_mem_input_pin; static IMediaSample *audiostream_media_sample; @@ -4687,6 +4797,7 @@ START_TEST(amstream) test_audiostream_receive(); test_audiostream_initialize(); test_audiostream_begin_flush_end_flush(); + test_audiostream_new_segment(); test_audiostreamsample_update(); test_audiostreamsample_completion_status(); -- 2.17.1