已合并
修复6.1 #4580
lu-daochun创建于 5月18日
修复6.1 #4580
已合并
从已删除 :OpenHarmony-6.1-Release合入到openharmony/multimedia_camera_frameworkOpenHarmony-6.1-Release
共 2 个文件变更+11-4
| @@ -350,7 +350,7 @@ private: | |||
| 350 | std::shared_ptr<DisablePolicyChangeCb> policyCallbackPtr_; | 350 | std::shared_ptr<DisablePolicyChangeCb> policyCallbackPtr_; |
| 351 | std::string GetACameraId(); | 351 | std::string GetACameraId(); |
| 352 | bool IsAllowOpen(pid_t activeClient); | 352 | bool IsAllowOpen(pid_t activeClient); |
| 353 | - int32_t GetCurrentCost() const; | 353 | + int32_t GetCurrentCost(); |
| 354 | std::vector<sptr<HCameraDeviceHolder>> WouldEvict(sptr<HCameraDeviceHolder> &cameraRequestOpen); | 354 | std::vector<sptr<HCameraDeviceHolder>> WouldEvict(sptr<HCameraDeviceHolder> &cameraRequestOpen); |
| 355 | void GenerateEachProcessCameraState(int32_t& processState, uint32_t processTokenId); | 355 | void GenerateEachProcessCameraState(int32_t& processState, uint32_t processTokenId); |
| 356 | void PrintClientInfo(sptr<HCameraDeviceHolder> activeCameraHolder, sptr<HCameraDeviceHolder> requestCameraHolder); | 356 | void PrintClientInfo(sptr<HCameraDeviceHolder> activeCameraHolder, sptr<HCameraDeviceHolder> requestCameraHolder); |
| @@ -65,6 +65,7 @@ sptr<HCameraDeviceManager> &HCameraDeviceManager::GetInstance() | |||
| 65 | 65 | ||
| 66 | size_t HCameraDeviceManager::GetActiveCamerasCount() | 66 | size_t HCameraDeviceManager::GetActiveCamerasCount() |
| 67 | { | 67 | { |
| 68 | + std::lock_guard<std::mutex> lock(mapMutex_); | ||
| 68 | MEDIA_INFO_LOG("HCameraDeviceManager::GetActiveCamerasCount: %{public}zu", activeCameras_.size()); | 69 | MEDIA_INFO_LOG("HCameraDeviceManager::GetActiveCamerasCount: %{public}zu", activeCameras_.size()); |
| 69 | return activeCameras_.size(); | 70 | return activeCameras_.size(); |
| 70 | } | 71 | } |
| @@ -334,8 +335,11 @@ bool HCameraDeviceManager::HandleCameraEvictions(std::vector<sptr<HCameraDeviceH | |||
| 334 | 335 | ||
| 335 | RefreshCameraDeviceHolderState(cameraRequestOpen); | 336 | RefreshCameraDeviceHolderState(cameraRequestOpen); |
| 336 | MEDIA_INFO_LOG("focusStateOfRequestProcess = %{public}d", cameraRequestOpen->GetFocusState()); | 337 | MEDIA_INFO_LOG("focusStateOfRequestProcess = %{public}d", cameraRequestOpen->GetFocusState()); |
| 337 | - for (const auto &deviceHolder : activeCameras_) { | 338 | + { |
| 338 | - RefreshCameraDeviceHolderState(deviceHolder); | 339 | + std::lock_guard<std::mutex> lock(mapMutex_); |
| 340 | + for (const auto &deviceHolder : activeCameras_) { | ||
| 341 | + RefreshCameraDeviceHolderState(deviceHolder); | ||
| 342 | + } | ||
| 339 | } | 343 | } |
| 340 | 344 | ||
| 341 | // Find Camera Device that would be evicted | 345 | // Find Camera Device that would be evicted |
| @@ -371,6 +375,7 @@ std::vector<sptr<HCameraDeviceHolder>> HCameraDeviceManager::WouldEvict(sptr<HCa | |||
| 371 | // Determine the MRU of the owners tied for having the highest priority | 375 | // Determine the MRU of the owners tied for having the highest priority |
| 372 | int32_t highestPriorityOwner = owner; | 376 | int32_t highestPriorityOwner = owner; |
| 373 | sptr<CameraProcessPriority> highestPriority = requestPriority; | 377 | sptr<CameraProcessPriority> highestPriority = requestPriority; |
| 378 | + std::lock_guard<std::mutex> lock(mapMutex_); | ||
| 374 | for (const auto &x : activeCameras_) { | 379 | for (const auto &x : activeCameras_) { |
| 375 | sptr<CameraProcessPriority> curPriority = x->GetPriority(); | 380 | sptr<CameraProcessPriority> curPriority = x->GetPriority(); |
| 376 | if (*curPriority > *highestPriority) { | 381 | if (*curPriority > *highestPriority) { |
| @@ -422,8 +427,9 @@ std::vector<sptr<HCameraDeviceHolder>> HCameraDeviceManager::WouldEvict(sptr<HCa | |||
| 422 | return evictList; | 427 | return evictList; |
| 423 | } | 428 | } |
| 424 | 429 | ||
| 425 | -int32_t HCameraDeviceManager::GetCurrentCost() const | 430 | +int32_t HCameraDeviceManager::GetCurrentCost() |
| 426 | { | 431 | { |
| 432 | + std::lock_guard<std::mutex> lock(mapMutex_); | ||
| 427 | int32_t totalCost = 0; | 433 | int32_t totalCost = 0; |
| 428 | for (const auto &x : activeCameras_) { | 434 | for (const auto &x : activeCameras_) { |
| 429 | totalCost += x->GetCost(); | 435 | totalCost += x->GetCost(); |
| @@ -620,6 +626,7 @@ void CameraConcurrentSelector::SetRequestCameraId(sptr<HCameraDeviceHolder> requ | |||
| 620 | 626 | ||
| 621 | std::vector<sptr<HCameraDeviceHolder>> HCameraDeviceManager::SortDeviceByPriority() | 627 | std::vector<sptr<HCameraDeviceHolder>> HCameraDeviceManager::SortDeviceByPriority() |
| 622 | { | 628 | { |
| 629 | + std::lock_guard<std::mutex> lock(mapMutex_); | ||
| 623 | std::vector<sptr<HCameraDeviceHolder>> sortedList = activeCameras_; | 630 | std::vector<sptr<HCameraDeviceHolder>> sortedList = activeCameras_; |
| 624 | std::sort(sortedList.begin(), sortedList.end(), | 631 | std::sort(sortedList.begin(), sortedList.end(), |
| 625 | [](const sptr<HCameraDeviceHolder> &a, const sptr<HCameraDeviceHolder> &b) { | 632 | [](const sptr<HCameraDeviceHolder> &a, const sptr<HCameraDeviceHolder> &b) { |