Skip to content

Commit be1bb74

Browse files
Gavin WilliamsChromium LUCI CQ
authored andcommitted
Boca: Plumb CRD AudioPackets to the WebUI page handler
This change sets up the necessary plumbing to forward audio packets from the Boca CRD client stack to the Boca WebUI's page handler. Bug: 450986461 Change-Id: Ic17140afd49e0638ca39912ff2180a95cfff9dfd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7046787 Reviewed-by: Ahmed Nasr <[email protected]> Commit-Queue: Gavin Williams <[email protected]> Cr-Commit-Position: refs/heads/main@{#1532388}
1 parent 8d91d6c commit be1bb74

11 files changed

+122
-27
lines changed

ash/webui/boca_receiver_app_ui/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static_library("boca_receiver_app_ui") {
3737
"//content/public/common",
3838
"//google_apis/common",
3939
"//net/traffic_annotation",
40+
"//remoting/proto",
4041
"//ui/webui",
4142
]
4243
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include_rules = [
22
"+google_apis/common",
3+
"+remoting/proto/audio.pb.h",
34
"+third_party/skia/include/core/SkBitmap.h",
45
"+third_party/webrtc/modules/desktop_capture/desktop_frame.h",
56
]

ash/webui/boca_receiver_app_ui/boca_receiver_untrusted_page_handler.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "google_apis/common/request_sender.h"
3232
#include "mojo/public/cpp/bindings/pending_remote.h"
3333
#include "net/traffic_annotation/network_traffic_annotation.h"
34+
#include "remoting/proto/audio.pb.h"
3435
#include "third_party/skia/include/core/SkBitmap.h"
3536
#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
3637

@@ -283,6 +284,9 @@ void BocaReceiverUntrustedPageHandler::MaybeStartConnection(
283284
weak_ptr_factory_.GetWeakPtr()),
284285
base::BindRepeating(&BocaReceiverUntrustedPageHandler::OnCrdFrameReceived,
285286
weak_ptr_factory_.GetWeakPtr()),
287+
base::BindRepeating(
288+
&BocaReceiverUntrustedPageHandler::OnCrdAudioPacketReceived,
289+
weak_ptr_factory_.GetWeakPtr()),
286290
base::BindRepeating(
287291
&BocaReceiverUntrustedPageHandler::OnCrdConnectionStateUpdated,
288292
weak_ptr_factory_.GetWeakPtr()));
@@ -329,6 +333,11 @@ void BocaReceiverUntrustedPageHandler::OnCrdFrameReceived(
329333
::boca::ReceiverConnectionState::CONNECTED);
330334
}
331335

336+
void BocaReceiverUntrustedPageHandler::OnCrdAudioPacketReceived(
337+
std::unique_ptr<remoting::AudioPacket> packet) {
338+
// TODO(crbug.com/450986461): Transform packet and pass it to UI through mojo.
339+
}
340+
332341
void BocaReceiverUntrustedPageHandler::OnCrdConnectionStateUpdated(
333342
boca::CrdConnectionState state) {
334343
switch (state) {

ash/webui/boca_receiver_app_ui/boca_receiver_untrusted_page_handler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ namespace net {
3939
struct NetworkTrafficAnnotationTag;
4040
} // namespace net
4141

42+
namespace remoting {
43+
class AudioPacket;
44+
} // namespace remoting
45+
4246
namespace webrtc {
4347
class DesktopFrame;
4448
} // namespace webrtc
@@ -104,6 +108,7 @@ class BocaReceiverUntrustedPageHandler
104108
void OnCrdSessionEnded();
105109
void OnCrdFrameReceived(SkBitmap bitmap,
106110
std::unique_ptr<webrtc::DesktopFrame>);
111+
void OnCrdAudioPacketReceived(std::unique_ptr<remoting::AudioPacket> packet);
107112
void OnCrdConnectionStateUpdated(boca::CrdConnectionState state);
108113

109114
mojo::Remote<mojom::UntrustedPage> page_;

ash/webui/boca_receiver_app_ui/boca_receiver_untrusted_page_handler_unittest.cc

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "chromeos/ash/components/boca/receiver/receiver_handler_delegate.h"
2828
#include "chromeos/ash/components/boca/receiver/register_receiver_request.h"
2929
#include "chromeos/ash/components/boca/receiver/update_kiosk_receiver_state_request.h"
30+
#include "chromeos/ash/components/boca/spotlight/spotlight_audio_stream_consumer.h"
3031
#include "chromeos/ash/components/boca/spotlight/spotlight_remoting_client_manager.h"
3132
#include "chromeos/ash/components/boca/util.h"
3233
#include "google_apis/common/dummy_auth_service.h"
@@ -163,6 +164,8 @@ class MockSpotlightRemotingClientManager
163164
base::OnceClosure crd_session_ended_callback,
164165
boca::SpotlightFrameConsumer::FrameReceivedCallback
165166
frame_received_callback,
167+
boca::SpotlightAudioStreamConsumer::AudioPacketReceivedCallback
168+
audio_packet_received_callback,
166169
boca::SpotlightCrdStateUpdatedCallback status_updated_callback),
167170
(override));
168171

