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 <RtpStack.h>
18 #include <RtpStackUtil.h>
19 #include <RtpTrace.h>
20
RtpStack()21 RtpStack::RtpStack() :
22 m_objRtpSessionList(std::list<RtpSession*>()),
23 m_pobjStackProfile(nullptr)
24 {
25 }
26
~RtpStack()27 RtpStack::~RtpStack()
28 {
29 // clear stack profile
30 if (m_pobjStackProfile != nullptr)
31 {
32 delete m_pobjStackProfile;
33 }
34
35 // delete all RTP session objects.
36 for (auto& pobjRtpSession : m_objRtpSessionList)
37 {
38 pobjRtpSession->deleteRtpSession();
39 }
40 m_objRtpSessionList.clear();
41 }
42
RtpStack(IN RtpStackProfile * pobjStackProfile)43 RtpStack::RtpStack(IN RtpStackProfile* pobjStackProfile)
44 {
45 m_pobjStackProfile = pobjStackProfile;
46 }
47
createRtpSession()48 RtpSession* RtpStack::createRtpSession()
49 {
50 RtpDt_UInt32 uiTermNum = m_pobjStackProfile->getTermNumber();
51
52 RtpSession* pobjRtpSession = new RtpSession(this);
53 if (pobjRtpSession == nullptr)
54 {
55 RTP_TRACE_WARNING("Memory allocation error.", RTP_ZERO, RTP_ZERO);
56 return nullptr;
57 }
58
59 // add session into m_objRtpSessionList
60 m_objRtpSessionList.push_back(pobjRtpSession);
61
62 // generate SSRC
63 RtpDt_UInt32 uiSsrc = RtpStackUtil::generateNewSsrc(uiTermNum);
64 pobjRtpSession->setSsrc(uiSsrc);
65
66 return pobjRtpSession;
67 }
68
isValidRtpSession(IN RtpSession * pobjSession)69 eRtp_Bool RtpStack::isValidRtpSession(IN RtpSession* pobjSession)
70 {
71 for (auto& pobjRtpSesItem : m_objRtpSessionList)
72 {
73 // get Rtp Session from list
74 if (pobjRtpSesItem->compareRtpSessions(pobjSession) == eRTP_SUCCESS)
75 {
76 return eRTP_SUCCESS;
77 }
78 }
79
80 return eRTP_FAILURE;
81 }
82
deleteRtpSession(IN RtpSession * pobjRtpSession)83 eRTP_STATUS_CODE RtpStack::deleteRtpSession(IN RtpSession* pobjRtpSession)
84 {
85 if (pobjRtpSession == nullptr)
86 {
87 RTP_TRACE_WARNING("deleteRtpSession, pobjRtpSession is NULL.", RTP_ZERO, RTP_ZERO);
88 return RTP_INVALID_PARAMS;
89 }
90
91 eRtp_Bool bisRtpSes = eRTP_SUCCESS;
92 bisRtpSes = isValidRtpSession(pobjRtpSession);
93
94 if (bisRtpSes == eRTP_SUCCESS)
95 {
96 pobjRtpSession->deleteRtpSession();
97 m_objRtpSessionList.remove(pobjRtpSession);
98
99 return RTP_SUCCESS;
100 }
101
102 return RTP_FAILURE;
103 }
104
getStackProfile()105 RtpStackProfile* RtpStack::getStackProfile()
106 {
107 return m_pobjStackProfile;
108 }
109
setStackProfile(IN RtpStackProfile * pobjStackProfile)110 RtpDt_Void RtpStack::setStackProfile(IN RtpStackProfile* pobjStackProfile)
111 {
112 m_pobjStackProfile = pobjStackProfile;
113 }
114