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