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

Side by Side Diff: content/renderer/media/media_stream_impl.cc

Issue 7990004: Adding support for MediaStream and PeerConnection functionality. (Closed) Base URL: http://git.chromium.org/chromium/chromium.git@trunk
Patch Set: Created 9 years, 3 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_impl.h" 5 #include "content/renderer/media/media_stream_impl.h"
6 6
7 #include "base/string_util.h" 7 #include <vector>
8
9 #include "base/logging.h"
10 #include "base/synchronization/waitable_event.h"
11 #include "base/utf_string_conversions.h"
12 #include "content/common/media/media_stream_options.h"
8 #include "content/renderer/media/capture_video_decoder.h" 13 #include "content/renderer/media/capture_video_decoder.h"
14 #include "content/renderer/media/media_stream_dispatcher.h"
15 #include "content/renderer/media/rtc_video_decoder.h"
9 #include "content/renderer/media/video_capture_impl_manager.h" 16 #include "content/renderer/media/video_capture_impl_manager.h"
10 #include "googleurl/src/gurl.h" 17 #include "content/renderer/media/video_capture_module_impl.h"
18 #include "content/renderer/media/webrtc_audio_device_impl.h"
19 #include "content/renderer/p2p/ipc_network_manager.h"
20 #include "content/renderer/p2p/ipc_socket_factory.h"
21 #include "content/renderer/p2p/socket_dispatcher.h"
22 #include "jingle/glue/thread_wrapper.h"
11 #include "media/base/message_loop_factory.h" 23 #include "media/base/message_loop_factory.h"
12 #include "media/base/pipeline.h" 24 #include "third_party/libjingle/source/talk/p2p/client/httpportallocator.h"
25 #include "third_party/libjingle/source/talk/session/phone/dummydevicemanager.h"
26 #include "third_party/libjingle/source/talk/session/phone/webrtcmediaengine.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamControl ler.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamTrackLi st.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamTrack.h "
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
13 35
14 namespace { 36 namespace {
15 37
16 static const int kVideoCaptureWidth = 352; 38 static const int kVideoCaptureWidth = 352;
17 static const int kVideoCaptureHeight = 288; 39 static const int kVideoCaptureHeight = 288;
18 static const int kVideoCaptureFramePerSecond = 30; 40 static const int kVideoCaptureFramePerSecond = 30;
19 41
20 static const int kStartOpenSessionId = 1;
21
22 // TODO(wjia): remove this string when full media stream code is checked in.
23 static const char kRawMediaScheme[] = "mediastream";
24
25 } // namespace 42 } // namespace
26 43
27 MediaStreamImpl::MediaStreamImpl(VideoCaptureImplManager* vc_manager) 44 MediaStreamImpl::MediaStreamImpl(
28 : vc_manager_(vc_manager) { 45 MediaStreamDispatcher* media_stream_dispatcher,
29 } 46 content::P2PSocketDispatcher* p2p_socket_dispatcher,
30 47 VideoCaptureImplManager* vc_manager)
31 MediaStreamImpl::~MediaStreamImpl() {} 48 : controller_(NULL),
49 media_stream_dispatcher_(media_stream_dispatcher),
50 media_engine_(NULL),
51 p2p_socket_dispatcher_(p2p_socket_dispatcher),
52 vc_manager_(vc_manager),
53 peer_connection_id_(-1),
54 signaling_thread_(NULL),
55 worker_thread_(NULL),
56 chrome_worker_thread_("Chrome_libJingle_WorkerThread"),
57 call_state_(NOT_STARTED),
58 vcm_is_created_(false) {
59 message_loop_proxy_ = base::MessageLoopProxy::current();
60 chrome_worker_thread_.Start();
tommi (sloooow) - chröme 2011/09/23 13:02:42 should we do this in newPeerConnection instead? (
grunell (dont use) 2011/09/29 13:38:17 I think so, moved it and added check of return val
61 }
62
63 MediaStreamImpl::~MediaStreamImpl() {
64 if (peer_connection_.get()) {
65 peer_connection_->RegisterObserver(NULL);
66 peer_connection_->Close();
67 }
68 }
69
70 void MediaStreamImpl::setController(
71 WebKit::WebMediaStreamController* controller) {
72 controller_.reset(controller);
73 }
74
75 void MediaStreamImpl::mediaStreamDestroyed() {
76 controller_.reset();
77 }
78
79 void MediaStreamImpl::generateStream(
80 int requestId, WebKit::WebGenerateStreamOptionFlags flags,
tommi (sloooow) - chröme 2011/09/23 13:02:42 see 'BadWrappingStyle' under function declarations
grunell (dont use) 2011/09/29 13:38:17 Done.
81 const WebKit::WebSecurityOrigin& webSecurityOrigin) {
82
83 bool audio = flags & WebKit::WebGenerateStreamRequestAudio;
tommi (sloooow) - chröme 2011/09/23 13:02:42 won't this generate a compiler warning? Should pe
grunell (dont use) 2011/09/29 13:38:17 No it doesn't. It will evaluate and assign with im
84 media_stream::StreamOptions::VideoOption video_option =
85 media_stream::StreamOptions::kNoCamera;
86
87 if ((flags & WebKit::WebGenerateStreamRequestVideoFacingUser) &&
88 (flags & WebKit::WebGenerateStreamRequestVideoFacingEnvironment)) {
89 video_option = media_stream::StreamOptions::kFacingBoth;
90 } else {
91 if (flags & WebKit::WebGenerateStreamRequestVideoFacingEnvironment)
92 video_option = media_stream::StreamOptions::kFacingEnvironment;
93 if (flags & WebKit::WebGenerateStreamRequestVideoFacingUser)
94 video_option = media_stream::StreamOptions::kFacingUser;
95 }
96
97 VLOG(1) << "MediaStreamImpl::generateStream("
98 << requestId << ", [ "
99 << (audio ? "audio " : "")
100 << ((flags &
101 flags & WebKit::WebGenerateStreamRequestVideoFacingUser) ?
102 "video_facing_user " : "")
103 << ((flags &
104 WebKit::WebGenerateStreamRequestVideoFacingEnvironment) ?
105 "video_facing_environment " : "")
106 << "], "
107 << static_cast<string16>(webSecurityOrigin.toString()) << ")";
108
109 media_stream_dispatcher_->GenerateStream(requestId, this,
110 media_stream::StreamOptions(audio, video_option),
111 UTF16ToUTF8(webSecurityOrigin.toString()));
112 }
113
114 void MediaStreamImpl::recordStream(
115 const WebKit::WebString& streamLabel, int recorderId) {
116 // TODO(grunell): Implement.
117 }
118
119 void MediaStreamImpl::getRecordedData(
120 const WebKit::WebString& streamLabel, int recorderId, int requestId) {
121 // TODO(grunell): Implement.
122 }
123
124 void MediaStreamImpl::disposeRecordedData(
125 const WebKit::WebString& streamLabel, int recorderId) {
126 // TODO(grunell): Implement.
127 }
128
129 void MediaStreamImpl::stopGeneratedStream(
130 const WebKit::WebString& streamLabel) {
131 std::string label = UTF16ToUTF8(streamLabel);
132 media_stream_dispatcher_->StopStream(label);
133 }
134
135 void MediaStreamImpl::setMediaStreamTrackEnabled(
136 const WebKit::WebString& trackId, bool enabled) {
137 // TODO(grunell): Implement.
138 }
139
140 void MediaStreamImpl::processSignalingMessage(int peerConnectionId,
141 const WebKit::WebString& message) {
142 VLOG(1) << "MediaStreamImpl::processSignalingMessage("
143 << UTF16ToUTF8(message) << ")";
144 if (peerConnectionId != peer_connection_id_) {
145 DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid";
146 return;
147 }
148 DCHECK(peer_connection_.get());
149 peer_connection_->SignalingMessage(UTF16ToUTF8(message));
150 }
151
152 void MediaStreamImpl::message(
153 int peerConnectionId, const WebKit::WebString& message) {
154 VLOG(1) << "MediaStreamImpl::message(" << UTF16ToUTF8(message) << ")";
155 if (peerConnectionId != peer_connection_id_) {
156 DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid";
157 return;
158 }
159 // TODO(grunell): Implement.
160 }
161
162 void MediaStreamImpl::addStream(int peerConnectionId,
163 const WebKit::WebString& streamLabel) {
164 VLOG(1) << "MediaStreamImpl::addStream(" << peerConnectionId << ", "
165 << UTF16ToUTF8(streamLabel) << ")";
tommi (sloooow) - chröme 2011/09/23 13:02:42 align <<
grunell (dont use) 2011/09/29 13:38:17 Done.
166 if (peerConnectionId != peer_connection_id_) {
167 DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid";
168 return;
169 }
170
171 // TODO(grunell): Fix code in this function after libjingle with new
172 // PeerConnection version has been rolled out.
173
174 if (call_state_ == NOT_STARTED) {
175 DCHECK(peer_connection_.get());
176 // TODO(grunell): Add audio and/or video depending on what's enabled
177 // in the stream.
178 std::string label = UTF16ToUTF8(streamLabel);
179 std::string audioLabel = label;
180 audioLabel.append("-audio");
181 peer_connection_->AddStream(audioLabel, false); // Audio
182 peer_connection_->AddStream(label, true); // Video
183 local_label_ = label;
184 call_state_ = INITIATING;
185 }
186 if (call_state_ == INITIATING || call_state_ == RECEIVING) {
187 if (!vcm_is_created_) {
188 // Set the capture device
189 // TODO(grunell): instead of using the first track,
190 // the selected track should be used.
191 int id = media_stream_dispatcher_->video_session_id(local_label_, 0);
192 if (id != media_stream::StreamDeviceInfo::kNoId) {
193 webrtc::VideoCaptureModule* vcm = new VideoCaptureModuleImpl(
194 id, vc_manager_.get());
195 vcm_is_created_ = true;
196 media_engine_->SetVideoCaptureModule(vcm);
197 peer_connection_->SetVideoCapture("");
198 }
199 }
200 if (call_state_ == INITIATING)
201 peer_connection_->Connect();
202 else if (call_state_ == RECEIVING)
203 call_state_ = SENDING_AND_RECEIVING;
204 } else {
205 DLOG(ERROR) << __FUNCTION__ << ": Multiple calls not supported";
206 return;
207 }
208 }
209
210 void MediaStreamImpl::newPeerConnection(int peerConnectionId,
211 const WebKit::WebString& configuration) {
212 if (peer_connection_.get()) {
213 LOG(ERROR) << __FUNCTION__ << ": A PeerConnection already exists";
214 return;
215 }
216
217 if (!media_engine_) {
218 webrtc::AudioDeviceModule* adm = new WebRtcAudioDeviceImpl();
219 webrtc::AudioDeviceModule* adm_sc = new WebRtcAudioDeviceImpl();
220 media_engine_ = new cricket::WebRtcMediaEngine(adm, adm_sc, NULL);
221 }
222
223 if (!signaling_thread_) {
224 jingle_glue::JingleThreadWrapper::EnsureForCurrentThread();
225 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true);
226 signaling_thread_ = jingle_glue::JingleThreadWrapper::current();
227 }
228
229 if (!worker_thread_) {
230 base::WaitableEvent event(true, false);
231 chrome_worker_thread_.message_loop()->PostTask(
232 FROM_HERE, NewRunnableMethod(
233 this, &MediaStreamImpl::initializeWorkerThread,
234 &worker_thread_, &event));
235 event.Wait();
236 DCHECK(worker_thread_);
237 }
238
239 if (!pc_factory_.get()) {
240 ipc_network_manager_.reset(
241 new content::IpcNetworkManager(p2p_socket_dispatcher_));
242 ipc_socket_factory_.reset(
243 new content::IpcPacketSocketFactory(p2p_socket_dispatcher_));
244 port_allocator_ = new cricket::HttpPortAllocator(
245 ipc_network_manager_.get(), ipc_socket_factory_.get(),
246 "PeerConnection");
247 // TODO(mallinath) - Following flags added to solve crash in HttpClient
248 port_allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
249 cricket::PORTALLOCATOR_DISABLE_RELAY);
250
251 // TODO(mallinath) - PeerConnectionFactory constructor changed in latest
252 // code and it no more accepts config string. Config string must be parsed
253 // here and set in HttpPortAllocator. Now using standard google STUN server
254 // address.
255 std::vector<talk_base::SocketAddress> stun_hosts;
256 stun_hosts.push_back(talk_base::SocketAddress("stun.l.google.com", 19302));
257 port_allocator_->SetStunHosts(stun_hosts);
258
259 pc_factory_.reset(new webrtc::PeerConnectionFactory(port_allocator_,
260 media_engine_, new cricket::DummyDeviceManager(), worker_thread_));
tommi (sloooow) - chröme 2011/09/23 13:02:42 run gcl lint?
grunell (dont use) 2011/09/29 13:38:17 Yes I had done so, no complaints. I fixed the inde
261 if (!pc_factory_->Initialize()) {
262 LOG(ERROR) << __FUNCTION__ << ": Could not initialize PeerConnection "
263 "factory";
264 return;
265 }
266 }
267
268 peer_connection_.reset(pc_factory_.get()->CreatePeerConnection(
269 signaling_thread_));
270 DCHECK(peer_connection_.get());
271 peer_connection_id_ = peerConnectionId;
272 peer_connection_->RegisterObserver(this);
273 }
274
275 void MediaStreamImpl::closePeerConnection(int peerConnectionId) {
276 if (peerConnectionId != peer_connection_id_) {
277 DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid";
278 return;
279 }
280 // TODO(grunell): Fix code in this function after libjingle with new
281 // PeerConnection version has been rolled out.
282 if (call_state_ == RECEIVING || call_state_ == SENDING_AND_RECEIVING)
283 call_state_ = TERMINATING;
284 if (peer_connection_.get())
285 DeletePeerConnection();
286 }
287
288 void MediaStreamImpl::startNegotiation(int peerConnectionId) {
289 if (peerConnectionId != peer_connection_id_) {
290 DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid";
291 return;
292 }
293 // TODO(grunell): Implement. Currently not supported in libjingle.
294 }
295
296 void MediaStreamImpl::removeStream(int peerConnectionId,
297 const WebKit::WebString& streamLabel) {
298 if (peerConnectionId != peer_connection_id_) {
299 DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid";
300 return;
301 }
302 // TODO(grunell): Implement. Currently not supported in libjingle.
303 }
304
305 void MediaStreamImpl::commitStreamChanges(int peerConnectionId) {
306 if (peerConnectionId != peer_connection_id_) {
307 DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid";
308 return;
309 }
310 // TODO(grunell): Implement. Currently not supported in libjingle.
311 }
32 312
33 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( 313 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder(
34 const GURL& url, media::MessageLoopFactory* message_loop_factory) { 314 const GURL& url, media::MessageLoopFactory* message_loop_factory) {
35 bool raw_media = (url.spec().find(kRawMediaScheme) == 0); 315 std::string label =
316 UTF16ToUTF8(WebKit::WebMediaStreamRegistry::mediaStreamLabel(url));
317 if (label.size() == 0)
tommi (sloooow) - chröme 2011/09/23 13:02:42 if (label.empty())
grunell (dont use) 2011/09/29 13:38:17 Done.
318 return NULL; // This is not a valid stream.
319
36 media::VideoDecoder* decoder = NULL; 320 media::VideoDecoder* decoder = NULL;
37 if (raw_media) { 321 if (media_stream_dispatcher_->IsStream(label)) {
322 // It's a local stream.
323 int video_session_id = media_stream_dispatcher_->video_session_id(label, 0);
38 media::VideoCapture::VideoCaptureCapability capability; 324 media::VideoCapture::VideoCaptureCapability capability;
39 capability.width = kVideoCaptureWidth; 325 capability.width = kVideoCaptureWidth;
40 capability.height = kVideoCaptureHeight; 326 capability.height = kVideoCaptureHeight;
41 capability.max_fps = kVideoCaptureFramePerSecond; 327 capability.max_fps = kVideoCaptureFramePerSecond;
42 capability.expected_capture_delay = 0; 328 capability.expected_capture_delay = 0;
43 capability.raw_type = media::VideoFrame::I420; 329 capability.raw_type = media::VideoFrame::I420;
44 capability.interlaced = false; 330 capability.interlaced = false;
45 capability.resolution_fixed = false; 331 capability.resolution_fixed = false;
46
47 decoder = new CaptureVideoDecoder( 332 decoder = new CaptureVideoDecoder(
48 message_loop_factory->GetMessageLoopProxy("CaptureVideoDecoder").get(), 333 message_loop_factory->GetMessageLoopProxy("CaptureVideoDecoderThread"),
49 kStartOpenSessionId, vc_manager_.get(), capability); 334 video_session_id, vc_manager_.get(), capability);
50 } 335 } else {
51 return decoder; 336 // It's a remote stream.
52 } 337 DCHECK(label.size());
338 if (rtc_video_decoder_.get()) {
339 // The renderer is used by PeerConnection, release it first.
340 size_t found = label.rfind("-remote");
341 if (found != std::string::npos)
342 label = label.substr(0, found);
343 if (peer_connection_.get()) {
344 peer_connection_->SetVideoRenderer(label, NULL);
345 }
346 }
347 rtc_video_decoder_ = new RTCVideoDecoder(
348 message_loop_factory->GetMessageLoop("RtcVideoDecoderThread"),
349 url.spec());
350 decoder = rtc_video_decoder_;
351 size_t found = label.rfind("-remote");
352 if (found != std::string::npos)
353 label = label.substr(0, found);
354 if (peer_connection_.get()) {
355 peer_connection_->SetVideoRenderer(label, rtc_video_decoder_);
356 }
357 }
358 scoped_refptr<media::VideoDecoder> sr_decoder(decoder);
tommi (sloooow) - chröme 2011/09/23 13:02:42 why not make decoder a scoped_refptr from the begi
grunell (dont use) 2011/09/29 13:38:17 Done.
359 return sr_decoder;
360 }
361
362 void MediaStreamImpl::OnStreamGenerated(
363 int requestId, const std::string& label,
364 const media_stream::StreamDeviceInfoArray& audio_array,
365 const media_stream::StreamDeviceInfoArray& video_array) {
366 VLOG(1) << "MediaStreamImpl::OnStreamGenerated(" << requestId << ", "
367 << label << ")";
368 DCHECK(controller_.get());
369
370 WebKit::WebVector<WebKit::WebMediaStreamTrack> web_track_vector(
371 audio_array.size() + video_array.size());
372
373 int track_num = 0;
374 for (media_stream::StreamDeviceInfoArray::const_iterator
375 it = audio_array.begin(); it != audio_array.end(); ++it) {
tommi (sloooow) - chröme 2011/09/23 13:02:42 indent
tommi (sloooow) - chröme 2011/09/23 13:02:42 is the iterator used? Could you instead just do:
grunell (dont use) 2011/09/29 13:38:17 Agree, with some modification to set audio and vid
grunell (dont use) 2011/09/29 13:38:17 Done.
376 web_track_vector[track_num].initialize(
377 WebKit::WebString::fromUTF8(""),
tommi (sloooow) - chröme 2011/09/23 13:02:42 initialize all these strings outside the loop.
grunell (dont use) 2011/09/29 13:38:17 Done.
grunell (dont use) 2011/09/29 13:38:17 Done.
378 WebKit::WebString::fromUTF8("main"),
379 WebKit::WebString::fromUTF8("AudioDevice"));
380 ++track_num;
381 }
382
383 for (media_stream::StreamDeviceInfoArray::const_iterator
tommi (sloooow) - chröme 2011/09/23 13:02:42 same iterator question
grunell (dont use) 2011/09/29 13:38:17 Done.
384 it = video_array.begin(); it != video_array.end(); ++it) {
tommi (sloooow) - chröme 2011/09/23 13:02:42 indent
grunell (dont use) 2011/09/29 13:38:17 Done.
385 web_track_vector[track_num].initialize(
386 WebKit::WebString::fromUTF8(""),
tommi (sloooow) - chröme 2011/09/23 13:02:42 initialize outside of the loop
grunell (dont use) 2011/09/29 13:38:17 Done.
387 WebKit::WebString::fromUTF8("main"),
388 WebKit::WebString::fromUTF8("VideoCapture"));
389 ++track_num;
390 }
391
392 local_label_ = label;
393
394 WebKit::WebMediaStreamTrackList web_track_list;
395 web_track_list.initialize(web_track_vector);
396 controller_->streamGenerated(
397 requestId, UTF8ToUTF16(label), web_track_list);
398 }
399
400 void MediaStreamImpl::OnStreamGenerationFailed(int requestId) {
tommi (sloooow) - chröme 2011/09/23 13:02:42 fix parameter names to chromium style.
grunell (dont use) 2011/09/29 13:38:17 Done for all functions.
401 VLOG(1) << "MediaStreamImpl::OnStreamGenerationFailed("
402 << requestId << ")\n";
403 DCHECK(controller_.get());
404 controller_->streamGenerationFailed(
405 requestId,
406 WebKit::WebMediaStreamController::ErrorPermissionDenied);
407 }
408
409 void MediaStreamImpl::OnVideoDeviceFailed(const std::string& label,
410 int index) {
411 VLOG(1) << "MediaStreamImpl::OnVideoDeviceFailed("
412 << label << ", " << index << ")\n";
413 DCHECK(controller_.get());
414 controller_->streamFailed(UTF8ToUTF16(label));
415 }
416
417 void MediaStreamImpl::OnAudioDeviceFailed(const std::string& label,
418 int index) {
419 VLOG(1) << "MediaStreamImpl::OnAudioDeviceFailed("
420 << label << ", " << index << ")\n";
421 DCHECK(controller_.get());
422 controller_->streamFailed(UTF8ToUTF16(label));
423 }
424
425 void MediaStreamImpl::OnError() {
426 VLOG(1) << "MediaStreamImpl::OnError()";
427
428 if (!message_loop_proxy_->BelongsToCurrentThread()) {
429 message_loop_proxy_->PostTask(
430 FROM_HERE,
431 NewRunnableMethod(this, &MediaStreamImpl::OnError));
432 }
433
434 DCHECK(controller_.get());
435 WebKit::WebString message("PeerConnection error.");
436 controller_->error(peer_connection_id_, message);
437 }
438
439 void MediaStreamImpl::OnSignalingMessage(const std::string& msg) {
440 VLOG(1) << "MediaStreamImpl::OnSignalingMessage(" << msg << ")";
441
442 if (!message_loop_proxy_->BelongsToCurrentThread()) {
443 message_loop_proxy_->PostTask(
444 FROM_HERE,
445 NewRunnableMethod(this, &MediaStreamImpl::OnSignalingMessage, msg));
446 return;
447 }
448
449 DCHECK(controller_.get());
450 controller_->onSignalingMessage(peer_connection_id_, UTF8ToUTF16(msg));
451 }
452
453 void MediaStreamImpl::OnAddStream(const std::string& stream_id, bool video) {
454 VLOG(1) << "MediaStreamImpl::OnAddStream(" << stream_id << ", "
455 << video << ")";
tommi (sloooow) - chröme 2011/09/23 13:02:42 indent
grunell (dont use) 2011/09/29 13:38:17 Done.
456
457 DCHECK(controller_.get());
458
459 // TODO(grunell): Fix code in this function after libjingle with new
460 // PeerConnection version has been rolled out.
461 if (video) {
462 if (call_state_ == NOT_STARTED) {
463 remote_label_ = stream_id;
464 call_state_ = RECEIVING;
465 } else if (call_state_ == INITIATING) {
466 std::string label = local_label_;
467 label += "-remote";
468 remote_label_ = label;
469 call_state_ = SENDING_AND_RECEIVING;
470 }
471
472 if (!message_loop_proxy_->BelongsToCurrentThread()) {
473 message_loop_proxy_->PostTask(
474 FROM_HERE,
475 NewRunnableMethod(this,
476 &MediaStreamImpl::OnAddStreamCallback,
477 remote_label_));
478 return;
479 } else {
480 OnAddStreamCallback(remote_label_);
481 }
482 }
483 }
484
485 void MediaStreamImpl::OnRemoveStream(const std::string& stream_id, bool video) {
486 VLOG(1) << "MediaStreamImpl::OnRemoveStream(" << stream_id << ", "
487 << video << ")";
488
489 if (video) {
490 if (!message_loop_proxy_->BelongsToCurrentThread())
tommi (sloooow) - chröme 2011/09/23 13:02:42 use braces
grunell (dont use) 2011/09/29 13:38:17 Done.
491 message_loop_proxy_->PostTask(
492 FROM_HERE,
493 NewRunnableMethod(this, &MediaStreamImpl::OnRemoveStreamCallback,
494 remote_label_));
495 else
496 OnRemoveStreamCallback(remote_label_);
497 }
498 }
499
500 void MediaStreamImpl::OnAddStreamCallback(std::string streamLabel) {
501 size_t size = 1;
502 WebKit::WebVector<WebKit::WebMediaStreamTrack> web_track_vector(size);
503 web_track_vector[0].initialize(WebKit::WebString::fromUTF8(""),
504 WebKit::WebString::fromUTF8("main"),
505 WebKit::WebString::fromUTF8(streamLabel));
506 WebKit::WebMediaStreamTrackList web_track_list;
507 web_track_list.initialize(web_track_vector);
508 controller_->onAddStream(peer_connection_id_,
509 UTF8ToUTF16(streamLabel), web_track_list);
510 }
511
512 void MediaStreamImpl::OnRemoveStreamCallback(std::string streamLabel) {
513 DCHECK(controller_.get());
514 controller_->onRemoveStream(peer_connection_id_, UTF8ToUTF16(streamLabel));
515 }
516
517 void MediaStreamImpl::DeletePeerConnection() {
518 DCHECK(peer_connection_.get());
519 peer_connection_->RegisterObserver(NULL);
520 peer_connection_.reset();
521 peer_connection_id_ = -1;
522 rtc_video_decoder_ = NULL;
523 media_engine_->SetVideoCaptureModule(NULL);
524 vcm_is_created_ = false;
525 call_state_ = NOT_STARTED;
526 }
527
528 void MediaStreamImpl::initializeWorkerThread(talk_base::Thread** thread,
529 base::WaitableEvent* event) {
530 jingle_glue::JingleThreadWrapper::EnsureForCurrentThread();
531 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true);
532 *thread = jingle_glue::JingleThreadWrapper::current();
533 event->Signal();
534 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698