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 innerImgBuffer_.clear(); 42 std::vector<uint8_t>().swap(innerImgBuffer_); 43 } 44 GetInnerImgBuffer()45 std::vector<uint8_t> GetInnerImgBuffer() const 46 { 47 return innerImgBuffer_; 48 } 49 SetInnerImgBuffer(const std::vector<uint8_t> & imgBuffer)50 void SetInnerImgBuffer(const std::vector<uint8_t>& imgBuffer) 51 { 52 std::lock_guard lockGuard(bufferLock_); 53 innerImgBuffer_.clear(); 54 innerImgBuffer_ = imgBuffer; 55 } 56 57 private: 58 std::vector<uint8_t> innerImgBuffer_; 59 std::recursive_mutex bufferLock_; 60 }; 61 } // namespace OHOS::AVSession 62 #endif // OHOS_AVSESSION_PIXEL_MAP_H