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 #ifndef RS_VIDEO_FRAME_RATE_VOTE_H
17 #define RS_VIDEO_FRAME_RATE_VOTE_H
18 
19 #include "ffrt.h"
20 #include "variable_frame_rate/rs_variable_frame_rate.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 class RSVideoFrameRateVote {
25 public:
26     RSVideoFrameRateVote(uint64_t surfaceNodeId, const std::function<void(uint64_t)>& releaseCallback,
27         const std::function<void(uint64_t, uint32_t)>& voteCallback);
28     ~RSVideoFrameRateVote();
29 
30     /**
31      * @brief vote frame rate by video rate
32      *
33      * @param videoRate the rate of video
34      */
35     void StartVideoFrameRateVote(double videoRate);
36 
37 private:
38     void VoteVideoFrameRate(double videoRate);
39     void SendDelayTask();
40     void CancelDelayTask();
41     void DoVoteCallback(uint32_t rate);
42     void DoReleaseCallback();
43 
44 private:
45     uint64_t surfaceNodeId_ {0};
46     std::function<void(uint64_t)> releaseCallback_ {nullptr};
47     std::function<void(uint64_t, uint32_t)> voteCallback_ {nullptr};
48     uint32_t lastRate_ {0};
49     std::shared_ptr<ffrt::queue> ffrtQueue_ {nullptr};
50     ffrt::mutex ffrtMutex_;
51     ffrt::task_handle taskHandler_ {nullptr};
52 };
53 } // namespace Rosen
54 } // namespace OHOS
55 #endif // RS_VIDEO_FRAME_RATE_VOTE_H