• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ENCODER_NODE_H
18 #define RTP_ENCODER_NODE_H
19 
20 #include <BaseNode.h>
21 #include <IRtpSession.h>
22 #include <RtpContextParams.h>
23 #include <RtpHeaderExtension.h>
24 #include <mutex>
25 
26 class RtpEncoderNode : public BaseNode, public IRtpEncoderListener
27 {
28 public:
29     RtpEncoderNode(BaseSessionCallback* callback = nullptr);
30     virtual ~RtpEncoderNode();
31     virtual kBaseNodeId GetNodeId();
32     virtual ImsMediaResult Start();
33     virtual void Stop();
34     virtual void ProcessData();
35     virtual bool IsRunTime();
36     virtual bool IsSourceNode();
37     virtual void SetConfig(void* config);
38     virtual bool IsSameConfig(void* config);
39     // IRtpEncoderListener method
40     virtual void OnRtpPacket(unsigned char* pData, uint32_t nSize);
41 
42     /**
43      * @brief Set the local ip address and port number
44      */
45     void SetLocalAddress(const RtpAddress& address);
46 
47     /**
48      * @brief Set the peer ip address and port number
49      */
50     void SetPeerAddress(const RtpAddress& address);
51 
52     /**
53      * @brief Set the camera facing and device orientation parameter for cvo extension in rtp header
54      *
55      * @param facing The facing of camera define in kCameraFacing in ImsMediaVideoUtil.h
56      * @param orientation The orientation value to send in degree unit
57      * @return true Return true when the extension data set properly
58      * @return false Return false when the cvo configuration is disabled
59      */
60     bool SetCvoExtension(const int64_t facing, const int64_t orientation);
61 
62     /**
63      * @brief Convert list of the RtpHeaderExtension to Rtp header extension payload
64      */
65     void SetRtpHeaderExtension(std::list<RtpHeaderExtension>* listExtension);
66 
67     /**
68      * @brief Sets RTP stack with params such as SSRC, sequence number, timestamp, etc. RTP Packets
69      * sent after this call will follow the new params set.
70      *
71      * @param rtpContextParams holds the rtp parameters such as ssrc, timestamp,
72      * sequence number, etc.
73      */
74     void SetRtpContext(RtpContextParams& rtpContextParams);
75 
76     void GetRtpContext(RtpContextParams& rtpContextParams);
77 
78 private:
79     bool ProcessAudioData(ImsMediaSubType subtype, uint8_t* pData, uint32_t nDataSize);
80     void ProcessVideoData(ImsMediaSubType subtype, uint8_t* pData, uint32_t nDataSize,
81             uint32_t timestamp, bool mark);
82     void ProcessTextData(ImsMediaSubType subtype, uint8_t* pData, uint32_t nDataSize,
83             uint32_t timestamp, bool mark);
84 
85     IRtpSession* mRtpSession;
86     std::mutex mMutex;
87     RtpAddress mLocalAddress;
88     RtpAddress mPeerAddress;
89     bool mDTMFMode;
90     bool mMark;
91     uint32_t mPrevTimestamp;
92     int8_t mSamplingRate;
93     int8_t mRtpPayloadTx;
94     int8_t mRtpPayloadRx;
95     int8_t mRtpTxDtmfPayload;
96     int8_t mRtpRxDtmfPayload;
97     int8_t mDtmfSamplingRate;
98     int32_t mDtmfTimestamp;
99     int32_t mCvoValue;
100     int8_t mRedundantPayload;
101     int8_t mRedundantLevel;
102     std::list<RtpHeaderExtensionInfo> mListRtpExtension;
103     RtpContextParams mRtpContextParams;
104 };
105 
106 #endif
107