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 : /*
8 :
9 : ,-----. ,--. ,--.
10 : ' .--./ ,--,--.,--.,--.,-' '-.`--' ,---. ,--,--,
11 : | | ' ,-. || || |'-. .-',--.| .-. || `
12 : ' '--'\\ '-' |' '' ' | | | |' '-' '| || |
13 : `-----' `--`--' `----' `--' `--' `---' `--''--'
14 :
15 : :+o+-
16 : -dNNNNNd.
17 : yNNNNNNNs
18 : :mNNNNNm-
19 : `/sso/``-://-
20 : .:+sydNNNNNNms: `://`
21 : `-/+shmNNNNNNNNNNNNNNNms- :mNNNm/
22 : `-/oydmNNNNNNNNNNNNNNNNNNNNNNNNdo- +NNNNNN+
23 : .shmNNNNNNNNNNNmdyo/:dNNNNNNNNNNNNNNNNdo. `sNNNNNm+
24 : hNNNNNNNNmhs+:-` .dNNNNNNNNNNNNNNNNNNNNh+-` `hNNNNNm:
25 : -yddyo/:. -dNNNNm::ymNNNNNNNNNNNNNNNmdy+/dNNNNNd.
26 : :mNNNNd. `/ymNNNNNNNNNNNNNNNNNNNNNNh`
27 : +NNNNNh` `+hNNNNNNNNNNNNNNNNNNNs
28 : sNNNNNy` .yNNNNNm`-/oymNNNm+
29 : `yNNNNNo oNNNNNm` `-.
30 : .dNNNNm/ oNNNNNm`
31 : oNNNNm: +NNNNNm`
32 : `+yho. +NNNNNm`
33 : +NNNNNNs.
34 : `yNNNNNNmy-
35 : -smNNNNNNh:
36 : .smNNNNNNh/
37 : `omNNNNNNd:
38 : `+dNNNNNd
39 : ````......```` /hmdy-
40 : `.:/+osyhddmNNMMMMMMMMMMMMMMMMMMMMNNmddhyso+/:.`
41 : `-+shmNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmhs+-`
42 : -smMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMds-
43 : hMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMh
44 : yMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMs
45 : .ohNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNh+.
46 : ./oydmMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMmhyo:.
47 : `.:/+osyyhddmmNNMMMMMMMMMMMMMMNNmmddhyyso+/:.`
48 :
49 : ,--------.,--. ,--. ,--.
50 : '--. .--'| ,---. `--' ,---. | | ,---.
51 : | | | .-. |,--.( .-' | |( .-'
52 : | | | | | || |.-' `) | |.-' `)
53 : `--' `--' `--'`--'`----' `--'`----'
54 : ,--.
55 : ,---. ,------. ,------. ,--. | |
56 : ' .-' | .-. \ | .--. ' ,--,--.,--.--.,-' '-. ,--,--.| |
57 : `. `-. | | \ :| '--' |' ,-. || .--''-. .-'' ,-. || |
58 : .-' || '--' /| | --' \ '-' || | | | \ '-' |`--'
59 : `-----' `-------' `--' `--`--'`--' `--' `--`--'.--.
60 : '__'
61 : */
62 :
63 : #ifndef _SDP_H_
64 : #define _SDP_H_
65 :
66 : #include <ostream>
67 : #include <vector>
68 : #include <sstream>
69 : #include "mozilla/UniquePtr.h"
70 : #include "mozilla/Maybe.h"
71 : #include "signaling/src/sdp/SdpMediaSection.h"
72 : #include "signaling/src/sdp/SdpAttributeList.h"
73 : #include "signaling/src/sdp/SdpEnum.h"
74 :
75 : namespace mozilla
76 : {
77 :
78 : class SdpOrigin;
79 : class SdpEncryptionKey;
80 : class SdpMediaSection;
81 :
82 : /**
83 : * Base class for an SDP
84 : */
85 : class Sdp
86 : {
87 : public:
88 0 : Sdp(){};
89 0 : virtual ~Sdp(){};
90 :
91 : virtual const SdpOrigin& GetOrigin() const = 0;
92 : // Note: connection information is always retrieved from media sections
93 : virtual uint32_t GetBandwidth(const std::string& type) const = 0;
94 :
95 : virtual const SdpAttributeList& GetAttributeList() const = 0;
96 : virtual SdpAttributeList& GetAttributeList() = 0;
97 :
98 : virtual size_t GetMediaSectionCount() const = 0;
99 : virtual const SdpMediaSection& GetMediaSection(size_t level) const = 0;
100 : virtual SdpMediaSection& GetMediaSection(size_t level) = 0;
101 :
102 : virtual SdpMediaSection& AddMediaSection(SdpMediaSection::MediaType media,
103 : SdpDirectionAttribute::Direction dir,
104 : uint16_t port,
105 : SdpMediaSection::Protocol proto,
106 : sdp::AddrType addrType,
107 : const std::string& addr) = 0;
108 :
109 : virtual void Serialize(std::ostream&) const = 0;
110 :
111 : std::string ToString() const;
112 : };
113 :
114 0 : inline std::ostream& operator<<(std::ostream& os, const Sdp& sdp)
115 : {
116 0 : sdp.Serialize(os);
117 0 : return os;
118 : }
119 :
120 : inline std::string
121 0 : Sdp::ToString() const
122 : {
123 0 : std::stringstream s;
124 0 : s << *this;
125 0 : return s.str();
126 : }
127 :
128 0 : class SdpOrigin
129 : {
130 : public:
131 0 : SdpOrigin(const std::string& username, uint64_t sessId, uint64_t sessVer,
132 : sdp::AddrType addrType, const std::string& addr)
133 0 : : mUsername(username),
134 : mSessionId(sessId),
135 : mSessionVersion(sessVer),
136 : mAddrType(addrType),
137 0 : mAddress(addr)
138 : {
139 0 : }
140 :
141 : const std::string&
142 : GetUsername() const
143 : {
144 : return mUsername;
145 : }
146 :
147 : uint64_t
148 : GetSessionId() const
149 : {
150 : return mSessionId;
151 : }
152 :
153 : uint64_t
154 : GetSessionVersion() const
155 : {
156 : return mSessionVersion;
157 : }
158 :
159 : sdp::AddrType
160 : GetAddrType() const
161 : {
162 : return mAddrType;
163 : }
164 :
165 : const std::string&
166 : GetAddress() const
167 : {
168 : return mAddress;
169 : }
170 :
171 : void
172 0 : Serialize(std::ostream& os) const
173 : {
174 0 : sdp::NetType netType = sdp::kInternet;
175 0 : os << "o=" << mUsername << " " << mSessionId << " " << mSessionVersion
176 0 : << " " << netType << " " << mAddrType << " " << mAddress << "\r\n";
177 0 : }
178 :
179 : private:
180 : std::string mUsername;
181 : uint64_t mSessionId;
182 : uint64_t mSessionVersion;
183 : sdp::AddrType mAddrType;
184 : std::string mAddress;
185 : };
186 :
187 0 : inline std::ostream& operator<<(std::ostream& os, const SdpOrigin& origin)
188 : {
189 0 : origin.Serialize(os);
190 0 : return os;
191 : }
192 :
193 : } // namespace mozilla
194 :
195 : #endif
|