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

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

Issue 9655018: Make AudioParameters a class instead of a struct (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copyright years 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
« no previous file with comments | « media/audio/fake_audio_output_stream.h ('k') | media/audio/linux/alsa_input.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "media/audio/audio_manager_base.h"
10 10
11 FakeAudioOutputStream* FakeAudioOutputStream::current_fake_stream_ = NULL; 11 FakeAudioOutputStream* FakeAudioOutputStream::current_fake_stream_ = NULL;
12 12
13 // static 13 // static
14 AudioOutputStream* FakeAudioOutputStream::MakeFakeStream( 14 AudioOutputStream* FakeAudioOutputStream::MakeFakeStream(
15 AudioManagerBase* manager, 15 AudioManagerBase* manager,
16 const AudioParameters& params) { 16 const AudioParameters& params) {
17 FakeAudioOutputStream* new_stream = new FakeAudioOutputStream(manager, 17 FakeAudioOutputStream* new_stream = new FakeAudioOutputStream(manager,
18 params); 18 params);
19 DCHECK(current_fake_stream_ == NULL); 19 DCHECK(current_fake_stream_ == NULL);
20 current_fake_stream_ = new_stream; 20 current_fake_stream_ = new_stream;
21 return new_stream; 21 return new_stream;
22 } 22 }
23 23
24 bool FakeAudioOutputStream::Open() { 24 bool FakeAudioOutputStream::Open() {
25 if (packet_size_ < sizeof(int16)) 25 if (bytes_per_buffer_ < sizeof(int16))
26 return false; 26 return false;
27 buffer_.reset(new uint8[packet_size_]); 27 buffer_.reset(new uint8[bytes_per_buffer_]);
28 return true; 28 return true;
29 } 29 }
30 30
31 // static 31 // static
32 FakeAudioOutputStream* FakeAudioOutputStream::GetCurrentFakeStream() { 32 FakeAudioOutputStream* FakeAudioOutputStream::GetCurrentFakeStream() {
33 return current_fake_stream_; 33 return current_fake_stream_;
34 } 34 }
35 35
36 void FakeAudioOutputStream::Start(AudioSourceCallback* callback) { 36 void FakeAudioOutputStream::Start(AudioSourceCallback* callback) {
37 callback_ = callback; 37 callback_ = callback;
38 memset(buffer_.get(), 0, packet_size_); 38 memset(buffer_.get(), 0, bytes_per_buffer_);
39 callback_->OnMoreData(this, buffer_.get(), packet_size_, 39 callback_->OnMoreData(this, buffer_.get(), bytes_per_buffer_,
40 AudioBuffersState(0, 0)); 40 AudioBuffersState(0, 0));
41 } 41 }
42 42
43 void FakeAudioOutputStream::Stop() { 43 void FakeAudioOutputStream::Stop() {
44 callback_ = NULL; 44 callback_ = NULL;
45 } 45 }
46 46
47 void FakeAudioOutputStream::SetVolume(double volume) { 47 void FakeAudioOutputStream::SetVolume(double volume) {
48 volume_ = volume; 48 volume_ = volume;
49 } 49 }
50 50
51 void FakeAudioOutputStream::GetVolume(double* volume) { 51 void FakeAudioOutputStream::GetVolume(double* volume) {
52 *volume = volume_; 52 *volume = volume_;
53 } 53 }
54 54
55 void FakeAudioOutputStream::Close() { 55 void FakeAudioOutputStream::Close() {
56 closed_ = true; 56 closed_ = true;
57 audio_manager_->ReleaseOutputStream(this); 57 audio_manager_->ReleaseOutputStream(this);
58 } 58 }
59 59
60 FakeAudioOutputStream::FakeAudioOutputStream(AudioManagerBase* manager, 60 FakeAudioOutputStream::FakeAudioOutputStream(AudioManagerBase* manager,
61 const AudioParameters& params) 61 const AudioParameters& params)
62 : audio_manager_(manager), 62 : audio_manager_(manager),
63 volume_(0), 63 volume_(0),
64 callback_(NULL), 64 callback_(NULL),
65 packet_size_(params.GetPacketSize()), 65 bytes_per_buffer_(params.GetBytesPerBuffer()),
66 closed_(false) { 66 closed_(false) {
67 } 67 }
68 68
69 FakeAudioOutputStream::~FakeAudioOutputStream() { 69 FakeAudioOutputStream::~FakeAudioOutputStream() {
70 if (current_fake_stream_ == this) 70 if (current_fake_stream_ == this)
71 current_fake_stream_ = NULL; 71 current_fake_stream_ = NULL;
72 } 72 }
OLDNEW
« no previous file with comments | « media/audio/fake_audio_output_stream.h ('k') | media/audio/linux/alsa_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698