mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-14 06:10:40 +01:00

This is a reland of 32ca95145c
Fix includes not enabling the screenshare conference behavior on non
screenshare sources even if the flag is enabled.
Original change's description:
> Only enable conference mode simulcast allocations with flag enabled
>
> Non-conference mode simulcast screenshares were mistakenly using the
> conference mode semantics in the simulcast rate allocator, which broke
> spec compliant usage in some situation.
>
> This behavior should only be used when explicitly using the SDP entry
> "a=x-google-flag:conference" in both offer and answer.
>
> Bug: webrtc:11310, chromium:1093819
> Change-Id: Ibcba75c88a8405d60467546b33977a782e04e469
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/179081
> Reviewed-by: Harald Alvestrand <hta@webrtc.org>
> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
> Commit-Queue: Florent Castelli <orphis@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#31828}
Bug: webrtc:11310
Bug: chromium:1093819
Change-Id: Ic933f93a5c4bad20583354fe821f8a1170e911cd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/180802
Commit-Queue: Florent Castelli <orphis@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31847}
104 lines
3.3 KiB
C++
104 lines
3.3 KiB
C++
/*
|
|
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "modules/video_coding/utility/simulcast_utility.h"
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
namespace webrtc {
|
|
|
|
uint32_t SimulcastUtility::SumStreamMaxBitrate(int streams,
|
|
const VideoCodec& codec) {
|
|
uint32_t bitrate_sum = 0;
|
|
for (int i = 0; i < streams; ++i) {
|
|
bitrate_sum += codec.simulcastStream[i].maxBitrate;
|
|
}
|
|
return bitrate_sum;
|
|
}
|
|
|
|
int SimulcastUtility::NumberOfSimulcastStreams(const VideoCodec& codec) {
|
|
int streams =
|
|
codec.numberOfSimulcastStreams < 1 ? 1 : codec.numberOfSimulcastStreams;
|
|
uint32_t simulcast_max_bitrate = SumStreamMaxBitrate(streams, codec);
|
|
if (simulcast_max_bitrate == 0) {
|
|
streams = 1;
|
|
}
|
|
return streams;
|
|
}
|
|
|
|
bool SimulcastUtility::ValidSimulcastParameters(const VideoCodec& codec,
|
|
int num_streams) {
|
|
// Check resolution.
|
|
if (codec.width != codec.simulcastStream[num_streams - 1].width ||
|
|
codec.height != codec.simulcastStream[num_streams - 1].height) {
|
|
return false;
|
|
}
|
|
for (int i = 0; i < num_streams; ++i) {
|
|
if (codec.width * codec.simulcastStream[i].height !=
|
|
codec.height * codec.simulcastStream[i].width) {
|
|
return false;
|
|
}
|
|
}
|
|
if (codec.codecType == webrtc::kVideoCodecVP8) {
|
|
for (int i = 1; i < num_streams; ++i) {
|
|
if (codec.simulcastStream[i].width < codec.simulcastStream[i - 1].width) {
|
|
return false;
|
|
}
|
|
}
|
|
} else {
|
|
// TODO(mirtad): H264 encoder implementation still assumes the default
|
|
// resolution downscaling is used.
|
|
for (int i = 1; i < num_streams; ++i) {
|
|
if (codec.simulcastStream[i].width !=
|
|
codec.simulcastStream[i - 1].width * 2) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Check frame-rate.
|
|
for (int i = 1; i < num_streams; ++i) {
|
|
if (fabs(codec.simulcastStream[i].maxFramerate -
|
|
codec.simulcastStream[i - 1].maxFramerate) > 1e-9) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Check temporal layers.
|
|
for (int i = 0; i < num_streams - 1; ++i) {
|
|
if (codec.simulcastStream[i].numberOfTemporalLayers !=
|
|
codec.simulcastStream[i + 1].numberOfTemporalLayers)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool SimulcastUtility::IsConferenceModeScreenshare(const VideoCodec& codec) {
|
|
return codec.mode == VideoCodecMode::kScreensharing &&
|
|
codec.legacy_conference_mode;
|
|
}
|
|
|
|
int SimulcastUtility::NumberOfTemporalLayers(const VideoCodec& codec,
|
|
int spatial_id) {
|
|
uint8_t num_temporal_layers =
|
|
std::max<uint8_t>(1, codec.VP8().numberOfTemporalLayers);
|
|
if (codec.numberOfSimulcastStreams > 0) {
|
|
RTC_DCHECK_LT(spatial_id, codec.numberOfSimulcastStreams);
|
|
num_temporal_layers =
|
|
std::max(num_temporal_layers,
|
|
codec.simulcastStream[spatial_id].numberOfTemporalLayers);
|
|
}
|
|
return num_temporal_layers;
|
|
}
|
|
|
|
} // namespace webrtc
|