| 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_impl.h" | 5 #include "content/renderer/media/media_stream_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 MediaStreamDependencyFactory* dependency_factory) | 62 MediaStreamDependencyFactory* dependency_factory) |
| 63 : content::RenderViewObserver(render_view), | 63 : content::RenderViewObserver(render_view), |
| 64 dependency_factory_(dependency_factory), | 64 dependency_factory_(dependency_factory), |
| 65 media_stream_dispatcher_(media_stream_dispatcher), | 65 media_stream_dispatcher_(media_stream_dispatcher), |
| 66 vc_manager_(vc_manager) { | 66 vc_manager_(vc_manager) { |
| 67 } | 67 } |
| 68 | 68 |
| 69 MediaStreamImpl::~MediaStreamImpl() { | 69 MediaStreamImpl::~MediaStreamImpl() { |
| 70 } | 70 } |
| 71 | 71 |
| 72 void MediaStreamImpl::StopLocalMediaStream( | 72 void MediaStreamImpl::OnLocalMediaStreamStop( |
| 73 const WebKit::WebMediaStreamDescriptor& stream) { | 73 const std::string& label) { |
| 74 DVLOG(1) << "MediaStreamImpl::StopLocalMediaStream"; | 74 DVLOG(1) << "MediaStreamImpl::OnLocalMediaStreamStop"; |
| 75 | 75 media_stream_dispatcher_->StopStream(label); |
| 76 MediaStreamExtraData* extra_data = | 76 local_media_streams_.erase(label); |
| 77 static_cast<MediaStreamExtraData*>(stream.extraData()); | |
| 78 if (extra_data && extra_data->local_stream()) { | |
| 79 media_stream_dispatcher_->StopStream(extra_data->local_stream()->label()); | |
| 80 local_media_streams_.erase(extra_data->local_stream()->label()); | |
| 81 } else { | |
| 82 NOTREACHED(); | |
| 83 } | |
| 84 } | 77 } |
| 85 | 78 |
| 86 void MediaStreamImpl::requestUserMedia( | 79 void MediaStreamImpl::requestUserMedia( |
| 87 const WebKit::WebUserMediaRequest& user_media_request, | 80 const WebKit::WebUserMediaRequest& user_media_request, |
| 88 const WebKit::WebVector<WebKit::WebMediaStreamSource>& audio_sources, | 81 const WebKit::WebVector<WebKit::WebMediaStreamSource>& audio_sources, |
| 89 const WebKit::WebVector<WebKit::WebMediaStreamSource>& video_sources) { | 82 const WebKit::WebVector<WebKit::WebMediaStreamSource>& video_sources) { |
| 90 // Save histogram data so we can see how much GetUserMedia is used. | 83 // Save histogram data so we can see how much GetUserMedia is used. |
| 91 // The histogram counts the number of calls to the JS API | 84 // The histogram counts the number of calls to the JS API |
| 92 // webGetUserMedia. | 85 // webGetUserMedia. |
| 93 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); | 86 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 DVLOG(1) << "Request ID not found"; | 191 DVLOG(1) << "Request ID not found"; |
| 199 media_stream_dispatcher_->StopStream(label); | 192 media_stream_dispatcher_->StopStream(label); |
| 200 return; | 193 return; |
| 201 } | 194 } |
| 202 | 195 |
| 203 WebKit::WebString webkit_label = UTF8ToUTF16(label); | 196 WebKit::WebString webkit_label = UTF8ToUTF16(label); |
| 204 WebKit::WebMediaStreamDescriptor description; | 197 WebKit::WebMediaStreamDescriptor description; |
| 205 description.initialize(webkit_label, audio_source_vector, | 198 description.initialize(webkit_label, audio_source_vector, |
| 206 video_source_vector); | 199 video_source_vector); |
| 207 | 200 |
| 208 if (!dependency_factory_->CreateNativeLocalMediaStream(&description)) { | 201 if (!dependency_factory_->CreateNativeLocalMediaStream( |
| 202 &description, base::Bind( |
| 203 &MediaStreamImpl::OnLocalMediaStreamStop, base::Unretained(this)))) { |
| 209 DVLOG(1) << "Failed to create native stream in OnStreamGenerated."; | 204 DVLOG(1) << "Failed to create native stream in OnStreamGenerated."; |
| 210 media_stream_dispatcher_->StopStream(label); | 205 media_stream_dispatcher_->StopStream(label); |
| 211 it->second.request_.requestFailed(); | 206 it->second.request_.requestFailed(); |
| 212 user_media_requests_.erase(it); | 207 user_media_requests_.erase(it); |
| 213 return; | 208 return; |
| 214 } | 209 } |
| 215 local_media_streams_[label] = it->second.frame_; | 210 local_media_streams_[label] = it->second.frame_; |
| 216 CompleteGetUserMediaRequest(description, &it->second.request_); | 211 CompleteGetUserMediaRequest(description, &it->second.request_); |
| 217 user_media_requests_.erase(it); | 212 user_media_requests_.erase(it); |
| 218 } | 213 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 return new RTCVideoDecoder( | 345 return new RTCVideoDecoder( |
| 351 message_loop_factory->GetMessageLoop(media::MessageLoopFactory::kDecoder), | 346 message_loop_factory->GetMessageLoop(media::MessageLoopFactory::kDecoder), |
| 352 base::MessageLoopProxy::current(), | 347 base::MessageLoopProxy::current(), |
| 353 stream->video_tracks()->at(0)); | 348 stream->video_tracks()->at(0)); |
| 354 } | 349 } |
| 355 | 350 |
| 356 MediaStreamExtraData::MediaStreamExtraData( | 351 MediaStreamExtraData::MediaStreamExtraData( |
| 357 webrtc::MediaStreamInterface* remote_stream) | 352 webrtc::MediaStreamInterface* remote_stream) |
| 358 : remote_stream_(remote_stream) { | 353 : remote_stream_(remote_stream) { |
| 359 } | 354 } |
| 355 |
| 360 MediaStreamExtraData::MediaStreamExtraData( | 356 MediaStreamExtraData::MediaStreamExtraData( |
| 361 webrtc::LocalMediaStreamInterface* local_stream) | 357 webrtc::LocalMediaStreamInterface* local_stream) |
| 362 : local_stream_(local_stream) { | 358 : local_stream_(local_stream) { |
| 363 } | 359 } |
| 360 |
| 364 MediaStreamExtraData::~MediaStreamExtraData() { | 361 MediaStreamExtraData::~MediaStreamExtraData() { |
| 365 } | 362 } |
| 363 |
| 364 void MediaStreamExtraData::SetLocalStreamStopCallback( |
| 365 const StreamStopCallback& stop_callback) { |
| 366 stream_stop_callback_ = stop_callback; |
| 367 } |
| 368 |
| 369 void MediaStreamExtraData::OnLocalStreamStop() { |
| 370 if (!stream_stop_callback_.is_null()) |
| 371 stream_stop_callback_.Run(local_stream_->label()); |
| 372 } |
| OLD | NEW |