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

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: Resolving Comments 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/bind.h"
8 #include "base/callback_helpers.h"
9 #include "base/location.h"
10 #include "base/single_thread_task_runner.h"
11 #include "media/audio/virtual_audio_input_stream.h"
12
13 namespace media {
14
15 // Buffer size limit is chosen large enough that in the normal case, we do not
16 // have data loss.
17 constexpr int kBufferSizeSecond = 1;
18
19 // This is not the system clock accuracy. But considering the cross-process
20 // communication, there is fluctuation between the actual and the ideal instant
21 // when we receive the audio data. Testing shows the fluctuation is on the order
22 // of 1 millisecond.
23 constexpr int kClockAccuracyMillisecond = 1;
miu 2016/05/28 02:45:00 This seems wrong, given the code comments here: h
qiangchen 2016/05/31 21:17:33 Done.
24
25 // See AudioShifter comment for detail about this parameter. We just take the
26 // suggestion from there.
27 constexpr int kAdjustTimeSecond = 1;
28
29 VirtualAudioSink::VirtualAudioSink(AudioParameters param,
30 VirtualAudioInputStream* target,
31 AfterCloseCallback callback)
32 : params_(param),
33 target_(target),
34 shifter_(base::TimeDelta::FromSeconds(kBufferSizeSecond),
35 base::TimeDelta::FromMilliseconds(kClockAccuracyMillisecond),
36 base::TimeDelta::FromSeconds(kAdjustTimeSecond),
37 param.sample_rate(),
38 param.channels()),
39 task_runner_(target->GetTaskRunner()),
40 after_close_callback_(callback) {
41 target_->AddInputProvider(this, params_);
42 }
43
44 VirtualAudioSink::~VirtualAudioSink() {}
45
46 void VirtualAudioSink::Close() {
47 target_->RemoveInputProvider(this, params_);
48 const AfterCloseCallback& cb = base::ResetAndReturn(&after_close_callback_);
49 if (!cb.is_null())
50 cb.Run(this);
51 }
52
53 void VirtualAudioSink::OnData(const AudioBus& source,
54 base::TimeTicks reference_time) {
55 // We must copy data here, and should not pass |source| to the
miu 2016/05/28 02:45:00 Given this should be done in AudioOutputController
qiangchen 2016/05/31 21:17:33 Then I think we need a lock for shifter_, otherwis
miu 2016/06/01 00:29:42 Yep. Sounds good to me.
qiangchen 2016/06/01 17:51:11 Acknowledged.
56 // |task_runner_|, because there is no guarantee that |source| is still a
57 // valid object when the posted task is run.
58 std::unique_ptr<AudioBus> source_copy(AudioBus::Create(params_));
59 source.CopyTo(source_copy.get());
60 task_runner_->PostTask(FROM_HERE,
61 base::Bind(&VirtualAudioSink::StoreData, AsWeakPtr(),
62 source_copy.release(), reference_time));
63 }
64
65 void VirtualAudioSink::StoreData(AudioBus* source,
66 base::TimeTicks reference_time) {
67 shifter_.Push(std::unique_ptr<AudioBus>(source), reference_time);
68 }
69
70 double VirtualAudioSink::ProvideInput(AudioBus* audio_bus,
71 base::TimeDelta buffer_delay) {
72 DCHECK(task_runner_->BelongsToCurrentThread());
73 shifter_.Pull(audio_bus, base::TimeTicks::Now() + buffer_delay);
74 return 1;
75 }
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698