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

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

Issue 1897953003: Unmute Tab Audio For Desktop Share (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unittest Created 4 years, 7 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
OLDNEW
(Empty)
1 // Copyright 2016 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 "media/audio/virtual_audio_sink.h"
6
7 #include "base/callback_helpers.h"
8 #include "media/audio/virtual_audio_input_stream.h"
9
10 namespace media {
11
12 // Buffer size limit is chosen large enough that in the normal case, we do not
13 // have data loss.
14 constexpr int kBufferSizeSecond = 1;
15
16 // This is not the system clock accuracy. But considering the cross-process
17 // communication, there is fluctuation between the actual and the ideal instant
18 // when we receive the audio data. Testing shows the fluctuation is on the order
19 // of 1 millisecond.
20 constexpr int kClockAccuracyMillisecond = 1;
21
22 // See AudioShifter comment for detail about this parameter. We just take the
23 // suggestion from there.
24 constexpr int kAdjustTimeSecond = 1;
25
26 VirtualAudioSink::VirtualAudioSink(AudioParameters param,
27 VirtualAudioInputStream* target,
28 AfterCloseCallback callback)
29 : params_(param),
30 target_(target),
31 shifter_(base::TimeDelta::FromSeconds(kBufferSizeSecond),
32 base::TimeDelta::FromMilliseconds(kClockAccuracyMillisecond),
33 base::TimeDelta::FromSeconds(kAdjustTimeSecond),
34 param.sample_rate(),
35 param.channels()),
36 after_close_callback_(callback) {
37 target_->AddInputProvider(this, params_);
38 }
39
40 VirtualAudioSink::~VirtualAudioSink() {}
41
42 void VirtualAudioSink::Close() {
43 target_->RemoveInputProvider(this, params_);
44 const AfterCloseCallback& cb = base::ResetAndReturn(&after_close_callback_);
45 if (!cb.is_null())
46 cb.Run(this);
47 }
48
49 void VirtualAudioSink::OnData(const AudioBus& source,
50 base::TimeTicks reference_time) {
51 std::unique_ptr<AudioBus> source_copy = AudioBus::Create(params_);
52 source.CopyTo(source_copy.get());
53 shifter_.Push(std::move(source_copy), reference_time);
54 }
55
56 double VirtualAudioSink::ProvideInput(AudioBus* audio_bus,
57 base::TimeDelta buffer_delay) {
58 shifter_.Pull(audio_bus, base::TimeTicks::Now() + buffer_delay);
59 return 1;
60 }
61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698