Bug 1210660 - Change vp8 threshold for static images in screensharing mode; r=jesup draft
authorDan Minor <dminor@mozilla.com>
Thu, 09 Jun 2016 13:38:43 -0400
changeset 377570 34d9fff2efb777bdfd5887db879184bc4ffc7442
parent 377169 3ccccf8e5036179a3178437cabc154b5e04b333d
child 523385 1dd3d22200c9d23f30692d291f1850d82e4ed996
push id20829
push userdminor@mozilla.com
push dateFri, 10 Jun 2016 18:02:24 +0000
reviewersjesup
bugs1210660
milestone50.0a1
Bug 1210660 - Change vp8 threshold for static images in screensharing mode; r=jesup This changes the static threshold in screensharing mode and ensures that the screensharing mode is in fact passed to the codec. This also causes the peer connection to update the media pipelines when a track is replaced to cause the codec to be notified that the source has changed and to change settings appropriately. It seems to be a common use case to have a camera track be replaced by a screenshare track during a call. MozReview-Commit-ID: HbV14uL4kIL
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -709,16 +709,17 @@ WebrtcVideoConduit::ConfigureSendMediaCo
 
   if(codecFound == false)
   {
     CSFLogError(logTag, "%s Codec Mismatch ", __FUNCTION__);
     return kMediaConduitInvalidSendCodec;
   }
   // Note: only for overriding parameters from GetCodec()!
   CodecConfigToWebRTCCodec(codecConfig, video_codec);
+  video_codec.mode = mCodecMode;
 
   if(mPtrViECodec->SetSendCodec(mChannel, video_codec) == -1)
   {
     error = mPtrViEBase->LastError();
     if(error == kViECodecInvalidCodec)
     {
       CSFLogError(logTag, "%s Invalid Send Codec", __FUNCTION__);
       return kMediaConduitInvalidSendCodec;
@@ -1407,16 +1408,17 @@ WebrtcVideoConduit::ReconfigureSendCodec
   }
   if (vie_codec.numberOfSimulcastStreams != 0) {
     vie_codec.minBitrate = std::max(minMinBitrate, vie_codec.minBitrate);
     vie_codec.maxBitrate = std::min(totalMaxBitrate, vie_codec.maxBitrate);
     vie_codec.startBitrate = std::max(vie_codec.minBitrate,
                                       std::min(minStartBitrate,
                                                vie_codec.maxBitrate));
   }
+  vie_codec.mode = mCodecMode;
   if ((err = mPtrViECodec->SetSendCodec(mChannel, vie_codec)) != 0)
   {
     CSFLogError(logTag, "%s: SetSendCodec(%ux%u) failed, err %d",
                 __FUNCTION__, width, height, err);
     return NS_ERROR_FAILURE;
   }
   if (mMinBitrateEstimate != 0) {
     mPtrViENetwork->SetBitrateConfig(mChannel,
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -2511,16 +2511,21 @@ PeerConnectionImpl::ReplaceTrack(MediaSt
     return NS_OK;
   }
   aThisTrack.RemovePrincipalChangeObserver(this);
   aWithTrack.AddPrincipalChangeObserver(this);
 #if !defined(MOZILLA_EXTERNAL_LINKAGE)
   PrincipalChanged(&aWithTrack);
 #endif
 
+  // We update the media pipelines here so we can apply different codec
+  // settings for different sources (e.g. screensharing as opposed to camera.)
+  // TODO: We should probably only do this if the source has in fact changed.
+  mMedia->UpdateMediaPipelines(*mJsepSession);
+
   pco->OnReplaceTrackSuccess(jrv);
   if (jrv.Failed()) {
     CSFLogError(logTag, "Error firing replaceTrack success callback");
     return NS_ERROR_UNEXPECTED;
   }
 
   return NS_OK;
 }
--- a/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc
+++ b/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc
@@ -680,17 +680,18 @@ int VP8EncoderImpl::InitAndSetControlSet
                     codec_.codecSpecific.VP8.denoisingOn ?
                     denoiser_state : kDenoiserOff);
   if (encoders_.size() > 2) {
     vpx_codec_control(&encoders_[1], VP8E_SET_NOISE_SENSITIVITY,
                       codec_.codecSpecific.VP8.denoisingOn ?
                       denoiser_state : kDenoiserOff);
   }
   for (size_t i = 0; i < encoders_.size(); ++i) {
-    vpx_codec_control(&(encoders_[i]), VP8E_SET_STATIC_THRESHOLD, 1);
+    vpx_codec_control(&(encoders_[i]), VP8E_SET_STATIC_THRESHOLD,
+                      codec_.mode == kScreensharing ? 300 : 1);
     vpx_codec_control(&(encoders_[i]), VP8E_SET_CPUUSED, cpu_speed_[i]);
     vpx_codec_control(&(encoders_[i]), VP8E_SET_TOKEN_PARTITIONS,
                       static_cast<vp8e_token_partitions>(token_partitions_));
     vpx_codec_control(&(encoders_[i]), VP8E_SET_MAX_INTRA_BITRATE_PCT,
                       rc_max_intra_target_);
     vpx_codec_control(&(encoders_[i]), VP8E_SET_SCREEN_CONTENT_MODE,
                       codec_.mode == kScreensharing);
   }