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 RTCPENCODERNODE_H_INCLUDED 18 #define RTCPENCODERNODE_H_INCLUDED 19 20 #include <BaseNode.h> 21 #include <IRtpSession.h> 22 #include <ImsMediaTimer.h> 23 #include <ImsMediaVideoUtil.h> 24 #include <ImsMediaBitWriter.h> 25 #include <mutex> 26 27 #define BLOCK_LENGTH_STATISTICS 40 28 #define BLOCK_LENGTH_VOIP_METRICS 36 29 30 class RtcpEncoderNode : public BaseNode, public IRtcpEncoderListener 31 { 32 public: 33 RtcpEncoderNode(BaseSessionCallback* callback = nullptr); 34 ~RtcpEncoderNode(); 35 static void OnTimer(hTimerHandler hTimer, void* pUserData); 36 virtual kBaseNodeId GetNodeId(); 37 virtual ImsMediaResult Start(); 38 virtual void Stop(); 39 virtual bool IsRunTime(); 40 virtual bool IsSourceNode(); 41 virtual void SetConfig(void* config); 42 virtual bool IsSameConfig(void* config); 43 virtual void OnRtcpPacket(unsigned char* pData, uint32_t wLen); 44 45 /** 46 * @brief The methods operates when the timer is expired 47 */ 48 virtual void ProcessTimer(); 49 50 /** 51 * @brief Set the local ip address and port number 52 */ 53 void SetLocalAddress(const RtpAddress& address); 54 55 /** 56 * @brief Set the peer ip address and port number 57 */ 58 void SetPeerAddress(const RtpAddress& address); 59 60 /** 61 * @brief Creates NACK payload and request RtpStack to send it 62 * 63 * @param param The parameters to packetize the payload 64 */ 65 bool SendNack(NackParams* param); 66 67 /** 68 * @brief Create PLI/FIR payload and request RtpStack to send it 69 * 70 * @param type The type of PLI or FIR 71 */ 72 bool SendPictureLost(const uint32_t type); 73 74 /** 75 * @brief Create TMMBR/TMMBN payload and request RtpStack to send it 76 * 77 * @param type The type of TMMBR or TMMBN 78 * @param param The parameters to packetize the payload 79 */ 80 bool SendTmmbrn(const uint32_t type, TmmbrParams* param); 81 82 /** 83 * @brief Send Rtcp-Xr payload to the RtpStack to add the rtp header to send it to the network 84 * 85 * @param data The payload of the rtcp-xr report blocks 86 * @param size The size of payload 87 */ 88 bool SendRtcpXr(uint8_t* data, uint32_t size); 89 90 private: 91 IRtpSession* mRtpSession; 92 RtpAddress mLocalAddress; 93 RtpAddress mPeerAddress; 94 uint32_t mRtcpInterval; 95 uint8_t* mRtcpXrPayload; 96 bool mEnableRtcpBye; 97 uint32_t mRtcpXrBlockTypes; 98 int32_t mRtcpXrCounter; 99 int32_t mRtcpFbTypes; 100 hTimerHandler mTimer; 101 std::mutex mMutexTimer; 102 uint32_t mLastTimeSentPli; 103 uint32_t mLastTimeSentFir; 104 ImsMediaBitWriter mBitWriter; 105 }; 106 107 #endif // RTCPENCODERNODE_H_INCLUDED 108