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 #include <ImsMediaTimer.h>
18 #include <RtpImpl.h>
19 #include <RtpService.h>
20 #include <RtpTrace.h>
21 #include <string>
22
RtpImpl()23 RtpImpl::RtpImpl()
24 {
25 m_pvAppdata = nullptr;
26 }
27
~RtpImpl()28 RtpImpl::~RtpImpl() {}
29
rtpSsrcCollisionInd(IN RtpDt_Int32 uiOldSsrc,IN RtpDt_Int32 uiNewSsrc)30 eRtp_Bool RtpImpl::rtpSsrcCollisionInd(IN RtpDt_Int32 uiOldSsrc, IN RtpDt_Int32 uiNewSsrc)
31 {
32 (RtpDt_Void) uiOldSsrc, (RtpDt_Void)uiNewSsrc;
33 return eRTP_FALSE;
34 }
35
setAppdata(IN RtpDt_Void * pvAppdata)36 RtpDt_Void RtpImpl::setAppdata(IN RtpDt_Void* pvAppdata)
37 {
38 m_pvAppdata = pvAppdata;
39 }
40
getAppdata()41 RtpDt_Void* RtpImpl::getAppdata()
42 {
43 return m_pvAppdata;
44 }
45
rtpNewMemberJoinInd(IN RtpDt_Int32 uiSsrc)46 eRtp_Bool RtpImpl::rtpNewMemberJoinInd(IN RtpDt_Int32 uiSsrc)
47 {
48 (RtpDt_Void) uiSsrc;
49 return eRTP_FALSE;
50 }
51
rtpMemberLeaveInd(IN eRTP_LEAVE_REASON eLeaveReason,IN RtpDt_Int32 uiSsrc)52 eRtp_Bool RtpImpl::rtpMemberLeaveInd(IN eRTP_LEAVE_REASON eLeaveReason, IN RtpDt_Int32 uiSsrc)
53 {
54 (RtpDt_Void) eLeaveReason, (RtpDt_Void)uiSsrc;
55 return eRTP_FALSE;
56 }
57
rtcpPacketSendInd(IN RtpBuffer * pobjRtcpBuf,IN RtpSession * pobjRtpSession)58 eRtp_Bool RtpImpl::rtcpPacketSendInd(IN RtpBuffer* pobjRtcpBuf, IN RtpSession* pobjRtpSession)
59 {
60 RTP_TRACE_MESSAGE("rtcpPacketSendInd", 0, 0);
61 RtpServiceListener* pobjRtpServiceListener =
62 reinterpret_cast<RtpServiceListener*>(getAppdata());
63 if (pobjRtpServiceListener == nullptr || pobjRtcpBuf == nullptr || pobjRtpSession == nullptr)
64 {
65 RTP_TRACE_ERROR("RTCP send failed. No listeners are set", 0, 0);
66 return eRTP_FALSE;
67 }
68
69 // dispatch to peer
70 if (pobjRtpServiceListener->OnRtcpPacket(pobjRtcpBuf->getBuffer(), pobjRtcpBuf->getLength()) ==
71 -1)
72 {
73 RTP_TRACE_ERROR("Send RTCP: IRTPSession returned Error", 0, 0);
74 pobjRtcpBuf->setBufferInfo(RTP_ZERO, nullptr);
75 return eRTP_FALSE;
76 }
77
78 return eRTP_TRUE;
79 }
80
rtcpAppPayloadReqInd(OUT RtpDt_UInt16 & pusSubType,OUT RtpDt_UInt32 & uiName,OUT RtpBuffer * pobjPayload)81 eRtp_Bool RtpImpl::rtcpAppPayloadReqInd(
82 OUT RtpDt_UInt16& pusSubType, OUT RtpDt_UInt32& uiName, OUT RtpBuffer* pobjPayload)
83 {
84 if (pobjPayload == nullptr)
85 {
86 return eRTP_FALSE;
87 }
88
89 (RtpDt_Void) pusSubType, (RtpDt_Void)uiName, (RtpDt_Void)pobjPayload;
90 // To be implemented when Application-Defined RTCP Packet Type feature has to be enabled
91
92 return eRTP_TRUE;
93 }
94
getRtpHdrExtInfo(OUT RtpBuffer * pobjExtHdrInfo)95 eRtp_Bool RtpImpl::getRtpHdrExtInfo(OUT RtpBuffer* pobjExtHdrInfo)
96 {
97 if (pobjExtHdrInfo == nullptr)
98 {
99 return eRTP_FALSE;
100 }
101
102 // allocated memory will be released by the RTP stack
103 std::string extInfo("extension header info");
104 RtpDt_UChar* pcExtHdrInfo = new RtpDt_UChar[extInfo.size() + 1];
105 strlcpy(reinterpret_cast<RtpDt_Char*>(pcExtHdrInfo), extInfo.data(), extInfo.size() + 1);
106 pobjExtHdrInfo->setBufferInfo(extInfo.size(), pcExtHdrInfo);
107 return eRTP_TRUE;
108 }
109
deleteRcvrInfo(RtpDt_UInt32 uiRemoteSsrc,RtpBuffer * pobjDestAddr,RtpDt_UInt16 usRemotePort)110 eRtp_Bool RtpImpl::deleteRcvrInfo(
111 RtpDt_UInt32 uiRemoteSsrc, RtpBuffer* pobjDestAddr, RtpDt_UInt16 usRemotePort)
112 {
113 (RtpDt_Void) uiRemoteSsrc, (RtpDt_Void)pobjDestAddr, (RtpDt_Void)usRemotePort;
114 return eRTP_TRUE;
115 }
116
rtcpTimerHdlErrorInd(IN eRTP_STATUS_CODE eStatus)117 eRtp_Bool RtpImpl::rtcpTimerHdlErrorInd(IN eRTP_STATUS_CODE eStatus)
118 {
119 (RtpDt_Void) eStatus;
120 return eRTP_TRUE;
121 }
122
RtpStartTimer(IN RtpDt_UInt32 uiDuration,IN eRtp_Bool bRepeat,IN RTPCB_TIMERHANDLER pfnTimerCb,IN RtpDt_Void * pvData)123 RtpDt_Void* RtpImpl::RtpStartTimer(IN RtpDt_UInt32 uiDuration, IN eRtp_Bool bRepeat,
124 IN RTPCB_TIMERHANDLER pfnTimerCb, IN RtpDt_Void* pvData)
125 {
126 RtpDt_Void* pvTimerId = reinterpret_cast<RtpDt_Void*>(ImsMediaTimer::TimerStart(
127 (RtpDt_UInt32)uiDuration, (bool)bRepeat, (fn_TimerCb)pfnTimerCb, pvData));
128
129 RTP_TRACE_MESSAGE("RtpStartTimer pvTimerId[%x], Duration= [%d]", pvTimerId, uiDuration);
130 return pvTimerId;
131 }
132
RtpStopTimer(IN RtpDt_Void * pTimerId,OUT RtpDt_Void ** ppUserData)133 eRtp_Bool RtpImpl::RtpStopTimer(IN RtpDt_Void* pTimerId, OUT RtpDt_Void** ppUserData)
134 {
135 RTP_TRACE_MESSAGE("RtpStopTimer pvTimerId[%x]", pTimerId, 0);
136 ImsMediaTimer::TimerStop((hTimerHandler)pTimerId, ppUserData);
137 (void)ppUserData;
138 return eRTP_TRUE;
139 }
140