OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_center.h" | 5 #include "content/renderer/media/media_stream_center.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "content/renderer/media/media_stream_impl.h" | |
13 #include "content/renderer/media/media_stream_extra_data.h" | |
14 #include "content/renderer/render_view_impl.h" | |
12 #include "third_party/libjingle/source/talk/app/webrtc/jsep.h" | 15 #include "third_party/libjingle/source/talk/app/webrtc/jsep.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebICECandid ateDescriptor.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebICECandid ateDescriptor.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amCenterClient.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amCenterClient.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amComponent.h" | |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amDescriptor.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amDescriptor.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSourcesRequest.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSourcesRequest.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSessionDe scriptionDescriptor.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSessionDe scriptionDescriptor.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
20 | 25 |
21 namespace content { | 26 namespace content { |
22 | 27 |
28 static MediaStreamImpl* GetMediaStreamImpl(WebKit::WebFrame* web_frame) { | |
29 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view()); | |
30 if (!render_view) | |
31 return NULL; | |
32 | |
33 // TODO(perkj): Avoid this cast? | |
34 return static_cast<MediaStreamImpl*>(render_view->userMediaClient()); | |
35 } | |
36 | |
37 static webrtc::MediaStreamInterface* GetNativeMediaStream( | |
38 const WebKit::WebMediaStreamDescriptor& stream) { | |
39 MediaStreamExtraData* extra_data = | |
40 static_cast<MediaStreamExtraData*>(stream.extraData()); | |
tommi (sloooow) - chröme
2012/05/13 20:08:46
indent
perkj_chrome
2012/05/14 11:50:25
Done.
| |
41 if (extra_data && extra_data->remote_stream()) | |
42 return extra_data->remote_stream(); | |
43 if (extra_data && extra_data->local_stream()) | |
tommi (sloooow) - chröme
2012/05/13 20:08:46
empty line before this one (looks as if it's an el
perkj_chrome
2012/05/14 11:50:25
Done.
| |
44 return extra_data->local_stream(); | |
45 else | |
tommi (sloooow) - chröme
2012/05/13 20:08:46
nit: no need for this else
perkj_chrome
2012/05/14 11:50:25
Done.
| |
46 NOTREACHED(); | |
47 return NULL; | |
48 } | |
49 | |
50 template <class TrackList> | |
51 static webrtc::MediaStreamTrackInterface* GetTrack( | |
52 const std::string& source_id, | |
53 TrackList* tracks) { | |
54 for (size_t i = 0; i < tracks->count(); ++i) { | |
55 if (tracks->at(i)->label() == source_id) | |
56 return tracks->at(i); | |
57 } | |
58 return NULL; | |
59 } | |
60 | |
61 static webrtc::MediaStreamTrackInterface* GetNativeMediaStreamTrack( | |
62 const WebKit::WebMediaStreamDescriptor& stream, | |
63 const WebKit::WebMediaStreamComponent& component) { | |
64 std::string source_id = UTF16ToUTF8(component.source().id()); | |
65 webrtc::MediaStreamInterface* native_stream = GetNativeMediaStream( | |
66 stream); | |
67 if (native_stream) { | |
68 if (component.source().type() == WebKit::WebMediaStreamSource::TypeAudio) | |
69 return GetTrack<webrtc::AudioTracks>( | |
tommi (sloooow) - chröme
2012/05/13 20:08:46
use {} whenever the body of an if() spans more tha
perkj_chrome
2012/05/14 11:50:25
Done.
| |
70 source_id, native_stream->audio_tracks()); | |
71 if (component.source().type() == WebKit::WebMediaStreamSource::TypeVideo) | |
72 return GetTrack<webrtc::VideoTracks>( | |
73 source_id, native_stream->video_tracks()); | |
74 } else { | |
75 NOTREACHED(); | |
76 } | |
77 return NULL; | |
78 } | |
79 | |
23 MediaStreamCenter::MediaStreamCenter( | 80 MediaStreamCenter::MediaStreamCenter( |
24 WebKit::WebMediaStreamCenterClient* client) | 81 WebKit::WebMediaStreamCenterClient* client) |
25 : client_(client) { | 82 : client_(client) { |
26 } | 83 } |
27 | 84 |
28 void MediaStreamCenter::queryMediaStreamSources( | 85 void MediaStreamCenter::queryMediaStreamSources( |
29 const WebKit::WebMediaStreamSourcesRequest& request) { | 86 const WebKit::WebMediaStreamSourcesRequest& request) { |
30 WebKit::WebVector<WebKit::WebMediaStreamSource> audioSources, videoSources; | 87 WebKit::WebVector<WebKit::WebMediaStreamSource> audioSources, videoSources; |
31 request.didCompleteQuery(audioSources, videoSources); | 88 request.didCompleteQuery(audioSources, videoSources); |
32 } | 89 } |
33 | 90 |
34 void MediaStreamCenter::didEnableMediaStreamTrack( | 91 void MediaStreamCenter::didEnableMediaStreamTrack( |
35 const WebKit::WebMediaStreamDescriptor& stream, | 92 const WebKit::WebMediaStreamDescriptor& stream, |
36 const WebKit::WebMediaStreamComponent& component) { | 93 const WebKit::WebMediaStreamComponent& component) { |
94 webrtc::MediaStreamTrackInterface* track = | |
95 GetNativeMediaStreamTrack(stream, component); | |
96 if (track) | |
97 track->set_enabled(true); | |
37 } | 98 } |
38 | 99 |
39 void MediaStreamCenter::didDisableMediaStreamTrack( | 100 void MediaStreamCenter::didDisableMediaStreamTrack( |
40 const WebKit::WebMediaStreamDescriptor& stream, | 101 const WebKit::WebMediaStreamDescriptor& stream, |
41 const WebKit::WebMediaStreamComponent& component) { | 102 const WebKit::WebMediaStreamComponent& component) { |
103 webrtc::MediaStreamTrackInterface* track = | |
104 GetNativeMediaStreamTrack(stream, component); | |
105 if (track) | |
106 track->set_enabled(false); | |
42 } | 107 } |
43 | 108 |
44 void MediaStreamCenter::didStopLocalMediaStream( | 109 void MediaStreamCenter::didStopLocalMediaStream( |
45 const WebKit::WebMediaStreamDescriptor& stream) { | 110 const WebKit::WebMediaStreamDescriptor& stream) { |
111 DVLOG(1) << "MediaStreamCenter::didStopLocalMediaStream"; | |
112 WebKit::WebFrame* web_frame = WebKit::WebFrame::frameForCurrentContext(); | |
113 if (!web_frame) | |
114 return; | |
115 MediaStreamImpl* ms_impl = GetMediaStreamImpl(web_frame); | |
116 if (ms_impl) | |
117 ms_impl->StopLocalMediaStream(stream); | |
118 else | |
tommi (sloooow) - chröme
2012/05/13 20:08:46
no need for else
perkj_chrome
2012/05/14 11:50:25
Done.
| |
119 NOTREACHED(); | |
46 } | 120 } |
47 | 121 |
48 void MediaStreamCenter::didConstructMediaStream( | 122 void MediaStreamCenter::didCreateMediaStream( |
49 const WebKit::WebMediaStreamDescriptor& stream) { | 123 WebKit::WebMediaStreamDescriptor& stream) { |
124 WebKit::WebFrame* web_frame = WebKit::WebFrame::frameForCurrentContext(); | |
125 if (!web_frame) | |
126 return; | |
127 MediaStreamImpl* ms_impl = GetMediaStreamImpl(web_frame); | |
128 if (ms_impl) | |
129 ms_impl->CreateMediaStream(web_frame, &stream); | |
130 else | |
tommi (sloooow) - chröme
2012/05/13 20:08:46
no need
perkj_chrome
2012/05/14 11:50:25
Done.
| |
131 NOTREACHED(); | |
50 } | 132 } |
51 | 133 |
52 WebKit::WebString MediaStreamCenter::constructSDP( | 134 WebKit::WebString MediaStreamCenter::constructSDP( |
53 const WebKit::WebICECandidateDescriptor& candidate) { | 135 const WebKit::WebICECandidateDescriptor& candidate) { |
54 scoped_ptr<webrtc::IceCandidateInterface> native_candidate( | 136 scoped_ptr<webrtc::IceCandidateInterface> native_candidate( |
55 webrtc::CreateIceCandidate(UTF16ToUTF8(candidate.label()), | 137 webrtc::CreateIceCandidate(UTF16ToUTF8(candidate.label()), |
56 UTF16ToUTF8(candidate.candidateLine()))); | 138 UTF16ToUTF8(candidate.candidateLine()))); |
57 std::string sdp; | 139 std::string sdp; |
58 if (!native_candidate->ToString(&sdp)) | 140 if (!native_candidate->ToString(&sdp)) |
59 LOG(ERROR) << "Could not create SDP string"; | 141 LOG(ERROR) << "Could not create SDP string"; |
(...skipping 15 matching lines...) Expand all Loading... | |
75 native_desc->AddCandidate(native_candidate.get()); | 157 native_desc->AddCandidate(native_candidate.get()); |
76 } | 158 } |
77 | 159 |
78 std::string sdp; | 160 std::string sdp; |
79 if (!native_desc->ToString(&sdp)) | 161 if (!native_desc->ToString(&sdp)) |
80 LOG(ERROR) << "Could not create SDP string"; | 162 LOG(ERROR) << "Could not create SDP string"; |
81 return UTF8ToUTF16(sdp); | 163 return UTF8ToUTF16(sdp); |
82 } | 164 } |
83 | 165 |
84 } // namespace content | 166 } // namespace content |
OLD | NEW |