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 // OnCaptureStarted() is expected to be called synchronously by this | 43 was_started_ = true; |
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_); | |
47 return true; | 44 return true; |
48 } | 45 } |
49 | 46 |
50 void ExternalMediaStreamAudioSource::EnsureSourceIsStopped() { | 47 void ExternalMediaStreamAudioSource::EnsureSourceIsStopped() { |
51 DCHECK(thread_checker_.CalledOnValidThread()); | 48 DCHECK(thread_checker_.CalledOnValidThread()); |
52 if (!source_) | 49 if (!source_) |
53 return; | 50 return; |
54 if (was_started_) | 51 if (was_started_) |
55 source_->Stop(); | 52 source_->Stop(); |
56 source_ = nullptr; | 53 source_ = nullptr; |
57 VLOG(1) << "Stopped externally-provided " | 54 VLOG(1) << "Stopped externally-provided " |
58 << (is_local_source() ? "local" : "remote") | 55 << (is_local_source() ? "local" : "remote") |
59 << " source with audio parameters={" | 56 << " source with audio parameters={" |
60 << GetAudioParameters().AsHumanReadableString() << "}."; | 57 << GetAudioParameters().AsHumanReadableString() << "}."; |
61 } | 58 } |
62 | 59 |
63 void ExternalMediaStreamAudioSource::OnCaptureStarted() { | |
64 was_started_ = true; | |
65 } | |
66 | |
67 void ExternalMediaStreamAudioSource::Capture(const media::AudioBus* audio_bus, | 60 void ExternalMediaStreamAudioSource::Capture(const media::AudioBus* audio_bus, |
68 int audio_delay_milliseconds, | 61 int audio_delay_milliseconds, |
69 double volume, | 62 double volume, |
70 bool key_pressed) { | 63 bool key_pressed) { |
71 DCHECK(audio_bus); | 64 DCHECK(audio_bus); |
72 // TODO(miu): Plumbing is needed to determine the actual capture timestamp | 65 // TODO(miu): Plumbing is needed to determine the actual capture timestamp |
73 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper | 66 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper |
74 // audio/video sync. http://crbug.com/335335 | 67 // audio/video sync. http://crbug.com/335335 |
75 MediaStreamAudioSource::DeliverDataToTracks( | 68 MediaStreamAudioSource::DeliverDataToTracks( |
76 *audio_bus, | 69 *audio_bus, |
77 base::TimeTicks::Now() - | 70 base::TimeTicks::Now() - |
78 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds)); | 71 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds)); |
79 } | 72 } |
80 | 73 |
81 void ExternalMediaStreamAudioSource::OnCaptureError(const std::string& why) { | 74 void ExternalMediaStreamAudioSource::OnCaptureError(const std::string& why) { |
82 StopSourceOnError(why); | 75 StopSourceOnError(why); |
83 } | 76 } |
84 | 77 |
85 } // namespace content | 78 } // namespace content |
OLD | NEW |