Merge changes Ib4f4300a,Iaa867f1e into main * changes: Log the duration of camera hal daemon start Label the apex listener thread
diff --git a/common/hal/common/hal_types.h b/common/hal/common/hal_types.h index 39890fd..5255cd4 100644 --- a/common/hal/common/hal_types.h +++ b/common/hal/common/hal_types.h
@@ -35,6 +35,9 @@ // Used to identify an invalid buffer handle. static constexpr buffer_handle_t kInvalidBufferHandle = nullptr; +// Used to identify an invalid stream group id. +static constexpr int32_t kInvalidStreamGroupId = -1; + // See the definition of // ::android::hardware::camera::common::V1_0::TorchMode enum class TorchMode : uint32_t {
diff --git a/common/hal/google_camera_hal/camera_device_session.cc b/common/hal/google_camera_hal/camera_device_session.cc index 8b7ffd8..00b5924 100644 --- a/common/hal/google_camera_hal/camera_device_session.cc +++ b/common/hal/google_camera_hal/camera_device_session.cc
@@ -1771,7 +1771,8 @@ .format = stream_format, .producer_flags = producer_usage, .consumer_flags = consumer_usage, - .num_buffers_to_cache = num_buffers_to_cache}; + .num_buffers_to_cache = num_buffers_to_cache, + .group_id = stream.group_id}; status_t res = stream_buffer_cache_manager_->RegisterStream(reg_info); if (res != OK) {
diff --git a/common/hal/utils/stream_buffer_cache_manager.cc b/common/hal/utils/stream_buffer_cache_manager.cc index c2f0e65..aa38a19 100644 --- a/common/hal/utils/stream_buffer_cache_manager.cc +++ b/common/hal/utils/stream_buffer_cache_manager.cc
@@ -371,6 +371,7 @@ std::unique_lock<std::mutex> cache_lock(cache_access_mutex_); // 0. the buffer cache must be active + SetClientGetBufferStatusLocked(/*has_started=*/true); if (!is_active_) { ALOGW("%s: The buffer cache for stream %d is not active.", __FUNCTION__, cache_info_.stream_id); @@ -437,6 +438,15 @@ void StreamBufferCacheManager::StreamBufferCache::SetManagerState(bool active) { std::unique_lock<std::mutex> lock(cache_access_mutex_); is_active_ = active; + if (!active) { + // When the SBC is deactivated, we reset the client get buffer status. + SetClientGetBufferStatusLocked(/*has_started=*/false); + } +} + +void StreamBufferCacheManager::StreamBufferCache::SetClientGetBufferStatusLocked( + bool has_started) { + has_started_get_buffer_ = has_started; } status_t StreamBufferCacheManager::StreamBufferCache::FlushLocked( @@ -454,6 +464,7 @@ if (cached_buffers_.empty()) { ALOGV("%s: Stream buffer cache is already empty.", __FUNCTION__); + SetClientGetBufferStatusLocked(/*has_started=*/false); ReleasePlaceholderBufferLocked(); return OK; } @@ -465,6 +476,7 @@ } cached_buffers_.clear(); + SetClientGetBufferStatusLocked(/*has_started=*/false); ReleasePlaceholderBufferLocked(); return OK; @@ -558,6 +570,15 @@ return false; } + // For group streams, we would start refill buffer caches only after first + // get buffer from the client, to avoid cache buffer allocation before using. + if (cache_info_.group_id != kInvalidStreamGroupId && + !has_started_get_buffer_) { + ALOGV("%s: skip refilling for group stream %d.", __FUNCTION__, + cache_info_.stream_id); + return false; + } + // Need to refill if the cache is empty. return cached_buffers_.empty(); }
diff --git a/common/hal/utils/stream_buffer_cache_manager.h b/common/hal/utils/stream_buffer_cache_manager.h index 2d59448..cd3e8d8 100644 --- a/common/hal/utils/stream_buffer_cache_manager.h +++ b/common/hal/utils/stream_buffer_cache_manager.h
@@ -73,6 +73,8 @@ uint64_t consumer_flags = 0; // Number of buffers that the manager needs to cache uint32_t num_buffers_to_cache = 1; + // Group ID of the stream + int32_t group_id = kInvalidStreamGroupId; }; // @@ -202,6 +204,10 @@ IHalBufferAllocator* placeholder_buffer_allocator); private: + // Return whether the client has already started getting buffers. + // The cache_access_mutex_ must be locked when calling this function. + void SetClientGetBufferStatusLocked(bool has_started); + // Flush all buffers acquired from the buffer provider. Return the acquired // buffers through the return_func. // The cache_access_mutex_ must be locked when calling this function. @@ -255,9 +261,12 @@ // BufferRequestResult must be set to true. StreamBuffer placeholder_buffer_; // StreamBufferCacheManager does not refill a StreamBufferCache until this - // is set true by the client. Client should set this flag to true after the - // buffer provider (e.g. framework) is ready to handle buffer requests, or - // when a new request is submitted for an idle camera device (no inflight + // is set true by the client. For group streams, we would + // start refill a StreamBufferCache only when client first get buffer, to + // avoid redundant cache buffer allocation of useless group streams, details + // can be found in b/420847957. Client should set this flag to true after + // the buffer provider (e.g. framework) is ready to handle buffer requests, + // or when a new request is submitted for an idle camera device (no inflight // requests). bool is_active_ = false; // Interface to notify the parent manager for new threadloop workload. @@ -265,6 +274,11 @@ // Allocator of the placeholder buffer for this stream. The stream buffer cache // manager owns this throughout the life cycle of this stream buffer cahce. IHalBufferAllocator* placeholder_buffer_allocator_ = nullptr; + // Whether the client has started getting buffer on the StreamBufferCache. + // The client should reset this flag to false when the stream buffer cache + // manager is deactivated or flush. + // Must be protected by cache_access_mutex_. + bool has_started_get_buffer_ = false; }; // Add stream buffer cache. Lock caches_map_mutex_ before calling this func.