• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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() = default;
45     int32_t GetSize(int32_t &width, int32_t &height);
46     int32_t GetDataSize(uint64_t &size);
47     int32_t GetFormat(int32_t &format);
48     NativeComponent* GetComponent(int32_t type);
49     int32_t CombineYUVComponents();
GetBuffer()50     sptr<SurfaceBuffer> GetBuffer()
51     {
52         return buffer_;
53     }
54     void release();
55 private:
56     NativeComponent* CreateComponent(int32_t type, size_t size, int32_t row, int32_t pixel, uint8_t* vir);
57     NativeComponent* CreateCombineComponent(int32_t type);
58     NativeComponent* GetCachedComponent(int32_t type);
59     int32_t SplitYUV422SPComponent();
60     int32_t SplitSurfaceToComponent();
61     uint8_t* GetSurfaceBufferAddr();
62     sptr<SurfaceBuffer> buffer_;
63     std::shared_ptr<IBufferProcessor> releaser_;
64     std::map<int32_t, std::unique_ptr<NativeComponent>> components_;
65 };
66 } // namespace Media
67 } // namespace OHOS
68 
69 #endif // INTERFACES_INNERKITS_INCLUDE_NATIVE_IMAGE_H
70