已合并
修复6.0 #4579
lu-daochun创建于 5月18日
修复6.0 #4579
已合并
lu-daochun创建于 5月18日
已删除 :OpenHarmony-6.0-Release合入到openharmony/multimedia_camera_frameworkOpenHarmony-6.0-Release
2 个文件变更+12-4
@@ -333,7 +333,7 @@ private:
333 sptr<CameraConcurrentSelector> concurrentSelector_;333 sptr<CameraConcurrentSelector> concurrentSelector_;
334 std::string GetACameraId();334 std::string GetACameraId();
335 bool IsAllowOpen(pid_t activeClient);335 bool IsAllowOpen(pid_t activeClient);
336- int32_t GetCurrentCost() const;336+ int32_t GetCurrentCost();
337 void DetermineHighestPriorityOwner(int32_t &highestPriorityOwner, int32_t &owner,337 void DetermineHighestPriorityOwner(int32_t &highestPriorityOwner, int32_t &owner,
338 sptr<CameraProcessPriority> requestPriority);338 sptr<CameraProcessPriority> requestPriority);
339 std::vector<sptr<HCameraDeviceHolder>> WouldEvict(sptr<HCameraDeviceHolder> &cameraRequestOpen);339 std::vector<sptr<HCameraDeviceHolder>> WouldEvict(sptr<HCameraDeviceHolder> &cameraRequestOpen);
@@ -63,6 +63,7 @@ sptr<HCameraDeviceManager> &HCameraDeviceManager::GetInstance()
63 63 
64size_t HCameraDeviceManager::GetActiveCamerasCount()64size_t HCameraDeviceManager::GetActiveCamerasCount()
65{65{
66+ std::lock_guard<std::mutex> lock(mapMutex_);
66 MEDIA_INFO_LOG("HCameraDeviceManager::GetActiveCamerasCount: %{public}zu", activeCameras_.size());67 MEDIA_INFO_LOG("HCameraDeviceManager::GetActiveCamerasCount: %{public}zu", activeCameras_.size());
67 return activeCameras_.size();68 return activeCameras_.size();
68}69}
@@ -360,8 +361,11 @@ bool HCameraDeviceManager::HandleCameraEvictions(std::vector<sptr<HCameraDeviceH
360 361 
361 RefreshCameraDeviceHolderState(cameraRequestOpen);362 RefreshCameraDeviceHolderState(cameraRequestOpen);
362 MEDIA_INFO_LOG("focusStateOfRequestProcess = %{public}d", cameraRequestOpen->GetFocusState());363 MEDIA_INFO_LOG("focusStateOfRequestProcess = %{public}d", cameraRequestOpen->GetFocusState());
363- for (const auto &deviceHolder : activeCameras_) {364+ {
364- RefreshCameraDeviceHolderState(deviceHolder);365+ std::lock_guard<std::mutex> lock(mapMutex_);
366+ for (const auto &deviceHolder : activeCameras_) {
367+ RefreshCameraDeviceHolderState(deviceHolder);
368+ }
365 }369 }
366 370 
367 // Find Camera Device that would be evicted371 // Find Camera Device that would be evicted
@@ -389,6 +393,7 @@ bool HCameraDeviceManager::HandleCameraEvictions(std::vector<sptr<HCameraDeviceH
389void HCameraDeviceManager::DetermineHighestPriorityOwner(int32_t &highestPriorityOwner, int32_t &owner,393void HCameraDeviceManager::DetermineHighestPriorityOwner(int32_t &highestPriorityOwner, int32_t &owner,
390 sptr<CameraProcessPriority> requestPriority)394 sptr<CameraProcessPriority> requestPriority)
391{395{
396+ std::lock_guard<std::mutex> lock(mapMutex_);
392 sptr<CameraProcessPriority> highestPriority = requestPriority;397 sptr<CameraProcessPriority> highestPriority = requestPriority;
393 for (const auto &x : activeCameras_) {398 for (const auto &x : activeCameras_) {
394 sptr<CameraProcessPriority> curPriority = x->GetPriority();399 sptr<CameraProcessPriority> curPriority = x->GetPriority();
@@ -419,6 +424,7 @@ std::vector<sptr<HCameraDeviceHolder>> HCameraDeviceManager::WouldEvict(sptr<HCa
419 DetermineHighestPriorityOwner(highestPriorityOwner, owner, requestPriority);424 DetermineHighestPriorityOwner(highestPriorityOwner, owner, requestPriority);
420 425 
421 // Build eviction list of clients to remove426 // Build eviction list of clients to remove
427+ std::lock_guard<std::mutex> lock(mapMutex_);
422 for (const auto &x : activeCameras_) {428 for (const auto &x : activeCameras_) {
423 const std::string &curCameraId = x->GetDevice()->GetCameraId();429 const std::string &curCameraId = x->GetDevice()->GetCameraId();
424 int32_t curCost = x->GetCost();430 int32_t curCost = x->GetCost();
@@ -459,8 +465,9 @@ std::vector<sptr<HCameraDeviceHolder>> HCameraDeviceManager::WouldEvict(sptr<HCa
459 return evictList;465 return evictList;
460}466}
461 467 
462-int32_t HCameraDeviceManager::GetCurrentCost() const468+int32_t HCameraDeviceManager::GetCurrentCost()
463{469{
470+ std::lock_guard<std::mutex> lock(mapMutex_);
464 int32_t totalCost = 0;471 int32_t totalCost = 0;
465 for (const auto &x : activeCameras_) {472 for (const auto &x : activeCameras_) {
466 totalCost += x->GetCost();473 totalCost += x->GetCost();
@@ -582,6 +589,7 @@ void CameraConcurrentSelector::SetRequestCameraId(sptr<HCameraDeviceHolder> requ
582 589 
583std::vector<sptr<HCameraDeviceHolder>> HCameraDeviceManager::SortDeviceByPriority()590std::vector<sptr<HCameraDeviceHolder>> HCameraDeviceManager::SortDeviceByPriority()
584{591{
592+ std::lock_guard<std::mutex> lock(mapMutex_);
585 std::vector<sptr<HCameraDeviceHolder>> sortedList = activeCameras_;593 std::vector<sptr<HCameraDeviceHolder>> sortedList = activeCameras_;
586 std::sort(sortedList.begin(), sortedList.end(),594 std::sort(sortedList.begin(), sortedList.end(),
587 [](const sptr<HCameraDeviceHolder> &a, const sptr<HCameraDeviceHolder> &b) {595 [](const sptr<HCameraDeviceHolder> &a, const sptr<HCameraDeviceHolder> &b) {