OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 TEST_F(AudioEncoderCopyRedTest, CheckProjectedPacketLossRatePropagation) { | 109 TEST_F(AudioEncoderCopyRedTest, CheckProjectedPacketLossRatePropagation) { |
110 EXPECT_CALL(mock_encoder_, SetProjectedPacketLossRate(0.5)); | 110 EXPECT_CALL(mock_encoder_, SetProjectedPacketLossRate(0.5)); |
111 red_->SetProjectedPacketLossRate(0.5); | 111 red_->SetProjectedPacketLossRate(0.5); |
112 } | 112 } |
113 | 113 |
114 // Checks that the an Encode() call is immediately propagated to the speech | 114 // Checks that the an Encode() call is immediately propagated to the speech |
115 // encoder. | 115 // encoder. |
116 TEST_F(AudioEncoderCopyRedTest, CheckImmediateEncode) { | 116 TEST_F(AudioEncoderCopyRedTest, CheckImmediateEncode) { |
117 // Interleaving the EXPECT_CALL sequence with expectations on the MockFunction | 117 // Interleaving the EXPECT_CALL sequence with expectations on the MockFunction |
118 // check ensures that exactly one call to EncodeInternal happens in each | 118 // check ensures that exactly one call to EncodeImpl happens in each |
119 // Encode call. | 119 // Encode call. |
120 InSequence s; | 120 InSequence s; |
121 MockFunction<void(int check_point_id)> check; | 121 MockFunction<void(int check_point_id)> check; |
122 for (int i = 1; i <= 6; ++i) { | 122 for (int i = 1; i <= 6; ++i) { |
123 EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _)) | 123 EXPECT_CALL(mock_encoder_, EncodeImpl(_, _, _)) |
124 .WillRepeatedly(Return(AudioEncoder::EncodedInfo())); | 124 .WillRepeatedly(Return(AudioEncoder::EncodedInfo())); |
125 EXPECT_CALL(check, Call(i)); | 125 EXPECT_CALL(check, Call(i)); |
126 Encode(); | 126 Encode(); |
127 check.Call(i); | 127 check.Call(i); |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 // Checks that no output is produced if the underlying codec doesn't emit any | 131 // Checks that no output is produced if the underlying codec doesn't emit any |
132 // new data, even if the RED codec is loaded with a secondary encoding. | 132 // new data, even if the RED codec is loaded with a secondary encoding. |
133 TEST_F(AudioEncoderCopyRedTest, CheckNoOutput) { | 133 TEST_F(AudioEncoderCopyRedTest, CheckNoOutput) { |
134 static const size_t kEncodedSize = 17; | 134 static const size_t kEncodedSize = 17; |
135 { | 135 { |
136 InSequence s; | 136 InSequence s; |
137 EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _)) | 137 EXPECT_CALL(mock_encoder_, EncodeImpl(_, _, _)) |
138 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(kEncodedSize))) | 138 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(kEncodedSize))) |
139 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(0))) | 139 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(0))) |
140 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(kEncodedSize))); | 140 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(kEncodedSize))); |
141 } | 141 } |
142 | 142 |
143 // Start with one Encode() call that will produce output. | 143 // Start with one Encode() call that will produce output. |
144 Encode(); | 144 Encode(); |
145 // First call is a special case, since it does not include a secondary | 145 // First call is a special case, since it does not include a secondary |
146 // payload. | 146 // payload. |
147 EXPECT_EQ(1u, encoded_info_.redundant.size()); | 147 EXPECT_EQ(1u, encoded_info_.redundant.size()); |
(...skipping 10 matching lines...) Expand all Loading... |
158 } | 158 } |
159 | 159 |
160 // Checks that the correct payload sizes are populated into the redundancy | 160 // Checks that the correct payload sizes are populated into the redundancy |
161 // information. | 161 // information. |
162 TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes) { | 162 TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes) { |
163 // Let the mock encoder return payload sizes 1, 2, 3, ..., 10 for the sequence | 163 // Let the mock encoder return payload sizes 1, 2, 3, ..., 10 for the sequence |
164 // of calls. | 164 // of calls. |
165 static const int kNumPackets = 10; | 165 static const int kNumPackets = 10; |
166 InSequence s; | 166 InSequence s; |
167 for (int encode_size = 1; encode_size <= kNumPackets; ++encode_size) { | 167 for (int encode_size = 1; encode_size <= kNumPackets; ++encode_size) { |
168 EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _)) | 168 EXPECT_CALL(mock_encoder_, EncodeImpl(_, _, _)) |
169 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(encode_size))); | 169 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(encode_size))); |
170 } | 170 } |
171 | 171 |
172 // First call is a special case, since it does not include a secondary | 172 // First call is a special case, since it does not include a secondary |
173 // payload. | 173 // payload. |
174 Encode(); | 174 Encode(); |
175 EXPECT_EQ(1u, encoded_info_.redundant.size()); | 175 EXPECT_EQ(1u, encoded_info_.redundant.size()); |
176 EXPECT_EQ(1u, encoded_info_.encoded_bytes); | 176 EXPECT_EQ(1u, encoded_info_.encoded_bytes); |
177 | 177 |
178 for (size_t i = 2; i <= kNumPackets; ++i) { | 178 for (size_t i = 2; i <= kNumPackets; ++i) { |
179 Encode(); | 179 Encode(); |
180 ASSERT_EQ(2u, encoded_info_.redundant.size()); | 180 ASSERT_EQ(2u, encoded_info_.redundant.size()); |
181 EXPECT_EQ(i, encoded_info_.redundant[0].encoded_bytes); | 181 EXPECT_EQ(i, encoded_info_.redundant[0].encoded_bytes); |
182 EXPECT_EQ(i - 1, encoded_info_.redundant[1].encoded_bytes); | 182 EXPECT_EQ(i - 1, encoded_info_.redundant[1].encoded_bytes); |
183 EXPECT_EQ(i + i - 1, encoded_info_.encoded_bytes); | 183 EXPECT_EQ(i + i - 1, encoded_info_.encoded_bytes); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 // Checks that the correct timestamps are returned. | 187 // Checks that the correct timestamps are returned. |
188 TEST_F(AudioEncoderCopyRedTest, CheckTimestamps) { | 188 TEST_F(AudioEncoderCopyRedTest, CheckTimestamps) { |
189 uint32_t primary_timestamp = timestamp_; | 189 uint32_t primary_timestamp = timestamp_; |
190 AudioEncoder::EncodedInfo info; | 190 AudioEncoder::EncodedInfo info; |
191 info.encoded_bytes = 17; | 191 info.encoded_bytes = 17; |
192 info.encoded_timestamp = timestamp_; | 192 info.encoded_timestamp = timestamp_; |
193 | 193 |
194 EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _)) | 194 EXPECT_CALL(mock_encoder_, EncodeImpl(_, _, _)) |
195 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(info))); | 195 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(info))); |
196 | 196 |
197 // First call is a special case, since it does not include a secondary | 197 // First call is a special case, since it does not include a secondary |
198 // payload. | 198 // payload. |
199 Encode(); | 199 Encode(); |
200 EXPECT_EQ(primary_timestamp, encoded_info_.encoded_timestamp); | 200 EXPECT_EQ(primary_timestamp, encoded_info_.encoded_timestamp); |
201 | 201 |
202 uint32_t secondary_timestamp = primary_timestamp; | 202 uint32_t secondary_timestamp = primary_timestamp; |
203 primary_timestamp = timestamp_; | 203 primary_timestamp = timestamp_; |
204 info.encoded_timestamp = timestamp_; | 204 info.encoded_timestamp = timestamp_; |
205 EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _)) | 205 EXPECT_CALL(mock_encoder_, EncodeImpl(_, _, _)) |
206 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(info))); | 206 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(info))); |
207 | 207 |
208 Encode(); | 208 Encode(); |
209 ASSERT_EQ(2u, encoded_info_.redundant.size()); | 209 ASSERT_EQ(2u, encoded_info_.redundant.size()); |
210 EXPECT_EQ(primary_timestamp, encoded_info_.redundant[0].encoded_timestamp); | 210 EXPECT_EQ(primary_timestamp, encoded_info_.redundant[0].encoded_timestamp); |
211 EXPECT_EQ(secondary_timestamp, encoded_info_.redundant[1].encoded_timestamp); | 211 EXPECT_EQ(secondary_timestamp, encoded_info_.redundant[1].encoded_timestamp); |
212 EXPECT_EQ(primary_timestamp, encoded_info_.encoded_timestamp); | 212 EXPECT_EQ(primary_timestamp, encoded_info_.encoded_timestamp); |
213 } | 213 } |
214 | 214 |
215 // Checks that the primary and secondary payloads are written correctly. | 215 // Checks that the primary and secondary payloads are written correctly. |
216 TEST_F(AudioEncoderCopyRedTest, CheckPayloads) { | 216 TEST_F(AudioEncoderCopyRedTest, CheckPayloads) { |
217 // Let the mock encoder write payloads with increasing values. The first | 217 // Let the mock encoder write payloads with increasing values. The first |
218 // payload will have values 0, 1, 2, ..., kPayloadLenBytes - 1. | 218 // payload will have values 0, 1, 2, ..., kPayloadLenBytes - 1. |
219 static const size_t kPayloadLenBytes = 5; | 219 static const size_t kPayloadLenBytes = 5; |
220 uint8_t payload[kPayloadLenBytes]; | 220 uint8_t payload[kPayloadLenBytes]; |
221 for (uint8_t i = 0; i < kPayloadLenBytes; ++i) { | 221 for (uint8_t i = 0; i < kPayloadLenBytes; ++i) { |
222 payload[i] = i; | 222 payload[i] = i; |
223 } | 223 } |
224 EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _)) | 224 EXPECT_CALL(mock_encoder_, EncodeImpl(_, _, _)) |
225 .WillRepeatedly(Invoke(MockAudioEncoder::CopyEncoding(payload))); | 225 .WillRepeatedly(Invoke(MockAudioEncoder::CopyEncoding(payload))); |
226 | 226 |
227 // First call is a special case, since it does not include a secondary | 227 // First call is a special case, since it does not include a secondary |
228 // payload. | 228 // payload. |
229 Encode(); | 229 Encode(); |
230 EXPECT_EQ(kPayloadLenBytes, encoded_info_.encoded_bytes); | 230 EXPECT_EQ(kPayloadLenBytes, encoded_info_.encoded_bytes); |
231 for (size_t i = 0; i < kPayloadLenBytes; ++i) { | 231 for (size_t i = 0; i < kPayloadLenBytes; ++i) { |
232 EXPECT_EQ(i, encoded_.data()[i]); | 232 EXPECT_EQ(i, encoded_.data()[i]); |
233 } | 233 } |
234 | 234 |
(...skipping 15 matching lines...) Expand all Loading... |
250 } | 250 } |
251 } | 251 } |
252 | 252 |
253 // Checks correct propagation of payload type. | 253 // Checks correct propagation of payload type. |
254 // Checks that the correct timestamps are returned. | 254 // Checks that the correct timestamps are returned. |
255 TEST_F(AudioEncoderCopyRedTest, CheckPayloadType) { | 255 TEST_F(AudioEncoderCopyRedTest, CheckPayloadType) { |
256 const int primary_payload_type = red_payload_type_ + 1; | 256 const int primary_payload_type = red_payload_type_ + 1; |
257 AudioEncoder::EncodedInfo info; | 257 AudioEncoder::EncodedInfo info; |
258 info.encoded_bytes = 17; | 258 info.encoded_bytes = 17; |
259 info.payload_type = primary_payload_type; | 259 info.payload_type = primary_payload_type; |
260 EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _)) | 260 EXPECT_CALL(mock_encoder_, EncodeImpl(_, _, _)) |
261 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(info))); | 261 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(info))); |
262 | 262 |
263 // First call is a special case, since it does not include a secondary | 263 // First call is a special case, since it does not include a secondary |
264 // payload. | 264 // payload. |
265 Encode(); | 265 Encode(); |
266 ASSERT_EQ(1u, encoded_info_.redundant.size()); | 266 ASSERT_EQ(1u, encoded_info_.redundant.size()); |
267 EXPECT_EQ(primary_payload_type, encoded_info_.redundant[0].payload_type); | 267 EXPECT_EQ(primary_payload_type, encoded_info_.redundant[0].payload_type); |
268 EXPECT_EQ(red_payload_type_, encoded_info_.payload_type); | 268 EXPECT_EQ(red_payload_type_, encoded_info_.payload_type); |
269 | 269 |
270 const int secondary_payload_type = red_payload_type_ + 2; | 270 const int secondary_payload_type = red_payload_type_ + 2; |
271 info.payload_type = secondary_payload_type; | 271 info.payload_type = secondary_payload_type; |
272 EXPECT_CALL(mock_encoder_, EncodeInternal(_, _, _)) | 272 EXPECT_CALL(mock_encoder_, EncodeImpl(_, _, _)) |
273 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(info))); | 273 .WillOnce(Invoke(MockAudioEncoder::FakeEncoding(info))); |
274 | 274 |
275 Encode(); | 275 Encode(); |
276 ASSERT_EQ(2u, encoded_info_.redundant.size()); | 276 ASSERT_EQ(2u, encoded_info_.redundant.size()); |
277 EXPECT_EQ(secondary_payload_type, encoded_info_.redundant[0].payload_type); | 277 EXPECT_EQ(secondary_payload_type, encoded_info_.redundant[0].payload_type); |
278 EXPECT_EQ(primary_payload_type, encoded_info_.redundant[1].payload_type); | 278 EXPECT_EQ(primary_payload_type, encoded_info_.redundant[1].payload_type); |
279 EXPECT_EQ(red_payload_type_, encoded_info_.payload_type); | 279 EXPECT_EQ(red_payload_type_, encoded_info_.payload_type); |
280 } | 280 } |
281 | 281 |
282 #if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 282 #if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
(...skipping 18 matching lines...) Expand all Loading... |
301 config.speech_encoder = NULL; | 301 config.speech_encoder = NULL; |
302 EXPECT_DEATH(red = new AudioEncoderCopyRed(config), | 302 EXPECT_DEATH(red = new AudioEncoderCopyRed(config), |
303 "Speech encoder not provided."); | 303 "Speech encoder not provided."); |
304 // The delete operation is needed to avoid leak reports from memcheck. | 304 // The delete operation is needed to avoid leak reports from memcheck. |
305 delete red; | 305 delete red; |
306 } | 306 } |
307 | 307 |
308 #endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 308 #endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
309 | 309 |
310 } // namespace webrtc | 310 } // namespace webrtc |
OLD | NEW |