OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "extensions/renderer/api/display_source/wifi_display/wifi_display_sessi
on.h" | 5 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_sessi
on.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
9 #include "content/public/common/service_registry.h" | 9 #include "content/public/common/service_registry.h" |
10 #include "content/public/renderer/render_frame.h" | 10 #include "content/public/renderer/render_frame.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 DCHECK(!error_callback_.is_null()) | 62 DCHECK(!error_callback_.is_null()) |
63 << "Should be set with 'SetNotificationCallbacks'"; | 63 << "Should be set with 'SetNotificationCallbacks'"; |
64 | 64 |
65 service_->Connect(params_.sink_id, params_.auth_method, params_.auth_data); | 65 service_->Connect(params_.sink_id, params_.auth_method, params_.auth_data); |
66 state_ = DisplaySourceSession::Establishing; | 66 state_ = DisplaySourceSession::Establishing; |
67 start_completion_callback_ = callback; | 67 start_completion_callback_ = callback; |
68 } | 68 } |
69 | 69 |
70 void WiFiDisplaySession::Terminate(const CompletionCallback& callback) { | 70 void WiFiDisplaySession::Terminate(const CompletionCallback& callback) { |
71 DCHECK_EQ(DisplaySourceSession::Established, state_); | 71 DCHECK_EQ(DisplaySourceSession::Established, state_); |
72 service_->Disconnect(); | 72 Terminate(); |
73 state_ = DisplaySourceSession::Terminating; | |
74 teminate_completion_callback_ = callback; | 73 teminate_completion_callback_ = callback; |
75 } | 74 } |
76 | 75 |
77 void WiFiDisplaySession::OnConnected(const mojo::String& ip_address) { | 76 void WiFiDisplaySession::OnConnected(const mojo::String& ip_address) { |
78 DCHECK_EQ(DisplaySourceSession::Established, state_); | 77 DCHECK_EQ(DisplaySourceSession::Established, state_); |
79 ip_address_ = ip_address; | 78 ip_address_ = ip_address; |
80 media_manager_.reset(new WiFiDisplayMediaManager()); | 79 media_manager_.reset( |
| 80 new WiFiDisplayMediaManager( |
| 81 params_.video_track, |
| 82 params_.audio_track, |
| 83 base::Bind( |
| 84 &WiFiDisplaySession::OnMediaError, |
| 85 weak_factory_.GetWeakPtr()))); |
81 wfd_source_.reset(wds::Source::Create(this, media_manager_.get(), this)); | 86 wfd_source_.reset(wds::Source::Create(this, media_manager_.get(), this)); |
82 wfd_source_->Start(); | 87 wfd_source_->Start(); |
83 } | 88 } |
84 | 89 |
85 void WiFiDisplaySession::OnConnectRequestHandled(bool success, | 90 void WiFiDisplaySession::OnConnectRequestHandled(bool success, |
86 const mojo::String& error) { | 91 const mojo::String& error) { |
87 DCHECK_EQ(DisplaySourceSession::Establishing, state_); | 92 DCHECK_EQ(DisplaySourceSession::Establishing, state_); |
88 state_ = | 93 state_ = |
89 success ? DisplaySourceSession::Established : DisplaySourceSession::Idle; | 94 success ? DisplaySourceSession::Established : DisplaySourceSession::Idle; |
90 RunStartCallback(success, error); | 95 RunStartCallback(success, error); |
(...skipping 19 matching lines...) Expand all Loading... |
110 DCHECK_EQ(DisplaySourceSession::Established, state_); | 115 DCHECK_EQ(DisplaySourceSession::Established, state_); |
111 error_callback_.Run(static_cast<ErrorType>(type), description); | 116 error_callback_.Run(static_cast<ErrorType>(type), description); |
112 } | 117 } |
113 | 118 |
114 void WiFiDisplaySession::OnMessage(const mojo::String& data) { | 119 void WiFiDisplaySession::OnMessage(const mojo::String& data) { |
115 DCHECK_EQ(DisplaySourceSession::Established, state_); | 120 DCHECK_EQ(DisplaySourceSession::Established, state_); |
116 DCHECK(wfd_source_); | 121 DCHECK(wfd_source_); |
117 wfd_source_->RTSPDataReceived(data); | 122 wfd_source_->RTSPDataReceived(data); |
118 } | 123 } |
119 | 124 |
120 void WiFiDisplaySession::OnIPCConnectionError() { | |
121 // We must explicitly notify the session termination as it will never | |
122 // arrive from browser process (IPC is broken). | |
123 switch (state_) { | |
124 case DisplaySourceSession::Idle: | |
125 case DisplaySourceSession::Establishing: | |
126 RunStartCallback(false, kErrorInternal); | |
127 break; | |
128 case DisplaySourceSession::Terminating: | |
129 case DisplaySourceSession::Established: | |
130 error_callback_.Run(api::display_source::ERROR_TYPE_UNKNOWN_ERROR, | |
131 kErrorInternal); | |
132 state_ = DisplaySourceSession::Idle; | |
133 terminated_callback_.Run(); | |
134 break; | |
135 default: | |
136 NOTREACHED(); | |
137 } | |
138 } | |
139 | |
140 std::string WiFiDisplaySession::GetLocalIPAddress() const { | 125 std::string WiFiDisplaySession::GetLocalIPAddress() const { |
141 return ip_address_; | 126 return ip_address_; |
142 } | 127 } |
143 | 128 |
144 int WiFiDisplaySession::GetNextCSeq(int* initial_peer_cseq) const { | 129 int WiFiDisplaySession::GetNextCSeq(int* initial_peer_cseq) const { |
145 return ++cseq_; | 130 return ++cseq_; |
146 } | 131 } |
147 | 132 |
148 void WiFiDisplaySession::SendRTSPData(const std::string& message) { | 133 void WiFiDisplaySession::SendRTSPData(const std::string& message) { |
149 service_->SendMessage(message); | 134 service_->SendMessage(message); |
(...skipping 21 matching lines...) Expand all Loading... |
171 | 156 |
172 void WiFiDisplaySession::ErrorOccurred(wds::ErrorType error) { | 157 void WiFiDisplaySession::ErrorOccurred(wds::ErrorType error) { |
173 DCHECK_NE(DisplaySourceSession::Idle, state_); | 158 DCHECK_NE(DisplaySourceSession::Idle, state_); |
174 if (error == wds::TimeoutError) { | 159 if (error == wds::TimeoutError) { |
175 error_callback_.Run(api::display_source::ERROR_TYPE_TIMEOUT_ERROR, | 160 error_callback_.Run(api::display_source::ERROR_TYPE_TIMEOUT_ERROR, |
176 kErrorTimeout); | 161 kErrorTimeout); |
177 } else { | 162 } else { |
178 error_callback_.Run(api::display_source::ERROR_TYPE_UNKNOWN_ERROR, | 163 error_callback_.Run(api::display_source::ERROR_TYPE_UNKNOWN_ERROR, |
179 kErrorInternal); | 164 kErrorInternal); |
180 } | 165 } |
181 | 166 // The session cannot continue. |
182 if (state_ == DisplaySourceSession::Established) { | 167 Terminate(); |
183 // The session cannot continue. | |
184 service_->Disconnect(); | |
185 state_ = DisplaySourceSession::Terminating; | |
186 } | |
187 } | 168 } |
188 | 169 |
189 void WiFiDisplaySession::SessionCompleted() { | 170 void WiFiDisplaySession::SessionCompleted() { |
190 DCHECK_NE(DisplaySourceSession::Idle, state_); | 171 DCHECK_NE(DisplaySourceSession::Idle, state_); |
| 172 // The session has finished normally. |
| 173 Terminate(); |
| 174 } |
| 175 |
| 176 void WiFiDisplaySession::OnIPCConnectionError() { |
| 177 // We must explicitly notify the session termination as it will never |
| 178 // arrive from browser process (IPC is broken). |
| 179 switch (state_) { |
| 180 case DisplaySourceSession::Idle: |
| 181 case DisplaySourceSession::Establishing: |
| 182 RunStartCallback(false, kErrorInternal); |
| 183 break; |
| 184 case DisplaySourceSession::Terminating: |
| 185 case DisplaySourceSession::Established: |
| 186 error_callback_.Run(api::display_source::ERROR_TYPE_UNKNOWN_ERROR, |
| 187 kErrorInternal); |
| 188 state_ = DisplaySourceSession::Idle; |
| 189 terminated_callback_.Run(); |
| 190 break; |
| 191 default: |
| 192 NOTREACHED(); |
| 193 } |
| 194 } |
| 195 |
| 196 void WiFiDisplaySession::OnMediaError(const std::string& error) { |
| 197 DCHECK_NE(DisplaySourceSession::Idle, state_); |
| 198 error_callback_.Run(api::display_source::ERROR_TYPE_MEDIA_PIPELINE_ERROR, |
| 199 error); |
| 200 Terminate(); |
| 201 } |
| 202 |
| 203 void WiFiDisplaySession::Terminate() { |
191 if (state_ == DisplaySourceSession::Established) { | 204 if (state_ == DisplaySourceSession::Established) { |
192 // The session has finished normally. | |
193 service_->Disconnect(); | 205 service_->Disconnect(); |
194 state_ = DisplaySourceSession::Terminating; | 206 state_ = DisplaySourceSession::Terminating; |
195 } | 207 } |
196 } | 208 } |
197 | 209 |
198 void WiFiDisplaySession::RunStartCallback(bool success, | 210 void WiFiDisplaySession::RunStartCallback(bool success, |
199 const std::string& error_message) { | 211 const std::string& error_message) { |
200 if (!start_completion_callback_.is_null()) | 212 if (!start_completion_callback_.is_null()) |
201 start_completion_callback_.Run(success, error_message); | 213 start_completion_callback_.Run(success, error_message); |
202 } | 214 } |
203 | 215 |
204 void WiFiDisplaySession::RunTerminateCallback( | 216 void WiFiDisplaySession::RunTerminateCallback( |
205 bool success, | 217 bool success, |
206 const std::string& error_message) { | 218 const std::string& error_message) { |
207 if (!teminate_completion_callback_.is_null()) | 219 if (!teminate_completion_callback_.is_null()) |
208 teminate_completion_callback_.Run(success, error_message); | 220 teminate_completion_callback_.Run(success, error_message); |
209 } | 221 } |
210 | 222 |
211 } // namespace extensions | 223 } // namespace extensions |
OLD | NEW |