• Home
  • History
  • Annotate
  • 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 #include <RtcpConfigInfo.h>
18 #include <string.h>
19 
RtcpConfigInfo()20 RtcpConfigInfo::RtcpConfigInfo() :
21         m_uiSdesItemCnt(RTP_ZERO),
22         m_uiByeReasonSize(RTP_ZERO),
23         m_uiAppDepDataSize(RTP_ZERO),
24         m_bEnaRtcpAppPktSend(eRTP_FALSE)
25 {
26     for (RtpDt_UInt32 uiCount = RTP_ZERO; uiCount < RTP_MAX_SDES_TYPE; uiCount++)
27     {
28         m_arrSdesInfo[uiCount].pValue = nullptr;
29         m_arrSdesInfo[uiCount].ucType = RTP_ZERO;
30         m_arrSdesInfo[uiCount].ucLength = RTP_ZERO;
31     }
32 }  // RtcpConfigInfo
33 
~RtcpConfigInfo()34 RtcpConfigInfo::~RtcpConfigInfo()
35 {
36     for (RtpDt_UInt32 uiCount = RTP_ZERO; uiCount < RTP_MAX_SDES_TYPE; uiCount++)
37     {
38         if (m_arrSdesInfo[uiCount].pValue != nullptr)
39         {
40             delete[] m_arrSdesInfo[uiCount].pValue;
41             m_arrSdesInfo[uiCount].pValue = nullptr;
42             m_arrSdesInfo[uiCount].ucLength = 0;
43         }
44     }
45 }
46 
setByeReasonSize(IN RtpDt_UInt32 uiByeReason)47 RtpDt_Void RtcpConfigInfo::setByeReasonSize(IN RtpDt_UInt32 uiByeReason)
48 {
49     m_uiByeReasonSize = uiByeReason;
50 }
51 
getByeReasonSize()52 RtpDt_UInt32 RtcpConfigInfo::getByeReasonSize()
53 {
54     return m_uiByeReasonSize;
55 }
56 
setAppDepDataSize(IN RtpDt_UInt32 uiAppDepSize)57 RtpDt_Void RtcpConfigInfo::setAppDepDataSize(IN RtpDt_UInt32 uiAppDepSize)
58 {
59     m_uiAppDepDataSize = uiAppDepSize;
60 }
61 
getAppDepDataSize()62 RtpDt_UInt32 RtcpConfigInfo::getAppDepDataSize()
63 {
64     return m_uiAppDepDataSize;
65 }
66 
estimateSdesPktSize()67 RtpDt_UInt32 RtcpConfigInfo::estimateSdesPktSize()
68 {
69     RtpDt_UInt32 uiSdesPktSize = RTP_WORD_SIZE;
70     for (RtpDt_UInt32 uiCount = RTP_ZERO; uiCount < RTP_MAX_SDES_TYPE; uiCount++)
71     {
72         if (m_arrSdesInfo[uiCount].pValue != nullptr)
73         {
74             uiSdesPktSize += m_arrSdesInfo[uiCount].ucLength;
75             uiSdesPktSize += RTP_TWO;
76         }
77     }
78     RtpDt_UInt32 uiTmpSize = uiSdesPktSize % RTP_WORD_SIZE;
79     if (uiTmpSize != RTP_ZERO)
80     {
81         uiTmpSize = RTP_WORD_SIZE - uiTmpSize;
82     }
83     uiSdesPktSize = uiSdesPktSize + uiTmpSize;
84     return uiSdesPktSize;
85 }  // estimateSdesPktSize
86 
addRtcpSdesItem(IN tRTCP_SDES_ITEM * pstSdesItem,IN RtpDt_UInt32 uiIndex)87 eRtp_Bool RtcpConfigInfo::addRtcpSdesItem(IN tRTCP_SDES_ITEM* pstSdesItem, IN RtpDt_UInt32 uiIndex)
88 {
89     if (pstSdesItem == nullptr)
90     {
91         return eRTP_FAILURE;
92     }
93     m_arrSdesInfo[uiIndex].ucType = pstSdesItem->ucType;
94     m_arrSdesInfo[uiIndex].ucLength = pstSdesItem->ucLength;
95     if (pstSdesItem->ucLength > RTP_ZERO)
96     {
97         RtpDt_UChar* pcBuffer = new RtpDt_UChar[pstSdesItem->ucLength];
98         if (pcBuffer == nullptr)
99         {
100             return eRTP_FALSE;
101         }
102         memcpy(pcBuffer, pstSdesItem->pValue, pstSdesItem->ucLength);
103         if (m_arrSdesInfo[uiIndex].pValue != nullptr)
104         {
105             delete[] m_arrSdesInfo[uiIndex].pValue;
106         }
107 
108         m_arrSdesInfo[uiIndex].pValue = pcBuffer;
109     }
110     else
111     {
112         return eRTP_FALSE;
113     }
114     m_arrSdesInfo[uiIndex].uiFreq = pstSdesItem->uiFreq;
115 
116     m_uiSdesItemCnt++;
117     return eRTP_SUCCESS;
118 }
119 
enableRtcpAppPktSend()120 RtpDt_Void RtcpConfigInfo::enableRtcpAppPktSend()
121 {
122     m_bEnaRtcpAppPktSend = eRTP_SUCCESS;
123 }
124 
isRtcpAppPktSendEnable()125 eRtp_Bool RtcpConfigInfo::isRtcpAppPktSendEnable()
126 {
127     return m_bEnaRtcpAppPktSend;
128 }
129 
getSdesItemCount()130 RtpDt_UInt32 RtcpConfigInfo::getSdesItemCount()
131 {
132     return m_uiSdesItemCnt;
133 }
134 
setSdesItemCount(IN RtpDt_UInt32 uiSdesItemCnt)135 RtpDt_Void RtcpConfigInfo::setSdesItemCount(IN RtpDt_UInt32 uiSdesItemCnt)
136 {
137     m_uiSdesItemCnt = uiSdesItemCnt;
138 }
139 
getRtcpSdesItem(IN RtpDt_UInt32 uiIndex)140 tRTCP_SDES_ITEM* RtcpConfigInfo::getRtcpSdesItem(IN RtpDt_UInt32 uiIndex)
141 {
142     if (uiIndex >= RTP_MAX_SDES_TYPE)
143         return nullptr;
144 
145     return &m_arrSdesInfo[uiIndex];
146 }
147