1 /* 2 * Copyright (C) 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 INTERFACES_INNERKITS_INCLUDE_NATIVE_IMAGE_H 17 #define INTERFACES_INNERKITS_INCLUDE_NATIVE_IMAGE_H 18 19 #include <map> 20 #include <memory> 21 #include <vector> 22 #include "image_receiver_context.h" 23 #include "image_format.h" 24 25 namespace OHOS { 26 namespace Media { 27 struct NativeComponent { 28 int32_t rowStride = 0; 29 int32_t pixelStride = 0; 30 std::vector<uint8_t> raw; 31 uint8_t* virAddr; 32 size_t size = 0; 33 }; 34 35 class IBufferProcessor { 36 public: ~IBufferProcessor()37 virtual ~IBufferProcessor() {}; 38 virtual void BufferRelease(sptr<SurfaceBuffer>& buffer) = 0; 39 }; 40 41 class NativeImage { 42 public: 43 NativeImage(sptr<SurfaceBuffer> buffer, std::shared_ptr<IBufferProcessor> releaser); 44 NativeImage(sptr<SurfaceBuffer> buffer, std::shared_ptr<IBufferProcessor> releaser, int64_t timestamp); 45 ~NativeImage() = default; 46 int32_t GetSize(int32_t &width, int32_t &height); 47 int32_t GetDataSize(uint64_t &size); 48 int32_t GetFormat(int32_t &format); 49 int32_t GetTimestamp(int64_t ×tamp); 50 NativeComponent* GetComponent(int32_t type); GetComponents()51 std::map<int32_t, std::unique_ptr<NativeComponent>>& GetComponents() 52 { 53 return components_; 54 } 55 int32_t CombineYUVComponents(); GetBuffer()56 sptr<SurfaceBuffer> GetBuffer() 57 { 58 return buffer_; 59 } 60 void release(); SetId(std::string id)61 void SetId(std::string id) 62 { 63 id_ = id; 64 } GetId()65 std::string GetId() 66 { 67 return id_; 68 } 69 private: 70 NativeComponent* CreateComponent(int32_t type, size_t size, int32_t row, int32_t pixel, uint8_t* vir); 71 NativeComponent* CreateCombineComponent(int32_t type); 72 NativeComponent* GetCachedComponent(int32_t type); 73 int32_t SplitYUV422SPComponent(); 74 int32_t SplitSurfaceToComponent(); 75 uint8_t* GetSurfaceBufferAddr(); 76 sptr<SurfaceBuffer> buffer_; 77 std::shared_ptr<IBufferProcessor> releaser_; 78 std::map<int32_t, std::unique_ptr<NativeComponent>> components_; 79 int64_t timestamp_; 80 std::string id_; 81 }; 82 } // namespace Media 83 } // namespace OHOS 84 85 #endif // INTERFACES_INNERKITS_INCLUDE_NATIVE_IMAGE_H 86