From 2f912311718e522b2fb5e2a06446fe84a4247025 Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Tue, 25 Aug 2015 09:49:36 -0700 Subject: libhb: add hb_buffer_list This brings together several independent implementations of a simple buffer list manager. --- libhb/nlmeans.c | 52 +++++++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) (limited to 'libhb/nlmeans.c') diff --git a/libhb/nlmeans.c b/libhb/nlmeans.c index a306c8f4a..295aad863 100644 --- a/libhb/nlmeans.c +++ b/libhb/nlmeans.c @@ -1070,26 +1070,20 @@ static hb_buffer_t * nlmeans_filter(hb_filter_private_t *pv) pv->next_frame -= pv->thread_count; // Collect results from taskset - hb_buffer_t *last = NULL, *out = NULL; + hb_buffer_list_t list; + hb_buffer_list_clear(&list); for (int t = 0; t < pv->thread_count; t++) { - if (out == NULL) - { - out = last = pv->thread_data[t]->out; - } - else - { - last->next = pv->thread_data[t]->out; - last = pv->thread_data[t]->out; - } + hb_buffer_list_append(&list, pv->thread_data[t]->out); } - return out; + return hb_buffer_list_clear(&list); } static hb_buffer_t * nlmeans_filter_flush(hb_filter_private_t *pv) { - hb_buffer_t *out = NULL, *last = NULL; + hb_buffer_list_t list; + hb_buffer_list_clear(&list); for (int f = 0; f < pv->next_frame; f++) { Frame *frame = &pv->frame[f]; @@ -1140,17 +1134,9 @@ static hb_buffer_t * nlmeans_filter_flush(hb_filter_private_t *pv) pv->diff_max[c]); } buf->s = frame->s; - if (out == NULL) - { - out = last = buf; - } - else - { - last->next = buf; - last = buf; - } + hb_buffer_list_append(&list, buf); } - return out; + return hb_buffer_list_clear(&list); } static int nlmeans_work(hb_filter_object_t *filter, @@ -1162,21 +1148,17 @@ static int nlmeans_work(hb_filter_object_t *filter, if (in->s.flags & HB_BUF_FLAG_EOF) { - hb_buffer_t *last; + hb_buffer_list_t list; + hb_buffer_t *buf; + // Flush buffered frames - last = *buf_out = nlmeans_filter_flush(pv); + buf = nlmeans_filter_flush(pv); + hb_buffer_list_set(&list, buf); + + // And terminate the buffer list with a EOF buffer + hb_buffer_list_append(&list, in); + *buf_out = hb_buffer_list_clear(&list); - // And terminate the buffer list with a null buffer - if (last != NULL) - { - while (last->next != NULL) - last = last->next; - last->next = in; - } - else - { - *buf_out = in; - } *buf_in = NULL; return HB_FILTER_DONE; } -- cgit v1.2.3