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/rtc_peer_connection_handler.h" | 5 #include "content/renderer/media/rtc_peer_connection_handler.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "content/renderer/render_thread_impl.h" | 36 #include "content/renderer/render_thread_impl.h" |
37 #include "media/base/media_switches.h" | 37 #include "media/base/media_switches.h" |
38 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 38 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
39 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" | 39 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" |
40 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h" | 40 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h" |
41 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" | 41 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
42 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" | 42 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" |
43 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" | 43 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" |
44 #include "third_party/WebKit/public/platform/WebRTCSessionDescription.h" | 44 #include "third_party/WebKit/public/platform/WebRTCSessionDescription.h" |
45 #include "third_party/WebKit/public/platform/WebRTCSessionDescriptionRequest.h" | 45 #include "third_party/WebKit/public/platform/WebRTCSessionDescriptionRequest.h" |
| 46 #include "third_party/WebKit/public/platform/WebRTCStats.h" |
46 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" | 47 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" |
47 #include "third_party/WebKit/public/platform/WebURL.h" | 48 #include "third_party/WebKit/public/platform/WebURL.h" |
48 #include "third_party/webrtc/pc/mediasession.h" | 49 #include "third_party/webrtc/pc/mediasession.h" |
49 | 50 |
50 using webrtc::DataChannelInterface; | 51 using webrtc::DataChannelInterface; |
51 using webrtc::IceCandidateInterface; | 52 using webrtc::IceCandidateInterface; |
52 using webrtc::MediaStreamInterface; | 53 using webrtc::MediaStreamInterface; |
53 using webrtc::PeerConnectionInterface; | 54 using webrtc::PeerConnectionInterface; |
54 using webrtc::PeerConnectionObserver; | 55 using webrtc::PeerConnectionObserver; |
55 using webrtc::StatsReport; | 56 using webrtc::StatsReport; |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 DLOG_IF(ERROR, !webkit_request_.isNull()) | 445 DLOG_IF(ERROR, !webkit_request_.isNull()) |
445 << "SetSessionDescriptionRequest not completed. Shutting down?"; | 446 << "SetSessionDescriptionRequest not completed. Shutting down?"; |
446 } | 447 } |
447 | 448 |
448 private: | 449 private: |
449 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 450 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
450 blink::WebRTCVoidRequest webkit_request_; | 451 blink::WebRTCVoidRequest webkit_request_; |
451 SessionDescriptionRequestTracker tracker_; | 452 SessionDescriptionRequestTracker tracker_; |
452 }; | 453 }; |
453 | 454 |
| 455 blink::WebRTCStatsType WebRTCStatsTypeFromStatsType( |
| 456 webrtc::StatsReport::StatsType name) { |
| 457 // TODO(hbos): Translate StatsType -> WebRTCStatsType. crbug.com/627816 |
| 458 return blink::WebRTCStatsTypeUnknown; |
| 459 } |
| 460 |
| 461 blink::WebRTCStatsMemberName WebRTCStatsMemberNameFromStatsValueName( |
| 462 webrtc::StatsReport::StatsValueName name) { |
| 463 // TODO(hbos): Translate StatsValueName -> WebRTCStatsMemberName. |
| 464 // crbug.com/627816 |
| 465 return blink::WebRTCStatsMemberNameUnknown; |
| 466 } |
| 467 |
| 468 blink::WebRTCStatsMemberType WebRTCStatsMemberTypeFromStatsValueType( |
| 469 webrtc::StatsReport::Value::Type type) { |
| 470 switch (type) { |
| 471 case StatsReport::Value::kInt: |
| 472 return blink::WebRTCStatsMemberTypeInt; |
| 473 case StatsReport::Value::kInt64: |
| 474 return blink::WebRTCStatsMemberTypeInt64; |
| 475 case StatsReport::Value::kFloat: |
| 476 return blink::WebRTCStatsMemberTypeFloat; |
| 477 case StatsReport::Value::kString: |
| 478 case StatsReport::Value::kStaticString: |
| 479 return blink::WebRTCStatsMemberTypeString; |
| 480 case StatsReport::Value::kBool: |
| 481 return blink::WebRTCStatsMemberTypeBool; |
| 482 case StatsReport::Value::kId: |
| 483 return blink::WebRTCStatsMemberTypeId; |
| 484 } |
| 485 NOTREACHED(); |
| 486 return blink::WebRTCStatsMemberTypeInt; |
| 487 } |
| 488 |
454 // Class mapping responses from calls to libjingle | 489 // Class mapping responses from calls to libjingle |
455 // GetStats into a blink::WebRTCStatsCallback. | 490 // GetStats into a blink::WebRTCStatsCallback. |
456 class StatsResponse : public webrtc::StatsObserver { | 491 class StatsResponse : public webrtc::StatsObserver { |
457 public: | 492 public: |
458 explicit StatsResponse(const scoped_refptr<LocalRTCStatsRequest>& request) | 493 explicit StatsResponse(const scoped_refptr<LocalRTCStatsRequest>& request) |
459 : request_(request.get()), | 494 : request_(request.get()), |
460 main_thread_(base::ThreadTaskRunnerHandle::Get()) { | 495 main_thread_(base::ThreadTaskRunnerHandle::Get()) { |
461 // Measure the overall time it takes to satisfy a getStats request. | 496 // Measure the overall time it takes to satisfy a getStats request. |
462 TRACE_EVENT_ASYNC_BEGIN0("webrtc", "getStats_Native", this); | 497 TRACE_EVENT_ASYNC_BEGIN0("webrtc", "getStats_Native", this); |
463 signaling_thread_checker_.DetachFromThread(); | 498 signaling_thread_checker_.DetachFromThread(); |
(...skipping 10 matching lines...) Expand all Loading... |
474 report_copies->push_back(new Report(r)); | 509 report_copies->push_back(new Report(r)); |
475 | 510 |
476 main_thread_->PostTaskAndReply(FROM_HERE, | 511 main_thread_->PostTaskAndReply(FROM_HERE, |
477 base::Bind(&StatsResponse::DeliverCallback, this, | 512 base::Bind(&StatsResponse::DeliverCallback, this, |
478 base::Unretained(report_copies)), | 513 base::Unretained(report_copies)), |
479 base::Bind(&StatsResponse::DeleteReports, | 514 base::Bind(&StatsResponse::DeleteReports, |
480 base::Unretained(report_copies))); | 515 base::Unretained(report_copies))); |
481 } | 516 } |
482 | 517 |
483 private: | 518 private: |
484 struct Report { | 519 class Report : public blink::WebRTCStats { |
| 520 public: |
| 521 class MemberIterator : public blink::WebRTCStatsMemberIterator { |
| 522 public: |
| 523 MemberIterator(const StatsReport::Values::const_iterator& it, |
| 524 const StatsReport::Values::const_iterator& end) |
| 525 : it_(it), end_(end) {} |
| 526 |
| 527 // blink::WebRTCStatsMemberIterator |
| 528 bool isEnd() const override { return it_ == end_; } |
| 529 void next() override { ++it_; } |
| 530 blink::WebRTCStatsMemberName name() const override { |
| 531 return WebRTCStatsMemberNameFromStatsValueName(it_->second->name); |
| 532 } |
| 533 blink::WebString displayName() const override { |
| 534 return blink::WebString::fromUTF8(it_->second->display_name()); |
| 535 } |
| 536 blink::WebRTCStatsMemberType type() const override { |
| 537 return WebRTCStatsMemberTypeFromStatsValueType(it_->second->type()); |
| 538 } |
| 539 int valueInt() const override { |
| 540 return it_->second->int_val(); |
| 541 } |
| 542 int64_t valueInt64() const override { |
| 543 return it_->second->int64_val(); |
| 544 } |
| 545 float valueFloat() const override { |
| 546 return it_->second->float_val(); |
| 547 } |
| 548 blink::WebString valueString() const override { |
| 549 const StatsReport::ValuePtr& value = it_->second; |
| 550 if (value->type() == StatsReport::Value::kString) |
| 551 return blink::WebString::fromUTF8(value->string_val()); |
| 552 DCHECK_EQ(value->type(), StatsReport::Value::kStaticString); |
| 553 return blink::WebString::fromUTF8(value->static_string_val()); |
| 554 } |
| 555 bool valueBool() const override { |
| 556 return it_->second->bool_val(); |
| 557 } |
| 558 blink::WebString valueToString() const override { |
| 559 const StatsReport::ValuePtr& value = it_->second; |
| 560 if (value->type() == StatsReport::Value::kString) |
| 561 return blink::WebString::fromUTF8(value->string_val()); |
| 562 if (value->type() == StatsReport::Value::kStaticString) |
| 563 return blink::WebString::fromUTF8(value->static_string_val()); |
| 564 return blink::WebString::fromUTF8(value->ToString()); |
| 565 } |
| 566 |
| 567 private: |
| 568 StatsReport::Values::const_iterator it_; |
| 569 StatsReport::Values::const_iterator end_; |
| 570 }; |
| 571 |
485 Report(const StatsReport* report) | 572 Report(const StatsReport* report) |
486 : thread_checker(), id(report->id()->ToString()), | 573 : thread_checker_(), |
487 type(report->TypeToString()), timestamp(report->timestamp()), | 574 id_(report->id()->ToString()), |
488 values(report->values()) { | 575 type_(report->type()), |
| 576 type_name_(report->TypeToString()), |
| 577 timestamp_(report->timestamp()), |
| 578 values_(report->values()) {} |
| 579 |
| 580 ~Report() override { |
| 581 // Since the values vector holds pointers to const objects that are bound |
| 582 // to the signaling thread, they must be released on the same thread. |
| 583 DCHECK(thread_checker_.CalledOnValidThread()); |
489 } | 584 } |
490 | 585 |
491 ~Report() { | 586 // blink::WebRTCStats |
492 // Since the values vector holds pointers to const objects that are bound | 587 blink::WebString id() const override { |
493 // to the signaling thread, they must be released on the same thread. | 588 return blink::WebString::fromUTF8(id_); |
494 DCHECK(thread_checker.CalledOnValidThread()); | 589 } |
| 590 blink::WebRTCStatsType type() const override { |
| 591 return WebRTCStatsTypeFromStatsType(type_); |
| 592 } |
| 593 blink::WebString typeToString() const override { |
| 594 return blink::WebString::fromUTF8(type_name_); |
| 595 } |
| 596 double timestamp() const override { |
| 597 return timestamp_; |
| 598 } |
| 599 blink::WebRTCStatsMemberIterator* iterator() const override { |
| 600 return new MemberIterator(values_.cbegin(), values_.cend()); |
495 } | 601 } |
496 | 602 |
497 const base::ThreadChecker thread_checker; | 603 bool HasValues() const { |
498 const std::string id, type; | 604 return values_.size() > 0; |
499 const double timestamp; | 605 } |
500 const StatsReport::Values values; | 606 |
| 607 private: |
| 608 const base::ThreadChecker thread_checker_; |
| 609 const std::string id_; |
| 610 const StatsReport::StatsType type_; |
| 611 const std::string type_name_; |
| 612 const double timestamp_; |
| 613 const StatsReport::Values values_; |
501 }; | 614 }; |
502 | 615 |
503 static void DeleteReports(std::vector<Report*>* reports) { | 616 static void DeleteReports(std::vector<Report*>* reports) { |
504 TRACE_EVENT0("webrtc", "StatsResponse::DeleteReports"); | 617 TRACE_EVENT0("webrtc", "StatsResponse::DeleteReports"); |
505 for (auto* p : *reports) | 618 for (auto* p : *reports) |
506 delete p; | 619 delete p; |
507 delete reports; | 620 delete reports; |
508 } | 621 } |
509 | 622 |
510 void DeliverCallback(const std::vector<Report*>* reports) { | 623 void DeliverCallback(const std::vector<Report*>* reports) { |
511 DCHECK(main_thread_->BelongsToCurrentThread()); | 624 DCHECK(main_thread_->BelongsToCurrentThread()); |
512 TRACE_EVENT0("webrtc", "StatsResponse::DeliverCallback"); | 625 TRACE_EVENT0("webrtc", "StatsResponse::DeliverCallback"); |
513 | 626 |
514 rtc::scoped_refptr<LocalRTCStatsResponse> response( | 627 rtc::scoped_refptr<LocalRTCStatsResponse> response( |
515 request_->createResponse().get()); | 628 request_->createResponse().get()); |
516 for (const auto* report : *reports) { | 629 for (const auto* report : *reports) { |
517 if (report->values.size() > 0) | 630 if (report->HasValues()) |
518 AddReport(response.get(), *report); | 631 AddReport(response.get(), *report); |
519 } | 632 } |
520 | 633 |
521 // Record the getStats operation as done before calling into Blink so that | 634 // Record the getStats operation as done before calling into Blink so that |
522 // we don't skew the perf measurements of the native code with whatever the | 635 // we don't skew the perf measurements of the native code with whatever the |
523 // callback might be doing. | 636 // callback might be doing. |
524 TRACE_EVENT_ASYNC_END0("webrtc", "getStats_Native", this); | 637 TRACE_EVENT_ASYNC_END0("webrtc", "getStats_Native", this); |
525 request_->requestSucceeded(response); | 638 request_->requestSucceeded(response); |
526 request_ = nullptr; // must be freed on the main thread. | 639 request_ = nullptr; // must be freed on the main thread. |
527 } | 640 } |
528 | 641 |
529 void AddReport(LocalRTCStatsResponse* response, const Report& report) { | 642 void AddReport(LocalRTCStatsResponse* response, const Report& report) { |
530 int idx = response->addReport(blink::WebString::fromUTF8(report.id), | 643 response->addStats(report); |
531 blink::WebString::fromUTF8(report.type), | |
532 report.timestamp); | |
533 blink::WebString name, value_str; | |
534 for (const auto& value : report.values) { | |
535 const StatsReport::ValuePtr& v = value.second; | |
536 name = blink::WebString::fromUTF8(value.second->display_name()); | |
537 | |
538 if (v->type() == StatsReport::Value::kString) | |
539 value_str = blink::WebString::fromUTF8(v->string_val()); | |
540 if (v->type() == StatsReport::Value::kStaticString) | |
541 value_str = blink::WebString::fromUTF8(v->static_string_val()); | |
542 else | |
543 value_str = blink::WebString::fromUTF8(v->ToString()); | |
544 | |
545 response->addStatistic(idx, name, value_str); | |
546 } | |
547 } | 644 } |
548 | 645 |
549 rtc::scoped_refptr<LocalRTCStatsRequest> request_; | 646 rtc::scoped_refptr<LocalRTCStatsRequest> request_; |
550 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 647 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
551 base::ThreadChecker signaling_thread_checker_; | 648 base::ThreadChecker signaling_thread_checker_; |
552 }; | 649 }; |
553 | 650 |
554 void GetStatsOnSignalingThread( | 651 void GetStatsOnSignalingThread( |
555 const scoped_refptr<webrtc::PeerConnectionInterface>& pc, | 652 const scoped_refptr<webrtc::PeerConnectionInterface>& pc, |
556 webrtc::PeerConnectionInterface::StatsOutputLevel level, | 653 webrtc::PeerConnectionInterface::StatsOutputLevel level, |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 void LocalRTCStatsRequest::requestSucceeded( | 845 void LocalRTCStatsRequest::requestSucceeded( |
749 const LocalRTCStatsResponse* response) { | 846 const LocalRTCStatsResponse* response) { |
750 impl_.requestSucceeded(response->webKitStatsResponse()); | 847 impl_.requestSucceeded(response->webKitStatsResponse()); |
751 } | 848 } |
752 | 849 |
753 // Implementation of LocalRTCStatsResponse. | 850 // Implementation of LocalRTCStatsResponse. |
754 blink::WebRTCStatsResponse LocalRTCStatsResponse::webKitStatsResponse() const { | 851 blink::WebRTCStatsResponse LocalRTCStatsResponse::webKitStatsResponse() const { |
755 return impl_; | 852 return impl_; |
756 } | 853 } |
757 | 854 |
758 size_t LocalRTCStatsResponse::addReport(blink::WebString type, | 855 void LocalRTCStatsResponse::addStats(const blink::WebRTCStats& stats) { |
759 blink::WebString id, | 856 impl_.addStats(stats); |
760 double timestamp) { | |
761 return impl_.addReport(type, id, timestamp); | |
762 } | |
763 | |
764 void LocalRTCStatsResponse::addStatistic(size_t report, | |
765 blink::WebString name, | |
766 blink::WebString value) { | |
767 impl_.addStatistic(report, name, value); | |
768 } | 857 } |
769 | 858 |
770 // Receives notifications from a PeerConnection object about state changes, | 859 // Receives notifications from a PeerConnection object about state changes, |
771 // track addition/removal etc. The callbacks we receive here come on the | 860 // track addition/removal etc. The callbacks we receive here come on the |
772 // signaling thread, so this class takes care of delivering them to an | 861 // signaling thread, so this class takes care of delivering them to an |
773 // RTCPeerConnectionHandler instance on the main thread. | 862 // RTCPeerConnectionHandler instance on the main thread. |
774 // In order to do safe PostTask-ing, the class is reference counted and | 863 // In order to do safe PostTask-ing, the class is reference counted and |
775 // checks for the existence of the RTCPeerConnectionHandler instance before | 864 // checks for the existence of the RTCPeerConnectionHandler instance before |
776 // delivering callbacks on the main thread. | 865 // delivering callbacks on the main thread. |
777 class RTCPeerConnectionHandler::Observer | 866 class RTCPeerConnectionHandler::Observer |
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 } | 1894 } |
1806 | 1895 |
1807 void RTCPeerConnectionHandler::ResetUMAStats() { | 1896 void RTCPeerConnectionHandler::ResetUMAStats() { |
1808 DCHECK(thread_checker_.CalledOnValidThread()); | 1897 DCHECK(thread_checker_.CalledOnValidThread()); |
1809 num_local_candidates_ipv6_ = 0; | 1898 num_local_candidates_ipv6_ = 0; |
1810 num_local_candidates_ipv4_ = 0; | 1899 num_local_candidates_ipv4_ = 0; |
1811 ice_connection_checking_start_ = base::TimeTicks(); | 1900 ice_connection_checking_start_ = base::TimeTicks(); |
1812 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); | 1901 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); |
1813 } | 1902 } |
1814 } // namespace content | 1903 } // namespace content |
OLD | NEW |