mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-14 14:20:45 +01:00

This CL is a step towards making the TemporalLayers landable in api/ : * It splits TemporalLayers from TemporalLayersChecker * It initially renames temporal_layer.h to vp8_temporal_layers.h and moved it into the include/ folder * It removes the dependency on VideoCodec, which was essentially only used to determine if screenshare_layers or default_temporal_layers should be used, and the number of temporal temporal layers to use. Subsequent CLs will make further cleanup before attempting a move to api Bug: webrtc:9012 Change-Id: I87ea7aac66d39284eaebd86aa9d015aba2eaaaea Reviewed-on: https://webrtc-review.googlesource.com/94156 Commit-Queue: Erik Språng <sprang@webrtc.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24920}
92 lines
3.1 KiB
C++
92 lines
3.1 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 <algorithm>
|
|
|
|
#include "modules/video_coding/utility/simulcast_utility.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::ValidSimulcastResolutions(const VideoCodec& codec,
|
|
int num_streams) {
|
|
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;
|
|
}
|
|
}
|
|
for (int i = 1; i < num_streams; ++i) {
|
|
if (codec.simulcastStream[i].width !=
|
|
codec.simulcastStream[i - 1].width * 2) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool SimulcastUtility::ValidSimulcastTemporalLayers(const VideoCodec& codec,
|
|
int num_streams) {
|
|
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) {
|
|
if (codec.mode != VideoCodecMode::kScreensharing ||
|
|
NumberOfTemporalLayers(codec, 0) != 2) {
|
|
return false;
|
|
}
|
|
// Fixed default bitrates for legacy screenshare layers mode.
|
|
return (codec.numberOfSimulcastStreams == 0 && codec.maxBitrate == 1000) ||
|
|
(codec.numberOfSimulcastStreams >= 1 &&
|
|
codec.simulcastStream[0].maxBitrate == 1000 &&
|
|
codec.simulcastStream[0].targetBitrate == 200);
|
|
}
|
|
|
|
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
|