Commit 28f17d8e authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

qcap/filewriter: Implement sample processing.

parent 439458af
......@@ -64,10 +64,36 @@ static HRESULT file_writer_sink_query_accept(struct strmbase_pin *iface, const A
return S_OK;
}
static HRESULT WINAPI file_writer_sink_receive(struct strmbase_sink *iface, IMediaSample *sample)
{
struct file_writer *filter = impl_from_strmbase_pin(&iface->pin);
REFERENCE_TIME start, stop;
LARGE_INTEGER offset;
HRESULT hr;
DWORD size;
BYTE *data;
if ((hr = IMediaSample_GetTime(sample, &start, &stop)) != S_OK)
ERR("Failed to get sample time, hr %#x.\n", hr);
if ((hr = IMediaSample_GetPointer(sample, &data)) != S_OK)
ERR("Failed to get sample pointer, hr %#x.\n", hr);
offset.QuadPart = start;
if (!SetFilePointerEx(filter->file, offset, NULL, FILE_BEGIN)
|| !WriteFile(filter->file, data, stop - start, &size, NULL))
ERR("Failed to write file, error %u.\n", GetLastError());
if (size != stop - start)
ERR("Short write, %u/%u.\n", size, (DWORD)(stop - start));
return S_OK;
}
static const struct strmbase_sink_ops sink_ops =
{
.base.pin_query_interface = file_writer_sink_query_interface,
.base.pin_query_accept = file_writer_sink_query_accept,
.pfnReceive = file_writer_sink_receive,
};
static inline struct file_writer *impl_from_strmbase_filter(struct strmbase_filter *iface)
......
......@@ -549,7 +549,7 @@ static void test_allocator(IMemInputPin *input, IMemAllocator *allocator)
ok(hr == E_POINTER, "Got hr %#x.\n", hr);
props.cBuffers = 1;
props.cbBuffer = 256;
props.cbBuffer = 512;
props.cbAlign = 512;
props.cbPrefix = 0;
hr = IMemAllocator_SetProperties(allocator, &props, &ret_props);
......@@ -616,6 +616,68 @@ static void test_filter_state(IMediaControl *control)
ok(state == State_Stopped, "Got state %u.\n", state);
}
static void test_sample_processing(IMediaControl *control, IMemInputPin *input,
IMemAllocator *allocator, const WCHAR *filename)
{
REFERENCE_TIME start, stop;
IMediaSample *sample;
BYTE buffer[600];
FILE *file;
HRESULT hr;
BYTE *data;
LONG size;
hr = IMemInputPin_ReceiveCanBlock(input);
ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IMediaControl_Pause(control);
ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
ok(hr == VFW_E_NOT_COMMITTED, "Got hr %#x.\n", hr);
hr = IMemAllocator_Commit(allocator);
ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IMediaSample_GetPointer(sample, &data);
ok(hr == S_OK, "Got hr %#x.\n", hr);
size = IMediaSample_GetSize(sample);
ok(size == 512, "Got size %d.\n", size);
memset(data, 0xcc, size);
start = 0;
stop = 512;
hr = IMediaSample_SetTime(sample, &start, &stop);
ok(hr == S_OK, "Got hr %#x.\n", hr);
strcpy((char *)data, "abcdefghi");
hr = IMediaSample_SetActualDataLength(sample, 9);
ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IMemInputPin_Receive(input, sample);
ok(hr == S_OK, "Got hr %#x.\n", hr);
memset(data, 0xcc, size);
strcpy((char *)data, "123456");
hr = IMediaSample_SetActualDataLength(sample, 6);
ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IMemInputPin_Receive(input, sample);
ok(hr == S_OK, "Got hr %#x.\n", hr);
file = _wfopen(filename, L"rb");
ok(!!file, "Failed to open file: %s.\n", strerror(errno));
size = fread(buffer, 1, sizeof(buffer), file);
ok(size == 512, "Got size %d.\n", size);
ok(!memcmp(buffer, "123456\0\xcc\xcc\xcc", 10), "Got data %s.\n",
debugstr_an((char *)buffer, size));
fclose(file);
hr = IMediaControl_Stop(control);
ok(hr == S_OK, "Got hr %#x.\n", hr);
IMediaSample_Release(sample);
}
static void test_connect_pin(void)
{
AM_MEDIA_TYPE req_mt =
......@@ -675,6 +737,7 @@ static void test_connect_pin(void)
test_allocator(meminput, allocator);
test_filter_state(control);
test_sample_processing(control, meminput, allocator, filename);
hr = IFilterGraph2_Disconnect(graph, pin);
ok(hr == S_OK, "Got hr %#x.\n", hr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment