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

Side by Side Diff: media/audio/linux/alsa_output_unittest.cc

Issue 2978005: Fixed ended event when playing audio on linux. (Closed)
Patch Set: Created 10 years, 5 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
« no previous file with comments | « media/audio/linux/alsa_output.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "media/audio/linux/alsa_output.h" 8 #include "media/audio/linux/alsa_output.h"
9 #include "media/audio/linux/alsa_wrapper.h" 9 #include "media/audio/linux/alsa_wrapper.h"
10 #include "media/audio/linux/audio_manager_linux.h" 10 #include "media/audio/linux/audio_manager_linux.h"
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 message_loop_.RunAllPending(); 425 message_loop_.RunAllPending();
426 426
427 // Expect Device setup. 427 // Expect Device setup.
428 EXPECT_CALL(mock_alsa_wrapper_, PcmDrop(kFakeHandle)) 428 EXPECT_CALL(mock_alsa_wrapper_, PcmDrop(kFakeHandle))
429 .WillOnce(Return(0)); 429 .WillOnce(Return(0));
430 EXPECT_CALL(mock_alsa_wrapper_, PcmPrepare(kFakeHandle)) 430 EXPECT_CALL(mock_alsa_wrapper_, PcmPrepare(kFakeHandle))
431 .WillOnce(Return(0)); 431 .WillOnce(Return(0));
432 432
433 // Expect the pre-roll. 433 // Expect the pre-roll.
434 MockAudioSourceCallback mock_callback; 434 MockAudioSourceCallback mock_callback;
435 EXPECT_CALL(mock_alsa_wrapper_, PcmState(kFakeHandle))
436 .Times(2)
437 .WillRepeatedly(Return(SND_PCM_STATE_RUNNING));
438 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(kFakeHandle, _))
439 .Times(2)
440 .WillRepeatedly(DoAll(SetArgumentPointee<1>(0), Return(0)));
441 EXPECT_CALL(mock_callback, 435 EXPECT_CALL(mock_callback,
442 OnMoreData(test_stream_.get(), _, kTestPacketSize, 0)) 436 OnMoreData(test_stream_.get(), _, kTestPacketSize, 0))
443 .Times(2) 437 .Times(2)
444 .WillOnce(Return(kTestPacketSize)) 438 .WillOnce(Return(kTestPacketSize))
445 .WillOnce(Return(0)); 439 .WillOnce(Return(0));
446 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _)) 440 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _))
447 .WillOnce(Return(kTestFramesPerPacket)); 441 .WillOnce(Return(kTestFramesPerPacket));
448 442
449 // Expect scheduling. 443 // Expect scheduling.
450 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) 444 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle))
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 test_stream_->WritePacket(); 531 test_stream_->WritePacket();
538 EXPECT_EQ(0u, test_stream_->buffer_->forward_bytes()); 532 EXPECT_EQ(0u, test_stream_->buffer_->forward_bytes());
539 } 533 }
540 534
541 TEST_F(AlsaPcmOutputStreamTest, BufferPacket) { 535 TEST_F(AlsaPcmOutputStreamTest, BufferPacket) {
542 InitBuffer(); 536 InitBuffer();
543 test_stream_->buffer_->Clear(); 537 test_stream_->buffer_->Clear();
544 538
545 // Return a partially filled packet. 539 // Return a partially filled packet.
546 MockAudioSourceCallback mock_callback; 540 MockAudioSourceCallback mock_callback;
547 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_))
548 .WillOnce(Return(SND_PCM_STATE_RUNNING));
549 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(_, _))
550 .WillOnce(DoAll(SetArgumentPointee<1>(1), Return(0)));
551 EXPECT_CALL(mock_callback, 541 EXPECT_CALL(mock_callback,
552 OnMoreData(test_stream_.get(), _, _, kTestBytesPerFrame)) 542 OnMoreData(test_stream_.get(), _, _, 0))
553 .WillOnce(Return(10)); 543 .WillOnce(Return(10));
554 544
555 bool source_exhausted; 545 bool source_exhausted;
556 test_stream_->shared_data_.set_source_callback(&mock_callback); 546 test_stream_->shared_data_.set_source_callback(&mock_callback);
557 test_stream_->packet_size_ = kTestPacketSize; 547 test_stream_->packet_size_ = kTestPacketSize;
558 test_stream_->BufferPacket(&source_exhausted); 548 test_stream_->BufferPacket(&source_exhausted);
559 549
560 EXPECT_EQ(10u, test_stream_->buffer_->forward_bytes()); 550 EXPECT_EQ(10u, test_stream_->buffer_->forward_bytes());
561 EXPECT_FALSE(source_exhausted); 551 EXPECT_FALSE(source_exhausted);
562 } 552 }
563 553
564 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Negative) { 554 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Negative) {
565 InitBuffer(); 555 InitBuffer();
566 test_stream_->buffer_->Clear(); 556 test_stream_->buffer_->Clear();
567 557
568 // Simulate where the underrun has occurred right after checking the delay. 558 // Simulate where the underrun has occurred right after checking the delay.
569 MockAudioSourceCallback mock_callback; 559 MockAudioSourceCallback mock_callback;
570 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_))
571 .WillOnce(Return(SND_PCM_STATE_RUNNING));
572 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(_, _))
573 .WillOnce(DoAll(SetArgumentPointee<1>(-1), Return(0)));
574 EXPECT_CALL(mock_callback, 560 EXPECT_CALL(mock_callback,
575 OnMoreData(test_stream_.get(), _, _, 0)) 561 OnMoreData(test_stream_.get(), _, _, 0))
576 .WillOnce(Return(10)); 562 .WillOnce(Return(10));
577 563
578 bool source_exhausted; 564 bool source_exhausted;
579 test_stream_->shared_data_.set_source_callback(&mock_callback); 565 test_stream_->shared_data_.set_source_callback(&mock_callback);
580 test_stream_->packet_size_ = kTestPacketSize; 566 test_stream_->packet_size_ = kTestPacketSize;
581 test_stream_->BufferPacket(&source_exhausted); 567 test_stream_->BufferPacket(&source_exhausted);
582 568
583 EXPECT_EQ(10u, test_stream_->buffer_->forward_bytes()); 569 EXPECT_EQ(10u, test_stream_->buffer_->forward_bytes());
584 EXPECT_FALSE(source_exhausted); 570 EXPECT_FALSE(source_exhausted);
585 } 571 }
586 572
587 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Underrun) { 573 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Underrun) {
588 InitBuffer(); 574 InitBuffer();
589 test_stream_->buffer_->Clear(); 575 test_stream_->buffer_->Clear();
590 576
591 // If ALSA has underrun then we should assume a delay of zero. 577 // If ALSA has underrun then we should assume a delay of zero.
592 MockAudioSourceCallback mock_callback; 578 MockAudioSourceCallback mock_callback;
593 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_))
594 .WillOnce(Return(SND_PCM_STATE_XRUN));
595 EXPECT_CALL(mock_callback, 579 EXPECT_CALL(mock_callback,
596 OnMoreData(test_stream_.get(), _, _, 0)) 580 OnMoreData(test_stream_.get(), _, _, 0))
597 .WillOnce(Return(10)); 581 .WillOnce(Return(10));
598 582
599 bool source_exhausted; 583 bool source_exhausted;
600 test_stream_->shared_data_.set_source_callback(&mock_callback); 584 test_stream_->shared_data_.set_source_callback(&mock_callback);
601 test_stream_->packet_size_ = kTestPacketSize; 585 test_stream_->packet_size_ = kTestPacketSize;
602 test_stream_->BufferPacket(&source_exhausted); 586 test_stream_->BufferPacket(&source_exhausted);
603 587
604 EXPECT_EQ(10u, test_stream_->buffer_->forward_bytes()); 588 EXPECT_EQ(10u, test_stream_->buffer_->forward_bytes());
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 759
776 test_stream_->stop_stream_ = true; 760 test_stream_->stop_stream_ = true;
777 test_stream_->ScheduleNextWrite(true); 761 test_stream_->ScheduleNextWrite(true);
778 762
779 // TODO(ajwong): Find a way to test whether or not another task has been 763 // TODO(ajwong): Find a way to test whether or not another task has been
780 // posted so we can verify that the Alsa code will indeed break the task 764 // posted so we can verify that the Alsa code will indeed break the task
781 // posting loop. 765 // posting loop.
782 766
783 test_stream_->shared_data_.TransitionTo(AlsaPcmOutputStream::kIsClosed); 767 test_stream_->shared_data_.TransitionTo(AlsaPcmOutputStream::kIsClosed);
784 } 768 }
OLDNEW
« no previous file with comments | « media/audio/linux/alsa_output.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698