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