diff options
author | Cheng Gu <gucheng@google.com> | 2022-07-26 21:19:57 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-07-26 21:19:57 +0000 |
commit | 1571151a187391002daff177d597ac6ade968494 (patch) | |
tree | b97bd207bcccfa7eacee3e1ee0f7cdc19cc3e82d | |
parent | 0f878e3c4bd5367dfb8795ee90294067ecd1ea6a (diff) | |
parent | f327f10b93ca246f38a4f80a30ea224b2bf933fe (diff) | |
download | camera-1571151a187391002daff177d597ac6ade968494.tar.gz |
Merge "ResultDispatcher: Give each instance a name" into tm-d1-dev am: f327f10b93
Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/google/camera/+/19398014
Change-Id: Id21bac283ab737130422160177deb25be36e9ad8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | common/hal/google_camera_hal/hdrplus_capture_session.cc | 4 | ||||
-rw-r--r-- | common/hal/google_camera_hal/rgbird_capture_session.cc | 4 | ||||
-rw-r--r-- | common/hal/tests/result_dispatcher_tests.cc | 3 | ||||
-rw-r--r-- | common/hal/utils/result_dispatcher.cc | 152 | ||||
-rw-r--r-- | common/hal/utils/result_dispatcher.h | 11 | ||||
-rw-r--r-- | common/hal/utils/zsl_result_dispatcher.cc | 12 |
6 files changed, 104 insertions, 82 deletions
diff --git a/common/hal/google_camera_hal/hdrplus_capture_session.cc b/common/hal/google_camera_hal/hdrplus_capture_session.cc index c7b676a..9a78e6e 100644 --- a/common/hal/google_camera_hal/hdrplus_capture_session.cc +++ b/common/hal/google_camera_hal/hdrplus_capture_session.cc @@ -480,8 +480,8 @@ status_t HdrplusCaptureSession::Initialize( } // Create result dispatcher - result_dispatcher_ = - ResultDispatcher::Create(kPartialResult, process_capture_result, notify); + result_dispatcher_ = ResultDispatcher::Create( + kPartialResult, process_capture_result, notify, "HdrplusDispatcher"); if (result_dispatcher_ == nullptr) { ALOGE("%s: Cannot create result dispatcher.", __FUNCTION__); return UNKNOWN_ERROR; diff --git a/common/hal/google_camera_hal/rgbird_capture_session.cc b/common/hal/google_camera_hal/rgbird_capture_session.cc index 272b2a8..919a2fa 100644 --- a/common/hal/google_camera_hal/rgbird_capture_session.cc +++ b/common/hal/google_camera_hal/rgbird_capture_session.cc @@ -986,8 +986,8 @@ status_t RgbirdCaptureSession::Initialize( } // Create result dispatcher - result_dispatcher_ = - ResultDispatcher::Create(kPartialResult, process_capture_result, notify); + result_dispatcher_ = ResultDispatcher::Create( + kPartialResult, process_capture_result, notify, "RgbirdDispatcher"); if (result_dispatcher_ == nullptr) { ALOGE("%s: Cannot create result dispatcher.", __FUNCTION__); return UNKNOWN_ERROR; diff --git a/common/hal/tests/result_dispatcher_tests.cc b/common/hal/tests/result_dispatcher_tests.cc index 7196767..4964ab3 100644 --- a/common/hal/tests/result_dispatcher_tests.cc +++ b/common/hal/tests/result_dispatcher_tests.cc @@ -64,7 +64,8 @@ class ResultDispatcherTests : public ::testing::Test { [this](std::unique_ptr<CaptureResult> result) { ProcessCaptureResult(std::move(result)); }, - [this](const NotifyMessage& message) { Notify(message); }); + [this](const NotifyMessage& message) { Notify(message); }, + "TestResultDispatcher"); ASSERT_NE(result_dispatcher_, nullptr) << "Creating ResultDispatcher failed"; diff --git a/common/hal/utils/result_dispatcher.cc b/common/hal/utils/result_dispatcher.cc index 0a4832c..6aa2d12 100644 --- a/common/hal/utils/result_dispatcher.cc +++ b/common/hal/utils/result_dispatcher.cc @@ -17,12 +17,15 @@ //#define LOG_NDEBUG 0 #define LOG_TAG "GCH_ResultDispatcher" #define ATRACE_TAG ATRACE_TAG_CAMERA +#include "result_dispatcher.h" + +#include <inttypes.h> #include <log/log.h> #include <utils/Trace.h> -#include <inttypes.h> +#include <string> +#include <string_view> -#include "result_dispatcher.h" #include "utils.h" namespace android { @@ -30,12 +33,14 @@ namespace google_camera_hal { std::unique_ptr<ResultDispatcher> ResultDispatcher::Create( uint32_t partial_result_count, - ProcessCaptureResultFunc process_capture_result, NotifyFunc notify) { + ProcessCaptureResultFunc process_capture_result, NotifyFunc notify, + std::string_view name) { ATRACE_CALL(); auto dispatcher = std::unique_ptr<ResultDispatcher>(new ResultDispatcher( - partial_result_count, process_capture_result, notify)); + partial_result_count, process_capture_result, notify, name)); if (dispatcher == nullptr) { - ALOGE("%s: Creating ResultDispatcher failed.", __FUNCTION__); + ALOGE("[%s] %s: Creating ResultDispatcher failed.", + std::string(name).c_str(), __FUNCTION__); return nullptr; } @@ -44,8 +49,10 @@ std::unique_ptr<ResultDispatcher> ResultDispatcher::Create( ResultDispatcher::ResultDispatcher( uint32_t partial_result_count, - ProcessCaptureResultFunc process_capture_result, NotifyFunc notify) + ProcessCaptureResultFunc process_capture_result, NotifyFunc notify, + std::string_view name) : kPartialResultCount(partial_result_count), + name_(name), process_capture_result_(process_capture_result), notify_(notify) { ATRACE_CALL(); @@ -56,9 +63,9 @@ ResultDispatcher::ResultDispatcher( status_t res = utils::SetRealtimeThread(notify_callback_thread_.native_handle()); if (res != OK) { - ALOGE("%s: SetRealtimeThread fail", __FUNCTION__); + ALOGE("[%s] %s: SetRealtimeThread fail", name_.c_str(), __FUNCTION__); } else { - ALOGI("%s: SetRealtimeThread OK", __FUNCTION__); + ALOGI("[%s] %s: SetRealtimeThread OK", name_.c_str(), __FUNCTION__); } } } @@ -87,8 +94,8 @@ status_t ResultDispatcher::AddPendingRequest( status_t res = AddPendingRequestLocked(pending_request); if (res != OK) { - ALOGE("%s: Adding a pending request failed: %s(%d).", __FUNCTION__, - strerror(-res), res); + ALOGE("[%s] %s: Adding a pending request failed: %s(%d).", name_.c_str(), + __FUNCTION__, strerror(-res), res); RemovePendingRequestLocked(pending_request.frame_number); return res; } @@ -103,23 +110,23 @@ status_t ResultDispatcher::AddPendingRequestLocked( status_t res = AddPendingShutterLocked(frame_number); if (res != OK) { - ALOGE("%s: Adding pending shutter for frame %u failed: %s(%d)", - __FUNCTION__, frame_number, strerror(-res), res); + ALOGE("[%s] %s: Adding pending shutter for frame %u failed: %s(%d)", + name_.c_str(), __FUNCTION__, frame_number, strerror(-res), res); return res; } res = AddPendingFinalResultMetadataLocked(frame_number); if (res != OK) { - ALOGE("%s: Adding pending result metadata for frame %u failed: %s(%d)", - __FUNCTION__, frame_number, strerror(-res), res); + ALOGE("[%s] %s: Adding pending result metadata for frame %u failed: %s(%d)", + name_.c_str(), __FUNCTION__, frame_number, strerror(-res), res); return res; } for (auto& buffer : pending_request.input_buffers) { res = AddPendingBufferLocked(frame_number, buffer, /*is_input=*/true); if (res != OK) { - ALOGE("%s: Adding pending input buffer for frame %u failed: %s(%d)", - __FUNCTION__, frame_number, strerror(-res), res); + ALOGE("[%s] %s: Adding pending input buffer for frame %u failed: %s(%d)", + name_.c_str(), __FUNCTION__, frame_number, strerror(-res), res); return res; } } @@ -127,8 +134,8 @@ status_t ResultDispatcher::AddPendingRequestLocked( for (auto& buffer : pending_request.output_buffers) { res = AddPendingBufferLocked(frame_number, buffer, /*is_input=*/false); if (res != OK) { - ALOGE("%s: Adding pending output buffer for frame %u failed: %s(%d)", - __FUNCTION__, frame_number, strerror(-res), res); + ALOGE("[%s] %s: Adding pending output buffer for frame %u failed: %s(%d)", + name_.c_str(), __FUNCTION__, frame_number, strerror(-res), res); return res; } } @@ -139,8 +146,8 @@ status_t ResultDispatcher::AddPendingRequestLocked( status_t ResultDispatcher::AddPendingShutterLocked(uint32_t frame_number) { ATRACE_CALL(); if (pending_shutters_.find(frame_number) != pending_shutters_.end()) { - ALOGE("%s: Pending shutter for frame %u already exists.", __FUNCTION__, - frame_number); + ALOGE("[%s] %s: Pending shutter for frame %u already exists.", + name_.c_str(), __FUNCTION__, frame_number); return ALREADY_EXISTS; } @@ -153,8 +160,8 @@ status_t ResultDispatcher::AddPendingFinalResultMetadataLocked( ATRACE_CALL(); if (pending_final_metadata_.find(frame_number) != pending_final_metadata_.end()) { - ALOGE("%s: Pending final result metadata for frame %u already exists.", - __FUNCTION__, frame_number); + ALOGE("[%s] %s: Pending final result metadata for frame %u already exists.", + name_.c_str(), __FUNCTION__, frame_number); return ALREADY_EXISTS; } @@ -174,8 +181,8 @@ status_t ResultDispatcher::AddPendingBufferLocked(uint32_t frame_number, if (stream_pending_buffers_map_[stream_id].find(frame_number) != stream_pending_buffers_map_[stream_id].end()) { - ALOGE("%s: Pending buffer of stream %u for frame %u already exists.", - __FUNCTION__, stream_id, frame_number); + ALOGE("[%s] %s: Pending buffer of stream %u for frame %u already exists.", + name_.c_str(), __FUNCTION__, stream_id, frame_number); return ALREADY_EXISTS; } @@ -205,8 +212,8 @@ status_t ResultDispatcher::AddResult(std::unique_ptr<CaptureResult> result) { std::move(result->physical_metadata), result->partial_result); if (res != OK) { - ALOGE("%s: Adding result metadata failed: %s (%d)", __FUNCTION__, - strerror(-res), res); + ALOGE("[%s] %s: Adding result metadata failed: %s (%d)", name_.c_str(), + __FUNCTION__, strerror(-res), res); failed = true; } } @@ -214,8 +221,8 @@ status_t ResultDispatcher::AddResult(std::unique_ptr<CaptureResult> result) { for (auto& buffer : result->output_buffers) { res = AddBuffer(frame_number, buffer); if (res != OK) { - ALOGE("%s: Adding an output buffer failed: %s (%d)", __FUNCTION__, - strerror(-res), res); + ALOGE("[%s] %s: Adding an output buffer failed: %s (%d)", name_.c_str(), + __FUNCTION__, strerror(-res), res); failed = true; } } @@ -223,8 +230,8 @@ status_t ResultDispatcher::AddResult(std::unique_ptr<CaptureResult> result) { for (auto& buffer : result->input_buffers) { res = AddBuffer(frame_number, buffer); if (res != OK) { - ALOGE("%s: Adding an input buffer failed: %s (%d)", __FUNCTION__, - strerror(-res), res); + ALOGE("[%s] %s: Adding an input buffer failed: %s (%d)", name_.c_str(), + __FUNCTION__, strerror(-res), res); failed = true; } } @@ -245,17 +252,16 @@ status_t ResultDispatcher::AddShutter(uint32_t frame_number, auto shutter_it = pending_shutters_.find(frame_number); if (shutter_it == pending_shutters_.end()) { - ALOGE("%s: Cannot find the pending shutter for frame %u", __FUNCTION__, - frame_number); + ALOGE("[%s] %s: Cannot find the pending shutter for frame %u", + name_.c_str(), __FUNCTION__, frame_number); return NAME_NOT_FOUND; } if (shutter_it->second.ready) { - ALOGE("%s: Already received shutter (%" PRId64 - ") for frame %u. New " - "timestamp %" PRId64, - __FUNCTION__, shutter_it->second.timestamp_ns, frame_number, - timestamp_ns); + ALOGE("[%s] %s: Already received shutter (%" PRId64 + ") for frame %u. New timestamp %" PRId64, + name_.c_str(), __FUNCTION__, shutter_it->second.timestamp_ns, + frame_number, timestamp_ns); return ALREADY_EXISTS; } @@ -288,8 +294,8 @@ status_t ResultDispatcher::AddError(const ErrorMessage& error) { } NotifyMessage message = {.type = MessageType::kError, .message.error = error}; - ALOGV("%s: Notify error %u for frame %u stream %d", __FUNCTION__, - error.error_code, frame_number, error.error_stream_id); + ALOGV("[%s] %s: Notify error %u for frame %u stream %d", name_.c_str(), + __FUNCTION__, error.error_code, frame_number, error.error_stream_id); notify_(message); return OK; @@ -318,14 +324,14 @@ status_t ResultDispatcher::AddFinalResultMetadata( auto metadata_it = pending_final_metadata_.find(frame_number); if (metadata_it == pending_final_metadata_.end()) { - ALOGE("%s: Cannot find the pending result metadata for frame %u", - __FUNCTION__, frame_number); + ALOGE("[%s] %s: Cannot find the pending result metadata for frame %u", + name_.c_str(), __FUNCTION__, frame_number); return NAME_NOT_FOUND; } if (metadata_it->second.ready) { - ALOGE("%s: Already received final result metadata for frame %u.", - __FUNCTION__, frame_number); + ALOGE("[%s] %s: Already received final result metadata for frame %u.", + name_.c_str(), __FUNCTION__, frame_number); return ALREADY_EXISTS; } @@ -341,13 +347,15 @@ status_t ResultDispatcher::AddResultMetadata( uint32_t partial_result) { ATRACE_CALL(); if (metadata == nullptr) { - ALOGE("%s: metadata is nullptr.", __FUNCTION__); + ALOGE("[%s] %s: metadata is nullptr.", name_.c_str(), __FUNCTION__); return BAD_VALUE; } if (partial_result > kPartialResultCount) { - ALOGE("%s: partial_result %u cannot be larger than partial result count %u", - __FUNCTION__, partial_result, kPartialResultCount); + ALOGE( + "[%s] %s: partial_result %u cannot be larger than partial result count " + "%u", + name_.c_str(), __FUNCTION__, partial_result, kPartialResultCount); return BAD_VALUE; } @@ -370,21 +378,21 @@ status_t ResultDispatcher::AddBuffer(uint32_t frame_number, uint32_t stream_id = buffer.stream_id; auto pending_buffers_it = stream_pending_buffers_map_.find(stream_id); if (pending_buffers_it == stream_pending_buffers_map_.end()) { - ALOGE("%s: Cannot find the pending buffer for stream %u", __FUNCTION__, - stream_id); + ALOGE("[%s] %s: Cannot find the pending buffer for stream %u", + name_.c_str(), __FUNCTION__, stream_id); return NAME_NOT_FOUND; } auto pending_buffer_it = pending_buffers_it->second.find(frame_number); if (pending_buffer_it == pending_buffers_it->second.end()) { - ALOGE("%s: Cannot find the pending buffer for stream %u for frame %u", - __FUNCTION__, stream_id, frame_number); + ALOGE("[%s] %s: Cannot find the pending buffer for stream %u for frame %u", + name_.c_str(), __FUNCTION__, stream_id, frame_number); return NAME_NOT_FOUND; } if (pending_buffer_it->second.ready) { - ALOGE("%s: Already received a buffer for stream %u for frame %u", - __FUNCTION__, stream_id, frame_number); + ALOGE("[%s] %s: Already received a buffer for stream %u for frame %u", + name_.c_str(), __FUNCTION__, stream_id, frame_number); return ALREADY_EXISTS; } @@ -395,8 +403,11 @@ status_t ResultDispatcher::AddBuffer(uint32_t frame_number, } void ResultDispatcher::NotifyCallbackThreadLoop() { - // max thread name len = 16 - pthread_setname_np(pthread_self(), "ResDispatcher"); + // '\0' counts toward the 16-character restriction. + constexpr int kPthreadNameLenMinusOne = 16 - 1; + pthread_setname_np( + pthread_self(), + name_.substr(/*pos=*/0, /*count=*/kPthreadNameLenMinusOne).c_str()); while (1) { NotifyShutters(); @@ -405,7 +416,8 @@ void ResultDispatcher::NotifyCallbackThreadLoop() { std::unique_lock<std::mutex> lock(notify_callback_lock_); if (notify_callback_thread_exiting_) { - ALOGV("%s: NotifyCallbackThreadLoop exits.", __FUNCTION__); + ALOGV("[%s] %s: NotifyCallbackThreadLoop exits.", name_.c_str(), + __FUNCTION__); return; } if (!is_result_shutter_updated_) { @@ -422,19 +434,20 @@ void ResultDispatcher::NotifyCallbackThreadLoop() { void ResultDispatcher::PrintTimeoutMessages() { std::lock_guard<std::mutex> lock(result_lock_); for (auto& [frame_number, shutter] : pending_shutters_) { - ALOGW("%s: pending shutter for frame %u ready %d", __FUNCTION__, - frame_number, shutter.ready); + ALOGW("[%s] %s: pending shutter for frame %u ready %d", name_.c_str(), + __FUNCTION__, frame_number, shutter.ready); } for (auto& [frame_number, final_metadata] : pending_final_metadata_) { - ALOGW("%s: pending final result metadaata for frame %u ready %d", - __FUNCTION__, frame_number, final_metadata.ready); + ALOGW("[%s] %s: pending final result metadaata for frame %u ready %d", + name_.c_str(), __FUNCTION__, frame_number, final_metadata.ready); } for (auto& [stream_id, pending_buffers] : stream_pending_buffers_map_) { for (auto& [frame_number, pending_buffer] : pending_buffers) { - ALOGW("%s: pending buffer of stream %d for frame %u ready %d", - __FUNCTION__, stream_id, frame_number, pending_buffer.ready); + ALOGW("[%s] %s: pending buffer of stream %d for frame %u ready %d", + name_.c_str(), __FUNCTION__, stream_id, frame_number, + pending_buffer.ready); } } } @@ -442,7 +455,7 @@ void ResultDispatcher::PrintTimeoutMessages() { status_t ResultDispatcher::GetReadyShutterMessage(NotifyMessage* message) { ATRACE_CALL(); if (message == nullptr) { - ALOGE("%s: message is nullptr", __FUNCTION__); + ALOGE("[%s] %s: message is nullptr", name_.c_str(), __FUNCTION__); return BAD_VALUE; } @@ -470,9 +483,9 @@ void ResultDispatcher::NotifyShutters() { if (GetReadyShutterMessage(&message) != OK) { break; } - ALOGV("%s: Notify shutter for frame %u timestamp %" PRIu64 + ALOGV("[%s] %s: Notify shutter for frame %u timestamp %" PRIu64 " readout_timestamp %" PRIu64, - __FUNCTION__, message.message.shutter.frame_number, + name_.c_str(), __FUNCTION__, message.message.shutter.frame_number, message.message.shutter.timestamp_ns, message.message.shutter.readout_timestamp_ns); notify_(message); @@ -484,8 +497,8 @@ status_t ResultDispatcher::GetReadyFinalMetadata( std::vector<PhysicalCameraMetadata>* physical_metadata) { ATRACE_CALL(); if (final_metadata == nullptr || frame_number == nullptr) { - ALOGE("%s: final_metadata (%p) or frame_number (%p) is nullptr", - __FUNCTION__, final_metadata, frame_number); + ALOGE("[%s] %s: final_metadata (%p) or frame_number (%p) is nullptr", + name_.c_str(), __FUNCTION__, final_metadata, frame_number); return BAD_VALUE; } @@ -514,7 +527,8 @@ void ResultDispatcher::NotifyFinalResultMetadata() { while (GetReadyFinalMetadata(&frame_number, &final_metadata, &physical_metadata) == OK) { - ALOGV("%s: Notify final metadata for frame %u", __FUNCTION__, frame_number); + ALOGV("[%s] %s: Notify final metadata for frame %u", name_.c_str(), + __FUNCTION__, frame_number); NotifyResultMetadata(frame_number, std::move(final_metadata), std::move(physical_metadata), kPartialResultCount); } @@ -525,7 +539,7 @@ status_t ResultDispatcher::GetReadyBufferResult( ATRACE_CALL(); std::lock_guard<std::mutex> lock(result_lock_); if (result == nullptr) { - ALOGE("%s: result is nullptr.", __FUNCTION__); + ALOGE("[%s] %s: result is nullptr.", name_.c_str(), __FUNCTION__); return BAD_VALUE; } @@ -563,7 +577,7 @@ void ResultDispatcher::NotifyBuffers() { while (GetReadyBufferResult(&result) == OK) { if (result == nullptr) { - ALOGE("%s: result is nullptr", __FUNCTION__); + ALOGE("[%s] %s: result is nullptr", name_.c_str(), __FUNCTION__); return; } std::lock_guard<std::mutex> lock(process_capture_result_lock_); diff --git a/common/hal/utils/result_dispatcher.h b/common/hal/utils/result_dispatcher.h index 19e7c9e..d610249 100644 --- a/common/hal/utils/result_dispatcher.h +++ b/common/hal/utils/result_dispatcher.h @@ -18,6 +18,8 @@ #define HARDWARE_GOOGLE_CAMERA_HAL_UTILS_RESULT_DISPATCHER_H_ #include <map> +#include <string> +#include <string_view> #include <thread> #include "hal_types.h" @@ -40,7 +42,8 @@ class ResultDispatcher { // notify is the function to notify shutter messages. static std::unique_ptr<ResultDispatcher> Create( uint32_t partial_result_count, - ProcessCaptureResultFunc process_capture_result, NotifyFunc notify); + ProcessCaptureResultFunc process_capture_result, NotifyFunc notify, + std::string_view name = "ResultDispatcher"); virtual ~ResultDispatcher(); @@ -68,7 +71,8 @@ class ResultDispatcher { ResultDispatcher(uint32_t partial_result_count, ProcessCaptureResultFunc process_capture_result, - NotifyFunc notify); + NotifyFunc notify, + std::string_view name = "ResultDispatcher"); private: static constexpr uint32_t kCallbackThreadTimeoutMs = 500; @@ -160,6 +164,9 @@ class ResultDispatcher { void PrintTimeoutMessages(); + // Name used for debugging purpose to disambiguate multiple ResultDispatchers. + std::string name_; + std::mutex result_lock_; // Maps from frame numbers to pending shutters. diff --git a/common/hal/utils/zsl_result_dispatcher.cc b/common/hal/utils/zsl_result_dispatcher.cc index e74d803..6389041 100644 --- a/common/hal/utils/zsl_result_dispatcher.cc +++ b/common/hal/utils/zsl_result_dispatcher.cc @@ -63,17 +63,17 @@ status_t ZslResultDispatcher::Initialize(uint32_t partial_result_count) { notify_ = NotifyFunc( [this](const NotifyMessage& message) { NotifyHalMessage(message); }); - normal_result_dispatcher_ = - std::unique_ptr<ResultDispatcher>(new ResultDispatcher( - partial_result_count, process_capture_result_, notify_)); + normal_result_dispatcher_ = std::unique_ptr<ResultDispatcher>( + new ResultDispatcher(partial_result_count, process_capture_result_, + notify_, "ZslNormalDispatcher")); if (normal_result_dispatcher_ == nullptr) { ALOGE("%s: Creating normal_result_dispatcher_ failed.", __FUNCTION__); return BAD_VALUE; } - zsl_result_dispatcher_ = - std::unique_ptr<ResultDispatcher>(new ResultDispatcher( - partial_result_count, process_capture_result_, notify_)); + zsl_result_dispatcher_ = std::unique_ptr<ResultDispatcher>( + new ResultDispatcher(partial_result_count, process_capture_result_, + notify_, "ZslZslDispatcher")); if (zsl_result_dispatcher_ == nullptr) { ALOGE("%s: Creating zsl_result_dispatcher_ failed.", __FUNCTION__); return BAD_VALUE; |