• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "video_refreshrate_prediction_fwk.h"
17 #include "extension_manager.h"
18 #include "surface_buffer.h"
19 #include "vpe_trace.h"
20 #include "vpe_log.h"
21 
22 namespace OHOS {
23 namespace Media {
24 namespace VideoProcessingEngine {
VideoRefreshRatePredictionFwk()25 VideoRefreshRatePredictionFwk::VideoRefreshRatePredictionFwk()
26 {
27     Extension::ExtensionManager::GetInstance().IncreaseInstance();
28 }
29 
~VideoRefreshRatePredictionFwk()30 VideoRefreshRatePredictionFwk::~VideoRefreshRatePredictionFwk()
31 {
32     impl_ = nullptr;
33     Extension::ExtensionManager::GetInstance().DecreaseInstance();
34 }
35 
Process(const sptr<SurfaceBuffer> & input,int videoFps,int codecType)36 VPEAlgoErrCode VideoRefreshRatePredictionFwk::Process(const sptr<SurfaceBuffer> &input, int videoFps, int codecType)
37 {
38     VPEAlgoErrCode ret = Init();
39     CHECK_AND_RETURN_RET_LOG(ret == VPE_ALGO_ERR_OK, ret, "VRR Init failed");
40     ret = impl_->Process(input, videoFps, codecType);
41     CHECK_AND_RETURN_RET_LOG(ret == VPE_ALGO_ERR_OK, ret, "Process failed, ret: %{public}d", ret);
42     return VPE_ALGO_ERR_OK;
43 }
44 
CheckVRRSupport(std::string processName)45 VPEAlgoErrCode VideoRefreshRatePredictionFwk::CheckVRRSupport(std::string processName)
46 {
47     VPEAlgoErrCode ret = Init();
48     CHECK_AND_RETURN_RET_LOG(ret == VPE_ALGO_ERR_OK, ret, "VRR Init failed");
49     ret = impl_->CheckVRRSupport(processName);
50     return ret;
51 }
52 
Init()53 VPEAlgoErrCode VideoRefreshRatePredictionFwk::Init()
54 {
55     if (initialized_) {
56         return VPE_ALGO_ERR_OK;
57     }
58     auto& manager = Extension::ExtensionManager::GetInstance();
59     VPE_SYNC_TRACE;
60     impl_ = manager.CreateVideoRefreshRatePredictor();
61     CHECK_AND_RETURN_RET_LOG(impl_ != nullptr, VPE_ALGO_ERR_NOT_IMPLEMENTED, "Create impl failed");
62     initialized_ = true;
63     VPE_LOGI("create VideoRefreshRatePredictionFwk Successed");
64     return VPE_ALGO_ERR_OK;
65 }
66 
67 
Create()68 std::shared_ptr<VideoRefreshRatePrediction> VideoRefreshRatePrediction::Create()
69 {
70     auto p = std::make_shared<VideoRefreshRatePredictionFwk>();
71     CHECK_AND_RETURN_RET_LOG(p != nullptr, nullptr, "Create VideoRefreshRatePrediction failed");
72     return std::static_pointer_cast<VideoRefreshRatePrediction>(p);
73 }
74 
75 struct VideoRefreshRatePredictionHandleImpl {
76     std::shared_ptr<VideoRefreshRatePredictionFwk> obj;
77 };
78 
VideoRefreshRatePredictionCreate()79 VideoRefreshRatePredictionHandle *VideoRefreshRatePredictionCreate()
80 {
81     auto impl = std::make_shared<VideoRefreshRatePredictionFwk>();
82     CHECK_AND_RETURN_RET_LOG(impl != nullptr, nullptr, "Create VideoRefreshRatePrediction failed");
83     auto handle = new VideoRefreshRatePredictionHandleImpl;
84     handle->obj = impl;
85     return static_cast<VideoRefreshRatePredictionHandle *>(handle);
86 }
87 
VideoRefreshRatePredictionDestroy(VideoRefreshRatePredictionHandle * handle)88 void VideoRefreshRatePredictionDestroy(VideoRefreshRatePredictionHandle *handle)
89 {
90     VPE_LOGD("VideoRefreshRatePredictionFwk Destroy");
91     if (handle != nullptr) {
92         auto p = static_cast<VideoRefreshRatePredictionHandleImpl *>(handle);
93         delete p;
94     }
95 }
96 
VideoRefreshRatePredictionCheckSupport(VideoRefreshRatePredictionHandle * handle,const char * processName)97 int32_t VideoRefreshRatePredictionCheckSupport(VideoRefreshRatePredictionHandle *handle, const char *processName)
98 {
99     auto p = static_cast<VideoRefreshRatePredictionHandleImpl *>(handle);
100     int32_t ret = p->obj->CheckVRRSupport(processName);
101     return ret;
102 }
103 
VideoRefreshRatePredictionProcess(VideoRefreshRatePredictionHandle * handle,OH_NativeBuffer * inputImageNativeBuffer,int videoFps,int codecType)104 void VideoRefreshRatePredictionProcess(VideoRefreshRatePredictionHandle *handle,
105     OH_NativeBuffer* inputImageNativeBuffer, int videoFps, int codecType)
106 {
107     auto p = static_cast<VideoRefreshRatePredictionHandleImpl *>(handle);
108     sptr<SurfaceBuffer> inputImageSurfaceBuffer(SurfaceBuffer::NativeBufferToSurfaceBuffer(inputImageNativeBuffer));
109     p->obj->Process(inputImageSurfaceBuffer, videoFps, codecType);
110 }
111 
112 } // namespace VideoProcessingEngine
113 } // namespace Media
114 } // namespace OHOS
115