pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #include "test/encoder_settings.h" |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 11 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 12 | #include <algorithm> |
| 13 | #include <string> |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 14 | |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 15 | #include "api/scoped_refptr.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 16 | #include "api/video_codecs/sdp_video_format.h" |
| 17 | #include "call/rtp_config.h" |
| 18 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "rtc_base/ref_counted_object.h" |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | namespace test { |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 23 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 24 | const size_t DefaultVideoStreamFactory::kMaxNumberOfStreams; |
| 25 | const int DefaultVideoStreamFactory::kMaxBitratePerStream[] = {150000, 450000, |
| 26 | 1500000}; |
| 27 | const int DefaultVideoStreamFactory::kDefaultMinBitratePerStream[] = { |
philipel | 5ef2bc1 | 2017-02-21 07:28:31 -0800 | [diff] [blame] | 28 | 30000, 200000, 700000}; |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 29 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 30 | // static |
| 31 | std::vector<VideoStream> CreateVideoStreams( |
| 32 | int width, |
| 33 | int height, |
| 34 | const webrtc::VideoEncoderConfig& encoder_config) { |
| 35 | RTC_DCHECK(encoder_config.number_of_streams <= |
| 36 | DefaultVideoStreamFactory::kMaxNumberOfStreams); |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 37 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 38 | std::vector<VideoStream> stream_settings(encoder_config.number_of_streams); |
| 39 | int bitrate_left_bps = encoder_config.max_bitrate_bps; |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 40 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 41 | for (size_t i = 0; i < encoder_config.number_of_streams; ++i) { |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 42 | stream_settings[i].width = |
| 43 | (i + 1) * width / encoder_config.number_of_streams; |
| 44 | stream_settings[i].height = |
| 45 | (i + 1) * height / encoder_config.number_of_streams; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 46 | stream_settings[i].max_framerate = 30; |
| 47 | stream_settings[i].min_bitrate_bps = |
| 48 | DefaultVideoStreamFactory::kDefaultMinBitratePerStream[i]; |
philipel | 0676f22 | 2018-04-17 16:12:21 +0200 | [diff] [blame] | 49 | |
| 50 | int target_bitrate_bps = -1; |
| 51 | int max_bitrate_bps = -1; |
| 52 | // Use configured values instead of default values if values has been |
| 53 | // configured. |
| 54 | if (i < encoder_config.simulcast_layers.size()) { |
| 55 | const VideoStream& stream = encoder_config.simulcast_layers[i]; |
| 56 | |
| 57 | max_bitrate_bps = |
| 58 | stream.max_bitrate_bps > 0 |
| 59 | ? stream.max_bitrate_bps |
| 60 | : DefaultVideoStreamFactory::kMaxBitratePerStream[i]; |
| 61 | max_bitrate_bps = std::min(bitrate_left_bps, max_bitrate_bps); |
| 62 | |
| 63 | target_bitrate_bps = |
| 64 | stream.target_bitrate_bps > 0 |
| 65 | ? stream.target_bitrate_bps |
| 66 | : DefaultVideoStreamFactory::kMaxBitratePerStream[i]; |
| 67 | target_bitrate_bps = std::min(max_bitrate_bps, target_bitrate_bps); |
Åsa Persson | f06bacc | 2018-10-12 11:07:20 +0200 | [diff] [blame] | 68 | |
Åsa Persson | 2174053 | 2019-04-15 14:00:30 +0200 | [diff] [blame] | 69 | if (stream.min_bitrate_bps > 0) { |
| 70 | RTC_DCHECK_LE(stream.min_bitrate_bps, target_bitrate_bps); |
| 71 | stream_settings[i].min_bitrate_bps = stream.min_bitrate_bps; |
| 72 | } |
Åsa Persson | f06bacc | 2018-10-12 11:07:20 +0200 | [diff] [blame] | 73 | if (stream.max_framerate > 0) { |
| 74 | stream_settings[i].max_framerate = stream.max_framerate; |
| 75 | } |
Åsa Persson | d34597c | 2018-10-22 17:34:02 +0200 | [diff] [blame] | 76 | if (stream.num_temporal_layers) { |
| 77 | RTC_DCHECK_GE(*stream.num_temporal_layers, 1); |
| 78 | stream_settings[i].num_temporal_layers = stream.num_temporal_layers; |
| 79 | } |
philipel | 0676f22 | 2018-04-17 16:12:21 +0200 | [diff] [blame] | 80 | } else { |
| 81 | max_bitrate_bps = std::min( |
| 82 | bitrate_left_bps, DefaultVideoStreamFactory::kMaxBitratePerStream[i]); |
| 83 | target_bitrate_bps = max_bitrate_bps; |
| 84 | } |
| 85 | |
| 86 | RTC_DCHECK_NE(target_bitrate_bps, -1); |
| 87 | RTC_DCHECK_NE(max_bitrate_bps, -1); |
| 88 | stream_settings[i].target_bitrate_bps = target_bitrate_bps; |
| 89 | stream_settings[i].max_bitrate_bps = max_bitrate_bps; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 90 | stream_settings[i].max_qp = 56; |
philipel | 0676f22 | 2018-04-17 16:12:21 +0200 | [diff] [blame] | 91 | |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 92 | if (i < encoder_config.simulcast_layers.size()) { |
| 93 | // Higher level controls are setting the active configuration for the |
| 94 | // VideoStream. |
| 95 | stream_settings[i].active = encoder_config.simulcast_layers[i].active; |
| 96 | } else { |
| 97 | stream_settings[i].active = true; |
| 98 | } |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 99 | bitrate_left_bps -= stream_settings[i].target_bitrate_bps; |
| 100 | } |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 101 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 102 | stream_settings[encoder_config.number_of_streams - 1].max_bitrate_bps += |
| 103 | bitrate_left_bps; |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 104 | stream_settings[0].bitrate_priority = encoder_config.bitrate_priority; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 105 | |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 106 | return stream_settings; |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 107 | } |
| 108 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 109 | DefaultVideoStreamFactory::DefaultVideoStreamFactory() {} |
| 110 | |
| 111 | std::vector<VideoStream> DefaultVideoStreamFactory::CreateEncoderStreams( |
| 112 | int width, |
| 113 | int height, |
| 114 | const webrtc::VideoEncoderConfig& encoder_config) { |
| 115 | return CreateVideoStreams(width, height, encoder_config); |
| 116 | } |
| 117 | |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 118 | void FillEncoderConfiguration(VideoCodecType codec_type, |
| 119 | size_t num_streams, |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 120 | VideoEncoderConfig* configuration) { |
| 121 | RTC_DCHECK_LE(num_streams, DefaultVideoStreamFactory::kMaxNumberOfStreams); |
| 122 | |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 123 | configuration->codec_type = codec_type; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 124 | configuration->number_of_streams = num_streams; |
| 125 | configuration->video_stream_factory = |
| 126 | new rtc::RefCountedObject<DefaultVideoStreamFactory>(); |
| 127 | configuration->max_bitrate_bps = 0; |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 128 | configuration->simulcast_layers = std::vector<VideoStream>(num_streams); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 129 | for (size_t i = 0; i < num_streams; ++i) { |
| 130 | configuration->max_bitrate_bps += |
| 131 | DefaultVideoStreamFactory::kMaxBitratePerStream[i]; |
| 132 | } |
| 133 | } |
| 134 | |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 135 | VideoReceiveStream::Decoder CreateMatchingDecoder( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 136 | int payload_type, |
| 137 | const std::string& payload_name) { |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 138 | VideoReceiveStream::Decoder decoder; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 139 | decoder.payload_type = payload_type; |
Niels Möller | cb7e1d2 | 2018-09-11 15:56:04 +0200 | [diff] [blame] | 140 | decoder.video_format = SdpVideoFormat(payload_name); |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 141 | return decoder; |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 142 | } |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 143 | |
| 144 | VideoReceiveStream::Decoder CreateMatchingDecoder( |
| 145 | const VideoSendStream::Config& config) { |
| 146 | return CreateMatchingDecoder(config.rtp.payload_type, |
| 147 | config.rtp.payload_name); |
| 148 | } |
| 149 | |
pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame] | 150 | } // namespace test |
| 151 | } // namespace webrtc |