1 /** 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef IMS_MEDIA_DATA_QUEUE_H 18 #define IMS_MEDIA_DATA_QUEUE_H 19 20 #include <ImsMediaDefine.h> 21 #include <list> 22 23 using namespace std; 24 25 class DataEntry 26 { 27 public: DataEntry()28 DataEntry() 29 { 30 pbBuffer = nullptr; 31 nBufferSize = 0; 32 nTimestamp = 0; 33 bMark = false; 34 nSeqNum = 0; 35 bHeader = false; 36 bValid = false; 37 arrivalTime = 0; 38 eDataType = MEDIASUBTYPE_UNDEFINED; 39 subtype = MEDIASUBTYPE_UNDEFINED; 40 } 41 DataEntry(const DataEntry & entry)42 DataEntry(const DataEntry& entry) 43 { 44 pbBuffer = nullptr; 45 46 if (entry.nBufferSize > 0 && entry.pbBuffer != nullptr) 47 { 48 pbBuffer = new uint8_t[entry.nBufferSize]; 49 memcpy(pbBuffer, entry.pbBuffer, entry.nBufferSize); 50 } 51 52 nBufferSize = entry.nBufferSize; 53 nTimestamp = entry.nTimestamp; 54 bMark = entry.bMark; 55 nSeqNum = entry.nSeqNum; 56 bHeader = entry.bHeader; 57 bValid = entry.bValid; 58 arrivalTime = entry.arrivalTime; 59 eDataType = entry.eDataType; 60 subtype = entry.subtype; 61 } 62 ~DataEntry()63 ~DataEntry() {} 64 deleteBuffer()65 void deleteBuffer() 66 { 67 if (pbBuffer != nullptr) 68 { 69 delete[] pbBuffer; 70 } 71 } 72 73 uint8_t* pbBuffer; // The data buffer 74 uint32_t nBufferSize; // The size of data 75 /** The timestamp of data, it can be milliseconds unit or rtp timestamp unit */ 76 uint32_t nTimestamp; 77 /** The flag when the data has marker bit set */ 78 bool bMark; 79 /** The sequence number of data. it is 0 when there is no valid sequence number set */ 80 uint16_t nSeqNum; 81 /** The flag when the data frame is header of the fragmented packet */ 82 bool bHeader; 83 /** The flag when the data is fully integrated from fragmented packet */ 84 bool bValid; 85 /** The arrival time of the packet */ 86 uint32_t arrivalTime; 87 /** The additional data type for the video frames */ 88 ImsMediaSubType eDataType; 89 /**The subtype of data stored in the queue. It can be various subtype according to the 90 * characteristics of the given data */ 91 ImsMediaSubType subtype; 92 }; 93 94 /*! 95 * @class ImsMediaDataQueue 96 * @brief 97 */ 98 class ImsMediaDataQueue 99 { 100 public: 101 ImsMediaDataQueue(); 102 virtual ~ImsMediaDataQueue(); 103 104 private: 105 ImsMediaDataQueue(const ImsMediaDataQueue& obj); 106 ImsMediaDataQueue& operator=(const ImsMediaDataQueue& obj); 107 108 public: 109 void Add(DataEntry* pEntry); 110 void InsertAt(uint32_t index, DataEntry* pEntry); 111 void Delete(); 112 void Clear(); 113 bool Get(DataEntry** ppEntry); 114 bool GetLast(DataEntry** ppEntry); 115 bool GetAt(uint32_t index, DataEntry** ppEntry); 116 uint32_t GetCount(); 117 void SetReadPosFirst(); 118 bool GetNext(DataEntry** ppEntry); 119 120 private: 121 list<DataEntry*> mList; // data list 122 list<DataEntry*>::iterator mListIter; 123 std::mutex mMutex; 124 }; 125 126 #endif