Avi Drissman | d6cdf9b | 2022-09-15 19:52:53 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
kelvinp@chromium.org | 324868c2 | 2014-05-01 00:19:05 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef REMOTING_PROTOCOL_MONITORED_VIDEO_STUB_H_ |
| 6 | #define REMOTING_PROTOCOL_MONITORED_VIDEO_STUB_H_ |
| 7 | |
Avi Drissman | 135261e | 2023-01-11 22:43:15 | [diff] [blame] | 8 | #include "base/functional/callback.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 9 | #include "base/memory/raw_ptr.h" |
kelvinp@chromium.org | 324868c2 | 2014-05-01 00:19:05 | [diff] [blame] | 10 | #include "base/threading/thread_checker.h" |
| 11 | #include "base/timer/timer.h" |
| 12 | #include "remoting/protocol/video_stub.h" |
| 13 | |
Joe Downing | 39d710e | 2022-08-25 20:11:45 | [diff] [blame] | 14 | namespace remoting::protocol { |
kelvinp@chromium.org | 324868c2 | 2014-05-01 00:19:05 | [diff] [blame] | 15 | |
| 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. |
Evan Stade | f3eda25d | 2020-06-08 17:47:10 | [diff] [blame] | 28 | typedef base::RepeatingCallback<void(bool connected)> ChannelStateCallback; |
kelvinp@chromium.org | 324868c2 | 2014-05-01 00:19:05 | [diff] [blame] | 29 | |
sergeyu@chromium.org | 6587aa7f | 2014-05-26 04:28:33 | [diff] [blame] | 30 | static const int kConnectivityCheckDelaySeconds = 2; |
kelvinp@chromium.org | 324868c2 | 2014-05-01 00:19:05 | [diff] [blame] | 31 | |
Joe Downing | 353ba2c7 | 2023-01-11 22:37:34 | [diff] [blame] | 32 | MonitoredVideoStub(VideoStub* video_stub, |
| 33 | base::TimeDelta connectivity_check_delay, |
| 34 | const ChannelStateCallback& callback); |
Peter Boström | e9178e4 | 2021-09-22 18:11:49 | [diff] [blame] | 35 | |
| 36 | MonitoredVideoStub(const MonitoredVideoStub&) = delete; |
| 37 | MonitoredVideoStub& operator=(const MonitoredVideoStub&) = delete; |
| 38 | |
dcheng | 562aba5 | 2014-10-21 12:30:14 | [diff] [blame] | 39 | ~MonitoredVideoStub() override; |
kelvinp@chromium.org | 324868c2 | 2014-05-01 00:19:05 | [diff] [blame] | 40 | |
| 41 | // VideoStub implementation. |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 42 | void ProcessVideoPacket(std::unique_ptr<VideoPacket> packet, |
Erik Jensen | 56d7f2e | 2019-02-20 01:38:56 | [diff] [blame] | 43 | base::OnceClosure done) override; |
kelvinp@chromium.org | 324868c2 | 2014-05-01 00:19:05 | [diff] [blame] | 44 | |
| 45 | private: |
| 46 | void OnConnectivityCheckTimeout(); |
| 47 | void NotifyChannelState(bool connected); |
| 48 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 49 | raw_ptr<VideoStub> video_stub_; |
kelvinp@chromium.org | 324868c2 | 2014-05-01 00:19:05 | [diff] [blame] | 50 | ChannelStateCallback callback_; |
kelvinp@chromium.org | 324868c2 | 2014-05-01 00:19:05 | [diff] [blame] | 51 | bool is_connected_; |
danakj | 8c3eb80 | 2015-09-24 07:53:00 | [diff] [blame] | 52 | base::DelayTimer connectivity_check_timer_; |
Joe Downing | 39d710e | 2022-08-25 20:11:45 | [diff] [blame] | 53 | |
| 54 | THREAD_CHECKER(thread_checker_); |
kelvinp@chromium.org | 324868c2 | 2014-05-01 00:19:05 | [diff] [blame] | 55 | }; |
| 56 | |
Joe Downing | 39d710e | 2022-08-25 20:11:45 | [diff] [blame] | 57 | } // namespace remoting::protocol |
kelvinp@chromium.org | 324868c2 | 2014-05-01 00:19:05 | [diff] [blame] | 58 | |
| 59 | #endif // REMOTING_PROTOCOL_MONITORED_VIDEO_STUB_H_ |