Define SimulcastStream as an alias for SpatialLayer
Step one in making it a separate type, that will be done as a followup, after downstream code is updated to use the new name. Bug: webrtc:11607 Change-Id: I6fa664a0729b1cfd71b7f02b6441880beee0e741 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/262806 Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36946}
This commit is contained in:
parent
1c633c8b87
commit
c0a9f35248
@ -23,6 +23,7 @@ rtc_library("video_codecs_api") {
|
||||
"h264_profile_level_id.h",
|
||||
"sdp_video_format.cc",
|
||||
"sdp_video_format.h",
|
||||
"simulcast_stream.h",
|
||||
"spatial_layer.cc",
|
||||
"spatial_layer.h",
|
||||
"video_codec.cc",
|
||||
|
||||
24
api/video_codecs/simulcast_stream.h
Normal file
24
api/video_codecs/simulcast_stream.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
#ifndef API_VIDEO_CODECS_SIMULCAST_STREAM_H_
|
||||
#define API_VIDEO_CODECS_SIMULCAST_STREAM_H_
|
||||
|
||||
#include "api/video_codecs/spatial_layer.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// TODO(bugs.webrtc.org/6883): Unify with struct VideoStream, part of
|
||||
// VideoEncoderConfig.
|
||||
// TODO(bugs.webrtc.org/11607): Make this a separate type, rather than an alias.
|
||||
using SimulcastStream = SpatialLayer;
|
||||
|
||||
} // namespace webrtc
|
||||
#endif // API_VIDEO_CODECS_SIMULCAST_STREAM_H_
|
||||
@ -20,6 +20,7 @@
|
||||
#include "api/video/video_bitrate_allocation.h"
|
||||
#include "api/video/video_codec_type.h"
|
||||
#include "api/video_codecs/scalability_mode.h"
|
||||
#include "api/video_codecs/simulcast_stream.h"
|
||||
#include "api/video_codecs/spatial_layer.h"
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
|
||||
@ -136,7 +137,7 @@ class RTC_EXPORT VideoCodec {
|
||||
|
||||
unsigned int qpMax;
|
||||
unsigned char numberOfSimulcastStreams;
|
||||
SpatialLayer simulcastStream[kMaxSimulcastStreams];
|
||||
SimulcastStream simulcastStream[kMaxSimulcastStreams];
|
||||
SpatialLayer spatialLayers[kMaxSpatialLayers];
|
||||
|
||||
VideoCodecMode mode;
|
||||
|
||||
@ -108,14 +108,14 @@ int VerifyCodec(const webrtc::VideoCodec* inst) {
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
bool StreamQualityCompare(const webrtc::SpatialLayer& a,
|
||||
const webrtc::SpatialLayer& b) {
|
||||
bool StreamQualityCompare(const webrtc::SimulcastStream& a,
|
||||
const webrtc::SimulcastStream& b) {
|
||||
return std::tie(a.height, a.width, a.maxBitrate, a.maxFramerate) <
|
||||
std::tie(b.height, b.width, b.maxBitrate, b.maxFramerate);
|
||||
}
|
||||
|
||||
void GetLowestAndHighestQualityStreamIndixes(
|
||||
rtc::ArrayView<webrtc::SpatialLayer> streams,
|
||||
rtc::ArrayView<webrtc::SimulcastStream> streams,
|
||||
int* lowest_quality_stream_idx,
|
||||
int* highest_quality_stream_idx) {
|
||||
const auto lowest_highest_quality_streams =
|
||||
@ -328,8 +328,8 @@ int SimulcastEncoderAdapter::InitEncode(
|
||||
int highest_quality_stream_idx = 0;
|
||||
if (!is_legacy_singlecast) {
|
||||
GetLowestAndHighestQualityStreamIndixes(
|
||||
rtc::ArrayView<SpatialLayer>(codec_.simulcastStream,
|
||||
total_streams_count_),
|
||||
rtc::ArrayView<SimulcastStream>(codec_.simulcastStream,
|
||||
total_streams_count_),
|
||||
&lowest_quality_stream_idx, &highest_quality_stream_idx);
|
||||
}
|
||||
|
||||
@ -762,7 +762,7 @@ webrtc::VideoCodec SimulcastEncoderAdapter::MakeStreamCodec(
|
||||
bool is_lowest_quality_stream,
|
||||
bool is_highest_quality_stream) {
|
||||
webrtc::VideoCodec codec_params = codec;
|
||||
const SpatialLayer& stream_params = codec.simulcastStream[stream_idx];
|
||||
const SimulcastStream& stream_params = codec.simulcastStream[stream_idx];
|
||||
|
||||
codec_params.numberOfSimulcastStreams = 0;
|
||||
codec_params.width = stream_params.width;
|
||||
|
||||
@ -70,7 +70,7 @@ void ConfigureSimulcast(VideoCodec* codec_settings) {
|
||||
/* is_screenshare = */ false, true, trials);
|
||||
|
||||
for (size_t i = 0; i < streams.size(); ++i) {
|
||||
SpatialLayer* ss = &codec_settings->simulcastStream[i];
|
||||
SimulcastStream* ss = &codec_settings->simulcastStream[i];
|
||||
ss->width = static_cast<uint16_t>(streams[i].width);
|
||||
ss->height = static_cast<uint16_t>(streams[i].height);
|
||||
ss->numberOfTemporalLayers =
|
||||
@ -302,7 +302,8 @@ std::string VideoCodecTestFixtureImpl::Config::ToString() const {
|
||||
if (codec_settings.numberOfSimulcastStreams > 1) {
|
||||
for (int i = 0; i < codec_settings.numberOfSimulcastStreams; ++i) {
|
||||
ss << "\n\n--> codec_settings.simulcastStream[" << i << "]";
|
||||
const SpatialLayer& simulcast_stream = codec_settings.simulcastStream[i];
|
||||
const SimulcastStream& simulcast_stream =
|
||||
codec_settings.simulcastStream[i];
|
||||
ss << "\nwidth: " << simulcast_stream.width;
|
||||
ss << "\nheight: " << simulcast_stream.height;
|
||||
ss << "\nnum_temporal_layers: "
|
||||
|
||||
@ -151,7 +151,7 @@ void SimulcastRateAllocator::DistributeAllocationToSimulcastLayers(
|
||||
size_t top_active_layer = active_layer;
|
||||
// Allocate up to the target bitrate for each active simulcast layer.
|
||||
for (; active_layer < codec_.numberOfSimulcastStreams; ++active_layer) {
|
||||
const SpatialLayer& stream =
|
||||
const SimulcastStream& stream =
|
||||
codec_.simulcastStream[layer_index[active_layer]];
|
||||
if (!stream.active) {
|
||||
stream_enabled_[layer_index[active_layer]] = false;
|
||||
@ -194,7 +194,7 @@ void SimulcastRateAllocator::DistributeAllocationToSimulcastLayers(
|
||||
// TODO(sprang): Allocate up to max bitrate for all layers once we have a
|
||||
// better idea of possible performance implications.
|
||||
if (left_in_total_allocation > DataRate::Zero()) {
|
||||
const SpatialLayer& stream = codec_.simulcastStream[top_active_layer];
|
||||
const SimulcastStream& stream = codec_.simulcastStream[top_active_layer];
|
||||
DataRate initial_layer_rate = DataRate::BitsPerSec(
|
||||
allocated_bitrates->GetSpatialLayerSum(top_active_layer));
|
||||
DataRate additional_allocation = std::min(
|
||||
|
||||
@ -188,7 +188,7 @@ void ConfigureStream(int width,
|
||||
int min_bitrate,
|
||||
int target_bitrate,
|
||||
float max_framerate,
|
||||
SpatialLayer* stream,
|
||||
SimulcastStream* stream,
|
||||
int num_temporal_layers) {
|
||||
RTC_DCHECK(stream);
|
||||
stream->width = width;
|
||||
|
||||
@ -100,7 +100,7 @@ VideoCodec VideoCodecInitializer::VideoEncoderConfigToVideoCodec(
|
||||
absl::optional<ScalabilityMode> scalability_mode =
|
||||
streams[0].scalability_mode;
|
||||
for (size_t i = 0; i < streams.size(); ++i) {
|
||||
SpatialLayer* sim_stream = &video_codec.simulcastStream[i];
|
||||
SimulcastStream* sim_stream = &video_codec.simulcastStream[i];
|
||||
RTC_DCHECK_GT(streams[i].width, 0);
|
||||
RTC_DCHECK_GT(streams[i].height, 0);
|
||||
RTC_DCHECK_GT(streams[i].max_framerate, 0);
|
||||
|
||||
@ -94,7 +94,7 @@ int32_t FakeEncoder::Encode(const VideoFrame& input_image,
|
||||
const std::vector<VideoFrameType>* frame_types) {
|
||||
unsigned char max_framerate;
|
||||
unsigned char num_simulcast_streams;
|
||||
SpatialLayer simulcast_streams[kMaxSimulcastStreams];
|
||||
SimulcastStream simulcast_streams[kMaxSimulcastStreams];
|
||||
EncodedImageCallback* callback;
|
||||
RateControlParameters rates;
|
||||
bool keyframe;
|
||||
@ -168,7 +168,7 @@ FakeEncoder::FrameInfo FakeEncoder::NextFrame(
|
||||
bool keyframe,
|
||||
uint8_t num_simulcast_streams,
|
||||
const VideoBitrateAllocation& target_bitrate,
|
||||
SpatialLayer simulcast_streams[kMaxSimulcastStreams],
|
||||
SimulcastStream simulcast_streams[kMaxSimulcastStreams],
|
||||
int framerate) {
|
||||
FrameInfo frame_info;
|
||||
frame_info.keyframe = keyframe;
|
||||
|
||||
@ -82,7 +82,7 @@ class FakeEncoder : public VideoEncoder {
|
||||
bool keyframe,
|
||||
uint8_t num_simulcast_streams,
|
||||
const VideoBitrateAllocation& target_bitrate,
|
||||
SpatialLayer simulcast_streams[kMaxSimulcastStreams],
|
||||
SimulcastStream simulcast_streams[kMaxSimulcastStreams],
|
||||
int framerate) RTC_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Called before the frame is passed to callback_->OnEncodedImage, to let
|
||||
|
||||
@ -33,24 +33,31 @@ void SetEncoderSpecific(VideoEncoderConfig* encoder_config,
|
||||
}
|
||||
}
|
||||
|
||||
SpatialLayer GetLayer(int pixels, const VideoCodec& codec) {
|
||||
struct BitrateLimits {
|
||||
DataRate min = DataRate::Zero();
|
||||
DataRate max = DataRate::Zero();
|
||||
};
|
||||
|
||||
BitrateLimits GetLayerBitrateLimits(int pixels, const VideoCodec& codec) {
|
||||
if (codec.codecType == VideoCodecType::kVideoCodecVP9) {
|
||||
for (size_t i = 0; i < codec.VP9().numberOfSpatialLayers; ++i) {
|
||||
if (codec.spatialLayers[i].width * codec.spatialLayers[i].height ==
|
||||
pixels) {
|
||||
return codec.spatialLayers[i];
|
||||
return {DataRate::KilobitsPerSec(codec.spatialLayers[i].minBitrate),
|
||||
DataRate::KilobitsPerSec(codec.spatialLayers[i].maxBitrate)};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < codec.numberOfSimulcastStreams; ++i) {
|
||||
if (codec.simulcastStream[i].width * codec.simulcastStream[i].height ==
|
||||
pixels) {
|
||||
return codec.simulcastStream[i];
|
||||
return {DataRate::KilobitsPerSec(codec.simulcastStream[i].minBitrate),
|
||||
DataRate::KilobitsPerSec(codec.simulcastStream[i].maxBitrate)};
|
||||
}
|
||||
}
|
||||
}
|
||||
ADD_FAILURE();
|
||||
return SpatialLayer();
|
||||
return BitrateLimits();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -147,17 +154,13 @@ class InitEncodeTest : public test::EndToEndTest,
|
||||
int32_t InitEncode(const VideoCodec* codec,
|
||||
const Settings& settings) override {
|
||||
for (const auto& expected : expectations_) {
|
||||
SpatialLayer layer = GetLayer(expected.pixels, *codec);
|
||||
BitrateLimits limits = GetLayerBitrateLimits(expected.pixels, *codec);
|
||||
if (expected.eq_bitrate.min)
|
||||
EXPECT_EQ(*expected.eq_bitrate.min,
|
||||
DataRate::KilobitsPerSec(layer.minBitrate));
|
||||
EXPECT_EQ(*expected.eq_bitrate.min, limits.min);
|
||||
if (expected.eq_bitrate.max)
|
||||
EXPECT_EQ(*expected.eq_bitrate.max,
|
||||
DataRate::KilobitsPerSec(layer.maxBitrate));
|
||||
EXPECT_NE(expected.ne_bitrate.min,
|
||||
DataRate::KilobitsPerSec(layer.minBitrate));
|
||||
EXPECT_NE(expected.ne_bitrate.max,
|
||||
DataRate::KilobitsPerSec(layer.maxBitrate));
|
||||
EXPECT_EQ(*expected.eq_bitrate.max, limits.max);
|
||||
EXPECT_NE(expected.ne_bitrate.min, limits.min);
|
||||
EXPECT_NE(expected.ne_bitrate.max, limits.max);
|
||||
}
|
||||
observation_complete_.Set();
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user