OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 MockAudioDecoder(int sample_rate_hz, size_t num_channels) | 33 MockAudioDecoder(int sample_rate_hz, size_t num_channels) |
34 : sample_rate_hz_(sample_rate_hz), | 34 : sample_rate_hz_(sample_rate_hz), |
35 num_channels_(num_channels), | 35 num_channels_(num_channels), |
36 fec_enabled_(false) {} | 36 fec_enabled_(false) {} |
37 ~MockAudioDecoder() /* override */ { Die(); } | 37 ~MockAudioDecoder() /* override */ { Die(); } |
38 MOCK_METHOD0(Die, void()); | 38 MOCK_METHOD0(Die, void()); |
39 | 39 |
40 MOCK_METHOD0(Reset, void()); | 40 MOCK_METHOD0(Reset, void()); |
41 | 41 |
42 int PacketDuration(const uint8_t* encoded, | 42 class MockFrame : public AudioDecoder::EncodedAudioFrame { |
43 size_t encoded_len) const /* override */ { | 43 public: |
44 return kPacketDuration; | 44 MockFrame(size_t num_channels) : num_channels_(num_channels) {} |
| 45 |
| 46 size_t Duration() const override { return kPacketDuration; } |
| 47 |
| 48 rtc::Optional<DecodeResult> Decode( |
| 49 rtc::ArrayView<int16_t> decoded) const override { |
| 50 const size_t output_size = |
| 51 sizeof(int16_t) * kPacketDuration * num_channels_; |
| 52 if (decoded.size() >= output_size) { |
| 53 memset(decoded.data(), 0, |
| 54 sizeof(int16_t) * kPacketDuration * num_channels_); |
| 55 return rtc::Optional<DecodeResult>( |
| 56 {kPacketDuration * num_channels_, kSpeech}); |
| 57 } else { |
| 58 // We can't use ASSERT_GE here, since Decode doesn't return void. |
| 59 // Instead call EXPECT_GE (to raise the error and get the printout) and |
| 60 // return an empty Optional manually. |
| 61 EXPECT_GE(decoded.size(), output_size); |
| 62 return rtc::Optional<DecodeResult>(); |
| 63 } |
| 64 } |
| 65 |
| 66 private: |
| 67 const size_t num_channels_; |
| 68 }; |
| 69 |
| 70 std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload, |
| 71 uint32_t timestamp) /* override */ { |
| 72 std::vector<ParseResult> results; |
| 73 if (fec_enabled_) { |
| 74 std::unique_ptr<MockFrame> fec_frame(new MockFrame(num_channels_)); |
| 75 results.emplace_back(timestamp - kPacketDuration, 1, |
| 76 std::move(fec_frame)); |
| 77 } |
| 78 |
| 79 std::unique_ptr<MockFrame> frame(new MockFrame(num_channels_)); |
| 80 results.emplace_back(timestamp, 0, std::move(frame)); |
| 81 return results; |
45 } | 82 } |
46 | 83 |
47 int PacketDurationRedundant(const uint8_t* encoded, | 84 int PacketDuration(const uint8_t* encoded, size_t encoded_len) const |
48 size_t encoded_len) const /* override */ { | 85 /* override */ { |
| 86 ADD_FAILURE() << "Since going through ParsePayload, PacketDuration should " |
| 87 "never get called."; |
49 return kPacketDuration; | 88 return kPacketDuration; |
50 } | 89 } |
51 | 90 |
52 bool PacketHasFec( | 91 bool PacketHasFec( |
53 const uint8_t* encoded, size_t encoded_len) const /* override */ { | 92 const uint8_t* encoded, size_t encoded_len) const /* override */ { |
| 93 ADD_FAILURE() << "Since going through ParsePayload, PacketHasFec should " |
| 94 "never get called."; |
54 return fec_enabled_; | 95 return fec_enabled_; |
55 } | 96 } |
56 | 97 |
57 int SampleRateHz() const /* override */ { return sample_rate_hz_; } | 98 int SampleRateHz() const /* override */ { return sample_rate_hz_; } |
58 | 99 |
59 size_t Channels() const /* override */ { return num_channels_; } | 100 size_t Channels() const /* override */ { return num_channels_; } |
60 | 101 |
61 void set_fec_enabled(bool enable_fec) { fec_enabled_ = enable_fec; } | 102 void set_fec_enabled(bool enable_fec) { fec_enabled_ = enable_fec; } |
62 | 103 |
63 bool fec_enabled() const { return fec_enabled_; } | 104 bool fec_enabled() const { return fec_enabled_; } |
64 | 105 |
65 protected: | 106 protected: |
66 // Override the following methods such that no actual payload is needed. | |
67 int DecodeInternal(const uint8_t* encoded, | 107 int DecodeInternal(const uint8_t* encoded, |
68 size_t encoded_len, | 108 size_t encoded_len, |
69 int /*sample_rate_hz*/, | 109 int sample_rate_hz, |
70 int16_t* decoded, | 110 int16_t* decoded, |
71 SpeechType* speech_type) /* override */ { | 111 SpeechType* speech_type) /* override */ { |
72 *speech_type = kSpeech; | 112 ADD_FAILURE() << "Since going through ParsePayload, DecodeInternal should " |
73 memset(decoded, 0, sizeof(int16_t) * kPacketDuration * Channels()); | 113 "never get called."; |
74 return kPacketDuration * Channels(); | 114 return -1; |
75 } | |
76 | |
77 int DecodeRedundantInternal(const uint8_t* encoded, | |
78 size_t encoded_len, | |
79 int sample_rate_hz, | |
80 int16_t* decoded, | |
81 SpeechType* speech_type) /* override */ { | |
82 return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded, | |
83 speech_type); | |
84 } | 115 } |
85 | 116 |
86 private: | 117 private: |
87 const int sample_rate_hz_; | 118 const int sample_rate_hz_; |
88 const size_t num_channels_; | 119 const size_t num_channels_; |
89 bool fec_enabled_; | 120 bool fec_enabled_; |
90 }; | 121 }; |
91 | 122 |
92 class NetEqNetworkStatsTest : public NetEqExternalDecoderTest { | 123 class NetEqNetworkStatsTest : public NetEqExternalDecoderTest { |
93 public: | 124 public: |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 328 |
298 TEST(NetEqNetworkStatsTest, NoiseExpansionTest) { | 329 TEST(NetEqNetworkStatsTest, NoiseExpansionTest) { |
299 MockAudioDecoder decoder(48000, 1); | 330 MockAudioDecoder decoder(48000, 1); |
300 NetEqNetworkStatsTest test(NetEqDecoder::kDecoderOpus, 48000, &decoder); | 331 NetEqNetworkStatsTest test(NetEqDecoder::kDecoderOpus, 48000, &decoder); |
301 test.NoiseExpansionTest(); | 332 test.NoiseExpansionTest(); |
302 EXPECT_CALL(decoder, Die()).Times(1); | 333 EXPECT_CALL(decoder, Die()).Times(1); |
303 } | 334 } |
304 | 335 |
305 } // namespace test | 336 } // namespace test |
306 } // namespace webrtc | 337 } // namespace webrtc |
OLD | NEW |