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 ADD_FAILURE() << "Expected decoded.size() to be >= output_size (" |
| 59 << decoded.size() << " vs. " << output_size << ")"; |
| 60 return rtc::Optional<DecodeResult>(); |
| 61 } |
| 62 } |
| 63 |
| 64 private: |
| 65 const size_t num_channels_; |
| 66 }; |
| 67 |
| 68 std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload, |
| 69 uint32_t timestamp) /* override */ { |
| 70 std::vector<ParseResult> results; |
| 71 if (fec_enabled_) { |
| 72 std::unique_ptr<MockFrame> fec_frame(new MockFrame(num_channels_)); |
| 73 results.emplace_back(timestamp - kPacketDuration, 1, |
| 74 std::move(fec_frame)); |
| 75 } |
| 76 |
| 77 std::unique_ptr<MockFrame> frame(new MockFrame(num_channels_)); |
| 78 results.emplace_back(timestamp, 0, std::move(frame)); |
| 79 return results; |
45 } | 80 } |
46 | 81 |
47 int PacketDurationRedundant(const uint8_t* encoded, | 82 int PacketDuration(const uint8_t* encoded, size_t encoded_len) const |
48 size_t encoded_len) const /* override */ { | 83 /* override */ { |
| 84 ADD_FAILURE() << "Since going through ParsePayload, PacketDuration should " |
| 85 "never get called."; |
49 return kPacketDuration; | 86 return kPacketDuration; |
50 } | 87 } |
51 | 88 |
52 bool PacketHasFec( | 89 bool PacketHasFec( |
53 const uint8_t* encoded, size_t encoded_len) const /* override */ { | 90 const uint8_t* encoded, size_t encoded_len) const /* override */ { |
| 91 ADD_FAILURE() << "Since going through ParsePayload, PacketHasFec should " |
| 92 "never get called."; |
54 return fec_enabled_; | 93 return fec_enabled_; |
55 } | 94 } |
56 | 95 |
57 int SampleRateHz() const /* override */ { return sample_rate_hz_; } | 96 int SampleRateHz() const /* override */ { return sample_rate_hz_; } |
58 | 97 |
59 size_t Channels() const /* override */ { return num_channels_; } | 98 size_t Channels() const /* override */ { return num_channels_; } |
60 | 99 |
61 void set_fec_enabled(bool enable_fec) { fec_enabled_ = enable_fec; } | 100 void set_fec_enabled(bool enable_fec) { fec_enabled_ = enable_fec; } |
62 | 101 |
63 bool fec_enabled() const { return fec_enabled_; } | 102 bool fec_enabled() const { return fec_enabled_; } |
64 | 103 |
65 protected: | 104 protected: |
66 // Override the following methods such that no actual payload is needed. | |
67 int DecodeInternal(const uint8_t* encoded, | 105 int DecodeInternal(const uint8_t* encoded, |
68 size_t encoded_len, | 106 size_t encoded_len, |
69 int /*sample_rate_hz*/, | 107 int sample_rate_hz, |
70 int16_t* decoded, | 108 int16_t* decoded, |
71 SpeechType* speech_type) /* override */ { | 109 SpeechType* speech_type) /* override */ { |
72 *speech_type = kSpeech; | 110 ADD_FAILURE() << "Since going through ParsePayload, DecodeInternal should " |
73 memset(decoded, 0, sizeof(int16_t) * kPacketDuration * Channels()); | 111 "never get called."; |
74 return kPacketDuration * Channels(); | 112 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 } | 113 } |
85 | 114 |
86 private: | 115 private: |
87 const int sample_rate_hz_; | 116 const int sample_rate_hz_; |
88 const size_t num_channels_; | 117 const size_t num_channels_; |
89 bool fec_enabled_; | 118 bool fec_enabled_; |
90 }; | 119 }; |
91 | 120 |
92 class NetEqNetworkStatsTest : public NetEqExternalDecoderTest { | 121 class NetEqNetworkStatsTest : public NetEqExternalDecoderTest { |
93 public: | 122 public: |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 326 |
298 TEST(NetEqNetworkStatsTest, NoiseExpansionTest) { | 327 TEST(NetEqNetworkStatsTest, NoiseExpansionTest) { |
299 MockAudioDecoder decoder(48000, 1); | 328 MockAudioDecoder decoder(48000, 1); |
300 NetEqNetworkStatsTest test(NetEqDecoder::kDecoderOpus, 48000, &decoder); | 329 NetEqNetworkStatsTest test(NetEqDecoder::kDecoderOpus, 48000, &decoder); |
301 test.NoiseExpansionTest(); | 330 test.NoiseExpansionTest(); |
302 EXPECT_CALL(decoder, Die()).Times(1); | 331 EXPECT_CALL(decoder, Die()).Times(1); |
303 } | 332 } |
304 | 333 |
305 } // namespace test | 334 } // namespace test |
306 } // namespace webrtc | 335 } // namespace webrtc |
OLD | NEW |