OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/at_exit.h" |
| 6 #include "media/audio/fake_audio_output_stream.h" |
| 7 |
| 8 bool FakeAudioOutputStream::has_created_fake_stream_ = false; |
| 9 FakeAudioOutputStream* FakeAudioOutputStream::last_fake_stream_ = NULL; |
| 10 |
| 11 // static |
| 12 AudioOutputStream* FakeAudioOutputStream::MakeFakeStream() { |
| 13 if (!has_created_fake_stream_) |
| 14 base::AtExitManager::RegisterCallback(&DestroyLastFakeStream, NULL); |
| 15 has_created_fake_stream_ = true; |
| 16 |
| 17 return new FakeAudioOutputStream(); |
| 18 } |
| 19 |
| 20 // static |
| 21 FakeAudioOutputStream* FakeAudioOutputStream::GetLastFakeStream() { |
| 22 return last_fake_stream_; |
| 23 } |
| 24 |
| 25 bool FakeAudioOutputStream::Open(size_t packet_size) { |
| 26 if (packet_size < sizeof(int16)) |
| 27 return false; |
| 28 packet_size_ = packet_size; |
| 29 buffer_.reset(new char[packet_size_]); |
| 30 return true; |
| 31 } |
| 32 |
| 33 void FakeAudioOutputStream::Start(AudioSourceCallback* callback) { |
| 34 callback_ = callback; |
| 35 memset(buffer_.get(), 0, packet_size_); |
| 36 callback_->OnMoreData(this, buffer_.get(), packet_size_); |
| 37 } |
| 38 |
| 39 void FakeAudioOutputStream::Stop() { |
| 40 } |
| 41 |
| 42 void FakeAudioOutputStream::SetVolume(double left_level, double right_level) { |
| 43 left_volume_ = left_level; |
| 44 right_volume_ = right_level; |
| 45 } |
| 46 |
| 47 void FakeAudioOutputStream::GetVolume(double* left_level, double* right_level) { |
| 48 *left_level = left_volume_; |
| 49 *right_level = right_volume_; |
| 50 } |
| 51 |
| 52 void FakeAudioOutputStream::Close() { |
| 53 callback_->OnClose(this); |
| 54 callback_ = NULL; |
| 55 |
| 56 if (last_fake_stream_) |
| 57 delete last_fake_stream_; |
| 58 last_fake_stream_ = this; |
| 59 } |
| 60 |
| 61 FakeAudioOutputStream::FakeAudioOutputStream() |
| 62 : left_volume_(0), |
| 63 right_volume_(0), |
| 64 callback_(NULL), |
| 65 packet_size_(0) { |
| 66 } |
| 67 |
| 68 // static |
| 69 void FakeAudioOutputStream::DestroyLastFakeStream(void* param) { |
| 70 if (last_fake_stream_) |
| 71 delete last_fake_stream_; |
| 72 } |
OLD | NEW |