Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc

Issue 2304603002: Change SimulcastEncoderAdapter to allow a 0 for SetRates. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 int32_t RegisterEncodeCompleteCallback( 127 int32_t RegisterEncodeCompleteCallback(
128 EncodedImageCallback* callback) /* override */ { 128 EncodedImageCallback* callback) /* override */ {
129 callback_ = callback; 129 callback_ = callback;
130 return 0; 130 return 0;
131 } 131 }
132 132
133 int32_t Release() /* override */ { return 0; } 133 int32_t Release() /* override */ { return 0; }
134 134
135 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) /* override */ { 135 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) /* override */ {
136 last_set_bitrate_ = static_cast<int32_t>(newBitRate);
136 return 0; 137 return 0;
137 } 138 }
138 139
139 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt)); 140 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt));
140 141
141 bool SupportsNativeHandle() const /* override */ { 142 bool SupportsNativeHandle() const /* override */ {
142 return supports_native_handle_; 143 return supports_native_handle_;
143 } 144 }
144 145
145 virtual ~MockVideoEncoder() {} 146 virtual ~MockVideoEncoder() {}
146 147
147 const VideoCodec& codec() const { return codec_; } 148 const VideoCodec& codec() const { return codec_; }
148 149
149 void SendEncodedImage(int width, int height) { 150 void SendEncodedImage(int width, int height) {
150 // Sends a fake image of the given width/height. 151 // Sends a fake image of the given width/height.
151 EncodedImage image; 152 EncodedImage image;
152 image._encodedWidth = width; 153 image._encodedWidth = width;
153 image._encodedHeight = height; 154 image._encodedHeight = height;
154 CodecSpecificInfo codecSpecificInfo; 155 CodecSpecificInfo codecSpecificInfo;
155 memset(&codecSpecificInfo, 0, sizeof(codecSpecificInfo)); 156 memset(&codecSpecificInfo, 0, sizeof(codecSpecificInfo));
156 callback_->Encoded(image, &codecSpecificInfo, NULL); 157 callback_->Encoded(image, &codecSpecificInfo, NULL);
157 } 158 }
158 159
159 void set_supports_native_handle(bool enabled) { 160 void set_supports_native_handle(bool enabled) {
160 supports_native_handle_ = enabled; 161 supports_native_handle_ = enabled;
161 } 162 }
163 int32_t last_set_bitrate() const { return last_set_bitrate_; }
162 164
163 MOCK_CONST_METHOD0(ImplementationName, const char*()); 165 MOCK_CONST_METHOD0(ImplementationName, const char*());
164 166
165 private: 167 private:
166 bool supports_native_handle_ = false; 168 bool supports_native_handle_ = false;
169 int32_t last_set_bitrate_ = -1;
170
167 VideoCodec codec_; 171 VideoCodec codec_;
168 EncodedImageCallback* callback_; 172 EncodedImageCallback* callback_;
169 }; 173 };
170 174
171 class MockVideoEncoderFactory : public VideoEncoderFactory { 175 class MockVideoEncoderFactory : public VideoEncoderFactory {
172 public: 176 public:
173 VideoEncoder* Create() override { 177 VideoEncoder* Create() override {
174 MockVideoEncoder* encoder = new 178 MockVideoEncoder* encoder = new
175 ::testing::NiceMock<MockVideoEncoder>(); 179 ::testing::NiceMock<MockVideoEncoder>();
176 const char* encoder_name = encoder_names_.empty() 180 const char* encoder_name = encoder_names_.empty()
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 codec_.numberOfSimulcastStreams = 1; 421 codec_.numberOfSimulcastStreams = 1;
418 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); 422 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
419 adapter_->RegisterEncodeCompleteCallback(this); 423 adapter_->RegisterEncodeCompleteCallback(this);
420 ASSERT_EQ(1u, helper_->factory()->encoders().size()); 424 ASSERT_EQ(1u, helper_->factory()->encoders().size());
421 helper_->factory()->encoders()[0]->set_supports_native_handle(true); 425 helper_->factory()->encoders()[0]->set_supports_native_handle(true);
422 EXPECT_TRUE(adapter_->SupportsNativeHandle()); 426 EXPECT_TRUE(adapter_->SupportsNativeHandle());
423 helper_->factory()->encoders()[0]->set_supports_native_handle(false); 427 helper_->factory()->encoders()[0]->set_supports_native_handle(false);
424 EXPECT_FALSE(adapter_->SupportsNativeHandle()); 428 EXPECT_FALSE(adapter_->SupportsNativeHandle());
425 } 429 }
426 430
431 TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) {
432 TestVp8Simulcast::DefaultSettings(
433 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
434 codec_.minBitrate = 50;
435 codec_.numberOfSimulcastStreams = 1;
436 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
437
438 // Above min should be respected.
439 adapter_->SetRates(100, 30);
440 EXPECT_EQ(100, helper_->factory()->encoders()[0]->last_set_bitrate());
441
442 // Below min but non-zero should be replaced with the min bitrate.
443 adapter_->SetRates(15, 30);
444 EXPECT_EQ(50, helper_->factory()->encoders()[0]->last_set_bitrate());
445
446 // Zero should be passed on as is, since it means "pause".
447 adapter_->SetRates(0, 30);
448 EXPECT_EQ(0, helper_->factory()->encoders()[0]->last_set_bitrate());
449 }
450
427 TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) { 451 TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) {
428 EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName()); 452 EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName());
429 TestVp8Simulcast::DefaultSettings( 453 TestVp8Simulcast::DefaultSettings(
430 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); 454 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
431 std::vector<const char*> encoder_names; 455 std::vector<const char*> encoder_names;
432 encoder_names.push_back("codec1"); 456 encoder_names.push_back("codec1");
433 encoder_names.push_back("codec2"); 457 encoder_names.push_back("codec2");
434 encoder_names.push_back("codec3"); 458 encoder_names.push_back("codec3");
435 helper_->factory()->SetEncoderNames(encoder_names); 459 helper_->factory()->SetEncoderNames(encoder_names);
436 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); 460 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 memset(input_frame.video_frame_buffer()->MutableDataV(), 0, 546 memset(input_frame.video_frame_buffer()->MutableDataV(), 0,
523 input_frame.allocated_size(kVPlane)); 547 input_frame.allocated_size(kVPlane));
524 548
525 std::vector<FrameType> frame_types(3, kVideoFrameKey); 549 std::vector<FrameType> frame_types(3, kVideoFrameKey);
526 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, 550 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE,
527 adapter_->Encode(input_frame, nullptr, &frame_types)); 551 adapter_->Encode(input_frame, nullptr, &frame_types));
528 } 552 }
529 553
530 } // namespace testing 554 } // namespace testing
531 } // namespace webrtc 555 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698