1 /* 2 * Copyright (c) 2021-2021 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 HISTREAMER_PLUGIN_COMMON_SURFACE_ALLOCATOR_H 17 #define HISTREAMER_PLUGIN_COMMON_SURFACE_ALLOCATOR_H 18 19 #if !defined(OHOS_LITE) && defined(VIDEO_SUPPORT) 20 21 #include "plugin/common/plugin_memory.h" 22 #include "plugin/common/plugin_types.h" 23 #include "refbase.h" 24 #include "surface/surface.h" 25 26 namespace OHOS { 27 namespace Media { 28 namespace Plugin { 29 class SurfaceAllocator : public Allocator { 30 public: 31 explicit SurfaceAllocator(sptr<Surface> surface = nullptr); 32 ~SurfaceAllocator() override = default; 33 34 sptr<SurfaceBuffer> AllocSurfaceBuffer(); 35 void ReleaseSurfaceBuffer(sptr<SurfaceBuffer>& surfaceBuffer, bool needRender); 36 37 void* Alloc(size_t size) override; 38 void Free(void* ptr) override; // NOLINT: void* 39 40 void Config(int32_t width, int32_t height, uint64_t usage, int32_t format, int32_t strideAlign, int32_t timeout); 41 void SetScaleType(VideoScaleType videoScaleType); 42 void UpdateSurfaceBufferScaleMode(sptr<SurfaceBuffer>& surfaceBuffer); 43 private: 44 sptr<Surface> surface_ {nullptr}; 45 BufferRequestConfig requestConfig_; 46 ScalingMode scalingMode_ {ScalingMode::SCALING_MODE_SCALE_TO_WINDOW}; 47 }; 48 } // namespace Plugin 49 } // namespace Media 50 } // namespace OHOS 51 52 #endif 53 #endif // HISTREAMER_PLUGIN_COMMON_SURFACE_BUFFER_H 54