1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
media / audio / fake_audio_output_stream.cc [blame]
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/audio/fake_audio_output_stream.h"
#include "base/check.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "media/audio/audio_manager_base.h"
namespace media {
// static
AudioOutputStream* FakeAudioOutputStream::MakeFakeStream(
AudioManagerBase* manager, const AudioParameters& params) {
return new FakeAudioOutputStream(manager, params);
}
FakeAudioOutputStream::FakeAudioOutputStream(AudioManagerBase* manager,
const AudioParameters& params)
: audio_manager_(manager),
fixed_data_delay_(FakeAudioWorker::ComputeFakeOutputDelay(params)),
callback_(nullptr),
fake_worker_(manager->GetWorkerTaskRunner(), params),
audio_bus_(AudioBus::Create(params)) {}
FakeAudioOutputStream::~FakeAudioOutputStream() {
DCHECK(!callback_);
}
bool FakeAudioOutputStream::Open() {
DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
audio_bus_->Zero();
return true;
}
void FakeAudioOutputStream::Start(AudioSourceCallback* callback) {
DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
callback_ = callback;
fake_worker_.Start(base::BindRepeating(&FakeAudioOutputStream::CallOnMoreData,
base::Unretained(this)));
}
void FakeAudioOutputStream::Stop() {
DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
fake_worker_.Stop();
callback_ = nullptr;
}
void FakeAudioOutputStream::Close() {
DCHECK(!callback_);
DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
audio_manager_->ReleaseOutputStream(this);
}
void FakeAudioOutputStream::Flush() {}
void FakeAudioOutputStream::SetVolume(double volume) {}
void FakeAudioOutputStream::GetVolume(double* volume) {
*volume = 0;
}
void FakeAudioOutputStream::CallOnMoreData(base::TimeTicks ideal_time,
base::TimeTicks now) {
DCHECK(audio_manager_->GetWorkerTaskRunner()->BelongsToCurrentThread());
// Real streams provide small tweaks to their delay values, alongside the
// current system time; and so the same is done here.
const auto delay =
fixed_data_delay_ + std::max(base::TimeDelta(), ideal_time - now);
callback_->OnMoreData(delay, now, {}, audio_bus_.get());
}
void FakeAudioOutputStream::SetMute(bool muted) {}
} // namespace media