• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 LPP_COMMON_H
17 #define LPP_COMMON_H
18 
19 #include <refbase.h>
20 #include "buffer/avbuffer.h"
21 #include "avcodec_common.h"
22 
23 namespace OHOS {
24 namespace Media {
25 
26 enum LppErrCode : int32_t {
27     LPP_ERROR_OK = 0,
28     LPP_ERROR_UNKONWN,
29 };
30 
31 class LppDataPacket : public OHOS::RefBase {
32 public:
33 
34     virtual ~LppDataPacket() = default;
35     int32_t GetRemainedCapacity();
36     bool AppendOneBuffer(const std::shared_ptr<AVBuffer> &buffer);
37     bool WriteToMessageParcel(MessageParcel &parcel);
38     bool ReadFromMessageParcel(MessageParcel &parcel);
39     virtual bool WriteToByteBuffer(std::shared_ptr<AVBuffer> &buffer);
40     bool ReadFromByteBuffer(uint8_t *buffer, int32_t capacity);
41     bool IsEmpty();
42     virtual bool WriteOneFrameToAVBuffer(std::shared_ptr<AVBuffer> &buffer);
43     bool WriteOneFrameToAVBuffer(std::shared_ptr<AVBuffer> &avbuffer, int& offset);
44     void Clear();
45     void Init(std::string streamerId);
46     void Disable();
47     void Enable();
48     bool IsEnable();
49     void DumpAVBufferToFile(const std::string& para, const std::shared_ptr<AVBuffer>& buffer, const bool isClient);
50 
51 public:
52     std::vector<uint32_t> flag_;
53     std::vector<int64_t> pts_;
54     std::vector<int32_t> size_;
55     std::shared_ptr<AVBuffer> buffer_ {nullptr};
56     std::shared_ptr<AVMemory> memory_ {nullptr};
57     std::string streamerId_{};
58     bool dumpBufferNeeded_ {false};
59     std::string dumpFileNameInput_{};
60 
61 private:
62     void Init();
63     bool WriteVector(MessageParcel &parcel);
64     bool ReadVector(MessageParcel &parcel);
65     bool IsEos();
66     int dataOffset_ {0};
67     size_t vectorReadIndex_ {0};
68     uint32_t frameCount_ {0};
69     bool inUser_ {false};
70 };
71 
72 } // namespace Media
73 } // namespace OHOS
74 #endif // LPP_COMMON_H