OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/public/renderer/media_stream_api.h" | |
6 | |
7 #include "base/base64.h" | |
8 #include "base/callback.h" | |
9 #include "base/rand_util.h" | |
10 #include "base/strings/utf_string_conversions.h" | |
11 #include "content/renderer/media/media_stream_audio_source.h" | |
12 #include "content/renderer/media/media_stream_video_capturer_source.h" | |
13 #include "content/renderer/media/media_stream_video_track.h" | |
14 #include "media/base/audio_capturer_source.h" | |
15 #include "media/base/video_capturer_source.h" | |
16 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" | |
17 #include "third_party/WebKit/public/platform/WebMediaStream.h" | |
18 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | |
19 #include "third_party/WebKit/public/platform/WebURL.h" | |
20 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" | |
21 #include "url/gurl.h" | |
22 | |
23 namespace content { | |
24 | |
25 namespace { | |
26 | |
27 blink::WebString MakeTrackId() { | |
28 std::string track_id; | |
29 base::Base64Encode(base::RandBytesAsString(64), &track_id); | |
30 return base::UTF8ToUTF16(track_id); | |
31 } | |
32 | |
33 } // namespace | |
34 | |
35 bool AddVideoTrackToMediaStream( | |
36 scoped_ptr<media::VideoCapturerSource> source, | |
37 bool is_remote, | |
38 bool is_readonly, | |
39 const std::string& media_stream_url) { | |
40 blink::WebMediaStream stream = | |
41 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor( | |
42 GURL(media_stream_url)); | |
43 | |
44 if (stream.isNull()) { | |
45 LOG(ERROR) << "Stream not found"; | |
46 return false; | |
47 } | |
48 blink::WebString track_id = MakeTrackId(); | |
49 blink::WebMediaStreamSource webkit_source; | |
50 scoped_ptr<MediaStreamVideoSource> media_stream_source( | |
51 new content::MediaStreamVideoCapturerSource( | |
jam
2015/03/04 07:07:06
ntit: here and elsewhere, no content:: inside cont
hubbe
2015/03/04 23:12:33
Done.
| |
52 content::MediaStreamSource::SourceStoppedCallback(), | |
53 source.Pass())); | |
54 webkit_source.initialize( | |
55 track_id, | |
56 blink::WebMediaStreamSource::TypeVideo, | |
57 track_id, | |
58 is_remote, | |
59 is_readonly); | |
60 webkit_source.setExtraData(media_stream_source.get()); | |
61 | |
62 blink::WebMediaConstraints constraints; | |
63 constraints.initialize(); | |
64 stream.addTrack(MediaStreamVideoTrack::CreateVideoTrack( | |
65 media_stream_source.release(), | |
66 constraints, | |
67 MediaStreamVideoSource::ConstraintsCallback(), | |
68 true)); | |
69 return true; | |
70 } | |
71 | |
72 bool AddAudioTrackToMediaStream( | |
73 scoped_refptr<media::AudioCapturerSource> source, | |
74 const media::AudioParameters& params, | |
75 bool is_remote, | |
76 bool is_readonly, | |
77 const std::string& media_stream_url) { | |
78 DCHECK(params.IsValid()) << params.AsHumanReadableString(); | |
79 blink::WebMediaStream stream = | |
80 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor( | |
81 GURL(media_stream_url)); | |
82 | |
83 if (stream.isNull()) { | |
84 LOG(ERROR) << "Stream not found"; | |
85 return false; | |
86 } | |
87 blink::WebMediaStreamSource webkit_source; | |
88 blink::WebString track_id = MakeTrackId(); | |
89 webkit_source.initialize( | |
90 track_id, | |
91 blink::WebMediaStreamSource::TypeAudio, | |
92 track_id, | |
93 is_remote, | |
94 is_readonly); | |
95 | |
96 MediaStreamAudioSource* audio_source( | |
97 new MediaStreamAudioSource( | |
jam
2015/03/04 07:07:06
nit: indentation
hubbe
2015/03/04 23:12:33
Done.
| |
98 -1, | |
99 StreamDeviceInfo(), | |
100 content::MediaStreamSource::SourceStoppedCallback(), | |
101 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory())); | |
102 | |
103 blink::WebMediaConstraints constraints; | |
104 constraints.initialize(); | |
105 scoped_refptr<WebRtcAudioCapturer> capturer( | |
106 WebRtcAudioCapturer::CreateCapturer( | |
107 -1, | |
108 StreamDeviceInfo(), | |
109 constraints, | |
110 nullptr, | |
111 audio_source)); | |
112 capturer->SetCapturerSource(source, params); | |
113 audio_source->SetAudioCapturer(capturer); | |
114 webkit_source.setExtraData(audio_source); | |
115 | |
116 blink::WebMediaStreamTrack web_media_audio_track; | |
117 web_media_audio_track.initialize(webkit_source); | |
118 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory()-> | |
119 CreateLocalAudioTrack(web_media_audio_track); | |
120 | |
121 stream.addTrack(web_media_audio_track); | |
122 return true; | |
123 } | |
124 | |
125 } // namespace content | |
OLD | NEW |