ice_connection_to_host.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_PROTOCOL_ICE_CONNECTION_TO_HOST_H_
  5. #define REMOTING_PROTOCOL_ICE_CONNECTION_TO_HOST_H_
  6. #include <memory>
  7. #include <set>
  8. #include <string>
  9. #include "base/callback_forward.h"
  10. #include "base/memory/raw_ptr.h"
  11. #include "base/memory/ref_counted.h"
  12. #include "base/sequence_checker.h"
  13. #include "base/task/single_thread_task_runner.h"
  14. #include "remoting/proto/internal.pb.h"
  15. #include "remoting/protocol/channel_dispatcher_base.h"
  16. #include "remoting/protocol/clipboard_filter.h"
  17. #include "remoting/protocol/connection_to_host.h"
  18. #include "remoting/protocol/errors.h"
  19. #include "remoting/protocol/ice_transport.h"
  20. #include "remoting/protocol/input_filter.h"
  21. #include "remoting/protocol/monitored_video_stub.h"
  22. #include "remoting/protocol/session.h"
  23. #include "remoting/protocol/session_config.h"
  24. namespace remoting {
  25. namespace protocol {
  26. class AudioDecodeScheduler;
  27. class AudioReader;
  28. class ClientControlDispatcher;
  29. class ClientEventDispatcher;
  30. class ClientVideoDispatcher;
  31. class IceConnectionToHost : public ConnectionToHost,
  32. public Session::EventHandler,
  33. public IceTransport::EventHandler,
  34. public ChannelDispatcherBase::EventHandler {
  35. public:
  36. IceConnectionToHost();
  37. IceConnectionToHost(const IceConnectionToHost&) = delete;
  38. IceConnectionToHost& operator=(const IceConnectionToHost&) = delete;
  39. ~IceConnectionToHost() override;
  40. // ConnectionToHost interface.
  41. void set_client_stub(ClientStub* client_stub) override;
  42. void set_clipboard_stub(ClipboardStub* clipboard_stub) override;
  43. void set_video_renderer(VideoRenderer* video_renderer) override;
  44. void InitializeAudio(
  45. scoped_refptr<base::SingleThreadTaskRunner> audio_decode_task_runner,
  46. base::WeakPtr<AudioStub> audio_stub) override;
  47. void Connect(std::unique_ptr<Session> session,
  48. scoped_refptr<TransportContext> transport_context,
  49. HostEventCallback* event_callback) override;
  50. void Disconnect(ErrorCode error) override;
  51. const SessionConfig& config() override;
  52. ClipboardStub* clipboard_forwarder() override;
  53. HostStub* host_stub() override;
  54. InputStub* input_stub() override;
  55. State state() const override;
  56. private:
  57. // Session::EventHandler interface.
  58. void OnSessionStateChange(Session::State state) override;
  59. // IceTransport::EventHandler interface.
  60. void OnIceTransportRouteChange(const std::string& channel_name,
  61. const TransportRoute& route) override;
  62. void OnIceTransportError(ErrorCode error) override;
  63. // ChannelDispatcherBase::EventHandler interface.
  64. void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override;
  65. void OnChannelClosed(ChannelDispatcherBase* channel_dispatcher) override;
  66. // MonitoredVideoStub::EventHandler interface.
  67. virtual void OnVideoChannelStatus(bool active);
  68. void NotifyIfChannelsReady();
  69. // Closes the P2P connection.
  70. void CloseChannels();
  71. void SetState(State state, ErrorCode error);
  72. raw_ptr<HostEventCallback> event_callback_ = nullptr;
  73. // Stub for incoming messages.
  74. raw_ptr<ClientStub> client_stub_ = nullptr;
  75. raw_ptr<ClipboardStub> clipboard_stub_ = nullptr;
  76. raw_ptr<VideoRenderer> video_renderer_ = nullptr;
  77. std::unique_ptr<AudioDecodeScheduler> audio_decode_scheduler_;
  78. std::unique_ptr<Session> session_;
  79. std::unique_ptr<IceTransport> transport_;
  80. std::unique_ptr<MonitoredVideoStub> monitored_video_stub_;
  81. std::unique_ptr<ClientVideoDispatcher> video_dispatcher_;
  82. std::unique_ptr<AudioReader> audio_reader_;
  83. std::unique_ptr<ClientControlDispatcher> control_dispatcher_;
  84. std::unique_ptr<ClientEventDispatcher> event_dispatcher_;
  85. ClipboardFilter clipboard_forwarder_;
  86. InputFilter event_forwarder_;
  87. // Internal state of the connection.
  88. State state_ = INITIALIZING;
  89. ErrorCode error_ = OK;
  90. private:
  91. SEQUENCE_CHECKER(sequence_checker_);
  92. };
  93. } // namespace protocol
  94. } // namespace remoting
  95. #endif // REMOTING_PROTOCOL_ICE_CONNECTION_TO_HOST_H_