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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 } | 442 } |
443 | 443 |
444 void MediaStreamImpl::CreateWebKitSourceVector( | 444 void MediaStreamImpl::CreateWebKitSourceVector( |
445 const std::string& label, | 445 const std::string& label, |
446 const StreamDeviceInfoArray& devices, | 446 const StreamDeviceInfoArray& devices, |
447 blink::WebMediaStreamSource::Type type, | 447 blink::WebMediaStreamSource::Type type, |
448 blink::WebFrame* frame, | 448 blink::WebFrame* frame, |
449 blink::WebVector<blink::WebMediaStreamSource>& webkit_sources) { | 449 blink::WebVector<blink::WebMediaStreamSource>& webkit_sources) { |
450 CHECK_EQ(devices.size(), webkit_sources.size()); | 450 CHECK_EQ(devices.size(), webkit_sources.size()); |
451 for (size_t i = 0; i < devices.size(); ++i) { | 451 for (size_t i = 0; i < devices.size(); ++i) { |
452 const char* track_type = | |
453 (type == blink::WebMediaStreamSource::TypeAudio) ? "a" : "v"; | |
454 std::string source_id = base::StringPrintf("%s%s%u", label.c_str(), | |
455 track_type, | |
456 static_cast<unsigned int>(i)); | |
457 | |
458 const blink::WebMediaStreamSource* existing_source = | 452 const blink::WebMediaStreamSource* existing_source = |
459 FindLocalSource(devices[i]); | 453 FindLocalSource(devices[i]); |
460 if (existing_source) { | 454 if (existing_source) { |
461 webkit_sources[i] = *existing_source; | 455 webkit_sources[i] = *existing_source; |
462 DVLOG(1) << "Source already exist. Reusing source with id " | 456 DVLOG(1) << "Source already exist. Reusing source with id " |
463 << webkit_sources[i]. id().utf8(); | 457 << webkit_sources[i]. id().utf8(); |
464 continue; | 458 continue; |
465 } | 459 } |
466 webkit_sources[i].initialize( | 460 webkit_sources[i].initialize( |
467 UTF8ToUTF16(source_id), | 461 UTF8ToUTF16(devices[i].device.id), |
468 type, | 462 type, |
469 UTF8ToUTF16(devices[i].device.name)); | 463 UTF8ToUTF16(devices[i].device.name)); |
470 MediaStreamSourceExtraData* source_extra_data( | 464 MediaStreamSourceExtraData* source_extra_data( |
471 new content::MediaStreamSourceExtraData( | 465 new content::MediaStreamSourceExtraData( |
472 devices[i], | 466 devices[i], |
473 base::Bind(&MediaStreamImpl::OnLocalSourceStop, AsWeakPtr()))); | 467 base::Bind(&MediaStreamImpl::OnLocalSourceStop, AsWeakPtr()))); |
474 // |source_extra_data| is owned by webkit_sources[i]. | 468 // |source_extra_data| is owned by webkit_sources[i]. |
475 webkit_sources[i].setExtraData(source_extra_data); | 469 webkit_sources[i].setExtraData(source_extra_data); |
476 webkit_sources[i].setDeviceId(UTF8ToUTF16( | 470 webkit_sources[i].setDeviceId(UTF8ToUTF16( |
477 base::IntToString(devices[i].session_id))); | 471 base::IntToString(devices[i].session_id))); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 | 547 |
554 const blink::WebMediaStreamSource* MediaStreamImpl::FindLocalSource( | 548 const blink::WebMediaStreamSource* MediaStreamImpl::FindLocalSource( |
555 const StreamDeviceInfo& device) const { | 549 const StreamDeviceInfo& device) const { |
556 for (LocalStreamSources::const_iterator it = local_sources_.begin(); | 550 for (LocalStreamSources::const_iterator it = local_sources_.begin(); |
557 it != local_sources_.end(); ++it) { | 551 it != local_sources_.end(); ++it) { |
558 MediaStreamSourceExtraData* extra_data = | 552 MediaStreamSourceExtraData* extra_data = |
559 static_cast<MediaStreamSourceExtraData*>( | 553 static_cast<MediaStreamSourceExtraData*>( |
560 it->source.extraData()); | 554 it->source.extraData()); |
561 const StreamDeviceInfo& active_device = extra_data->device_info(); | 555 const StreamDeviceInfo& active_device = extra_data->device_info(); |
562 if (active_device.device.id == device.device.id && | 556 if (active_device.device.id == device.device.id && |
563 active_device.session_id == device.session_id) { | 557 active_device.device.type == device.device.type) { |
564 return &it->source; | 558 return &it->source; |
565 } | 559 } |
566 } | 560 } |
567 return NULL; | 561 return NULL; |
568 } | 562 } |
569 | 563 |
570 bool MediaStreamImpl::FindSourceInRequests( | 564 bool MediaStreamImpl::FindSourceInRequests( |
571 const blink::WebMediaStreamSource& source) const { | 565 const blink::WebMediaStreamSource& source) const { |
572 for (UserMediaRequests::const_iterator req_it = user_media_requests_.begin(); | 566 for (UserMediaRequests::const_iterator req_it = user_media_requests_.begin(); |
573 req_it != user_media_requests_.end(); ++req_it) { | 567 req_it != user_media_requests_.end(); ++req_it) { |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 enable_automatic_output_device_selection( | 886 enable_automatic_output_device_selection( |
893 enable_automatic_output_device_selection), | 887 enable_automatic_output_device_selection), |
894 frame(frame), | 888 frame(frame), |
895 request(request) { | 889 request(request) { |
896 } | 890 } |
897 | 891 |
898 MediaStreamImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { | 892 MediaStreamImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { |
899 } | 893 } |
900 | 894 |
901 } // namespace content | 895 } // namespace content |
OLD | NEW |