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()); | |
Tommy Widenflycht
2012/05/14 12:15:16
If extradata is null (which will happen for MediaS
perkj_chrome
2012/05/14 12:55:39
Done.
| |
41 if (extra_data && extra_data->remote_stream()) | |
42 return extra_data->remote_stream(); | |
43 | |
44 if (extra_data && extra_data->local_stream()) | |
45 return extra_data->local_stream(); | |
46 | |
47 NOTREACHED(); | |
48 return NULL; | |
49 } | |
50 | |
51 template <class TrackList> | |
52 static webrtc::MediaStreamTrackInterface* GetTrack( | |
53 const std::string& source_id, | |
54 TrackList* tracks) { | |
55 for (size_t i = 0; i < tracks->count(); ++i) { | |
56 if (tracks->at(i)->label() == source_id) | |
57 return tracks->at(i); | |
58 } | |
59 return NULL; | |
60 } | |
61 | |
62 static webrtc::MediaStreamTrackInterface* GetNativeMediaStreamTrack( | |
63 const WebKit::WebMediaStreamDescriptor& stream, | |
64 const WebKit::WebMediaStreamComponent& component) { | |
65 std::string source_id = UTF16ToUTF8(component.source().id()); | |
66 webrtc::MediaStreamInterface* native_stream = GetNativeMediaStream(stream); | |
67 if (native_stream) { | |
68 if (component.source().type() == WebKit::WebMediaStreamSource::TypeAudio) { | |
69 return GetTrack<webrtc::AudioTracks>( | |
70 source_id, native_stream->audio_tracks()); | |
71 } | |
72 if (component.source().type() == WebKit::WebMediaStreamSource::TypeVideo) { | |
73 return GetTrack<webrtc::VideoTracks>( | |
74 source_id, native_stream->video_tracks()); | |
75 } | |
76 } | |
77 NOTREACHED(); | |
Tommy Widenflycht
2012/05/14 12:15:16
See previous comment.
perkj_chrome
2012/05/14 12:55:39
Done.
| |
78 return NULL; | |
79 } | |
80 | |
23 MediaStreamCenter::MediaStreamCenter( | 81 MediaStreamCenter::MediaStreamCenter( |
24 WebKit::WebMediaStreamCenterClient* client) | 82 WebKit::WebMediaStreamCenterClient* client) |
25 : client_(client) { | 83 : client_(client) { |
26 } | 84 } |
27 | 85 |
28 void MediaStreamCenter::queryMediaStreamSources( | 86 void MediaStreamCenter::queryMediaStreamSources( |
29 const WebKit::WebMediaStreamSourcesRequest& request) { | 87 const WebKit::WebMediaStreamSourcesRequest& request) { |
30 WebKit::WebVector<WebKit::WebMediaStreamSource> audioSources, videoSources; | 88 WebKit::WebVector<WebKit::WebMediaStreamSource> audioSources, videoSources; |
31 request.didCompleteQuery(audioSources, videoSources); | 89 request.didCompleteQuery(audioSources, videoSources); |
32 } | 90 } |
33 | 91 |
34 void MediaStreamCenter::didEnableMediaStreamTrack( | 92 void MediaStreamCenter::didEnableMediaStreamTrack( |
35 const WebKit::WebMediaStreamDescriptor& stream, | 93 const WebKit::WebMediaStreamDescriptor& stream, |
36 const WebKit::WebMediaStreamComponent& component) { | 94 const WebKit::WebMediaStreamComponent& component) { |
95 webrtc::MediaStreamTrackInterface* track = | |
96 GetNativeMediaStreamTrack(stream, component); | |
97 if (track) | |
98 track->set_enabled(true); | |
37 } | 99 } |
38 | 100 |
39 void MediaStreamCenter::didDisableMediaStreamTrack( | 101 void MediaStreamCenter::didDisableMediaStreamTrack( |
40 const WebKit::WebMediaStreamDescriptor& stream, | 102 const WebKit::WebMediaStreamDescriptor& stream, |
41 const WebKit::WebMediaStreamComponent& component) { | 103 const WebKit::WebMediaStreamComponent& component) { |
104 webrtc::MediaStreamTrackInterface* track = | |
105 GetNativeMediaStreamTrack(stream, component); | |
106 if (track) | |
107 track->set_enabled(false); | |
42 } | 108 } |
43 | 109 |
44 void MediaStreamCenter::didStopLocalMediaStream( | 110 void MediaStreamCenter::didStopLocalMediaStream( |
45 const WebKit::WebMediaStreamDescriptor& stream) { | 111 const WebKit::WebMediaStreamDescriptor& stream) { |
112 DVLOG(1) << "MediaStreamCenter::didStopLocalMediaStream"; | |
113 WebKit::WebFrame* web_frame = WebKit::WebFrame::frameForCurrentContext(); | |
114 if (!web_frame) | |
115 return; | |
116 MediaStreamImpl* ms_impl = GetMediaStreamImpl(web_frame); | |
117 if (ms_impl) { | |
118 ms_impl->StopLocalMediaStream(stream); | |
119 return; | |
120 } | |
121 | |
122 NOTREACHED(); | |
46 } | 123 } |
47 | 124 |
48 void MediaStreamCenter::didConstructMediaStream( | 125 void MediaStreamCenter::didCreateMediaStream( |
49 const WebKit::WebMediaStreamDescriptor& stream) { | 126 WebKit::WebMediaStreamDescriptor& stream) { |
127 WebKit::WebFrame* web_frame = WebKit::WebFrame::frameForCurrentContext(); | |
128 if (!web_frame) | |
129 return; | |
130 MediaStreamImpl* ms_impl = GetMediaStreamImpl(web_frame); | |
131 if (ms_impl) { | |
132 ms_impl->CreateMediaStream(web_frame, &stream); | |
133 return; | |
134 } | |
135 NOTREACHED(); | |
Tommy Widenflycht
2012/05/14 12:15:16
Remove or change.
perkj_chrome
2012/05/14 12:55:39
Its an error to end up here.
| |
50 } | 136 } |
51 | 137 |
52 WebKit::WebString MediaStreamCenter::constructSDP( | 138 WebKit::WebString MediaStreamCenter::constructSDP( |
53 const WebKit::WebICECandidateDescriptor& candidate) { | 139 const WebKit::WebICECandidateDescriptor& candidate) { |
54 scoped_ptr<webrtc::IceCandidateInterface> native_candidate( | 140 scoped_ptr<webrtc::IceCandidateInterface> native_candidate( |
55 webrtc::CreateIceCandidate(UTF16ToUTF8(candidate.label()), | 141 webrtc::CreateIceCandidate(UTF16ToUTF8(candidate.label()), |
56 UTF16ToUTF8(candidate.candidateLine()))); | 142 UTF16ToUTF8(candidate.candidateLine()))); |
57 std::string sdp; | 143 std::string sdp; |
58 if (!native_candidate->ToString(&sdp)) | 144 if (!native_candidate->ToString(&sdp)) |
59 LOG(ERROR) << "Could not create SDP string"; | 145 LOG(ERROR) << "Could not create SDP string"; |
(...skipping 15 matching lines...) Expand all Loading... | |
75 native_desc->AddCandidate(native_candidate.get()); | 161 native_desc->AddCandidate(native_candidate.get()); |
76 } | 162 } |
77 | 163 |
78 std::string sdp; | 164 std::string sdp; |
79 if (!native_desc->ToString(&sdp)) | 165 if (!native_desc->ToString(&sdp)) |
80 LOG(ERROR) << "Could not create SDP string"; | 166 LOG(ERROR) << "Could not create SDP string"; |
81 return UTF8ToUTF16(sdp); | 167 return UTF8ToUTF16(sdp); |
82 } | 168 } |
83 | 169 |
84 } // namespace content | 170 } // namespace content |
OLD | NEW |