Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 blink::WebString MakeTrackId() { | 25 blink::WebString MakeTrackId() { |
| 26 std::string track_id; | 26 std::string track_id; |
| 27 base::Base64Encode(base::RandBytesAsString(64), &track_id); | 27 base::Base64Encode(base::RandBytesAsString(64), &track_id); |
| 28 return base::UTF8ToUTF16(track_id); | 28 return base::UTF8ToUTF16(track_id); |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 bool AddVideoTrackToMediaStream( | 33 bool AddVideoTrackToMediaStream(scoped_ptr<media::VideoCapturerSource> source, |
| 34 scoped_ptr<media::VideoCapturerSource> source, | 34 bool is_remote, |
| 35 bool is_remote, | 35 bool is_readonly, |
| 36 bool is_readonly, | 36 const std::string& media_stream_url) { |
| 37 const std::string& media_stream_url) { | |
| 38 blink::WebMediaStream web_stream = | 37 blink::WebMediaStream web_stream = |
| 39 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor( | 38 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor( |
| 40 GURL(media_stream_url)); | 39 GURL(media_stream_url)); |
| 41 return AddVideoTrackToMediaStream(source.Pass(), is_remote, is_readonly, | 40 return AddVideoTrackToMediaStream(source.Pass(), is_remote, is_readonly, |
| 42 &web_stream); | 41 &web_stream); |
| 43 } | 42 } |
| 44 | 43 |
| 44 bool AddVideoTrackToMediaStream(scoped_ptr<media::VideoCapturerSource> source, | |
| 45 bool is_remote, | |
| 46 bool is_readonly, | |
| 47 blink::WebMediaStream* web_stream) { | |
| 48 if (web_stream->isNull()) { | |
| 49 DLOG(ERROR) << "Stream not found"; | |
| 50 return false; | |
| 51 } | |
| 52 const blink::WebString track_id = MakeTrackId(); | |
| 53 blink::WebMediaStreamSource webkit_source; | |
| 54 scoped_ptr<MediaStreamVideoSource> media_stream_source( | |
| 55 new MediaStreamVideoCapturerSource( | |
| 56 MediaStreamSource::SourceStoppedCallback(), source.Pass())); | |
| 57 webkit_source.initialize(track_id, blink::WebMediaStreamSource::TypeVideo, | |
| 58 track_id, is_remote, is_readonly); | |
| 59 webkit_source.setExtraData(media_stream_source.get()); | |
| 60 | |
| 61 blink::WebMediaConstraints constraints; | |
| 62 constraints.initialize(); | |
| 63 web_stream->addTrack(MediaStreamVideoTrack::CreateVideoTrack( | |
| 64 media_stream_source.release(), constraints, | |
| 65 MediaStreamVideoSource::ConstraintsCallback(), true)); | |
| 66 return true; | |
| 67 } | |
| 68 | |
| 45 bool AddAudioTrackToMediaStream( | 69 bool AddAudioTrackToMediaStream( |
| 46 const scoped_refptr<media::AudioCapturerSource>& source, | 70 const scoped_refptr<media::AudioCapturerSource>& source, |
| 47 const media::AudioParameters& params, | 71 const media::AudioParameters& params, |
| 48 bool is_remote, | 72 bool is_remote, |
| 49 bool is_readonly, | 73 bool is_readonly, |
| 50 const std::string& media_stream_url) { | 74 const std::string& media_stream_url) { |
| 51 DCHECK(params.IsValid()) << params.AsHumanReadableString(); | 75 DCHECK(params.IsValid()) << params.AsHumanReadableString(); |
| 52 blink::WebMediaStream web_stream = | 76 blink::WebMediaStream web_stream = |
| 53 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor( | 77 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor( |
| 54 GURL(media_stream_url)); | 78 GURL(media_stream_url)); |
| 55 if (web_stream.isNull()) { | 79 return AddAudioTrackToMediaStream(source, |
| 80 // params, | |
| 81 is_remote, is_readonly, &web_stream); | |
| 82 } | |
| 83 | |
| 84 bool AddAudioTrackToMediaStream( | |
| 85 const scoped_refptr<media::AudioCapturerSource>& source, | |
| 86 // const media::AudioParameters& params, | |
| 87 bool is_remote, | |
| 88 bool is_readonly, | |
| 89 blink::WebMediaStream* web_stream) { | |
| 90 if (web_stream->isNull()) { | |
| 56 DLOG(ERROR) << "Stream not found"; | 91 DLOG(ERROR) << "Stream not found"; |
| 57 return false; | 92 return false; |
| 58 } | 93 } |
| 94 | |
| 95 media::AudioParameters params( | |
| 96 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO, | |
| 97 48000, // audio_config.rtp_timebase, // sampling rate | |
|
mcasas
2015/11/17 21:56:00
Please clean up these comments.
ajose
2015/11/18 03:35:27
Done.
| |
| 98 16, | |
| 99 480); // audio_config.rtp_timebase / audio_config.target_frame_rate); | |
| 100 | |
| 59 blink::WebMediaStreamSource webkit_source; | 101 blink::WebMediaStreamSource webkit_source; |
| 60 const blink::WebString track_id = MakeTrackId(); | 102 const blink::WebString track_id = MakeTrackId(); |
| 61 webkit_source.initialize(track_id, | 103 webkit_source.initialize(track_id, |
| 62 blink::WebMediaStreamSource::TypeAudio, | 104 blink::WebMediaStreamSource::TypeAudio, |
| 63 track_id, | 105 track_id, |
| 64 is_remote, | 106 is_remote, |
| 65 is_readonly); | 107 is_readonly); |
| 66 | 108 |
| 67 MediaStreamAudioSource* audio_source( | 109 MediaStreamAudioSource* audio_source( |
| 68 new MediaStreamAudioSource( | 110 new MediaStreamAudioSource( |
| 69 -1, | 111 -1, |
| 70 StreamDeviceInfo(), | 112 StreamDeviceInfo(), |
| 71 MediaStreamSource::SourceStoppedCallback(), | 113 MediaStreamSource::SourceStoppedCallback(), |
| 72 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory())); | 114 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory())); |
| 73 | 115 |
| 74 blink::WebMediaConstraints constraints; | 116 blink::WebMediaConstraints constraints; |
| 75 constraints.initialize(); | 117 constraints.initialize(); |
| 76 scoped_refptr<WebRtcAudioCapturer> capturer( | 118 scoped_refptr<WebRtcAudioCapturer> capturer( |
| 77 WebRtcAudioCapturer::CreateCapturer(-1, StreamDeviceInfo(), constraints, | 119 WebRtcAudioCapturer::CreateCapturer(-1, StreamDeviceInfo(), constraints, |
| 78 nullptr, audio_source)); | 120 nullptr, audio_source)); |
| 79 capturer->SetCapturerSource(source, params); | 121 capturer->SetCapturerSource(source, params); |
| 80 audio_source->SetAudioCapturer(capturer); | 122 audio_source->SetAudioCapturer(capturer); |
| 81 webkit_source.setExtraData(audio_source); | 123 webkit_source.setExtraData(audio_source); |
| 82 | 124 |
| 83 blink::WebMediaStreamTrack web_media_audio_track; | 125 blink::WebMediaStreamTrack web_media_audio_track; |
| 84 web_media_audio_track.initialize(webkit_source); | 126 web_media_audio_track.initialize(webkit_source); |
| 85 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory()-> | 127 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory()-> |
| 86 CreateLocalAudioTrack(web_media_audio_track); | 128 CreateLocalAudioTrack(web_media_audio_track); |
| 87 | 129 |
| 88 web_stream.addTrack(web_media_audio_track); | 130 web_stream->addTrack(web_media_audio_track); |
| 89 return true; | 131 return true; |
| 90 } | 132 } |
| 91 | 133 |
| 92 bool AddVideoTrackToMediaStream(scoped_ptr<media::VideoCapturerSource> source, | |
| 93 bool is_remote, | |
| 94 bool is_readonly, | |
| 95 blink::WebMediaStream* web_stream) { | |
| 96 if (web_stream->isNull()) { | |
| 97 DLOG(ERROR) << "Stream not found"; | |
| 98 return false; | |
| 99 } | |
| 100 const blink::WebString track_id = MakeTrackId(); | |
| 101 blink::WebMediaStreamSource webkit_source; | |
| 102 scoped_ptr<MediaStreamVideoSource> media_stream_source( | |
| 103 new MediaStreamVideoCapturerSource( | |
| 104 MediaStreamSource::SourceStoppedCallback(), | |
| 105 source.Pass())); | |
| 106 webkit_source.initialize(track_id, | |
| 107 blink::WebMediaStreamSource::TypeVideo, | |
| 108 track_id, | |
| 109 is_remote, | |
| 110 is_readonly); | |
| 111 webkit_source.setExtraData(media_stream_source.get()); | |
| 112 | |
| 113 blink::WebMediaConstraints constraints; | |
| 114 constraints.initialize(); | |
| 115 web_stream->addTrack(MediaStreamVideoTrack::CreateVideoTrack( | |
| 116 media_stream_source.release(), | |
| 117 constraints, | |
| 118 MediaStreamVideoSource::ConstraintsCallback(), | |
| 119 true)); | |
| 120 return true; | |
| 121 } | |
| 122 | |
| 123 } // namespace content | 134 } // namespace content |
| OLD | NEW |