Skip to content

Commit

Permalink
mfplat/sample: Optimize copying to 2d buffer.
Browse files Browse the repository at this point in the history
CW-Bug-Id: #22084
  • Loading branch information
Paul Gofman authored and ivyl committed Sep 7, 2023
1 parent 7495381 commit 9cabd71
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions dlls/mfplat/sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,9 @@ static HRESULT WINAPI sample_CopyToBuffer(IMFSample *iface, IMFMediaBuffer *buff
struct sample *sample = impl_from_IMFSample(iface);
DWORD total_length, dst_length, dst_current_length, src_max_length, current_length;
BYTE *src_ptr, *dst_ptr;
BOOL locked;
HRESULT hr;
IMF2DBuffer *buffer2d;
BOOL locked = FALSE;
HRESULT hr = E_FAIL;
size_t i;

TRACE("%p, %p.\n", iface, buffer);
Expand All @@ -872,6 +873,25 @@ static HRESULT WINAPI sample_CopyToBuffer(IMFSample *iface, IMFMediaBuffer *buff
total_length = sample_get_total_length(sample);
dst_current_length = 0;

if (sample->buffer_count == 1
&& SUCCEEDED(IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer, (void **)&buffer2d)))
{
if (SUCCEEDED(IMFMediaBuffer_GetCurrentLength(sample->buffers[0], &current_length))
&& SUCCEEDED(IMF2DBuffer_GetContiguousLength(buffer2d, &dst_length))
&& current_length == dst_length
&& SUCCEEDED(IMFMediaBuffer_Lock(sample->buffers[0], &src_ptr, &src_max_length, &current_length)))
{
hr = IMF2DBuffer_ContiguousCopyFrom(buffer2d, src_ptr, current_length);
IMFMediaBuffer_Unlock(sample->buffers[0]);
}
IMF2DBuffer_Release(buffer2d);
if (SUCCEEDED(hr))
{
dst_current_length = current_length;
goto done;
}
}

dst_ptr = NULL;
dst_length = current_length = 0;
locked = SUCCEEDED(hr = IMFMediaBuffer_Lock(buffer, &dst_ptr, &dst_length, &current_length));
Expand Down

0 comments on commit 9cabd71

Please sign in to comment.