amstream: Implement AMAudioStream::NewSegment.

Signed-off-by: Anton Baskanov <baskanov@gmail.com>
Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Anton Baskanov 2020-06-20 00:18:52 +07:00 committed by Alexandre Julliard
parent 0736217336
commit b9712f2f37
2 changed files with 129 additions and 8 deletions

View File

@ -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);

View File

@ -3440,10 +3440,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;
@ -3464,6 +3460,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;
@ -4699,6 +4809,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();