summaryrefslogtreecommitdiff
path: root/.clang-format
AgeCommit message (Expand)Author
2021-08-27clang-format: Remove unsupported optionKieran Bingham
2021-08-11clang-format: Regroup sort ordersKieran Bingham
2021-03-08clang-format: Enable sorted includesKieran Bingham
2021-03-08clang-format: Update to reflect coding styleLaurent Pinchart
2021-03-08clang-format: Update to clang-format-7Laurent Pinchart
2020-04-15licenses: Replace deprecated GPL-2.0 with GPL-2.0-onlyLaurent Pinchart
2019-09-23clang-format: Don't indent namespacesLaurent Pinchart
2019-02-13clang-format: Remove space after templateLaurent Pinchart
2019-02-04clang-format: Enable BreakBeforeTernaryOperatorsKieran Bingham
2019-01-22libcamera: Add clang-format styleLaurent Pinchart
/a> 19 20 21 22 23 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * v4l2_camera.h - V4L2 compatibility camera
 */

#ifndef __V4L2_CAMERA_H__
#define __V4L2_CAMERA_H__

#include <deque>
#include <mutex>
#include <utility>

#include <libcamera/base/semaphore.h>

#include <libcamera/camera.h>
#include <libcamera/file_descriptor.h>
#include <libcamera/framebuffer.h>
#include <libcamera/framebuffer_allocator.h>

using namespace libcamera;

class V4L2Camera
{
public:
	struct Buffer {
		Buffer(unsigned int index, const FrameMetadata &data)
			: index_(index), data_(data)
		{
		}

		unsigned int index_;
		FrameMetadata data_;
	};

	V4L2Camera(std::shared_ptr<Camera> camera);
	~V4L2Camera();

	int open(StreamConfiguration *streamConfig);
	void close();
	void bind(int efd);
	void unbind();

	std::vector<Buffer> completedBuffers();

	int configure(StreamConfiguration *streamConfigOut,
		      const Size &size, const PixelFormat &pixelformat,
		      unsigned int bufferCount);
	int validateConfiguration(const PixelFormat &pixelformat,
				  const Size &size,
				  StreamConfiguration *streamConfigOut);

	int allocBuffers(unsigned int count);
	void freeBuffers();
	FileDescriptor getBufferFd(unsigned int index);

	int streamOn();
	int streamOff();

	int qbuf(unsigned int index);

	void waitForBufferAvailable();
	bool isBufferAvailable();

	bool isRunning();

private:
	void requestComplete(Request *request);

	std::shared_ptr<Camera> camera_;
	std::unique_ptr<CameraConfiguration> config_;

	bool isRunning_;

	std::mutex bufferLock_;
	FrameBufferAllocator *bufferAllocator_;

	std::vector<std::unique_ptr<Request>> requestPool_;

	std::deque<Request *> pendingRequests_;
	std::deque<std::unique_ptr<Buffer>> completedBuffers_;

	int efd_;

	Mutex bufferMutex_;
	std::condition_variable bufferCV_;
	unsigned int bufferAvailableCount_;
};

#endif /* __V4L2_CAMERA_H__ */