| 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/user_media_client_impl.h" | 5 #include "content/renderer/media/user_media_client_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 | 541 |
| 542 blink::WebString webkit_id = blink::WebString::fromUTF8(label); | 542 blink::WebString webkit_id = blink::WebString::fromUTF8(label); |
| 543 blink::WebMediaStream* web_stream = &(request_info->web_stream); | 543 blink::WebMediaStream* web_stream = &(request_info->web_stream); |
| 544 | 544 |
| 545 web_stream->initialize(webkit_id, audio_track_vector, video_track_vector); | 545 web_stream->initialize(webkit_id, audio_track_vector, video_track_vector); |
| 546 web_stream->setExtraData(new MediaStream()); | 546 web_stream->setExtraData(new MediaStream()); |
| 547 | 547 |
| 548 // Wait for the tracks to be started successfully or to fail. | 548 // Wait for the tracks to be started successfully or to fail. |
| 549 request_info->CallbackOnTracksStarted( | 549 request_info->CallbackOnTracksStarted( |
| 550 base::Bind(&UserMediaClientImpl::OnCreateNativeTracksCompleted, | 550 base::Bind(&UserMediaClientImpl::OnCreateNativeTracksCompleted, |
| 551 weak_factory_.GetWeakPtr())); | 551 weak_factory_.GetWeakPtr(), label)); |
| 552 } | 552 } |
| 553 | 553 |
| 554 void UserMediaClientImpl::OnStreamGeneratedForCancelledRequest( | 554 void UserMediaClientImpl::OnStreamGeneratedForCancelledRequest( |
| 555 const StreamDeviceInfoArray& audio_array, | 555 const StreamDeviceInfoArray& audio_array, |
| 556 const StreamDeviceInfoArray& video_array) { | 556 const StreamDeviceInfoArray& video_array) { |
| 557 // Only stop the device if the device is not used in another MediaStream. | 557 // Only stop the device if the device is not used in another MediaStream. |
| 558 for (StreamDeviceInfoArray::const_iterator device_it = audio_array.begin(); | 558 for (StreamDeviceInfoArray::const_iterator device_it = audio_array.begin(); |
| 559 device_it != audio_array.end(); ++device_it) { | 559 device_it != audio_array.end(); ++device_it) { |
| 560 if (!FindLocalSource(*device_it)) | 560 if (!FindLocalSource(*device_it)) |
| 561 media_stream_dispatcher_->StopStreamDevice(*device_it); | 561 media_stream_dispatcher_->StopStreamDevice(*device_it); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { | 810 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { |
| 811 bool is_pending = false; | 811 bool is_pending = false; |
| 812 blink::WebMediaStreamSource source = InitializeAudioSourceObject( | 812 blink::WebMediaStreamSource source = InitializeAudioSourceObject( |
| 813 overridden_audio_array[i], constraints, &is_pending); | 813 overridden_audio_array[i], constraints, &is_pending); |
| 814 (*webkit_tracks)[i].initialize(source); | 814 (*webkit_tracks)[i].initialize(source); |
| 815 request->StartAudioTrack((*webkit_tracks)[i], is_pending); | 815 request->StartAudioTrack((*webkit_tracks)[i], is_pending); |
| 816 } | 816 } |
| 817 } | 817 } |
| 818 | 818 |
| 819 void UserMediaClientImpl::OnCreateNativeTracksCompleted( | 819 void UserMediaClientImpl::OnCreateNativeTracksCompleted( |
| 820 const std::string& label, |
| 820 UserMediaRequestInfo* request, | 821 UserMediaRequestInfo* request, |
| 821 MediaStreamRequestResult result, | 822 MediaStreamRequestResult result, |
| 822 const blink::WebString& result_name) { | 823 const blink::WebString& result_name) { |
| 823 DCHECK(CalledOnValidThread()); | 824 DCHECK(CalledOnValidThread()); |
| 824 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete(" | 825 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete(" |
| 825 << "{request_id = " << request->request_id << "} " | 826 << "{request_id = " << request->request_id << "} " |
| 826 << "{result = " << result << "})"; | 827 << "{result = " << result << "})"; |
| 827 | 828 |
| 828 if (result == content::MEDIA_DEVICE_OK) { | 829 if (result == content::MEDIA_DEVICE_OK) { |
| 829 GetUserMediaRequestSucceeded(request->web_stream, request->request); | 830 GetUserMediaRequestSucceeded(request->web_stream, request->request); |
| 831 media_stream_dispatcher_->OnStreamStarted(label); |
| 830 } else { | 832 } else { |
| 831 GetUserMediaRequestFailed(request->request, result, result_name); | 833 GetUserMediaRequestFailed(request->request, result, result_name); |
| 832 | 834 |
| 833 blink::WebVector<blink::WebMediaStreamTrack> tracks; | 835 blink::WebVector<blink::WebMediaStreamTrack> tracks; |
| 834 request->web_stream.audioTracks(tracks); | 836 request->web_stream.audioTracks(tracks); |
| 835 for (auto& web_track : tracks) { | 837 for (auto& web_track : tracks) { |
| 836 MediaStreamTrack* track = MediaStreamTrack::GetTrack(web_track); | 838 MediaStreamTrack* track = MediaStreamTrack::GetTrack(web_track); |
| 837 if (track) | 839 if (track) |
| 838 track->Stop(); | 840 track->Stop(); |
| 839 } | 841 } |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 sources_waiting_for_callback_.end(), source); | 1248 sources_waiting_for_callback_.end(), source); |
| 1247 if (found != sources_waiting_for_callback_.end()) | 1249 if (found != sources_waiting_for_callback_.end()) |
| 1248 OnTrackStarted(source, result, result_name); | 1250 OnTrackStarted(source, result, result_name); |
| 1249 } | 1251 } |
| 1250 | 1252 |
| 1251 void UserMediaClientImpl::OnDestruct() { | 1253 void UserMediaClientImpl::OnDestruct() { |
| 1252 delete this; | 1254 delete this; |
| 1253 } | 1255 } |
| 1254 | 1256 |
| 1255 } // namespace content | 1257 } // namespace content |
| OLD | NEW |