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