Skip to content

Commit 9cabd71

Browse files
Paul Gofmanivyl
authored andcommitted
mfplat/sample: Optimize copying to 2d buffer.
CW-Bug-Id: #22084
1 parent 7495381 commit 9cabd71

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

dlls/mfplat/sample.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,9 @@ static HRESULT WINAPI sample_CopyToBuffer(IMFSample *iface, IMFMediaBuffer *buff
852852
struct sample *sample = impl_from_IMFSample(iface);
853853
DWORD total_length, dst_length, dst_current_length, src_max_length, current_length;
854854
BYTE *src_ptr, *dst_ptr;
855-
BOOL locked;
856-
HRESULT hr;
855+
IMF2DBuffer *buffer2d;
856+
BOOL locked = FALSE;
857+
HRESULT hr = E_FAIL;
857858
size_t i;
858859

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

876+
if (sample->buffer_count == 1
877+
&& SUCCEEDED(IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer, (void **)&buffer2d)))
878+
{
879+
if (SUCCEEDED(IMFMediaBuffer_GetCurrentLength(sample->buffers[0], &current_length))
880+
&& SUCCEEDED(IMF2DBuffer_GetContiguousLength(buffer2d, &dst_length))
881+
&& current_length == dst_length
882+
&& SUCCEEDED(IMFMediaBuffer_Lock(sample->buffers[0], &src_ptr, &src_max_length, &current_length)))
883+
{
884+
hr = IMF2DBuffer_ContiguousCopyFrom(buffer2d, src_ptr, current_length);
885+
IMFMediaBuffer_Unlock(sample->buffers[0]);
886+
}
887+
IMF2DBuffer_Release(buffer2d);
888+
if (SUCCEEDED(hr))
889+
{
890+
dst_current_length = current_length;
891+
goto done;
892+
}
893+
}
894+
875895
dst_ptr = NULL;
876896
dst_length = current_length = 0;
877897
locked = SUCCEEDED(hr = IMFMediaBuffer_Lock(buffer, &dst_ptr, &dst_length, &current_length));

0 commit comments

Comments
 (0)