@@ -354,7 +357,7 @@ TEST_F(BocaReceiverUntrustedPageHandlerTest, StartRequestedNoCodeThenWithCode) {
354357
auto remoting_client =
355358
std::make_unique<NiceMock<MockSpotlightRemotingClientManager>>();
356359
EXPECT_CALL(*remoting_client,
357-
StartCrdClient(std::string(kConnectionCode), _, _, _))
360+
StartCrdClient(std::string(kConnectionCode), _, _, _, _))
358361
.Times(1);
359362
EXPECT_CALL(handler_delegate_, CreateRemotingClientManager)
360363
.WillOnce(Return(ByMove(std::move(remoting_client))));
@@ -385,7 +388,7 @@ TEST_F(BocaReceiverUntrustedPageHandlerTest,
385388
auto remoting_client =
386389
std::make_unique<NiceMock<MockSpotlightRemotingClientManager>>();
387390
EXPECT_CALL(*remoting_client,
388-
StartCrdClient(std::string(kConnectionCode), _, _, _))
391+
StartCrdClient(std::string(kConnectionCode), _, _, _, _))
389392
.Times(1);
390393
EXPECT_CALL(handler_delegate_, CreateRemotingClientManager)
391394
.WillOnce(Return(ByMove(std::move(remoting_client))));
@@ -407,11 +410,11 @@ TEST_F(BocaReceiverUntrustedPageHandlerTest, FrameReceived) {
407410
auto remoting_client =
408411
std::make_unique<NiceMock<MockSpotlightRemotingClientManager>>();
409412
EXPECT_CALL(*remoting_client,
410-
StartCrdClient(std::string(kConnectionCode), _, _, _))
411-
.WillOnce(
412-
[&frame_received_cb](auto, auto, auto frame_received_cb_param, auto) {
413-
frame_received_cb = std::move(frame_received_cb_param);
414-
});
413+
StartCrdClient(std::string(kConnectionCode), _, _, _, _))
414+
.WillOnce([&frame_received_cb](auto, auto, auto frame_received_cb_param,
415+
auto, auto) {
416+
frame_received_cb = std::move(frame_received_cb_param);
417+
});
415418
EXPECT_CALL(handler_delegate_, CreateRemotingClientManager)
416419
.WillOnce(Return(ByMove(std::move(remoting_client))));
417420
WaitForTokenUpload();
@@ -461,10 +464,10 @@ TEST_F(BocaReceiverUntrustedPageHandlerTest, CrdSessionEnded) {
461464
auto remoting_client =
462465
std::make_unique<NiceMock<MockSpotlightRemotingClientManager>>();
463466
EXPECT_CALL(*remoting_client,
464-
StartCrdClient(std::string(kConnectionCode), _, _, _))
467+
StartCrdClient(std::string(kConnectionCode), _, _, _, _))
465468
.WillOnce([&session_ended_cb](auto,
466469
base::OnceClosure session_ended_cb_param,
467-
auto, auto) {
470+
auto, auto, auto) {
468471
session_ended_cb = std::move(session_ended_cb_param);
469472
});
470473
EXPECT_CALL(handler_delegate_, CreateRemotingClientManager)
@@ -691,11 +694,11 @@ TEST_P(BocaReceiverUntrustedPageHandlerCrdStateTest,
691694
std::make_unique<NiceMock<MockSpotlightRemotingClientManager>>();
692695
auto* remoting_client_ptr = remoting_client.get();
693696
EXPECT_CALL(*remoting_client,
694-
StartCrdClient(std::string(kConnectionCode), _, _, _))
695-
.WillOnce(
696-
[&state_updated_cb](auto, auto, auto, auto state_updated_cb_param) {
697-
state_updated_cb = std::move(state_updated_cb_param);
698-
});
697+
StartCrdClient(std::string(kConnectionCode), _, _, _, _))
698+
.WillOnce([&state_updated_cb](auto, auto, auto, auto,
699+
auto state_updated_cb_param) {
700+
state_updated_cb = std::move(state_updated_cb_param);
701+
});
699702
EXPECT_CALL(handler_delegate_, CreateRemotingClientManager)
700703
.WillOnce(Return(ByMove(std::move(remoting_client))));
701704
WaitForTokenUpload();

