#ifndef REMOTING_TEST_CYCLIC_FRAME_GENERATOR_H_
#define REMOTING_TEST_CYCLIC_FRAME_GENERATOR_H_
#include <map>
#include <memory>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/time/default_tick_clock.h"
#include "base/time/time.h"
#include "remoting/protocol/input_event_timestamps.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
namespace remoting {
namespace test {
class CyclicFrameGenerator : public protocol::InputEventTimestampsSource {
public:
enum class ChangeType {
NO_CHANGES,
FULL,
CURSOR,
};
struct ChangeInfo {
ChangeInfo();
ChangeInfo(ChangeType type, base::TimeTicks timestamp);
ChangeType type = ChangeType::NO_CHANGES;
base::TimeTicks timestamp;
};
typedef std::vector<ChangeInfo> ChangeInfoList;
static scoped_refptr<CyclicFrameGenerator> Create();
explicit CyclicFrameGenerator(
std::vector<std::unique_ptr<webrtc::DesktopFrame>> reference_frames);
CyclicFrameGenerator(const CyclicFrameGenerator&) = delete;
CyclicFrameGenerator& operator=(const CyclicFrameGenerator&) = delete;
void set_frame_cycle_period(base::TimeDelta frame_cycle_period) {
frame_cycle_period_ = frame_cycle_period;
}
void set_cursor_blink_period(base::TimeDelta cursor_blink_period) {
cursor_blink_period_ = cursor_blink_period;
}
void SetTickClock(const base::TickClock* tick_clock);
std::unique_ptr<webrtc::DesktopFrame> GenerateFrame(
webrtc::SharedMemoryFactory* shared_memory_factory);
ChangeType last_frame_type() { return last_frame_type_; }
ChangeInfoList GetChangeList(base::TimeTicks timestamp);
protocol::InputEventTimestamps TakeLastEventTimestamps() override;
private:
~CyclicFrameGenerator() override;
friend class base::RefCountedThreadSafe<CyclicFrameGenerator>;
std::vector<std::unique_ptr<webrtc::DesktopFrame>> reference_frames_;
raw_ptr<const base::TickClock> clock_;
webrtc::DesktopSize screen_size_;
base::TimeDelta frame_cycle_period_ = base::Seconds(2);
base::TimeDelta cursor_blink_period_ = base::Milliseconds(250);
int last_reference_frame_ = -1;
bool last_cursor_state_ = false;
ChangeType last_frame_type_ = ChangeType::NO_CHANGES;
base::TimeTicks started_time_;
int last_identifier_frame_ = -1;
};
}
}
#endif