Home | History | Annotate | Download | only in webrtc
      1 /*
      2  * libjingle
      3  * Copyright 2012, Google Inc.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are met:
      7  *
      8  *  1. Redistributions of source code must retain the above copyright notice,
      9  *     this list of conditions and the following disclaimer.
     10  *  2. Redistributions in binary form must reproduce the above copyright notice,
     11  *     this list of conditions and the following disclaimer in the documentation
     12  *     and/or other materials provided with the distribution.
     13  *  3. The name of the author may not be used to endorse or promote products
     14  *     derived from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
     19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 // Implements the SessionDescriptionInterface.
     29 
     30 #ifndef TALK_APP_WEBRTC_JSEPSESSIONDESCRIPTION_H_
     31 #define TALK_APP_WEBRTC_JSEPSESSIONDESCRIPTION_H_
     32 
     33 #include <string>
     34 #include <vector>
     35 
     36 #include "talk/app/webrtc/jsep.h"
     37 #include "talk/app/webrtc/jsepicecandidate.h"
     38 #include "talk/base/scoped_ptr.h"
     39 
     40 namespace cricket {
     41 class SessionDescription;
     42 }
     43 
     44 namespace webrtc {
     45 
     46 class JsepSessionDescription : public SessionDescriptionInterface {
     47  public:
     48   explicit JsepSessionDescription(const std::string& type);
     49   virtual ~JsepSessionDescription();
     50 
     51   // |error| can be NULL if don't care about the failure reason.
     52   bool Initialize(const std::string& sdp, SdpParseError* error);
     53 
     54   // Takes ownership of |description|.
     55   bool Initialize(cricket::SessionDescription* description,
     56       const std::string& session_id,
     57       const std::string& session_version);
     58 
     59   virtual cricket::SessionDescription* description() {
     60     return description_.get();
     61   }
     62   virtual const cricket::SessionDescription* description() const {
     63     return description_.get();
     64   }
     65   virtual std::string session_id() const {
     66     return session_id_;
     67   }
     68   virtual std::string session_version() const {
     69     return session_version_;
     70   }
     71   virtual std::string type() const {
     72     return type_;
     73   }
     74   // Allow changing the type. Used for testing.
     75   void set_type(const std::string& type) { type_ = type; }
     76   virtual bool AddCandidate(const IceCandidateInterface* candidate);
     77   virtual size_t number_of_mediasections() const;
     78   virtual const IceCandidateCollection* candidates(
     79       size_t mediasection_index) const;
     80   virtual bool ToString(std::string* out) const;
     81 
     82   // Default video encoder settings. The resolution is the max resolution.
     83   // TODO(perkj): Implement proper negotiation of video resolution.
     84   static const int kDefaultVideoCodecId;
     85   static const int kDefaultVideoCodecFramerate;
     86   static const char kDefaultVideoCodecName[];
     87   static const int kMaxVideoCodecWidth;
     88   static const int kMaxVideoCodecHeight;
     89   static const int kDefaultVideoCodecPreference;
     90 
     91  private:
     92   talk_base::scoped_ptr<cricket::SessionDescription> description_;
     93   std::string session_id_;
     94   std::string session_version_;
     95   std::string type_;
     96   std::vector<JsepCandidateCollection> candidate_collection_;
     97 
     98   bool GetMediasectionIndex(const IceCandidateInterface* candidate,
     99                             size_t* index);
    100 
    101   DISALLOW_COPY_AND_ASSIGN(JsepSessionDescription);
    102 };
    103 
    104 }  // namespace webrtc
    105 
    106 #endif  // TALK_APP_WEBRTC_JSEPSESSIONDESCRIPTION_H_
    107