Commit ca20e060 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

winegstreamer: Remove the callback mechanism from wg_allocator.

parent 59dedf27
......@@ -60,9 +60,9 @@ extern NTSTATUS wg_transform_flush(void *args) DECLSPEC_HIDDEN;
/* wg_allocator_release_sample can be used to release any sample that was requested. */
typedef struct wg_sample *(*wg_allocator_request_sample_cb)(gsize size, void *context);
extern GstAllocator *wg_allocator_create(wg_allocator_request_sample_cb request_sample,
void *request_sample_context) DECLSPEC_HIDDEN;
extern GstAllocator *wg_allocator_create(void) DECLSPEC_HIDDEN;
extern void wg_allocator_destroy(GstAllocator *allocator) DECLSPEC_HIDDEN;
extern void wg_allocator_provide_sample(GstAllocator *allocator, struct wg_sample *sample) DECLSPEC_HIDDEN;
extern void wg_allocator_release_sample(GstAllocator *allocator, struct wg_sample *sample,
bool discard_data) DECLSPEC_HIDDEN;
......
......@@ -51,12 +51,11 @@ typedef struct
{
GstAllocator parent;
wg_allocator_request_sample_cb request_sample;
void *request_sample_context;
pthread_mutex_t mutex;
pthread_cond_t release_cond;
struct list memory_list;
struct wg_sample *next_sample;
} WgAllocator;
typedef struct
......@@ -147,7 +146,6 @@ static GstMemory *wg_allocator_alloc(GstAllocator *gst_allocator, gsize size,
GstAllocationParams *params)
{
WgAllocator *allocator = (WgAllocator *)gst_allocator;
struct wg_sample *sample;
WgMemory *memory;
GST_LOG("allocator %p, size %#zx, params %p", allocator, size, params);
......@@ -160,11 +158,11 @@ static GstMemory *wg_allocator_alloc(GstAllocator *gst_allocator, gsize size,
pthread_mutex_lock(&allocator->mutex);
sample = allocator->request_sample(size, allocator->request_sample_context);
if (sample && sample->max_size < size)
InterlockedDecrement(&sample->refcount);
memory->sample = allocator->next_sample;
if (memory->sample && memory->sample->max_size >= size)
allocator->next_sample = NULL;
else
memory->sample = sample;
memory->sample = NULL;
list_add_tail(&allocator->memory_list, &memory->entry);
......@@ -209,15 +207,13 @@ static void wg_allocator_class_init(WgAllocatorClass *klass)
root_class->finalize = wg_allocator_finalize;
}
GstAllocator *wg_allocator_create(wg_allocator_request_sample_cb request_sample, void *request_sample_context)
GstAllocator *wg_allocator_create(void)
{
WgAllocator *allocator;
if (!(allocator = g_object_new(wg_allocator_get_type(), NULL)))
return NULL;
allocator->request_sample = request_sample;
allocator->request_sample_context = request_sample_context;
return GST_ALLOCATOR(allocator);
}
......@@ -273,6 +269,25 @@ static WgMemory *find_sample_memory(WgAllocator *allocator, struct wg_sample *sa
return NULL;
}
void wg_allocator_provide_sample(GstAllocator *gst_allocator, struct wg_sample *sample)
{
WgAllocator *allocator = (WgAllocator *)gst_allocator;
struct wg_sample *previous;
GST_LOG("allocator %p, sample %p", allocator, sample);
if (sample)
InterlockedIncrement(&sample->refcount);
pthread_mutex_lock(&allocator->mutex);
previous = allocator->next_sample;
allocator->next_sample = sample;
pthread_mutex_unlock(&allocator->mutex);
if (previous)
InterlockedDecrement(&previous->refcount);
}
void wg_allocator_release_sample(GstAllocator *gst_allocator, struct wg_sample *sample,
bool discard_data)
{
......
......@@ -57,7 +57,6 @@ struct wg_transform
GstElement *video_flip;
struct wg_format output_format;
struct wg_sample *output_wg_sample;
GstAtomicQueue *output_queue;
GstSample *output_sample;
bool output_caps_changed;
......@@ -281,15 +280,6 @@ NTSTATUS wg_transform_destroy(void *args)
return STATUS_SUCCESS;
}
static struct wg_sample *transform_request_sample(gsize size, void *context)
{
struct wg_transform *transform = context;
GST_LOG("size %#zx, context %p", size, transform);
return InterlockedExchangePointer((void **)&transform->output_wg_sample, NULL);
}
static bool wg_format_video_is_flipped(const struct wg_format *format)
{
return format->major_type == WG_MAJOR_TYPE_VIDEO && (format->u.video.height < 0);
......@@ -318,7 +308,7 @@ NTSTATUS wg_transform_create(void *args)
goto out;
if (!(transform->drain_query = gst_query_new_drain()))
goto out;
if (!(transform->allocator = wg_allocator_create(transform_request_sample, transform)))
if (!(transform->allocator = wg_allocator_create()))
goto out;
transform->attrs = *params->attrs;
transform->output_format = output_format;
......@@ -762,9 +752,7 @@ static bool get_transform_output(struct wg_transform *transform, struct wg_sampl
GstBuffer *input_buffer;
GstFlowReturn ret;
/* Provide the sample for transform_request_sample to pick it up */
InterlockedIncrement(&sample->refcount);
InterlockedExchangePointer((void **)&transform->output_wg_sample, sample);
wg_allocator_provide_sample(transform->allocator, sample);
while (!(transform->output_sample = gst_atomic_queue_pop(transform->output_queue))
&& (input_buffer = gst_atomic_queue_pop(transform->input_queue)))
......@@ -773,9 +761,8 @@ static bool get_transform_output(struct wg_transform *transform, struct wg_sampl
GST_WARNING("Failed to push transform input, error %d", ret);
}
/* Remove the sample so transform_request_sample cannot use it */
if (InterlockedExchangePointer((void **)&transform->output_wg_sample, NULL))
InterlockedDecrement(&sample->refcount);
/* Remove the sample so the allocator cannot use it */
wg_allocator_provide_sample(transform->allocator, NULL);
return !!transform->output_sample;
}
......
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