Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : #ifndef _SDPHELPER_H_
6 : #define _SDPHELPER_H_
7 :
8 : #include "nsError.h"
9 :
10 : #include "signaling/src/sdp/SdpMediaSection.h"
11 : #include "signaling/src/sdp/SdpAttribute.h"
12 :
13 : #include "m_cpp_utils.h"
14 :
15 : #include <string>
16 : #include <map>
17 : #include <vector>
18 :
19 : namespace mozilla {
20 : class SdpMediaSection;
21 : class Sdp;
22 :
23 : class SdpHelper {
24 : public:
25 : enum MsectionBundleType {
26 : kNoBundle,
27 : kSlaveBundle,
28 : kMasterBundle
29 : };
30 :
31 : // Takes a std::string* into which error strings will be written for the
32 : // lifetime of the SdpHelper.
33 0 : explicit SdpHelper(std::string* errorDest) : mLastError(*errorDest) {}
34 0 : ~SdpHelper() {}
35 :
36 : nsresult GetComponent(const std::string& candidate, size_t* component);
37 : nsresult CopyTransportParams(size_t numComponents,
38 : const SdpMediaSection& source,
39 : SdpMediaSection* dest);
40 : bool AreOldTransportParamsValid(const Sdp& oldAnswer,
41 : const Sdp& offerersPreviousSdp,
42 : const Sdp& newOffer,
43 : size_t level);
44 : bool IceCredentialsDiffer(const SdpMediaSection& msection1,
45 : const SdpMediaSection& msection2);
46 :
47 : bool MsectionIsDisabled(const SdpMediaSection& msection) const;
48 : static void DisableMsection(Sdp* sdp, SdpMediaSection* msection);
49 :
50 : // Maps each mid to the m-section that is the master of its bundle.
51 : // Mids that do not appear in an a=group:BUNDLE do not appear here.
52 : typedef std::map<std::string, const SdpMediaSection*> BundledMids;
53 :
54 : nsresult GetBundledMids(const Sdp& sdp, BundledMids* bundledMids);
55 :
56 : bool IsBundleSlave(const Sdp& localSdp, uint16_t level);
57 : void GetBundleGroups(
58 : const Sdp& sdp,
59 : std::vector<SdpGroupAttributeList::Group>* groups) const;
60 :
61 : nsresult GetMidFromLevel(const Sdp& sdp,
62 : uint16_t level,
63 : std::string* mid);
64 : nsresult GetIdsFromMsid(const Sdp& sdp,
65 : const SdpMediaSection& msection,
66 : std::string* streamId,
67 : std::string* trackId);
68 : nsresult GetMsids(const SdpMediaSection& msection,
69 : std::vector<SdpMsidAttributeList::Msid>* msids);
70 : nsresult ParseMsid(const std::string& msidAttribute,
71 : std::string* streamId,
72 : std::string* trackId);
73 : nsresult AddCandidateToSdp(Sdp* sdp,
74 : const std::string& candidate,
75 : const std::string& mid,
76 : uint16_t level);
77 : void SetIceGatheringComplete(Sdp* sdp,
78 : uint16_t level,
79 : BundledMids bundledMids);
80 : void SetDefaultAddresses(const std::string& defaultCandidateAddr,
81 : uint16_t defaultCandidatePort,
82 : const std::string& defaultRtcpCandidateAddr,
83 : uint16_t defaultRtcpCandidatePort,
84 : Sdp* sdp,
85 : uint16_t level,
86 : BundledMids bundledMids);
87 : void SetDefaultAddresses(const std::string& defaultCandidateAddr,
88 : uint16_t defaultCandidatePort,
89 : const std::string& defaultRtcpCandidateAddr,
90 : uint16_t defaultRtcpCandidatePort,
91 : SdpMediaSection* msection);
92 : void SetupMsidSemantic(const std::vector<std::string>& msids,
93 : Sdp* sdp) const;
94 : MsectionBundleType GetMsectionBundleType(const Sdp& sdp,
95 : uint16_t level,
96 : BundledMids& bundledMids,
97 : std::string* masterMid) const;
98 :
99 : std::string GetCNAME(const SdpMediaSection& msection) const;
100 :
101 : SdpMediaSection* FindMsectionByMid(Sdp& sdp,
102 : const std::string& mid) const;
103 :
104 : const SdpMediaSection* FindMsectionByMid(const Sdp& sdp,
105 : const std::string& mid) const;
106 :
107 : nsresult CopyStickyParams(const SdpMediaSection& source,
108 : SdpMediaSection* dest);
109 : bool HasRtcp(SdpMediaSection::Protocol proto) const;
110 : static SdpMediaSection::Protocol GetProtocolForMediaType(
111 : SdpMediaSection::MediaType type);
112 : void appendSdpParseErrors(
113 : const std::vector<std::pair<size_t, std::string> >& aErrors,
114 : std::string* aErrorString);
115 :
116 : static bool GetPtAsInt(const std::string& ptString, uint16_t* ptOutparam);
117 :
118 : void AddCommonExtmaps(
119 : const SdpMediaSection& remoteMsection,
120 : const std::vector<SdpExtmapAttributeList::Extmap>& localExtensions,
121 : SdpMediaSection* localMsection);
122 :
123 : private:
124 : std::string& mLastError;
125 :
126 : DISALLOW_COPY_ASSIGN(SdpHelper);
127 : };
128 : } // namespace mozilla
129 :
130 : #endif // _SDPHELPER_H_
131 :
|