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 #include "content/renderer/media/peer_connection_tracker.h" | 4 #include "content/renderer/media/peer_connection_tracker.h" |
5 | 5 |
6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
9 #include "content/common/media/peer_connection_tracker_messages.h" | 9 #include "content/common/media/peer_connection_tracker_messages.h" |
10 #include "content/renderer/media/rtc_media_constraints.h" | 10 #include "content/renderer/media/rtc_media_constraints.h" |
11 #include "content/renderer/media/rtc_peer_connection_handler.h" | 11 #include "content/renderer/media/rtc_peer_connection_handler.h" |
12 #include "content/renderer/render_thread_impl.h" | 12 #include "content/renderer/render_thread_impl.h" |
13 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 13 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
14 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 14 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
15 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 15 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
17 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" | 17 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" |
18 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h " | 18 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h " |
19 #include "third_party/WebKit/public/web/WebDocument.h" | 19 #include "third_party/WebKit/public/web/WebDocument.h" |
20 #include "third_party/WebKit/public/web/WebFrame.h" | 20 #include "third_party/WebKit/public/web/WebFrame.h" |
21 #include "third_party/WebKit/public/web/WebUserMediaRequest.h" | 21 #include "third_party/WebKit/public/web/WebUserMediaRequest.h" |
22 | 22 |
23 using std::string; | 23 using std::string; |
24 using webrtc::MediaConstraintsInterface; | 24 using webrtc::MediaConstraintsInterface; |
25 using webrtc::StatsReport; | |
26 using webrtc::StatsReports; | |
25 using blink::WebRTCPeerConnectionHandlerClient; | 27 using blink::WebRTCPeerConnectionHandlerClient; |
26 | 28 |
27 namespace content { | 29 namespace content { |
28 | 30 |
29 static string SerializeServers( | 31 static string SerializeServers( |
30 const std::vector<webrtc::PeerConnectionInterface::IceServer>& servers) { | 32 const std::vector<webrtc::PeerConnectionInterface::IceServer>& servers) { |
31 string result = "["; | 33 string result = "["; |
32 for (size_t i = 0; i < servers.size(); ++i) { | 34 for (size_t i = 0; i < servers.size(); ++i) { |
33 result += servers[i].uri; | 35 result += servers[i].uri; |
34 if (i != servers.size() - 1) | 36 if (i != servers.size() - 1) |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 break; | 199 break; |
198 } | 200 } |
199 return result; | 201 return result; |
200 } | 202 } |
201 | 203 |
202 // Builds a DictionaryValue from the StatsReport. | 204 // Builds a DictionaryValue from the StatsReport. |
203 // The caller takes the ownership of the returned value. | 205 // The caller takes the ownership of the returned value. |
204 // Note: | 206 // Note: |
205 // The format must be consistent with what webrtc_internals.js expects. | 207 // The format must be consistent with what webrtc_internals.js expects. |
206 // If you change it here, you must change webrtc_internals.js as well. | 208 // If you change it here, you must change webrtc_internals.js as well. |
207 static base::DictionaryValue* GetDictValueStats( | 209 static base::DictionaryValue* GetDictValueStats(const StatsReport& report) { |
208 const webrtc::StatsReport& report) { | |
209 if (report.values().empty()) | 210 if (report.values().empty()) |
210 return NULL; | 211 return NULL; |
211 | 212 |
212 base::DictionaryValue* dict = new base::DictionaryValue(); | 213 base::DictionaryValue* dict = new base::DictionaryValue(); |
213 dict->SetDouble("timestamp", report.timestamp()); | 214 dict->SetDouble("timestamp", report.timestamp()); |
214 | 215 |
215 base::ListValue* values = new base::ListValue(); | 216 base::ListValue* values = new base::ListValue(); |
216 dict->Set("values", values); | 217 dict->Set("values", values); |
217 | 218 |
218 for (const auto& v : report.values()) { | 219 for (const auto& v : report.values()) { |
219 values->AppendString(v.second->display_name()); | 220 const StatsReport::ValuePtr& value = v.second; |
220 values->AppendString(v.second->ToString()); | 221 values->AppendString(value->display_name()); |
222 switch (value->type()) { | |
223 case StatsReport::Value::kInt: | |
224 values->AppendInteger(value->int_val()); | |
225 break; | |
226 case StatsReport::Value::kFloat: | |
227 values->AppendDouble(value->float_val()); | |
228 break; | |
229 case StatsReport::Value::kString: | |
230 values->AppendString(value->string_val()); | |
231 break; | |
232 case StatsReport::Value::kStaticString: | |
233 values->AppendString(value->static_string_val()); | |
234 break; | |
235 case StatsReport::Value::kBool: | |
236 values->AppendBoolean(value->bool_val()); | |
237 break; | |
238 case StatsReport::Value::kInt64: // int64 isn't supported, so use string. | |
perkj_chrome
2015/03/16 10:36:39
todo:tommi fix int64 support?
tommi (sloooow) - chröme
2015/03/16 18:07:41
It's not supported by base::ListValue and apparent
| |
239 case StatsReport::Value::kId: | |
240 default: | |
241 values->AppendString(value->ToString()); | |
242 break; | |
243 } | |
221 } | 244 } |
222 | 245 |
223 return dict; | 246 return dict; |
224 } | 247 } |
225 | 248 |
226 // Builds a DictionaryValue from the StatsReport. | 249 // Builds a DictionaryValue from the StatsReport. |
227 // The caller takes the ownership of the returned value. | 250 // The caller takes the ownership of the returned value. |
228 static base::DictionaryValue* GetDictValue(const webrtc::StatsReport& report) { | 251 static base::DictionaryValue* GetDictValue(const StatsReport& report) { |
229 scoped_ptr<base::DictionaryValue> stats, result; | 252 scoped_ptr<base::DictionaryValue> stats, result; |
230 | 253 |
231 stats.reset(GetDictValueStats(report)); | 254 stats.reset(GetDictValueStats(report)); |
232 if (!stats) | 255 if (!stats) |
233 return NULL; | 256 return NULL; |
234 | 257 |
235 result.reset(new base::DictionaryValue()); | 258 result.reset(new base::DictionaryValue()); |
236 // Note: | 259 // Note: |
237 // The format must be consistent with what webrtc_internals.js expects. | 260 // The format must be consistent with what webrtc_internals.js expects. |
238 // If you change it here, you must change webrtc_internals.js as well. | 261 // If you change it here, you must change webrtc_internals.js as well. |
239 result->Set("stats", stats.release()); | 262 result->Set("stats", stats.release()); |
240 result->SetString("id", report.id()->ToString()); | 263 result->SetString("id", report.id()->ToString()); |
241 result->SetString("type", report.TypeToString()); | 264 result->SetString("type", report.TypeToString()); |
242 | 265 |
243 return result.release(); | 266 return result.release(); |
244 } | 267 } |
245 | 268 |
246 class InternalStatsObserver : public webrtc::StatsObserver { | 269 class InternalStatsObserver : public webrtc::StatsObserver { |
247 public: | 270 public: |
248 InternalStatsObserver(int lid) | 271 InternalStatsObserver(int lid) |
249 : lid_(lid), main_thread_(base::ThreadTaskRunnerHandle::Get()) {} | 272 : lid_(lid), main_thread_(base::ThreadTaskRunnerHandle::Get()) {} |
250 | 273 |
251 void OnComplete(const webrtc::StatsReports& reports) override { | 274 void OnComplete(const StatsReports& reports) override { |
252 scoped_ptr<base::ListValue> list(new base::ListValue()); | 275 scoped_ptr<base::ListValue> list(new base::ListValue()); |
253 | 276 |
254 for (const auto* r : reports) { | 277 for (const auto* r : reports) { |
255 base::DictionaryValue* report = GetDictValue(*r); | 278 base::DictionaryValue* report = GetDictValue(*r); |
256 if (report) | 279 if (report) |
257 list->Append(report); | 280 list->Append(report); |
258 } | 281 } |
259 | 282 |
260 if (!list->empty()) { | 283 if (!list->empty()) { |
261 main_thread_->PostTask(FROM_HERE, | 284 main_thread_->PostTask(FROM_HERE, |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 DCHECK(main_thread_.CalledOnValidThread()); | 597 DCHECK(main_thread_.CalledOnValidThread()); |
575 if (peer_connection_id_map_.find(pc_handler) == peer_connection_id_map_.end()) | 598 if (peer_connection_id_map_.find(pc_handler) == peer_connection_id_map_.end()) |
576 return; | 599 return; |
577 | 600 |
578 RenderThreadImpl::current()->Send( | 601 RenderThreadImpl::current()->Send( |
579 new PeerConnectionTrackerHost_UpdatePeerConnection( | 602 new PeerConnectionTrackerHost_UpdatePeerConnection( |
580 peer_connection_id_map_[pc_handler], type, value)); | 603 peer_connection_id_map_[pc_handler], type, value)); |
581 } | 604 } |
582 | 605 |
583 } // namespace content | 606 } // namespace content |
OLD | NEW |