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

Unified Diff: webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc

Issue 2528933002: Adding OnReceivedOverhead to AudioEncoder. (Closed)
Patch Set: on Michael's comments Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc
diff --git a/webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc b/webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..213b876adab2ae84afc19af649ebc6f2bcc7d79e
--- /dev/null
+++ b/webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
+#include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h"
+#include "webrtc/test/field_trial.h"
+#include "webrtc/test/gmock.h"
+#include "webrtc/test/gtest.h"
+
+namespace webrtc {
+
+using testing::_;
+using testing::Invoke;
+using testing::Return;
+using testing::StrictMock;
+
+TEST(AudioEncoderTest, DoNotInvokeSetTargetBitrateIfOverheadUnknown) {
+ test::ScopedFieldTrials override_field_trials(
+ "WebRTC-SendSideBwe-WithOverhead/Enabled/");
+
+ StrictMock<MockAudioEncoder> mock_audio_encoder;
+ EXPECT_CALL(mock_audio_encoder, Die());
+ // In this test, we want to test logics within
+ // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder|
+ // but we invoke the original method.
+ EXPECT_CALL(mock_audio_encoder, OnReceivedTargetAudioBitrate(_))
+ .WillOnce(
+ Invoke(&mock_audio_encoder,
+ &MockAudioEncoder::AudioEncoderOnReceivedTargetAudioBitrate));
+ mock_audio_encoder.OnReceivedTargetAudioBitrate(12345);
+ // Since |OnReceivedOverhead| has not been called,
+ // |mock_audio_encoder.SetTargetBitrate| should not be invoked.
+}
+
+TEST(AudioEncoderTest, OverheadRemovedFromTargetAudioBitrate) {
+ test::ScopedFieldTrials override_field_trials(
+ "WebRTC-SendSideBwe-WithOverhead/Enabled/");
+
+ StrictMock<MockAudioEncoder> mock_audio_encoder;
+ EXPECT_CALL(mock_audio_encoder, Die());
+
+ // In this test, we want to test logics within
+ // |AudioEncoder::OnReceivedOverhead| and
+ // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder|
+ // but we invoke the original methods.
+ EXPECT_CALL(mock_audio_encoder, OnReceivedOverhead(_))
+ .WillOnce(Invoke(&mock_audio_encoder,
+ &MockAudioEncoder::AudioEncoderOnReceivedOverhead));
+ EXPECT_CALL(mock_audio_encoder, OnReceivedTargetAudioBitrate(_))
+ .WillOnce(
+ Invoke(&mock_audio_encoder,
+ &MockAudioEncoder::AudioEncoderOnReceivedTargetAudioBitrate));
+
+ constexpr int kFrameLengthMs = 60;
+ constexpr size_t kNum10MsFramesPerPacket = kFrameLengthMs / 10;
+ EXPECT_CALL(mock_audio_encoder, Num10MsFramesInNextPacket())
+ .WillOnce(Return(kNum10MsFramesPerPacket));
+
+ constexpr size_t kOverheadBytesPerPacket = 64;
+ mock_audio_encoder.OnReceivedOverhead(kOverheadBytesPerPacket);
+
+ constexpr size_t kTargetBitrateBps = 12345;
+ EXPECT_CALL(mock_audio_encoder, SetTargetBitrate(kTargetBitrateBps -
+ kOverheadBytesPerPacket * 8 *
+ 1000 / kFrameLengthMs));
+ mock_audio_encoder.OnReceivedTargetAudioBitrate(kTargetBitrateBps);
+}
+
+TEST(AudioEncoderTest, BitrateNeverBecomesNegative) {
+ test::ScopedFieldTrials override_field_trials(
+ "WebRTC-SendSideBwe-WithOverhead/Enabled/");
+
+ StrictMock<MockAudioEncoder> mock_audio_encoder;
+ EXPECT_CALL(mock_audio_encoder, Die());
+
+ // In this test, we want to test logics within
+ // |AudioEncoder::OnReceivedOverhead| and
+ // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder|
+ // but we invoke the original methods.
+ EXPECT_CALL(mock_audio_encoder, OnReceivedOverhead(_))
+ .WillOnce(Invoke(&mock_audio_encoder,
+ &MockAudioEncoder::AudioEncoderOnReceivedOverhead));
+ EXPECT_CALL(mock_audio_encoder, OnReceivedTargetAudioBitrate(_))
+ .WillOnce(
+ Invoke(&mock_audio_encoder,
+ &MockAudioEncoder::AudioEncoderOnReceivedTargetAudioBitrate));
+
+ constexpr int kFrameLengthMs = 60;
+ constexpr size_t kNum10MsFramesPerPacket = kFrameLengthMs / 10;
+ EXPECT_CALL(mock_audio_encoder, Num10MsFramesInNextPacket())
+ .WillOnce(Return(kNum10MsFramesPerPacket));
+
+ constexpr size_t kOverheadBytesPerPacket = 64;
+ mock_audio_encoder.OnReceivedOverhead(kOverheadBytesPerPacket);
+
+ // Set a target rate smaller than overhead rate, the bitrate is bounded by 0.
+ constexpr size_t kTargetBitrateBps =
+ kOverheadBytesPerPacket * 8 * 1000 / kFrameLengthMs - 1;
+ EXPECT_CALL(mock_audio_encoder, SetTargetBitrate(0));
+ mock_audio_encoder.OnReceivedTargetAudioBitrate(kTargetBitrateBps);
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698