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 BASE_JITTER_BUFFER_H_INCLUDEED 18 #define BASE_JITTER_BUFFER_H_INCLUDEED 19 20 #include <ImsMediaDataQueue.h> 21 #include <BaseSessionCallback.h> 22 #include <mutex> 23 24 /*! 25 * @class BaseJitterBuffer 26 */ 27 class BaseJitterBuffer 28 { 29 public: 30 BaseJitterBuffer(); 31 virtual ~BaseJitterBuffer(); 32 virtual void SetSessionCallback(BaseSessionCallback* callback); 33 34 /** 35 * @brief Set the codec type 36 */ 37 virtual void SetCodecType(uint32_t type); 38 virtual void SetJitterBufferSize(uint32_t nInit, uint32_t nMin, uint32_t nMax); 39 40 /** 41 * @brief Get the size of the queue 42 */ 43 virtual uint32_t GetCount(); 44 45 /** 46 * @brief Reset the parameters for playing 47 */ 48 virtual void Reset(); 49 50 /** 51 * @brief Delete the first data in the queue 52 */ 53 virtual void Delete(); 54 55 /** 56 * @brief Delete all the data frames in the queue 57 */ 58 virtual void ClearBuffer(); 59 60 /** 61 * @brief Add data frame to jitter buffer for dejittering 62 * 63 * @param subtype The subtype of data stored in the queue. It can be various subtype according 64 * to the characteristics of the given data 65 * @param data The data buffer 66 * @param dataSize The size of data 67 * @param timestamp The timestamp of data, it can be milliseconds unit or rtp timestamp unit 68 * @param mark It is true when the data has marker bit set 69 * @param seq The sequence number of data. it is 0 when there is no valid sequence number set 70 * @param dataType The additional data type for the video frames 71 * @param arrivalTime The arrival time of the packet in milliseconds unit 72 */ 73 virtual void Add(ImsMediaSubType subtype, uint8_t* data, uint32_t dataSize, uint32_t timestamp, 74 bool mark, uint32_t seq, 75 /** TODO: remove deprecated argument dataType */ 76 ImsMediaSubType dataType = ImsMediaSubType::MEDIASUBTYPE_UNDEFINED, 77 uint32_t arrivalTime = 0) = 0; 78 79 /** 80 * @brief Get data frame from the jitter buffer 81 * 82 * @param subtype The subtype of data stored in the queue. It can be various subtype according 83 * to the characteristics of the given data 84 * @param data The data buffer 85 * @param dataSize The size of data 86 * @param timestamp The timestamp of data, it can be milliseconds unit or rtp timestamp unit 87 * @param mark It is true when the data has marker bit set 88 * @param seq The sequence number of data. it is 0 when there is no valid sequence number set 89 * @param currentTime The current timestamp of this method invoked with milliseconds unit 90 */ 91 virtual bool Get(ImsMediaSubType* psubtype, uint8_t** ppData, uint32_t* pnDataSize, 92 uint32_t* ptimestamp, bool* pmark, uint32_t* pnSeqNum, uint32_t currentTime, 93 ImsMediaSubType* pDataType = nullptr) = 0; 94 virtual bool GetRedundantFrame(uint32_t lostSeq, uint8_t** ppData = nullptr, 95 uint32_t* pnDataSize = nullptr, bool* hasNextFrame = nullptr, 96 uint8_t* nextFrameFirstByte = nullptr); 97 98 protected: 99 BaseSessionCallback* mCallback; 100 bool mFirstFrameReceived; 101 uint32_t mSsrc; 102 uint32_t mCodecType; 103 ImsMediaDataQueue mDataQueue; 104 std::mutex mMutex; 105 uint32_t mInitJitterBufferSize; 106 uint32_t mMinJitterBufferSize; 107 uint32_t mMaxJitterBufferSize; 108 bool mNewInputData; 109 uint16_t mLastPlayedSeqNum; 110 uint32_t mLastPlayedTimestamp; 111 uint32_t mMaxSaveFrameNum; 112 }; 113 114 #endif