• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define MLOG_TAG "DeferredPhotoProcessingAdapter"
17 
18 #include "deferred_photo_proc_adapter.h"
19 
20 #ifdef ABILITY_CAMERA_SUPPORT
21 #include "camera_manager.h"
22 #endif
23 #include "ipc_skeleton.h"
24 #include "media_log.h"
25 
26 using namespace std;
27 #ifdef ABILITY_CAMERA_SUPPORT
28 using namespace OHOS::CameraStandard;
29 #endif
30 
31 namespace OHOS {
32 namespace Media {
33 
DeferredPhotoProcessingAdapter()34 DeferredPhotoProcessingAdapter::DeferredPhotoProcessingAdapter()
35 {
36 #ifdef ABILITY_CAMERA_SUPPORT
37     const static int32_t INVALID_UID = -1;
38     const static int32_t BASE_USER_RANGE = 200000;
39 
40     int uid = IPCSkeleton::GetCallingUid();
41     CHECK_AND_RETURN_LOG(uid > INVALID_UID, "DeferredPhotoProcessingAdapter invalid uid: %{public}d", uid);
42 
43     int32_t userId = uid / BASE_USER_RANGE;
44     photoProcCallback_ = make_shared<MultiStagesCaptureDeferredPhotoProcSessionCallback>();
45     CHECK_AND_RETURN_LOG(photoProcCallback_ != nullptr, "make PhotoProcSessionCallback fail");
46     deferredPhotoProcSession_ = CameraManager::CreateDeferredPhotoProcessingSession(userId, photoProcCallback_);
47     CHECK_AND_PRINT_LOG(deferredPhotoProcSession_ != nullptr, "CreateDeferredPhotoProcessingSession err");
48 #endif
49     MEDIA_INFO_LOG("DeferredPhotoProcessingAdapter init succ");
50 }
51 
~DeferredPhotoProcessingAdapter()52 DeferredPhotoProcessingAdapter::~DeferredPhotoProcessingAdapter() {}
53 
BeginSynchronize()54 void DeferredPhotoProcessingAdapter::BeginSynchronize()
55 {
56     MEDIA_INFO_LOG("DeferredPhotoProcessingAdapter::BeginSynchronize");
57 #ifdef ABILITY_CAMERA_SUPPORT
58     if (deferredPhotoProcSession_ == nullptr) {
59         MEDIA_ERR_LOG("BeginSynchronize deferredPhotoProcSession_ is nullptr");
60         return;
61     }
62     deferredPhotoProcSession_->BeginSynchronize();
63 #endif
64 }
65 
EndSynchronize()66 void DeferredPhotoProcessingAdapter::EndSynchronize()
67 {
68     MEDIA_INFO_LOG("DeferredPhotoProcessingAdapter::EndSynchronize");
69 #ifdef ABILITY_CAMERA_SUPPORT
70     if (deferredPhotoProcSession_ == nullptr) {
71         MEDIA_ERR_LOG("EndSynchronize deferredPhotoProcSession_ is nullptr");
72         return;
73     }
74     deferredPhotoProcSession_->EndSynchronize();
75 #endif
76 }
77 
78 #ifdef ABILITY_CAMERA_SUPPORT
AddImage(const std::string & imageId,DpsMetadata & metadata,const bool isTrashed)79 void DeferredPhotoProcessingAdapter::AddImage(const std::string &imageId, DpsMetadata &metadata, const bool isTrashed)
80 {
81     MEDIA_INFO_LOG("enter photoid: %{public}s, isTrashed: %{public}d", imageId.c_str(), isTrashed);
82     CHECK_AND_RETURN_LOG(deferredPhotoProcSession_ != nullptr, "AddImage deferredPhotoProcSession_ is nullptr");
83     deferredPhotoProcSession_->AddImage(imageId, metadata, isTrashed);
84 }
85 #endif
86 
RemoveImage(const std::string & imageId,bool isRestorable)87 void DeferredPhotoProcessingAdapter::RemoveImage(const std::string &imageId, bool isRestorable)
88 {
89     MEDIA_INFO_LOG("enter photoid: %{public}s, isRestorable: %{public}d", imageId.c_str(), isRestorable);
90 #ifdef ABILITY_CAMERA_SUPPORT
91     CHECK_AND_RETURN_LOG(deferredPhotoProcSession_ != nullptr, "RemoveImage deferredPhotoProcSession_ is nullptr");
92     deferredPhotoProcSession_->RemoveImage(imageId, isRestorable);
93 #endif
94 }
95 
RestoreImage(const std::string & imageId)96 void DeferredPhotoProcessingAdapter::RestoreImage(const std::string &imageId)
97 {
98     MEDIA_INFO_LOG("enter photoid: %{public}s", imageId.c_str());
99 #ifdef ABILITY_CAMERA_SUPPORT
100     if (deferredPhotoProcSession_ == nullptr) {
101         MEDIA_ERR_LOG("RestoreImage deferredPhotoProcSession_ is nullptr");
102         return;
103     }
104     deferredPhotoProcSession_->RestoreImage(imageId);
105 #endif
106 }
107 
ProcessImage(const std::string & appName,const std::string & imageId)108 void DeferredPhotoProcessingAdapter::ProcessImage(const std::string &appName, const std::string &imageId)
109 {
110     MEDIA_INFO_LOG("enter appName: %{public}s, photoid: %{public}s", appName.c_str(), imageId.c_str());
111 #ifdef ABILITY_CAMERA_SUPPORT
112     if (deferredPhotoProcSession_ == nullptr) {
113         MEDIA_ERR_LOG("ProcessImage deferredPhotoProcSession_ is nullptr");
114         return;
115     }
116     deferredPhotoProcSession_->ProcessImage(appName, imageId);
117 #endif
118 }
119 
CancelProcessImage(const std::string & imageId)120 bool DeferredPhotoProcessingAdapter::CancelProcessImage(const std::string &imageId)
121 {
122     MEDIA_INFO_LOG("DeferredPhotoProcessingAdapter::CancelProcessImage photoid: %{public}s", imageId.c_str());
123 #ifdef ABILITY_CAMERA_SUPPORT
124     if (deferredPhotoProcSession_ == nullptr) {
125         MEDIA_ERR_LOG("CancelProcessImage deferredPhotoProcSession_ is nullptr");
126         return false;
127     }
128     return deferredPhotoProcSession_->CancelProcessImage(imageId);
129 #else
130     return false;
131 #endif
132 }
133 
134 #ifdef ABILITY_CAMERA_SUPPORT
SetProcessImageDoneCallback(const ProcessDoneHandler & func)135 void DeferredPhotoProcessingAdapter::SetProcessImageDoneCallback(const ProcessDoneHandler &func)
136 {
137     photoProcCallback_->SetProcessImageDoneCallback(func);
138 }
139 #endif
140 } // namespace Media
141 } // namespace OHOS