chromeos/ash/components/boca/boca_session_manager.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "components/session_manager/core/session_manager.h"
4747
#include "components/user_manager/user_manager.h"
4848
#include "google_apis/common/api_error_codes.h"
49+
#include "remoting/proto/audio.pb.h"
4950
#include "services/network/public/cpp/shared_url_loader_factory.h"
5051
#include "ui/base/l10n/l10n_util.h"
5152
#include "ui/message_center/message_center.h"
@@ -422,7 +423,9 @@ void BocaSessionManager::StartCrdClient(
422423

423424
remoting_client_manager_->StartCrdClient(
424425
crd_connection_code, std::move(done_callback),
425-
std::move(frame_received_callback), std::move(crd_state_callback));
426+
std::move(frame_received_callback),
427+
/* audio_packet_received_callback= */ base::DoNothing(),
428+
std::move(crd_state_callback));
426429
}
427430

428431
void BocaSessionManager::EndSpotlightSession(

chromeos/ash/components/boca/spotlight/remoting_client_io_proxy.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ RemotingClientIOProxyImpl::RemotingClientIOProxyImpl(
2828
std::unique_ptr<network::PendingSharedURLLoaderFactory>
2929
pending_url_loader_factory,
3030
SpotlightFrameConsumer::FrameReceivedCallback frame_received_callback,
31+
SpotlightAudioStreamConsumer::AudioPacketReceivedCallback
32+
audio_packet_received_callback,
3133
SpotlightCrdStateUpdatedCallback status_updated_callback)
3234
: pending_url_loader_factory_(std::move(pending_url_loader_factory)),
3335
frame_received_callback_(std::move(frame_received_callback)),
36+
audio_packet_received_callback_(
37+
std::move(audio_packet_received_callback)),
3438
status_updated_callback_(std::move(status_updated_callback)) {
3539
DETACH_FROM_SEQUENCE(sequence_checker_);
3640
}
@@ -138,7 +142,7 @@ void RemotingClientIOProxyImpl::OnFrameReceived(
138142
void RemotingClientIOProxyImpl::OnAudioPacketReceived(
139143
std::unique_ptr<remoting::AudioPacket> packet) {
140144
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
141-
// TODO(crbug.com/450986461): Send `packet` to a callback.
145+
audio_packet_received_callback_.Run(std::move(packet));
142146
}
143147

144148
void RemotingClientIOProxyImpl::ResetRemotingClient(

chromeos/ash/components/boca/spotlight/remoting_client_io_proxy.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "base/sequence_checker.h"
1515
#include "base/task/sequenced_task_runner.h"
1616
#include "base/task/single_thread_task_runner.h"
17+
#include "chromeos/ash/components/boca/spotlight/spotlight_audio_stream_consumer.h"
1718
#include "chromeos/ash/components/boca/spotlight/spotlight_constants.h"
1819
#include "chromeos/ash/components/boca/spotlight/spotlight_frame_consumer.h"
1920
#include "remoting/client/common/client_status_observer.h"
@@ -63,6 +64,8 @@ class RemotingClientIOProxyImpl : public RemotingClientIOProxy,
6364
std::unique_ptr<network::PendingSharedURLLoaderFactory>
6465
pending_url_loader_factory,
6566
SpotlightFrameConsumer::FrameReceivedCallback frame_received_callback,
67+
SpotlightAudioStreamConsumer::AudioPacketReceivedCallback
68+
audio_packet_received_callback,
6669
SpotlightCrdStateUpdatedCallback status_updated_callback);
6770
RemotingClientIOProxyImpl(const RemotingClientIOProxyImpl&) = delete;
6871
RemotingClientIOProxyImpl& operator=(const RemotingClientIOProxyImpl&) =
@@ -113,6 +116,8 @@ class RemotingClientIOProxyImpl : public RemotingClientIOProxy,
113116
base::OnceClosure crd_session_ended_callback_;
114117
// Callback for receiving a completed frame from `SpotlightFrameConsumer`.
115118
SpotlightFrameConsumer::FrameReceivedCallback frame_received_callback_;
119+
SpotlightAudioStreamConsumer::AudioPacketReceivedCallback
120+
audio_packet_received_callback_;
116121
// Callback for `CrdConnectionState` updates.
117122
SpotlightCrdStateUpdatedCallback status_updated_callback_;
118123
std::unique_ptr<SpotlightFrameConsumer> frame_consumer_;

chromeos/ash/components/boca/spotlight/spotlight_remoting_client_manager.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "chromeos/ash/components/boca/spotlight/remoting_client_io_proxy.h"
2828
#include "chromeos/ash/components/boca/spotlight/spotlight_constants.h"
2929
#include "chromeos/ash/components/boca/spotlight/spotlight_oauth_token_fetcher.h"
30+
#include "remoting/proto/audio.pb.h"
3031
#include "services/network/public/cpp/shared_url_loader_factory.h"
3132
#include "third_party/skia/include/core/SkBitmap.h"
3233
#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
@@ -51,6 +52,9 @@ SpotlightRemotingClientManagerImpl::SpotlightRemotingClientManagerImpl(
5152
base::BindPostTaskToCurrentDefault(base::BindRepeating(
5253
&SpotlightRemotingClientManagerImpl::HandleFrameReceived,
5354
weak_factory_.GetWeakPtr())),
55+
base::BindPostTaskToCurrentDefault(base::BindRepeating(
56+
&SpotlightRemotingClientManagerImpl::HandleAudioPacketReceived,
57+
weak_factory_.GetWeakPtr())),
5458
base::BindPostTaskToCurrentDefault(base::BindRepeating(
5559
&SpotlightRemotingClientManagerImpl::UpdateState,
5660
weak_factory_.GetWeakPtr()))));
@@ -69,6 +73,8 @@ void SpotlightRemotingClientManagerImpl::StartCrdClient(
6973
std::string crd_connection_code,
7074
base::OnceClosure crd_session_ended_callback,
7175
SpotlightFrameConsumer::FrameReceivedCallback frame_received_callback,
76+
SpotlightAudioStreamConsumer::AudioPacketReceivedCallback
77+
audio_packet_received_callback,
7278
SpotlightCrdStateUpdatedCallback status_updated_callback) {
7379
CHECK(ash::features::IsBocaSpotlightRobotRequesterEnabled());
7480
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -91,6 +97,7 @@ void SpotlightRemotingClientManagerImpl::StartCrdClient(
9197

9298
crd_session_ended_callback_ = std::move(crd_session_ended_callback);
9399
frame_received_callback_ = std::move(frame_received_callback);
100+
audio_packet_received_callback_ = std::move(audio_packet_received_callback);
94101
status_updated_callback_ = std::move(status_updated_callback);
95102

96103
token_fetcher_->Start((base::BindOnce(
@@ -122,9 +129,12 @@ SpotlightRemotingClientManagerImpl::CreateRemotingIOProxy(
122129
std::unique_ptr<network::PendingSharedURLLoaderFactory>
123130
pending_url_loader_factory,
124131
SpotlightFrameConsumer::FrameReceivedCallback frame_received_callback,
132+
SpotlightAudioStreamConsumer::AudioPacketReceivedCallback
133+
audio_packet_received_callback,
125134
SpotlightCrdStateUpdatedCallback status_updated_callback) {
126135
return std::make_unique<RemotingClientIOProxyImpl>(
127136
std::move(pending_url_loader_factory), std::move(frame_received_callback),
137+
std::move(audio_packet_received_callback),
128138
std::move(status_updated_callback));
129139
}
130140

@@ -183,10 +193,20 @@ void SpotlightRemotingClientManagerImpl::HandleFrameReceived(
183193
frame_received_callback_.Run(std::move(bitmap), std::move(frame));
184194
}
185195

196+
void SpotlightRemotingClientManagerImpl::HandleAudioPacketReceived(
197+
std::unique_ptr<remoting::AudioPacket> packet) {
198+
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
199+
if (!audio_packet_received_callback_) {
200+
return;
201+
}
202+
audio_packet_received_callback_.Run(std::move(packet));
203+
}
204+
186205
void SpotlightRemotingClientManagerImpl::Reset() {
187206
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
188207
crd_session_ended_callback_.Reset();
189208
frame_received_callback_.Reset();
209+
audio_packet_received_callback_.Reset();
190210
status_updated_callback_.Reset();
191211
frame_timeout_timer_.Stop();
192212
session_in_progress_ = false;

chromeos/ash/components/boca/spotlight/spotlight_remoting_client_manager.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "base/threading/thread.h"
1818
#include "base/timer/timer.h"
1919
#include "chromeos/ash/components/boca/spotlight/remoting_client_io_proxy.h"
20+
#include "chromeos/ash/components/boca/spotlight/spotlight_audio_stream_consumer.h"
2021
#include "chromeos/ash/components/boca/spotlight/spotlight_constants.h"
2122
#include "chromeos/ash/components/boca/spotlight/spotlight_frame_consumer.h"
2223
#include "chromeos/ash/components/boca/spotlight/spotlight_oauth_token_fetcher.h"
@@ -27,6 +28,7 @@ class SharedURLLoaderFactory;
2728
} // namespace network
2829

2930
namespace remoting {
31+
class AudioPacket;
3032
class RemotingClient;
3133
} // namespace remoting
3234

@@ -49,6 +51,8 @@ class SpotlightRemotingClientManager {
4951
std::string crd_connection_code,
5052
base::OnceClosure crd_session_ended_callback,
5153
SpotlightFrameConsumer::FrameReceivedCallback frame_received_callback,
54+
SpotlightAudioStreamConsumer::AudioPacketReceivedCallback
55+
audio_packet_received_callback,
5256
SpotlightCrdStateUpdatedCallback status_updated_callback) = 0;
5357

5458
virtual void StopCrdClient(base::OnceClosure on_stopped_callback) = 0;
@@ -66,6 +70,7 @@ class SpotlightRemotingClientManagerImpl
6670
base::RepeatingCallback<std::unique_ptr<RemotingClientIOProxy>(
6771
std::unique_ptr<network::PendingSharedURLLoaderFactory>,
6872
SpotlightFrameConsumer::FrameReceivedCallback,
73+
SpotlightAudioStreamConsumer::AudioPacketReceivedCallback,
6974
SpotlightCrdStateUpdatedCallback)>;
7075

7176
SpotlightRemotingClientManagerImpl(
@@ -86,6 +91,8 @@ class SpotlightRemotingClientManagerImpl
8691
std::string crd_connection_code,
8792
base::OnceClosure crd_session_ended_callback,
8893
SpotlightFrameConsumer::FrameReceivedCallback frame_received_callback,
94+
SpotlightAudioStreamConsumer::AudioPacketReceivedCallback
95+
audio_packet_received_callback,
8996
SpotlightCrdStateUpdatedCallback status_updated_callback) override;
9097
// Forwards the request to stop the crd client to the
9198
// `remoting_client_io_proxy_`.
@@ -100,6 +107,8 @@ class SpotlightRemotingClientManagerImpl
100107
std::unique_ptr<network::PendingSharedURLLoaderFactory>
101108
pending_url_loader_factory,
102109
SpotlightFrameConsumer::FrameReceivedCallback frame_received_callback,
110+
SpotlightAudioStreamConsumer::AudioPacketReceivedCallback
111+
audio_packet_received_callback,
103112
SpotlightCrdStateUpdatedCallback status_updated_callback);
104113

105114
// Receives the OAuth token on the main/UI thread and calls the
@@ -117,6 +126,9 @@ class SpotlightRemotingClientManagerImpl
117126
void HandleFrameReceived(SkBitmap bitmap,
118127
std::unique_ptr<webrtc::DesktopFrame> frame);
119128

129+
// Forwards the audio packet to the `audio_packet_received_callback_`;
130+
void HandleAudioPacketReceived(std::unique_ptr<remoting::AudioPacket> packet);
131+
120132
void Reset();
121133

122134
SEQUENCE_CHECKER(sequence_checker_);
@@ -127,6 +139,8 @@ class SpotlightRemotingClientManagerImpl
127139
base::Thread io_thread_;
128140
base::OnceClosure crd_session_ended_callback_;
129141
SpotlightFrameConsumer::FrameReceivedCallback frame_received_callback_;
142+
SpotlightAudioStreamConsumer::AudioPacketReceivedCallback
143+
audio_packet_received_callback_;
130144
SpotlightCrdStateUpdatedCallback status_updated_callback_;
131145
std::unique_ptr<SpotlightOAuthTokenFetcher> token_fetcher_;
132146
// The `SpotlightRemotingClientManagerImpl` is owned by the main/UI thread

0 commit comments

Comments
 (0)