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

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

Powered by Google App Engine
This is Rietveld 408576698