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

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: fix Android compiling problem 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 current_fake_stream_ = new_stream;
tommi (sloooow) - chröme 2012/03/13 16:20:09 Add this first: DCHECK(current_fake_stream_ == NUL
no longer working on chromium 2012/03/13 16:38:08 It is a bit odd that we only allow one FakeOutputS
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; 20 return new_stream;
29 } 21 }
30 22
31 // static
32 FakeAudioOutputStream* FakeAudioOutputStream::GetLastFakeStream() {
33 return last_fake_stream_;
34 }
35
36 bool FakeAudioOutputStream::Open() { 23 bool FakeAudioOutputStream::Open() {
37 if (packet_size_ < sizeof(int16)) 24 if (packet_size_ < sizeof(int16))
38 return false; 25 return false;
39 buffer_.reset(new uint8[packet_size_]); 26 buffer_.reset(new uint8[packet_size_]);
40 return true; 27 return true;
41 } 28 }
42 29
30 // static
31 FakeAudioOutputStream* FakeAudioOutputStream::GetCurrentFakeStream() {
32 return current_fake_stream_;
33 }
34
43 void FakeAudioOutputStream::Start(AudioSourceCallback* callback) { 35 void FakeAudioOutputStream::Start(AudioSourceCallback* callback) {
44 callback_ = callback; 36 callback_ = callback;
45 memset(buffer_.get(), 0, packet_size_); 37 memset(buffer_.get(), 0, packet_size_);
46 callback_->OnMoreData(this, buffer_.get(), packet_size_, 38 callback_->OnMoreData(this, buffer_.get(), packet_size_,
47 AudioBuffersState(0, 0)); 39 AudioBuffersState(0, 0));
48 } 40 }
49 41
50 void FakeAudioOutputStream::Stop() { 42 void FakeAudioOutputStream::Stop() {
51 callback_ = NULL; 43 callback_ = NULL;
52 } 44 }
53 45
54 void FakeAudioOutputStream::SetVolume(double volume) { 46 void FakeAudioOutputStream::SetVolume(double volume) {
55 volume_ = volume; 47 volume_ = volume;
56 } 48 }
57 49
58 void FakeAudioOutputStream::GetVolume(double* volume) { 50 void FakeAudioOutputStream::GetVolume(double* volume) {
59 *volume = volume_; 51 *volume = volume_;
60 } 52 }
61 53
62 void FakeAudioOutputStream::Close() { 54 void FakeAudioOutputStream::Close() {
63 closed_ = true; 55 closed_ = true;
56 current_fake_stream_ = NULL;
tommi (sloooow) - chröme 2012/03/13 16:20:09 remove... see comment in destructor below.
no longer working on chromium 2012/03/13 16:38:08 Done.
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() {}
tommi (sloooow) - chröme 2012/03/13 16:20:09 add: if (current_fake_stream_ == this) current_
no longer working on chromium 2012/03/13 16:38:08 Done.
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