client_video_stats_dispatcher.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2016 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/client_video_stats_dispatcher.h"
  5. #include <utility>
  6. #include "base/bind.h"
  7. #include "base/callback_helpers.h"
  8. #include "net/socket/stream_socket.h"
  9. #include "remoting/base/compound_buffer.h"
  10. #include "remoting/proto/video_stats.pb.h"
  11. #include "remoting/protocol/frame_stats.h"
  12. #include "remoting/protocol/message_pipe.h"
  13. #include "remoting/protocol/message_serialization.h"
  14. #include "remoting/protocol/video_stats_stub.h"
  15. namespace remoting {
  16. namespace protocol {
  17. ClientVideoStatsDispatcher::ClientVideoStatsDispatcher(
  18. const std::string& stream_name,
  19. VideoStatsStub* video_stats_stub)
  20. : ChannelDispatcherBase(kVideoStatsChannelNamePrefix + stream_name),
  21. video_stats_stub_(video_stats_stub) {}
  22. ClientVideoStatsDispatcher::~ClientVideoStatsDispatcher() = default;
  23. void ClientVideoStatsDispatcher::OnIncomingMessage(
  24. std::unique_ptr<CompoundBuffer> message) {
  25. std::unique_ptr<FrameStatsMessage> stats_proto =
  26. ParseMessage<FrameStatsMessage>(message.get());
  27. if (!stats_proto)
  28. return;
  29. if (!stats_proto->has_frame_id()) {
  30. LOG(ERROR) << "Received invalid FrameStatsMessage.";
  31. return;
  32. }
  33. video_stats_stub_->OnVideoFrameStats(
  34. stats_proto->frame_id(),
  35. HostFrameStats::FromFrameStatsMessage(*stats_proto));
  36. }
  37. } // namespace protocol
  38. } // namespace remoting