Remove timeout for __codec_v4l2_get_idle_buffer()
authorJeongmo Yang <jm80.yang@samsung.com>
Tue, 4 Feb 2025 11:38:45 +0000 (20:38 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Tue, 4 Feb 2025 11:38:45 +0000 (20:38 +0900)
The input buffers can be pushed continuously although all buffers are consumed.
In that case, we should wait until buffer is back from driver.

Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
src/hal_backend_codec_v4l2.c
src/hal_backend_codec_v4l2_private.h

index 1ff3ace3625550d87cb50fa3e8f4adb238b08dcf..2fa1139d4dcb0cb442aa3b28ef492cc004316f71 100644 (file)
@@ -1773,8 +1773,7 @@ static gpointer __codec_v4l2_buffer_handler_func(gpointer data)
                                        usleep(POLL_ERROR_TRY_SLEEP_US);
                                        continue;
                                } else {
-                                       LOGE("error count[%d] exceeded", POLL_ERROR_TRY_COUNT_MAX);
-                                       break;
+                                       LOGE("error count[%d][max:%d] exceeded", error_count, POLL_ERROR_TRY_COUNT_MAX);
                                }
                        }
                }
@@ -1947,15 +1946,22 @@ static hal_codec_buffer_s *__codec_v4l2_get_idle_buffer(codec_hal_buffer_control
        locker = g_mutex_locker_new(&buffer_control->lock);
 
        while (g_queue_is_empty(buffer_control->buffers.idle_buffers)) {
-               LOGD("type[%d] wait for idle buffer for %"G_GINT64_FORMAT" ms",
-                       buffer_control->type, timeout_ms);
+               if (timeout_ms > 0) {
+                       LOGD("wait for idle buffer for %"G_GINT64_FORMAT" ms", timeout_ms);
 
-               end_time = g_get_monotonic_time() + (G_TIME_SPAN_MILLISECOND * timeout_ms);
+                       end_time = g_get_monotonic_time() + (G_TIME_SPAN_MILLISECOND * timeout_ms);
 
-               if (!g_cond_wait_until(&buffer_control->cond, &buffer_control->lock, end_time)) {
-                       LOGE("type[%d] wait timed out for %"G_GINT64_FORMAT" ms", buffer_control->type, timeout_ms);
-                       return NULL;
+                       if (!g_cond_wait_until(&buffer_control->cond, &buffer_control->lock, end_time)) {
+                               LOGE("wait timed out for %"G_GINT64_FORMAT" ms", timeout_ms);
+                               return NULL;
+                       }
+               } else {
+                       LOGD("wait for idle buffer");
+                       g_cond_wait(&buffer_control->cond, &buffer_control->lock);
                }
+
+               LOGD("signal received - check again[queue length:%u]",
+                       g_queue_get_length(buffer_control->buffers.idle_buffers));
        }
 
        index = GPOINTER_TO_INT(g_queue_pop_head(buffer_control->buffers.idle_buffers));
@@ -2024,10 +2030,10 @@ int codec_v4l2_decode(void *codec_handle, hal_codec_buffer_s *buffer)
                return HAL_CODEC_ERROR_NONE;
        }
 
-       idle_buffer = __codec_v4l2_get_idle_buffer(buffer_control, IDLE_BUFFER_TIME_OUT_MS);
+       idle_buffer = __codec_v4l2_get_idle_buffer(buffer_control, 0);
        if (!idle_buffer) {
                LOGE("no idle buffer");
-               return HAL_CODEC_ERROR_INTERNAL;
+               return HAL_CODEC_ERROR_DEVICE_BUSY;
        }
 
        memcpy(idle_buffer->planes.plane[0].data, buffer->planes.plane[0].data, buffer->planes.plane[0].bytesused);
index e32eb04a31c5df0785fa2fcdb8ede4c14121b1c9..c27867b9e357cfc7c24496e72cdb76280b867e5d 100644 (file)
@@ -29,7 +29,7 @@
 
 #define CODEC_HAL_INITIAL_INDEX         -1
 #define CODEC_HAL_INITIAL_FD            -1
-#define BUFFER_MIN                      6
+#define BUFFER_MIN                      8
 #define BUFFER_MAX                      16
 #define V4L2_PLANES_MAX                 4