output: add debug logs
[platform/core/uifw/libtdm.git] / src / tdm_capture.c
1 /**************************************************************************
2  *
3  * libtdm
4  *
5  * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6  *
7  * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8  *          JinYoung Jeon <jy0.jeon@samsung.com>,
9  *          Taeheon Kim <th908.kim@samsung.com>,
10  *          YoungJun Cho <yj44.cho@samsung.com>,
11  *          SooChan Lim <sc1.lim@samsung.com>,
12  *          Boram Park <sc1.lim@samsung.com>
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the
16  * "Software"), to deal in the Software without restriction, including
17  * without limitation the rights to use, copy, modify, merge, publish,
18  * distribute, sub license, and/or sell copies of the Software, and to
19  * permit persons to whom the Software is furnished to do so, subject to
20  * the following conditions:
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34 **************************************************************************/
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 #include "tdm.h"
41 #include "tdm_backend.h"
42 #include "tdm_private.h"
43 #include "tdm_helper.h"
44
45 #define CAPTURE_FUNC_ENTRY() \
46         tdm_func_capture *func_capture; \
47         tdm_private_display *private_display; \
48         tdm_private_capture *private_capture; \
49         tdm_error ret = TDM_ERROR_NONE; \
50         TDM_RETURN_VAL_IF_FAIL(capture != NULL, TDM_ERROR_INVALID_PARAMETER); \
51         private_capture = (tdm_private_capture*)capture; \
52         private_display = private_capture->private_display; \
53         func_capture = &private_display->func_capture
54
55 static void
56 _tdm_capture_print_list(struct list_head *list)
57 {
58         tdm_capture_private_buffer *b = NULL;
59         char str[512], *p;
60         int len = sizeof(str);
61
62         TDM_RETURN_IF_FAIL(list != NULL);
63
64         p = str;
65         LIST_FOR_EACH_ENTRY(b, list, link) {
66                 if (len > 0) {
67                         int l = snprintf(p, len, " (%p)", b->buffer);
68                         p += l;
69                         len -= l;
70                 } else
71                         break;
72         }
73
74         TDM_INFO("\t %s", str);
75 }
76
77 static tdm_capture_private_buffer *
78 _tdm_capture_find_tbm_buffer(struct list_head *list, tbm_surface_h buffer)
79 {
80         tdm_capture_private_buffer *b = NULL, *bb = NULL;
81
82         LIST_FOR_EACH_ENTRY_SAFE(b, bb, list, link) {
83                 if (b->buffer == buffer)
84                         return b;
85         }
86
87         return NULL;
88 }
89
90 static tdm_capture_private_buffer *
91 _tdm_capture_find_buffer(struct list_head *list, tdm_capture_private_buffer *capture_buffer)
92 {
93         tdm_capture_private_buffer *b = NULL, *bb = NULL;
94
95         LIST_FOR_EACH_ENTRY_SAFE(b, bb, list, link) {
96                 if (b == capture_buffer)
97                         return b;
98         }
99
100         return NULL;
101 }
102
103 INTERN void
104 tdm_capture_cb_done(tdm_capture *capture_backend, tbm_surface_h buffer,
105                                         void *user_data)
106 {
107         tdm_private_capture *private_capture = user_data;
108         tdm_private_display *private_display = private_capture->private_display;
109         tdm_capture_private_buffer *capture_buffer = NULL, *first_entry = NULL;
110
111         TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
112
113         if (private_capture->owner_tid != syscall(SYS_gettid)) {
114                 tdm_thread_cb_capture_done capture_done;
115                 tdm_error ret;
116
117                 capture_done.base.type = TDM_THREAD_CB_CAPTURE_DONE;
118                 capture_done.base.length = sizeof capture_done;
119                 capture_done.capture_stamp = private_capture->stamp;
120                 capture_done.buffer = buffer;
121                 capture_done.user_data = user_data;
122
123                 ret = tdm_thread_send_cb(private_display->private_loop, &capture_done.base);
124                 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
125
126                 return;
127         }
128
129         if (private_capture->owner_tid != syscall(SYS_gettid))
130                 TDM_NEVER_GET_HERE();
131
132         if (tdm_debug_dump & TDM_DUMP_FLAG_CAPTURE) {
133                 /* LCOV_EXCL_START */
134                 char str[TDM_PATH_LEN];
135                 static int i;
136                 snprintf(str, TDM_PATH_LEN, "capture_%03d", i++);
137                 tdm_helper_dump_buffer_str(buffer, tdm_debug_dump_dir, str);
138                 /* LCOV_EXCL_STOP */
139         }
140
141         if (tdm_debug_module & TDM_DEBUG_BUFFER)
142                 TDM_INFO("capture(%p) done: %p", private_capture, buffer);
143
144         if (!LIST_IS_EMPTY(&private_capture->buffer_list)) {
145                 first_entry = container_of((&private_capture->buffer_list)->next, capture_buffer, link);
146                 if (first_entry->buffer != buffer)
147                         TDM_ERR("buffer(%p) is skipped", first_entry->buffer);
148         } else {
149                 TDM_NEVER_GET_HERE();
150         }
151
152         if ((capture_buffer = _tdm_capture_find_tbm_buffer(&private_capture->buffer_list, buffer))) {
153                 LIST_DEL(&capture_buffer->link);
154                 LIST_DELINIT(&capture_buffer->commit_link);
155
156                 _pthread_mutex_unlock(&private_display->lock);
157                 if (private_capture->done_func)
158                         private_capture->done_func(capture_buffer, buffer, private_capture->done_user_data);
159                 tdm_buffer_unref_backend(buffer);
160                 _pthread_mutex_lock(&private_display->lock);
161
162                 free(capture_buffer);
163         }
164 }
165
166 INTERN tdm_private_capture *
167 tdm_capture_find_stamp(tdm_private_display *private_display, double stamp)
168 {
169         tdm_private_capture *private_capture = NULL;
170
171         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), NULL);
172
173         LIST_FOR_EACH_ENTRY(private_capture, &private_display->capture_list, display_link) {
174                 if (private_capture->stamp == stamp)
175                         return private_capture;
176         }
177
178         return NULL;
179 }
180
181 INTERN tdm_private_capture *
182 tdm_capture_create_output_internal(tdm_private_output *private_output,
183                                                                    tdm_error *error)
184 {
185         tdm_private_display *private_display = private_output->private_display;
186         tdm_func_output *func_output = &private_display->func_output;
187         tdm_func_capture *func_capture = &private_display->func_capture;
188         tdm_private_capture *private_capture = NULL;
189         tdm_capture *capture_backend = NULL;
190         tdm_error ret = TDM_ERROR_NONE;
191
192         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), NULL);
193
194         if (!(private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE)) {
195                 /* LCOV_EXCL_START */
196                 TDM_ERR("no capture capability");
197                 if (error)
198                         *error = TDM_ERROR_NO_CAPABILITY;
199                 return NULL;
200                 /* LCOV_EXCL_STOP */
201         }
202
203         if (!(private_display->caps_capture.capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT)) {
204                 /* LCOV_EXCL_START */
205                 TDM_ERR("no output capture capability");
206                 if (error)
207                         *error = TDM_ERROR_NO_CAPABILITY;
208                 return NULL;
209                 /* LCOV_EXCL_STOP */
210         }
211
212         capture_backend = func_output->output_create_capture(
213                                                   private_output->output_backend, &ret);
214         if (ret != TDM_ERROR_NONE) {
215                 /* LCOV_EXCL_START */
216                 if (error)
217                         *error = ret;
218                 return NULL;
219                 /* LCOV_EXCL_STOP */
220         }
221
222         private_capture = calloc(1, sizeof(tdm_private_capture));
223         if (!private_capture) {
224                 /* LCOV_EXCL_START */
225                 TDM_ERR("failed: alloc memory");
226                 func_capture->capture_destroy(capture_backend);
227                 if (error)
228                         *error = TDM_ERROR_OUT_OF_MEMORY;
229                 return NULL;
230                 /* LCOV_EXCL_STOP */
231         }
232
233         ret = func_capture->capture_set_done_handler(capture_backend,
234                         tdm_capture_cb_done, private_capture);
235         if (ret != TDM_ERROR_NONE) {
236                 /* LCOV_EXCL_START */
237                 TDM_ERR("capture(%p) set capture_done_handler failed", private_capture);
238                 func_capture->capture_destroy(capture_backend);
239                 if (error)
240                         *error = ret;
241                 return NULL;
242                 /* LCOV_EXCL_STOP */
243         }
244
245         private_capture->stamp = tdm_helper_get_time();
246         while (tdm_capture_find_stamp(private_display, private_capture->stamp))
247                 private_capture->stamp++;
248
249         LIST_ADD(&private_capture->link, &private_output->capture_list);
250         LIST_ADD(&private_capture->display_link, &private_display->capture_list);
251
252         private_capture->target = TDM_CAPTURE_TARGET_OUTPUT;
253         private_capture->private_display = private_display;
254         private_capture->private_output = private_output;
255         private_capture->private_layer = NULL;
256         private_capture->capture_backend = capture_backend;
257         private_capture->owner_tid = syscall(SYS_gettid);
258
259         LIST_INITHEAD(&private_capture->pending_buffer_list);
260         LIST_INITHEAD(&private_capture->buffer_list);
261
262         TDM_DBG("capture(%p) create", private_capture);
263
264         if (error)
265                 *error = TDM_ERROR_NONE;
266
267         return private_capture;
268 }
269
270 /* LCOV_EXCL_START */
271 INTERN tdm_private_capture *
272 tdm_capture_create_layer_internal(tdm_private_layer *private_layer,
273                                                                   tdm_error *error)
274 {
275         tdm_private_output *private_output = private_layer->private_output;
276         tdm_private_display *private_display = private_output->private_display;
277         tdm_func_layer *func_layer = &private_display->func_layer;
278         tdm_func_capture *func_capture = &private_display->func_capture;
279         tdm_private_capture *private_capture = NULL;
280         tdm_capture *capture_backend = NULL;
281         tdm_error ret = TDM_ERROR_NONE;
282
283         TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), NULL);
284
285         if (!(private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE)) {
286                 TDM_ERR("no capture capability");
287                 if (error)
288                         *error = TDM_ERROR_NO_CAPABILITY;
289                 return NULL;
290         }
291
292         if (!(private_display->caps_capture.capabilities & TDM_CAPTURE_CAPABILITY_LAYER)) {
293                 TDM_ERR("no layer capture capability");
294                 if (error)
295                         *error = TDM_ERROR_NO_CAPABILITY;
296                 return NULL;
297         }
298
299         capture_backend = func_layer->layer_create_capture(private_layer->layer_backend,
300                                           &ret);
301         if (ret != TDM_ERROR_NONE)
302                 return NULL;
303
304         private_capture = calloc(1, sizeof(tdm_private_capture));
305         if (!private_capture) {
306                 TDM_ERR("failed: alloc memory");
307                 func_capture->capture_destroy(capture_backend);
308                 if (error)
309                         *error = TDM_ERROR_OUT_OF_MEMORY;
310                 return NULL;
311         }
312
313         private_capture->stamp = tdm_helper_get_time();
314         while (tdm_capture_find_stamp(private_display, private_capture->stamp))
315                 private_capture->stamp++;
316
317         LIST_ADD(&private_capture->link, &private_layer->capture_list);
318         LIST_ADD(&private_capture->display_link, &private_display->capture_list);
319
320         private_capture->target = TDM_CAPTURE_TARGET_LAYER;
321         private_capture->private_display = private_display;
322         private_capture->private_output = private_output;
323         private_capture->private_layer = private_layer;
324         private_capture->capture_backend = capture_backend;
325         private_capture->owner_tid = syscall(SYS_gettid);
326
327         LIST_INITHEAD(&private_capture->pending_buffer_list);
328         LIST_INITHEAD(&private_capture->buffer_list);
329
330         TDM_DBG("capture(%p) create", private_capture);
331
332         if (error)
333                 *error = TDM_ERROR_NONE;
334
335         return private_capture;
336 }
337 /* LCOV_EXCL_STOP */
338
339 INTERN void
340 tdm_capture_destroy_internal(tdm_private_capture *private_capture)
341 {
342         tdm_private_display *private_display;
343         tdm_func_capture *func_capture;
344         tdm_capture_private_buffer *b = NULL, *bb = NULL;
345         struct list_head clone_list;
346
347         TDM_RETURN_IF_FAIL(TDM_MUTEX_IS_LOCKED());
348
349         if (!private_capture)
350                 return;
351
352         private_display = private_capture->private_display;
353
354         LIST_DEL(&private_capture->link);
355         LIST_DEL(&private_capture->display_link);
356
357         func_capture = &private_capture->private_display->func_capture;
358         func_capture->capture_destroy(private_capture->capture_backend);
359
360         if (!LIST_IS_EMPTY(&private_capture->pending_buffer_list)) {
361                 TDM_WRN("capture(%p) not finished:", private_capture);
362                 _tdm_capture_print_list(&private_capture->pending_buffer_list);
363
364                 LIST_INITHEAD(&clone_list);
365                 LIST_FOR_EACH_ENTRY_SAFE(b, bb, &private_capture->pending_buffer_list, link) {
366                         LIST_DEL(&b->link);
367                         LIST_ADDTAIL(&b->link, &clone_list);
368                 }
369
370                 _pthread_mutex_unlock(&private_display->lock);
371                 LIST_FOR_EACH_ENTRY_SAFE(b, bb, &clone_list, link) {
372                         LIST_DEL(&b->link);
373                         tdm_buffer_unref_backend(b->buffer);
374                         free(b);
375                 }
376                 _pthread_mutex_lock(&private_display->lock);
377         }
378
379         if (!LIST_IS_EMPTY(&private_capture->buffer_list)) {
380                 TDM_WRN("capture(%p) not finished:", private_capture);
381                 _tdm_capture_print_list(&private_capture->buffer_list);
382
383                 LIST_INITHEAD(&clone_list);
384                 LIST_FOR_EACH_ENTRY_SAFE(b, bb, &private_capture->buffer_list, link) {
385                         LIST_DEL(&b->link);
386                         LIST_ADDTAIL(&b->link, &clone_list);
387                 }
388
389                 _pthread_mutex_unlock(&private_display->lock);
390                 LIST_FOR_EACH_ENTRY_SAFE(b, bb, &clone_list, link) {
391                         LIST_DEL(&b->link);
392                         tdm_buffer_unref_backend(b->buffer);
393                         free(b);
394                 }
395                 _pthread_mutex_lock(&private_display->lock);
396         }
397
398         private_capture->stamp = 0;
399         free(private_capture);
400 }
401
402 EXTERN void
403 tdm_capture_destroy(tdm_capture *capture)
404 {
405         tdm_private_capture *private_capture = capture;
406         tdm_private_display *private_display;
407
408         if (!private_capture)
409                 return;
410
411         TDM_DBG("capture(%p) destroy", private_capture);
412
413         private_display = private_capture->private_display;
414
415         _pthread_mutex_lock(&private_display->lock);
416         tdm_capture_destroy_internal(private_capture);
417         _pthread_mutex_unlock(&private_display->lock);
418 }
419
420 EXTERN tdm_error
421 tdm_capture_set_info(tdm_capture *capture, tdm_info_capture *info)
422 {
423         CAPTURE_FUNC_ENTRY();
424
425         TDM_RETURN_VAL_IF_FAIL(info != NULL, TDM_ERROR_INVALID_PARAMETER);
426         TDM_RETURN_VAL_IF_FAIL(info->type != 0, TDM_ERROR_INVALID_PARAMETER);
427
428         _pthread_mutex_lock(&private_display->lock);
429
430         if (!func_capture->capture_set_info) {
431                 /* LCOV_EXCL_START */
432                 _pthread_mutex_unlock(&private_display->lock);
433                 TDM_DBG("failed: not implemented!!");
434                 return TDM_ERROR_NOT_IMPLEMENTED;
435                 /* LCOV_EXCL_STOP */
436         }
437
438         if (info->type == TDM_CAPTURE_TYPE_STREAM && info->frequency == 0) {
439                 tdm_private_output *private_output = private_capture->private_output;
440                 info->frequency = private_output->current_mode->vrefresh;
441         }
442
443         TDM_INFO("capture(%p) info: dst(%dx%d %d,%d %dx%d %c%c%c%c) trans(%d) type(%d) freq(%d) flags(%x)",
444                          private_capture,
445                          info->dst_config.size.h, info->dst_config.size.v,
446                          info->dst_config.pos.x, info->dst_config.pos.y,
447                          info->dst_config.pos.w, info->dst_config.pos.h,
448                          FOURCC_STR(info->dst_config.format),
449                          info->transform, info->type, info->frequency, info->flags);
450
451         ret = func_capture->capture_set_info(private_capture->capture_backend, info);
452         TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
453
454         private_capture->info = *info;
455
456         _pthread_mutex_unlock(&private_display->lock);
457
458         return ret;
459 }
460
461 EXTERN tdm_error
462 tdm_capture_set_done_handler(tdm_capture *capture, tdm_capture_done_handler func, void *user_data)
463 {
464         tdm_private_display *private_display;
465         tdm_private_capture *private_capture;
466         tdm_error ret = TDM_ERROR_NONE;
467
468         TDM_RETURN_VAL_IF_FAIL(capture != NULL, TDM_ERROR_INVALID_PARAMETER);
469
470         private_capture = (tdm_private_capture*)capture;
471         private_display = private_capture->private_display;
472
473         TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
474
475         _pthread_mutex_lock(&private_display->lock);
476
477         private_capture->done_func = func;
478         private_capture->done_user_data = user_data;
479
480         _pthread_mutex_unlock(&private_display->lock);
481
482         return ret;
483 }
484
485 EXTERN tdm_error
486 tdm_capture_attach(tdm_capture *capture, tbm_surface_h buffer)
487 {
488         tdm_capture_private_buffer *capture_buffer;
489
490         CAPTURE_FUNC_ENTRY();
491
492         TDM_RETURN_VAL_IF_FAIL(buffer != NULL, TDM_ERROR_INVALID_PARAMETER);
493
494         _pthread_mutex_lock(&private_display->lock);
495
496         if (!func_capture->capture_attach) {
497                 /* LCOV_EXCL_START */
498                 _pthread_mutex_unlock(&private_display->lock);
499                 TDM_DBG("failed: not implemented!!");
500                 return TDM_ERROR_NOT_IMPLEMENTED;
501                 /* LCOV_EXCL_STOP */
502         }
503
504         if (tdm_display_check_module_abi(private_display, 1, 2) &&
505                 private_display->caps_capture.max_attach_count > 0) {
506                 /* LCOV_EXCL_START */
507                 int length = LIST_LENGTH(&private_capture->pending_buffer_list) +
508                                          LIST_LENGTH(&private_capture->buffer_list);
509                 if (length >= private_display->caps_capture.max_attach_count) {
510                         _pthread_mutex_unlock(&private_display->lock);
511                         TDM_DBG("failed: too many attached!! max_attach_count(%d)",
512                                         private_display->caps_capture.max_attach_count);
513                         return TDM_ERROR_BAD_REQUEST;
514                 }
515                 /* LCOV_EXCL_STOP */
516         }
517
518         capture_buffer = calloc(1, sizeof * capture_buffer);
519         if (!capture_buffer) {
520                 /* LCOV_EXCL_START */
521                 _pthread_mutex_unlock(&private_display->lock);
522                 TDM_ERR("alloc failed");
523                 return TDM_ERROR_OUT_OF_MEMORY;
524                 /* LCOV_EXCL_STOP */
525         }
526
527         ret = func_capture->capture_attach(private_capture->capture_backend, buffer);
528         TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
529
530         if (ret != TDM_ERROR_NONE) {
531                 /* LCOV_EXCL_START */
532                 free(capture_buffer);
533                 _pthread_mutex_unlock(&private_display->lock);
534                 TDM_ERR("attach failed");
535                 return ret;
536                 /* LCOV_EXCL_STOP */
537         }
538
539         LIST_ADDTAIL(&capture_buffer->link, &private_capture->pending_buffer_list);
540         capture_buffer->buffer = tdm_buffer_ref_backend(buffer);
541
542         if (tdm_debug_module & TDM_DEBUG_BUFFER) {
543                 TDM_INFO("capture(%p) attached:", private_capture);
544                 tdm_buffer_list_dump(&private_capture->buffer_list);
545         }
546
547         _pthread_mutex_unlock(&private_display->lock);
548
549         return ret;
550 }
551
552 EXTERN tdm_error
553 tdm_capture_commit(tdm_capture *capture)
554 {
555         tdm_capture_private_buffer *b = NULL, *bb = NULL;
556         tdm_private_output *private_output;
557         struct list_head commit_buffer_list;
558
559         CAPTURE_FUNC_ENTRY();
560
561         _pthread_mutex_lock(&private_display->lock);
562
563         private_output = private_capture->private_output;
564         if (private_output->current_dpms_value > TDM_OUTPUT_DPMS_ON) {
565                 TDM_ERR("output(%d) dpms: %s", private_output->pipe,
566                                 tdm_dpms_str(private_output->current_dpms_value));
567                 _pthread_mutex_unlock(&private_display->lock);
568                 return TDM_ERROR_BAD_REQUEST;
569         }
570
571         if (!func_capture->capture_commit) {
572                 /* LCOV_EXCL_START */
573                 _pthread_mutex_unlock(&private_display->lock);
574                 TDM_DBG("failed: not implemented!!");
575                 return TDM_ERROR_NOT_IMPLEMENTED;
576                 /* LCOV_EXCL_STOP */
577         }
578
579         LIST_INITHEAD(&commit_buffer_list);
580
581         LIST_FOR_EACH_ENTRY_SAFE(b, bb, &private_capture->pending_buffer_list, link) {
582                 LIST_DEL(&b->link);
583                 LIST_ADDTAIL(&b->link, &private_capture->buffer_list);
584                 LIST_ADDTAIL(&b->commit_link, &commit_buffer_list);
585         }
586
587         ret = func_capture->capture_commit(private_capture->capture_backend);
588         TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
589
590         LIST_FOR_EACH_ENTRY_SAFE(b, bb, &commit_buffer_list, commit_link) {
591                 LIST_DELINIT(&b->commit_link);
592
593                 if (!_tdm_capture_find_buffer(&private_capture->buffer_list, b))
594                         continue;
595
596                 if (ret != TDM_ERROR_NONE) {
597                         /* LCOV_EXCL_START */
598                         /* Not to call the user release handler when failed.
599                          * Do we have to call this function here really?
600                          * User better use set_done_handler to know when pp is done. Using
601                          * buffer_release_handler is not good.
602                          */
603                         tdm_buffer_remove_release_handler_internal(b->buffer);
604
605                         _pthread_mutex_unlock(&private_display->lock);
606                         tdm_buffer_unref_backend(b->buffer);
607                         _pthread_mutex_lock(&private_display->lock);
608                         LIST_DEL(&b->link);
609
610                         free(b);
611                         /* LCOV_EXCL_STOP */
612                 }
613         }
614
615         _pthread_mutex_unlock(&private_display->lock);
616
617         return ret;
618 }