Commit 0066be78 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

evr/allocator: Fix reference counting for returned samples.

parent 2ef767dc
...@@ -459,7 +459,6 @@ static void sample_allocator_release_samples(struct sample_allocator *allocator) ...@@ -459,7 +459,6 @@ static void sample_allocator_release_samples(struct sample_allocator *allocator)
LIST_FOR_EACH_ENTRY_SAFE(iter, iter2, &allocator->used_samples, struct queued_sample, entry) LIST_FOR_EACH_ENTRY_SAFE(iter, iter2, &allocator->used_samples, struct queued_sample, entry)
{ {
list_remove(&iter->entry); list_remove(&iter->entry);
IMFSample_Release(iter->sample);
heap_free(iter); heap_free(iter);
} }
} }
...@@ -676,8 +675,10 @@ static HRESULT WINAPI sample_allocator_AllocateSample(IMFVideoSampleAllocator *i ...@@ -676,8 +675,10 @@ static HRESULT WINAPI sample_allocator_AllocateSample(IMFVideoSampleAllocator *i
list_add_tail(&allocator->used_samples, head); list_add_tail(&allocator->used_samples, head);
allocator->free_sample_count--; allocator->free_sample_count--;
/* Reference counter is not increased when sample is returned, so next release could trigger
tracking condition. This is balanced by incremented reference counter when sample is returned
back to the free list. */
*out = sample; *out = sample;
IMFSample_AddRef(*out);
} }
} }
...@@ -816,6 +817,7 @@ static HRESULT WINAPI sample_allocator_tracking_callback_Invoke(IMFAsyncCallback ...@@ -816,6 +817,7 @@ static HRESULT WINAPI sample_allocator_tracking_callback_Invoke(IMFAsyncCallback
{ {
list_remove(&iter->entry); list_remove(&iter->entry);
list_add_tail(&allocator->free_samples, &iter->entry); list_add_tail(&allocator->free_samples, &iter->entry);
IMFSample_AddRef(iter->sample);
allocator->free_sample_count++; allocator->free_sample_count++;
break; break;
} }
......
...@@ -1326,13 +1326,13 @@ static void test_MFCreateVideoSampleAllocator(void) ...@@ -1326,13 +1326,13 @@ static void test_MFCreateVideoSampleAllocator(void)
IDirect3DSurface9 *surface; IDirect3DSurface9 *surface;
IDirect3DDevice9 *device; IDirect3DDevice9 *device;
IMFMediaBuffer *buffer; IMFMediaBuffer *buffer;
LONG refcount, count;
unsigned int token; unsigned int token;
IMFGetService *gs; IMFGetService *gs;
IDirect3D9 *d3d; IDirect3D9 *d3d;
IUnknown *unk; IUnknown *unk;
HWND window; HWND window;
HRESULT hr; HRESULT hr;
LONG count;
BYTE *data; BYTE *data;
hr = MFCreateVideoSampleAllocator(&IID_IUnknown, (void **)&unk); hr = MFCreateVideoSampleAllocator(&IID_IUnknown, (void **)&unk);
...@@ -1397,7 +1397,7 @@ todo_wine ...@@ -1397,7 +1397,7 @@ todo_wine
sample = NULL; sample = NULL;
hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample); hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
ok(get_refcount(sample) == 3, "Unexpected refcount %u.\n", get_refcount(sample)); refcount = get_refcount(sample);
hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample2); hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample2);
ok(hr == MF_E_SAMPLEALLOCATOR_EMPTY, "Unexpected hr %#x.\n", hr); ok(hr == MF_E_SAMPLEALLOCATOR_EMPTY, "Unexpected hr %#x.\n", hr);
...@@ -1405,8 +1405,7 @@ todo_wine ...@@ -1405,8 +1405,7 @@ todo_wine
/* Reinitialize with active sample. */ /* Reinitialize with active sample. */
hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 4, video_type); hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 4, video_type);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
todo_wine ok(refcount == get_refcount(sample), "Unexpected refcount %u.\n", get_refcount(sample));
ok(get_refcount(sample) == 3, "Unexpected refcount %u.\n", get_refcount(sample));
hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count); hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr); ok(hr == S_OK, "Unexpected 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