Signed-off-by: Anton Baskanov baskanov@gmail.com --- dlls/amstream/filter.c | 28 ++++++- dlls/amstream/tests/amstream.c | 137 +++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 3 deletions(-)
diff --git a/dlls/amstream/filter.c b/dlls/amstream/filter.c index 05a02e3f66..3dff686b21 100644 --- a/dlls/amstream/filter.c +++ b/dlls/amstream/filter.c @@ -174,6 +174,7 @@ struct filter IAMMediaStream **streams; IAMMediaStream *seekable_stream; FILTER_STATE state; + REFERENCE_TIME start_time; };
static inline struct filter *impl_from_IMediaStreamFilter(IMediaStreamFilter *iface) @@ -295,6 +296,7 @@ static HRESULT WINAPI filter_Run(IMediaStreamFilter *iface, REFERENCE_TIME start
EnterCriticalSection(&filter->cs);
+ filter->start_time = start; set_state(filter, State_Running);
LeaveCriticalSection(&filter->cs); @@ -614,11 +616,31 @@ static HRESULT WINAPI filter_ReferenceTimeToStreamTime(IMediaStreamFilter *iface return E_NOTIMPL; }
-static HRESULT WINAPI filter_GetCurrentStreamTime(IMediaStreamFilter *iface, REFERENCE_TIME *pCurrentStreamTime) +static HRESULT WINAPI filter_GetCurrentStreamTime(IMediaStreamFilter *iface, REFERENCE_TIME *time) { - FIXME("(%p)->(%p): Stub!\n", iface, pCurrentStreamTime); + struct filter *filter = impl_from_IMediaStreamFilter(iface);
- return E_NOTIMPL; + TRACE("filter %p, time %p.\n", filter, time); + + if (!time) + return E_POINTER; + + EnterCriticalSection(&filter->cs); + + if (filter->state != State_Running || !filter->clock) + { + *time = 0; + LeaveCriticalSection(&filter->cs); + return S_FALSE; + } + + IReferenceClock_GetTime(filter->clock, time); + + *time -= filter->start_time; + + LeaveCriticalSection(&filter->cs); + + return S_OK; }
static HRESULT WINAPI filter_WaitUntil(IMediaStreamFilter *iface, REFERENCE_TIME WaitStreamTime) diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index 2bc1310a96..e1f6a15ad3 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -2641,6 +2641,87 @@ static const IMediaSeekingVtbl testsource_seeking_vtbl = testsource_seeking_GetPreroll, };
+struct testclock +{ + IReferenceClock IReferenceClock_iface; + LONG refcount; + LONGLONG time; + HRESULT get_time_hr; +}; + +static inline struct testclock *impl_from_IReferenceClock(IReferenceClock *iface) +{ + return CONTAINING_RECORD(iface, struct testclock, IReferenceClock_iface); +} + +static HRESULT WINAPI testclock_QueryInterface(IReferenceClock *iface, REFIID iid, void **out) +{ + if (winetest_debug > 1) trace("QueryInterface(%s)\n", wine_dbgstr_guid(iid)); + if (IsEqualGUID(iid, &IID_IReferenceClock) + || IsEqualGUID(iid, &IID_IUnknown)) + { + *out = iface; + IReferenceClock_AddRef(iface); + return S_OK; + } + return E_NOINTERFACE; +} + +static ULONG WINAPI testclock_AddRef(IReferenceClock *iface) +{ + struct testclock *clock = impl_from_IReferenceClock(iface); + return InterlockedIncrement(&clock->refcount); +} + +static ULONG WINAPI testclock_Release(IReferenceClock *iface) +{ + struct testclock *clock = impl_from_IReferenceClock(iface); + return InterlockedDecrement(&clock->refcount); +} + +static HRESULT WINAPI testclock_GetTime(IReferenceClock *iface, REFERENCE_TIME *time) +{ + struct testclock *clock = impl_from_IReferenceClock(iface); + if (SUCCEEDED(clock->get_time_hr)) + *time = clock->time; + return clock->get_time_hr; +} + +static HRESULT WINAPI testclock_AdviseTime(IReferenceClock *iface, REFERENCE_TIME base, REFERENCE_TIME offset, HEVENT event, DWORD_PTR *cookie) +{ + ok(0, "Unexpected call.\n"); + return E_NOTIMPL; +} + +static HRESULT WINAPI testclock_AdvisePeriodic(IReferenceClock *iface, REFERENCE_TIME start, REFERENCE_TIME period, HSEMAPHORE semaphore, DWORD_PTR *cookie) +{ + ok(0, "Unexpected call.\n"); + return E_NOTIMPL; +} + +static HRESULT WINAPI testclock_Unadvise(IReferenceClock *iface, DWORD_PTR cookie) +{ + ok(0, "Unexpected call.\n"); + return E_NOTIMPL; +} + +static IReferenceClockVtbl testclock_vtbl = +{ + testclock_QueryInterface, + testclock_AddRef, + testclock_Release, + testclock_GetTime, + testclock_AdviseTime, + testclock_AdvisePeriodic, + testclock_Unadvise, +}; + +static void testclock_init(struct testclock *clock) +{ + memset(clock, 0, sizeof(*clock)); + clock->IReferenceClock_iface.lpVtbl = &testclock_vtbl; +} + static void test_audiostream_get_format(void) { static const WAVEFORMATEX pin_format = @@ -4330,6 +4411,61 @@ static void test_mediastreamfilter_set_positions(void) ok(!ref, "Got outstanding refcount %d.\n", ref); }
+static void test_mediastreamfilter_get_current_stream_time(void) +{ + IMediaStreamFilter *filter; + struct testclock clock; + REFERENCE_TIME time; + HRESULT hr; + ULONG ref; + + hr = CoCreateInstance(&CLSID_MediaStreamFilter, NULL, CLSCTX_INPROC_SERVER, + &IID_IMediaStreamFilter, (void **)&filter); + ok(hr == S_OK, "Got hr %#x.\n", hr); + testclock_init(&clock); + + /* Crashes on native. */ + if (0) + { + hr = IMediaStreamFilter_GetCurrentStreamTime(filter, NULL); + ok(hr == E_POINTER, "Got hr %#x.\n", hr); + } + + time = 0xdeadbeefdeadbeef; + hr = IMediaStreamFilter_GetCurrentStreamTime(filter, &time); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + ok(time == 0, "Got time %s.\n", wine_dbgstr_longlong(time)); + + hr = IMediaStreamFilter_SetSyncSource(filter, &clock.IReferenceClock_iface); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + clock.get_time_hr = E_FAIL; + + time = 0xdeadbeefdeadbeef; + hr = IMediaStreamFilter_GetCurrentStreamTime(filter, &time); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + ok(time == 0, "Got time %s.\n", wine_dbgstr_longlong(time)); + + hr = IMediaStreamFilter_Run(filter, 23456789); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + time = 0xdeadbeefdeadbeef; + hr = IMediaStreamFilter_GetCurrentStreamTime(filter, &time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(time == 0xdeadbeefdd47d2da, "Got time %s.\n", wine_dbgstr_longlong(time)); + + clock.time = 34567890; + clock.get_time_hr = S_OK; + + time = 0xdeadbeefdeadbeef; + hr = IMediaStreamFilter_GetCurrentStreamTime(filter, &time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(time == 11111101, "Got time %s.\n", wine_dbgstr_longlong(time)); + + ref = IMediaStreamFilter_Release(filter); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + START_TEST(amstream) { HANDLE file; @@ -4383,6 +4519,7 @@ START_TEST(amstream) test_mediastreamfilter_stop_pause_run(); test_mediastreamfilter_support_seeking(); test_mediastreamfilter_set_positions(); + test_mediastreamfilter_get_current_stream_time();
CoUninitialize(); }
Signed-off-by: Anton Baskanov baskanov@gmail.com --- dlls/amstream/audiostream.c | 35 ++++++- dlls/amstream/tests/amstream.c | 181 +++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+), 2 deletions(-)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index 8fba877719..a985cfd50e 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -34,6 +34,8 @@ struct queued_receive DWORD length; BYTE *pointer; DWORD position; + STREAM_TIME start_time; + STREAM_TIME end_time; };
struct audio_stream @@ -66,6 +68,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 +106,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 +119,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 +219,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 +1253,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 +1280,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 +1292,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; 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();
On 6/17/20 1:18 PM, Anton Baskanov wrote:
Signed-off-by: Anton Baskanov baskanov@gmail.com
dlls/amstream/audiostream.c | 35 ++++++- dlls/amstream/tests/amstream.c | 181 +++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+), 2 deletions(-)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index 8fba877719..a985cfd50e 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -34,6 +34,8 @@ struct queued_receive DWORD length; BYTE *pointer; DWORD position;
- STREAM_TIME start_time;
- STREAM_TIME end_time;
};
struct audio_stream @@ -66,6 +68,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 +106,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 +119,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 +219,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 +1253,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 +1280,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 +1292,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;
You don't seem to be using "receive->end_time" anywhere. I'd leave it out of this patch in that case, even if you're going to use it later.
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();
On Friday, 19 June 2020 00:13:29 +07 you wrote:
On 6/17/20 1:18 PM, Anton Baskanov wrote:
Signed-off-by: Anton Baskanov baskanov@gmail.com
dlls/amstream/audiostream.c | 35 ++++++- dlls/amstream/tests/amstream.c | 181 +++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+), 2 deletions(-)
diff --git a/dlls/amstream/audiostream.c b/dlls/amstream/audiostream.c index 8fba877719..a985cfd50e 100644 --- a/dlls/amstream/audiostream.c +++ b/dlls/amstream/audiostream.c @@ -34,6 +34,8 @@ struct queued_receive
DWORD length; BYTE *pointer; DWORD position;
- STREAM_TIME start_time;
- STREAM_TIME end_time;
};
struct audio_stream
@@ -66,6 +68,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 +106,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 +119,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 +219,19 @@ static HRESULT WINAPI IAudioStreamSampleImpl_GetMediaStream(IAudioStreamSample *> static HRESULT WINAPI IAudioStreamSampleImpl_GetSampleTimes(IAudioStreamSample *iface, STREAM_TIME *start_time,> STREAM_T IME *end_ti me, STREAM_ TIME *curren t_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 +1253,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 +1280,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 +1292,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;
You don't seem to be using "receive->end_time" anywhere. I'd leave it out of this patch in that case, even if you're going to use it later.
Thanks for spotting! This was a leftover from an earlier version.
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 | 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();