blob: 5de9521d931caf7d4c60ccc0cb6d308775fe85cd [file] [log] [blame]
joedow20fd2b02015-03-11 22:08:031// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
sergeyud3022d362015-12-18 05:43:215#ifndef REMOTING_PROTOCOL_ICE_CONNECTION_TO_HOST_H_
6#define REMOTING_PROTOCOL_ICE_CONNECTION_TO_HOST_H_
joedow20fd2b02015-03-11 22:08:037
dcheng0765c492016-04-06 22:41:538#include <memory>
joedow20fd2b02015-03-11 22:08:039#include <set>
10#include <string>
11
12#include "base/callback_forward.h"
Keishi Hattori0e45c022021-11-27 09:25:5213#include "base/memory/raw_ptr.h"
joedow20fd2b02015-03-11 22:08:0314#include "base/memory/ref_counted.h"
gabbf77513a2017-06-01 14:35:3415#include "base/sequence_checker.h"
Patrick Monette643cdf62021-10-15 19:13:4216#include "base/task/single_thread_task_runner.h"
joedow20fd2b02015-03-11 22:08:0317#include "remoting/proto/internal.pb.h"
18#include "remoting/protocol/channel_dispatcher_base.h"
19#include "remoting/protocol/clipboard_filter.h"
20#include "remoting/protocol/connection_to_host.h"
21#include "remoting/protocol/errors.h"
sergeyue5767602015-12-28 19:49:0322#include "remoting/protocol/ice_transport.h"
joedow20fd2b02015-03-11 22:08:0323#include "remoting/protocol/input_filter.h"
joedow20fd2b02015-03-11 22:08:0324#include "remoting/protocol/monitored_video_stub.h"
25#include "remoting/protocol/session.h"
26#include "remoting/protocol/session_config.h"
joedow20fd2b02015-03-11 22:08:0327
28namespace remoting {
joedow20fd2b02015-03-11 22:08:0329namespace protocol {
30
sergeyu77b42df82016-10-04 02:08:3831class AudioDecodeScheduler;
joedow20fd2b02015-03-11 22:08:0332class AudioReader;
33class ClientControlDispatcher;
34class ClientEventDispatcher;
35class ClientVideoDispatcher;
36
sergeyud3022d362015-12-18 05:43:2137class IceConnectionToHost : public ConnectionToHost,
38 public Session::EventHandler,
sergeyue5767602015-12-28 19:49:0339 public IceTransport::EventHandler,
gabbf77513a2017-06-01 14:35:3440 public ChannelDispatcherBase::EventHandler {
joedow20fd2b02015-03-11 22:08:0341 public:
Yuwei Huang5bc831e2019-07-12 21:30:2742 IceConnectionToHost();
Peter Boströme9178e42021-09-22 18:11:4943
44 IceConnectionToHost(const IceConnectionToHost&) = delete;
45 IceConnectionToHost& operator=(const IceConnectionToHost&) = delete;
46
sergeyud3022d362015-12-18 05:43:2147 ~IceConnectionToHost() override;
joedow20fd2b02015-03-11 22:08:0348
49 // ConnectionToHost interface.
joedow20fd2b02015-03-11 22:08:0350 void set_client_stub(ClientStub* client_stub) override;
51 void set_clipboard_stub(ClipboardStub* clipboard_stub) override;
sergeyu0b570732016-01-05 23:36:4452 void set_video_renderer(VideoRenderer* video_renderer) override;
sergeyu77b42df82016-10-04 02:08:3853 void InitializeAudio(
54 scoped_refptr<base::SingleThreadTaskRunner> audio_decode_task_runner,
55 base::WeakPtr<AudioStub> audio_stub) override;
dcheng0765c492016-04-06 22:41:5356 void Connect(std::unique_ptr<Session> session,
sergeyue5767602015-12-28 19:49:0357 scoped_refptr<TransportContext> transport_context,
joedow20fd2b02015-03-11 22:08:0358 HostEventCallback* event_callback) override;
Yuwei Huang632c53d2019-06-25 21:59:0559 void Disconnect(ErrorCode error) override;
joedow20fd2b02015-03-11 22:08:0360 const SessionConfig& config() override;
61 ClipboardStub* clipboard_forwarder() override;
62 HostStub* host_stub() override;
63 InputStub* input_stub() override;
64 State state() const override;
65
66 private:
joedow20fd2b02015-03-11 22:08:0367 // Session::EventHandler interface.
68 void OnSessionStateChange(Session::State state) override;
sergeyue5767602015-12-28 19:49:0369
70 // IceTransport::EventHandler interface.
71 void OnIceTransportRouteChange(const std::string& channel_name,
72 const TransportRoute& route) override;
73 void OnIceTransportError(ErrorCode error) override;
joedow20fd2b02015-03-11 22:08:0374
75 // ChannelDispatcherBase::EventHandler interface.
76 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override;
sergeyud059c462016-07-20 19:34:1077 void OnChannelClosed(ChannelDispatcherBase* channel_dispatcher) override;
joedow20fd2b02015-03-11 22:08:0378
79 // MonitoredVideoStub::EventHandler interface.
80 virtual void OnVideoChannelStatus(bool active);
81
82 void NotifyIfChannelsReady();
83
sergeyue5767602015-12-28 19:49:0384 // Closes the P2P connection.
joedow20fd2b02015-03-11 22:08:0385 void CloseChannels();
86
87 void SetState(State state, ErrorCode error);
88
Keishi Hattori0e45c022021-11-27 09:25:5289 raw_ptr<HostEventCallback> event_callback_ = nullptr;
joedow20fd2b02015-03-11 22:08:0390
91 // Stub for incoming messages.
Keishi Hattori0e45c022021-11-27 09:25:5292 raw_ptr<ClientStub> client_stub_ = nullptr;
93 raw_ptr<ClipboardStub> clipboard_stub_ = nullptr;
94 raw_ptr<VideoRenderer> video_renderer_ = nullptr;
sergeyu77b42df82016-10-04 02:08:3895
96 std::unique_ptr<AudioDecodeScheduler> audio_decode_scheduler_;
joedow20fd2b02015-03-11 22:08:0397
dcheng0765c492016-04-06 22:41:5398 std::unique_ptr<Session> session_;
99 std::unique_ptr<IceTransport> transport_;
joedow20fd2b02015-03-11 22:08:03100
dcheng0765c492016-04-06 22:41:53101 std::unique_ptr<MonitoredVideoStub> monitored_video_stub_;
102 std::unique_ptr<ClientVideoDispatcher> video_dispatcher_;
103 std::unique_ptr<AudioReader> audio_reader_;
104 std::unique_ptr<ClientControlDispatcher> control_dispatcher_;
105 std::unique_ptr<ClientEventDispatcher> event_dispatcher_;
joedow20fd2b02015-03-11 22:08:03106 ClipboardFilter clipboard_forwarder_;
107 InputFilter event_forwarder_;
108
109 // Internal state of the connection.
sergeyu06fa7c52015-12-17 18:17:03110 State state_ = INITIALIZING;
111 ErrorCode error_ = OK;
joedow20fd2b02015-03-11 22:08:03112
113 private:
gabbf77513a2017-06-01 14:35:34114 SEQUENCE_CHECKER(sequence_checker_);
joedow20fd2b02015-03-11 22:08:03115};
116
117} // namespace protocol
118} // namespace remoting
119
sergeyud3022d362015-12-18 05:43:21120#endif // REMOTING_PROTOCOL_ICE_CONNECTION_TO_HOST_H_