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