diff --git a/api/video_codecs/BUILD.gn b/api/video_codecs/BUILD.gn index 597478ba0a..848008fc53 100644 --- a/api/video_codecs/BUILD.gn +++ b/api/video_codecs/BUILD.gn @@ -17,6 +17,8 @@ rtc_library("video_codecs_api") { sources = [ "sdp_video_format.cc", "sdp_video_format.h", + "spatial_layer.cc", + "spatial_layer.h", "video_codec.cc", "video_codec.h", "video_decoder.cc", diff --git a/api/video_codecs/spatial_layer.cc b/api/video_codecs/spatial_layer.cc new file mode 100644 index 0000000000..25ccdfeb48 --- /dev/null +++ b/api/video_codecs/spatial_layer.cc @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2020 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 "api/video_codecs/spatial_layer.h" + +namespace webrtc { + +bool SpatialLayer::operator==(const SpatialLayer& other) const { + return (width == other.width && height == other.height && + maxFramerate == other.maxFramerate && + numberOfTemporalLayers == other.numberOfTemporalLayers && + maxBitrate == other.maxBitrate && + targetBitrate == other.targetBitrate && + minBitrate == other.minBitrate && qpMax == other.qpMax && + active == other.active); +} + +} // namespace webrtc diff --git a/api/video_codecs/spatial_layer.h b/api/video_codecs/spatial_layer.h new file mode 100644 index 0000000000..5a1b425427 --- /dev/null +++ b/api/video_codecs/spatial_layer.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 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_SPATIAL_LAYER_H_ +#define API_VIDEO_CODECS_SPATIAL_LAYER_H_ + +namespace webrtc { + +struct SpatialLayer { + bool operator==(const SpatialLayer& other) const; + bool operator!=(const SpatialLayer& other) const { return !(*this == other); } + + unsigned short width; // NOLINT(runtime/int) + unsigned short height; // NOLINT(runtime/int) + float maxFramerate; // fps. + unsigned char numberOfTemporalLayers; + unsigned int maxBitrate; // kilobits/sec. + unsigned int targetBitrate; // kilobits/sec. + unsigned int minBitrate; // kilobits/sec. + unsigned int qpMax; // minimum quality + bool active; // encoded and sent. +}; + +} // namespace webrtc +#endif // API_VIDEO_CODECS_SPATIAL_LAYER_H_ diff --git a/api/video_codecs/video_codec.cc b/api/video_codecs/video_codec.cc index 92da338d2d..490eced4e0 100644 --- a/api/video_codecs/video_codec.cc +++ b/api/video_codecs/video_codec.cc @@ -56,16 +56,6 @@ bool VideoCodecH264::operator==(const VideoCodecH264& other) const { numberOfTemporalLayers == other.numberOfTemporalLayers); } -bool SpatialLayer::operator==(const SpatialLayer& other) const { - return (width == other.width && height == other.height && - maxFramerate == other.maxFramerate && - numberOfTemporalLayers == other.numberOfTemporalLayers && - maxBitrate == other.maxBitrate && - targetBitrate == other.targetBitrate && - minBitrate == other.minBitrate && qpMax == other.qpMax && - active == other.active); -} - VideoCodec::VideoCodec() : codecType(kVideoCodecGeneric), width(0), diff --git a/api/video_codecs/video_codec.h b/api/video_codecs/video_codec.h index d783390095..48e72edb67 100644 --- a/api/video_codecs/video_codec.h +++ b/api/video_codecs/video_codec.h @@ -19,7 +19,7 @@ #include "absl/types/optional.h" #include "api/video/video_bitrate_allocation.h" #include "api/video/video_codec_type.h" -#include "common_types.h" // NOLINT(build/include_directory) +#include "api/video_codecs/spatial_layer.h" #include "rtc_base/system/rtc_export.h" namespace webrtc { @@ -120,7 +120,7 @@ class RTC_EXPORT VideoCodec { unsigned int qpMax; unsigned char numberOfSimulcastStreams; - SimulcastStream simulcastStream[kMaxSimulcastStreams]; + SpatialLayer simulcastStream[kMaxSimulcastStreams]; SpatialLayer spatialLayers[kMaxSpatialLayers]; VideoCodecMode mode; diff --git a/common_types.h b/common_types.h index 1bf92bff5b..de1a5fd50b 100644 --- a/common_types.h +++ b/common_types.h @@ -31,29 +31,6 @@ class FrameCountObserver { uint32_t ssrc) = 0; }; -// ================================================================== -// Video specific types -// ================================================================== - -struct SpatialLayer { - bool operator==(const SpatialLayer& other) const; - bool operator!=(const SpatialLayer& other) const { return !(*this == other); } - - unsigned short width; - unsigned short height; - float maxFramerate; // fps. - unsigned char numberOfTemporalLayers; - unsigned int maxBitrate; // kilobits/sec. - unsigned int targetBitrate; // kilobits/sec. - unsigned int minBitrate; // kilobits/sec. - unsigned int qpMax; // minimum quality - bool active; // encoded and sent. -}; - -// Simulcast is when the same stream is encoded multiple times with different -// settings such as resolution. -typedef SpatialLayer SimulcastStream; - // Minimum and maximum playout delay values from capture to render. // These are best effort values. // diff --git a/media/engine/simulcast_encoder_adapter.cc b/media/engine/simulcast_encoder_adapter.cc index 60baed9daa..0f96dc2fa6 100644 --- a/media/engine/simulcast_encoder_adapter.cc +++ b/media/engine/simulcast_encoder_adapter.cc @@ -103,8 +103,8 @@ int VerifyCodec(const webrtc::VideoCodec* inst) { return WEBRTC_VIDEO_CODEC_OK; } -bool StreamResolutionCompare(const webrtc::SimulcastStream& a, - const webrtc::SimulcastStream& b) { +bool StreamResolutionCompare(const webrtc::SpatialLayer& a, + const webrtc::SpatialLayer& b) { return std::tie(a.height, a.width, a.maxBitrate, a.maxFramerate) < std::tie(b.height, b.width, b.maxBitrate, b.maxFramerate); } diff --git a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc index 990db54321..ee6301b739 100644 --- a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc +++ b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc @@ -67,7 +67,7 @@ void ConfigureSimulcast(VideoCodec* codec_settings) { /* is_screenshare = */ false, true); for (size_t i = 0; i < streams.size(); ++i) { - SimulcastStream* ss = &codec_settings->simulcastStream[i]; + SpatialLayer* ss = &codec_settings->simulcastStream[i]; ss->width = static_cast(streams[i].width); ss->height = static_cast(streams[i].height); ss->numberOfTemporalLayers = @@ -277,8 +277,7 @@ 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 SimulcastStream& simulcast_stream = - codec_settings.simulcastStream[i]; + const SpatialLayer& simulcast_stream = codec_settings.simulcastStream[i]; ss << "\nwidth: " << simulcast_stream.width; ss << "\nheight: " << simulcast_stream.height; ss << "\nnum_temporal_layers: " diff --git a/modules/video_coding/codecs/vp9/svc_config.h b/modules/video_coding/codecs/vp9/svc_config.h index 9bd8b0e313..f6b562e189 100644 --- a/modules/video_coding/codecs/vp9/svc_config.h +++ b/modules/video_coding/codecs/vp9/svc_config.h @@ -14,7 +14,7 @@ #include -#include "common_types.h" // NOLINT(build/include) +#include "api/video_codecs/spatial_layer.h" namespace webrtc { diff --git a/modules/video_coding/utility/simulcast_rate_allocator.cc b/modules/video_coding/utility/simulcast_rate_allocator.cc index 13de8755d0..3427676525 100644 --- a/modules/video_coding/utility/simulcast_rate_allocator.cc +++ b/modules/video_coding/utility/simulcast_rate_allocator.cc @@ -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 SimulcastStream& stream = + const SpatialLayer& 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 SimulcastStream& stream = codec_.simulcastStream[top_active_layer]; + const SpatialLayer& stream = codec_.simulcastStream[top_active_layer]; DataRate initial_layer_rate = DataRate::BitsPerSec( allocated_bitrates->GetSpatialLayerSum(top_active_layer)); DataRate additional_allocation = std::min( diff --git a/modules/video_coding/utility/simulcast_test_fixture_impl.cc b/modules/video_coding/utility/simulcast_test_fixture_impl.cc index 93d6fb7b25..a0abd96208 100644 --- a/modules/video_coding/utility/simulcast_test_fixture_impl.cc +++ b/modules/video_coding/utility/simulcast_test_fixture_impl.cc @@ -196,7 +196,7 @@ void ConfigureStream(int width, int min_bitrate, int target_bitrate, float max_framerate, - SimulcastStream* stream, + SpatialLayer* stream, int num_temporal_layers) { assert(stream); stream->width = width; diff --git a/modules/video_coding/video_codec_initializer.cc b/modules/video_coding/video_codec_initializer.cc index 2859dd022a..777056fb24 100644 --- a/modules/video_coding/video_codec_initializer.cc +++ b/modules/video_coding/video_codec_initializer.cc @@ -95,7 +95,7 @@ VideoCodec VideoCodecInitializer::VideoEncoderConfigToVideoCodec( int max_framerate = 0; for (size_t i = 0; i < streams.size(); ++i) { - SimulcastStream* sim_stream = &video_codec.simulcastStream[i]; + SpatialLayer* 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); diff --git a/test/fake_encoder.cc b/test/fake_encoder.cc index 219dafcf16..f33d3e85bd 100644 --- a/test/fake_encoder.cc +++ b/test/fake_encoder.cc @@ -92,7 +92,7 @@ int32_t FakeEncoder::Encode(const VideoFrame& input_image, const std::vector* frame_types) { unsigned char max_framerate; unsigned char num_simulcast_streams; - SimulcastStream simulcast_streams[kMaxSimulcastStreams]; + SpatialLayer simulcast_streams[kMaxSimulcastStreams]; EncodedImageCallback* callback; RateControlParameters rates; VideoCodecMode mode; @@ -168,7 +168,7 @@ FakeEncoder::FrameInfo FakeEncoder::NextFrame( bool keyframe, uint8_t num_simulcast_streams, const VideoBitrateAllocation& target_bitrate, - SimulcastStream simulcast_streams[kMaxSimulcastStreams], + SpatialLayer simulcast_streams[kMaxSimulcastStreams], int framerate) { FrameInfo frame_info; frame_info.keyframe = keyframe; diff --git a/test/fake_encoder.h b/test/fake_encoder.h index 22c772311c..6808256523 100644 --- a/test/fake_encoder.h +++ b/test/fake_encoder.h @@ -80,7 +80,7 @@ class FakeEncoder : public VideoEncoder { bool keyframe, uint8_t num_simulcast_streams, const VideoBitrateAllocation& target_bitrate, - SimulcastStream simulcast_streams[kMaxSimulcastStreams], + SpatialLayer simulcast_streams[kMaxSimulcastStreams], int framerate) RTC_LOCKS_EXCLUDED(mutex_); // Called before the frame is passed to callback_->OnEncodedImage, to let