summaryrefslogtreecommitdiffstats
path: root/media/webrtc/signaling/src/sdp/SdpHelper.h
blob: 21940f280fea3e3796aa7cdddd1ed25ae43949fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef _SDPHELPER_H_
#define _SDPHELPER_H_

#include "nsError.h"

#include "signaling/src/sdp/SdpMediaSection.h"
#include "signaling/src/sdp/SdpAttribute.h"

#include "m_cpp_utils.h"

#include <string>
#include <map>
#include <vector>

namespace mozilla {
class SdpMediaSection;
class Sdp;

class SdpHelper {
  public:
    enum MsectionBundleType {
      kNoBundle,
      kSlaveBundle,
      kMasterBundle
    };

    // Takes a std::string* into which error strings will be written for the
    // lifetime of the SdpHelper.
    explicit SdpHelper(std::string* errorDest) : mLastError(*errorDest) {}
    ~SdpHelper() {}

    nsresult GetComponent(const std::string& candidate, size_t* component);
    nsresult CopyTransportParams(size_t numComponents,
                                 const SdpMediaSection& source,
                                 SdpMediaSection* dest);
    bool AreOldTransportParamsValid(const Sdp& oldAnswer,
                                    const Sdp& offerersPreviousSdp,
                                    const Sdp& newOffer,
                                    size_t level);
    bool IceCredentialsDiffer(const SdpMediaSection& msection1,
                              const SdpMediaSection& msection2);

    bool MsectionIsDisabled(const SdpMediaSection& msection) const;
    static void DisableMsection(Sdp* sdp, SdpMediaSection* msection);

    // Maps each mid to the m-section that is the master of its bundle.
    // Mids that do not appear in an a=group:BUNDLE do not appear here.
    typedef std::map<std::string, const SdpMediaSection*> BundledMids;

    nsresult GetBundledMids(const Sdp& sdp, BundledMids* bundledMids);

    bool IsBundleSlave(const Sdp& localSdp, uint16_t level);
    void GetBundleGroups(
        const Sdp& sdp,
        std::vector<SdpGroupAttributeList::Group>* groups) const;

    nsresult GetMidFromLevel(const Sdp& sdp,
                             uint16_t level,
                             std::string* mid);
    nsresult GetIdsFromMsid(const Sdp& sdp,
                            const SdpMediaSection& msection,
                            std::string* streamId,
                            std::string* trackId);
    nsresult GetMsids(const SdpMediaSection& msection,
                      std::vector<SdpMsidAttributeList::Msid>* msids);
    nsresult ParseMsid(const std::string& msidAttribute,
                       std::string* streamId,
                       std::string* trackId);
    nsresult AddCandidateToSdp(Sdp* sdp,
                               const std::string& candidate,
                               const std::string& mid,
                               uint16_t level);
    void SetIceGatheringComplete(Sdp* sdp,
                                 uint16_t level,
                                 BundledMids bundledMids);
    void SetDefaultAddresses(const std::string& defaultCandidateAddr,
                             uint16_t defaultCandidatePort,
                             const std::string& defaultRtcpCandidateAddr,
                             uint16_t defaultRtcpCandidatePort,
                             Sdp* sdp,
                             uint16_t level,
                             BundledMids bundledMids);
    void SetDefaultAddresses(const std::string& defaultCandidateAddr,
                             uint16_t defaultCandidatePort,
                             const std::string& defaultRtcpCandidateAddr,
                             uint16_t defaultRtcpCandidatePort,
                             SdpMediaSection* msection);
    void SetupMsidSemantic(const std::vector<std::string>& msids,
                           Sdp* sdp) const;
    MsectionBundleType GetMsectionBundleType(const Sdp& sdp,
                                             uint16_t level,
                                             BundledMids& bundledMids,
                                             std::string* masterMid) const;

    std::string GetCNAME(const SdpMediaSection& msection) const;

    SdpMediaSection* FindMsectionByMid(Sdp& sdp,
                                       const std::string& mid) const;

    const SdpMediaSection* FindMsectionByMid(const Sdp& sdp,
                                             const std::string& mid) const;

    nsresult CopyStickyParams(const SdpMediaSection& source,
                              SdpMediaSection* dest);
    bool HasRtcp(SdpMediaSection::Protocol proto) const;
    static SdpMediaSection::Protocol GetProtocolForMediaType(
        SdpMediaSection::MediaType type);
    void appendSdpParseErrors(
          const std::vector<std::pair<size_t, std::string> >& aErrors,
          std::string* aErrorString);

    static bool GetPtAsInt(const std::string& ptString, uint16_t* ptOutparam);

    void AddCommonExtmaps(
        const SdpMediaSection& remoteMsection,
        const std::vector<SdpExtmapAttributeList::Extmap>& localExtensions,
        SdpMediaSection* localMsection);

  private:
    std::string& mLastError;

    DISALLOW_COPY_ASSIGN(SdpHelper);
};
} // namespace mozilla

#endif // _SDPHELPER_H_