| OLD | NEW |
| 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_input_stream.h" | 5 #include "media/audio/fake_audio_input_stream.h" |
| 6 | 6 |
| 7 using base::Time; | 7 using base::Time; |
| 8 using base::TimeDelta; | 8 using base::TimeDelta; |
| 9 | 9 |
| 10 AudioInputStream* FakeAudioInputStream::MakeFakeStream(AudioParameters params, | 10 AudioInputStream* FakeAudioInputStream::MakeFakeStream(AudioParameters params) { |
| 11 int samples_per_packet) { | 11 return new FakeAudioInputStream(params); |
| 12 return new FakeAudioInputStream(params, samples_per_packet); | |
| 13 } | 12 } |
| 14 | 13 |
| 15 FakeAudioInputStream::FakeAudioInputStream(AudioParameters params, | 14 FakeAudioInputStream::FakeAudioInputStream(AudioParameters params) |
| 16 int samples_per_packet) | |
| 17 : callback_(NULL), | 15 : callback_(NULL), |
| 18 buffer_size_((params.channels * params.bits_per_sample * | 16 buffer_size_((params.channels * params.bits_per_sample * |
| 19 samples_per_packet) / 8), | 17 params.samples_per_packet) / 8), |
| 20 thread_("FakeAudioRecordingThread"), | 18 thread_("FakeAudioRecordingThread"), |
| 21 callback_interval_ms_((samples_per_packet * 1000) / params.sample_rate) { | 19 callback_interval_ms_((params.samples_per_packet * 1000) / |
| 20 params.sample_rate) { |
| 22 // This object is ref counted (so that it can be used with Thread, PostTask) | 21 // This object is ref counted (so that it can be used with Thread, PostTask) |
| 23 // but the caller expects a plain pointer. So we take a reference here and | 22 // but the caller expects a plain pointer. So we take a reference here and |
| 24 // will Release() ourselves in Close(). | 23 // will Release() ourselves in Close(). |
| 25 AddRef(); | 24 AddRef(); |
| 26 } | 25 } |
| 27 | 26 |
| 28 FakeAudioInputStream::~FakeAudioInputStream() {} | 27 FakeAudioInputStream::~FakeAudioInputStream() {} |
| 29 | 28 |
| 30 bool FakeAudioInputStream::Open() { | 29 bool FakeAudioInputStream::Open() { |
| 31 buffer_.reset(new uint8[buffer_size_]); | 30 buffer_.reset(new uint8[buffer_size_]); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 thread_.Stop(); | 67 thread_.Stop(); |
| 69 } | 68 } |
| 70 | 69 |
| 71 void FakeAudioInputStream::Close() { | 70 void FakeAudioInputStream::Close() { |
| 72 if (callback_) { | 71 if (callback_) { |
| 73 callback_->OnClose(this); | 72 callback_->OnClose(this); |
| 74 callback_ = NULL; | 73 callback_ = NULL; |
| 75 } | 74 } |
| 76 Release(); // Destoys this object. | 75 Release(); // Destoys this object. |
| 77 } | 76 } |
| OLD | NEW |