ice_connection_to_client.h 3.55 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_PROTOCOL_ICE_CONNECTION_TO_CLIENT_H_
#define REMOTING_PROTOCOL_ICE_CONNECTION_TO_CLIENT_H_

8 9
#include <stdint.h>

10
#include <memory>
11 12 13
#include <string>

#include "base/macros.h"
14 15
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
16 17 18
#include "base/threading/thread_checker.h"
#include "remoting/protocol/channel_dispatcher_base.h"
#include "remoting/protocol/connection_to_client.h"
19
#include "remoting/protocol/ice_transport.h"
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include "remoting/protocol/session.h"

namespace remoting {
namespace protocol {

class AudioWriter;
class HostControlDispatcher;
class HostEventDispatcher;
class HostVideoDispatcher;

// This class represents a remote viewer connection to the chromoting
// host. It sets up all protocol channels and connects them to the
// stubs.
class IceConnectionToClient : public ConnectionToClient,
                              public Session::EventHandler,
35
                              public IceTransport::EventHandler,
36 37
                              public ChannelDispatcherBase::EventHandler {
 public:
sergeyu's avatar
sergeyu committed
38
  IceConnectionToClient(
39
      std::unique_ptr<Session> session,
40
      scoped_refptr<TransportContext> transport_context,
41 42
      scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner,
      scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner);
43 44 45 46 47 48 49
  ~IceConnectionToClient() override;

  // ConnectionToClient interface.
  void SetEventHandler(
      ConnectionToClient::EventHandler* event_handler) override;
  Session* session() override;
  void Disconnect(ErrorCode error) override;
50 51
  std::unique_ptr<VideoStream> StartVideoStream(
      std::unique_ptr<webrtc::DesktopCapturer> desktop_capturer) override;
52 53
  std::unique_ptr<AudioStream> StartAudioStream(
      std::unique_ptr<AudioSource> audio_source) override;
54 55 56 57 58
  ClientStub* client_stub() override;
  void set_clipboard_stub(ClipboardStub* clipboard_stub) override;
  void set_host_stub(HostStub* host_stub) override;
  void set_input_stub(InputStub* input_stub) override;

59
 private:
60 61
  // Session::EventHandler interface.
  void OnSessionStateChange(Session::State state) override;
62 63 64 65 66

  // IceTransport::EventHandler interface.
  void OnIceTransportRouteChange(const std::string& channel_name,
                                 const TransportRoute& route) override;
  void OnIceTransportError(ErrorCode error) override;
67 68 69

  // ChannelDispatcherBase::EventHandler interface.
  void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override;
70
  void OnChannelClosed(ChannelDispatcherBase* channel_dispatcher) override;
71

72 73 74
  // Callback passed to |event_dispatcher_|
  void OnInputEventReceived(int64_t timestamp);

75 76 77 78 79 80 81
  void NotifyIfChannelsReady();

  void CloseChannels();

  base::ThreadChecker thread_checker_;

  // Event handler for handling events sent from this object.
sergeyu's avatar
sergeyu committed
82
  ConnectionToClient::EventHandler* event_handler_;
83

84
  std::unique_ptr<Session> session_;
85

sergeyu's avatar
sergeyu committed
86
  scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_;
87
  scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
sergeyu's avatar
sergeyu committed
88

89 90
  IceTransport transport_;

91 92 93 94
  std::unique_ptr<HostControlDispatcher> control_dispatcher_;
  std::unique_ptr<HostEventDispatcher> event_dispatcher_;
  std::unique_ptr<HostVideoDispatcher> video_dispatcher_;
  std::unique_ptr<AudioWriter> audio_writer_;
95 96 97 98 99 100 101 102

  DISALLOW_COPY_AND_ASSIGN(IceConnectionToClient);
};

}  // namespace protocol
}  // namespace remoting

#endif  // REMOTING_PROTOCOL_ICE_CONNECTION_TO_CLIENT_H_