Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Side by Side Diff: extensions/renderer/api/display_source/wifi_display/wifi_display_session.cc

Issue 1783843002: [chrome.displaySource][WiFi Display] Video formats capability negotiation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@export_video_format
Patch Set: Style fixes Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/renderer/api/display_source/wifi_display/wifi_display_session.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
9 #include "content/public/common/service_registry.h" 11 #include "content/public/common/service_registry.h"
10 #include "content/public/renderer/render_frame.h" 12 #include "content/public/renderer/render_frame.h"
11 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_media _manager.h" 13 #include "extensions/renderer/api/display_source/wifi_display/wifi_display_media _manager.h"
12 #include "third_party/wds/src/libwds/public/logging.h" 14 #include "third_party/wds/src/libwds/public/logging.h"
13 #include "third_party/wds/src/libwds/public/media_manager.h" 15 #include "third_party/wds/src/libwds/public/media_manager.h"
14 16
15 namespace { 17 namespace {
16 const char kErrorInternal[] = "An internal error has occurred"; 18 const char kErrorInternal[] = "An internal error has occurred";
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 DCHECK(!error_callback_.is_null()) 64 DCHECK(!error_callback_.is_null())
63 << "Should be set with 'SetNotificationCallbacks'"; 65 << "Should be set with 'SetNotificationCallbacks'";
64 66
65 service_->Connect(params_.sink_id, params_.auth_method, params_.auth_data); 67 service_->Connect(params_.sink_id, params_.auth_method, params_.auth_data);
66 state_ = DisplaySourceSession::Establishing; 68 state_ = DisplaySourceSession::Establishing;
67 start_completion_callback_ = callback; 69 start_completion_callback_ = callback;
68 } 70 }
69 71
70 void WiFiDisplaySession::Terminate(const CompletionCallback& callback) { 72 void WiFiDisplaySession::Terminate(const CompletionCallback& callback) {
71 DCHECK_EQ(DisplaySourceSession::Established, state_); 73 DCHECK_EQ(DisplaySourceSession::Established, state_);
72 service_->Disconnect(); 74 Terminate();
73 state_ = DisplaySourceSession::Terminating;
74 teminate_completion_callback_ = callback; 75 teminate_completion_callback_ = callback;
75 } 76 }
76 77
77 void WiFiDisplaySession::OnConnected(const mojo::String& ip_address) { 78 void WiFiDisplaySession::OnConnected(const mojo::String& ip_address) {
78 DCHECK_EQ(DisplaySourceSession::Established, state_); 79 DCHECK_EQ(DisplaySourceSession::Established, state_);
79 ip_address_ = ip_address; 80 ip_address_ = ip_address;
80 media_manager_.reset(new WiFiDisplayMediaManager()); 81 media_manager_.reset(
82 new WiFiDisplayMediaManager(
83 params_.video_track,
84 params_.audio_track,
85 base::Bind(
86 &WiFiDisplaySession::OnMediaError,
87 weak_factory_.GetWeakPtr())));
81 wfd_source_.reset(wds::Source::Create(this, media_manager_.get(), this)); 88 wfd_source_.reset(wds::Source::Create(this, media_manager_.get(), this));
82 wfd_source_->Start(); 89 wfd_source_->Start();
83 } 90 }
84 91
85 void WiFiDisplaySession::OnConnectRequestHandled(bool success, 92 void WiFiDisplaySession::OnConnectRequestHandled(bool success,
86 const mojo::String& error) { 93 const mojo::String& error) {
87 DCHECK_EQ(DisplaySourceSession::Establishing, state_); 94 DCHECK_EQ(DisplaySourceSession::Establishing, state_);
88 state_ = 95 state_ =
89 success ? DisplaySourceSession::Established : DisplaySourceSession::Idle; 96 success ? DisplaySourceSession::Established : DisplaySourceSession::Idle;
90 RunStartCallback(success, error); 97 RunStartCallback(success, error);
(...skipping 19 matching lines...) Expand all
110 DCHECK_EQ(DisplaySourceSession::Established, state_); 117 DCHECK_EQ(DisplaySourceSession::Established, state_);
111 error_callback_.Run(static_cast<ErrorType>(type), description); 118 error_callback_.Run(static_cast<ErrorType>(type), description);
112 } 119 }
113 120
114 void WiFiDisplaySession::OnMessage(const mojo::String& data) { 121 void WiFiDisplaySession::OnMessage(const mojo::String& data) {
115 DCHECK_EQ(DisplaySourceSession::Established, state_); 122 DCHECK_EQ(DisplaySourceSession::Established, state_);
116 DCHECK(wfd_source_); 123 DCHECK(wfd_source_);
117 wfd_source_->RTSPDataReceived(data); 124 wfd_source_->RTSPDataReceived(data);
118 } 125 }
119 126
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 { 127 std::string WiFiDisplaySession::GetLocalIPAddress() const {
141 return ip_address_; 128 return ip_address_;
142 } 129 }
143 130
144 int WiFiDisplaySession::GetNextCSeq(int* initial_peer_cseq) const { 131 int WiFiDisplaySession::GetNextCSeq(int* initial_peer_cseq) const {
145 return ++cseq_; 132 return ++cseq_;
146 } 133 }
147 134
148 void WiFiDisplaySession::SendRTSPData(const std::string& message) { 135 void WiFiDisplaySession::SendRTSPData(const std::string& message) {
149 service_->SendMessage(message); 136 service_->SendMessage(message);
(...skipping 21 matching lines...) Expand all
171 158
172 void WiFiDisplaySession::ErrorOccurred(wds::ErrorType error) { 159 void WiFiDisplaySession::ErrorOccurred(wds::ErrorType error) {
173 DCHECK_NE(DisplaySourceSession::Idle, state_); 160 DCHECK_NE(DisplaySourceSession::Idle, state_);
174 if (error == wds::TimeoutError) { 161 if (error == wds::TimeoutError) {
175 error_callback_.Run(api::display_source::ERROR_TYPE_TIMEOUT_ERROR, 162 error_callback_.Run(api::display_source::ERROR_TYPE_TIMEOUT_ERROR,
176 kErrorTimeout); 163 kErrorTimeout);
177 } else { 164 } else {
178 error_callback_.Run(api::display_source::ERROR_TYPE_UNKNOWN_ERROR, 165 error_callback_.Run(api::display_source::ERROR_TYPE_UNKNOWN_ERROR,
179 kErrorInternal); 166 kErrorInternal);
180 } 167 }
181 168 // The session cannot continue.
182 if (state_ == DisplaySourceSession::Established) { 169 Terminate();
183 // The session cannot continue.
184 service_->Disconnect();
185 state_ = DisplaySourceSession::Terminating;
186 }
187 } 170 }
188 171
189 void WiFiDisplaySession::SessionCompleted() { 172 void WiFiDisplaySession::SessionCompleted() {
190 DCHECK_NE(DisplaySourceSession::Idle, state_); 173 DCHECK_NE(DisplaySourceSession::Idle, state_);
174 // The session has finished normally.
175 Terminate();
176 }
177
178 void WiFiDisplaySession::OnIPCConnectionError() {
179 // We must explicitly notify the session termination as it will never
180 // arrive from browser process (IPC is broken).
181 switch (state_) {
182 case DisplaySourceSession::Idle:
183 case DisplaySourceSession::Establishing:
184 RunStartCallback(false, kErrorInternal);
185 break;
186 case DisplaySourceSession::Terminating:
187 case DisplaySourceSession::Established:
188 error_callback_.Run(api::display_source::ERROR_TYPE_UNKNOWN_ERROR,
189 kErrorInternal);
190 state_ = DisplaySourceSession::Idle;
191 terminated_callback_.Run();
192 break;
193 default:
194 NOTREACHED();
195 }
196 }
197
198 void WiFiDisplaySession::OnMediaError(const std::string& error) {
199 DCHECK_NE(DisplaySourceSession::Idle, state_);
200 error_callback_.Run(api::display_source::ERROR_TYPE_MEDIA_PIPELINE_ERROR,
201 error);
202 Terminate();
203 }
204
205 void WiFiDisplaySession::Terminate() {
191 if (state_ == DisplaySourceSession::Established) { 206 if (state_ == DisplaySourceSession::Established) {
192 // The session has finished normally.
193 service_->Disconnect(); 207 service_->Disconnect();
194 state_ = DisplaySourceSession::Terminating; 208 state_ = DisplaySourceSession::Terminating;
195 } 209 }
196 } 210 }
197 211
198 void WiFiDisplaySession::RunStartCallback(bool success, 212 void WiFiDisplaySession::RunStartCallback(bool success,
199 const std::string& error_message) { 213 const std::string& error_message) {
200 if (!start_completion_callback_.is_null()) 214 if (!start_completion_callback_.is_null())
201 start_completion_callback_.Run(success, error_message); 215 start_completion_callback_.Run(success, error_message);
202 } 216 }
203 217
204 void WiFiDisplaySession::RunTerminateCallback( 218 void WiFiDisplaySession::RunTerminateCallback(
205 bool success, 219 bool success,
206 const std::string& error_message) { 220 const std::string& error_message) {
207 if (!teminate_completion_callback_.is_null()) 221 if (!teminate_completion_callback_.is_null())
208 teminate_completion_callback_.Run(success, error_message); 222 teminate_completion_callback_.Run(success, error_message);
209 } 223 }
210 224
211 } // namespace extensions 225 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/api/display_source/wifi_display/wifi_display_session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698