input_event_timestamps.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef REMOTING_PROTOCOL_INPUT_EVENT_TIMESTAMPS_H_
  5. #define REMOTING_PROTOCOL_INPUT_EVENT_TIMESTAMPS_H_
  6. #include "base/memory/ref_counted.h"
  7. #include "base/time/time.h"
  8. namespace remoting {
  9. namespace protocol {
  10. // Used on the host side to track timestamps for input events.
  11. struct InputEventTimestamps {
  12. // Client-side timestamps. This value comes from the client clock, so it
  13. // should not be used for any calculations on the host side (except in tests).
  14. base::TimeTicks client_timestamp;
  15. // Time when the event was processed by the host.
  16. base::TimeTicks host_timestamp;
  17. bool is_null() const { return client_timestamp.is_null(); }
  18. };
  19. // InputEventTimestampsSource is used by VideoStream implementations to get
  20. // event timestamps that are sent back to the client as part of VideoStats
  21. // message.
  22. class InputEventTimestampsSource
  23. : public base::RefCountedThreadSafe<InputEventTimestampsSource> {
  24. public:
  25. InputEventTimestampsSource() {}
  26. // Returns event timestamps for the input event that was received since the
  27. // previous call. Null InputEventTimestamps value is returned if no input
  28. // events were received. If multiple input events were received, then
  29. // timestamps for the last one should be returned
  30. virtual InputEventTimestamps TakeLastEventTimestamps() = 0;
  31. protected:
  32. friend base::RefCountedThreadSafe<InputEventTimestampsSource>;
  33. virtual ~InputEventTimestampsSource() {}
  34. };
  35. // Simple implementations of InputEventTimestampsSource that just stores the
  36. // value provided to OnEventReceived().
  37. class InputEventTimestampsSourceImpl : public InputEventTimestampsSource {
  38. public:
  39. InputEventTimestampsSourceImpl();
  40. void OnEventReceived(InputEventTimestamps timestamps);
  41. // InputEventTimestampsSource implementation.
  42. InputEventTimestamps TakeLastEventTimestamps() override;
  43. protected:
  44. ~InputEventTimestampsSourceImpl() override;
  45. private:
  46. InputEventTimestamps last_timestamps_;
  47. };
  48. } // namespace protocol
  49. } // namespace remoting
  50. #endif // REMOTING_PROTOCOL_INPUT_EVENT_TIMESTAMPS_H_