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

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

Issue 22886005: Switch audio synchronization from sleep() based to select() based. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Split out base/ changes. Created 7 years, 3 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
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/environment.h" 7 #include "base/environment.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 private: 46 private:
47 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); 47 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler);
48 }; 48 };
49 49
50 class MockAudioOutputControllerSyncReader 50 class MockAudioOutputControllerSyncReader
51 : public AudioOutputController::SyncReader { 51 : public AudioOutputController::SyncReader {
52 public: 52 public:
53 MockAudioOutputControllerSyncReader() {} 53 MockAudioOutputControllerSyncReader() {}
54 54
55 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); 55 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes));
56 MOCK_METHOD3(Read, int(bool block, const AudioBus* source, AudioBus* dest)); 56 MOCK_METHOD2(Read, void(const AudioBus* source, AudioBus* dest));
57 MOCK_METHOD0(Close, void()); 57 MOCK_METHOD0(Close, void());
58 58
59 private: 59 private:
60 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); 60 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader);
61 }; 61 };
62 62
63 class MockAudioOutputStream : public AudioOutputStream { 63 class MockAudioOutputStream : public AudioOutputStream {
64 public: 64 public:
65 MOCK_METHOD0(Open, bool()); 65 MOCK_METHOD0(Open, bool());
66 MOCK_METHOD1(Start, void(AudioSourceCallback* callback)); 66 MOCK_METHOD1(Start, void(AudioSourceCallback* callback));
67 MOCK_METHOD0(Stop, void()); 67 MOCK_METHOD0(Stop, void());
68 MOCK_METHOD1(SetVolume, void(double volume)); 68 MOCK_METHOD1(SetVolume, void(double volume));
69 MOCK_METHOD1(GetVolume, void(double* volume)); 69 MOCK_METHOD1(GetVolume, void(double* volume));
70 MOCK_METHOD0(Close, void()); 70 MOCK_METHOD0(Close, void());
71 71
72 // Set/get the callback passed to Start(). 72 // Set/get the callback passed to Start().
73 AudioSourceCallback* callback() const { return callback_; } 73 AudioSourceCallback* callback() const { return callback_; }
74 void SetCallback(AudioSourceCallback* asc) { callback_ = asc; } 74 void SetCallback(AudioSourceCallback* asc) { callback_ = asc; }
75 75
76 private: 76 private:
77 AudioSourceCallback* callback_; 77 AudioSourceCallback* callback_;
78 }; 78 };
79 79
80 ACTION_P(SignalEvent, event) { 80 ACTION_P(SignalEvent, event) {
81 event->Signal(); 81 event->Signal();
82 } 82 }
83 83
84 static const float kBufferNonZeroData = 1.0f; 84 static const float kBufferNonZeroData = 1.0f;
85 ACTION(PopulateBuffer) { 85 ACTION(PopulateBuffer) {
86 arg2->Zero(); 86 arg1->Zero();
87 // Note: To confirm the buffer will be populated in these tests, it's 87 // Note: To confirm the buffer will be populated in these tests, it's
88 // sufficient that only the first float in channel 0 is set to the value. 88 // sufficient that only the first float in channel 0 is set to the value.
89 arg2->channel(0)[0] = kBufferNonZeroData; 89 arg1->channel(0)[0] = kBufferNonZeroData;
90 } 90 }
91 91
92 class AudioOutputControllerTest : public testing::Test { 92 class AudioOutputControllerTest : public testing::Test {
93 public: 93 public:
94 AudioOutputControllerTest() 94 AudioOutputControllerTest()
95 : audio_manager_(AudioManager::Create()), 95 : audio_manager_(AudioManager::Create()),
96 create_event_(false, false), 96 create_event_(false, false),
97 play_event_(false, false), 97 play_event_(false, false),
98 read_event_(false, false), 98 read_event_(false, false),
99 pause_event_(false, false) { 99 pause_event_(false, false) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // OnPowerMeasured() calls. 132 // OnPowerMeasured() calls.
133 EXPECT_CALL(mock_event_handler_, OnPlaying()) 133 EXPECT_CALL(mock_event_handler_, OnPlaying())
134 .WillOnce(SignalEvent(&play_event_)); 134 .WillOnce(SignalEvent(&play_event_));
135 EXPECT_CALL(mock_event_handler_, OnPowerMeasured(_, false)) 135 EXPECT_CALL(mock_event_handler_, OnPowerMeasured(_, false))
136 .Times(AtLeast(1)); 136 .Times(AtLeast(1));
137 137
138 // During playback, the mock pretends to provide audio data rendered and 138 // During playback, the mock pretends to provide audio data rendered and
139 // sent from the render process. 139 // sent from the render process.
140 EXPECT_CALL(mock_sync_reader_, UpdatePendingBytes(_)) 140 EXPECT_CALL(mock_sync_reader_, UpdatePendingBytes(_))
141 .Times(AtLeast(1)); 141 .Times(AtLeast(1));
142 EXPECT_CALL(mock_sync_reader_, Read(_, _, _)) 142 EXPECT_CALL(mock_sync_reader_, Read(_, _))
143 .WillRepeatedly(DoAll(PopulateBuffer(), 143 .WillRepeatedly(DoAll(PopulateBuffer(),
144 SignalEvent(&read_event_), 144 SignalEvent(&read_event_)));
145 Return(params_.frames_per_buffer())));
146 controller_->Play(); 145 controller_->Play();
147 } 146 }
148 147
149 void Pause() { 148 void Pause() {
150 // Expect the event handler to receive one OnPaused() call. 149 // Expect the event handler to receive one OnPaused() call.
151 EXPECT_CALL(mock_event_handler_, OnPaused()) 150 EXPECT_CALL(mock_event_handler_, OnPaused())
152 .WillOnce(SignalEvent(&pause_event_)); 151 .WillOnce(SignalEvent(&pause_event_));
153 152
154 controller_->Pause(); 153 controller_->Pause();
155 } 154 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 367
369 TEST_F(AudioOutputControllerTest, DivertRevertClose) { 368 TEST_F(AudioOutputControllerTest, DivertRevertClose) {
370 Create(kSamplesPerPacket); 369 Create(kSamplesPerPacket);
371 WaitForCreate(); 370 WaitForCreate();
372 DivertNeverPlaying(); 371 DivertNeverPlaying();
373 RevertWasNotPlaying(); 372 RevertWasNotPlaying();
374 Close(); 373 Close();
375 } 374 }
376 375
377 } // namespace media 376 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698