Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mfplat/buffer.c | 24 +++++++++++++++++-- dlls/mfplat/tests/mfplat.c | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/dlls/mfplat/buffer.c b/dlls/mfplat/buffer.c index 524398aeac..27ae44a91c 100644 --- a/dlls/mfplat/buffer.c +++ b/dlls/mfplat/buffer.c @@ -686,9 +686,29 @@ static HRESULT WINAPI sample_GetBufferByIndex(IMFSample *iface, DWORD index, IMF
static HRESULT WINAPI sample_ConvertToContiguousBuffer(IMFSample *iface, IMFMediaBuffer **buffer) { - FIXME("%p, %p.\n", iface, buffer); + struct sample *sample = impl_from_IMFSample(iface); + HRESULT hr = S_OK;
- return E_NOTIMPL; + TRACE("%p, %p.\n", iface, buffer); + + EnterCriticalSection(&sample->cs); + + if (sample->buffer_count == 0) + hr = E_UNEXPECTED; + else if (sample->buffer_count == 1) + { + *buffer = sample->buffers[0]; + IMFMediaBuffer_AddRef(*buffer); + } + else + { + FIXME("Samples with multiple buffers are not supported.\n"); + hr = E_NOTIMPL; + } + + LeaveCriticalSection(&sample->cs); + + return hr; }
static HRESULT WINAPI sample_AddBuffer(IMFSample *iface, IMFMediaBuffer *buffer) diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index 571d57a220..541b236731 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -1475,6 +1475,53 @@ static void test_sample(void)
IMFAttributes_Release(attributes); IMFSample_Release(sample); + + /* ConvertToContiguousBuffer() */ + hr = MFCreateSample(&sample); + ok(hr == S_OK, "Failed to create a sample, hr %#x.\n", hr); + + hr = IMFSample_ConvertToContiguousBuffer(sample, &buffer); + ok(hr == E_UNEXPECTED, "Unexpected hr %#x.\n", hr); + + hr = MFCreateMemoryBuffer(16, &buffer); + ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr); + + hr = IMFSample_AddBuffer(sample, buffer); + ok(hr == S_OK, "Failed to add buffer, hr %#x.\n", hr); + + hr = IMFSample_ConvertToContiguousBuffer(sample, &buffer2); + ok(hr == S_OK, "Failed to convert, hr %#x.\n", hr); + ok(buffer2 == buffer, "Unexpected buffer instance.\n"); + IMFMediaBuffer_Release(buffer2); + + hr = IMFSample_ConvertToContiguousBuffer(sample, &buffer2); + ok(hr == S_OK, "Failed to convert, hr %#x.\n", hr); + ok(buffer2 == buffer, "Unexpected buffer instance.\n"); + IMFMediaBuffer_Release(buffer2); + + hr = MFCreateMemoryBuffer(16, &buffer2); + ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr); + + hr = IMFSample_AddBuffer(sample, buffer2); + ok(hr == S_OK, "Failed to add buffer, hr %#x.\n", hr); + IMFMediaBuffer_Release(buffer2); + + hr = IMFSample_GetBufferCount(sample, &count); + ok(hr == S_OK, "Failed to get buffer count, hr %#x.\n", hr); + ok(count == 2, "Unexpected buffer count %u.\n", count); + + hr = IMFSample_ConvertToContiguousBuffer(sample, &buffer2); +todo_wine + ok(hr == S_OK, "Failed to convert, hr %#x.\n", hr); + if (SUCCEEDED(hr)) + IMFMediaBuffer_Release(buffer2); + + hr = IMFSample_GetBufferCount(sample, &count); + ok(hr == S_OK, "Failed to get buffer count, hr %#x.\n", hr); +todo_wine + ok(count == 1, "Unexpected buffer count %u.\n", count); + + IMFSample_Release(sample); }
struct test_callback