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

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

Issue 3185022: Share one thread between all AudioOutputControllers instead of creating one per stream. (Closed)
Patch Set: - Created 10 years, 4 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
« no previous file with comments | « media/audio/fake_audio_output_stream.h ('k') | media/audio/linux/alsa_output.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9
9 bool FakeAudioOutputStream::has_created_fake_stream_ = false; 10 bool FakeAudioOutputStream::has_created_fake_stream_ = false;
10 FakeAudioOutputStream* FakeAudioOutputStream::last_fake_stream_ = NULL; 11 FakeAudioOutputStream* FakeAudioOutputStream::last_fake_stream_ = NULL;
11 12
12 // static 13 // static
13 AudioOutputStream* FakeAudioOutputStream::MakeFakeStream() { 14 AudioOutputStream* FakeAudioOutputStream::MakeFakeStream() {
14 if (!has_created_fake_stream_) 15 if (!has_created_fake_stream_)
15 base::AtExitManager::RegisterCallback(&DestroyLastFakeStream, NULL); 16 base::AtExitManager::RegisterCallback(&DestroyLastFakeStream, NULL);
16 has_created_fake_stream_ = true; 17 has_created_fake_stream_ = true;
17 18
18 return new FakeAudioOutputStream(); 19 FakeAudioOutputStream* new_stream = new FakeAudioOutputStream();
20
21 if (last_fake_stream_) {
22 DCHECK(last_fake_stream_->closed_);
23 delete last_fake_stream_;
24 }
25 last_fake_stream_ = new_stream;
26
27 return new_stream;
19 } 28 }
20 29
21 // static 30 // static
22 FakeAudioOutputStream* FakeAudioOutputStream::GetLastFakeStream() { 31 FakeAudioOutputStream* FakeAudioOutputStream::GetLastFakeStream() {
23 return last_fake_stream_; 32 return last_fake_stream_;
24 } 33 }
25 34
26 bool FakeAudioOutputStream::Open(uint32 packet_size) { 35 bool FakeAudioOutputStream::Open(uint32 packet_size) {
27 if (packet_size < sizeof(int16)) 36 if (packet_size < sizeof(int16))
28 return false; 37 return false;
(...skipping 19 matching lines...) Expand all
48 *volume = volume_; 57 *volume = volume_;
49 } 58 }
50 59
51 void FakeAudioOutputStream::Close() { 60 void FakeAudioOutputStream::Close() {
52 // Calls |callback_| only if it is valid. We don't have |callback_| if 61 // Calls |callback_| only if it is valid. We don't have |callback_| if
53 // we have not yet started. 62 // we have not yet started.
54 if (callback_) { 63 if (callback_) {
55 callback_->OnClose(this); 64 callback_->OnClose(this);
56 callback_ = NULL; 65 callback_ = NULL;
57 } 66 }
58 67 closed_ = true;
59 if (last_fake_stream_)
60 delete last_fake_stream_;
61 last_fake_stream_ = this;
62 } 68 }
63 69
64 FakeAudioOutputStream::FakeAudioOutputStream() 70 FakeAudioOutputStream::FakeAudioOutputStream()
65 : volume_(0), 71 : volume_(0),
66 callback_(NULL), 72 callback_(NULL),
67 packet_size_(0) { 73 packet_size_(0),
74 closed_(false) {
68 } 75 }
69 76
70 // static 77 // static
71 void FakeAudioOutputStream::DestroyLastFakeStream(void* param) { 78 void FakeAudioOutputStream::DestroyLastFakeStream(void* param) {
72 if (last_fake_stream_) 79 if (last_fake_stream_) {
80 DCHECK(last_fake_stream_->closed_);
73 delete last_fake_stream_; 81 delete last_fake_stream_;
82 }
74 } 83 }
OLDNEW
« no previous file with comments | « media/audio/fake_audio_output_stream.h ('k') | media/audio/linux/alsa_output.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698