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_DEFERRED_VIDEO_PROCESSING_SESSION_H
17 #define OHOS_CAMERA_DPS_DEFERRED_VIDEO_PROCESSING_SESSION_H
18 
19 #include "deferred_video_processing_session_stub.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
23 namespace DeferredProcessing {
24 class DeferredVideoProcessingSession : public DeferredVideoProcessingSessionStub {
25 public:
26     class VideoInfo {
27     public:
VideoInfo(const sptr<IPCFileDescriptor> & srcFd,const sptr<IPCFileDescriptor> & dstFd)28         VideoInfo(const sptr<IPCFileDescriptor>& srcFd, const sptr<IPCFileDescriptor>& dstFd)
29             : srcFd_(srcFd), dstFd_(dstFd)
30         {}
31 
~VideoInfo()32         ~VideoInfo()
33         {
34             srcFd_ = nullptr;
35             dstFd_ = nullptr;
36         }
37 
38         sptr<IPCFileDescriptor> srcFd_;
39         sptr<IPCFileDescriptor> dstFd_;
40     };
41 
42     DeferredVideoProcessingSession(const int32_t userId);
43     ~DeferredVideoProcessingSession();
44 
45     int32_t BeginSynchronize() override;
46     int32_t EndSynchronize() override;
47     int32_t AddVideo(const std::string& videoId, const sptr<IPCFileDescriptor>& srcFd,
48         const sptr<IPCFileDescriptor>& dstFd) override;
49     int32_t RemoveVideo(const std::string& videoId, bool restorable) override;
50     int32_t RestoreVideo(const std::string& videoId) override;
51 
52 private:
53     std::mutex mutex_;
54     const int32_t userId_;
55     std::atomic<bool> inSync_ {false};
56     std::unordered_map<std::string, std::shared_ptr<VideoInfo>> videoIds_ {};
57 };
58 } // namespace DeferredProcessing
59 } // namespace CameraStandard
60 } // namespace OHOS
61 #endif // OHOS_CAMERA_DPS_DEFERRED_VIDEO_PROCESSING_SESSION_H