• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 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 #ifndef OHOS_CAMERA_DPS_SCHEDULE_CONTROLLER_H
17 #define OHOS_CAMERA_DPS_SCHEDULE_CONTROLLER_H
18 
19 #include "set"
20 
21 #include "photo_job_repository.h"
22 #include "photo_post_processor.h"
23 
24 namespace OHOS {
25 namespace CameraStandard {
26 namespace DeferredProcessing {
27 class DeferredPhotoProcessor : public IImageProcessCallbacks,
28     public std::enable_shared_from_this<IImageProcessCallbacks> {
29 public:
30     ~DeferredPhotoProcessor();
31     void Initialize();
32 
33     void AddImage(const std::string& imageId, bool discardable, DpsMetadata& metadata);
34     void RemoveImage(const std::string& imageId, bool restorable);
35     void RestoreImage(const std::string& imageId);
36     void ProcessImage(const std::string& appName, const std::string& imageId);
37     void CancelProcessImage(const std::string& imageId);
38     void OnProcessDone(const int32_t userId, const std::string& imageId,
39         const std::shared_ptr<BufferInfo>& bufferInfo) override;
40     void OnProcessDoneExt(int userId, const std::string& imageId,
41         const std::shared_ptr<BufferInfoExt>& bufferInfo) override;
42     void OnError(const int32_t userId, const std::string& imageId, DpsError errorCode) override;
43     void OnStateChanged(const int32_t userId, DpsStatus statusCode) override;
44     void NotifyScheduleState(DpsStatus status);
45     void PostProcess(const DeferredPhotoWorkPtr& work);
46     void SetDefaultExecutionMode();
47     void Interrupt();
48     int32_t GetConcurrency(ExecutionMode mode);
49     bool GetPendingImages(std::vector<std::string>& pendingImages);
50 
51 protected:
52     DeferredPhotoProcessor(const int32_t userId, const std::shared_ptr<PhotoJobRepository>& repository,
53         const std::shared_ptr<PhotoPostProcessor>& postProcessor,
54         const std::weak_ptr<IImageProcessCallbacks>& callback);
55 
56 private:
57     bool IsFatalError(DpsError errorCode);
58 
59     const int32_t userId_;
60     std::shared_ptr<PhotoJobRepository> repository_;
61     std::shared_ptr<PhotoPostProcessor> postProcessor_;
62     std::weak_ptr<IImageProcessCallbacks> callback_;
63     std::set<std::string> requestedImages_ {};
64     std::string postedImageId_;
65 };
66 } // namespace DeferredProcessing
67 } // namespace CameraStandard
68 } // namespace OHOS
69 #endif // OHOS_CAMERA_DPS_SCHEDULE_CONTROLLER_H