Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "signaling/src/sdp/SdpMediaSection.h"
8 :
9 : namespace mozilla
10 : {
11 : const SdpFmtpAttributeList::Parameters*
12 0 : SdpMediaSection::FindFmtp(const std::string& pt) const
13 : {
14 0 : const SdpAttributeList& attrs = GetAttributeList();
15 :
16 0 : if (attrs.HasAttribute(SdpAttribute::kFmtpAttribute)) {
17 0 : for (auto& fmtpAttr : attrs.GetFmtp().mFmtps) {
18 0 : if (fmtpAttr.format == pt && fmtpAttr.parameters) {
19 0 : return fmtpAttr.parameters.get();
20 : }
21 : }
22 : }
23 0 : return nullptr;
24 : }
25 :
26 : void
27 0 : SdpMediaSection::SetFmtp(const SdpFmtpAttributeList::Fmtp& fmtpToSet)
28 : {
29 0 : UniquePtr<SdpFmtpAttributeList> fmtps(new SdpFmtpAttributeList);
30 :
31 0 : if (GetAttributeList().HasAttribute(SdpAttribute::kFmtpAttribute)) {
32 0 : *fmtps = GetAttributeList().GetFmtp();
33 : }
34 :
35 0 : bool found = false;
36 0 : for (SdpFmtpAttributeList::Fmtp& fmtp : fmtps->mFmtps) {
37 0 : if (fmtp.format == fmtpToSet.format) {
38 0 : fmtp = fmtpToSet;
39 0 : found = true;
40 : }
41 : }
42 :
43 0 : if (!found) {
44 0 : fmtps->mFmtps.push_back(fmtpToSet);
45 : }
46 :
47 0 : GetAttributeList().SetAttribute(fmtps.release());
48 0 : }
49 :
50 : void
51 0 : SdpMediaSection::RemoveFmtp(const std::string& pt)
52 : {
53 0 : UniquePtr<SdpFmtpAttributeList> fmtps(new SdpFmtpAttributeList);
54 :
55 0 : SdpAttributeList& attrList = GetAttributeList();
56 0 : if (attrList.HasAttribute(SdpAttribute::kFmtpAttribute)) {
57 0 : *fmtps = attrList.GetFmtp();
58 : }
59 :
60 0 : for (size_t i = 0; i < fmtps->mFmtps.size(); ++i) {
61 0 : if (pt == fmtps->mFmtps[i].format) {
62 0 : fmtps->mFmtps.erase(fmtps->mFmtps.begin() + i);
63 0 : break;
64 : }
65 : }
66 :
67 0 : attrList.SetAttribute(fmtps.release());
68 0 : }
69 :
70 : const SdpRtpmapAttributeList::Rtpmap*
71 0 : SdpMediaSection::FindRtpmap(const std::string& pt) const
72 : {
73 0 : auto& attrs = GetAttributeList();
74 0 : if (!attrs.HasAttribute(SdpAttribute::kRtpmapAttribute)) {
75 0 : return nullptr;
76 : }
77 :
78 0 : const SdpRtpmapAttributeList& rtpmap = attrs.GetRtpmap();
79 0 : if (!rtpmap.HasEntry(pt)) {
80 0 : return nullptr;
81 : }
82 :
83 0 : return &rtpmap.GetEntry(pt);
84 : }
85 :
86 : const SdpSctpmapAttributeList::Sctpmap*
87 0 : SdpMediaSection::GetSctpmap() const
88 : {
89 0 : auto& attrs = GetAttributeList();
90 0 : if (!attrs.HasAttribute(SdpAttribute::kSctpmapAttribute)) {
91 0 : return nullptr;
92 : }
93 :
94 0 : const SdpSctpmapAttributeList& sctpmap = attrs.GetSctpmap();
95 0 : if (!sctpmap.mSctpmaps.size()) {
96 0 : return nullptr;
97 : }
98 :
99 0 : return &sctpmap.GetFirstEntry();
100 : }
101 :
102 : uint32_t
103 0 : SdpMediaSection::GetSctpPort() const
104 : {
105 0 : auto& attrs = GetAttributeList();
106 0 : if (!attrs.HasAttribute(SdpAttribute::kSctpPortAttribute)) {
107 0 : return 0;
108 : }
109 :
110 0 : return attrs.GetSctpPort();
111 : }
112 :
113 : bool
114 0 : SdpMediaSection::GetMaxMessageSize(uint32_t* size) const
115 : {
116 0 : *size = 0;
117 :
118 0 : auto& attrs = GetAttributeList();
119 0 : if (!attrs.HasAttribute(SdpAttribute::kMaxMessageSizeAttribute)) {
120 0 : return false;
121 : }
122 :
123 0 : *size = attrs.GetMaxMessageSize();
124 0 : return true;
125 : }
126 :
127 : bool
128 0 : SdpMediaSection::HasRtcpFb(const std::string& pt,
129 : SdpRtcpFbAttributeList::Type type,
130 : const std::string& subType) const
131 : {
132 0 : const SdpAttributeList& attrs(GetAttributeList());
133 :
134 0 : if (!attrs.HasAttribute(SdpAttribute::kRtcpFbAttribute)) {
135 0 : return false;
136 : }
137 :
138 0 : for (auto& rtcpfb : attrs.GetRtcpFb().mFeedbacks) {
139 0 : if (rtcpfb.type == type) {
140 0 : if (rtcpfb.pt == "*" || rtcpfb.pt == pt) {
141 0 : if (rtcpfb.parameter == subType) {
142 0 : return true;
143 : }
144 : }
145 : }
146 : }
147 :
148 0 : return false;
149 : }
150 :
151 : SdpRtcpFbAttributeList
152 0 : SdpMediaSection::GetRtcpFbs() const
153 : {
154 0 : SdpRtcpFbAttributeList result;
155 0 : if (GetAttributeList().HasAttribute(SdpAttribute::kRtcpFbAttribute)) {
156 0 : result = GetAttributeList().GetRtcpFb();
157 : }
158 0 : return result;
159 : }
160 :
161 : void
162 0 : SdpMediaSection::SetRtcpFbs(const SdpRtcpFbAttributeList& rtcpfbs)
163 : {
164 0 : if (rtcpfbs.mFeedbacks.empty()) {
165 0 : GetAttributeList().RemoveAttribute(SdpAttribute::kRtcpFbAttribute);
166 0 : return;
167 : }
168 :
169 0 : GetAttributeList().SetAttribute(new SdpRtcpFbAttributeList(rtcpfbs));
170 : }
171 :
172 : void
173 0 : SdpMediaSection::SetSsrcs(const std::vector<uint32_t>& ssrcs,
174 : const std::string& cname)
175 : {
176 0 : if (ssrcs.empty()) {
177 0 : GetAttributeList().RemoveAttribute(SdpAttribute::kSsrcAttribute);
178 0 : return;
179 : }
180 :
181 0 : UniquePtr<SdpSsrcAttributeList> ssrcAttr(new SdpSsrcAttributeList);
182 0 : for (auto ssrc : ssrcs) {
183 : // When using ssrc attributes, we are required to at least have a cname.
184 : // (See https://tools.ietf.org/html/rfc5576#section-6.1)
185 0 : std::string cnameAttr("cname:");
186 0 : cnameAttr += cname;
187 0 : ssrcAttr->PushEntry(ssrc, cnameAttr);
188 : }
189 :
190 0 : GetAttributeList().SetAttribute(ssrcAttr.release());
191 : }
192 :
193 : void
194 0 : SdpMediaSection::AddMsid(const std::string& id, const std::string& appdata)
195 : {
196 0 : UniquePtr<SdpMsidAttributeList> msids(new SdpMsidAttributeList);
197 0 : if (GetAttributeList().HasAttribute(SdpAttribute::kMsidAttribute)) {
198 0 : msids->mMsids = GetAttributeList().GetMsid().mMsids;
199 : }
200 0 : msids->PushEntry(id, appdata);
201 0 : GetAttributeList().SetAttribute(msids.release());
202 0 : }
203 :
204 : const SdpRidAttributeList::Rid*
205 0 : SdpMediaSection::FindRid(const std::string& id) const
206 : {
207 0 : if (!GetAttributeList().HasAttribute(SdpAttribute::kRidAttribute)) {
208 0 : return nullptr;
209 : }
210 :
211 0 : for (const auto& rid : GetAttributeList().GetRid().mRids) {
212 0 : if (rid.id == id) {
213 0 : return &rid;
214 : }
215 : }
216 :
217 0 : return nullptr;
218 : }
219 :
220 : } // namespace mozilla
221 :
|