[PATCH 2/3] amstream: Implement IAudioStreamSample::GetSampleTimes.
Anton Baskanov
baskanov at gmail.com
Fri Jun 19 12:21:57 CDT 2020
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 at 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();
More information about the wine-devel
mailing list