2016-11-16 16:41:30 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/include/video_codec_initializer.h"
|
2016-11-16 16:41:30 +01:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
#include "absl/types/optional.h"
|
2019-01-25 20:26:48 +01:00
|
|
|
#include "api/scoped_refptr.h"
|
2019-10-11 16:54:18 +02:00
|
|
|
#include "api/units/data_rate.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "api/video/video_bitrate_allocation.h"
|
2018-01-30 10:32:13 +01:00
|
|
|
#include "api/video_codecs/video_encoder.h"
|
2018-03-28 19:32:37 +02:00
|
|
|
#include "modules/video_coding/codecs/vp9/svc_config.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/include/video_coding_defines.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/checks.h"
|
2019-10-11 16:54:18 +02:00
|
|
|
#include "rtc_base/experiments/min_video_bitrate_experiment.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/logging.h"
|
2019-10-11 16:54:18 +02:00
|
|
|
#include "rtc_base/numerics/safe_conversions.h"
|
2016-11-16 16:41:30 +01:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2018-11-08 10:02:56 -08:00
|
|
|
bool VideoCodecInitializer::SetupCodec(const VideoEncoderConfig& config,
|
|
|
|
|
const std::vector<VideoStream>& streams,
|
|
|
|
|
VideoCodec* codec) {
|
Reland "Reland "Move rtp-specific config out of EncoderSettings.""
This reverts commit 6c2c13af06b32778b86950681758a7970d1c5d9e.
Reason for revert: Intend to investigate and fix perf problems.
Original change's description:
> Revert "Reland "Move rtp-specific config out of EncoderSettings.""
>
> This reverts commit 04dd1768625eb2241d1fb97fd0137897e703e266.
>
> Reason for revert: Regression in ramp up perf tests.
>
> Original change's description:
> > Reland "Move rtp-specific config out of EncoderSettings."
> >
> > This is a reland of bc900cb1d1810fcf678fe41cf1e3966daa39c88c
> >
> > Original change's description:
> > > Move rtp-specific config out of EncoderSettings.
> > >
> > > In VideoSendStream::Config, move payload_name and payload_type from
> > > EncoderSettings to Rtp.
> > >
> > > EncoderSettings now contains configuration for VideoStreamEncoder only,
> > > and should perhaps be renamed in a follow up cl. It's no longer
> > > passed as an argument to VideoCodecInitializer::SetupCodec.
> > >
> > > The latter then needs a different way to know the codec type,
> > > which is provided by a new codec_type member in VideoEncoderConfig.
> > >
> > > Bug: webrtc:8830
> > > Change-Id: Ifcc691aef1ee6a95e43c0452c5e630d92a511cd6
> > > Reviewed-on: https://webrtc-review.googlesource.com/62062
> > > Commit-Queue: Niels Moller <nisse@webrtc.org>
> > > Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
> > > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
> > > Cr-Commit-Position: refs/heads/master@{#22532}
> >
> > Bug: webrtc:8830
> > Change-Id: If88ef7d57cdaa4fae3c7b2a97ea5a6e1b833e019
> > Reviewed-on: https://webrtc-review.googlesource.com/63721
> > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
> > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > Commit-Queue: Niels Moller <nisse@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#22595}
>
> TBR=brandtr@webrtc.org,magjed@webrtc.org,nisse@webrtc.org,stefan@webrtc.org
>
> Bug: webrtc:8830,chromium:827080
> Change-Id: Iaaf146de91ec5c0d741b8efdf143f7e173084fef
> Reviewed-on: https://webrtc-review.googlesource.com/65520
> Commit-Queue: Niels Moller <nisse@webrtc.org>
> Reviewed-by: Niels Moller <nisse@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#22677}
TBR=brandtr@webrtc.org,magjed@webrtc.org,nisse@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: webrtc:8830, chromium:827080
Change-Id: I9b62987bf5daced90dfeb3ebb6739c80117c487f
Reviewed-on: https://webrtc-review.googlesource.com/66862
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22751}
2018-04-05 15:36:51 +02:00
|
|
|
if (config.codec_type == kVideoCodecMultiplex) {
|
2018-03-22 08:52:50 +01:00
|
|
|
VideoEncoderConfig associated_config = config.Copy();
|
|
|
|
|
associated_config.codec_type = kVideoCodecVP9;
|
2018-11-08 10:02:56 -08:00
|
|
|
if (!SetupCodec(associated_config, streams, codec)) {
|
2017-12-11 12:21:02 +05:30
|
|
|
RTC_LOG(LS_ERROR) << "Failed to create stereo encoder configuration.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-01-25 13:01:09 -08:00
|
|
|
codec->codecType = kVideoCodecMultiplex;
|
2017-12-11 12:21:02 +05:30
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
*codec = VideoEncoderConfigToVideoCodec(config, streams);
|
2016-11-16 16:41:30 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(sprang): Split this up and separate the codec specific parts.
|
|
|
|
|
VideoCodec VideoCodecInitializer::VideoEncoderConfigToVideoCodec(
|
|
|
|
|
const VideoEncoderConfig& config,
|
2018-04-26 09:51:47 +02:00
|
|
|
const std::vector<VideoStream>& streams) {
|
2016-11-16 16:41:30 +01:00
|
|
|
static const int kEncoderMinBitrateKbps = 30;
|
|
|
|
|
RTC_DCHECK(!streams.empty());
|
|
|
|
|
RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0);
|
|
|
|
|
|
|
|
|
|
VideoCodec video_codec;
|
|
|
|
|
memset(&video_codec, 0, sizeof(video_codec));
|
Reland "Reland "Move rtp-specific config out of EncoderSettings.""
This reverts commit 6c2c13af06b32778b86950681758a7970d1c5d9e.
Reason for revert: Intend to investigate and fix perf problems.
Original change's description:
> Revert "Reland "Move rtp-specific config out of EncoderSettings.""
>
> This reverts commit 04dd1768625eb2241d1fb97fd0137897e703e266.
>
> Reason for revert: Regression in ramp up perf tests.
>
> Original change's description:
> > Reland "Move rtp-specific config out of EncoderSettings."
> >
> > This is a reland of bc900cb1d1810fcf678fe41cf1e3966daa39c88c
> >
> > Original change's description:
> > > Move rtp-specific config out of EncoderSettings.
> > >
> > > In VideoSendStream::Config, move payload_name and payload_type from
> > > EncoderSettings to Rtp.
> > >
> > > EncoderSettings now contains configuration for VideoStreamEncoder only,
> > > and should perhaps be renamed in a follow up cl. It's no longer
> > > passed as an argument to VideoCodecInitializer::SetupCodec.
> > >
> > > The latter then needs a different way to know the codec type,
> > > which is provided by a new codec_type member in VideoEncoderConfig.
> > >
> > > Bug: webrtc:8830
> > > Change-Id: Ifcc691aef1ee6a95e43c0452c5e630d92a511cd6
> > > Reviewed-on: https://webrtc-review.googlesource.com/62062
> > > Commit-Queue: Niels Moller <nisse@webrtc.org>
> > > Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
> > > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
> > > Cr-Commit-Position: refs/heads/master@{#22532}
> >
> > Bug: webrtc:8830
> > Change-Id: If88ef7d57cdaa4fae3c7b2a97ea5a6e1b833e019
> > Reviewed-on: https://webrtc-review.googlesource.com/63721
> > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
> > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > Commit-Queue: Niels Moller <nisse@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#22595}
>
> TBR=brandtr@webrtc.org,magjed@webrtc.org,nisse@webrtc.org,stefan@webrtc.org
>
> Bug: webrtc:8830,chromium:827080
> Change-Id: Iaaf146de91ec5c0d741b8efdf143f7e173084fef
> Reviewed-on: https://webrtc-review.googlesource.com/65520
> Commit-Queue: Niels Moller <nisse@webrtc.org>
> Reviewed-by: Niels Moller <nisse@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#22677}
TBR=brandtr@webrtc.org,magjed@webrtc.org,nisse@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: webrtc:8830, chromium:827080
Change-Id: I9b62987bf5daced90dfeb3ebb6739c80117c487f
Reviewed-on: https://webrtc-review.googlesource.com/66862
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22751}
2018-04-05 15:36:51 +02:00
|
|
|
video_codec.codecType = config.codec_type;
|
2016-11-16 16:41:30 +01:00
|
|
|
|
|
|
|
|
switch (config.content_type) {
|
|
|
|
|
case VideoEncoderConfig::ContentType::kRealtimeVideo:
|
2018-06-13 11:52:16 +02:00
|
|
|
video_codec.mode = VideoCodecMode::kRealtimeVideo;
|
2016-11-16 16:41:30 +01:00
|
|
|
break;
|
|
|
|
|
case VideoEncoderConfig::ContentType::kScreen:
|
2018-06-13 11:52:16 +02:00
|
|
|
video_codec.mode = VideoCodecMode::kScreensharing;
|
2016-11-16 16:41:30 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-04 11:40:23 +02:00
|
|
|
video_codec.legacy_conference_mode =
|
|
|
|
|
config.content_type == VideoEncoderConfig::ContentType::kScreen &&
|
|
|
|
|
config.legacy_conference_mode;
|
|
|
|
|
|
2016-11-16 16:41:30 +01:00
|
|
|
video_codec.numberOfSimulcastStreams =
|
|
|
|
|
static_cast<unsigned char>(streams.size());
|
|
|
|
|
video_codec.minBitrate = streams[0].min_bitrate_bps / 1000;
|
2018-01-18 10:39:54 -08:00
|
|
|
bool codec_active = false;
|
2020-06-18 19:16:53 +02:00
|
|
|
// Active configuration might not be fully copied to |streams| for SVC yet.
|
|
|
|
|
// Therefore the |config| is checked here.
|
|
|
|
|
for (const VideoStream& stream : config.simulcast_layers) {
|
2018-01-18 10:39:54 -08:00
|
|
|
if (stream.active) {
|
|
|
|
|
codec_active = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Set active for the entire video codec for the non simulcast case.
|
|
|
|
|
video_codec.active = codec_active;
|
2016-11-16 16:41:30 +01:00
|
|
|
if (video_codec.minBitrate < kEncoderMinBitrateKbps)
|
|
|
|
|
video_codec.minBitrate = kEncoderMinBitrateKbps;
|
2017-06-19 07:18:55 -07:00
|
|
|
video_codec.timing_frame_thresholds = {kDefaultTimingFramesDelayMs,
|
|
|
|
|
kDefaultOutlierFrameSizePercent};
|
2016-11-28 15:58:53 -08:00
|
|
|
RTC_DCHECK_LE(streams.size(), kMaxSimulcastStreams);
|
2018-03-28 19:32:37 +02:00
|
|
|
|
2019-12-06 15:03:19 +01:00
|
|
|
int max_framerate = 0;
|
|
|
|
|
|
2016-11-16 16:41:30 +01:00
|
|
|
for (size_t i = 0; i < streams.size(); ++i) {
|
2020-08-14 15:32:14 +02:00
|
|
|
SpatialLayer* sim_stream = &video_codec.simulcastStream[i];
|
2016-11-28 15:21:39 -08:00
|
|
|
RTC_DCHECK_GT(streams[i].width, 0);
|
|
|
|
|
RTC_DCHECK_GT(streams[i].height, 0);
|
2016-11-16 16:41:30 +01:00
|
|
|
RTC_DCHECK_GT(streams[i].max_framerate, 0);
|
|
|
|
|
RTC_DCHECK_GE(streams[i].min_bitrate_bps, 0);
|
|
|
|
|
RTC_DCHECK_GE(streams[i].target_bitrate_bps, streams[i].min_bitrate_bps);
|
|
|
|
|
RTC_DCHECK_GE(streams[i].max_bitrate_bps, streams[i].target_bitrate_bps);
|
|
|
|
|
RTC_DCHECK_GE(streams[i].max_qp, 0);
|
|
|
|
|
|
|
|
|
|
sim_stream->width = static_cast<uint16_t>(streams[i].width);
|
|
|
|
|
sim_stream->height = static_cast<uint16_t>(streams[i].height);
|
2018-08-22 11:42:16 +02:00
|
|
|
sim_stream->maxFramerate = streams[i].max_framerate;
|
2016-11-16 16:41:30 +01:00
|
|
|
sim_stream->minBitrate = streams[i].min_bitrate_bps / 1000;
|
|
|
|
|
sim_stream->targetBitrate = streams[i].target_bitrate_bps / 1000;
|
|
|
|
|
sim_stream->maxBitrate = streams[i].max_bitrate_bps / 1000;
|
|
|
|
|
sim_stream->qpMax = streams[i].max_qp;
|
2018-03-01 15:11:29 +01:00
|
|
|
sim_stream->numberOfTemporalLayers =
|
|
|
|
|
static_cast<unsigned char>(streams[i].num_temporal_layers.value_or(1));
|
2018-01-18 10:39:54 -08:00
|
|
|
sim_stream->active = streams[i].active;
|
2016-11-16 16:41:30 +01:00
|
|
|
|
|
|
|
|
video_codec.width =
|
2018-06-08 11:04:04 +00:00
|
|
|
std::max(video_codec.width, static_cast<uint16_t>(streams[i].width));
|
2016-11-16 16:41:30 +01:00
|
|
|
video_codec.height =
|
2018-06-08 11:04:04 +00:00
|
|
|
std::max(video_codec.height, static_cast<uint16_t>(streams[i].height));
|
2016-11-16 16:41:30 +01:00
|
|
|
video_codec.minBitrate =
|
|
|
|
|
std::min(static_cast<uint16_t>(video_codec.minBitrate),
|
|
|
|
|
static_cast<uint16_t>(streams[i].min_bitrate_bps / 1000));
|
|
|
|
|
video_codec.maxBitrate += streams[i].max_bitrate_bps / 1000;
|
|
|
|
|
video_codec.qpMax = std::max(video_codec.qpMax,
|
|
|
|
|
static_cast<unsigned int>(streams[i].max_qp));
|
2019-12-06 15:03:19 +01:00
|
|
|
max_framerate = std::max(max_framerate, streams[i].max_framerate);
|
2016-11-16 16:41:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (video_codec.maxBitrate == 0) {
|
|
|
|
|
// Unset max bitrate -> cap to one bit per pixel.
|
|
|
|
|
video_codec.maxBitrate =
|
|
|
|
|
(video_codec.width * video_codec.height * video_codec.maxFramerate) /
|
|
|
|
|
1000;
|
|
|
|
|
}
|
|
|
|
|
if (video_codec.maxBitrate < kEncoderMinBitrateKbps)
|
|
|
|
|
video_codec.maxBitrate = kEncoderMinBitrateKbps;
|
|
|
|
|
|
2019-12-06 15:03:19 +01:00
|
|
|
video_codec.maxFramerate = max_framerate;
|
2018-03-28 19:32:37 +02:00
|
|
|
|
|
|
|
|
// Set codec specific options
|
|
|
|
|
if (config.encoder_specific_settings)
|
|
|
|
|
config.encoder_specific_settings->FillEncoderSpecificSettings(&video_codec);
|
|
|
|
|
|
|
|
|
|
switch (video_codec.codecType) {
|
|
|
|
|
case kVideoCodecVP8: {
|
|
|
|
|
if (!config.encoder_specific_settings) {
|
|
|
|
|
*video_codec.VP8() = VideoEncoder::GetDefaultVp8Settings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
video_codec.VP8()->numberOfTemporalLayers = static_cast<unsigned char>(
|
|
|
|
|
streams.back().num_temporal_layers.value_or(
|
|
|
|
|
video_codec.VP8()->numberOfTemporalLayers));
|
|
|
|
|
RTC_DCHECK_GE(video_codec.VP8()->numberOfTemporalLayers, 1);
|
|
|
|
|
RTC_DCHECK_LE(video_codec.VP8()->numberOfTemporalLayers,
|
|
|
|
|
kMaxTemporalStreams);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kVideoCodecVP9: {
|
2020-02-05 17:31:00 +01:00
|
|
|
// Force the first stream to always be active.
|
|
|
|
|
video_codec.simulcastStream[0].active = codec_active;
|
|
|
|
|
|
2018-03-28 19:32:37 +02:00
|
|
|
if (!config.encoder_specific_settings) {
|
|
|
|
|
*video_codec.VP9() = VideoEncoder::GetDefaultVp9Settings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
video_codec.VP9()->numberOfTemporalLayers = static_cast<unsigned char>(
|
|
|
|
|
streams.back().num_temporal_layers.value_or(
|
|
|
|
|
video_codec.VP9()->numberOfTemporalLayers));
|
|
|
|
|
RTC_DCHECK_GE(video_codec.VP9()->numberOfTemporalLayers, 1);
|
|
|
|
|
RTC_DCHECK_LE(video_codec.VP9()->numberOfTemporalLayers,
|
|
|
|
|
kMaxTemporalStreams);
|
|
|
|
|
|
2018-05-17 16:46:43 +02:00
|
|
|
RTC_DCHECK(config.spatial_layers.empty() ||
|
|
|
|
|
config.spatial_layers.size() ==
|
|
|
|
|
video_codec.VP9()->numberOfSpatialLayers);
|
|
|
|
|
|
|
|
|
|
std::vector<SpatialLayer> spatial_layers;
|
|
|
|
|
if (!config.spatial_layers.empty()) {
|
|
|
|
|
// Layering is set explicitly.
|
|
|
|
|
spatial_layers = config.spatial_layers;
|
2018-03-28 19:32:37 +02:00
|
|
|
} else {
|
2020-04-14 10:28:19 +02:00
|
|
|
size_t first_active_layer = 0;
|
2020-02-11 12:50:38 +01:00
|
|
|
for (size_t spatial_idx = 0;
|
|
|
|
|
spatial_idx < config.simulcast_layers.size(); ++spatial_idx) {
|
|
|
|
|
if (config.simulcast_layers[spatial_idx].active) {
|
2020-04-14 10:28:19 +02:00
|
|
|
first_active_layer = spatial_idx;
|
2020-02-11 12:50:38 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-22 11:42:16 +02:00
|
|
|
spatial_layers = GetSvcConfig(
|
|
|
|
|
video_codec.width, video_codec.height, video_codec.maxFramerate,
|
2020-04-14 10:28:19 +02:00
|
|
|
first_active_layer, video_codec.VP9()->numberOfSpatialLayers,
|
2018-08-22 11:42:16 +02:00
|
|
|
video_codec.VP9()->numberOfTemporalLayers,
|
|
|
|
|
video_codec.mode == VideoCodecMode::kScreensharing);
|
2018-05-17 16:46:43 +02:00
|
|
|
|
2018-11-28 13:32:13 +01:00
|
|
|
// If there was no request for spatial layering, don't limit bitrate
|
|
|
|
|
// of single spatial layer.
|
|
|
|
|
const bool no_spatial_layering =
|
|
|
|
|
video_codec.VP9()->numberOfSpatialLayers <= 1;
|
2018-05-17 16:46:43 +02:00
|
|
|
if (no_spatial_layering) {
|
|
|
|
|
// Use codec's bitrate limits.
|
|
|
|
|
spatial_layers.back().minBitrate = video_codec.minBitrate;
|
2019-03-05 10:08:35 +01:00
|
|
|
spatial_layers.back().targetBitrate = video_codec.maxBitrate;
|
2018-05-17 16:46:43 +02:00
|
|
|
spatial_layers.back().maxBitrate = video_codec.maxBitrate;
|
2018-03-28 19:32:37 +02:00
|
|
|
}
|
2018-12-10 09:28:53 +01:00
|
|
|
|
2020-06-18 19:16:53 +02:00
|
|
|
for (size_t spatial_idx = first_active_layer;
|
2018-12-10 09:28:53 +01:00
|
|
|
spatial_idx < config.simulcast_layers.size() &&
|
|
|
|
|
spatial_idx < spatial_layers.size();
|
|
|
|
|
++spatial_idx) {
|
2020-04-14 10:28:19 +02:00
|
|
|
spatial_layers[spatial_idx - first_active_layer].active =
|
2018-12-10 09:28:53 +01:00
|
|
|
config.simulcast_layers[spatial_idx].active;
|
|
|
|
|
}
|
2018-05-17 16:46:43 +02:00
|
|
|
}
|
2018-03-28 19:32:37 +02:00
|
|
|
|
2018-05-17 16:46:43 +02:00
|
|
|
RTC_DCHECK(!spatial_layers.empty());
|
|
|
|
|
for (size_t i = 0; i < spatial_layers.size(); ++i) {
|
|
|
|
|
video_codec.spatialLayers[i] = spatial_layers[i];
|
2018-03-28 19:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
2020-06-05 12:36:32 +02:00
|
|
|
// The top spatial layer dimensions may not be equal to the input
|
|
|
|
|
// resolution because of the rounding or explicit configuration.
|
|
|
|
|
// This difference must be propagated to the stream configuration.
|
|
|
|
|
video_codec.width = spatial_layers.back().width;
|
|
|
|
|
video_codec.height = spatial_layers.back().height;
|
|
|
|
|
video_codec.simulcastStream[0].width = spatial_layers.back().width;
|
|
|
|
|
video_codec.simulcastStream[0].height = spatial_layers.back().height;
|
|
|
|
|
|
2018-05-17 16:46:43 +02:00
|
|
|
// Update layering settings.
|
|
|
|
|
video_codec.VP9()->numberOfSpatialLayers =
|
|
|
|
|
static_cast<unsigned char>(spatial_layers.size());
|
|
|
|
|
RTC_DCHECK_GE(video_codec.VP9()->numberOfSpatialLayers, 1);
|
|
|
|
|
RTC_DCHECK_LE(video_codec.VP9()->numberOfSpatialLayers,
|
|
|
|
|
kMaxSpatialLayers);
|
|
|
|
|
|
|
|
|
|
video_codec.VP9()->numberOfTemporalLayers = static_cast<unsigned char>(
|
|
|
|
|
spatial_layers.back().numberOfTemporalLayers);
|
|
|
|
|
RTC_DCHECK_GE(video_codec.VP9()->numberOfTemporalLayers, 1);
|
|
|
|
|
RTC_DCHECK_LE(video_codec.VP9()->numberOfTemporalLayers,
|
|
|
|
|
kMaxTemporalStreams);
|
|
|
|
|
|
2018-03-28 19:32:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case kVideoCodecH264: {
|
|
|
|
|
if (!config.encoder_specific_settings)
|
|
|
|
|
*video_codec.H264() = VideoEncoder::GetDefaultH264Settings();
|
2019-02-08 14:25:40 -05:00
|
|
|
video_codec.H264()->numberOfTemporalLayers = static_cast<unsigned char>(
|
|
|
|
|
streams.back().num_temporal_layers.value_or(
|
|
|
|
|
video_codec.H264()->numberOfTemporalLayers));
|
|
|
|
|
RTC_DCHECK_GE(video_codec.H264()->numberOfTemporalLayers, 1);
|
|
|
|
|
RTC_DCHECK_LE(video_codec.H264()->numberOfTemporalLayers,
|
|
|
|
|
kMaxTemporalStreams);
|
2018-03-28 19:32:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
// TODO(pbos): Support encoder_settings codec-agnostically.
|
|
|
|
|
RTC_DCHECK(!config.encoder_specific_settings)
|
|
|
|
|
<< "Encoder-specific settings for codec type not wired up.";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-11 16:54:18 +02:00
|
|
|
const absl::optional<DataRate> experimental_min_bitrate =
|
|
|
|
|
GetExperimentalMinVideoBitrate(video_codec.codecType);
|
|
|
|
|
if (experimental_min_bitrate) {
|
|
|
|
|
const int experimental_min_bitrate_kbps =
|
|
|
|
|
rtc::saturated_cast<int>(experimental_min_bitrate->kbps());
|
|
|
|
|
video_codec.minBitrate = experimental_min_bitrate_kbps;
|
|
|
|
|
video_codec.simulcastStream[0].minBitrate = experimental_min_bitrate_kbps;
|
|
|
|
|
if (video_codec.codecType == kVideoCodecVP9) {
|
|
|
|
|
video_codec.spatialLayers[0].minBitrate = experimental_min_bitrate_kbps;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-16 16:41:30 +01:00
|
|
|
return video_codec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|