| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/external_media_stream_audio_source.h" | 5 #include "content/renderer/media/external_media_stream_audio_source.h" |
| 6 | 6 |
| 7 namespace content { | 7 namespace content { |
| 8 | 8 |
| 9 ExternalMediaStreamAudioSource::ExternalMediaStreamAudioSource( | 9 ExternalMediaStreamAudioSource::ExternalMediaStreamAudioSource( |
| 10 scoped_refptr<media::AudioCapturerSource> source, | 10 scoped_refptr<media::AudioCapturerSource> source, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 bool ExternalMediaStreamAudioSource::EnsureSourceIsStarted() { | 33 bool ExternalMediaStreamAudioSource::EnsureSourceIsStarted() { |
| 34 DCHECK(thread_checker_.CalledOnValidThread()); | 34 DCHECK(thread_checker_.CalledOnValidThread()); |
| 35 if (was_started_) | 35 if (was_started_) |
| 36 return true; | 36 return true; |
| 37 VLOG(1) << "Starting externally-provided " | 37 VLOG(1) << "Starting externally-provided " |
| 38 << (is_local_source() ? "local" : "remote") | 38 << (is_local_source() ? "local" : "remote") |
| 39 << " source with audio parameters={" | 39 << " source with audio parameters={" |
| 40 << GetAudioParameters().AsHumanReadableString() << "}."; | 40 << GetAudioParameters().AsHumanReadableString() << "}."; |
| 41 source_->Initialize(GetAudioParameters(), this, -1); | 41 source_->Initialize(GetAudioParameters(), this, -1); |
| 42 source_->Start(); | 42 source_->Start(); |
| 43 was_started_ = true; | 43 // OnCaptureStarted() is expected to be called synchronously by this |
| 44 // implementation. If this needs to be changed, the source needs to be started |
| 45 // outside of EnsureSourceIsStarted since its design is synchronous. |
| 46 CHECK(was_started_); |
| 44 return true; | 47 return true; |
| 45 } | 48 } |
| 46 | 49 |
| 47 void ExternalMediaStreamAudioSource::EnsureSourceIsStopped() { | 50 void ExternalMediaStreamAudioSource::EnsureSourceIsStopped() { |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | 51 DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 if (!source_) | 52 if (!source_) |
| 50 return; | 53 return; |
| 51 if (was_started_) | 54 if (was_started_) |
| 52 source_->Stop(); | 55 source_->Stop(); |
| 53 source_ = nullptr; | 56 source_ = nullptr; |
| 54 VLOG(1) << "Stopped externally-provided " | 57 VLOG(1) << "Stopped externally-provided " |
| 55 << (is_local_source() ? "local" : "remote") | 58 << (is_local_source() ? "local" : "remote") |
| 56 << " source with audio parameters={" | 59 << " source with audio parameters={" |
| 57 << GetAudioParameters().AsHumanReadableString() << "}."; | 60 << GetAudioParameters().AsHumanReadableString() << "}."; |
| 58 } | 61 } |
| 59 | 62 |
| 63 void ExternalMediaStreamAudioSource::OnCaptureStarted() { |
| 64 was_started_ = true; |
| 65 } |
| 66 |
| 60 void ExternalMediaStreamAudioSource::Capture(const media::AudioBus* audio_bus, | 67 void ExternalMediaStreamAudioSource::Capture(const media::AudioBus* audio_bus, |
| 61 int audio_delay_milliseconds, | 68 int audio_delay_milliseconds, |
| 62 double volume, | 69 double volume, |
| 63 bool key_pressed) { | 70 bool key_pressed) { |
| 64 DCHECK(audio_bus); | 71 DCHECK(audio_bus); |
| 65 // TODO(miu): Plumbing is needed to determine the actual capture timestamp | 72 // TODO(miu): Plumbing is needed to determine the actual capture timestamp |
| 66 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper | 73 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper |
| 67 // audio/video sync. http://crbug.com/335335 | 74 // audio/video sync. http://crbug.com/335335 |
| 68 MediaStreamAudioSource::DeliverDataToTracks( | 75 MediaStreamAudioSource::DeliverDataToTracks( |
| 69 *audio_bus, | 76 *audio_bus, |
| 70 base::TimeTicks::Now() - | 77 base::TimeTicks::Now() - |
| 71 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds)); | 78 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds)); |
| 72 } | 79 } |
| 73 | 80 |
| 74 void ExternalMediaStreamAudioSource::OnCaptureError(const std::string& why) { | 81 void ExternalMediaStreamAudioSource::OnCaptureError(const std::string& why) { |
| 75 StopSourceOnError(why); | 82 StopSourceOnError(why); |
| 76 } | 83 } |
| 77 | 84 |
| 78 } // namespace content | 85 } // namespace content |
| OLD | NEW |