summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/sdp/RsdparsaSdpAttributeList.h
blob: 812f15e112ea680bd6539c1d65bb48c82723663a (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
146
147
148
149
150
151
152
153
154
155
156
157
/* -*- 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 _RSDPARSA_SDP_ATTRIBUTE_LIST_H_
#define _RSDPARSA_SDP_ATTRIBUTE_LIST_H_

#include "sdp/RsdparsaSdpGlue.h"
#include "sdp/RsdparsaSdpInc.h"
#include "sdp/SdpAttributeList.h"

namespace mozilla {

class RsdparsaSdp;
class RsdparsaSdpMediaSection;
class SdpParser;

class RsdparsaSdpAttributeList : public SdpAttributeList {
  friend class RsdparsaSdpMediaSection;
  friend class RsdparsaSdp;

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

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

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

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

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

  SdpDirectionAttribute::Direction GetDirection() const override;

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

  virtual ~RsdparsaSdpAttributeList();

 private:
  explicit RsdparsaSdpAttributeList(RsdparsaSessionHandle session)
      : mSession(std::move(session)),
        mSessionAttributes(nullptr),
        mIsVideo(false),
        mAttributes() {
    RustAttributeList* attributes = get_sdp_session_attributes(mSession.get());
    LoadAll(attributes);
  }

  RsdparsaSdpAttributeList(RsdparsaSessionHandle session,
                           const RustMediaSection* const msection,
                           const RsdparsaSdpAttributeList* sessionAttributes)
      : mSession(std::move(session)),
        mSessionAttributes(sessionAttributes),
        mAttributes() {
    mIsVideo =
        sdp_rust_get_media_type(msection) == RustSdpMediaValue::kRustVideo;
    RustAttributeList* attributes = sdp_get_media_attribute_list(msection);
    LoadAll(attributes);
  }

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

  const RsdparsaSessionHandle mSession;
  const RsdparsaSdpAttributeList* mSessionAttributes;
  bool mIsVideo;

  bool AtSessionLevel() const { return !mSessionAttributes; }

  bool IsAllowedHere(SdpAttribute::AttributeType type);
  void LoadAll(RustAttributeList* attributeList);
  void LoadAttribute(RustAttributeList* attributeList, AttributeType type);
  void LoadIceUfrag(RustAttributeList* attributeList);
  void LoadIcePwd(RustAttributeList* attributeList);
  void LoadIdentity(RustAttributeList* attributeList);
  void LoadIceOptions(RustAttributeList* attributeList);
  void LoadFingerprint(RustAttributeList* attributeList);
  void LoadDtlsMessage(RustAttributeList* attributeList);
  void LoadSetup(RustAttributeList* attributeList);
  void LoadSsrc(RustAttributeList* attributeList);
  void LoadSsrcGroup(RustAttributeList* attributeList);
  void LoadRtpmap(RustAttributeList* attributeList);
  void LoadFmtp(RustAttributeList* attributeList);
  void LoadPtime(RustAttributeList* attributeList);
  void LoadFlags(RustAttributeList* attributeList);
  void LoadMaxMessageSize(RustAttributeList* attributeList);
  void LoadMid(RustAttributeList* attributeList);
  void LoadMsid(RustAttributeList* attributeList);
  void LoadMsidSemantics(RustAttributeList* attributeList);
  void LoadGroup(RustAttributeList* attributeList);
  void LoadRtcp(RustAttributeList* attributeList);
  void LoadRtcpFb(RustAttributeList* attributeList);
  void LoadSctpPort(RustAttributeList* attributeList);
  void LoadSimulcast(RustAttributeList* attributeList);
  void LoadImageattr(RustAttributeList* attributeList);
  void LoadSctpmaps(RustAttributeList* attributeList);
  void LoadDirection(RustAttributeList* attributeList);
  void LoadRemoteCandidates(RustAttributeList* attributeList);
  void LoadRids(RustAttributeList* attributeList);
  void LoadExtmap(RustAttributeList* attributeList);
  void LoadMaxPtime(RustAttributeList* attributeList);
  void LoadCandidate(RustAttributeList* attributeList);

  void WarnAboutMisplacedAttribute(SdpAttribute::AttributeType type,
                                   uint32_t lineNumber, SdpParser& errorHolder);

  SdpAttribute* mAttributes[kNumAttributeTypes];

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

}  // namespace mozilla

#endif