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

Side by Side Diff: content/renderer/media/local_media_stream_audio_source.cc

Issue 2219933003: Use LocalMediaStreamAudioSource for screen-casting use cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 "content/renderer/media/local_media_stream_audio_source.h"
6
7 #include "content/common/media/media_stream_options.h"
8 #include "content/renderer/media/audio_device_factory.h"
9 #include "content/renderer/render_frame_impl.h"
10
11 namespace content {
12
13 LocalMediaStreamAudioSource::LocalMediaStreamAudioSource(
14 int consumer_render_frame_id,
15 const StreamDeviceInfo& device_info)
16 : MediaStreamAudioSource(true /* is_local_source */),
17 consumer_render_frame_id_(consumer_render_frame_id) {
18 DVLOG(1) << "LocalMediaStreamAudioSource::LocalMediaStreamAudioSource()";
19 MediaStreamSource::SetDeviceInfo(device_info);
20 MediaStreamAudioSource::SetFormat(media::AudioParameters(
21 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
22 static_cast<media::ChannelLayout>(
23 device_info.device.input.channel_layout),
24 device_info.device.input.sample_rate,
25 16, // Legacy parameter (data is always in 32-bit float format).
26 // If specified, use frames_per_buffer; else, default to 10 ms.
27 device_info.device.input.frames_per_buffer > 0 ?
28 device_info.device.input.frames_per_buffer :
29 device_info.device.input.sample_rate / 100));
o1ka 2016/08/15 15:15:00 Should we probably unify ProcessedLocalAudioSource
miu 2016/08/16 04:30:02 Done. Opened a crbug for tracking (http://crbug.co
30 }
31
32 LocalMediaStreamAudioSource::~LocalMediaStreamAudioSource() {
33 DVLOG(1) << "LocalMediaStreamAudioSource::~LocalMediaStreamAudioSource()";
34 EnsureSourceIsStopped();
35 }
36
37 bool LocalMediaStreamAudioSource::EnsureSourceIsStarted() {
38 DCHECK(thread_checker_.CalledOnValidThread());
39
40 if (source_)
41 return true;
42
43 // Sanity-check that the consuming RenderFrame still exists. This is required
44 // by AudioDeviceFactory.
45 if (!RenderFrameImpl::FromRoutingID(consumer_render_frame_id_))
46 return false;
47
48 VLOG(1) << "Starting local audio input device (session_id="
49 << device_info().session_id << ") for render frame "
50 << consumer_render_frame_id_ << " with audio parameters={"
51 << GetAudioParameters().AsHumanReadableString() << "}.";
52
53 source_ =
54 AudioDeviceFactory::NewAudioCapturerSource(consumer_render_frame_id_);
55 source_->Initialize(GetAudioParameters(), this, device_info().session_id);
56 source_->Start();
57 return true;
58 }
59
60 void LocalMediaStreamAudioSource::EnsureSourceIsStopped() {
61 DCHECK(thread_checker_.CalledOnValidThread());
62
63 if (!source_)
64 return;
65
66 source_->Stop();
67 source_ = nullptr;
68
69 VLOG(1) << "Stopped local audio input device (session_id="
70 << device_info().session_id << ") for render frame "
71 << consumer_render_frame_id_ << " with audio parameters={"
72 << GetAudioParameters().AsHumanReadableString() << "}.";
73 }
74
75 void LocalMediaStreamAudioSource::Capture(const media::AudioBus* audio_bus,
76 int audio_delay_milliseconds,
77 double volume,
78 bool key_pressed) {
79 DCHECK(audio_bus);
80 // TODO(miu): Plumbing is needed to determine the actual capture timestamp
81 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper
82 // audio/video sync. http://crbug.com/335335
83 MediaStreamAudioSource::DeliverDataToTracks(
84 *audio_bus,
85 base::TimeTicks::Now() -
86 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds));
87 }
88
89 void LocalMediaStreamAudioSource::OnCaptureError(const std::string& why) {
90 // As of this writing, this method doesn't get called for anything useful,
91 // and all other implementors just log the message, but don't disconnect sinks
92 // or take any other action. So, just log the error.
93 LOG(ERROR) << why;
94 }
95
96 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698