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 RTP_DECODER_NODE_H
18 #define RTP_DECODER_NODE_H
19 
20 #include <BaseNode.h>
21 #include <IRtpSession.h>
22 #include <RtpHeaderExtension.h>
23 
24 /**
25  * @brief This class is to depacketize the rtp packet and acquires sequence number, ssrc, timestamp,
26  * mark flag from the rtp packet header by interfacing with the RtpStack module. This module can
27  * simulate the packet loss, delay, duplicate and mixed order to check the jitter buffer handles the
28  * variouse cases caused by the network condition.
29  */
30 class RtpDecoderNode : public BaseNode, public IRtpDecoderListener
31 {
32 public:
33     RtpDecoderNode(BaseSessionCallback* callback = nullptr);
34     virtual ~RtpDecoderNode();
35     virtual kBaseNodeId GetNodeId();
36     virtual ImsMediaResult Start();
37     virtual void Stop();
38     virtual bool IsRunTime();
39     virtual bool IsSourceNode();
40     virtual void SetConfig(void* config);
41     virtual bool IsSameConfig(void* config);
42     virtual void OnDataFromFrontNode(ImsMediaSubType subtype, uint8_t* pData, uint32_t nDataSize,
43             uint32_t timestamp, bool mark, uint32_t nSeqNum, ImsMediaSubType nDataType,
44             uint32_t arrivalTime = 0);
45     virtual void OnMediaDataInd(unsigned char* data, uint32_t dataSize, uint32_t timestamp,
46             bool mark, uint16_t seqNum, uint32_t payloadType, uint32_t ssrc,
47             const RtpHeaderExtensionInfo& extensionInfo);
48     // IRtpDecoderListener
49     virtual void OnNumReceivedPacket(uint32_t nNumRtpPacket);
50 
51     /**
52      * @brief Set the local ip address and port number
53      */
54     void SetLocalAddress(const RtpAddress& address);
55 
56     /**
57      * @brief Set the peer ip address and port number
58      */
59     void SetPeerAddress(const RtpAddress& address);
60 
61     /**
62      * @brief Set the inactivity timer in second unit
63      */
64     void SetInactivityTimerSec(const uint32_t time);
65 
66 private:
67     void processDtmf(uint8_t* data);
68     std::list<RtpHeaderExtension>* DecodeRtpHeaderExtension(
69             const RtpHeaderExtensionInfo& extensionInfo);
70 
71     IRtpSession* mRtpSession;
72     RtpAddress mLocalAddress;
73     RtpAddress mPeerAddress;
74     int8_t mSamplingRate;
75     int8_t mRtpPayloadTx;
76     int8_t mRtpPayloadRx;
77     int8_t mRtpTxDtmfPayload;
78     int8_t mRtpRxDtmfPayload;
79     int8_t mDtmfSamplingRate;
80     int32_t mCvoValue;
81     uint32_t mReceivingSSRC;
82     uint32_t mInactivityTime;
83     uint32_t mNoRtpTime;
84     int8_t mRedundantPayload;
85     uint32_t mArrivalTime;
86     ImsMediaSubType mSubtype;
87     bool mDtmfEndBit;
88     uint64_t mPacketTimestamp;
89 #if defined(SIMULATION_LOSS) || defined(SIMULATION_DUPLICATE) || defined(SIMULATION_SSRC_CHANGE)
90     uint32_t mPacketCounter;
91 #endif
92 #ifdef SIMULATION_DELAY
93     uint32_t mNextTime;
94 #endif
95 #ifdef SIMULATION_REORDER
96     ImsMediaDataQueue jitterData;
97     uint32_t mReorderDataCount;
98 #endif
99 #ifdef SIMULATION_SSRC_CHANGE
100     uint32_t mTestSsrc;
101     uint16_t mTestSeq;
102 #endif
103 };
104 
105 #endif
106