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

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: used the correct way to delete the fake streams & addressed Tommi's comment 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 9 #include "media/audio/audio_manager_base.h"
10 bool FakeAudioOutputStream::has_created_fake_stream_ = false;
11 FakeAudioOutputStream* FakeAudioOutputStream::last_fake_stream_ = NULL;
12 10
13 // static 11 // static
14 AudioOutputStream* FakeAudioOutputStream::MakeFakeStream( 12 AudioOutputStream* FakeAudioOutputStream::MakeFakeStream(
13 AudioManagerBase* manager,
15 const AudioParameters& params) { 14 const AudioParameters& params) {
16 if (!has_created_fake_stream_) 15 FakeAudioOutputStream* new_stream = new FakeAudioOutputStream(manager,
17 base::AtExitManager::RegisterCallback(&DestroyLastFakeStream, NULL); 16 params);
18 has_created_fake_stream_ = true;
19
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; 17 return new_stream;
29 } 18 }
30 19
31 // static
32 FakeAudioOutputStream* FakeAudioOutputStream::GetLastFakeStream() {
33 return last_fake_stream_;
34 }
35
36 bool FakeAudioOutputStream::Open() { 20 bool FakeAudioOutputStream::Open() {
37 if (packet_size_ < sizeof(int16)) 21 if (packet_size_ < sizeof(int16))
38 return false; 22 return false;
39 buffer_.reset(new uint8[packet_size_]); 23 buffer_.reset(new uint8[packet_size_]);
40 return true; 24 return true;
41 } 25 }
42 26
43 void FakeAudioOutputStream::Start(AudioSourceCallback* callback) { 27 void FakeAudioOutputStream::Start(AudioSourceCallback* callback) {
44 callback_ = callback; 28 callback_ = callback;
45 memset(buffer_.get(), 0, packet_size_); 29 memset(buffer_.get(), 0, packet_size_);
46 callback_->OnMoreData(this, buffer_.get(), packet_size_, 30 callback_->OnMoreData(this, buffer_.get(), packet_size_,
47 AudioBuffersState(0, 0)); 31 AudioBuffersState(0, 0));
48 } 32 }
49 33
50 void FakeAudioOutputStream::Stop() { 34 void FakeAudioOutputStream::Stop() {
51 callback_ = NULL; 35 callback_ = NULL;
52 } 36 }
53 37
54 void FakeAudioOutputStream::SetVolume(double volume) { 38 void FakeAudioOutputStream::SetVolume(double volume) {
55 volume_ = volume; 39 volume_ = volume;
56 } 40 }
57 41
58 void FakeAudioOutputStream::GetVolume(double* volume) { 42 void FakeAudioOutputStream::GetVolume(double* volume) {
59 *volume = volume_; 43 *volume = volume_;
60 } 44 }
61 45
62 void FakeAudioOutputStream::Close() { 46 void FakeAudioOutputStream::Close() {
63 closed_ = true; 47 closed_ = true;
48 audio_manager_->ReleaseOutputStream(this);
64 } 49 }
65 50
66 FakeAudioOutputStream::FakeAudioOutputStream(const AudioParameters& params) 51 FakeAudioOutputStream::FakeAudioOutputStream(AudioManagerBase* manager,
67 : volume_(0), 52 const AudioParameters& params)
53 : audio_manager_(manager),
54 volume_(0),
68 callback_(NULL), 55 callback_(NULL),
69 packet_size_(params.GetPacketSize()), 56 packet_size_(params.GetPacketSize()),
70 closed_(false) { 57 closed_(false) {
71 } 58 }
72 59
73 FakeAudioOutputStream::~FakeAudioOutputStream() {} 60 FakeAudioOutputStream::~FakeAudioOutputStream() {}
74
75 // static
76 void FakeAudioOutputStream::DestroyLastFakeStream(void* param) {
77 if (last_fake_stream_) {
78 DCHECK(last_fake_stream_->closed_);
79 delete last_fake_stream_;
80 }
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698