summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-07-31 06:04:20 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-07-31 06:04:20 +0000
commit9e9a40e0cd82a47c124886e4f31436b0faad1e2d (patch)
tree72d1c590cb1e62f0f5283d89d1c2fc97f6d792cd
parent6c7dba227b49c0c2bb10a31a5c9a58d59c916724 (diff)
parent13eb6526f693fd27b27f3e86077af8e8691bd8cf (diff)
downloadcamera-9e9a40e0cd82a47c124886e4f31436b0faad1e2d.tar.gz
Merge "camera: Support stream configuration set to RT thread" into rvc-d1-dev
-rw-r--r--common/hal/google_camera_hal/camera_device_session.cc41
-rw-r--r--common/hal/utils/utils.cc24
-rw-r--r--common/hal/utils/utils.h2
3 files changed, 66 insertions, 1 deletions
diff --git a/common/hal/google_camera_hal/camera_device_session.cc b/common/hal/google_camera_hal/camera_device_session.cc
index 89d79c7..99b054d 100644
--- a/common/hal/google_camera_hal/camera_device_session.cc
+++ b/common/hal/google_camera_hal/camera_device_session.cc
@@ -579,6 +579,28 @@ status_t CameraDeviceSession::ConfigureStreams(
const StreamConfiguration& stream_config,
std::vector<HalStream>* hal_config) {
ATRACE_CALL();
+ bool set_realtime_thread = false;
+ int32_t schedule_policy;
+ struct sched_param schedule_param = {0};
+ if (utils::SupportRealtimeThread()) {
+ bool get_thread_schedule = false;
+ if (pthread_getschedparam(pthread_self(), &schedule_policy,
+ &schedule_param) == 0) {
+ get_thread_schedule = true;
+ } else {
+ ALOGE("%s: pthread_getschedparam fail", __FUNCTION__);
+ }
+
+ if (get_thread_schedule) {
+ status_t res = utils::SetRealtimeThread(pthread_self());
+ if (res != OK) {
+ ALOGE("%s: SetRealtimeThread fail", __FUNCTION__);
+ } else {
+ set_realtime_thread = true;
+ }
+ }
+ }
+
std::lock_guard<std::mutex> lock(session_lock_);
std::lock_guard lock_capture_session(capture_session_lock_);
@@ -629,6 +651,9 @@ status_t CameraDeviceSession::ConfigureStreams(
if (capture_session_ == nullptr) {
ALOGE("%s: Cannot find a capture session compatible with stream config",
__FUNCTION__);
+ if (set_realtime_thread) {
+ utils::UpdateThreadSched(pthread_self(), schedule_policy, &schedule_param);
+ }
return BAD_VALUE;
}
@@ -636,6 +661,10 @@ status_t CameraDeviceSession::ConfigureStreams(
stream_buffer_cache_manager_ = StreamBufferCacheManager::Create();
if (stream_buffer_cache_manager_ == nullptr) {
ALOGE("%s: Failed to create stream buffer cache manager.", __FUNCTION__);
+ if (set_realtime_thread) {
+ utils::UpdateThreadSched(pthread_self(), schedule_policy,
+ &schedule_param);
+ }
return UNKNOWN_ERROR;
}
@@ -644,6 +673,10 @@ status_t CameraDeviceSession::ConfigureStreams(
if (res != OK) {
ALOGE("%s: Failed to register streams into stream buffer cache manager.",
__FUNCTION__);
+ if (set_realtime_thread) {
+ utils::UpdateThreadSched(pthread_self(), schedule_policy,
+ &schedule_param);
+ }
return res;
}
}
@@ -664,6 +697,10 @@ status_t CameraDeviceSession::ConfigureStreams(
pending_requests_tracker_ = PendingRequestsTracker::Create(*hal_config);
if (pending_requests_tracker_ == nullptr) {
ALOGE("%s: Cannot create a pending request tracker.", __FUNCTION__);
+ if (set_realtime_thread) {
+ utils::UpdateThreadSched(pthread_self(), schedule_policy,
+ &schedule_param);
+ }
return UNKNOWN_ERROR;
}
@@ -682,6 +719,10 @@ status_t CameraDeviceSession::ConfigureStreams(
last_request_settings_ = nullptr;
last_timestamp_ns_for_trace_ = 0;
+ if (set_realtime_thread) {
+ utils::UpdateThreadSched(pthread_self(), schedule_policy, &schedule_param);
+ }
+
return OK;
}
diff --git a/common/hal/utils/utils.cc b/common/hal/utils/utils.cc
index f2ad310..24d0063 100644
--- a/common/hal/utils/utils.cc
+++ b/common/hal/utils/utils.cc
@@ -384,7 +384,14 @@ void ConvertZoomRatio(const float zoom_ratio,
}
bool SupportRealtimeThread() {
- return property_get_bool(kRealtimeThreadSetProp.c_str(), false);
+ static bool support_real_time = false;
+ static bool first_time = false;
+ if (first_time == false) {
+ first_time = true;
+ support_real_time = property_get_bool(kRealtimeThreadSetProp.c_str(), false);
+ }
+
+ return support_real_time;
}
status_t SetRealtimeThread(pthread_t thread) {
@@ -401,6 +408,21 @@ status_t SetRealtimeThread(pthread_t thread) {
return OK;
}
+status_t UpdateThreadSched(pthread_t thread, int32_t policy,
+ struct sched_param* param) {
+ if (param == nullptr) {
+ ALOGE("%s: sched_param is nullptr", __FUNCTION__);
+ return BAD_VALUE;
+ }
+ int32_t res = pthread_setschedparam(thread, policy, param);
+ if (res != 0) {
+ ALOGE("%s: Couldn't set schedparam", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
+
} // namespace utils
} // namespace google_camera_hal
} // namespace android
diff --git a/common/hal/utils/utils.h b/common/hal/utils/utils.h
index ce95d66..f79773f 100644
--- a/common/hal/utils/utils.h
+++ b/common/hal/utils/utils.h
@@ -68,6 +68,8 @@ bool IsSessionParameterCompatible(const HalCameraMetadata* old_session,
bool SupportRealtimeThread();
status_t SetRealtimeThread(pthread_t thread);
+status_t UpdateThreadSched(pthread_t thread, int32_t policy,
+ struct sched_param* param);
// Map the rectangle to the coordination of HAL.
void ConvertZoomRatio(float zoom_ratio, const Dimension& active_array_dimension,