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

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

Issue 2416123002: Stop media stream source when audio capture error occurs. (Closed)
Patch Set: Rebase. Created 4 years, 2 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/media_stream_audio_source.h" 5 #include "content/renderer/media/media_stream_audio_source.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/threading/thread_task_runner_handle.h"
8 #include "content/renderer/media/media_stream_audio_track.h" 10 #include "content/renderer/media/media_stream_audio_track.h"
9 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 11 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
10 #include "third_party/WebKit/public/platform/WebString.h" 12 #include "third_party/WebKit/public/platform/WebString.h"
11 13
12 namespace content { 14 namespace content {
13 15
14 MediaStreamAudioSource::MediaStreamAudioSource(bool is_local_source) 16 MediaStreamAudioSource::MediaStreamAudioSource(bool is_local_source)
15 : is_local_source_(is_local_source), 17 : is_local_source_(is_local_source),
16 is_stopped_(false), 18 is_stopped_(false),
19 task_runner_(base::ThreadTaskRunnerHandle::Get()),
17 weak_factory_(this) { 20 weak_factory_(this) {
18 DVLOG(1) << "MediaStreamAudioSource@" << this << "::MediaStreamAudioSource(" 21 DVLOG(1) << "MediaStreamAudioSource@" << this << "::MediaStreamAudioSource("
19 << (is_local_source_ ? "local" : "remote") << " source)"; 22 << (is_local_source_ ? "local" : "remote") << " source)";
20 } 23 }
21 24
22 MediaStreamAudioSource::~MediaStreamAudioSource() { 25 MediaStreamAudioSource::~MediaStreamAudioSource() {
23 DCHECK(thread_checker_.CalledOnValidThread()); 26 DCHECK(task_runner_->RunsTasksOnCurrentThread());
24 DVLOG(1) << "MediaStreamAudioSource@" << this << " is being destroyed."; 27 DVLOG(1) << "MediaStreamAudioSource@" << this << " is being destroyed.";
25 } 28 }
26 29
27 // static 30 // static
28 MediaStreamAudioSource* MediaStreamAudioSource::From( 31 MediaStreamAudioSource* MediaStreamAudioSource::From(
29 const blink::WebMediaStreamSource& source) { 32 const blink::WebMediaStreamSource& source) {
30 if (source.isNull() || 33 if (source.isNull() ||
31 source.getType() != blink::WebMediaStreamSource::TypeAudio) { 34 source.getType() != blink::WebMediaStreamSource::TypeAudio) {
32 return nullptr; 35 return nullptr;
33 } 36 }
34 return static_cast<MediaStreamAudioSource*>(source.getExtraData()); 37 return static_cast<MediaStreamAudioSource*>(source.getExtraData());
35 } 38 }
36 39
37 bool MediaStreamAudioSource::ConnectToTrack( 40 bool MediaStreamAudioSource::ConnectToTrack(
38 const blink::WebMediaStreamTrack& blink_track) { 41 const blink::WebMediaStreamTrack& blink_track) {
39 DCHECK(thread_checker_.CalledOnValidThread()); 42 DCHECK(task_runner_->RunsTasksOnCurrentThread());
40 DCHECK(!blink_track.isNull()); 43 DCHECK(!blink_track.isNull());
41 44
42 // Sanity-check that there is not already a MediaStreamAudioTrack instance 45 // Sanity-check that there is not already a MediaStreamAudioTrack instance
43 // associated with |blink_track|. 46 // associated with |blink_track|.
44 if (MediaStreamAudioTrack::From(blink_track)) { 47 if (MediaStreamAudioTrack::From(blink_track)) {
45 LOG(DFATAL) 48 LOG(DFATAL)
46 << "Attempting to connect another source to a WebMediaStreamTrack."; 49 << "Attempting to connect another source to a WebMediaStreamTrack.";
47 return false; 50 return false;
48 } 51 }
49 52
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 media::AudioParameters MediaStreamAudioSource::GetAudioParameters() const { 84 media::AudioParameters MediaStreamAudioSource::GetAudioParameters() const {
82 return deliverer_.GetAudioParameters(); 85 return deliverer_.GetAudioParameters();
83 } 86 }
84 87
85 void* MediaStreamAudioSource::GetClassIdentifier() const { 88 void* MediaStreamAudioSource::GetClassIdentifier() const {
86 return nullptr; 89 return nullptr;
87 } 90 }
88 91
89 std::unique_ptr<MediaStreamAudioTrack> 92 std::unique_ptr<MediaStreamAudioTrack>
90 MediaStreamAudioSource::CreateMediaStreamAudioTrack(const std::string& id) { 93 MediaStreamAudioSource::CreateMediaStreamAudioTrack(const std::string& id) {
91 DCHECK(thread_checker_.CalledOnValidThread()); 94 DCHECK(task_runner_->RunsTasksOnCurrentThread());
92 return std::unique_ptr<MediaStreamAudioTrack>( 95 return std::unique_ptr<MediaStreamAudioTrack>(
93 new MediaStreamAudioTrack(is_local_source())); 96 new MediaStreamAudioTrack(is_local_source()));
94 } 97 }
95 98
96 bool MediaStreamAudioSource::EnsureSourceIsStarted() { 99 bool MediaStreamAudioSource::EnsureSourceIsStarted() {
97 DCHECK(thread_checker_.CalledOnValidThread()); 100 DCHECK(task_runner_->RunsTasksOnCurrentThread());
98 DVLOG(1) << "MediaStreamAudioSource@" << this << "::EnsureSourceIsStarted()"; 101 DVLOG(1) << "MediaStreamAudioSource@" << this << "::EnsureSourceIsStarted()";
99 return true; 102 return true;
100 } 103 }
101 104
102 void MediaStreamAudioSource::EnsureSourceIsStopped() { 105 void MediaStreamAudioSource::EnsureSourceIsStopped() {
103 DCHECK(thread_checker_.CalledOnValidThread()); 106 DCHECK(task_runner_->RunsTasksOnCurrentThread());
104 DVLOG(1) << "MediaStreamAudioSource@" << this << "::EnsureSourceIsStopped()"; 107 DVLOG(1) << "MediaStreamAudioSource@" << this << "::EnsureSourceIsStopped()";
105 } 108 }
106 109
107 void MediaStreamAudioSource::SetFormat(const media::AudioParameters& params) { 110 void MediaStreamAudioSource::SetFormat(const media::AudioParameters& params) {
108 DVLOG(1) << "MediaStreamAudioSource@" << this << "::SetFormat(" 111 DVLOG(1) << "MediaStreamAudioSource@" << this << "::SetFormat("
109 << params.AsHumanReadableString() << "), was previously set to {" 112 << params.AsHumanReadableString() << "), was previously set to {"
110 << deliverer_.GetAudioParameters().AsHumanReadableString() << "}."; 113 << deliverer_.GetAudioParameters().AsHumanReadableString() << "}.";
111 deliverer_.OnSetFormat(params); 114 deliverer_.OnSetFormat(params);
112 } 115 }
113 116
114 void MediaStreamAudioSource::DeliverDataToTracks( 117 void MediaStreamAudioSource::DeliverDataToTracks(
115 const media::AudioBus& audio_bus, 118 const media::AudioBus& audio_bus,
116 base::TimeTicks reference_time) { 119 base::TimeTicks reference_time) {
117 deliverer_.OnData(audio_bus, reference_time); 120 deliverer_.OnData(audio_bus, reference_time);
118 } 121 }
119 122
120 void MediaStreamAudioSource::DoStopSource() { 123 void MediaStreamAudioSource::DoStopSource() {
121 DCHECK(thread_checker_.CalledOnValidThread()); 124 DCHECK(task_runner_->RunsTasksOnCurrentThread());
122 EnsureSourceIsStopped(); 125 EnsureSourceIsStopped();
123 is_stopped_ = true; 126 is_stopped_ = true;
124 } 127 }
125 128
126 void MediaStreamAudioSource::StopAudioDeliveryTo(MediaStreamAudioTrack* track) { 129 void MediaStreamAudioSource::StopAudioDeliveryTo(MediaStreamAudioTrack* track) {
127 DCHECK(thread_checker_.CalledOnValidThread()); 130 DCHECK(task_runner_->RunsTasksOnCurrentThread());
128 131
129 const bool did_remove_last_track = deliverer_.RemoveConsumer(track); 132 const bool did_remove_last_track = deliverer_.RemoveConsumer(track);
130 DVLOG(1) << "Removed MediaStreamAudioTrack@" << track 133 DVLOG(1) << "Removed MediaStreamAudioTrack@" << track
131 << " as a consumer of MediaStreamAudioSource@" << this << '.'; 134 << " as a consumer of MediaStreamAudioSource@" << this << '.';
132 135
133 // The W3C spec requires a source automatically stop when the last track is 136 // The W3C spec requires a source automatically stop when the last track is
134 // stopped. 137 // stopped.
135 if (!is_stopped_ && did_remove_last_track) 138 if (!is_stopped_ && did_remove_last_track)
136 MediaStreamSource::StopSource(); 139 MediaStreamSource::StopSource();
137 } 140 }
138 141
142 void MediaStreamAudioSource::StopSourceOnError(const std::string& why) {
143 VLOG(1) << why;
144
145 // Stop source when error occurs.
146 task_runner_->PostTask(
147 FROM_HERE, base::Bind(&MediaStreamSource::StopSource, GetWeakPtr()));
148 }
149
139 } // namespace content 150 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_audio_source.h ('k') | content/renderer/media/media_stream_audio_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698