summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/monitored_video_stub.cc
blob: 3975fc3129fc45d6a8ecd5d427f7709cc79ef60a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2014 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.

#include "remoting/protocol/monitored_video_stub.h"

#include <utility>

#include "base/bind.h"
#include "base/logging.h"
#include "remoting/proto/video.pb.h"

namespace remoting {
namespace protocol {

MonitoredVideoStub::MonitoredVideoStub(VideoStub* video_stub,
                                       base::TimeDelta connectivity_check_delay,
                                       const ChannelStateCallback& callback)
    : video_stub_(video_stub),
      callback_(callback),
      is_connected_(false),
      connectivity_check_timer_(
          FROM_HERE,
          connectivity_check_delay,
          this,
          &MonitoredVideoStub::OnConnectivityCheckTimeout) {
}

MonitoredVideoStub::~MonitoredVideoStub() {
}

void MonitoredVideoStub::ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
                                            const base::Closure& done) {
  DCHECK(thread_checker_.CalledOnValidThread());

  connectivity_check_timer_.Reset();

  NotifyChannelState(true);

  video_stub_->ProcessVideoPacket(std::move(packet), done);
}

void MonitoredVideoStub::OnConnectivityCheckTimeout() {
  DCHECK(thread_checker_.CalledOnValidThread());
  NotifyChannelState(false);
}

void MonitoredVideoStub::NotifyChannelState(bool connected) {
  if (is_connected_ != connected) {
    is_connected_ = connected;
    callback_.Run(is_connected_);
  }
}

}  // namespace protocol
}  // namespace remoting