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

Side by Side 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 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 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 "webrtc/modules/audio_coding/codecs/audio_encoder.h"
12 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h"
13 #include "webrtc/test/field_trial.h"
14 #include "webrtc/test/gmock.h"
15 #include "webrtc/test/gtest.h"
16
17 namespace webrtc {
18
19 using testing::_;
20 using testing::Invoke;
21 using testing::Return;
22 using testing::StrictMock;
23
24 TEST(AudioEncoderTest, DoNotInvokeSetTargetBitrateIfOverheadUnknown) {
25 test::ScopedFieldTrials override_field_trials(
26 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
27
28 StrictMock<MockAudioEncoder> mock_audio_encoder;
29 EXPECT_CALL(mock_audio_encoder, Die());
30 // In this test, we want to test logics within
31 // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder|
32 // but we invoke the original method.
33 EXPECT_CALL(mock_audio_encoder, OnReceivedTargetAudioBitrate(_))
34 .WillOnce(
35 Invoke(&mock_audio_encoder,
36 &MockAudioEncoder::AudioEncoderOnReceivedTargetAudioBitrate));
37 mock_audio_encoder.OnReceivedTargetAudioBitrate(12345);
38 // Since |OnReceivedOverhead| has not been called,
39 // |mock_audio_encoder.SetTargetBitrate| should not be invoked.
40 }
41
42 TEST(AudioEncoderTest, OverheadRemovedFromTargetAudioBitrate) {
43 test::ScopedFieldTrials override_field_trials(
44 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
45
46 StrictMock<MockAudioEncoder> mock_audio_encoder;
47 EXPECT_CALL(mock_audio_encoder, Die());
48
49 // In this test, we want to test logics within
50 // |AudioEncoder::OnReceivedOverhead| and
51 // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder|
52 // but we invoke the original methods.
53 EXPECT_CALL(mock_audio_encoder, OnReceivedOverhead(_))
54 .WillOnce(Invoke(&mock_audio_encoder,
55 &MockAudioEncoder::AudioEncoderOnReceivedOverhead));
56 EXPECT_CALL(mock_audio_encoder, OnReceivedTargetAudioBitrate(_))
57 .WillOnce(
58 Invoke(&mock_audio_encoder,
59 &MockAudioEncoder::AudioEncoderOnReceivedTargetAudioBitrate));
60
61 constexpr int kFrameLengthMs = 60;
62 constexpr size_t kNum10MsFramesPerPacket = kFrameLengthMs / 10;
63 EXPECT_CALL(mock_audio_encoder, Num10MsFramesInNextPacket())
64 .WillOnce(Return(kNum10MsFramesPerPacket));
65
66 constexpr size_t kOverheadBytesPerPacket = 64;
67 mock_audio_encoder.OnReceivedOverhead(kOverheadBytesPerPacket);
68
69 constexpr size_t kTargetBitrateBps = 12345;
70 EXPECT_CALL(mock_audio_encoder, SetTargetBitrate(kTargetBitrateBps -
71 kOverheadBytesPerPacket * 8 *
72 1000 / kFrameLengthMs));
73 mock_audio_encoder.OnReceivedTargetAudioBitrate(kTargetBitrateBps);
74 }
75
76 TEST(AudioEncoderTest, BitrateNeverBecomesNegative) {
77 test::ScopedFieldTrials override_field_trials(
78 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
79
80 StrictMock<MockAudioEncoder> mock_audio_encoder;
81 EXPECT_CALL(mock_audio_encoder, Die());
82
83 // In this test, we want to test logics within
84 // |AudioEncoder::OnReceivedOverhead| and
85 // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder|
86 // but we invoke the original methods.
87 EXPECT_CALL(mock_audio_encoder, OnReceivedOverhead(_))
88 .WillOnce(Invoke(&mock_audio_encoder,
89 &MockAudioEncoder::AudioEncoderOnReceivedOverhead));
90 EXPECT_CALL(mock_audio_encoder, OnReceivedTargetAudioBitrate(_))
91 .WillOnce(
92 Invoke(&mock_audio_encoder,
93 &MockAudioEncoder::AudioEncoderOnReceivedTargetAudioBitrate));
94
95 constexpr int kFrameLengthMs = 60;
96 constexpr size_t kNum10MsFramesPerPacket = kFrameLengthMs / 10;
97 EXPECT_CALL(mock_audio_encoder, Num10MsFramesInNextPacket())
98 .WillOnce(Return(kNum10MsFramesPerPacket));
99
100 constexpr size_t kOverheadBytesPerPacket = 64;
101 mock_audio_encoder.OnReceivedOverhead(kOverheadBytesPerPacket);
102
103 // Set a target rate smaller than overhead rate, the bitrate is bounded by 0.
104 constexpr size_t kTargetBitrateBps =
105 kOverheadBytesPerPacket * 8 * 1000 / kFrameLengthMs - 1;
106 EXPECT_CALL(mock_audio_encoder, SetTargetBitrate(0));
107 mock_audio_encoder.OnReceivedTargetAudioBitrate(kTargetBitrateBps);
108 }
109
110 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698