OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_TEST_CYCLIC_FRAME_GENERATOR_H_ | 5 #ifndef REMOTING_TEST_CYCLIC_FRAME_GENERATOR_H_ |
6 #define REMOTING_TEST_CYCLIC_FRAME_GENERATOR_H_ | 6 #define REMOTING_TEST_CYCLIC_FRAME_GENERATOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | |
13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
14 #include "base/time/default_tick_clock.h" | 13 #include "base/time/default_tick_clock.h" |
15 #include "remoting/protocol/input_event_timestamps.h" | |
16 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 14 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
17 | 15 |
18 namespace remoting { | 16 namespace remoting { |
19 namespace test { | 17 namespace test { |
20 | 18 |
21 // CyclicFrameGenerator generates a sequence of frames that approximates | 19 // CyclicFrameGenerator generates a sequence of frames that approximates |
22 // properties of a real video stream when using a desktop applications. It | 20 // properties of a real video stream when using a desktop applications. It |
23 // loads a sequence of reference frames and switches between them with the | 21 // loads a sequence of reference frames and switches between them with the |
24 // specified frequency (every 2 seconds by default). Between reference frames it | 22 // specified frequency (every 2 seconds by default). Between reference frames it |
25 // also generate frames with small changes which simulate a blinking cursor. | 23 // also generate frames with small changes which simulate a blinking cursor. |
26 class CyclicFrameGenerator : public protocol::InputEventTimestampsSource { | 24 class CyclicFrameGenerator |
| 25 : public base::RefCountedThreadSafe<CyclicFrameGenerator> { |
27 public: | 26 public: |
28 enum class ChangeType { | 27 enum class ChangeType { |
29 // No changes. | 28 // No changes. |
30 NO_CHANGES, | 29 NO_CHANGES, |
31 | 30 |
32 // Whole screen changed. | 31 // Whole screen changed. |
33 FULL, | 32 FULL, |
34 | 33 |
35 // Cursor state has changed. | 34 // Cursor state has changed. |
36 CURSOR, | 35 CURSOR, |
(...skipping 17 matching lines...) Expand all Loading... |
54 void set_frame_cycle_period(base::TimeDelta frame_cycle_period) { | 53 void set_frame_cycle_period(base::TimeDelta frame_cycle_period) { |
55 frame_cycle_period_ = frame_cycle_period; | 54 frame_cycle_period_ = frame_cycle_period; |
56 } | 55 } |
57 | 56 |
58 void set_cursor_blink_period(base::TimeDelta cursor_blink_period) { | 57 void set_cursor_blink_period(base::TimeDelta cursor_blink_period) { |
59 cursor_blink_period_ = cursor_blink_period; | 58 cursor_blink_period_ = cursor_blink_period; |
60 } | 59 } |
61 | 60 |
62 void SetTickClock(base::TickClock* tick_clock); | 61 void SetTickClock(base::TickClock* tick_clock); |
63 | 62 |
| 63 // When |draw_barcode| is set to true a barcode is drawn on each generated |
| 64 // frame. This makes it possible to call GetChangeList() to identify the frame |
| 65 // by its content. |
| 66 void set_draw_barcode(bool draw_barcode) { draw_barcode_ = draw_barcode; } |
| 67 |
64 std::unique_ptr<webrtc::DesktopFrame> GenerateFrame( | 68 std::unique_ptr<webrtc::DesktopFrame> GenerateFrame( |
65 webrtc::SharedMemoryFactory* shared_memory_factory); | 69 webrtc::SharedMemoryFactory* shared_memory_factory); |
66 | 70 |
67 ChangeType last_frame_type() { return last_frame_type_; } | 71 ChangeType last_frame_type() { return last_frame_type_; } |
68 | 72 |
69 // Returns list of changes for the frame with the specified |timestamp|, which | 73 // Identifies |frame| by its content and returns list of ChangeInfo for all |
70 // should be an event timestamp generated by InputEventTimestampsSource | 74 // changes between the frame passed to the previous GetChangeList() call and |
71 // implemented in this class. Must be called in the same order in which frames | 75 // this one. GetChangeList() must be called for the frames in the order in |
72 // were generated. | 76 // which they were received, which is expected to match the order in which |
73 ChangeInfoList GetChangeList(base::TimeTicks timestamp); | 77 // they are generated. |
74 | 78 ChangeInfoList GetChangeList(webrtc::DesktopFrame* frame); |
75 // InputEventTimestampsSource interface. | |
76 protocol::InputEventTimestamps TakeLastEventTimestamps() override; | |
77 | 79 |
78 private: | 80 private: |
79 ~CyclicFrameGenerator() override; | 81 ~CyclicFrameGenerator(); |
80 friend class base::RefCountedThreadSafe<CyclicFrameGenerator>; | 82 friend class base::RefCountedThreadSafe<CyclicFrameGenerator>; |
81 | 83 |
82 std::vector<std::unique_ptr<webrtc::DesktopFrame>> reference_frames_; | 84 std::vector<std::unique_ptr<webrtc::DesktopFrame>> reference_frames_; |
83 base::DefaultTickClock default_tick_clock_; | 85 base::DefaultTickClock default_tick_clock_; |
84 base::TickClock* clock_; | 86 base::TickClock* clock_; |
85 webrtc::DesktopSize screen_size_; | 87 webrtc::DesktopSize screen_size_; |
86 | 88 |
87 // By default switch between reference frames every 2 seconds. | 89 // By default switch between reference frames every 2 seconds. |
88 base::TimeDelta frame_cycle_period_ = base::TimeDelta::FromSeconds(2); | 90 base::TimeDelta frame_cycle_period_ = base::TimeDelta::FromSeconds(2); |
89 | 91 |
90 // By default blink the cursor 4 times per seconds. | 92 // By default blink the cursor 4 times per seconds. |
91 base::TimeDelta cursor_blink_period_ = base::TimeDelta::FromMilliseconds(250); | 93 base::TimeDelta cursor_blink_period_ = base::TimeDelta::FromMilliseconds(250); |
92 | 94 |
| 95 // Id of the last frame encoded on the barcode. |
| 96 int last_frame_id_ = -1; |
| 97 |
93 // Index of the reference frame used to render the last generated frame. | 98 // Index of the reference frame used to render the last generated frame. |
94 int last_reference_frame_ = -1; | 99 int last_reference_frame_ = -1; |
95 | 100 |
96 // True if the cursor was rendered on the last generated frame. | 101 // True if the cursor was rendered on the last generated frame. |
97 bool last_cursor_state_ = false; | 102 bool last_cursor_state_ = false; |
98 | 103 |
99 ChangeType last_frame_type_ = ChangeType::NO_CHANGES; | 104 ChangeType last_frame_type_ = ChangeType::NO_CHANGES; |
100 | 105 |
| 106 bool draw_barcode_ = false; |
| 107 |
101 base::TimeTicks started_time_; | 108 base::TimeTicks started_time_; |
102 | 109 |
103 // frame_id of the frame passed to the last GetChangeList() call. | 110 // frame_id of the frame passed to the last GetChangeList() call. |
104 int last_identifier_frame_ = -1; | 111 int last_identifier_frame_ = -1; |
105 | 112 |
106 DISALLOW_COPY_AND_ASSIGN(CyclicFrameGenerator); | 113 DISALLOW_COPY_AND_ASSIGN(CyclicFrameGenerator); |
107 }; | 114 }; |
108 | 115 |
109 } // namespace test | 116 } // namespace test |
110 } // namespace remoting | 117 } // namespace remoting |
111 | 118 |
112 #endif // REMOTING_TEST_CYCLIC_FRAME_GENERATOR_H_ | 119 #endif // REMOTING_TEST_CYCLIC_FRAME_GENERATOR_H_ |
OLD | NEW |