| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "remoting/host/cast_extension_session.h" | 5 #include "remoting/host/cast_extension_session.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" | 
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" | 
| 10 #include "base/logging.h" | 10 #include "base/logging.h" | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 64 const int kMinFramesPerSecond = 5; | 64 const int kMinFramesPerSecond = 5; | 
| 65 | 65 | 
| 66 // A webrtc::SetSessionDescriptionObserver implementation used to receive the | 66 // A webrtc::SetSessionDescriptionObserver implementation used to receive the | 
| 67 // results of setting local and remote descriptions of the PeerConnection. | 67 // results of setting local and remote descriptions of the PeerConnection. | 
| 68 class CastSetSessionDescriptionObserver | 68 class CastSetSessionDescriptionObserver | 
| 69     : public webrtc::SetSessionDescriptionObserver { | 69     : public webrtc::SetSessionDescriptionObserver { | 
| 70  public: | 70  public: | 
| 71   static CastSetSessionDescriptionObserver* Create() { | 71   static CastSetSessionDescriptionObserver* Create() { | 
| 72     return new rtc::RefCountedObject<CastSetSessionDescriptionObserver>(); | 72     return new rtc::RefCountedObject<CastSetSessionDescriptionObserver>(); | 
| 73   } | 73   } | 
| 74   virtual void OnSuccess() override { | 74   void OnSuccess() override { | 
| 75     VLOG(1) << "Setting session description succeeded."; | 75     VLOG(1) << "Setting session description succeeded."; | 
| 76   } | 76   } | 
| 77   virtual void OnFailure(const std::string& error) override { | 77   void OnFailure(const std::string& error) override { | 
| 78     LOG(ERROR) << "Setting session description failed: " << error; | 78     LOG(ERROR) << "Setting session description failed: " << error; | 
| 79   } | 79   } | 
| 80 | 80 | 
| 81  protected: | 81  protected: | 
| 82   CastSetSessionDescriptionObserver() {} | 82   CastSetSessionDescriptionObserver() {} | 
| 83   virtual ~CastSetSessionDescriptionObserver() {} | 83   ~CastSetSessionDescriptionObserver() override {} | 
| 84 | 84 | 
| 85   DISALLOW_COPY_AND_ASSIGN(CastSetSessionDescriptionObserver); | 85   DISALLOW_COPY_AND_ASSIGN(CastSetSessionDescriptionObserver); | 
| 86 }; | 86 }; | 
| 87 | 87 | 
| 88 // A webrtc::CreateSessionDescriptionObserver implementation used to receive the | 88 // A webrtc::CreateSessionDescriptionObserver implementation used to receive the | 
| 89 // results of creating descriptions for this end of the PeerConnection. | 89 // results of creating descriptions for this end of the PeerConnection. | 
| 90 class CastCreateSessionDescriptionObserver | 90 class CastCreateSessionDescriptionObserver | 
| 91     : public webrtc::CreateSessionDescriptionObserver { | 91     : public webrtc::CreateSessionDescriptionObserver { | 
| 92  public: | 92  public: | 
| 93   static CastCreateSessionDescriptionObserver* Create( | 93   static CastCreateSessionDescriptionObserver* Create( | 
| 94       CastExtensionSession* session) { | 94       CastExtensionSession* session) { | 
| 95     return new rtc::RefCountedObject<CastCreateSessionDescriptionObserver>( | 95     return new rtc::RefCountedObject<CastCreateSessionDescriptionObserver>( | 
| 96         session); | 96         session); | 
| 97   } | 97   } | 
| 98   virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc) override { | 98   void OnSuccess(webrtc::SessionDescriptionInterface* desc) override { | 
| 99     if (cast_extension_session_ == NULL) { | 99     if (cast_extension_session_ == NULL) { | 
| 100       LOG(ERROR) | 100       LOG(ERROR) | 
| 101           << "No CastExtensionSession. Creating session description succeeded."; | 101           << "No CastExtensionSession. Creating session description succeeded."; | 
| 102       return; | 102       return; | 
| 103     } | 103     } | 
| 104     cast_extension_session_->OnCreateSessionDescription(desc); | 104     cast_extension_session_->OnCreateSessionDescription(desc); | 
| 105   } | 105   } | 
| 106   virtual void OnFailure(const std::string& error) override { | 106   void OnFailure(const std::string& error) override { | 
| 107     if (cast_extension_session_ == NULL) { | 107     if (cast_extension_session_ == NULL) { | 
| 108       LOG(ERROR) | 108       LOG(ERROR) | 
| 109           << "No CastExtensionSession. Creating session description failed."; | 109           << "No CastExtensionSession. Creating session description failed."; | 
| 110       return; | 110       return; | 
| 111     } | 111     } | 
| 112     cast_extension_session_->OnCreateSessionDescriptionFailure(error); | 112     cast_extension_session_->OnCreateSessionDescriptionFailure(error); | 
| 113   } | 113   } | 
| 114   void SetCastExtensionSession(CastExtensionSession* cast_extension_session) { | 114   void SetCastExtensionSession(CastExtensionSession* cast_extension_session) { | 
| 115     cast_extension_session_ = cast_extension_session; | 115     cast_extension_session_ = cast_extension_session; | 
| 116   } | 116   } | 
| 117 | 117 | 
| 118  protected: | 118  protected: | 
| 119   explicit CastCreateSessionDescriptionObserver(CastExtensionSession* session) | 119   explicit CastCreateSessionDescriptionObserver(CastExtensionSession* session) | 
| 120       : cast_extension_session_(session) {} | 120       : cast_extension_session_(session) {} | 
| 121   virtual ~CastCreateSessionDescriptionObserver() {} | 121   ~CastCreateSessionDescriptionObserver() override {} | 
| 122 | 122 | 
| 123  private: | 123  private: | 
| 124   CastExtensionSession* cast_extension_session_; | 124   CastExtensionSession* cast_extension_session_; | 
| 125 | 125 | 
| 126   DISALLOW_COPY_AND_ASSIGN(CastCreateSessionDescriptionObserver); | 126   DISALLOW_COPY_AND_ASSIGN(CastCreateSessionDescriptionObserver); | 
| 127 }; | 127 }; | 
| 128 | 128 | 
| 129 // A webrtc::StatsObserver implementation used to receive statistics about the | 129 // A webrtc::StatsObserver implementation used to receive statistics about the | 
| 130 // current PeerConnection. | 130 // current PeerConnection. | 
| 131 class CastStatsObserver : public webrtc::StatsObserver { | 131 class CastStatsObserver : public webrtc::StatsObserver { | 
| 132  public: | 132  public: | 
| 133   static CastStatsObserver* Create() { | 133   static CastStatsObserver* Create() { | 
| 134     return new rtc::RefCountedObject<CastStatsObserver>(); | 134     return new rtc::RefCountedObject<CastStatsObserver>(); | 
| 135   } | 135   } | 
| 136 | 136 | 
| 137   virtual void OnComplete( | 137   void OnComplete(const std::vector<webrtc::StatsReport>& reports) override { | 
| 138       const std::vector<webrtc::StatsReport>& reports) override { |  | 
| 139     typedef webrtc::StatsReport::Values::iterator ValuesIterator; | 138     typedef webrtc::StatsReport::Values::iterator ValuesIterator; | 
| 140 | 139 | 
| 141     VLOG(1) << "Received " << reports.size() << " new StatsReports."; | 140     VLOG(1) << "Received " << reports.size() << " new StatsReports."; | 
| 142 | 141 | 
| 143     int index; | 142     int index; | 
| 144     std::vector<webrtc::StatsReport>::const_iterator it; | 143     std::vector<webrtc::StatsReport>::const_iterator it; | 
| 145     for (it = reports.begin(), index = 0; it != reports.end(); ++it, ++index) { | 144     for (it = reports.begin(), index = 0; it != reports.end(); ++it, ++index) { | 
| 146       webrtc::StatsReport::Values v = it->values; | 145       webrtc::StatsReport::Values v = it->values; | 
| 147       VLOG(1) << "Report " << index << ":"; | 146       VLOG(1) << "Report " << index << ":"; | 
| 148       for (ValuesIterator vIt = v.begin(); vIt != v.end(); ++vIt) { | 147       for (ValuesIterator vIt = v.begin(); vIt != v.end(); ++vIt) { | 
| 149         VLOG(1) << "Stat: " << vIt->name << "=" << vIt->value << "."; | 148         VLOG(1) << "Stat: " << vIt->name << "=" << vIt->value << "."; | 
| 150       } | 149       } | 
| 151     } | 150     } | 
| 152   } | 151   } | 
| 153 | 152 | 
| 154  protected: | 153  protected: | 
| 155   CastStatsObserver() {} | 154   CastStatsObserver() {} | 
| 156   virtual ~CastStatsObserver() {} | 155   ~CastStatsObserver() override {} | 
| 157 | 156 | 
| 158   DISALLOW_COPY_AND_ASSIGN(CastStatsObserver); | 157   DISALLOW_COPY_AND_ASSIGN(CastStatsObserver); | 
| 159 }; | 158 }; | 
| 160 | 159 | 
| 161 // TODO(aiguha): Fix PeerConnnection-related tear down crash caused by premature | 160 // TODO(aiguha): Fix PeerConnnection-related tear down crash caused by premature | 
| 162 // destruction of cricket::CaptureManager (which occurs on releasing | 161 // destruction of cricket::CaptureManager (which occurs on releasing | 
| 163 // |peer_conn_factory_|). See crbug.com/403840. | 162 // |peer_conn_factory_|). See crbug.com/403840. | 
| 164 CastExtensionSession::~CastExtensionSession() { | 163 CastExtensionSession::~CastExtensionSession() { | 
| 165   DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 164   DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 
| 166 | 165 | 
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 661   json->SetString(kWebRtcCandidate, candidate_str); | 660   json->SetString(kWebRtcCandidate, candidate_str); | 
| 662   std::string json_str; | 661   std::string json_str; | 
| 663   if (!base::JSONWriter::Write(json.get(), &json_str)) { | 662   if (!base::JSONWriter::Write(json.get(), &json_str)) { | 
| 664     LOG(ERROR) << "Failed to serialize candidate message."; | 663     LOG(ERROR) << "Failed to serialize candidate message."; | 
| 665     return; | 664     return; | 
| 666   } | 665   } | 
| 667   SendMessageToClient(kSubjectNewCandidate, json_str); | 666   SendMessageToClient(kSubjectNewCandidate, json_str); | 
| 668 } | 667 } | 
| 669 | 668 | 
| 670 }  // namespace remoting | 669 }  // namespace remoting | 
| OLD | NEW | 
|---|