[go: nahoru, domu]

blob: 46e09dd0c4fcd1596d1a1007812a7beca706627e [file] [log] [blame]
Avi Drissmand6cdf9b2022-09-15 19:52:531// Copyright 2014 The Chromium Authors
kelvinp@chromium.org324868c22014-05-01 00:19:052// 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 Drissman135261e2023-01-11 22:43:158#include "base/functional/callback.h"
Keishi Hattori0e45c022021-11-27 09:25:529#include "base/memory/raw_ptr.h"
kelvinp@chromium.org324868c22014-05-01 00:19:0510#include "base/threading/thread_checker.h"
11#include "base/timer/timer.h"
12#include "remoting/protocol/video_stub.h"
13
Joe Downing39d710e2022-08-25 20:11:4514namespace remoting::protocol {
kelvinp@chromium.org324868c22014-05-01 00:19:0515
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.
24class MonitoredVideoStub : public VideoStub {
25 public:
26 // Callback to be called when channel state changes. The Callback should not
27 // destroy the MonitoredVideoStub object.
Evan Stadef3eda25d2020-06-08 17:47:1028 typedef base::RepeatingCallback<void(bool connected)> ChannelStateCallback;
kelvinp@chromium.org324868c22014-05-01 00:19:0529
sergeyu@chromium.org6587aa7f2014-05-26 04:28:3330 static const int kConnectivityCheckDelaySeconds = 2;
kelvinp@chromium.org324868c22014-05-01 00:19:0531
Joe Downing353ba2c72023-01-11 22:37:3432 MonitoredVideoStub(VideoStub* video_stub,
33 base::TimeDelta connectivity_check_delay,
34 const ChannelStateCallback& callback);
Peter Boströme9178e42021-09-22 18:11:4935
36 MonitoredVideoStub(const MonitoredVideoStub&) = delete;
37 MonitoredVideoStub& operator=(const MonitoredVideoStub&) = delete;
38
dcheng562aba52014-10-21 12:30:1439 ~MonitoredVideoStub() override;
kelvinp@chromium.org324868c22014-05-01 00:19:0540
41 // VideoStub implementation.
dcheng0765c492016-04-06 22:41:5342 void ProcessVideoPacket(std::unique_ptr<VideoPacket> packet,
Erik Jensen56d7f2e2019-02-20 01:38:5643 base::OnceClosure done) override;
kelvinp@chromium.org324868c22014-05-01 00:19:0544
45 private:
46 void OnConnectivityCheckTimeout();
47 void NotifyChannelState(bool connected);
48
Keishi Hattori0e45c022021-11-27 09:25:5249 raw_ptr<VideoStub> video_stub_;
kelvinp@chromium.org324868c22014-05-01 00:19:0550 ChannelStateCallback callback_;
kelvinp@chromium.org324868c22014-05-01 00:19:0551 bool is_connected_;
danakj8c3eb802015-09-24 07:53:0052 base::DelayTimer connectivity_check_timer_;
Joe Downing39d710e2022-08-25 20:11:4553
54 THREAD_CHECKER(thread_checker_);
kelvinp@chromium.org324868c22014-05-01 00:19:0555};
56
Joe Downing39d710e2022-08-25 20:11:4557} // namespace remoting::protocol
kelvinp@chromium.org324868c22014-05-01 00:19:0558
59#endif // REMOTING_PROTOCOL_MONITORED_VIDEO_STUB_H_