| 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 <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time/default_tick_clock.h" | 13 #include "base/time/default_tick_clock.h" |
| 13 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 14 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
| 14 | 15 |
| 15 namespace remoting { | 16 namespace remoting { |
| 16 namespace test { | 17 namespace test { |
| 17 | 18 |
| 18 // CyclicFrameGenerator generates a sequence of frames that approximates | 19 // CyclicFrameGenerator generates a sequence of frames that approximates |
| 19 // 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 |
| 20 // 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 |
| 21 // specified frequency (every 2 seconds by default). Between reference frames it | 22 // specified frequency (every 2 seconds by default). Between reference frames it |
| 22 // also generate frames with small changes which simulate a blinking cursor. | 23 // also generate frames with small changes which simulate a blinking cursor. |
| 23 class CyclicFrameGenerator | 24 class CyclicFrameGenerator |
| 24 : public base::RefCountedThreadSafe<CyclicFrameGenerator> { | 25 : public base::RefCountedThreadSafe<CyclicFrameGenerator> { |
| 25 public: | 26 public: |
| 26 enum class FrameType { | 27 enum class FrameType { |
| 27 // Frame had no changes. | 28 // Frame had no changes. |
| 28 EMPTY, | 29 EMPTY, |
| 29 | 30 |
| 30 // Whole screen changed. | 31 // Whole screen changed. |
| 31 FULL, | 32 FULL, |
| 32 | 33 |
| 33 // Cursor state has changed. | 34 // Cursor state has changed. |
| 34 CURSOR, | 35 CURSOR, |
| 35 }; | 36 }; |
| 36 | 37 |
| 38 struct FrameInfo { |
| 39 FrameInfo(); |
| 40 FrameInfo(int frame_id, FrameType type, base::TimeTicks timestamp); |
| 41 |
| 42 int frame_id = 0; |
| 43 FrameType type = FrameType::EMPTY; |
| 44 base::TimeTicks timestamp; |
| 45 }; |
| 46 |
| 37 static scoped_refptr<CyclicFrameGenerator> Create(); | 47 static scoped_refptr<CyclicFrameGenerator> Create(); |
| 38 | 48 |
| 39 CyclicFrameGenerator( | 49 CyclicFrameGenerator( |
| 40 std::vector<scoped_ptr<webrtc::DesktopFrame>> reference_frames); | 50 std::vector<scoped_ptr<webrtc::DesktopFrame>> reference_frames); |
| 41 | 51 |
| 42 void set_frame_cycle_period(base::TimeDelta frame_cycle_period) { | 52 void set_frame_cycle_period(base::TimeDelta frame_cycle_period) { |
| 43 frame_cycle_period_ = frame_cycle_period; | 53 frame_cycle_period_ = frame_cycle_period; |
| 44 } | 54 } |
| 45 | 55 |
| 46 void set_cursor_blink_period(base::TimeDelta cursor_blink_period) { | 56 void set_cursor_blink_period(base::TimeDelta cursor_blink_period) { |
| 47 cursor_blink_period_ = cursor_blink_period; | 57 cursor_blink_period_ = cursor_blink_period; |
| 48 } | 58 } |
| 49 | 59 |
| 50 void SetTickClock(base::TickClock* tick_clock); | 60 void SetTickClock(base::TickClock* tick_clock); |
| 51 | 61 |
| 62 // When |draw_barcode| is set to true a barcode is drawn on each generated |
| 63 // frame. This make it possible to call IdentifyFrame() to identify the frame |
| 64 // by its content. |
| 65 void set_draw_barcode(bool draw_barcode) { draw_barcode_ = draw_barcode; } |
| 66 |
| 52 scoped_ptr<webrtc::DesktopFrame> GenerateFrame( | 67 scoped_ptr<webrtc::DesktopFrame> GenerateFrame( |
| 53 webrtc::DesktopCapturer::Callback* callback); | 68 webrtc::DesktopCapturer::Callback* callback); |
| 54 | 69 |
| 55 FrameType last_frame_type() { return last_frame_type_; } | 70 FrameType last_frame_type() { return last_frame_type_; } |
| 56 | 71 |
| 72 // Identifies |frame| by its content and returns FrameInfo corresponding to |
| 73 // the frame. |
| 74 FrameInfo IdentifyFrame(webrtc::DesktopFrame* frame); |
| 75 |
| 57 private: | 76 private: |
| 58 ~CyclicFrameGenerator(); | 77 ~CyclicFrameGenerator(); |
| 59 friend class base::RefCountedThreadSafe<CyclicFrameGenerator>; | 78 friend class base::RefCountedThreadSafe<CyclicFrameGenerator>; |
| 60 | 79 |
| 61 std::vector<scoped_ptr<webrtc::DesktopFrame>> reference_frames_; | 80 std::vector<scoped_ptr<webrtc::DesktopFrame>> reference_frames_; |
| 62 base::DefaultTickClock default_tick_clock_; | 81 base::DefaultTickClock default_tick_clock_; |
| 63 base::TickClock* clock_; | 82 base::TickClock* clock_; |
| 64 webrtc::DesktopSize screen_size_; | 83 webrtc::DesktopSize screen_size_; |
| 65 | 84 |
| 66 // By default switch between reference frames every 2 seconds. | 85 // By default switch between reference frames every 2 seconds. |
| 67 base::TimeDelta frame_cycle_period_ = base::TimeDelta::FromSeconds(2); | 86 base::TimeDelta frame_cycle_period_ = base::TimeDelta::FromSeconds(2); |
| 68 | 87 |
| 69 // By default blink the cursor 4 times per seconds. | 88 // By default blink the cursor 4 times per seconds. |
| 70 base::TimeDelta cursor_blink_period_ = base::TimeDelta::FromMilliseconds(250); | 89 base::TimeDelta cursor_blink_period_ = base::TimeDelta::FromMilliseconds(250); |
| 71 | 90 |
| 91 // Id of the last frame encoded on the barcode. |
| 92 int last_frame_id_ = -1; |
| 93 |
| 72 // Index of the reference frame used to render the last generated frame. | 94 // Index of the reference frame used to render the last generated frame. |
| 73 int last_reference_frame_ = -1; | 95 int last_reference_frame_ = -1; |
| 74 | 96 |
| 75 // True if the cursor was rendered on the last generated frame. | 97 // True if the cursor was rendered on the last generated frame. |
| 76 bool last_cursor_state_ = false; | 98 bool last_cursor_state_ = false; |
| 77 | 99 |
| 78 FrameType last_frame_type_ = FrameType::EMPTY; | 100 FrameType last_frame_type_ = FrameType::EMPTY; |
| 79 | 101 |
| 102 bool draw_barcode_ = false; |
| 103 |
| 80 base::TimeTicks started_time_; | 104 base::TimeTicks started_time_; |
| 81 | 105 |
| 106 std::map<int, FrameInfo> generated_frames_info_; |
| 107 |
| 82 DISALLOW_COPY_AND_ASSIGN(CyclicFrameGenerator); | 108 DISALLOW_COPY_AND_ASSIGN(CyclicFrameGenerator); |
| 83 }; | 109 }; |
| 84 | 110 |
| 85 } // namespace test | 111 } // namespace test |
| 86 } // namespace remoting | 112 } // namespace remoting |
| 87 | 113 |
| 88 #endif // REMOTING_TEST_CYCLIC_FRAME_GENERATOR_H_ | 114 #endif // REMOTING_TEST_CYCLIC_FRAME_GENERATOR_H_ |
| OLD | NEW |