Bug 1253499 - Accomodate for changes to scaleDownBy when configuring send codec. r?jesup
Otherwise we would also need a change in input resolution for a change to take effect.
MozReview-Commit-ID: 1EKuqRRybH8
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -502,18 +502,18 @@ WebrtcVideoConduit::ConfigureSendMediaCo
MediaConduitErrorCode condError = kMediaConduitNoError;
// validate basic params
if ((condError = ValidateCodecConfig(codecConfig, true)) != kMediaConduitNoError) {
return condError;
}
- size_t streamCount = std::min(codecConfig->mSimulcastEncodings.size(),
- (size_t)webrtc::kMaxSimulcastStreams);
+ const int streamCount = std::min((int)codecConfig->mSimulcastEncodings.size(),
+ (int)webrtc::kMaxSimulcastStreams);
CSFLogDebug(logTag, "%s for VideoConduit:%p stream count:%d", __FUNCTION__,
this, static_cast<int>(streamCount));
mSendingFramerate = 0;
mEncoderConfig.ClearStreams();
mSendStreamConfig.rtp.rids.clear();
unsigned short width = 320;
@@ -528,19 +528,16 @@ WebrtcVideoConduit::ConfigureSendMediaCo
mSendingFramerate = SelectSendFrameRate(codecConfig,
max_framerate,
mSendingWidth,
mSendingHeight);
// So we can comply with b=TIAS/b=AS/maxbr=X when input resolution changes
mNegotiatedMaxBitrate = codecConfig->mTias;
- // width/height will be overridden on the first frame; they must be 'sane' for
- // SetSendCodec()
-
if (mSendingWidth != 0) {
// We're already in a call and are reconfiguring (perhaps due to
// ReplaceTrack).
bool resolutionChanged;
{
MutexAutoLock lock(mCodecMutex);
resolutionChanged = !mCurSendCodecConfig->ResolutionEquals(*codecConfig);
}
@@ -571,33 +568,45 @@ WebrtcVideoConduit::ConfigureSendMediaCo
}
if (config.max_bitrate_bps > 0 &&
config.max_bitrate_bps < mMinBitrateEstimate) {
config.max_bitrate_bps = mMinBitrateEstimate;
}
mCall->Call()->SetBitrateConfig(config);
}
- for (size_t idx = streamCount - 1; streamCount > 0; idx--, streamCount--) {
+ for (int idx = streamCount - 1; idx >= 0; --idx) {
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
- // width/height will be overridden on the first frame; they must be 'sane' for
- // SetSendCodec()
- video_stream.width = width >> idx;
- video_stream.height = height >> idx;
+ auto& simulcastEncoding = codecConfig->mSimulcastEncodings[idx];
+ CSFLogWarn(logTag, "%s streamCount %d", __FUNCTION__, streamCount);
+ if (streamCount == 1) {
+ // No simulcast, so there are no constraints on the resolution.
+ video_stream.width = width / simulcastEncoding.constraints.scaleDownBy;
+ video_stream.height = height / simulcastEncoding.constraints.scaleDownBy;
+ } else {
+ // Simulcast, all layers have to maintain the same exact aspect ratio.
+ video_stream.width = width >> idx;
+ video_stream.height = height >> idx;
+ if (video_stream.width * height != width * video_stream.height) {
+ // See ValidSimulcastResolutions() in vp8_impl.cc.
+ CSFLogWarn(logTag, "%s Invalid aspect ratio of simulcast layer nr %d",
+ __FUNCTION__, streamCount - idx);
+ break;
+ }
+ }
video_stream.max_framerate = mSendingFramerate;
- auto& simulcastEncoding = codecConfig->mSimulcastEncodings[idx];
// The underlying code (as of 49 and 57) actually ignores the values in
// the array, and uses the size of the array + 1. Chrome uses 3 for
// temporal layers when simulcast is in use (see simulcast.cc)
- video_stream.temporal_layer_thresholds_bps.resize(streamCount > 1 ? 3 : 1);
+ video_stream.temporal_layer_thresholds_bps.resize(idx > 0 ? 3 : 1);
// Calculate these first
video_stream.max_bitrate_bps = MinIgnoreZero(simulcastEncoding.constraints.maxBr,
kDefaultMaxBitrate_bps);
video_stream.max_bitrate_bps = MinIgnoreZero((int) mPrefMaxBitrate,
video_stream.max_bitrate_bps);
video_stream.min_bitrate_bps = (mMinBitrate ? mMinBitrate : kDefaultMinBitrate_bps);
if (video_stream.min_bitrate_bps > video_stream.max_bitrate_bps) {
video_stream.min_bitrate_bps = video_stream.max_bitrate_bps;