• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef OHOS_AVSESSION_PIXEL_MAP_H
16 #define OHOS_AVSESSION_PIXEL_MAP_H
17 
18 #include <vector>
19 #include "parcel.h"
20 
21 #if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM) and !defined(IOS_PLATFORM)
22 #include <malloc.h>
23 #endif
24 
25 namespace OHOS::AVSession {
26 constexpr size_t DEFAULT_BUFFER_SIZE = 160 * 1024;
27 class AVSessionPixelMap : public Parcelable {
28 public:
29     AVSessionPixelMap() = default;
~AVSessionPixelMap()30     ~AVSessionPixelMap() override
31     {
32         Clear();
33     }
34 
35     bool Marshalling(Parcel& parcel) const override;
36     static AVSessionPixelMap* Unmarshalling(Parcel& data);
37 
Clear()38     void Clear()
39     {
40         innerImgBuffer_.clear();
41         std::vector<uint8_t>().swap(innerImgBuffer_);
42     }
43 
GetInnerImgBuffer()44     std::vector<uint8_t> GetInnerImgBuffer() const
45     {
46         return innerImgBuffer_;
47     }
48 
SetInnerImgBuffer(const std::vector<uint8_t> & imgBuffer)49     void SetInnerImgBuffer(const std::vector<uint8_t>& imgBuffer)
50     {
51         innerImgBuffer_.clear();
52         innerImgBuffer_ = imgBuffer;
53         if (innerImgBuffer_.capacity() < DEFAULT_BUFFER_SIZE) {
54             innerImgBuffer_.reserve(DEFAULT_BUFFER_SIZE);
55         }
56     }
57 
58 private:
59     std::vector<uint8_t> innerImgBuffer_;
60 };
61 } // namespace OHOS::AVSession
62 #endif // OHOS_AVSESSION_PIXEL_MAP_H