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

Side by Side Diff: webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc

Issue 2528933002: Adding OnReceivedOverhead to AudioEncoder. (Closed)
Patch Set: fixing and adding unittest 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::_;
michaelt 2016/11/28 09:26:57 testing::_ not used at the moment.
20 using testing::Invoke;
michaelt 2016/11/28 09:26:57 testing::Invoke not used at the moment.
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 // In this test, we want to test logics within
29 // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder|
30 // since this method is not mocked. If it needs to be mocked in the future, we
31 // can maintain the test by letting the mocked method invoke the original
32 // method.
michaelt 2016/11/28 09:26:57 I think i would prefer to add the mock function an
33 StrictMock<MockAudioEncoder> mock_audio_encoder;
34 EXPECT_CALL(mock_audio_encoder, Die());
35 mock_audio_encoder.OnReceivedTargetAudioBitrate(12345);
36 // Since |OnReceivedOverhead| has not been called,
37 // |mock_audio_encoder.SetTargetBitrate| should not be invoked.
38 }
39
40 TEST(AudioEncoderTest, OverheadRemovedFromTargetAudioBitrate) {
41 test::ScopedFieldTrials override_field_trials(
42 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
43
44 // In this test, we want to test logics within
45 // |AudioEncoder::OnReceivedOverhead| and
46 // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder|
47 // since these methods are not mocked. If they needs to be mocked in the
48 // future, we can maintain the test by letting the mocked methods invoke the
49 // original methods.
50 StrictMock<MockAudioEncoder> mock_audio_encoder;
51 EXPECT_CALL(mock_audio_encoder, Die());
52
53 constexpr int kFrameLengthMs = 60;
54 constexpr size_t kNum10MsFramesPerPacket = kFrameLengthMs / 10;
55 EXPECT_CALL(mock_audio_encoder, Num10MsFramesInNextPacket())
56 .WillOnce(Return(kNum10MsFramesPerPacket));
57
58 constexpr size_t kOverheadBytesPerPacket = 64;
59 mock_audio_encoder.OnReceivedOverhead(kOverheadBytesPerPacket);
60
61 constexpr size_t kTargetBitrateBps = 12345;
62 EXPECT_CALL(mock_audio_encoder, SetTargetBitrate(kTargetBitrateBps -
63 kOverheadBytesPerPacket * 8 *
64 1000 / kFrameLengthMs));
65 mock_audio_encoder.OnReceivedTargetAudioBitrate(kTargetBitrateBps);
66 }
67
68 TEST(AudioEncoderTest, BitrateNeverBecomesNegative) {
69 test::ScopedFieldTrials override_field_trials(
70 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
71
72 // In this test, we want to test logics within
73 // |AudioEncoder::OnReceivedOverhead| and
74 // |AudioEncoder::OnReceivedTargetAudioBitrate|, we use |MockAudioEncoder|
75 // since these methods are not mocked. If they needs to be mocked in the
76 // future, we can maintain the test by letting the mocked methods invoke the
77 // original methods.
78 StrictMock<MockAudioEncoder> mock_audio_encoder;
79 EXPECT_CALL(mock_audio_encoder, Die());
80
81 constexpr int kFrameLengthMs = 60;
82 constexpr size_t kNum10MsFramesPerPacket = kFrameLengthMs / 10;
83 EXPECT_CALL(mock_audio_encoder, Num10MsFramesInNextPacket())
84 .WillOnce(Return(kNum10MsFramesPerPacket));
85
86 constexpr size_t kOverheadBytesPerPacket = 64;
87 mock_audio_encoder.OnReceivedOverhead(kOverheadBytesPerPacket);
88
89 // Set a target rate smaller than overhead rate, the bitrate is bounded by 0.
90 constexpr size_t kTargetBitrateBps =
91 kOverheadBytesPerPacket * 8 * 1000 / kFrameLengthMs - 1;
92 EXPECT_CALL(mock_audio_encoder, SetTargetBitrate(0));
93 mock_audio_encoder.OnReceivedTargetAudioBitrate(kTargetBitrateBps);
94 }
95
96 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/codecs/audio_encoder.cc ('k') | webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698