Index: webrtc/test/encoder_settings.cc |
diff --git a/webrtc/test/encoder_settings.cc b/webrtc/test/encoder_settings.cc |
index 64339df4aad89af0b917dbd9bea8f9d12ce6a5db..80c42ef04a5f4028cb72b09790cb8494384a39b7 100644 |
--- a/webrtc/test/encoder_settings.cc |
+++ b/webrtc/test/encoder_settings.cc |
@@ -9,50 +9,76 @@ |
*/ |
#include "webrtc/test/encoder_settings.h" |
-#include <assert.h> |
-#include <string.h> |
+#include <algorithm> |
+#include <string> |
#include "webrtc/test/fake_decoder.h" |
#include "webrtc/video_decoder.h" |
namespace webrtc { |
namespace test { |
-std::vector<VideoStream> CreateVideoStreams(size_t num_streams) { |
- assert(num_streams > 0); |
- // Add more streams to the settings above with reasonable values if required. |
- static const size_t kNumSettings = 3; |
- assert(num_streams <= kNumSettings); |
+const size_t DefaultVideoStreamFactory::kMaxNumberOfStreams; |
+const int DefaultVideoStreamFactory::kMaxBitratePerStream[] = {150000, 450000, |
+ 1500000}; |
+const int DefaultVideoStreamFactory::kDefaultMinBitratePerStream[] = { |
+ 50000, 200000, 700000}; |
- std::vector<VideoStream> stream_settings(kNumSettings); |
+// static |
+std::vector<VideoStream> CreateVideoStreams( |
+ int width, |
+ int height, |
+ const webrtc::VideoEncoderConfig& encoder_config) { |
+ RTC_DCHECK(encoder_config.number_of_streams <= |
+ DefaultVideoStreamFactory::kMaxNumberOfStreams); |
- stream_settings[0].width = 320; |
- stream_settings[0].height = 180; |
- stream_settings[0].max_framerate = 30; |
- stream_settings[0].min_bitrate_bps = 50000; |
- stream_settings[0].target_bitrate_bps = stream_settings[0].max_bitrate_bps = |
- 150000; |
- stream_settings[0].max_qp = 56; |
+ std::vector<VideoStream> stream_settings(encoder_config.number_of_streams); |
+ int bitrate_left_bps = encoder_config.max_bitrate_bps; |
- stream_settings[1].width = 640; |
- stream_settings[1].height = 360; |
- stream_settings[1].max_framerate = 30; |
- stream_settings[1].min_bitrate_bps = 200000; |
- stream_settings[1].target_bitrate_bps = stream_settings[1].max_bitrate_bps = |
- 450000; |
- stream_settings[1].max_qp = 56; |
+ for (size_t i = 0; i < encoder_config.number_of_streams; ++i) { |
+ stream_settings[i].width = |
+ (i + 1) * width / encoder_config.number_of_streams; |
+ stream_settings[i].height = |
+ (i + 1) * height / encoder_config.number_of_streams; |
+ stream_settings[i].max_framerate = 30; |
+ stream_settings[i].min_bitrate_bps = |
+ DefaultVideoStreamFactory::kDefaultMinBitratePerStream[i]; |
+ stream_settings[i].target_bitrate_bps = stream_settings[i].max_bitrate_bps = |
+ std::min(bitrate_left_bps, |
+ DefaultVideoStreamFactory::kMaxBitratePerStream[i]); |
+ stream_settings[i].max_qp = 56; |
+ bitrate_left_bps -= stream_settings[i].target_bitrate_bps; |
+ } |
+ |
+ stream_settings[encoder_config.number_of_streams - 1].max_bitrate_bps += |
+ bitrate_left_bps; |
- stream_settings[2].width = 1280; |
- stream_settings[2].height = 720; |
- stream_settings[2].max_framerate = 30; |
- stream_settings[2].min_bitrate_bps = 700000; |
- stream_settings[2].target_bitrate_bps = stream_settings[2].max_bitrate_bps = |
- 1500000; |
- stream_settings[2].max_qp = 56; |
- stream_settings.resize(num_streams); |
return stream_settings; |
} |
+DefaultVideoStreamFactory::DefaultVideoStreamFactory() {} |
+ |
+std::vector<VideoStream> DefaultVideoStreamFactory::CreateEncoderStreams( |
+ int width, |
+ int height, |
+ const webrtc::VideoEncoderConfig& encoder_config) { |
+ return CreateVideoStreams(width, height, encoder_config); |
+} |
+ |
+void FillEncoderConfiguration(size_t num_streams, |
+ VideoEncoderConfig* configuration) { |
+ RTC_DCHECK_LE(num_streams, DefaultVideoStreamFactory::kMaxNumberOfStreams); |
+ |
+ configuration->number_of_streams = num_streams; |
+ configuration->video_stream_factory = |
+ new rtc::RefCountedObject<DefaultVideoStreamFactory>(); |
+ configuration->max_bitrate_bps = 0; |
+ for (size_t i = 0; i < num_streams; ++i) { |
+ configuration->max_bitrate_bps += |
+ DefaultVideoStreamFactory::kMaxBitratePerStream[i]; |
+ } |
+} |
+ |
VideoReceiveStream::Decoder CreateMatchingDecoder( |
const VideoSendStream::Config::EncoderSettings& encoder_settings) { |
VideoReceiveStream::Decoder decoder; |