Revert "Omit calls to set composing region when pasting image."
[chromium-blink-merge.git] / media / audio / fake_audio_input_stream.cc
blob458118da01c3cc54e4476ec5b1a5bcc3e8054a6e
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
3 // found in the LICENSE file.
5 #include "media/audio/fake_audio_input_stream.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/command_line.h"
10 #include "base/files/file_path.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/time/time.h"
13 #include "media/audio/audio_manager_base.h"
14 #include "media/audio/simple_sources.h"
15 #include "media/base/audio_bus.h"
16 #include "media/base/media_switches.h"
18 namespace media {
20 AudioInputStream* FakeAudioInputStream::MakeFakeStream(
21 AudioManagerBase* manager,
22 const AudioParameters& params) {
23 return new FakeAudioInputStream(manager, params);
26 FakeAudioInputStream::FakeAudioInputStream(AudioManagerBase* manager,
27 const AudioParameters& params)
28 : audio_manager_(manager),
29 callback_(NULL),
30 fake_audio_worker_(manager->GetWorkerTaskRunner(), params),
31 params_(params),
32 audio_bus_(AudioBus::Create(params)) {
33 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
36 FakeAudioInputStream::~FakeAudioInputStream() {
37 DCHECK(!callback_);
40 bool FakeAudioInputStream::Open() {
41 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
42 audio_bus_->Zero();
44 return true;
47 void FakeAudioInputStream::Start(AudioInputCallback* callback) {
48 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
49 callback_ = callback;
50 fake_audio_worker_.Start(base::Bind(
51 &FakeAudioInputStream::ReadAudioFromSource, base::Unretained(this)));
54 void FakeAudioInputStream::Stop() {
55 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
56 fake_audio_worker_.Stop();
57 callback_ = NULL;
60 void FakeAudioInputStream::Close() {
61 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
62 DCHECK(!callback_);
63 audio_manager_->ReleaseInputStream(this);
66 double FakeAudioInputStream::GetMaxVolume() {
67 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
68 return 1.0;
71 void FakeAudioInputStream::SetVolume(double volume) {
72 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
75 double FakeAudioInputStream::GetVolume() {
76 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
77 return 1.0;
80 bool FakeAudioInputStream::IsMuted() {
81 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
82 return false;
85 bool FakeAudioInputStream::SetAutomaticGainControl(bool enabled) {
86 return false;
89 bool FakeAudioInputStream::GetAutomaticGainControl() {
90 return false;
93 void FakeAudioInputStream::ReadAudioFromSource() {
94 DCHECK(audio_manager_->GetWorkerTaskRunner()->BelongsToCurrentThread());
95 DCHECK(callback_);
97 if (!audio_source_)
98 audio_source_ = ChooseSource();
100 const int kNoDelay = 0;
101 audio_source_->OnMoreData(audio_bus_.get(), kNoDelay);
102 callback_->OnData(this, audio_bus_.get(), 0, 1.0);
105 using AudioSourceCallback = AudioOutputStream::AudioSourceCallback;
106 scoped_ptr<AudioSourceCallback> FakeAudioInputStream::ChooseSource() {
107 DCHECK(audio_manager_->GetWorkerTaskRunner()->BelongsToCurrentThread());
109 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
110 switches::kUseFileForFakeAudioCapture)) {
111 base::FilePath path_to_wav_file =
112 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
113 switches::kUseFileForFakeAudioCapture);
114 CHECK(!path_to_wav_file.empty())
115 << "You must pass the file to use as argument to --"
116 << switches::kUseFileForFakeAudioCapture << ".";
118 return make_scoped_ptr(new FileSource(params_, path_to_wav_file));
120 return make_scoped_ptr(new BeepingSource(params_));
123 void FakeAudioInputStream::BeepOnce() {
124 BeepingSource::BeepOnce();
127 } // namespace media