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

Side by Side Diff: content/public/renderer/media_stream_api.cc

Issue 1721273002: 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/public/renderer/media_stream_api.h" 5 #include "content/public/renderer/media_stream_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
11 #include "base/rand_util.h" 12 #include "base/rand_util.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "content/renderer/media/media_stream_audio_source.h" 14 #include "content/renderer/media/media_stream_audio_source.h"
14 #include "content/renderer/media/media_stream_video_capturer_source.h" 15 #include "content/renderer/media/media_stream_video_capturer_source.h"
15 #include "content/renderer/media/media_stream_video_track.h" 16 #include "content/renderer/media/media_stream_video_track.h"
16 #include "content/renderer/render_thread_impl.h" 17 #include "content/renderer/render_thread_impl.h"
17 #include "third_party/WebKit/public/platform/WebMediaStream.h" 18 #include "third_party/WebKit/public/platform/WebMediaStream.h"
18 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 19 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
19 #include "third_party/WebKit/public/platform/WebURL.h" 20 #include "third_party/WebKit/public/platform/WebURL.h"
20 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" 21 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h"
21 #include "url/gurl.h" 22 #include "url/gurl.h"
22 23
23 namespace content { 24 namespace content {
24 25
25 namespace { 26 namespace {
26 27
27 blink::WebString MakeTrackId() { 28 blink::WebString MakeTrackId() {
28 std::string track_id; 29 std::string track_id;
29 base::Base64Encode(base::RandBytesAsString(64), &track_id); 30 base::Base64Encode(base::RandBytesAsString(64), &track_id);
30 return base::UTF8ToUTF16(track_id); 31 return base::UTF8ToUTF16(track_id);
31 } 32 }
32 33
33 } // namespace 34 } // namespace
34 35
35 bool AddVideoTrackToMediaStream(scoped_ptr<media::VideoCapturerSource> source, 36 bool AddVideoTrackToMediaStream(
36 bool is_remote, 37 scoped_ptr<media::VideoCapturerSource> video_source,
37 bool is_readonly, 38 bool is_remote,
38 const std::string& media_stream_url) { 39 bool is_readonly,
39 blink::WebMediaStream web_stream = 40 blink::WebMediaStream* web_media_stream) {
40 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor( 41 DCHECK(video_source.get());
41 GURL(media_stream_url)); 42 if (!web_media_stream || web_media_stream->isNull()) {
42 return AddVideoTrackToMediaStream(std::move(source), is_remote, is_readonly, 43 DLOG(ERROR) << "WebMediaStream is null";
43 &web_stream);
44 }
45
46 bool AddVideoTrackToMediaStream(scoped_ptr<media::VideoCapturerSource> source,
47 bool is_remote,
48 bool is_readonly,
49 blink::WebMediaStream* web_stream) {
50 if (web_stream->isNull()) {
51 DLOG(ERROR) << "Stream not found";
52 return false; 44 return false;
53 } 45 }
46
54 const blink::WebString track_id = MakeTrackId(); 47 const blink::WebString track_id = MakeTrackId();
mcasas 2016/02/26 01:28:19 Seems like a WebMediaStreamSource::id, which is no
miu 2016/02/27 03:46:36 Sounds good to me. Done.
55 blink::WebMediaStreamSource webkit_source; 48 blink::WebMediaStreamSource web_media_stream_source;
56 scoped_ptr<MediaStreamVideoSource> media_stream_source( 49 MediaStreamVideoSource* const media_stream_source =
57 new MediaStreamVideoCapturerSource( 50 new MediaStreamVideoCapturerSource(
58 MediaStreamSource::SourceStoppedCallback(), std::move(source))); 51 MediaStreamSource::SourceStoppedCallback(), std::move(video_source));
59 webkit_source.initialize(track_id, blink::WebMediaStreamSource::TypeVideo, 52 web_media_stream_source.initialize(track_id,
60 track_id, is_remote, is_readonly); 53 blink::WebMediaStreamSource::TypeVideo,
61 webkit_source.setExtraData(media_stream_source.get()); 54 track_id, is_remote, is_readonly);
55 // Takes ownership of |media_stream_source|.
56 web_media_stream_source.setExtraData(media_stream_source);
62 57
63 blink::WebMediaConstraints constraints; 58 blink::WebMediaConstraints constraints;
64 constraints.initialize(); 59 constraints.initialize();
65 web_stream->addTrack(MediaStreamVideoTrack::CreateVideoTrack( 60 web_media_stream->addTrack(MediaStreamVideoTrack::CreateVideoTrack(
66 media_stream_source.release(), constraints, 61 media_stream_source, constraints,
67 MediaStreamVideoSource::ConstraintsCallback(), true)); 62 MediaStreamVideoSource::ConstraintsCallback(), true));
68 return true; 63 return true;
69 } 64 }
70 65
71 bool AddAudioTrackToMediaStream( 66 bool AddAudioTrackToMediaStream(
72 const scoped_refptr<media::AudioCapturerSource>& source, 67 const scoped_refptr<media::AudioCapturerSource>& audio_source,
73 const media::AudioParameters& params, 68 int sample_rate,
69 media::ChannelLayout channel_layout,
70 int frames_per_buffer,
74 bool is_remote, 71 bool is_remote,
75 bool is_readonly, 72 bool is_readonly,
76 const std::string& media_stream_url) { 73 blink::WebMediaStream* web_media_stream) {
77 DCHECK(params.IsValid()) << params.AsHumanReadableString(); 74 DCHECK(audio_source.get());
78 blink::WebMediaStream web_stream = 75 if (!web_media_stream || web_media_stream->isNull()) {
79 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor( 76 DLOG(ERROR) << "WebMediaStream is null";
80 GURL(media_stream_url));
81 return AddAudioTrackToMediaStream(source,
82 is_remote, is_readonly, &web_stream);
83 }
84
85 bool AddAudioTrackToMediaStream(
86 const scoped_refptr<media::AudioCapturerSource>& source,
87 bool is_remote,
88 bool is_readonly,
89 blink::WebMediaStream* web_stream) {
90 if (web_stream->isNull()) {
91 DLOG(ERROR) << "Stream not found";
92 return false; 77 return false;
93 } 78 }
94 79
95 media::AudioParameters params( 80 const media::AudioParameters params(
96 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO, 81 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
97 48000, /* sample rate */ 82 sample_rate, sizeof(int16_t) * 8, frames_per_buffer);
98 16, /* bits per sample */ 83 if (!params.IsValid()) {
99 480); /* frames per buffer */ 84 DLOG(ERROR) << "Invalid audio parameters.";
85 return false;
86 }
100 87
101 blink::WebMediaStreamSource webkit_source; 88 blink::WebMediaStreamSource web_media_stream_source;
102 const blink::WebString track_id = MakeTrackId(); 89 const blink::WebString track_id = MakeTrackId();
103 webkit_source.initialize(track_id, 90 web_media_stream_source.initialize(track_id,
104 blink::WebMediaStreamSource::TypeAudio, 91 blink::WebMediaStreamSource::TypeAudio,
105 track_id, 92 track_id, is_remote, is_readonly);
106 is_remote,
107 is_readonly);
108 93
109 MediaStreamAudioSource* audio_source( 94 MediaStreamAudioSource* media_stream_source(new MediaStreamAudioSource(
110 new MediaStreamAudioSource( 95 -1, StreamDeviceInfo(), MediaStreamSource::SourceStoppedCallback(),
111 -1, 96 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory()));
112 StreamDeviceInfo(),
113 MediaStreamSource::SourceStoppedCallback(),
114 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory()));
115 97
116 blink::WebMediaConstraints constraints; 98 blink::WebMediaConstraints constraints;
117 constraints.initialize(); 99 constraints.initialize();
118 scoped_refptr<WebRtcAudioCapturer> capturer( 100 {
119 WebRtcAudioCapturer::CreateCapturer(-1, StreamDeviceInfo(), constraints, 101 // TODO(miu): In an upcoming change, a source purposed for passing audio
120 nullptr, audio_source)); 102 // directly (i.e., without modification) will replace this "hacky" use of
121 capturer->SetCapturerSource(source, params); 103 // WebRtcAudioCapturer. http://crbug.com/577881
122 audio_source->SetAudioCapturer(capturer); 104 scoped_ptr<WebRtcAudioCapturer> capturer(
123 webkit_source.setExtraData(audio_source); 105 WebRtcAudioCapturer::CreateCapturer(-1, StreamDeviceInfo(), constraints,
106 nullptr, media_stream_source));
107 capturer->SetCapturerSource(audio_source, params);
108 media_stream_source->SetAudioCapturer(std::move(capturer));
109 }
110 web_media_stream_source.setExtraData(
111 media_stream_source); // Takes ownership.
124 112
125 blink::WebMediaStreamTrack web_media_audio_track; 113 blink::WebMediaStreamTrack web_media_stream_track;
126 web_media_audio_track.initialize(webkit_source); 114 web_media_stream_track.initialize(web_media_stream_source);
127 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory()-> 115 RenderThreadImpl::current()
128 CreateLocalAudioTrack(web_media_audio_track); 116 ->GetPeerConnectionDependencyFactory()
117 ->CreateLocalAudioTrack(web_media_stream_track);
129 118
130 web_stream->addTrack(web_media_audio_track); 119 web_media_stream->addTrack(web_media_stream_track);
131 return true; 120 return true;
132 } 121 }
133 122
134 } // namespace content 123 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698