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

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

Issue 9692038: stopping the audio thread before destroying the AudioManager<Platform> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and fixed the speech recognition unittest Created 8 years, 9 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) 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 "media/audio/fake_audio_output_stream.h" 5 #include "media/audio/fake_audio_output_stream.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/audio/audio_manager_base.h"
9 10
10 bool FakeAudioOutputStream::has_created_fake_stream_ = false; 11 FakeAudioOutputStream* FakeAudioOutputStream::current_fake_stream_ = NULL;
11 FakeAudioOutputStream* FakeAudioOutputStream::last_fake_stream_ = NULL;
12 12
13 // static 13 // static
14 AudioOutputStream* FakeAudioOutputStream::MakeFakeStream( 14 AudioOutputStream* FakeAudioOutputStream::MakeFakeStream(
15 AudioManagerBase* manager,
15 const AudioParameters& params) { 16 const AudioParameters& params) {
16 if (!has_created_fake_stream_) 17 FakeAudioOutputStream* new_stream = new FakeAudioOutputStream(manager,
17 base::AtExitManager::RegisterCallback(&DestroyLastFakeStream, NULL); 18 params);
18 has_created_fake_stream_ = true; 19 DCHECK(current_fake_stream_ == NULL);
19 20 current_fake_stream_ = new_stream;
20 FakeAudioOutputStream* new_stream = new FakeAudioOutputStream(params);
21
22 if (last_fake_stream_) {
23 DCHECK(last_fake_stream_->closed_);
24 delete last_fake_stream_;
25 }
26 last_fake_stream_ = new_stream;
27
28 return new_stream; 21 return new_stream;
29 } 22 }
30 23
31 // static
32 FakeAudioOutputStream* FakeAudioOutputStream::GetLastFakeStream() {
33 return last_fake_stream_;
34 }
35
36 bool FakeAudioOutputStream::Open() { 24 bool FakeAudioOutputStream::Open() {
37 if (packet_size_ < sizeof(int16)) 25 if (packet_size_ < sizeof(int16))
38 return false; 26 return false;
39 buffer_.reset(new uint8[packet_size_]); 27 buffer_.reset(new uint8[packet_size_]);
40 return true; 28 return true;
41 } 29 }
42 30
31 // static
32 FakeAudioOutputStream* FakeAudioOutputStream::GetCurrentFakeStream() {
33 return current_fake_stream_;
34 }
35
43 void FakeAudioOutputStream::Start(AudioSourceCallback* callback) { 36 void FakeAudioOutputStream::Start(AudioSourceCallback* callback) {
44 callback_ = callback; 37 callback_ = callback;
45 memset(buffer_.get(), 0, packet_size_); 38 memset(buffer_.get(), 0, packet_size_);
46 callback_->OnMoreData(this, buffer_.get(), packet_size_, 39 callback_->OnMoreData(this, buffer_.get(), packet_size_,
47 AudioBuffersState(0, 0)); 40 AudioBuffersState(0, 0));
48 } 41 }
49 42
50 void FakeAudioOutputStream::Stop() { 43 void FakeAudioOutputStream::Stop() {
51 callback_ = NULL; 44 callback_ = NULL;
52 } 45 }
53 46
54 void FakeAudioOutputStream::SetVolume(double volume) { 47 void FakeAudioOutputStream::SetVolume(double volume) {
55 volume_ = volume; 48 volume_ = volume;
56 } 49 }
57 50
58 void FakeAudioOutputStream::GetVolume(double* volume) { 51 void FakeAudioOutputStream::GetVolume(double* volume) {
59 *volume = volume_; 52 *volume = volume_;
60 } 53 }
61 54
62 void FakeAudioOutputStream::Close() { 55 void FakeAudioOutputStream::Close() {
63 closed_ = true; 56 closed_ = true;
57 audio_manager_->ReleaseOutputStream(this);
64 } 58 }
65 59
66 FakeAudioOutputStream::FakeAudioOutputStream(const AudioParameters& params) 60 FakeAudioOutputStream::FakeAudioOutputStream(AudioManagerBase* manager,
67 : volume_(0), 61 const AudioParameters& params)
62 : audio_manager_(manager),
63 volume_(0),
68 callback_(NULL), 64 callback_(NULL),
69 packet_size_(params.GetPacketSize()), 65 packet_size_(params.GetPacketSize()),
70 closed_(false) { 66 closed_(false) {
71 } 67 }
72 68
73 FakeAudioOutputStream::~FakeAudioOutputStream() {} 69 FakeAudioOutputStream::~FakeAudioOutputStream() {
74 70 if (current_fake_stream_ == this)
75 // static 71 current_fake_stream_ = NULL;
76 void FakeAudioOutputStream::DestroyLastFakeStream(void* param) {
77 if (last_fake_stream_) {
78 DCHECK(last_fake_stream_->closed_);
79 delete last_fake_stream_;
80 }
81 } 72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698