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

          Line data    Source code
       1             : /* This Source Code Form is subject to the terms of the Mozilla Public
       2             :  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
       3             :  * You can obtain one at http://mozilla.org/MPL/2.0/. */
       4             : 
       5             : #ifndef _JSEPSESSION_H_
       6             : #define _JSEPSESSION_H_
       7             : 
       8             : #include <string>
       9             : #include <vector>
      10             : #include "mozilla/Maybe.h"
      11             : #include "mozilla/RefPtr.h"
      12             : #include "mozilla/UniquePtr.h"
      13             : #include "nsError.h"
      14             : 
      15             : #include "signaling/src/jsep/JsepTransport.h"
      16             : #include "signaling/src/sdp/Sdp.h"
      17             : 
      18             : #include "JsepTrack.h"
      19             : 
      20             : namespace mozilla {
      21             : 
      22             : // Forward declarations
      23             : class JsepCodecDescription;
      24             : class JsepTrack;
      25             : 
      26             : enum JsepSignalingState {
      27             :   kJsepStateStable,
      28             :   kJsepStateHaveLocalOffer,
      29             :   kJsepStateHaveRemoteOffer,
      30             :   kJsepStateHaveLocalPranswer,
      31             :   kJsepStateHaveRemotePranswer,
      32             :   kJsepStateClosed
      33             : };
      34             : 
      35             : enum JsepSdpType {
      36             :   kJsepSdpOffer,
      37             :   kJsepSdpAnswer,
      38             :   kJsepSdpPranswer,
      39             :   kJsepSdpRollback
      40             : };
      41             : 
      42             : enum JsepDescriptionPendingOrCurrent {
      43             :   kJsepDescriptionCurrent,
      44             :   kJsepDescriptionPending,
      45             :   kJsepDescriptionPendingOrCurrent
      46             : };
      47             : 
      48           0 : struct JsepOAOptions {};
      49           0 : struct JsepOfferOptions : public JsepOAOptions {
      50             :   Maybe<size_t> mOfferToReceiveAudio;
      51             :   Maybe<size_t> mOfferToReceiveVideo;
      52             :   Maybe<bool> mDontOfferDataChannel;
      53             :   Maybe<bool> mIceRestart; // currently ignored by JsepSession
      54             : };
      55             : struct JsepAnswerOptions : public JsepOAOptions {};
      56             : 
      57             : enum JsepBundlePolicy {
      58             :   kBundleBalanced,
      59             :   kBundleMaxCompat,
      60             :   kBundleMaxBundle
      61             : };
      62             : 
      63             : class JsepSession
      64             : {
      65             : public:
      66           0 :   explicit JsepSession(const std::string& name)
      67           0 :     : mName(name), mState(kJsepStateStable), mNegotiations(0)
      68             :   {
      69           0 :   }
      70           0 :   virtual ~JsepSession() {}
      71             : 
      72             :   virtual nsresult Init() = 0;
      73             : 
      74             :   // Accessors for basic properties.
      75             :   virtual const std::string&
      76           0 :   GetName() const
      77             :   {
      78           0 :     return mName;
      79             :   }
      80             :   virtual JsepSignalingState
      81           0 :   GetState() const
      82             :   {
      83           0 :     return mState;
      84             :   }
      85             :   virtual uint32_t
      86           0 :   GetNegotiations() const
      87             :   {
      88           0 :     return mNegotiations;
      89             :   }
      90             : 
      91             :   // Set up the ICE And DTLS data.
      92             :   virtual nsresult SetIceCredentials(const std::string& ufrag,
      93             :                                      const std::string& pwd) = 0;
      94             :   virtual const std::string& GetUfrag() const = 0;
      95             :   virtual const std::string& GetPwd() const = 0;
      96             :   virtual nsresult SetBundlePolicy(JsepBundlePolicy policy) = 0;
      97             :   virtual bool RemoteIsIceLite() const = 0;
      98             :   virtual bool RemoteIceIsRestarting() const = 0;
      99             :   virtual std::vector<std::string> GetIceOptions() const = 0;
     100             : 
     101             :   virtual nsresult AddDtlsFingerprint(const std::string& algorithm,
     102             :                                       const std::vector<uint8_t>& value) = 0;
     103             : 
     104             :   virtual nsresult AddAudioRtpExtension(const std::string& extensionName,
     105             :                                         SdpDirectionAttribute::Direction direction) = 0;
     106             :   virtual nsresult AddVideoRtpExtension(const std::string& extensionName,
     107             :                                         SdpDirectionAttribute::Direction direction) = 0;
     108             : 
     109             :   // Kinda gross to be locking down the data structure type like this, but
     110             :   // returning by value is problematic due to the lack of stl move semantics in
     111             :   // our build config, since we can't use UniquePtr in the container. The
     112             :   // alternative is writing a raft of accessor functions that allow arbitrary
     113             :   // manipulation (which will be unwieldy), or allowing functors to be injected
     114             :   // that manipulate the data structure (still pretty unwieldy).
     115             :   virtual std::vector<JsepCodecDescription*>& Codecs() = 0;
     116             : 
     117             :   template <class UnaryFunction>
     118           0 :   void ForEachCodec(UnaryFunction& function)
     119             :   {
     120           0 :     std::for_each(Codecs().begin(), Codecs().end(), function);
     121           0 :     for (RefPtr<JsepTrack>& track : GetLocalTracks()) {
     122           0 :       track->ForEachCodec(function);
     123             :     }
     124           0 :     for (RefPtr<JsepTrack>& track : GetRemoteTracks()) {
     125           0 :       track->ForEachCodec(function);
     126             :     }
     127           0 :   }
     128             : 
     129             :   template <class BinaryPredicate>
     130           0 :   void SortCodecs(BinaryPredicate& sorter)
     131             :   {
     132           0 :     std::stable_sort(Codecs().begin(), Codecs().end(), sorter);
     133           0 :     for (RefPtr<JsepTrack>& track : GetLocalTracks()) {
     134           0 :       track->SortCodecs(sorter);
     135             :     }
     136           0 :     for (RefPtr<JsepTrack>& track : GetRemoteTracks()) {
     137           0 :       track->SortCodecs(sorter);
     138             :     }
     139           0 :   }
     140             : 
     141             :   // Manage tracks. We take shared ownership of any track.
     142             :   virtual nsresult AddTrack(const RefPtr<JsepTrack>& track) = 0;
     143             :   virtual nsresult RemoveTrack(const std::string& streamId,
     144             :                                const std::string& trackId) = 0;
     145             :   virtual nsresult ReplaceTrack(const std::string& oldStreamId,
     146             :                                 const std::string& oldTrackId,
     147             :                                 const std::string& newStreamId,
     148             :                                 const std::string& newTrackId) = 0;
     149             :   virtual nsresult SetParameters(
     150             :       const std::string& streamId,
     151             :       const std::string& trackId,
     152             :       const std::vector<JsepTrack::JsConstraints>& constraints) = 0;
     153             : 
     154             :   virtual nsresult GetParameters(
     155             :       const std::string& streamId,
     156             :       const std::string& trackId,
     157             :       std::vector<JsepTrack::JsConstraints>* outConstraints) = 0;
     158             : 
     159             :   virtual std::vector<RefPtr<JsepTrack>> GetLocalTracks() const = 0;
     160             : 
     161             :   virtual std::vector<RefPtr<JsepTrack>> GetRemoteTracks() const = 0;
     162             : 
     163             :   virtual std::vector<RefPtr<JsepTrack>> GetRemoteTracksAdded() const = 0;
     164             : 
     165             :   virtual std::vector<RefPtr<JsepTrack>> GetRemoteTracksRemoved() const = 0;
     166             : 
     167             :   // Access the negotiated track pairs.
     168             :   virtual std::vector<JsepTrackPair> GetNegotiatedTrackPairs() const = 0;
     169             : 
     170             :   // Access transports.
     171             :   virtual std::vector<RefPtr<JsepTransport>> GetTransports() const = 0;
     172             : 
     173             :   // Basic JSEP operations.
     174             :   virtual nsresult CreateOffer(const JsepOfferOptions& options,
     175             :                                std::string* offer) = 0;
     176             :   virtual nsresult CreateAnswer(const JsepAnswerOptions& options,
     177             :                                 std::string* answer) = 0;
     178             :   virtual std::string GetLocalDescription(JsepDescriptionPendingOrCurrent type)
     179             :                                           const = 0;
     180             :   virtual std::string GetRemoteDescription(JsepDescriptionPendingOrCurrent type)
     181             :                                            const = 0;
     182             :   virtual nsresult SetLocalDescription(JsepSdpType type,
     183             :                                        const std::string& sdp) = 0;
     184             :   virtual nsresult SetRemoteDescription(JsepSdpType type,
     185             :                                         const std::string& sdp) = 0;
     186             :   virtual nsresult AddRemoteIceCandidate(const std::string& candidate,
     187             :                                          const std::string& mid,
     188             :                                          uint16_t level) = 0;
     189             :   virtual nsresult AddLocalIceCandidate(const std::string& candidate,
     190             :                                         uint16_t level,
     191             :                                         std::string* mid,
     192             :                                         bool* skipped) = 0;
     193             :   virtual nsresult UpdateDefaultCandidate(
     194             :       const std::string& defaultCandidateAddr,
     195             :       uint16_t defaultCandidatePort,
     196             :       const std::string& defaultRtcpCandidateAddr,
     197             :       uint16_t defaultRtcpCandidatePort,
     198             :       uint16_t level) = 0;
     199             :   virtual nsresult EndOfLocalCandidates(uint16_t level) = 0;
     200             :   virtual nsresult Close() = 0;
     201             : 
     202             :   // ICE controlling or controlled
     203             :   virtual bool IsIceControlling() const = 0;
     204             :   virtual bool IsOfferer() const = 0;
     205             : 
     206             :   virtual const std::string
     207           0 :   GetLastError() const
     208             :   {
     209           0 :     return "Error";
     210             :   }
     211             : 
     212             :   static const char*
     213           0 :   GetStateStr(JsepSignalingState state)
     214             :   {
     215             :     static const char* states[] = { "stable", "have-local-offer",
     216             :                                     "have-remote-offer", "have-local-pranswer",
     217             :                                     "have-remote-pranswer", "closed" };
     218             : 
     219           0 :     return states[state];
     220             :   }
     221             : 
     222             :   virtual bool AllLocalTracksAreAssigned() const = 0;
     223             : 
     224             :   void
     225           0 :   CountTracks(uint16_t (&receiving)[SdpMediaSection::kMediaTypes],
     226             :               uint16_t (&sending)[SdpMediaSection::kMediaTypes]) const
     227             :   {
     228           0 :     auto trackPairs = GetNegotiatedTrackPairs();
     229             : 
     230           0 :     memset(receiving, 0, sizeof(receiving));
     231           0 :     memset(sending, 0, sizeof(sending));
     232             : 
     233           0 :     for (auto& pair : trackPairs) {
     234           0 :       if (pair.mReceiving) {
     235           0 :         receiving[pair.mReceiving->GetMediaType()]++;
     236             :       }
     237             : 
     238           0 :       if (pair.mSending) {
     239           0 :         sending[pair.mSending->GetMediaType()]++;
     240             :       }
     241             :     }
     242           0 :   }
     243             : 
     244             : protected:
     245             :   const std::string mName;
     246             :   JsepSignalingState mState;
     247             :   uint32_t mNegotiations;
     248             : };
     249             : 
     250             : } // namespace mozilla
     251             : 
     252             : #endif

Generated by: LCOV version 1.13