video_stream_input_state_provider_unittest.cc (2937B)
1 /* 2 * Copyright (c) 2020 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 */ 10 11 #include "call/adaptation/video_stream_input_state_provider.h" 12 13 #include <optional> 14 #include <utility> 15 16 #include "api/video/video_codec_type.h" 17 #include "api/video_codecs/video_codec.h" 18 #include "api/video_codecs/video_encoder.h" 19 #include "call/adaptation/encoder_settings.h" 20 #include "call/adaptation/test/fake_frame_rate_provider.h" 21 #include "call/adaptation/video_stream_input_state.h" 22 #include "test/gtest.h" 23 #include "video/config/video_encoder_config.h" 24 25 namespace webrtc { 26 27 TEST(VideoStreamInputStateProviderTest, DefaultValues) { 28 FakeFrameRateProvider frame_rate_provider; 29 VideoStreamInputStateProvider input_state_provider(&frame_rate_provider); 30 VideoStreamInputState input_state = input_state_provider.InputState(); 31 EXPECT_EQ(false, input_state.has_input()); 32 EXPECT_EQ(std::nullopt, input_state.frame_size_pixels()); 33 EXPECT_EQ(0, input_state.frames_per_second()); 34 EXPECT_EQ(VideoCodecType::kVideoCodecGeneric, input_state.video_codec_type()); 35 EXPECT_EQ(kDefaultMinPixelsPerFrame, input_state.min_pixels_per_frame()); 36 EXPECT_EQ(std::nullopt, input_state.single_active_stream_pixels()); 37 } 38 39 TEST(VideoStreamInputStateProviderTest, ValuesSet) { 40 FakeFrameRateProvider frame_rate_provider; 41 VideoStreamInputStateProvider input_state_provider(&frame_rate_provider); 42 input_state_provider.OnHasInputChanged(true); 43 input_state_provider.OnFrameSizeObserved(42); 44 frame_rate_provider.set_fps(123); 45 VideoEncoder::EncoderInfo encoder_info; 46 encoder_info.scaling_settings.min_pixels_per_frame = 1337; 47 VideoEncoderConfig encoder_config; 48 encoder_config.codec_type = VideoCodecType::kVideoCodecVP9; 49 VideoCodec video_codec; 50 video_codec.codecType = VideoCodecType::kVideoCodecVP8; 51 video_codec.numberOfSimulcastStreams = 2; 52 video_codec.simulcastStream[0].active = false; 53 video_codec.simulcastStream[1].active = true; 54 video_codec.simulcastStream[1].width = 111; 55 video_codec.simulcastStream[1].height = 222; 56 input_state_provider.OnEncoderSettingsChanged(EncoderSettings( 57 std::move(encoder_info), std::move(encoder_config), video_codec)); 58 VideoStreamInputState input_state = input_state_provider.InputState(); 59 EXPECT_EQ(true, input_state.has_input()); 60 EXPECT_EQ(42, input_state.frame_size_pixels()); 61 EXPECT_EQ(123, input_state.frames_per_second()); 62 EXPECT_EQ(VideoCodecType::kVideoCodecVP9, input_state.video_codec_type()); 63 EXPECT_EQ(1337, input_state.min_pixels_per_frame()); 64 EXPECT_EQ(111 * 222, input_state.single_active_stream_pixels()); 65 } 66 67 } // namespace webrtc