| 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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } | 412 } |
| 413 | 413 |
| 414 void MediaStreamImpl::CreateWebKitSourceVector( | 414 void MediaStreamImpl::CreateWebKitSourceVector( |
| 415 const std::string& label, | 415 const std::string& label, |
| 416 const StreamDeviceInfoArray& devices, | 416 const StreamDeviceInfoArray& devices, |
| 417 WebKit::WebMediaStreamSource::Type type, | 417 WebKit::WebMediaStreamSource::Type type, |
| 418 WebKit::WebFrame* frame, | 418 WebKit::WebFrame* frame, |
| 419 WebKit::WebVector<WebKit::WebMediaStreamSource>& webkit_sources) { | 419 WebKit::WebVector<WebKit::WebMediaStreamSource>& webkit_sources) { |
| 420 CHECK_EQ(devices.size(), webkit_sources.size()); | 420 CHECK_EQ(devices.size(), webkit_sources.size()); |
| 421 for (size_t i = 0; i < devices.size(); ++i) { | 421 for (size_t i = 0; i < devices.size(); ++i) { |
| 422 const char* track_type = |
| 423 (type == WebKit::WebMediaStreamSource::TypeAudio) ? "a" : "v"; |
| 424 std::string source_id = base::StringPrintf("%s%s%u", label.c_str(), |
| 425 track_type, |
| 426 static_cast<unsigned int>(i)); |
| 427 |
| 422 const WebKit::WebMediaStreamSource* existing_source = | 428 const WebKit::WebMediaStreamSource* existing_source = |
| 423 FindLocalSource(devices[i]); | 429 FindLocalSource(devices[i]); |
| 424 if (existing_source) { | 430 if (existing_source) { |
| 425 webkit_sources[i] = *existing_source; | 431 webkit_sources[i] = *existing_source; |
| 426 DVLOG(1) << "Source already exist. Reusing source with id " | 432 DVLOG(1) << "Source already exist. Reusing source with id " |
| 427 << webkit_sources[i]. id().utf8(); | 433 << webkit_sources[i]. id().utf8(); |
| 428 continue; | 434 continue; |
| 429 } | 435 } |
| 430 webkit_sources[i].initialize( | 436 webkit_sources[i].initialize( |
| 431 UTF8ToUTF16(devices[i].device.id), | 437 UTF8ToUTF16(source_id), |
| 432 type, | 438 type, |
| 433 UTF8ToUTF16(devices[i].device.name)); | 439 UTF8ToUTF16(devices[i].device.name)); |
| 434 MediaStreamSourceExtraData* source_extra_data( | 440 MediaStreamSourceExtraData* source_extra_data( |
| 435 new content::MediaStreamSourceExtraData( | 441 new content::MediaStreamSourceExtraData( |
| 436 devices[i], | 442 devices[i], |
| 437 base::Bind(&MediaStreamImpl::OnLocalSourceStop, AsWeakPtr()))); | 443 base::Bind(&MediaStreamImpl::OnLocalSourceStop, AsWeakPtr()))); |
| 438 // |source_extra_data| is owned by webkit_sources[i]. | 444 // |source_extra_data| is owned by webkit_sources[i]. |
| 439 webkit_sources[i].setExtraData(source_extra_data); | 445 webkit_sources[i].setExtraData(source_extra_data); |
| 440 webkit_sources[i].setDeviceId(UTF8ToUTF16( | 446 webkit_sources[i].setDeviceId(UTF8ToUTF16( |
| 441 base::IntToString(devices[i].session_id))); | 447 base::IntToString(devices[i].session_id))); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 523 |
| 518 const WebKit::WebMediaStreamSource* MediaStreamImpl::FindLocalSource( | 524 const WebKit::WebMediaStreamSource* MediaStreamImpl::FindLocalSource( |
| 519 const StreamDeviceInfo& device) const { | 525 const StreamDeviceInfo& device) const { |
| 520 for (LocalStreamSources::const_iterator it = local_sources_.begin(); | 526 for (LocalStreamSources::const_iterator it = local_sources_.begin(); |
| 521 it != local_sources_.end(); ++it) { | 527 it != local_sources_.end(); ++it) { |
| 522 MediaStreamSourceExtraData* extra_data = | 528 MediaStreamSourceExtraData* extra_data = |
| 523 static_cast<MediaStreamSourceExtraData*>( | 529 static_cast<MediaStreamSourceExtraData*>( |
| 524 it->source.extraData()); | 530 it->source.extraData()); |
| 525 const StreamDeviceInfo& active_device = extra_data->device_info(); | 531 const StreamDeviceInfo& active_device = extra_data->device_info(); |
| 526 if (active_device.device.id == device.device.id && | 532 if (active_device.device.id == device.device.id && |
| 527 active_device.device.type == device.device.type) { | 533 active_device.session_id == device.session_id) { |
| 528 return &it->source; | 534 return &it->source; |
| 529 } | 535 } |
| 530 } | 536 } |
| 531 return NULL; | 537 return NULL; |
| 532 } | 538 } |
| 533 | 539 |
| 534 bool MediaStreamImpl::FindSourceInRequests( | 540 bool MediaStreamImpl::FindSourceInRequests( |
| 535 const WebKit::WebMediaStreamSource& source) const { | 541 const WebKit::WebMediaStreamSource& source) const { |
| 536 for (UserMediaRequests::const_iterator req_it = user_media_requests_.begin(); | 542 for (UserMediaRequests::const_iterator req_it = user_media_requests_.begin(); |
| 537 req_it != user_media_requests_.end(); ++req_it) { | 543 req_it != user_media_requests_.end(); ++req_it) { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 enable_automatic_output_device_selection( | 863 enable_automatic_output_device_selection( |
| 858 enable_automatic_output_device_selection), | 864 enable_automatic_output_device_selection), |
| 859 frame(frame), | 865 frame(frame), |
| 860 request(request) { | 866 request(request) { |
| 861 } | 867 } |
| 862 | 868 |
| 863 MediaStreamImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { | 869 MediaStreamImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { |
| 864 } | 870 } |
| 865 | 871 |
| 866 } // namespace content | 872 } // namespace content |
| OLD | NEW |