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

Side by Side Diff: media/audio/audio_output_proxy_unittest.cc

Issue 10154007: Change the way audio mixer gets "pending bytes" (amount of data currently buffered (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_output_mixer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "media/audio/audio_output_dispatcher_impl.h" 10 #include "media/audio/audio_output_dispatcher_impl.h"
11 #include "media/audio/audio_output_mixer.h" 11 #include "media/audio/audio_output_mixer.h"
12 #include "media/audio/audio_output_proxy.h" 12 #include "media/audio/audio_output_proxy.h"
13 #include "media/audio/audio_manager.h" 13 #include "media/audio/audio_manager.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using ::testing::_; 17 using ::testing::_;
18 using ::testing::AllOf;
19 using ::testing::Field;
18 using ::testing::Mock; 20 using ::testing::Mock;
19 using ::testing::Return; 21 using ::testing::Return;
20 using media::AudioBuffersState; 22 using media::AudioBuffersState;
21 using media::AudioInputStream; 23 using media::AudioInputStream;
22 using media::AudioManager; 24 using media::AudioManager;
23 using media::AudioOutputDispatcher; 25 using media::AudioOutputDispatcher;
24 using media::AudioOutputProxy; 26 using media::AudioOutputProxy;
25 using media::AudioOutputStream; 27 using media::AudioOutputStream;
26 using media::AudioParameters; 28 using media::AudioParameters;
27 29
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 proxy1->Start(&callback_); 429 proxy1->Start(&callback_);
428 proxy2->Start(&callback_); 430 proxy2->Start(&callback_);
429 proxy1->Stop(); 431 proxy1->Stop();
430 proxy2->Stop(); 432 proxy2->Stop();
431 433
432 proxy1->Close(); 434 proxy1->Close();
433 proxy2->Close(); 435 proxy2->Close();
434 } 436 }
435 437
436 // Two streams, both are playing. Still have to use single device. 438 // Two streams, both are playing. Still have to use single device.
439 // Also verifies that every proxy stream gets its own pending_bytes.
437 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) { 440 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) {
438 MockAudioOutputStream stream; 441 MockAudioOutputStream stream;
439 442
440 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); 443 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs));
441 444
442 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 445 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
443 .WillOnce(Return(&stream)); 446 .WillOnce(Return(&stream));
444 447
445 EXPECT_CALL(stream, Open()) 448 EXPECT_CALL(stream, Open())
446 .WillOnce(Return(true)); 449 .WillOnce(Return(true));
447 EXPECT_CALL(stream, Start(_)) 450 EXPECT_CALL(stream, Start(_))
448 .Times(1); 451 .Times(1);
449 EXPECT_CALL(stream, SetVolume(_)) 452 EXPECT_CALL(stream, SetVolume(_))
450 .Times(1); 453 .Times(1);
451 EXPECT_CALL(stream, Stop()) 454 EXPECT_CALL(stream, Stop())
452 .Times(1); 455 .Times(1);
453 EXPECT_CALL(stream, Close()) 456 EXPECT_CALL(stream, Close())
454 .Times(1); 457 .Times(1);
455 458
456 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_); 459 AudioOutputProxy* proxy1 = new AudioOutputProxy(mixer_);
457 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_); 460 AudioOutputProxy* proxy2 = new AudioOutputProxy(mixer_);
458 EXPECT_TRUE(proxy1->Open()); 461 EXPECT_TRUE(proxy1->Open());
459 EXPECT_TRUE(proxy2->Open()); 462 EXPECT_TRUE(proxy2->Open());
460 463
461 proxy1->Start(&callback_); 464 proxy1->Start(&callback_);
465 uint8 buf1[4] = {0};
466 EXPECT_CALL(callback_,
467 OnMoreData(_, 4,
468 AllOf(Field(&AudioBuffersState::pending_bytes, 0),
469 Field(&AudioBuffersState::hardware_delay_bytes, 0))))
470 .WillOnce(Return(4));
471 mixer_->OnMoreData(buf1, sizeof(buf1), AudioBuffersState(0, 0));
462 proxy2->Start(&callback_); 472 proxy2->Start(&callback_);
473 uint8 buf2[4] = {0};
474 EXPECT_CALL(callback_,
475 OnMoreData(_, 4,
476 AllOf(Field(&AudioBuffersState::pending_bytes, 4),
477 Field(&AudioBuffersState::hardware_delay_bytes, 0))))
478 .WillOnce(Return(4));
479 EXPECT_CALL(callback_,
480 OnMoreData(_, 4,
481 AllOf(Field(&AudioBuffersState::pending_bytes, 0),
482 Field(&AudioBuffersState::hardware_delay_bytes, 0))))
483 .WillOnce(Return(4));
484 mixer_->OnMoreData(buf2, sizeof(buf2), AudioBuffersState(4, 0));
463 proxy1->Stop(); 485 proxy1->Stop();
464 proxy2->Stop(); 486 proxy2->Stop();
465 487
466 proxy1->Close(); 488 proxy1->Close();
467 proxy2->Close(); 489 proxy2->Close();
468 WaitForCloseTimer(kTestCloseDelayMs); 490 WaitForCloseTimer(kTestCloseDelayMs);
469 } 491 }
470 492
471 TEST_F(AudioOutputProxyTest, OpenFailed) { 493 TEST_F(AudioOutputProxyTest, OpenFailed) {
472 OpenFailed(dispatcher_impl_); 494 OpenFailed(dispatcher_impl_);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 572
551 proxy2->Start(&callback_); 573 proxy2->Start(&callback_);
552 574
553 Mock::VerifyAndClear(&callback_); 575 Mock::VerifyAndClear(&callback_);
554 576
555 proxy2->Close(); 577 proxy2->Close();
556 WaitForCloseTimer(kTestCloseDelayMs); 578 WaitForCloseTimer(kTestCloseDelayMs);
557 } 579 }
558 580
559 } // namespace media 581 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_mixer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698