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