monitored_video_stub.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #include "remoting/protocol/monitored_video_stub.h"
  5. #include <utility>
  6. #include "base/bind.h"
  7. #include "base/check.h"
  8. #include "remoting/proto/video.pb.h"
  9. namespace remoting {
  10. namespace protocol {
  11. MonitoredVideoStub::MonitoredVideoStub(VideoStub* video_stub,
  12. base::TimeDelta connectivity_check_delay,
  13. const ChannelStateCallback& callback)
  14. : video_stub_(video_stub),
  15. callback_(callback),
  16. is_connected_(false),
  17. connectivity_check_timer_(
  18. FROM_HERE,
  19. connectivity_check_delay,
  20. this,
  21. &MonitoredVideoStub::OnConnectivityCheckTimeout) {
  22. }
  23. MonitoredVideoStub::~MonitoredVideoStub() {
  24. DCHECK(thread_checker_.CalledOnValidThread());
  25. }
  26. void MonitoredVideoStub::ProcessVideoPacket(std::unique_ptr<VideoPacket> packet,
  27. base::OnceClosure done) {
  28. DCHECK(thread_checker_.CalledOnValidThread());
  29. connectivity_check_timer_.Reset();
  30. NotifyChannelState(true);
  31. video_stub_->ProcessVideoPacket(std::move(packet), std::move(done));
  32. }
  33. void MonitoredVideoStub::OnConnectivityCheckTimeout() {
  34. DCHECK(thread_checker_.CalledOnValidThread());
  35. NotifyChannelState(false);
  36. }
  37. void MonitoredVideoStub::NotifyChannelState(bool connected) {
  38. if (is_connected_ != connected) {
  39. is_connected_ = connected;
  40. callback_.Run(is_connected_);
  41. }
  42. }
  43. } // namespace protocol
  44. } // namespace remoting