• 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 "log_tags.h"
23 #include "image_receiver_context.h"
24 #include "image_format.h"
25 
26 namespace OHOS {
27 namespace Media {
28 struct NativeComponent {
29     int32_t rowStride = 0;
30     int32_t pixelStride = 0;
31     std::vector<uint8_t> raw;
32     uint8_t* virAddr;
33     size_t size = 0;
34 };
35 
36 class IBufferProcessor {
37 public:
~IBufferProcessor()38     virtual ~IBufferProcessor() {};
39     virtual void BufferRelease(sptr<SurfaceBuffer>& buffer) = 0;
40 };
41 
42 class NativeImage {
43 public:
44     NativeImage(sptr<SurfaceBuffer> buffer, std::shared_ptr<IBufferProcessor> releaser);
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     NativeComponent* GetComponent(int32_t type);
50     int32_t CombineYUVComponents();
GetBuffer()51     sptr<SurfaceBuffer> GetBuffer()
52     {
53         return buffer_;
54     }
55     void release();
56 private:
57     NativeComponent* CreateComponent(int32_t type, size_t size, int32_t row, int32_t pixel, uint8_t* vir);
58     NativeComponent* CreateCombineComponent(int32_t type);
59     NativeComponent* GetCachedComponent(int32_t type);
60     int32_t SplitYUV422SPComponent();
61     int32_t SplitSurfaceToComponent();
62     uint8_t* GetSurfaceBufferAddr();
63     sptr<SurfaceBuffer> buffer_;
64     std::shared_ptr<IBufferProcessor> releaser_;
65     std::map<int32_t, std::unique_ptr<NativeComponent>> components_;
66 };
67 } // namespace Media
68 } // namespace OHOS
69 
70 #endif // INTERFACES_INNERKITS_INCLUDE_NATIVE_IMAGE_H_
71