Bug 1320101 - Differentiate between b=TIAS and simulcast stream max-br. r=bwc,jesup
authorAndreas Pehrson <pehrsons@gmail.com>
Wed, 07 Dec 2016 08:38:13 -1000
changeset 325414 337f8b56236774aea32593bba2c540df33cddd26
parent 325413 38e008ff60f0f595cc6f57ecbac6775166ab480a
child 325415 afdc890658747791601d65c77ed549d4607d0d77
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersbwc, jesup
bugs1320101
milestone53.0a1
Bug 1320101 - Differentiate between b=TIAS and simulcast stream max-br. r=bwc,jesup MozReview-Commit-ID: HPnOvwtawwV
media/webrtc/signaling/src/jsep/JsepTrack.cpp
media/webrtc/signaling/src/jsep/JsepTrack.h
media/webrtc/signaling/src/jsep/JsepTrackEncoding.h
media/webrtc/signaling/src/media-conduit/CodecConfig.h
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
--- a/media/webrtc/signaling/src/jsep/JsepTrack.cpp
+++ b/media/webrtc/signaling/src/jsep/JsepTrack.cpp
@@ -256,16 +256,19 @@ JsepTrack::FindConstraints(const std::st
 }
 
 void
 JsepTrack::CreateEncodings(
     const SdpMediaSection& remote,
     const std::vector<JsepCodecDescription*>& negotiatedCodecs,
     JsepTrackNegotiatedDetails* negotiatedDetails)
 {
+  negotiatedDetails->mTias = remote.GetBandwidth("TIAS");
+  // TODO add support for b=AS if TIAS is not set (bug 976521)
+
   std::vector<SdpRidAttributeList::Rid> rids;
   GetRids(remote, sdp::kRecv, &rids); // Get rids we will send
   NegotiateRids(rids, &mJsEncodeConstraints);
   if (rids.empty()) {
     // Add dummy value with an empty id to make sure we get a single unicast
     // stream.
     rids.push_back(SdpRidAttributeList::Rid());
   }
@@ -289,18 +292,16 @@ JsepTrack::CreateEncodings(
     // If we end up supporting params for rid, we would handle that here.
 
     // Incorporate the corresponding JS encoding constraints, if they exist
     for (const JsConstraints& jsConstraints : mJsEncodeConstraints) {
       if (jsConstraints.rid == rids[i].id) {
         encoding->mConstraints = jsConstraints.constraints;
       }
     }
-
-    encoding->UpdateMaxBitrate(remote);
   }
 }
 
 std::vector<JsepCodecDescription*>
 JsepTrack::GetCodecClones() const
 {
   std::vector<JsepCodecDescription*> clones;
   for (const JsepCodecDescription* codec : mPrototypeCodecs.values) {
--- a/media/webrtc/signaling/src/jsep/JsepTrack.h
+++ b/media/webrtc/signaling/src/jsep/JsepTrack.h
@@ -23,16 +23,20 @@
 #include "signaling/src/sdp/SdpMediaSection.h"
 #include "signaling/src/common/PtrVector.h"
 
 namespace mozilla {
 
 class JsepTrackNegotiatedDetails
 {
 public:
+  JsepTrackNegotiatedDetails() :
+    mTias(0)
+  {}
+
   size_t
   GetEncodingCount() const
   {
     return mEncodings.values.size();
   }
 
   const JsepTrackEncoding&
   GetEncoding(size_t index) const
@@ -51,22 +55,28 @@ public:
     return nullptr;
   }
 
   std::vector<uint8_t> GetUniquePayloadTypes() const
   {
     return mUniquePayloadTypes;
   }
 
+  uint32_t GetTias() const
+  {
+    return mTias;
+  }
+
 private:
   friend class JsepTrack;
 
   std::map<std::string, SdpExtmapAttributeList::Extmap> mExtmap;
   std::vector<uint8_t> mUniquePayloadTypes;
   PtrVector<JsepTrackEncoding> mEncodings;
+  uint32_t mTias; // bits per second
 };
 
 class JsepTrack
 {
 public:
   JsepTrack(mozilla::SdpMediaSection::MediaType type,
             const std::string& streamid,
             const std::string& trackid,
--- a/media/webrtc/signaling/src/jsep/JsepTrackEncoding.h
+++ b/media/webrtc/signaling/src/jsep/JsepTrackEncoding.h
@@ -34,26 +34,16 @@ public:
     for (const JsepCodecDescription* codec : mCodecs.values) {
       if (codec->mDefaultPt == format) {
         return true;
       }
     }
     return false;
   }
 
-  void UpdateMaxBitrate(const SdpMediaSection& remote)
-  {
-    uint32_t tias = remote.GetBandwidth("TIAS");
-    // select minimum of the two which is not zero
-    mConstraints.maxBr = std::min(tias ? tias : mConstraints.maxBr,
-                                  mConstraints.maxBr ? mConstraints.maxBr :
-                                                       tias);
-    // TODO add support for b=AS if TIAS is not set (bug 976521)
-  }
-
   EncodingConstraints mConstraints;
   std::string mRid;
 
 private:
   PtrVector<JsepCodecDescription> mCodecs;
 };
 }
 
--- a/media/webrtc/signaling/src/media-conduit/CodecConfig.h
+++ b/media/webrtc/signaling/src/media-conduit/CodecConfig.h
@@ -85,16 +85,17 @@ public:
   std::vector<std::string> mAckFbTypes;
   std::vector<std::string> mNackFbTypes;
   std::vector<std::string> mCcmFbTypes;
   // Don't pass mOtherFbTypes from JsepVideoCodecDescription because we'd have
   // to drag SdpRtcpFbAttributeList::Feedback along too.
   bool mRembFbSet;
   bool mFECFbSet;
 
+  uint32_t mTias;
   EncodingConstraints mEncodingConstraints;
   struct SimulcastEncoding {
     std::string rid;
     EncodingConstraints constraints;
   };
   std::vector<SimulcastEncoding> mSimulcastEncodings;
   std::string mSpropParameterSets;
   uint8_t mProfile;
@@ -105,16 +106,17 @@ public:
 
   VideoCodecConfig(int type,
                    std::string name,
                    const EncodingConstraints& constraints,
                    const struct VideoCodecConfigH264 *h264 = nullptr) :
     mType(type),
     mName(name),
     mFECFbSet(false),
+    mTias(0),
     mEncodingConstraints(constraints),
     mProfile(0x42),
     mConstraints(0xE0),
     mLevel(0x0C),
     mPacketizationMode(1)
   {
     if (h264) {
       mProfile = (h264->profile_level_id & 0x00FF0000) >> 16;
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -727,16 +727,20 @@ WebrtcVideoConduit::ConfigureSendMediaCo
     }//for
   }
 
   if(codecFound == false)
   {
     CSFLogError(logTag, "%s Codec Mismatch ", __FUNCTION__);
     return kMediaConduitInvalidSendCodec;
   }
+
+  // So we can comply with b=TIAS/b=AS/maxbr=X when input resolution changes
+  mNegotiatedMaxBitrate = codecConfig->mTias / 1000;
+
   // Note: only for overriding parameters from GetCodec()!
   CodecConfigToWebRTCCodec(codecConfig, video_codec);
   if (mSendingWidth != 0) {
     // We're already in a call and are reconfiguring (perhaps due to
     // ReplaceTrack).  Set to match the last frame we sent.
 
     // We could also set mLastWidth to 0, to force immediate reconfig -
     // more expensive, but perhaps less risk of missing something.  Really
@@ -746,18 +750,16 @@ WebrtcVideoConduit::ConfigureSendMediaCo
     video_codec.width = mSendingWidth;
     video_codec.height = mSendingHeight;
     video_codec.maxFramerate = mSendingFramerate;
   } else {
     mSendingWidth = 0;
     mSendingHeight = 0;
     mSendingFramerate = video_codec.maxFramerate;
   }
-  // So we can comply with b=TIAS/b=AS/maxbr=X when input resolution changes
-  mNegotiatedMaxBitrate = MinIgnoreZero(mPrefMaxBitrate, video_codec.maxBitrate);
 
   video_codec.mode = mCodecMode;
 
   if(mPtrViECodec->SetSendCodec(mChannel, video_codec) == -1)
   {
     error = mPtrViEBase->LastError();
     if(error == kViECodecInvalidCodec)
     {
--- a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
+++ b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
@@ -162,25 +162,28 @@ NegotiatedDetailsToVideoCodecConfigs(con
 {
   std::vector<JsepCodecDescription*> codecs(GetCodecs(aDetails));
   for (const JsepCodecDescription* codec : codecs) {
     VideoCodecConfig* config;
     if (NS_FAILED(JsepCodecDescToCodecConfig(*codec, &config))) {
       return NS_ERROR_INVALID_ARG;
     }
 
+    config->mTias = aDetails.GetTias();
+
     for (size_t i = 0; i < aDetails.GetEncodingCount(); ++i) {
       const JsepTrackEncoding& jsepEncoding(aDetails.GetEncoding(i));
       if (jsepEncoding.HasFormat(codec->mDefaultPt)) {
         VideoCodecConfig::SimulcastEncoding encoding;
         encoding.rid = jsepEncoding.mRid;
         encoding.constraints = jsepEncoding.mConstraints;
         config->mSimulcastEncodings.push_back(encoding);
       }
     }
+
     aConfigs->values.push_back(config);
   }
 
   return NS_OK;
 }
 
 // Accessing the PCMedia should be safe here because we shouldn't
 // have enqueued this function unless it was still active and