Signed-off-by: Anton Baskanov baskanov@gmail.com --- dlls/amstream/audiostream.c | 33 +++++- dlls/amstream/tests/amstream.c | 181 +++++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+), 2 deletions(-)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index 8fba877719..4c6c326d84 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -34,6 +34,7 @@ struct queued_receive DWORD length; BYTE *pointer; DWORD position; + STREAM_TIME start_time; };
struct audio_stream @@ -66,6 +67,8 @@ typedef struct { LONG ref; struct audio_stream *parent; IAudioData *audio_data; + STREAM_TIME start_time; + STREAM_TIME end_time; HANDLE update_event;
struct list entry; @@ -102,6 +105,12 @@ static void flush_receive_queue(struct audio_stream *stream) remove_queued_receive(LIST_ENTRY(entry, struct queued_receive, entry)); }
+static STREAM_TIME stream_time_from_position(struct audio_stream *stream, struct queued_receive *receive) +{ + const WAVEFORMATEX *format = (WAVEFORMATEX *)stream->mt.pbFormat; + return receive->start_time + (receive->position * 10000000 + format->nAvgBytesPerSec / 2) / format->nAvgBytesPerSec; +} + static void process_update(IAudioStreamSampleImpl *sample, struct queued_receive *receive) { DWORD advance; @@ -109,9 +118,14 @@ static void process_update(IAudioStreamSampleImpl *sample, struct queued_receive advance = min(receive->length - receive->position, sample->length - sample->position); memcpy(&sample->pointer[sample->position], &receive->pointer[receive->position], advance);
+ if (!sample->position) + sample->start_time = stream_time_from_position(sample->parent, receive); + receive->position += advance; sample->position += advance;
+ sample->end_time = stream_time_from_position(sample->parent, receive); + sample->update_hr = (sample->position == sample->length) ? S_OK : MS_S_PENDING; }
@@ -204,9 +218,19 @@ static HRESULT WINAPI IAudioStreamSampleImpl_GetMediaStream(IAudioStreamSample * static HRESULT WINAPI IAudioStreamSampleImpl_GetSampleTimes(IAudioStreamSample *iface, STREAM_TIME *start_time, STREAM_TIME *end_time, STREAM_TIME *current_time) { - FIXME("(%p)->(%p,%p,%p): stub\n", iface, start_time, end_time, current_time); + IAudioStreamSampleImpl *sample = impl_from_IAudioStreamSample(iface);
- return E_NOTIMPL; + TRACE("sample %p, start_time %p, end_time %p, current_time %p.\n", sample, start_time, end_time, current_time); + + if (current_time) + IMediaStreamFilter_GetCurrentStreamTime(sample->parent->filter, current_time); + + if (start_time) + *start_time = sample->start_time; + if (end_time) + *end_time = sample->end_time; + + return S_OK; }
static HRESULT WINAPI IAudioStreamSampleImpl_SetSampleTimes(IAudioStreamSample *iface, const STREAM_TIME *start_time, @@ -1228,6 +1252,8 @@ static HRESULT WINAPI audio_meminput_Receive(IMemInputPin *iface, IMediaSample * { struct audio_stream *stream = impl_from_IMemInputPin(iface); struct queued_receive *receive; + REFERENCE_TIME start_time = 0; + REFERENCE_TIME end_time = 0; BYTE *pointer; HRESULT hr;
@@ -1253,6 +1279,8 @@ static HRESULT WINAPI audio_meminput_Receive(IMemInputPin *iface, IMediaSample * return hr; }
+ IMediaSample_GetTime(sample, &start_time, &end_time); + receive = calloc(1, sizeof(*receive)); if (!receive) { @@ -1263,6 +1291,7 @@ 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; 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 e1f6a15ad3..d12441fc2e 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -3851,6 +3851,186 @@ void test_audiostreamsample_completion_status(void) CloseHandle(event); }
+static void test_audiostreamsample_get_sample_times(void) +{ + IAMMultiMediaStream *mmstream = create_ammultimediastream(); + static const BYTE test_data[8] = { 0 }; + IAudioStreamSample *stream_sample; + IMediaFilter *graph_media_filter; + IAudioMediaStream *audio_stream; + STREAM_TIME filter_start_time; + IMemInputPin *mem_input_pin; + IMediaStreamFilter *filter; + IMediaSample *media_sample; + struct testfilter source; + STREAM_TIME current_time; + struct testclock clock; + 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_GetFilter(mmstream, &filter); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!!filter, "Expected non-null filter.\n"); + 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"); + hr = IGraphBuilder_QueryInterface(graph, &IID_IMediaFilter, (void **)&graph_media_filter); + ok(hr == S_OK, "Got hr %#x.\n", hr); + 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); + testclock_init(&clock); + + clock.time = 12345678; + + current_time = 0xdeadbeefdeadbeef; + hr = IAudioStreamSample_GetSampleTimes(stream_sample, NULL, NULL, ¤t_time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(current_time == 0, "Got current time %s.\n", wine_dbgstr_longlong(current_time)); + + IMediaFilter_SetSyncSource(graph_media_filter, &clock.IReferenceClock_iface); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + current_time = 0xdeadbeefdeadbeef; + hr = IAudioStreamSample_GetSampleTimes(stream_sample, NULL, NULL, ¤t_time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(current_time == 0, "Got current time %s.\n", wine_dbgstr_longlong(current_time)); + + 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 = IMediaStreamFilter_GetCurrentStreamTime(filter, &filter_start_time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + clock.get_time_hr = E_FAIL; + + current_time = 0xdeadbeefdeadbeef; + hr = IAudioStreamSample_GetSampleTimes(stream_sample, NULL, NULL, ¤t_time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(current_time == 0xdeadbeefddf15da1 + filter_start_time, "Expected current time %s, got %s.\n", + wine_dbgstr_longlong(0xdeadbeefddf15da1 + filter_start_time), wine_dbgstr_longlong(current_time)); + + clock.get_time_hr = S_OK; + + current_time = 0xdeadbeefdeadbeef; + hr = IAudioStreamSample_GetSampleTimes(stream_sample, NULL, NULL, ¤t_time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(current_time == filter_start_time, "Expected current time %s, got %s.\n", + wine_dbgstr_longlong(filter_start_time), wine_dbgstr_longlong(current_time)); + + clock.time = 23456789; + + current_time = 0xdeadbeefdeadbeef; + hr = IAudioStreamSample_GetSampleTimes(stream_sample, NULL, NULL, ¤t_time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(current_time == filter_start_time + 11111111, "Expected current time %s, got %s.\n", + wine_dbgstr_longlong(filter_start_time + 11111111), wine_dbgstr_longlong(current_time)); + + 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 == 0, "Got start time %s.\n", wine_dbgstr_longlong(start_time)); + ok(end_time == 0, "Got end time %s.\n", wine_dbgstr_longlong(end_time)); + + media_sample = audiostream_allocate_sample(&source, test_data, 8); + 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 == 12345678, "Got start time %s.\n", wine_dbgstr_longlong(start_time)); + ok(end_time == 12347946, "Got end time %s.\n", wine_dbgstr_longlong(end_time)); + + media_sample = audiostream_allocate_sample(&source, test_data, 6); + 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 == 12347946, "Got start time %s.\n", wine_dbgstr_longlong(start_time)); + ok(end_time == 12346585, "Got end time %s.\n", wine_dbgstr_longlong(end_time)); + + hr = IPin_EndOfStream(pin); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + 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 == 12346585, "Got start time %s.\n", wine_dbgstr_longlong(start_time)); + ok(end_time == 12348399, "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); + IMediaFilter_Release(graph_media_filter); + ref = IGraphBuilder_Release(graph); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IMediaStreamFilter_Release(filter); + 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 test_ddrawstream_initialize(void) { IDirectDrawMediaStream *ddraw_stream; @@ -4510,6 +4690,7 @@ START_TEST(amstream)
test_audiostreamsample_update(); test_audiostreamsample_completion_status(); + test_audiostreamsample_get_sample_times();
test_ddrawstream_initialize();
Signed-off-by: Anton Baskanov baskanov@gmail.com --- dlls/amstream/audiostream.c | 18 +++-- dlls/amstream/tests/amstream.c | 119 +++++++++++++++++++++++++++++++-- 2 files changed, 129 insertions(+), 8 deletions(-)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index 4c6c326d84..a19cb4ea96 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -56,6 +56,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; @@ -1158,9 +1159,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 = @@ -1291,7 +1301,7 @@ 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->start_time = start_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();
Signed-off-by: Zebediah Figura <z.figura12@gmail.com
Signed-off-by: Zebediah Figura z.figura12@gmail.com