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 POST_PROCESSING_CONTROLLER_H 17 #define POST_PROCESSING_CONTROLLER_H 18 19 #include <type_traits> 20 #include "surface.h" 21 #include "avcodec_errors.h" 22 #include "meta/format.h" 23 #include "utils.h" 24 25 namespace OHOS { 26 namespace MediaAVCodec { 27 namespace PostProcessing { 28 29 template<typename T> 30 class Controller { 31 public: 32 virtual ~Controller() = default; 33 LoadInterfaces()34 bool LoadInterfaces() 35 { 36 return This()->LoadInterfacesImpl(); 37 } 38 UnloadInterfaces()39 void UnloadInterfaces() 40 { 41 return This()->UnloadInterfacesImpl(); 42 } 43 IsColorSpaceConversionSupported(const CapabilityInfo & input,const CapabilityInfo & output)44 bool IsColorSpaceConversionSupported(const CapabilityInfo& input, const CapabilityInfo& output) 45 { 46 return This()->IsColorSpaceConversionSupportedImpl(input, output); 47 } 48 Create()49 int32_t Create() 50 { 51 return This()->CreateImpl(); 52 } 53 Destroy()54 void Destroy() 55 { 56 return This()->DestroyImpl(); 57 } 58 SetCallback(void * callback,void * userData)59 int32_t SetCallback(void* callback, void* userData) 60 { 61 return This()->SetCallbackImpl(callback, userData); 62 } 63 SetOutputSurface(sptr<Surface> surface)64 int32_t SetOutputSurface(sptr<Surface> surface) 65 { 66 return This()->SetOutputSurfaceImpl(surface); 67 } 68 CreateInputSurface(sptr<Surface> & surface)69 int32_t CreateInputSurface(sptr<Surface>& surface) 70 { 71 return This()->CreateInputSurfaceImpl(surface); 72 } 73 SetParameter(Media::Format & parameter)74 int32_t SetParameter(Media::Format& parameter) 75 { 76 return This()->SetParameterImpl(parameter); 77 } 78 GetParameter(Media::Format & parameter)79 int32_t GetParameter(Media::Format& parameter) 80 { 81 return This()->GetParameterImpl(parameter); 82 } 83 Configure(Media::Format & config)84 int32_t Configure(Media::Format& config) 85 { 86 return This()->ConfigureImpl(config); 87 } 88 Prepare()89 int32_t Prepare() 90 { 91 return This()->PrepareImpl(); 92 } 93 Start()94 int32_t Start() 95 { 96 return This()->StartImpl(); 97 } 98 Stop()99 int32_t Stop() 100 { 101 return This()->StopImpl(); 102 } 103 Flush()104 int32_t Flush() 105 { 106 return This()->FlushImpl(); 107 } 108 GetOutputFormat(Media::Format & format)109 int32_t GetOutputFormat(Media::Format& format) 110 { 111 return This()->GetOutputFormatImpl(format); 112 } 113 Reset()114 int32_t Reset() 115 { 116 return This()->ResetImpl(); 117 } 118 Release()119 int32_t Release() 120 { 121 return This()->ReleaseImpl(); 122 } 123 ReleaseOutputBuffer(uint32_t index,bool render)124 int32_t ReleaseOutputBuffer(uint32_t index, bool render) 125 { 126 return This()->ReleaseOutputBufferImpl(index, render); 127 } 128 private: This()129 T* This() 130 { 131 return static_cast<T*>(this); 132 } 133 134 static constexpr HiviewDFX::HiLogLabel LABEL{LogLabel("Controller")}; 135 }; 136 137 template<typename T> 138 using IsDerivedController = std::enable_if_t< 139 std::conjunction_v< 140 std::is_base_of<Controller<T>, T>, 141 std::is_convertible<const volatile T*, const volatile Controller<T>*> 142 > 143 >; 144 145 } // namespace OHOS 146 } // namespace MediaAVCodec 147 } // namespace PostProcessing 148 149 #endif // POST_PROCESSING_CONTROLLER_H