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

Side by Side Diff: media/audio/sounds/audio_stream_handler.cc

Issue 102693003: Fix flaky AudioStreamHandler initialization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | « no previous file | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "media/audio/sounds/audio_stream_handler.h" 5 #include "media/audio/sounds/audio_stream_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "media/audio/audio_manager.h" 11 #include "media/audio/audio_manager.h"
12 #include "media/audio/audio_manager_base.h" 12 #include "media/audio/audio_manager_base.h"
13 #include "media/base/channel_layout.h" 13 #include "media/base/channel_layout.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 namespace { 17 namespace {
18 18
19 // Volume percent. 19 // Volume percent.
20 const double kOutputVolumePercent = 0.8; 20 const double kOutputVolumePercent = 0.8;
21 21
22 // The number of frames each OnMoreData() call will request.
23 const int kDefaultFrameCount = 1024;
24
22 AudioStreamHandler::TestObserver* g_observer_for_testing = NULL; 25 AudioStreamHandler::TestObserver* g_observer_for_testing = NULL;
23 AudioOutputStream::AudioSourceCallback* g_audio_source_for_testing = NULL; 26 AudioOutputStream::AudioSourceCallback* g_audio_source_for_testing = NULL;
24 27
25 } // namespace 28 } // namespace
26 29
27 class AudioStreamHandler::AudioStreamContainer 30 class AudioStreamHandler::AudioStreamContainer
28 : public AudioOutputStream::AudioSourceCallback { 31 : public AudioOutputStream::AudioSourceCallback {
29 public: 32 public:
30 AudioStreamContainer(const WavAudioHandler& wav_audio, 33 AudioStreamContainer(const WavAudioHandler& wav_audio,
31 const AudioParameters& params) 34 const AudioParameters& params)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 }; 120 };
118 121
119 AudioStreamHandler::AudioStreamHandler(const base::StringPiece& wav_data) 122 AudioStreamHandler::AudioStreamHandler(const base::StringPiece& wav_data)
120 : wav_audio_(wav_data), 123 : wav_audio_(wav_data),
121 initialized_(false) { 124 initialized_(false) {
122 AudioManager* manager = AudioManager::Get(); 125 AudioManager* manager = AudioManager::Get();
123 if (!manager) { 126 if (!manager) {
124 LOG(ERROR) << "Can't get access to audio manager."; 127 LOG(ERROR) << "Can't get access to audio manager.";
125 return; 128 return;
126 } 129 }
127 AudioParameters params( 130 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY,
128 AudioParameters::AUDIO_PCM_LOW_LATENCY, 131 GuessChannelLayout(wav_audio_.num_channels()),
129 GuessChannelLayout(wav_audio_.num_channels()), 132 wav_audio_.sample_rate(),
130 wav_audio_.sample_rate(), 133 wav_audio_.bits_per_sample(),
131 wav_audio_.bits_per_sample(), 134 kDefaultFrameCount);
132 manager->GetDefaultOutputStreamParameters().frames_per_buffer());
133 if (!params.IsValid()) { 135 if (!params.IsValid()) {
134 LOG(ERROR) << "Audio params are invalid."; 136 LOG(ERROR) << "Audio params are invalid.";
135 return; 137 return;
136 } 138 }
137 stream_.reset(new AudioStreamContainer(wav_audio_, params)); 139 stream_.reset(new AudioStreamContainer(wav_audio_, params));
138 initialized_ = true; 140 initialized_ = true;
139 } 141 }
140 142
141 AudioStreamHandler::~AudioStreamHandler() { 143 AudioStreamHandler::~AudioStreamHandler() {
142 DCHECK(CalledOnValidThread()); 144 DCHECK(CalledOnValidThread());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 g_observer_for_testing = observer; 179 g_observer_for_testing = observer;
178 } 180 }
179 181
180 // static 182 // static
181 void AudioStreamHandler::SetAudioSourceForTesting( 183 void AudioStreamHandler::SetAudioSourceForTesting(
182 AudioOutputStream::AudioSourceCallback* source) { 184 AudioOutputStream::AudioSourceCallback* source) {
183 g_audio_source_for_testing = source; 185 g_audio_source_for_testing = source;
184 } 186 }
185 187
186 } // namespace media 188 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698