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 /** \addtogroup RTP_Stack 18 * @{ 19 */ 20 21 /** 22 * @brief Integration layer for RTP Protocol stack integration with ImsMedia (IRtpSession) 23 */ 24 25 #ifndef __RTP_SERVICE_H_ 26 #define __RTP_SERVICE_H_ 27 28 #include <RtpGlobal.h> 29 #include <RtpServiceTypes.h> 30 #include <stdint.h> 31 32 #define GLOBAL 33 34 class RtpServiceListener 35 { 36 public: RtpServiceListener()37 RtpServiceListener() {} ~RtpServiceListener()38 virtual ~RtpServiceListener() {} 39 // receive RTP packet, send it to rtp tx node 40 virtual int OnRtpPacket(unsigned char* pData, RtpSvc_Length wLen) = 0; 41 // receive RTCP packet, send it to rtcp node 42 virtual int OnRtcpPacket(unsigned char* pData, RtpSvc_Length wLen) = 0; 43 // indication from the RtpStack 44 virtual void OnPeerInd(tRtpSvc_IndicationFromStack eIndType, void* pMsg) = 0; 45 // indication from the RtpStack 46 virtual void OnPeerRtcpComponents(void* nMsg) = 0; 47 }; 48 49 /** 50 * Initialized RTP Protocol Stack. This API should be called only once per 51 * lifecycle of the application. RTP Sessions can be created after successful 52 * return of this function. 53 */ 54 GLOBAL eRtp_Bool IMS_RtpSvc_Initialize(); 55 56 /** 57 * Deinitialized RTP Protocol Stack by freeying the memory used to manage RTPSessions. 58 * This API should be called at the end of lifecycle of the application. 59 */ 60 GLOBAL eRtp_Bool IMS_RtpSvc_Deinitialize(); 61 62 /** 63 * API should be used to create RTP Sessions. One RTP session per stream. 64 * Same RTP Session can be used for both sending and receiving a given payload type. 65 * 66 * @param szLocalIP LocalIP address on which RTP packets will be received. 67 * 68 * @param uiPort RTP port on which packets will be received. 69 * 70 * @param pAppData Data to be store with the RTP Session. 71 * 72 * @param puSsrc SSRC of the newly created session 73 * 74 * @param hRtpSession handle of the newly created session. 75 */ 76 GLOBAL eRtp_Bool IMS_RtpSvc_CreateSession(IN RtpDt_Char* szLocalIP, IN RtpDt_UInt32 port, 77 IN RtpDt_Void* pAppData, OUT RtpDt_UInt32* puSsrc, OUT RTPSESSIONID* hRtpSession); 78 79 /** 80 * This API should be called to set payload info of the RTP packets to be processed but 81 * the RTP Stack. 82 * 83 * @param hRtpSession A session handled to which payload params to be updated. 84 * 85 * @param pstPayloadInfo Array of payload info which contains payload type, sampling rate 86 * and framerate. 87 * 88 * @param bEnableXHdr Flag to enable CVO RTP extension header for VT streams. 89 * 90 * @param nNumOfPayloadParam Size of payload info array. If the RTP session has to process more 91 * than one payload types like Audio Frames and telephony-events then this array can be used. 92 */ 93 GLOBAL eRtp_Bool IMS_RtpSvc_SetPayload(IN RTPSESSIONID hRtpSession, 94 IN tRtpSvc_SetPayloadParam* pstPayloadInfo, IN eRtp_Bool bEnableXHdr, 95 IN RtpDt_UInt32 nNumOfPayloadParam); 96 97 /** 98 * This API can be used to set RTCP send interval. 99 * 100 * @param hRtpSession A session handled to which RTCP interval to be set. 101 * 102 * @param nInterval time difference between RTCP packets in seconds. 103 */ 104 GLOBAL eRtp_Bool IMS_RtpSvc_SetRTCPInterval(IN RTPSESSIONID hRtpSession, IN RtpDt_UInt32 nInterval); 105 106 /** 107 * API to delete RTP session. 108 * 109 * @param hRtpSession RTP session to be deleted. 110 */ 111 GLOBAL eRtp_Bool IMS_RtpSvc_DeleteSession(IN RTPSESSIONID hRtpSession); 112 113 /** 114 * This API is should be called by the application to RTP encode and send the media 115 * buffer to peer device. 116 * 117 * @param pobjRtpServiceListener media session Listener which will be used for sending the packet to 118 * network nodes after RTP encoding. 119 * 120 * @param hRtpSession A session handled associated with the media stream. 121 * 122 * @param pBuffer Media buffer to be transferred to peer device. 123 * 124 * @param wBufferLength Media buffer length in bytes. 125 * 126 * @param pstRtpParam Packet info such as marker-bit (used in case of fragmented media packets), 127 * payload-type number, Flag to use Previous RTP time-stamp (Ex: used in case of DTMF), 128 * time difference since last media packet/buffer. 129 */ 130 GLOBAL eRtp_Bool IMS_RtpSvc_SendRtpPacket(IN RtpServiceListener* pobjRtpServiceListener, 131 IN RTPSESSIONID hRtpSession, IN RtpDt_Char* pBuffer, IN RtpDt_UInt16 wBufferLength, 132 IN tRtpSvc_SendRtpPacketParam* pstRtpParam); 133 134 /** 135 * This API processes the received RTP packet. Processed information is sent using 136 * callback OnPeerInd. 137 * 138 * @param pobjRtpServiceListener media session Listener used to call callback function and 139 * pass extracted information back to the caller 140 * 141 * @param hRtpSession A session handled associated with the media stream. 142 * 143 * @param pMsg Received RTP packet buffer from Network node. 144 * 145 * @param uiMsgLength Length of RTP packet buffer in bytes. 146 * 147 * @param pPeerIp IP Address of the RTP packet sender. Used for SSRC collision check. 148 * 149 * @param uiPeerPort RTP port number. 150 * 151 * @param uiPeerSsrc SSRC of the Sender. 152 */ 153 GLOBAL eRtp_Bool IMS_RtpSvc_ProcRtpPacket(IN RtpServiceListener* pobjRtpServiceListener, 154 IN RTPSESSIONID hRtpSession, IN RtpDt_UChar* pMsg, IN RtpDt_UInt16 uiMsgLength, 155 IN RtpDt_Char* pPeerIp, IN RtpDt_UInt16 uiPeerPort, OUT RtpDt_UInt32& uiPeerSsrc); 156 157 /** 158 * This API starts the RTP session. After successful return, stack is ready to send and 159 * receive RTP packets. 160 * 161 * @param rtpSessionId A session handled associated with the media stream. 162 */ 163 GLOBAL eRtp_Bool IMS_RtpSvc_SessionEnableRTP(IN RTPSESSIONID rtpSessionId, IN eRtp_Bool bResetSsrc); 164 165 /** 166 * This API stops processing TX and RX RTP packets. 167 * 168 * @param rtpSessionId session which need to be stopped. 169 */ 170 171 GLOBAL eRtp_Bool IMS_RtpSvc_SessionDisableRTP(IN RTPSESSIONID rtpSessionId); 172 173 /** 174 * This API enables RTP session and starts sending periodic RTCP packets. 175 * 176 * @param hRtpSession RTP session to be started. 177 * 178 * @param enableRTCPBye Flag to control sending RTCP BYE packet when session is stopped. 179 */ 180 GLOBAL eRtp_Bool IMS_RtpSvc_SessionEnableRTCP( 181 IN RTPSESSIONID hRtpSession, IN eRtp_Bool enableRTCPBye); 182 183 /** 184 * This API stops RTCP timer and hence sending periodic RTCP packets. 185 */ 186 GLOBAL eRtp_Bool IMS_RtpSvc_SessionDisableRTCP(IN RTPSESSIONID hRtpSession); 187 188 /** 189 * This API should be used to send RTCP BYE packet. 190 * 191 * @param hRtpSession RTP session which should send BYE packet. 192 */ 193 GLOBAL eRtp_Bool IMS_RtpSvc_SendRtcpByePacket(IN RTPSESSIONID hRtpSession); 194 195 /** 196 * Method for sending RTP Fb message. 197 * 198 * @param hRtpSession pointer RtpSession 199 * @param uiFbType Feedback Type 200 * @param pcBuff FCI buffer 201 * @param uiLen FCI buffer length 202 * @param uiMediaSsrc SSRC of media source 203 */ 204 GLOBAL eRtp_Bool IMS_RtpSvc_SendRtcpRtpFbPacket(IN RTPSESSIONID hRtpSession, 205 IN RtpDt_UInt32 uiFbType, IN RtpDt_Char* pcBuff, IN RtpDt_UInt32 uiLen, 206 IN RtpDt_UInt32 uiMediaSsrc); 207 208 /** 209 * Method for sending RTCP Fb message. 210 * 211 * @param hRtpSession RtpSession 212 * @param uiFbType Feedback Type 213 * @param pcBuff FCI buffer 214 * @param uiLen FCI buffer length 215 * @param uiMediaSsrc SSRC of media source 216 */ 217 GLOBAL eRtp_Bool IMS_RtpSvc_SendRtcpPayloadFbPacket(IN RTPSESSIONID hRtpSession, 218 IN RtpDt_UInt32 uiFbType, IN RtpDt_Char* pcBuff, IN RtpDt_UInt32 uiLen, 219 IN RtpDt_UInt32 uiMediaSsrc); 220 221 /** 222 * Method for processing incoming RTCP packets. 223 * 224 * @param pobjRtpServiceListener Media session Listener for sending processed info via callbacks 225 * @param hRtpSession RTP session handle 226 * @param pMsg Received RTCP packet buffer 227 * @param uiMsgLength RTCP buffer length in bytes 228 * @param pcIpAddr Peer IP address 229 * @param uiRtcpPort RTCP Port number 230 * @param uiPeerSsrc SSRC of the Source 231 */ 232 GLOBAL eRtp_Bool IMS_RtpSvc_ProcRtcpPacket(IN RtpServiceListener* pobjRtpServiceListener, 233 IN RTPSESSIONID hRtpSession, IN RtpDt_UChar* pMsg, IN RtpDt_UInt16 uiMsgLength, 234 IN RtpDt_Char* pcIpAddr, IN RtpDt_UInt32 uiRtcpPort, OUT RtpDt_UInt32* uiPeerSsrc); 235 /** 236 * Method to set RTCP XR info. 237 * 238 * @param m_hRtpSession RTP session handle 239 * @param m_pBlockBuffer XR Block buffer 240 * @param nblockLength Buffer length in bytes 241 */ 242 GLOBAL eRtp_Bool IMS_RtpSvc_SendRtcpXrPacket( 243 IN RTPSESSIONID hRtpSession, IN RtpDt_UChar* m_pBlockBuffer, IN RtpDt_UInt16 nblockLength); 244 245 GLOBAL eRtp_Bool IMS_RtpSvc_SetRtpContext(IN RTPSESSIONID hRtpSession, IN RtpDt_UInt32 ssrc, 246 IN RtpDt_UInt32 timestamp, IN RtpDt_UInt16 seqNumber); 247 248 GLOBAL eRtp_Bool IMS_RtpSvc_GetRtpContext(IN RTPSESSIONID hRtpSession, IN RtpDt_UInt32& ssrc, 249 IN RtpDt_UInt32& timestamp, IN RtpDt_UInt16& seqNumber); 250 251 #endif /* __RTP_SERVICE_H_ */ 252 253 /** @}*/ 254