| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/peer_connection_tracker.h" | 5 #include "content/renderer/media/peer_connection_tracker.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> |
| 11 #include <utility> | 12 #include <utility> |
| 13 #include <vector> |
| 12 | 14 |
| 13 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/values.h" | 19 #include "base/values.h" |
| 18 #include "content/common/media/peer_connection_tracker_messages.h" | 20 #include "content/common/media/peer_connection_tracker_messages.h" |
| 19 #include "content/renderer/media/rtc_peer_connection_handler.h" | 21 #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 20 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
| 21 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 23 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 22 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 24 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 23 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 25 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 24 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 26 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 25 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" | 27 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" |
| 26 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" | 28 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" |
| 27 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" | 29 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" |
| 28 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" | 30 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" |
| 29 #include "third_party/WebKit/public/web/WebDocument.h" | 31 #include "third_party/WebKit/public/web/WebDocument.h" |
| 30 #include "third_party/WebKit/public/web/WebFrame.h" | 32 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 31 #include "third_party/WebKit/public/web/WebUserMediaRequest.h" | 33 #include "third_party/WebKit/public/web/WebUserMediaRequest.h" |
| 32 | 34 |
| 33 using webrtc::MediaConstraintsInterface; | 35 using webrtc::MediaConstraintsInterface; |
| 34 using webrtc::StatsReport; | 36 using webrtc::StatsReport; |
| 35 using webrtc::StatsReports; | 37 using webrtc::StatsReports; |
| 36 using blink::WebRTCPeerConnectionHandlerClient; | 38 using blink::WebRTCPeerConnectionHandlerClient; |
| 37 | 39 |
| 38 namespace content { | 40 namespace content { |
| 39 | 41 |
| 40 // TODO(hta): This module should be redesigned to reduce string copies. | 42 // TODO(hta): This module should be redesigned to reduce string copies. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 transport_type = "relay"; | 131 transport_type = "relay"; |
| 130 break; | 132 break; |
| 131 case webrtc::PeerConnectionInterface::kAll: | 133 case webrtc::PeerConnectionInterface::kAll: |
| 132 transport_type = "all"; | 134 transport_type = "all"; |
| 133 break; | 135 break; |
| 134 case webrtc::PeerConnectionInterface::kNoHost: | 136 case webrtc::PeerConnectionInterface::kNoHost: |
| 135 transport_type = "noHost"; | 137 transport_type = "noHost"; |
| 136 break; | 138 break; |
| 137 default: | 139 default: |
| 138 NOTREACHED(); | 140 NOTREACHED(); |
| 139 }; | 141 } |
| 140 return transport_type; | 142 return transport_type; |
| 141 } | 143 } |
| 142 | 144 |
| 143 static const char* SerializeBundlePolicy( | 145 static const char* SerializeBundlePolicy( |
| 144 webrtc::PeerConnectionInterface::BundlePolicy policy) { | 146 webrtc::PeerConnectionInterface::BundlePolicy policy) { |
| 145 const char* policy_str = ""; | 147 const char* policy_str = ""; |
| 146 switch (policy) { | 148 switch (policy) { |
| 147 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced: | 149 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced: |
| 148 policy_str = "balanced"; | 150 policy_str = "balanced"; |
| 149 break; | 151 break; |
| 150 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle: | 152 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle: |
| 151 policy_str = "max-bundle"; | 153 policy_str = "max-bundle"; |
| 152 break; | 154 break; |
| 153 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat: | 155 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat: |
| 154 policy_str = "max-compat"; | 156 policy_str = "max-compat"; |
| 155 break; | 157 break; |
| 156 default: | 158 default: |
| 157 NOTREACHED(); | 159 NOTREACHED(); |
| 158 }; | 160 } |
| 159 return policy_str; | 161 return policy_str; |
| 160 } | 162 } |
| 161 | 163 |
| 162 static const char* SerializeRtcpMuxPolicy( | 164 static const char* SerializeRtcpMuxPolicy( |
| 163 webrtc::PeerConnectionInterface::RtcpMuxPolicy policy) { | 165 webrtc::PeerConnectionInterface::RtcpMuxPolicy policy) { |
| 164 const char* policy_str = ""; | 166 const char* policy_str = ""; |
| 165 switch (policy) { | 167 switch (policy) { |
| 166 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate: | 168 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate: |
| 167 policy_str = "negotiate"; | 169 policy_str = "negotiate"; |
| 168 break; | 170 break; |
| 169 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire: | 171 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire: |
| 170 policy_str = "require"; | 172 policy_str = "require"; |
| 171 break; | 173 break; |
| 172 default: | 174 default: |
| 173 NOTREACHED(); | 175 NOTREACHED(); |
| 174 }; | 176 } |
| 175 return policy_str; | 177 return policy_str; |
| 176 } | 178 } |
| 177 | 179 |
| 178 static std::string SerializeConfiguration( | 180 static std::string SerializeConfiguration( |
| 179 const webrtc::PeerConnectionInterface::RTCConfiguration& config) { | 181 const webrtc::PeerConnectionInterface::RTCConfiguration& config) { |
| 180 std::ostringstream oss; | 182 std::ostringstream oss; |
| 181 // TODO(hbos): Add serialization of certificate. | 183 // TODO(hbos): Add serialization of certificate. |
| 182 oss << "{ iceServers: " << SerializeServers(config.servers) | 184 oss << "{ iceServers: " << SerializeServers(config.servers) |
| 183 << ", iceTransportPolicy: " << SerializeIceTransportType(config.type) | 185 << ", iceTransportPolicy: " << SerializeIceTransportType(config.type) |
| 184 << ", bundlePolicy: " << SerializeBundlePolicy(config.bundle_policy) | 186 << ", bundlePolicy: " << SerializeBundlePolicy(config.bundle_policy) |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 auto result = base::MakeUnique<base::DictionaryValue>(); | 307 auto result = base::MakeUnique<base::DictionaryValue>(); |
| 306 result->Set("stats", std::move(stats)); | 308 result->Set("stats", std::move(stats)); |
| 307 result->SetString("id", report.id()->ToString()); | 309 result->SetString("id", report.id()->ToString()); |
| 308 result->SetString("type", report.TypeToString()); | 310 result->SetString("type", report.TypeToString()); |
| 309 | 311 |
| 310 return result; | 312 return result; |
| 311 } | 313 } |
| 312 | 314 |
| 313 class InternalStatsObserver : public webrtc::StatsObserver { | 315 class InternalStatsObserver : public webrtc::StatsObserver { |
| 314 public: | 316 public: |
| 315 InternalStatsObserver(int lid) | 317 explicit InternalStatsObserver(int lid) |
| 316 : lid_(lid), main_thread_(base::ThreadTaskRunnerHandle::Get()) {} | 318 : lid_(lid), main_thread_(base::ThreadTaskRunnerHandle::Get()) {} |
| 317 | 319 |
| 318 void OnComplete(const StatsReports& reports) override { | 320 void OnComplete(const StatsReports& reports) override { |
| 319 std::unique_ptr<base::ListValue> list(new base::ListValue()); | 321 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
| 320 | 322 |
| 321 for (const auto* r : reports) { | 323 for (const auto* r : reports) { |
| 322 std::unique_ptr<base::DictionaryValue> report = GetDictValue(*r); | 324 std::unique_ptr<base::DictionaryValue> report = GetDictValue(*r); |
| 323 if (report) | 325 if (report) |
| 324 list->Append(std::move(report)); | 326 list->Append(std::move(report)); |
| 325 } | 327 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 it.first->StopEventLog(); | 431 it.first->StopEventLog(); |
| 430 return; | 432 return; |
| 431 } | 433 } |
| 432 } | 434 } |
| 433 } | 435 } |
| 434 | 436 |
| 435 void PeerConnectionTracker::RegisterPeerConnection( | 437 void PeerConnectionTracker::RegisterPeerConnection( |
| 436 RTCPeerConnectionHandler* pc_handler, | 438 RTCPeerConnectionHandler* pc_handler, |
| 437 const webrtc::PeerConnectionInterface::RTCConfiguration& config, | 439 const webrtc::PeerConnectionInterface::RTCConfiguration& config, |
| 438 const blink::WebMediaConstraints& constraints, | 440 const blink::WebMediaConstraints& constraints, |
| 439 const blink::WebFrame* frame) { | 441 const blink::WebLocalFrame* frame) { |
| 440 DCHECK(main_thread_.CalledOnValidThread()); | 442 DCHECK(main_thread_.CalledOnValidThread()); |
| 441 DCHECK_EQ(GetLocalIDForHandler(pc_handler), -1); | 443 DCHECK_EQ(GetLocalIDForHandler(pc_handler), -1); |
| 442 DVLOG(1) << "PeerConnectionTracker::RegisterPeerConnection()"; | 444 DVLOG(1) << "PeerConnectionTracker::RegisterPeerConnection()"; |
| 443 PeerConnectionInfo info; | 445 PeerConnectionInfo info; |
| 444 | 446 |
| 445 info.lid = GetNextLocalID(); | 447 info.lid = GetNextLocalID(); |
| 446 info.rtc_configuration = SerializeConfiguration(config); | 448 info.rtc_configuration = SerializeConfiguration(config); |
| 447 | 449 |
| 448 info.constraints = SerializeMediaConstraints(constraints); | 450 info.constraints = SerializeMediaConstraints(constraints); |
| 449 if (frame) | 451 if (frame) |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 if (id == -1) | 583 if (id == -1) |
| 582 return; | 584 return; |
| 583 SendPeerConnectionUpdate( | 585 SendPeerConnectionUpdate( |
| 584 id, source == SOURCE_LOCAL ? "addStream" : "onAddStream", | 586 id, source == SOURCE_LOCAL ? "addStream" : "onAddStream", |
| 585 SerializeMediaDescriptor(stream)); | 587 SerializeMediaDescriptor(stream)); |
| 586 } | 588 } |
| 587 | 589 |
| 588 void PeerConnectionTracker::TrackRemoveStream( | 590 void PeerConnectionTracker::TrackRemoveStream( |
| 589 RTCPeerConnectionHandler* pc_handler, | 591 RTCPeerConnectionHandler* pc_handler, |
| 590 const blink::WebMediaStream& stream, | 592 const blink::WebMediaStream& stream, |
| 591 Source source){ | 593 Source source) { |
| 592 DCHECK(main_thread_.CalledOnValidThread()); | 594 DCHECK(main_thread_.CalledOnValidThread()); |
| 593 int id = GetLocalIDForHandler(pc_handler); | 595 int id = GetLocalIDForHandler(pc_handler); |
| 594 if (id == -1) | 596 if (id == -1) |
| 595 return; | 597 return; |
| 596 SendPeerConnectionUpdate( | 598 SendPeerConnectionUpdate( |
| 597 id, source == SOURCE_LOCAL ? "removeStream" : "onRemoveStream", | 599 id, source == SOURCE_LOCAL ? "removeStream" : "onRemoveStream", |
| 598 SerializeMediaDescriptor(stream)); | 600 SerializeMediaDescriptor(stream)); |
| 599 } | 601 } |
| 600 | 602 |
| 601 void PeerConnectionTracker::TrackCreateDataChannel( | 603 void PeerConnectionTracker::TrackCreateDataChannel( |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 DCHECK(main_thread_.CalledOnValidThread()); | 745 DCHECK(main_thread_.CalledOnValidThread()); |
| 744 SendTarget()->Send(new PeerConnectionTrackerHost_UpdatePeerConnection( | 746 SendTarget()->Send(new PeerConnectionTrackerHost_UpdatePeerConnection( |
| 745 local_id, std::string(callback_type), value)); | 747 local_id, std::string(callback_type), value)); |
| 746 } | 748 } |
| 747 | 749 |
| 748 void PeerConnectionTracker::OverrideSendTargetForTesting(RenderThread* target) { | 750 void PeerConnectionTracker::OverrideSendTargetForTesting(RenderThread* target) { |
| 749 send_target_for_test_ = target; | 751 send_target_for_test_ = target; |
| 750 } | 752 } |
| 751 | 753 |
| 752 } // namespace content | 754 } // namespace content |
| OLD | NEW |