LCOV - code coverage report
Current view: top level - media/webrtc/signaling/src/sdp - SdpMediaSection.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 106 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 17 0.0 %
Legend: Lines: hit not hit

          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             : #ifndef _SDPMEDIASECTION_H_
       8             : #define _SDPMEDIASECTION_H_
       9             : 
      10             : #include "mozilla/Maybe.h"
      11             : #include "signaling/src/sdp/SdpEnum.h"
      12             : #include "signaling/src/sdp/SdpAttributeList.h"
      13             : #include <string>
      14             : #include <vector>
      15             : #include <sstream>
      16             : 
      17             : namespace mozilla
      18             : {
      19             : 
      20             : class SdpAttributeList;
      21             : 
      22             : class SdpConnection;
      23             : 
      24             : class SdpMediaSection
      25             : {
      26             : public:
      27             :   enum MediaType { kAudio, kVideo, kText, kApplication, kMessage };
      28             :   // don't add to enum to avoid warnings about unhandled enum values
      29             :   static const size_t kMediaTypes = static_cast<size_t>(kMessage) + 1;
      30             : 
      31             :   enum Protocol {
      32             :     kRtpAvp,            // RTP/AVP [RFC4566]
      33             :     kUdp,               // udp [RFC4566]
      34             :     kVat,               // vat [historic]
      35             :     kRtp,               // rtp [historic]
      36             :     kUdptl,             // udptl [ITU-T]
      37             :     kTcp,               // TCP [RFC4145]
      38             :     kRtpAvpf,           // RTP/AVPF [RFC4585]
      39             :     kTcpRtpAvp,         // TCP/RTP/AVP [RFC4571]
      40             :     kRtpSavp,           // RTP/SAVP [RFC3711]
      41             :     kTcpBfcp,           // TCP/BFCP [RFC4583]
      42             :     kTcpTlsBfcp,        // TCP/TLS/BFCP [RFC4583]
      43             :     kTcpTls,            // TCP/TLS [RFC4572]
      44             :     kFluteUdp,          // FLUTE/UDP [RFC-mehta-rmt-flute-sdp-05]
      45             :     kTcpMsrp,           // TCP/MSRP [RFC4975]
      46             :     kTcpTlsMsrp,        // TCP/TLS/MSRP [RFC4975]
      47             :     kDccp,              // DCCP [RFC5762]
      48             :     kDccpRtpAvp,        // DCCP/RTP/AVP [RFC5762]
      49             :     kDccpRtpSavp,       // DCCP/RTP/SAVP [RFC5762]
      50             :     kDccpRtpAvpf,       // DCCP/RTP/AVPF [RFC5762]
      51             :     kDccpRtpSavpf,      // DCCP/RTP/SAVPF [RFC5762]
      52             :     kRtpSavpf,          // RTP/SAVPF [RFC5124]
      53             :     kUdpTlsRtpSavp,     // UDP/TLS/RTP/SAVP [RFC5764]
      54             :     kTcpTlsRtpSavp,     // TCP/TLS/RTP/SAVP [JSEP-TBD]
      55             :     kDccpTlsRtpSavp,    // DCCP/TLS/RTP/SAVP [RFC5764]
      56             :     kUdpTlsRtpSavpf,    // UDP/TLS/RTP/SAVPF [RFC5764]
      57             :     kTcpTlsRtpSavpf,    // TCP/TLS/RTP/SAVPF [JSEP-TBD]
      58             :     kDccpTlsRtpSavpf,   // DCCP/TLS/RTP/SAVPF [RFC5764]
      59             :     kUdpMbmsFecRtpAvp,  // UDP/MBMS-FEC/RTP/AVP [RFC6064]
      60             :     kUdpMbmsFecRtpSavp, // UDP/MBMS-FEC/RTP/SAVP [RFC6064]
      61             :     kUdpMbmsRepair,     // UDP/MBMS-REPAIR [RFC6064]
      62             :     kFecUdp,            // FEC/UDP [RFC6364]
      63             :     kUdpFec,            // UDP/FEC [RFC6364]
      64             :     kTcpMrcpv2,         // TCP/MRCPv2 [RFC6787]
      65             :     kTcpTlsMrcpv2,      // TCP/TLS/MRCPv2 [RFC6787]
      66             :     kPstn,              // PSTN [RFC7195]
      67             :     kUdpTlsUdptl,       // UDP/TLS/UDPTL [RFC7345]
      68             :     kSctp,              // SCTP [draft-ietf-mmusic-sctp-sdp-07]
      69             :     kDtlsSctp,          // DTLS/SCTP [draft-ietf-mmusic-sctp-sdp-07]
      70             :     kUdpDtlsSctp,       // UDP/DTLS/SCTP [draft-ietf-mmusic-sctp-sdp-21]
      71             :     kTcpDtlsSctp        // TCP/DTLS/SCTP [draft-ietf-mmusic-sctp-sdp-21]
      72             :   };
      73             : 
      74           0 :   explicit SdpMediaSection(size_t level) : mLevel(level) {}
      75             : 
      76             :   virtual MediaType GetMediaType() const = 0;
      77             :   virtual unsigned int GetPort() const = 0;
      78             :   virtual void SetPort(unsigned int port) = 0;
      79             :   virtual unsigned int GetPortCount() const = 0;
      80             :   virtual Protocol GetProtocol() const = 0;
      81             :   virtual const SdpConnection& GetConnection() const = 0;
      82             :   virtual SdpConnection& GetConnection() = 0;
      83             :   virtual uint32_t GetBandwidth(const std::string& type) const = 0;
      84             :   virtual const std::vector<std::string>& GetFormats() const = 0;
      85             : 
      86             :   std::vector<std::string> GetFormatsForSimulcastVersion(
      87             :       size_t simulcastVersion, bool send, bool recv) const;
      88             :   virtual const SdpAttributeList& GetAttributeList() const = 0;
      89             :   virtual SdpAttributeList& GetAttributeList() = 0;
      90             : 
      91             :   virtual SdpDirectionAttribute GetDirectionAttribute() const = 0;
      92             : 
      93             :   virtual void Serialize(std::ostream&) const = 0;
      94             : 
      95             :   virtual void AddCodec(const std::string& pt, const std::string& name,
      96             :                         uint32_t clockrate, uint16_t channels) = 0;
      97             :   virtual void ClearCodecs() = 0;
      98             : 
      99             :   virtual void AddDataChannel(const std::string& name, uint16_t port,
     100             :                               uint16_t streams, uint32_t message_size) = 0;
     101             : 
     102             :   size_t
     103           0 :   GetLevel() const
     104             :   {
     105           0 :     return mLevel;
     106             :   }
     107             : 
     108             :   inline bool
     109           0 :   IsReceiving() const
     110             :   {
     111           0 :     return GetDirectionAttribute().mValue & sdp::kRecv;
     112             :   }
     113             : 
     114             :   inline bool
     115           0 :   IsSending() const
     116             :   {
     117           0 :     return GetDirectionAttribute().mValue & sdp::kSend;
     118             :   }
     119             : 
     120             :   inline void
     121           0 :   SetReceiving(bool receiving)
     122             :   {
     123           0 :     auto direction = GetDirectionAttribute().mValue;
     124           0 :     if (direction & sdp::kSend) {
     125           0 :       SetDirection(receiving ?
     126             :                    SdpDirectionAttribute::kSendrecv :
     127           0 :                    SdpDirectionAttribute::kSendonly);
     128             :     } else {
     129           0 :       SetDirection(receiving ?
     130             :                    SdpDirectionAttribute::kRecvonly :
     131           0 :                    SdpDirectionAttribute::kInactive);
     132             :     }
     133           0 :   }
     134             : 
     135             :   inline void
     136           0 :   SetSending(bool sending)
     137             :   {
     138           0 :     auto direction = GetDirectionAttribute().mValue;
     139           0 :     if (direction & sdp::kRecv) {
     140           0 :       SetDirection(sending ?
     141             :                    SdpDirectionAttribute::kSendrecv :
     142           0 :                    SdpDirectionAttribute::kRecvonly);
     143             :     } else {
     144           0 :       SetDirection(sending ?
     145             :                    SdpDirectionAttribute::kSendonly :
     146           0 :                    SdpDirectionAttribute::kInactive);
     147             :     }
     148           0 :   }
     149             : 
     150           0 :   inline void SetDirection(SdpDirectionAttribute::Direction direction)
     151             :   {
     152           0 :     GetAttributeList().SetAttribute(new SdpDirectionAttribute(direction));
     153           0 :   }
     154             : 
     155             :   const SdpFmtpAttributeList::Parameters* FindFmtp(const std::string& pt) const;
     156             :   void SetFmtp(const SdpFmtpAttributeList::Fmtp& fmtp);
     157             :   void RemoveFmtp(const std::string& pt);
     158             :   const SdpRtpmapAttributeList::Rtpmap* FindRtpmap(const std::string& pt) const;
     159             :   const SdpSctpmapAttributeList::Sctpmap* GetSctpmap() const;
     160             :   uint32_t GetSctpPort() const;
     161             :   bool GetMaxMessageSize(uint32_t* size) const;
     162             :   bool HasRtcpFb(const std::string& pt,
     163             :                  SdpRtcpFbAttributeList::Type type,
     164             :                  const std::string& subType) const;
     165             :   SdpRtcpFbAttributeList GetRtcpFbs() const;
     166             :   void SetRtcpFbs(const SdpRtcpFbAttributeList& rtcpfbs);
     167           0 :   bool HasFormat(const std::string& format) const
     168             :   {
     169           0 :     return std::find(GetFormats().begin(), GetFormats().end(), format) !=
     170           0 :         GetFormats().end();
     171             :   }
     172             :   void SetSsrcs(const std::vector<uint32_t>& ssrcs,
     173             :                 const std::string& cname);
     174             :   void AddMsid(const std::string& id, const std::string& appdata);
     175             :   const SdpRidAttributeList::Rid* FindRid(const std::string& id) const;
     176             : 
     177             : private:
     178             :   size_t mLevel;
     179             : };
     180             : 
     181           0 : inline std::ostream& operator<<(std::ostream& os, const SdpMediaSection& ms)
     182             : {
     183           0 :   ms.Serialize(os);
     184           0 :   return os;
     185             : }
     186             : 
     187           0 : inline std::ostream& operator<<(std::ostream& os, SdpMediaSection::MediaType t)
     188             : {
     189           0 :   switch (t) {
     190             :     case SdpMediaSection::kAudio:
     191           0 :       return os << "audio";
     192             :     case SdpMediaSection::kVideo:
     193           0 :       return os << "video";
     194             :     case SdpMediaSection::kText:
     195           0 :       return os << "text";
     196             :     case SdpMediaSection::kApplication:
     197           0 :       return os << "application";
     198             :     case SdpMediaSection::kMessage:
     199           0 :       return os << "message";
     200             :   }
     201           0 :   MOZ_ASSERT(false, "Unknown MediaType");
     202             :   return os << "?";
     203             : }
     204             : 
     205           0 : inline std::ostream& operator<<(std::ostream& os, SdpMediaSection::Protocol p)
     206             : {
     207           0 :   switch (p) {
     208             :     case SdpMediaSection::kRtpAvp:
     209           0 :       return os << "RTP/AVP";
     210             :     case SdpMediaSection::kUdp:
     211           0 :       return os << "udp";
     212             :     case SdpMediaSection::kVat:
     213           0 :       return os << "vat";
     214             :     case SdpMediaSection::kRtp:
     215           0 :       return os << "rtp";
     216             :     case SdpMediaSection::kUdptl:
     217           0 :       return os << "udptl";
     218             :     case SdpMediaSection::kTcp:
     219           0 :       return os << "TCP";
     220             :     case SdpMediaSection::kRtpAvpf:
     221           0 :       return os << "RTP/AVPF";
     222             :     case SdpMediaSection::kTcpRtpAvp:
     223           0 :       return os << "TCP/RTP/AVP";
     224             :     case SdpMediaSection::kRtpSavp:
     225           0 :       return os << "RTP/SAVP";
     226             :     case SdpMediaSection::kTcpBfcp:
     227           0 :       return os << "TCP/BFCP";
     228             :     case SdpMediaSection::kTcpTlsBfcp:
     229           0 :       return os << "TCP/TLS/BFCP";
     230             :     case SdpMediaSection::kTcpTls:
     231           0 :       return os << "TCP/TLS";
     232             :     case SdpMediaSection::kFluteUdp:
     233           0 :       return os << "FLUTE/UDP";
     234             :     case SdpMediaSection::kTcpMsrp:
     235           0 :       return os << "TCP/MSRP";
     236             :     case SdpMediaSection::kTcpTlsMsrp:
     237           0 :       return os << "TCP/TLS/MSRP";
     238             :     case SdpMediaSection::kDccp:
     239           0 :       return os << "DCCP";
     240             :     case SdpMediaSection::kDccpRtpAvp:
     241           0 :       return os << "DCCP/RTP/AVP";
     242             :     case SdpMediaSection::kDccpRtpSavp:
     243           0 :       return os << "DCCP/RTP/SAVP";
     244             :     case SdpMediaSection::kDccpRtpAvpf:
     245           0 :       return os << "DCCP/RTP/AVPF";
     246             :     case SdpMediaSection::kDccpRtpSavpf:
     247           0 :       return os << "DCCP/RTP/SAVPF";
     248             :     case SdpMediaSection::kRtpSavpf:
     249           0 :       return os << "RTP/SAVPF";
     250             :     case SdpMediaSection::kUdpTlsRtpSavp:
     251           0 :       return os << "UDP/TLS/RTP/SAVP";
     252             :     case SdpMediaSection::kTcpTlsRtpSavp:
     253           0 :       return os << "TCP/TLS/RTP/SAVP";
     254             :     case SdpMediaSection::kDccpTlsRtpSavp:
     255           0 :       return os << "DCCP/TLS/RTP/SAVP";
     256             :     case SdpMediaSection::kUdpTlsRtpSavpf:
     257           0 :       return os << "UDP/TLS/RTP/SAVPF";
     258             :     case SdpMediaSection::kTcpTlsRtpSavpf:
     259           0 :       return os << "TCP/TLS/RTP/SAVPF";
     260             :     case SdpMediaSection::kDccpTlsRtpSavpf:
     261           0 :       return os << "DCCP/TLS/RTP/SAVPF";
     262             :     case SdpMediaSection::kUdpMbmsFecRtpAvp:
     263           0 :       return os << "UDP/MBMS-FEC/RTP/AVP";
     264             :     case SdpMediaSection::kUdpMbmsFecRtpSavp:
     265           0 :       return os << "UDP/MBMS-FEC/RTP/SAVP";
     266             :     case SdpMediaSection::kUdpMbmsRepair:
     267           0 :       return os << "UDP/MBMS-REPAIR";
     268             :     case SdpMediaSection::kFecUdp:
     269           0 :       return os << "FEC/UDP";
     270             :     case SdpMediaSection::kUdpFec:
     271           0 :       return os << "UDP/FEC";
     272             :     case SdpMediaSection::kTcpMrcpv2:
     273           0 :       return os << "TCP/MRCPv2";
     274             :     case SdpMediaSection::kTcpTlsMrcpv2:
     275           0 :       return os << "TCP/TLS/MRCPv2";
     276             :     case SdpMediaSection::kPstn:
     277           0 :       return os << "PSTN";
     278             :     case SdpMediaSection::kUdpTlsUdptl:
     279           0 :       return os << "UDP/TLS/UDPTL";
     280             :     case SdpMediaSection::kSctp:
     281           0 :       return os << "SCTP";
     282             :     case SdpMediaSection::kDtlsSctp:
     283           0 :       return os << "DTLS/SCTP";
     284             :     case SdpMediaSection::kUdpDtlsSctp:
     285           0 :       return os << "UDP/DTLS/SCTP";
     286             :     case SdpMediaSection::kTcpDtlsSctp:
     287           0 :       return os << "TCP/DTLS/SCTP";
     288             :   }
     289           0 :   MOZ_ASSERT(false, "Unknown Protocol");
     290             :   return os << "?";
     291             : }
     292             : 
     293           0 : class SdpConnection
     294             : {
     295             : public:
     296           0 :   SdpConnection(sdp::AddrType addrType, std::string addr, uint8_t ttl = 0,
     297             :                 uint32_t count = 0)
     298           0 :       : mAddrType(addrType), mAddr(addr), mTtl(ttl), mCount(count)
     299             :   {
     300           0 :   }
     301           0 :   ~SdpConnection() {}
     302             : 
     303             :   sdp::AddrType
     304             :   GetAddrType() const
     305             :   {
     306             :     return mAddrType;
     307             :   }
     308             :   const std::string&
     309             :   GetAddress() const
     310             :   {
     311             :     return mAddr;
     312             :   }
     313             :   void
     314           0 :   SetAddress(const std::string& address)
     315             :   {
     316           0 :     mAddr = address;
     317           0 :     if (mAddr.find(':') != std::string::npos) {
     318           0 :       mAddrType = sdp::kIPv6;
     319             :     } else {
     320           0 :       mAddrType = sdp::kIPv4;
     321             :     }
     322           0 :   }
     323             :   uint8_t
     324             :   GetTtl() const
     325             :   {
     326             :     return mTtl;
     327             :   }
     328             :   uint32_t
     329             :   GetCount() const
     330             :   {
     331             :     return mCount;
     332             :   }
     333             : 
     334             :   void
     335           0 :   Serialize(std::ostream& os) const
     336             :   {
     337           0 :     sdp::NetType netType = sdp::kInternet;
     338             : 
     339           0 :     os << "c=" << netType << " " << mAddrType << " " << mAddr;
     340             : 
     341           0 :     if (mTtl) {
     342           0 :       os << "/" << static_cast<uint32_t>(mTtl);
     343           0 :       if (mCount) {
     344           0 :         os << "/" << mCount;
     345             :       }
     346             :     }
     347           0 :     os << "\r\n";
     348           0 :   }
     349             : 
     350             : private:
     351             :   sdp::AddrType mAddrType;
     352             :   std::string mAddr;
     353             :   uint8_t mTtl;    // 0-255; 0 when unset
     354             :   uint32_t mCount; // 0 when unset
     355             : };
     356             : 
     357           0 : inline std::ostream& operator<<(std::ostream& os, const SdpConnection& c)
     358             : {
     359           0 :   c.Serialize(os);
     360           0 :   return os;
     361             : }
     362             : 
     363             : } // namespace mozilla
     364             : 
     365             : #endif

Generated by: LCOV version 1.13