OLD | NEW |
| (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 "content/renderer/media/external_media_stream_audio_source.h" | |
6 | |
7 namespace content { | |
8 | |
9 ExternalMediaStreamAudioSource::ExternalMediaStreamAudioSource( | |
10 scoped_refptr<media::AudioCapturerSource> source, | |
11 int sample_rate, | |
12 media::ChannelLayout channel_layout, | |
13 int frames_per_buffer, | |
14 bool is_remote) | |
15 : MediaStreamAudioSource(!is_remote), source_(std::move(source)), | |
16 was_started_(false) { | |
17 DVLOG(1) | |
18 << "ExternalMediaStreamAudioSource::ExternalMediaStreamAudioSource()"; | |
19 DCHECK(source_.get()); | |
20 MediaStreamAudioSource::SetFormat(media::AudioParameters( | |
21 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | |
22 sample_rate, | |
23 16, // Legacy parameter (data is always in 32-bit float format). | |
24 frames_per_buffer)); | |
25 } | |
26 | |
27 ExternalMediaStreamAudioSource::~ExternalMediaStreamAudioSource() { | |
28 DVLOG(1) | |
29 << "ExternalMediaStreamAudioSource::~ExternalMediaStreamAudioSource()"; | |
30 EnsureSourceIsStopped(); | |
31 } | |
32 | |
33 bool ExternalMediaStreamAudioSource::EnsureSourceIsStarted() { | |
34 DCHECK(thread_checker_.CalledOnValidThread()); | |
35 if (was_started_) | |
36 return true; | |
37 VLOG(1) << "Starting externally-provided " | |
38 << (is_local_source() ? "local" : "remote") | |
39 << " source with audio parameters={" | |
40 << GetAudioParameters().AsHumanReadableString() << "}."; | |
41 source_->Initialize(GetAudioParameters(), this, -1); | |
42 source_->Start(); | |
43 was_started_ = true; | |
44 return true; | |
45 } | |
46 | |
47 void ExternalMediaStreamAudioSource::EnsureSourceIsStopped() { | |
48 DCHECK(thread_checker_.CalledOnValidThread()); | |
49 if (!source_) | |
50 return; | |
51 if (was_started_) | |
52 source_->Stop(); | |
53 source_ = nullptr; | |
54 VLOG(1) << "Stopped externally-provided " | |
55 << (is_local_source() ? "local" : "remote") | |
56 << " source with audio parameters={" | |
57 << GetAudioParameters().AsHumanReadableString() << "}."; | |
58 } | |
59 | |
60 void ExternalMediaStreamAudioSource::Capture(const media::AudioBus* audio_bus, | |
61 int audio_delay_milliseconds, | |
62 double volume, | |
63 bool key_pressed) { | |
64 DCHECK(audio_bus); | |
65 // TODO(miu): Plumbing is needed to determine the actual capture timestamp | |
66 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper | |
67 // audio/video sync. http://crbug.com/335335 | |
68 MediaStreamAudioSource::DeliverDataToTracks( | |
69 *audio_bus, | |
70 base::TimeTicks::Now() - | |
71 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds)); | |
72 } | |
73 | |
74 void ExternalMediaStreamAudioSource::OnCaptureError(const std::string& why) { | |
75 // As of this writing, this method doesn't get called for anything useful, | |
76 // and all other implementors just log the message, but don't disconnect sinks | |
77 // or take any other action. So, just log the error. | |
78 LOG(ERROR) << why; | |
79 } | |
80 | |
81 } // namespace content | |
OLD | NEW |