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

Side by Side Diff: content/browser/renderer_host/media/audio_input_sync_writer_unittest.cc

Issue 2689483006: Switch browser side audio capture path to use base time primitives. (Closed)
Patch Set: Bloop Created 3 years, 10 months 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/media/audio_input_sync_writer.h" 5 #include "content/browser/renderer_host/media/audio_input_sync_writer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 private: 190 private:
191 TestBrowserThreadBundle thread_bundle_; 191 TestBrowserThreadBundle thread_bundle_;
192 192
193 DISALLOW_COPY_AND_ASSIGN(AudioInputSyncWriterTest); 193 DISALLOW_COPY_AND_ASSIGN(AudioInputSyncWriterTest);
194 }; 194 };
195 195
196 TEST_F(AudioInputSyncWriterTest, SingleWriteAndRead) { 196 TEST_F(AudioInputSyncWriterTest, SingleWriteAndRead) {
197 EXPECT_CALL(*writer_.get(), AddToNativeLog(_)) 197 EXPECT_CALL(*writer_.get(), AddToNativeLog(_))
198 .Times(GetTotalNumberOfExpectedLogCalls(0)); 198 .Times(GetTotalNumberOfExpectedLogCalls(0));
199 199
200 writer_->Write(audio_bus_.get(), 0, false, 0); 200 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
201 base::TimeTicks::Now());
201 EXPECT_TRUE(TestSocketAndFifoExpectations(1, 0, 0)); 202 EXPECT_TRUE(TestSocketAndFifoExpectations(1, 0, 0));
202 203
203 socket_->Read(1); 204 socket_->Read(1);
204 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 1 * sizeof(uint32_t), 0)); 205 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 1 * sizeof(uint32_t), 0));
205 } 206 }
206 207
207 TEST_F(AudioInputSyncWriterTest, MultipleWritesAndReads) { 208 TEST_F(AudioInputSyncWriterTest, MultipleWritesAndReads) {
208 EXPECT_CALL(*writer_.get(), AddToNativeLog(_)) 209 EXPECT_CALL(*writer_.get(), AddToNativeLog(_))
209 .Times(GetTotalNumberOfExpectedLogCalls(0)); 210 .Times(GetTotalNumberOfExpectedLogCalls(0));
210 211
211 for (int i = 1; i <= 2 * kSegments; ++i) { 212 for (int i = 1; i <= 2 * kSegments; ++i) {
212 writer_->Write(audio_bus_.get(), 0, false, 0); 213 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
214 base::TimeTicks::Now());
213 EXPECT_TRUE(TestSocketAndFifoExpectations(1, 0, 0)); 215 EXPECT_TRUE(TestSocketAndFifoExpectations(1, 0, 0));
214 socket_->Read(1); 216 socket_->Read(1);
215 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 1 * sizeof(uint32_t), 0)); 217 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 1 * sizeof(uint32_t), 0));
216 } 218 }
217 } 219 }
218 220
219 TEST_F(AudioInputSyncWriterTest, MultipleWritesNoReads) { 221 TEST_F(AudioInputSyncWriterTest, MultipleWritesNoReads) {
220 EXPECT_CALL(*writer_.get(), AddToNativeLog(_)) 222 EXPECT_CALL(*writer_.get(), AddToNativeLog(_))
221 .Times(GetTotalNumberOfExpectedLogCalls(1)); 223 .Times(GetTotalNumberOfExpectedLogCalls(1));
222 224
223 // Fill the ring buffer. 225 // Fill the ring buffer.
224 for (int i = 1; i <= kSegments; ++i) { 226 for (int i = 1; i <= kSegments; ++i) {
225 writer_->Write(audio_bus_.get(), 0, false, 0); 227 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
228 base::TimeTicks::Now());
226 EXPECT_TRUE(TestSocketAndFifoExpectations(i, 0, 0)); 229 EXPECT_TRUE(TestSocketAndFifoExpectations(i, 0, 0));
227 } 230 }
228 231
229 // Now the ring buffer is full, do more writes. We should start filling the 232 // Now the ring buffer is full, do more writes. We should start filling the
230 // fifo and should get one extra log call for that. 233 // fifo and should get one extra log call for that.
231 for (size_t i = 1; i <= kSegments; ++i) { 234 for (size_t i = 1; i <= kSegments; ++i) {
232 writer_->Write(audio_bus_.get(), 0, false, 0); 235 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
236 base::TimeTicks::Now());
233 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, i)); 237 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, i));
234 } 238 }
235 } 239 }
236 240
237 TEST_F(AudioInputSyncWriterTest, FillAndEmptyRingBuffer) { 241 TEST_F(AudioInputSyncWriterTest, FillAndEmptyRingBuffer) {
238 EXPECT_CALL(*writer_.get(), AddToNativeLog(_)) 242 EXPECT_CALL(*writer_.get(), AddToNativeLog(_))
239 .Times(GetTotalNumberOfExpectedLogCalls(2)); 243 .Times(GetTotalNumberOfExpectedLogCalls(2));
240 244
241 // Fill the ring buffer. 245 // Fill the ring buffer.
242 for (int i = 1; i <= kSegments; ++i) { 246 for (int i = 1; i <= kSegments; ++i) {
243 writer_->Write(audio_bus_.get(), 0, false, 0); 247 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
248 base::TimeTicks::Now());
244 } 249 }
245 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 0)); 250 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 0));
246 251
247 // Empty half of the ring buffer. 252 // Empty half of the ring buffer.
248 const int buffers_to_read = kSegments / 2; 253 const int buffers_to_read = kSegments / 2;
249 socket_->Read(buffers_to_read); 254 socket_->Read(buffers_to_read);
250 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments - buffers_to_read, 255 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments - buffers_to_read,
251 buffers_to_read * sizeof(uint32_t), 256 buffers_to_read * sizeof(uint32_t),
252 0)); 257 0));
253 258
254 // Fill up again. The first write should do receive until that queue is 259 // Fill up again. The first write should do receive until that queue is
255 // empty. 260 // empty.
256 for (int i = kSegments - buffers_to_read + 1; i <= kSegments; ++i) { 261 for (int i = kSegments - buffers_to_read + 1; i <= kSegments; ++i) {
257 writer_->Write(audio_bus_.get(), 0, false, 0); 262 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
263 base::TimeTicks::Now());
258 EXPECT_TRUE(TestSocketAndFifoExpectations(i, 0, 0)); 264 EXPECT_TRUE(TestSocketAndFifoExpectations(i, 0, 0));
259 } 265 }
260 266
261 // Another write, should put the data in the fifo, and render an extra log 267 // Another write, should put the data in the fifo, and render an extra log
262 // call. 268 // call.
263 writer_->Write(audio_bus_.get(), 0, false, 0); 269 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
270 base::TimeTicks::Now());
264 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 1)); 271 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 1));
265 272
266 // Empty the ring buffer. 273 // Empty the ring buffer.
267 socket_->Read(kSegments); 274 socket_->Read(kSegments);
268 EXPECT_TRUE( 275 EXPECT_TRUE(
269 TestSocketAndFifoExpectations(0, kSegments * sizeof(uint32_t), 1)); 276 TestSocketAndFifoExpectations(0, kSegments * sizeof(uint32_t), 1));
270 277
271 // Another write, should do receive until that queue is empty and write both 278 // Another write, should do receive until that queue is empty and write both
272 // the data in the fifo and the new data, and render a log call. 279 // the data in the fifo and the new data, and render a log call.
273 writer_->Write(audio_bus_.get(), 0, false, 0); 280 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
281 base::TimeTicks::Now());
274 EXPECT_TRUE(TestSocketAndFifoExpectations(2, 0, 0)); 282 EXPECT_TRUE(TestSocketAndFifoExpectations(2, 0, 0));
275 283
276 // Read the two data blocks. 284 // Read the two data blocks.
277 socket_->Read(2); 285 socket_->Read(2);
278 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 2 * sizeof(uint32_t), 0)); 286 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 2 * sizeof(uint32_t), 0));
279 } 287 }
280 288
281 TEST_F(AudioInputSyncWriterTest, FillRingBufferAndFifo) { 289 TEST_F(AudioInputSyncWriterTest, FillRingBufferAndFifo) {
282 EXPECT_CALL(*writer_.get(), AddToNativeLog(_)) 290 EXPECT_CALL(*writer_.get(), AddToNativeLog(_))
283 .Times(GetTotalNumberOfExpectedLogCalls(2)); 291 .Times(GetTotalNumberOfExpectedLogCalls(2));
284 292
285 // Fill the ring buffer. 293 // Fill the ring buffer.
286 for (int i = 1; i <= kSegments; ++i) { 294 for (int i = 1; i <= kSegments; ++i) {
287 writer_->Write(audio_bus_.get(), 0, false, 0); 295 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
296 base::TimeTicks::Now());
288 } 297 }
289 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 0)); 298 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 0));
290 299
291 // Fill the fifo. Should render one log call for starting filling it. 300 // Fill the fifo. Should render one log call for starting filling it.
292 const size_t max_fifo_size = AudioInputSyncWriter::kMaxOverflowBusesSize; 301 const size_t max_fifo_size = AudioInputSyncWriter::kMaxOverflowBusesSize;
293 for (size_t i = 1; i <= max_fifo_size; ++i) { 302 for (size_t i = 1; i <= max_fifo_size; ++i) {
294 writer_->Write(audio_bus_.get(), 0, false, 0); 303 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
304 base::TimeTicks::Now());
295 } 305 }
296 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, max_fifo_size)); 306 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, max_fifo_size));
297 307
298 // Another write, data should be dropped and render one log call. 308 // Another write, data should be dropped and render one log call.
299 writer_->Write(audio_bus_.get(), 0, false, 0); 309 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
310 base::TimeTicks::Now());
300 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, max_fifo_size)); 311 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, max_fifo_size));
301 } 312 }
302 313
303 TEST_F(AudioInputSyncWriterTest, MultipleFillAndEmptyRingBufferAndPartOfFifo) { 314 TEST_F(AudioInputSyncWriterTest, MultipleFillAndEmptyRingBufferAndPartOfFifo) {
304 EXPECT_CALL(*writer_.get(), AddToNativeLog(_)) 315 EXPECT_CALL(*writer_.get(), AddToNativeLog(_))
305 .Times(GetTotalNumberOfExpectedLogCalls(4)); 316 .Times(GetTotalNumberOfExpectedLogCalls(4));
306 317
307 // Fill the ring buffer. 318 // Fill the ring buffer.
308 for (int i = 1; i <= kSegments; ++i) { 319 for (int i = 1; i <= kSegments; ++i) {
309 writer_->Write(audio_bus_.get(), 0, false, 0); 320 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
321 base::TimeTicks::Now());
310 } 322 }
311 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 0)); 323 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 0));
312 324
313 // Write more data, should be put in the fifo and render one log call for 325 // Write more data, should be put in the fifo and render one log call for
314 // starting filling it. 326 // starting filling it.
315 for (size_t i = 1; i <= 2 * kSegments; ++i) { 327 for (size_t i = 1; i <= 2 * kSegments; ++i) {
316 writer_->Write(audio_bus_.get(), 0, false, 0); 328 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
329 base::TimeTicks::Now());
317 } 330 }
318 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 2 * kSegments)); 331 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 2 * kSegments));
319 332
320 // Empty the ring buffer. 333 // Empty the ring buffer.
321 socket_->Read(kSegments); 334 socket_->Read(kSegments);
322 EXPECT_TRUE(TestSocketAndFifoExpectations(0, kSegments * sizeof(uint32_t), 335 EXPECT_TRUE(TestSocketAndFifoExpectations(0, kSegments * sizeof(uint32_t),
323 2 * kSegments)); 336 2 * kSegments));
324 337
325 // Another write should fill up the ring buffer with data from the fifo and 338 // Another write should fill up the ring buffer with data from the fifo and
326 // put this data into the fifo. 339 // put this data into the fifo.
327 writer_->Write(audio_bus_.get(), 0, false, 0); 340 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
341 base::TimeTicks::Now());
328 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, kSegments + 1)); 342 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, kSegments + 1));
329 343
330 // Empty the ring buffer again. 344 // Empty the ring buffer again.
331 socket_->Read(kSegments); 345 socket_->Read(kSegments);
332 EXPECT_TRUE(TestSocketAndFifoExpectations(0, kSegments * sizeof(uint32_t), 346 EXPECT_TRUE(TestSocketAndFifoExpectations(0, kSegments * sizeof(uint32_t),
333 kSegments + 1)); 347 kSegments + 1));
334 348
335 // Another write should fill up the ring buffer with data from the fifo and 349 // Another write should fill up the ring buffer with data from the fifo and
336 // put this data into the fifo. 350 // put this data into the fifo.
337 writer_->Write(audio_bus_.get(), 0, false, 0); 351 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
352 base::TimeTicks::Now());
338 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 2)); 353 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 2));
339 354
340 // Empty the ring buffer again. 355 // Empty the ring buffer again.
341 socket_->Read(kSegments); 356 socket_->Read(kSegments);
342 EXPECT_TRUE( 357 EXPECT_TRUE(
343 TestSocketAndFifoExpectations(0, kSegments * sizeof(uint32_t), 2)); 358 TestSocketAndFifoExpectations(0, kSegments * sizeof(uint32_t), 2));
344 359
345 // Another write should put the remaining data in the fifo in the ring buffer 360 // Another write should put the remaining data in the fifo in the ring buffer
346 // together with this data. Should render a log call for emptying the fifo. 361 // together with this data. Should render a log call for emptying the fifo.
347 writer_->Write(audio_bus_.get(), 0, false, 0); 362 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
363 base::TimeTicks::Now());
348 EXPECT_TRUE(TestSocketAndFifoExpectations(3, 0, 0)); 364 EXPECT_TRUE(TestSocketAndFifoExpectations(3, 0, 0));
349 365
350 // Read the remaining data. 366 // Read the remaining data.
351 socket_->Read(3); 367 socket_->Read(3);
352 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 3 * sizeof(uint32_t), 0)); 368 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 3 * sizeof(uint32_t), 0));
353 369
354 // Fill the ring buffer and part of the fifo. Should render one log call for 370 // Fill the ring buffer and part of the fifo. Should render one log call for
355 // starting filling it. 371 // starting filling it.
356 for (int i = 1; i <= kSegments + 2; ++i) { 372 for (int i = 1; i <= kSegments + 2; ++i) {
357 writer_->Write(audio_bus_.get(), 0, false, 0); 373 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
374 base::TimeTicks::Now());
358 } 375 }
359 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 2)); 376 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 2));
360 377
361 // Empty both. Should render a log call for emptying the fifo. 378 // Empty both. Should render a log call for emptying the fifo.
362 socket_->Read(kSegments); 379 socket_->Read(kSegments);
363 writer_->Write(audio_bus_.get(), 0, false, 0); 380 writer_->Write(audio_bus_.get(), 0, false, base::TimeDelta(),
381 base::TimeTicks::Now());
364 socket_->Read(3); 382 socket_->Read(3);
365 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 3 * sizeof(uint32_t), 0)); 383 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 3 * sizeof(uint32_t), 0));
366 } 384 }
367 385
368 } // namespace content 386 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698