• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 #include "deferred_processing_service.h"
17 
18 #include "events_info.h"
19 #include "events_monitor.h"
20 #include "dp_log.h"
21 #include "dps.h"
22 #include "picture_interface.h"
23 
24 namespace OHOS {
25 namespace CameraStandard {
26 namespace DeferredProcessing {
DeferredProcessingService()27 DeferredProcessingService::DeferredProcessingService()
28 {
29     DP_DEBUG_LOG("entered.");
30 }
31 
~DeferredProcessingService()32 DeferredProcessingService::~DeferredProcessingService()
33 {
34     DP_INFO_LOG("entered.");
35     DPS_Destroy();
36 }
37 
Initialize()38 void DeferredProcessingService::Initialize()
39 {
40     DP_DEBUG_LOG("entered.");
41     EventsMonitor::GetInstance().Initialize();
42     auto ret = DPS_Initialize();
43     DP_CHECK_ERROR_RETURN_LOG(ret != DP_OK, "DeferredProcessingService init failed, ret: %{public}d", ret);
44     initialized_.store(true);
45 }
46 
NotifyLowQualityImage(const int32_t userId,const std::string & imageId,std::shared_ptr<PictureIntf> picture)47 void DeferredProcessingService::NotifyLowQualityImage(const int32_t userId, const std::string& imageId,
48     std::shared_ptr<PictureIntf> picture)
49 {
50     DP_CHECK_RETURN(!initialized_.load());
51 
52     auto sessionManager = DPS_GetSessionManager();
53     DP_CHECK_ERROR_RETURN_LOG(sessionManager == nullptr, "SessionManager is nullptr, userId: %{public}d", userId);
54 
55     if (auto callback = sessionManager->GetCallback(userId)) {
56         callback->OnDeliveryLowQualityImage(imageId, picture);
57         return;
58     }
59     DP_ERR_LOG("DeferredPhotoProcessingSessionCallback::NotifyLowQualityImage not set!, Discarding callback");
60 }
61 
CreateDeferredPhotoProcessingSession(const int32_t userId,const sptr<IDeferredPhotoProcessingSessionCallback> & callback)62 sptr<IDeferredPhotoProcessingSession> DeferredProcessingService::CreateDeferredPhotoProcessingSession(
63     const int32_t userId, const sptr<IDeferredPhotoProcessingSessionCallback>& callback)
64 {
65     DP_CHECK_RETURN_RET(!initialized_.load(), nullptr);
66 
67     DP_INFO_LOG("Create photo session for userId: %{public}d", userId);
68     auto sessionManager = DPS_GetSessionManager();
69     DP_CHECK_ERROR_RETURN_RET_LOG(sessionManager == nullptr, nullptr,
70         "SessionManager is nullptr, userId: %{public}d", userId);
71     return sessionManager->CreateDeferredPhotoProcessingSession(userId, callback);
72 }
73 
CreateDeferredVideoProcessingSession(const int32_t userId,const sptr<IDeferredVideoProcessingSessionCallback> & callbacks)74 sptr<IDeferredVideoProcessingSession> DeferredProcessingService::CreateDeferredVideoProcessingSession(
75     const int32_t userId, const sptr<IDeferredVideoProcessingSessionCallback>& callbacks)
76 {
77     DP_CHECK_RETURN_RET(!initialized_.load(), nullptr);
78 
79     DP_INFO_LOG("Create video session for userId: %{public}d", userId);
80     auto sessionManager = DPS_GetSessionManager();
81     DP_CHECK_ERROR_RETURN_RET_LOG(sessionManager == nullptr, nullptr,
82         "SessionManager is null, userId: %{public}d", userId);
83     return sessionManager->CreateDeferredVideoProcessingSession(userId, callbacks);
84 }
85 } // namespace DeferredProcessing
86 } // namespace CameraStandard
87 } // namespace OHOS