Bug 1320101 - Differentiate between b=TIAS and simulcast stream max-br. r=pehrsons
authorAndreas Pehrson <pehrsons@gmail.com>
Wed, 07 Dec 2016 08:38:13 -1000
changeset 375062 84568b4acdccb31cc8c5c4d91a653b4d54f5b07d
parent 375061 cd5f8d67b620278cab7d009466858cc3b9de748c
child 375063 45500e7a10c367be371038514a1e5c95ea0adb3f
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1320101, 1250326
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1320101 - Differentiate between b=TIAS and simulcast stream max-br. r=pehrsons Reland of bug 1320101 patch 4 due to partial backout via mismerge in bug 1250326 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
@@ -24,16 +24,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
@@ -61,22 +65,28 @@ public:
     }
   }
 
   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;
     bool operator==(const SimulcastEncoding& aOther) const {
       return rid == aOther.rid &&
         constraints == aOther.constraints;
     }
@@ -110,16 +111,17 @@ public:
   bool operator==(const VideoCodecConfig& aRhs) const {
     if (mType != aRhs.mType ||
         mName != aRhs.mName ||
         mAckFbTypes != aRhs.mAckFbTypes ||
         mNackFbTypes != aRhs.mNackFbTypes ||
         mCcmFbTypes != aRhs.mCcmFbTypes ||
         mRembFbSet != aRhs.mRembFbSet ||
         mFECFbSet != aRhs.mFECFbSet ||
+        mTias != aRhs.mTias ||
         !(mEncodingConstraints == aRhs.mEncodingConstraints) ||
         !(mSimulcastEncodings == aRhs.mSimulcastEncodings) ||
         mSpropParameterSets != aRhs.mSpropParameterSets ||
         mProfile != aRhs.mProfile ||
         mConstraints != aRhs.mConstraints ||
         mLevel != aRhs.mLevel ||
         mPacketizationMode != aRhs.mPacketizationMode) {
       return false;
@@ -130,16 +132,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
@@ -532,18 +532,17 @@ WebrtcVideoConduit::ConfigureSendMediaCo
     width = mSendingWidth;
     height = mSendingHeight;
     // max framerate remains the same
   }
   mSendingFramerate = std::max(mSendingFramerate,
                                static_cast<unsigned int>(max_framerate));
 
   // So we can comply with b=TIAS/b=AS/maxbr=X when input resolution changes
-  // XXX not sure this is right!
-  // XXX mNegotiatedMaxBitrate = MinIgnoreZero(mPrefMaxBitrate, codecConfig->maxBitrate);
+  mNegotiatedMaxBitrate = codecConfig->mTias / 1000;
 
   for (size_t idx = streamCount - 1; streamCount > 0; idx--, streamCount--) {
     webrtc::VideoStream video_stream;
     VideoEncoderConfigBuilder::SimulcastStreamConfig simulcast_config;
     // Stream dimensions must be divisable by 2^(n-1), where n is the number of layers.
     // Each lower resolution layer is 1/2^(n-1) of the size of largest layer,
     // where n is the number of the layer
 
--- a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
+++ b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
@@ -152,25 +152,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