monitored_video_stub.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2014 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_MONITORED_VIDEO_STUB_H_
  5. #define REMOTING_PROTOCOL_MONITORED_VIDEO_STUB_H_
  6. #include "base/callback.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/threading/thread_checker.h"
  9. #include "base/timer/timer.h"
  10. #include "remoting/protocol/video_stub.h"
  11. namespace base {
  12. class ThreadChecker;
  13. } // namespace base
  14. namespace remoting {
  15. namespace protocol {
  16. // MonitoredVideoStub is responsible for notifying the event handler if no
  17. // frames have been received within |connectivity_check_delay|.
  18. // The implementation uses the decorator pattern in which the MonitoredVideoStub
  19. // implements the same interface as the VideoStub. It overrides the
  20. // ProcessVideoPacket function to provide notification to the client when the
  21. // video channel is connected and forward the packet to the underlying
  22. // VideoStub. Multiple decorators can be stacked on top of each other if more
  23. // functionality is needed in the future.
  24. class MonitoredVideoStub : public VideoStub {
  25. public:
  26. // Callback to be called when channel state changes. The Callback should not
  27. // destroy the MonitoredVideoStub object.
  28. typedef base::RepeatingCallback<void(bool connected)> ChannelStateCallback;
  29. static const int kConnectivityCheckDelaySeconds = 2;
  30. MonitoredVideoStub(
  31. VideoStub* video_stub,
  32. base::TimeDelta connectivity_check_delay,
  33. const ChannelStateCallback& callback);
  34. MonitoredVideoStub(const MonitoredVideoStub&) = delete;
  35. MonitoredVideoStub& operator=(const MonitoredVideoStub&) = delete;
  36. ~MonitoredVideoStub() override;
  37. // VideoStub implementation.
  38. void ProcessVideoPacket(std::unique_ptr<VideoPacket> packet,
  39. base::OnceClosure done) override;
  40. private:
  41. void OnConnectivityCheckTimeout();
  42. void NotifyChannelState(bool connected);
  43. raw_ptr<VideoStub> video_stub_;
  44. ChannelStateCallback callback_;
  45. base::ThreadChecker thread_checker_;
  46. bool is_connected_;
  47. base::DelayTimer connectivity_check_timer_;
  48. };
  49. } // namespace protocol
  50. } // namespace remoting
  51. #endif // REMOTING_PROTOCOL_MONITORED_VIDEO_STUB_H_