OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/copresence/mediums/audio/audio_player_impl.h" | 5 #include "components/copresence/mediums/audio/audio_player_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 const int kDefaultFrameCount = 1024; | 22 const int kDefaultFrameCount = 1024; |
23 const double kOutputVolumePercent = 1.0f; | 23 const double kOutputVolumePercent = 1.0f; |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 namespace copresence { | 27 namespace copresence { |
28 | 28 |
29 // Public methods. | 29 // Public methods. |
30 | 30 |
31 AudioPlayerImpl::AudioPlayerImpl() | 31 AudioPlayerImpl::AudioPlayerImpl() |
32 : is_playing_(false), stream_(NULL), frame_index_(0) { | 32 : is_playing_(false), stream_(nullptr), frame_index_(0) { |
33 } | 33 } |
34 | 34 |
35 AudioPlayerImpl::~AudioPlayerImpl() { | 35 AudioPlayerImpl::~AudioPlayerImpl() { |
36 } | 36 } |
37 | 37 |
38 void AudioPlayerImpl::Initialize() { | 38 void AudioPlayerImpl::Initialize() { |
39 media::AudioManager::Get()->GetTaskRunner()->PostTask( | 39 media::AudioManager::Get()->GetTaskRunner()->PostTask( |
40 FROM_HERE, | 40 FROM_HERE, |
41 base::Bind(&AudioPlayerImpl::InitializeOnAudioThread, | 41 base::Bind(&AudioPlayerImpl::InitializeOnAudioThread, |
42 base::Unretained(this))); | 42 base::Unretained(this))); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 media::CHANNEL_LAYOUT_MONO, | 80 media::CHANNEL_LAYOUT_MONO, |
81 kDefaultSampleRate, | 81 kDefaultSampleRate, |
82 kDefaultBitsPerSample, | 82 kDefaultBitsPerSample, |
83 kDefaultFrameCount), | 83 kDefaultFrameCount), |
84 std::string()); | 84 std::string()); |
85 | 85 |
86 if (!stream_ || !stream_->Open()) { | 86 if (!stream_ || !stream_->Open()) { |
87 LOG(ERROR) << "Failed to open an output stream."; | 87 LOG(ERROR) << "Failed to open an output stream."; |
88 if (stream_) { | 88 if (stream_) { |
89 stream_->Close(); | 89 stream_->Close(); |
90 stream_ = NULL; | 90 stream_ = nullptr; |
91 } | 91 } |
92 return; | 92 return; |
93 } | 93 } |
94 stream_->SetVolume(kOutputVolumePercent); | 94 stream_->SetVolume(kOutputVolumePercent); |
95 } | 95 } |
96 | 96 |
97 void AudioPlayerImpl::PlayOnAudioThread( | 97 void AudioPlayerImpl::PlayOnAudioThread( |
98 const scoped_refptr<media::AudioBusRefCounted>& samples) { | 98 const scoped_refptr<media::AudioBusRefCounted>& samples) { |
99 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 99 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
100 if (!stream_) | 100 if (!stream_) |
(...skipping 23 matching lines...) Expand all Loading... |
124 } | 124 } |
125 | 125 |
126 void AudioPlayerImpl::StopAndCloseOnAudioThread() { | 126 void AudioPlayerImpl::StopAndCloseOnAudioThread() { |
127 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 127 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
128 if (!stream_) | 128 if (!stream_) |
129 return; | 129 return; |
130 | 130 |
131 if (is_playing_) | 131 if (is_playing_) |
132 stream_->Stop(); | 132 stream_->Stop(); |
133 stream_->Close(); | 133 stream_->Close(); |
134 stream_ = NULL; | 134 stream_ = nullptr; |
135 | 135 |
136 is_playing_ = false; | 136 is_playing_ = false; |
137 } | 137 } |
138 | 138 |
139 void AudioPlayerImpl::FinalizeOnAudioThread() { | 139 void AudioPlayerImpl::FinalizeOnAudioThread() { |
140 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); | 140 DCHECK(media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
141 StopAndCloseOnAudioThread(); | 141 StopAndCloseOnAudioThread(); |
142 delete this; | 142 delete this; |
143 } | 143 } |
144 | 144 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 base::RunLoop rl; | 179 base::RunLoop rl; |
180 media::AudioManager::Get()->GetTaskRunner()->PostTaskAndReply( | 180 media::AudioManager::Get()->GetTaskRunner()->PostTaskAndReply( |
181 FROM_HERE, | 181 FROM_HERE, |
182 base::Bind(base::IgnoreResult(&AudioPlayerImpl::FlushAudioLoopForTesting), | 182 base::Bind(base::IgnoreResult(&AudioPlayerImpl::FlushAudioLoopForTesting), |
183 base::Unretained(this)), | 183 base::Unretained(this)), |
184 rl.QuitClosure()); | 184 rl.QuitClosure()); |
185 rl.Run(); | 185 rl.Run(); |
186 } | 186 } |
187 | 187 |
188 } // namespace copresence | 188 } // namespace copresence |
OLD | NEW |