| Index: media/audio/sounds/audio_stream_handler.cc
|
| diff --git a/media/audio/sounds/audio_stream_handler.cc b/media/audio/sounds/audio_stream_handler.cc
|
| index 5f175ea75ad97b1f073d67e76c1c7c20bb02e30e..c3a26aee0e9ceacad2156a0162214a8e0ae11cfc 100644
|
| --- a/media/audio/sounds/audio_stream_handler.cc
|
| +++ b/media/audio/sounds/audio_stream_handler.cc
|
| @@ -36,12 +36,14 @@ AudioOutputStream::AudioSourceCallback* g_audio_source_for_testing = NULL;
|
| class AudioStreamHandler::AudioStreamContainer
|
| : public AudioOutputStream::AudioSourceCallback {
|
| public:
|
| - explicit AudioStreamContainer(const WavAudioHandler& wav_audio)
|
| + explicit AudioStreamContainer(scoped_ptr<WavAudioHandler> wav_audio)
|
| : started_(false),
|
| stream_(NULL),
|
| cursor_(0),
|
| delayed_stop_posted_(false),
|
| - wav_audio_(wav_audio) {}
|
| + wav_audio_(wav_audio.Pass()) {
|
| + DCHECK(wav_audio_);
|
| + }
|
|
|
| ~AudioStreamContainer() override {
|
| DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread());
|
| @@ -53,8 +55,9 @@ class AudioStreamHandler::AudioStreamContainer
|
| if (!stream_) {
|
| const AudioParameters params(
|
| AudioParameters::AUDIO_PCM_LOW_LATENCY,
|
| - GuessChannelLayout(wav_audio_.num_channels()),
|
| - wav_audio_.sample_rate(), wav_audio_.bits_per_sample(),
|
| + GuessChannelLayout(wav_audio_->num_channels()),
|
| + wav_audio_->sample_rate(),
|
| + wav_audio_->bits_per_sample(),
|
| kDefaultFrameCount);
|
| stream_ = AudioManager::Get()->MakeAudioOutputStreamProxy(params,
|
| std::string());
|
| @@ -73,7 +76,7 @@ class AudioStreamHandler::AudioStreamContainer
|
| base::Unretained(this)));
|
|
|
| if (started_) {
|
| - if (wav_audio_.AtEnd(cursor_))
|
| + if (wav_audio_->AtEnd(cursor_))
|
| cursor_ = 0;
|
| return;
|
| }
|
| @@ -107,8 +110,8 @@ class AudioStreamHandler::AudioStreamContainer
|
| base::AutoLock al(state_lock_);
|
| size_t bytes_written = 0;
|
|
|
| - if (wav_audio_.AtEnd(cursor_) ||
|
| - !wav_audio_.CopyTo(dest, cursor_, &bytes_written)) {
|
| + if (wav_audio_->AtEnd(cursor_) ||
|
| + !wav_audio_->CopyTo(dest, cursor_, &bytes_written)) {
|
| if (delayed_stop_posted_)
|
| return 0;
|
| delayed_stop_posted_ = true;
|
| @@ -150,29 +153,43 @@ class AudioStreamHandler::AudioStreamContainer
|
| base::Lock state_lock_;
|
| size_t cursor_;
|
| bool delayed_stop_posted_;
|
| - const WavAudioHandler wav_audio_;
|
| + scoped_ptr<WavAudioHandler> wav_audio_;
|
| base::CancelableClosure stop_closure_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(AudioStreamContainer);
|
| };
|
|
|
| AudioStreamHandler::AudioStreamHandler(const base::StringPiece& wav_data)
|
| - : wav_audio_(wav_data),
|
| - initialized_(false) {
|
| + : initialized_(false) {
|
| AudioManager* manager = AudioManager::Get();
|
| if (!manager) {
|
| LOG(ERROR) << "Can't get access to audio manager.";
|
| return;
|
| }
|
| - const AudioParameters params(
|
| - AudioParameters::AUDIO_PCM_LOW_LATENCY,
|
| - GuessChannelLayout(wav_audio_.num_channels()), wav_audio_.sample_rate(),
|
| - wav_audio_.bits_per_sample(), kDefaultFrameCount);
|
| +
|
| + wav_audio_ = WavAudioHandler::Create(wav_data);
|
| + if (!wav_audio_) {
|
| + LOG(ERROR) << "wav_audio handler is not valid";
|
| + return;
|
| + }
|
| +
|
| + const AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY,
|
| + GuessChannelLayout(wav_audio_->num_channels()),
|
| + wav_audio_->sample_rate(),
|
| + wav_audio_->bits_per_sample(),
|
| + kDefaultFrameCount);
|
| if (!params.IsValid()) {
|
| LOG(ERROR) << "Audio params are invalid.";
|
| return;
|
| }
|
| - stream_.reset(new AudioStreamContainer(wav_audio_));
|
| +
|
| + // Create an identical WavAudioHandler and pass it to AudioStreamContainer.
|
| + // This copy will be used on the AudioManager thread, and |wav_audio_| can
|
| + // safely be accessed on this thread via wav_audio_handler().
|
| + // TODO(slan): Find a way to use just one copy. This approach is silly.
|
| + auto wav_audio_copy = WavAudioHandler::Create(wav_data);
|
| + DCHECK(wav_audio_copy);
|
| + stream_.reset(new AudioStreamContainer(wav_audio_copy.Pass()));
|
| initialized_ = true;
|
| }
|
|
|
|
|