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

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

Issue 1780653002: Revert of MediaStream audio object graph untangling and clean-ups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 "content/renderer/media/webrtc_local_audio_track.h"
8 #include "content/renderer/render_frame_impl.h" 7 #include "content/renderer/render_frame_impl.h"
9 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
10 8
11 namespace content { 9 namespace content {
12 10
13 MediaStreamAudioSource::MediaStreamAudioSource( 11 MediaStreamAudioSource::MediaStreamAudioSource(
14 int render_frame_id, 12 int render_frame_id,
15 const StreamDeviceInfo& device_info, 13 const StreamDeviceInfo& device_info,
16 const SourceStoppedCallback& stop_callback, 14 const SourceStoppedCallback& stop_callback,
17 PeerConnectionDependencyFactory* factory) 15 PeerConnectionDependencyFactory* factory)
18 : render_frame_id_(render_frame_id), factory_(factory), 16 : render_frame_id_(render_frame_id), factory_(factory) {
19 weak_factory_(this) {
20 SetDeviceInfo(device_info); 17 SetDeviceInfo(device_info);
21 SetStopCallback(stop_callback); 18 SetStopCallback(stop_callback);
22 } 19 }
23 20
24 MediaStreamAudioSource::MediaStreamAudioSource() 21 MediaStreamAudioSource::MediaStreamAudioSource()
25 : render_frame_id_(-1), factory_(NULL), weak_factory_(this) { 22 : render_frame_id_(-1), factory_(NULL) {
26 } 23 }
27 24
28 MediaStreamAudioSource::~MediaStreamAudioSource() {} 25 MediaStreamAudioSource::~MediaStreamAudioSource() {}
29 26
30 // static
31 MediaStreamAudioSource* MediaStreamAudioSource::From(
32 const blink::WebMediaStreamSource& source) {
33 if (source.isNull() ||
34 source.getType() != blink::WebMediaStreamSource::TypeAudio) {
35 return nullptr;
36 }
37 return static_cast<MediaStreamAudioSource*>(source.getExtraData());
38 }
39
40 void MediaStreamAudioSource::DoStopSource() { 27 void MediaStreamAudioSource::DoStopSource() {
41 if (audio_capturer_) 28 if (audio_capturer_.get())
42 audio_capturer_->Stop(); 29 audio_capturer_->Stop();
43 if (webaudio_capturer_)
44 webaudio_capturer_->Stop();
45 } 30 }
46 31
47 void MediaStreamAudioSource::AddTrack( 32 void MediaStreamAudioSource::AddTrack(
48 const blink::WebMediaStreamTrack& track, 33 const blink::WebMediaStreamTrack& track,
49 const blink::WebMediaConstraints& constraints, 34 const blink::WebMediaConstraints& constraints,
50 const ConstraintsCallback& callback) { 35 const ConstraintsCallback& callback) {
51 // TODO(xians): Properly implement for audio sources. 36 // TODO(xians): Properly implement for audio sources.
52 if (!local_audio_source_.get()) { 37 if (!local_audio_source_.get()) {
53 if (!factory_->InitializeMediaStreamAudioSource(render_frame_id_, 38 if (!factory_->InitializeMediaStreamAudioSource(render_frame_id_,
54 constraints, this)) { 39 constraints, this)) {
55 // The source failed to start. 40 // The source failed to start.
56 // UserMediaClientImpl rely on the |stop_callback| to be triggered when 41 // UserMediaClientImpl rely on the |stop_callback| to be triggered when
57 // the last track is removed from the source. But in this case, the 42 // the last track is removed from the source. But in this case, the
58 // source is is not even started. So we need to fail both adding the 43 // source is is not even started. So we need to fail both adding the
59 // track and trigger |stop_callback|. 44 // track and trigger |stop_callback|.
60 callback.Run(this, MEDIA_DEVICE_TRACK_START_FAILURE, ""); 45 callback.Run(this, MEDIA_DEVICE_TRACK_START_FAILURE, "");
61 StopSource(); 46 StopSource();
62 return; 47 return;
63 } 48 }
64 } 49 }
65 50
66 factory_->CreateLocalAudioTrack(track); 51 factory_->CreateLocalAudioTrack(track);
67 callback.Run(this, MEDIA_DEVICE_OK, ""); 52 callback.Run(this, MEDIA_DEVICE_OK, "");
68 } 53 }
69 54
70 void MediaStreamAudioSource::StopAudioDeliveryTo(MediaStreamAudioTrack* track) {
71 DCHECK(track);
72 if (audio_capturer_) {
73 // The cast here is safe because only WebRtcLocalAudioTracks are ever used
74 // with WebRtcAudioCapturer sources.
75 //
76 // TODO(miu): That said, this ugly cast won't be necessary after my
77 // soon-upcoming refactoring change.
78 audio_capturer_->RemoveTrack(static_cast<WebRtcLocalAudioTrack*>(track));
79 }
80 if (webaudio_capturer_) {
81 // A separate source is created for each track, so just stop the source.
82 webaudio_capturer_->Stop();
83 }
84 }
85
86 } // namespace content 55 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_audio_source.h ('k') | content/renderer/media/media_stream_audio_track.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698