summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/sdp/SipccSdpAttributeList.h
blob: 4499e84bb986af3c547a2deb542942cabb6c5c40 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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 _SIPCCSDPATTRIBUTELIST_H_
#define _SIPCCSDPATTRIBUTELIST_H_

#include "sdp/SdpParser.h"
#include "sdp/SdpAttributeList.h"

extern "C" {
#include "sipcc_sdp.h"
}

namespace mozilla {

class SipccSdp;
class SipccSdpMediaSection;

class SipccSdpAttributeList : public SdpAttributeList {
  friend class SipccSdpMediaSection;
  friend class SipccSdp;

 public:
  // Make sure we don't hide the default arg thunks
  using SdpAttributeList::GetAttribute;
  using SdpAttributeList::HasAttribute;

  virtual bool HasAttribute(AttributeType type,
                            bool sessionFallback) const override;
  virtual const SdpAttribute* GetAttribute(AttributeType type,
                                           bool sessionFallback) const override;
  virtual void SetAttribute(SdpAttribute* attr) override;
  virtual void RemoveAttribute(AttributeType type) override;
  virtual void Clear() override;
  virtual uint32_t Count() const override;

  virtual const SdpConnectionAttribute& GetConnection() const override;
  virtual const SdpFingerprintAttributeList& GetFingerprint() const override;
  virtual const SdpGroupAttributeList& GetGroup() const override;
  virtual const SdpOptionsAttribute& GetIceOptions() const override;
  virtual const SdpRtcpAttribute& GetRtcp() const override;
  virtual const SdpRemoteCandidatesAttribute& GetRemoteCandidates()
      const override;
  virtual const SdpSetupAttribute& GetSetup() const override;
  virtual const SdpSsrcAttributeList& GetSsrc() const override;
  virtual const SdpSsrcGroupAttributeList& GetSsrcGroup() const override;
  virtual const SdpDtlsMessageAttribute& GetDtlsMessage() const override;

  // These attributes can appear multiple times, so the returned
  // classes actually represent a collection of values.
  virtual const std::vector<std::string>& GetCandidate() const override;
  virtual const SdpExtmapAttributeList& GetExtmap() const override;
  virtual const SdpFmtpAttributeList& GetFmtp() const override;
  virtual const SdpImageattrAttributeList& GetImageattr() const override;
  const SdpSimulcastAttribute& GetSimulcast() const override;
  virtual const SdpMsidAttributeList& GetMsid() const override;
  virtual const SdpMsidSemanticAttributeList& GetMsidSemantic() const override;
  const SdpRidAttributeList& GetRid() const override;
  virtual const SdpRtcpFbAttributeList& GetRtcpFb() const override;
  virtual const SdpRtpmapAttributeList& GetRtpmap() const override;
  virtual const SdpSctpmapAttributeList& GetSctpmap() const override;
  virtual uint32_t GetSctpPort() const override;
  virtual uint32_t GetMaxMessageSize() const override;

  // These attributes are effectively simple types, so we'll make life
  // easy by just returning their value.
  virtual const std::string& GetIcePwd() const override;
  virtual const std::string& GetIceUfrag() const override;
  virtual const std::string& GetIdentity() const override;
  virtual const std::string& GetLabel() const override;
  virtual unsigned int GetMaxptime() const override;
  virtual const std::string& GetMid() const override;
  virtual unsigned int GetPtime() const override;

  virtual SdpDirectionAttribute::Direction GetDirection() const override;

  virtual void Serialize(std::ostream&) const override;

  virtual ~SipccSdpAttributeList();

 private:
  static const std::string kEmptyString;
  static const size_t kNumAttributeTypes = SdpAttribute::kLastAttribute + 1;

  // Pass a session-level attribute list if constructing a media-level one,
  // otherwise pass nullptr
  explicit SipccSdpAttributeList(const SipccSdpAttributeList* sessionLevel);

  // Copy c'tor, sort of
  SipccSdpAttributeList(const SipccSdpAttributeList& aOrig,
                        const SipccSdpAttributeList* sessionLevel);

  using InternalResults = SdpParser::InternalResults;

  bool Load(sdp_t* sdp, uint16_t level, InternalResults& results);
  void LoadSimpleStrings(sdp_t* sdp, uint16_t level, InternalResults& results);
  void LoadSimpleString(sdp_t* sdp, uint16_t level, sdp_attr_e attr,
                        AttributeType targetType, InternalResults& results);
  void LoadSimpleNumbers(sdp_t* sdp, uint16_t level, InternalResults& results);
  void LoadSimpleNumber(sdp_t* sdp, uint16_t level, sdp_attr_e attr,
                        AttributeType targetType, InternalResults& results);
  void LoadFlags(sdp_t* sdp, uint16_t level);
  void LoadDirection(sdp_t* sdp, uint16_t level, InternalResults& results);
  bool LoadRtpmap(sdp_t* sdp, uint16_t level, InternalResults& results);
  bool LoadSctpmap(sdp_t* sdp, uint16_t level, InternalResults& results);
  void LoadIceAttributes(sdp_t* sdp, uint16_t level);
  bool LoadFingerprint(sdp_t* sdp, uint16_t level, InternalResults& results);
  void LoadCandidate(sdp_t* sdp, uint16_t level);
  void LoadSetup(sdp_t* sdp, uint16_t level);
  void LoadSsrc(sdp_t* sdp, uint16_t level);
  void LoadSsrcGroup(sdp_t* sdp, uint16_t level);
  bool LoadImageattr(sdp_t* sdp, uint16_t level, InternalResults& results);
  bool LoadSimulcast(sdp_t* sdp, uint16_t level, InternalResults& results);
  bool LoadGroups(sdp_t* sdp, uint16_t level, InternalResults& results);
  bool LoadMsidSemantics(sdp_t* sdp, uint16_t level, InternalResults& results);
  void LoadIdentity(sdp_t* sdp, uint16_t level);
  void LoadDtlsMessage(sdp_t* sdp, uint16_t level);
  void LoadFmtp(sdp_t* sdp, uint16_t level);
  void LoadMsids(sdp_t* sdp, uint16_t level, InternalResults& results);
  bool LoadRid(sdp_t* sdp, uint16_t level, InternalResults& results);
  void LoadExtmap(sdp_t* sdp, uint16_t level, InternalResults& results);
  void LoadRtcpFb(sdp_t* sdp, uint16_t level, InternalResults& results);
  void LoadRtcp(sdp_t* sdp, uint16_t level, InternalResults& results);
  static SdpRtpmapAttributeList::CodecType GetCodecType(rtp_ptype type);

  bool AtSessionLevel() const { return !mSessionLevel; }
  bool IsAllowedHere(SdpAttribute::AttributeType type) const;
  void WarnAboutMisplacedAttribute(SdpAttribute::AttributeType type,
                                   uint32_t lineNumber,
                                   InternalResults& results);

  const SipccSdpAttributeList* mSessionLevel;

  SdpAttribute* mAttributes[kNumAttributeTypes];

  SipccSdpAttributeList(const SipccSdpAttributeList& orig) = delete;
  SipccSdpAttributeList& operator=(const SipccSdpAttributeList& rhs) = delete;
};

}  // namespace mozilla

#endif