• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 #ifndef OHOS_CAMERA_DPS_VIDEO_POST_PROCESSOR_H
17 #define OHOS_CAMERA_DPS_VIDEO_POST_PROCESSOR_H
18 
19 #include "basic_definitions.h"
20 #include "deferred_video_job.h"
21 #include "iservstat_listener_hdi.h"
22 #include "ivideo_process_callbacks.h"
23 #include "media_manager_proxy.h"
24 #include "v1_4/ivideo_process_service.h"
25 #include "v1_4/ivideo_process_callback.h"
26 #include "video_process_result.h"
27 
28 namespace OHOS {
29 namespace CameraStandard {
30 namespace DeferredProcessing {
31 using OHOS::HDI::Camera::V1_3::IVideoProcessSession;
32 using OHOS::HDI::Camera::V1_3::StreamDescription;
33 using OHOS::HDI::Camera::V1_1::StreamInfo_V1_1;
34 using HDI::Camera::V1_0::BufferProducerSequenceable;
35 
36 class VideoPostProcessor : public std::enable_shared_from_this<VideoPostProcessor> {
37 public:
38     ~VideoPostProcessor();
39 
40     void Initialize();
41     bool GetPendingVideos(std::vector<std::string>& pendingVideos);
42     void SetExecutionMode(ExecutionMode executionMode);
43     void SetDefaultExecutionMode();
44     void ProcessRequest(const DeferredVideoWorkPtr& work);
45     void RemoveRequest(const std::string& videoId);
46     void PauseRequest(const std::string& videoId, const SchedulerType& type);
47     DeferredVideoWorkPtr GetRunningWork(const std::string& videoId);
48     void OnProcessDone(const std::string& videoId, std::unique_ptr<MediaUserInfo> userInfo);
49     void OnError(const std::string& videoId, DpsError errorCode);
50     void OnStateChanged(HdiStatus hdiStatus);
51     void OnSessionDied();
52 
53 protected:
54     explicit VideoPostProcessor(const int32_t userId);
55 
56 private:
57     class VideoServiceListener;
58     class SessionDeathRecipient;
59     class VideoProcessListener;
60 
61     void ConnectService();
62     void DisconnectService();
63     DpsError PrepareStreams(const std::string& videoId, const int inputFd);
64     bool ProcessStream(const StreamDescription& stream);
65     void ReleaseStreams();
66     void SetStreamInfo(const StreamDescription& stream, sptr<BufferProducerSequenceable>& producer);
67     HDI::Camera::V1_0::StreamIntent GetIntent(HDI::Camera::V1_3::MediaStreamType type);
68     bool StartMpeg(const std::string& videoId, const sptr<IPCFileDescriptor>& inputFd);
69     bool StopMpeg(const MediaResult result, const DeferredVideoWorkPtr& work);
70     void ReleaseMpeg();
71     void StartTimer(const std::string& videoId, const DeferredVideoWorkPtr& work);
72     void StopTimer(const DeferredVideoWorkPtr& work);
73     void OnTimerOut(const std::string& videoId);
74     void OnServiceChange(const HDI::ServiceManager::V1_0::ServiceStatus& status);
75     void copyFileByFd(const int srcFd, const int dstFd);
76     DpsError MapHdiError(OHOS::HDI::Camera::V1_2::ErrorCode errorCode);
77 
GetVideoSession()78     inline sptr<IVideoProcessSession> GetVideoSession()
79     {
80         std::lock_guard<std::mutex> lock(sessionMutex_);
81         return session_;
82     }
83 
SetVideoSession(const sptr<IVideoProcessSession> & session)84     inline void SetVideoSession(const sptr<IVideoProcessSession>& session)
85     {
86         std::lock_guard<std::mutex> lock(sessionMutex_);
87         session_ = session;
88     }
89 
90     std::mutex sessionMutex_;
91     const int32_t userId_;
92     sptr<IVideoProcessSession> session_ {nullptr};
93     std::shared_ptr<MediaManagerProxy> mediaManagerProxy_ {nullptr};
94     std::shared_ptr<VideoProcessResult> processResult_ {nullptr};
95     sptr<VideoServiceListener> serviceListener_;
96     sptr<SessionDeathRecipient> sessionDeathRecipient_;
97     sptr<VideoProcessListener> processListener_;
98     std::vector<StreamInfo_V1_1> allStreamInfo_ {};
99     std::unordered_map<std::string, DeferredVideoWorkPtr> runningWork_ {};
100 };
101 } // namespace DeferredProcessing
102 } // namespace CameraStandard
103 } // namespace OHOS
104 #endif // OHOS_CAMERA_DPS_VIDEO_POST_PROCESSOR_H