ice_connection_to_client.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_CLIENT_H_
  5. #define REMOTING_PROTOCOL_ICE_CONNECTION_TO_CLIENT_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <string>
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/memory/ref_counted.h"
  11. #include "base/task/single_thread_task_runner.h"
  12. #include "base/threading/thread_checker.h"
  13. #include "remoting/protocol/channel_dispatcher_base.h"
  14. #include "remoting/protocol/connection_to_client.h"
  15. #include "remoting/protocol/ice_transport.h"
  16. #include "remoting/protocol/session.h"
  17. namespace remoting {
  18. namespace protocol {
  19. class AudioWriter;
  20. class HostControlDispatcher;
  21. class HostEventDispatcher;
  22. class HostVideoDispatcher;
  23. // This class represents a remote viewer connection to the chromoting
  24. // host. It sets up all protocol channels and connects them to the
  25. // stubs.
  26. class IceConnectionToClient : public ConnectionToClient,
  27. public Session::EventHandler,
  28. public IceTransport::EventHandler,
  29. public ChannelDispatcherBase::EventHandler {
  30. public:
  31. IceConnectionToClient(
  32. std::unique_ptr<Session> session,
  33. scoped_refptr<TransportContext> transport_context,
  34. scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner,
  35. scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner);
  36. IceConnectionToClient(const IceConnectionToClient&) = delete;
  37. IceConnectionToClient& operator=(const IceConnectionToClient&) = delete;
  38. ~IceConnectionToClient() override;
  39. // ConnectionToClient interface.
  40. void SetEventHandler(
  41. ConnectionToClient::EventHandler* event_handler) override;
  42. Session* session() override;
  43. void Disconnect(ErrorCode error) override;
  44. std::unique_ptr<VideoStream> StartVideoStream(
  45. const std::string& stream_name,
  46. std::unique_ptr<webrtc::DesktopCapturer> desktop_capturer) override;
  47. std::unique_ptr<AudioStream> StartAudioStream(
  48. std::unique_ptr<AudioSource> audio_source) override;
  49. ClientStub* client_stub() override;
  50. void set_clipboard_stub(ClipboardStub* clipboard_stub) override;
  51. void set_host_stub(HostStub* host_stub) override;
  52. void set_input_stub(InputStub* input_stub) override;
  53. PeerConnectionControls* peer_connection_controls() override;
  54. WebrtcEventLogData* rtc_event_log() override;
  55. private:
  56. // Session::EventHandler interface.
  57. void OnSessionStateChange(Session::State state) override;
  58. // IceTransport::EventHandler interface.
  59. void OnIceTransportRouteChange(const std::string& channel_name,
  60. const TransportRoute& route) override;
  61. void OnIceTransportError(ErrorCode error) override;
  62. // ChannelDispatcherBase::EventHandler interface.
  63. void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override;
  64. void OnChannelClosed(ChannelDispatcherBase* channel_dispatcher) override;
  65. // Callback passed to |event_dispatcher_|
  66. void OnInputEventReceived(int64_t timestamp);
  67. void NotifyIfChannelsReady();
  68. void CloseChannels();
  69. base::ThreadChecker thread_checker_;
  70. // Event handler for handling events sent from this object.
  71. raw_ptr<ConnectionToClient::EventHandler> event_handler_;
  72. std::unique_ptr<Session> session_;
  73. scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_;
  74. scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
  75. IceTransport transport_;
  76. std::unique_ptr<HostControlDispatcher> control_dispatcher_;
  77. std::unique_ptr<HostEventDispatcher> event_dispatcher_;
  78. std::unique_ptr<HostVideoDispatcher> video_dispatcher_;
  79. std::unique_ptr<AudioWriter> audio_writer_;
  80. };
  81. } // namespace protocol
  82. } // namespace remoting
  83. #endif // REMOTING_PROTOCOL_ICE_CONNECTION_TO_CLIENT_H_