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 #ifndef AV_CODEC_FSURFACE_MEMORY_H 17 #define AV_CODEC_FSURFACE_MEMORY_H 18 19 #include "refbase.h" 20 #include "surface.h" 21 #include "sync_fence.h" 22 23 namespace OHOS { 24 namespace MediaAVCodec { 25 namespace { 26 constexpr uint64_t USAGE = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA; 27 constexpr int32_t SURFACE_STRIDE_ALIGN = 8; 28 constexpr int32_t TIMEOUT = 0; 29 } // namespace 30 31 class FSurfaceMemory { 32 public: 33 FSurfaceMemory() = default; 34 ~FSurfaceMemory(); 35 static std::shared_ptr<FSurfaceMemory> Create(); 36 static void SetSurface(sptr<Surface> surface); 37 static void SetConfig(int32_t width, int32_t height, int32_t format, uint64_t usage = USAGE, 38 int32_t strideAlign = SURFACE_STRIDE_ALIGN, int32_t timeout = TIMEOUT); 39 static void SetScaleType(ScalingMode videoScaleMode); 40 void AllocSurfaceBuffer(); 41 void ReleaseSurfaceBuffer(); 42 sptr<SurfaceBuffer> GetSurfaceBuffer(); 43 int32_t GetSurfaceBufferStride(); 44 int32_t GetFence(); 45 void UpdateSurfaceBufferScaleMode(); 46 void SetNeedRender(bool needRender); 47 uint8_t *GetBase() const; 48 int32_t GetSize() const; 49 50 private: 51 // Allocated memory size. 52 sptr<SurfaceBuffer> surfaceBuffer_ = nullptr; 53 int32_t fence_ = -1; 54 int32_t stride_ = 0; 55 bool needRender_ = false; 56 static sptr<Surface> surface_; 57 static BufferRequestConfig requestConfig_; 58 static ScalingMode scalingMode_; 59 }; 60 } // namespace MediaAVCodec 61 } // namespace OHOS 62 #endif 63