summaryrefslogtreecommitdiff
path: root/include/android
AgeCommit message (Expand)Author
2021-05-31android: Update Android headersLaurent Pinchart
2020-05-13licenses: License all meson files under CC0-1.0Laurent Pinchart
2019-08-12include: android: Add SPDX tagsJacopo Mondi
2019-08-12include: android: Add Android headers from CrosJacopo Mondi
24'>24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * timeline.h - Timeline for per-frame controls
 */
#ifndef __LIBCAMERA_TIMELINE_H__
#define __LIBCAMERA_TIMELINE_H__

#include <list>
#include <map>

#include "libcamera/internal/timer.h"
#include "libcamera/internal/utils.h"

namespace libcamera {

class FrameAction
{
public:
	FrameAction(unsigned int frame, unsigned int type)
		: frame_(frame), type_(type) {}

	virtual ~FrameAction() = default;

	unsigned int frame() const { return frame_; }
	unsigned int type() const { return type_; }

	virtual void run() = 0;

private:
	unsigned int frame_;
	unsigned int type_;
};

class Timeline
{
public:
	Timeline();
	virtual ~Timeline() = default;

	virtual void reset();
	virtual void scheduleAction(std::unique_ptr<FrameAction> action);
	virtual void notifyStartOfExposure(unsigned int frame, utils::time_point time);

	utils::duration frameInterval() const { return frameInterval_; }

protected:
	int frameOffset(unsigned int type) const;
	utils::duration timeOffset(unsigned int type) const;

	void setRawDelay(unsigned int type, int frame, utils::duration time);

	std::map<unsigned int, std::pair<int, utils::duration>> delays_;

private:
	static constexpr unsigned int HISTORY_DEPTH = 10;

	void timeout(Timer *timer);
	void updateDeadline();

	std::list<std::pair<unsigned int, utils::time_point>> history_;
	std::multimap<utils::time_point, std::unique_ptr<FrameAction>> actions_;
	utils::duration frameInterval_;

	Timer timer_;
};

} /* namespace libcamera */

#endif /* __LIBCAMERA_TIMELINE_H__ */