summaryrefslogtreecommitdiff
path: root/src/v4l2/v4l2_camera_file.cpp
blob: d8fe854b6d067386c37879eefcadc7ae29e1bb68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2020, Google Inc.
 *
 * V4L2 compatibility camera file information
 */

#include "v4l2_camera_file.h"

#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>

#include <linux/videodev2.h>

#include "v4l2_camera_proxy.h"

using namespace libcamera;

V4L2CameraFile::V4L2CameraFile(int dirfd, const char *path, int efd,
			       bool nonBlocking, V4L2CameraProxy *proxy)
	: proxy_(proxy), nonBlocking_(nonBlocking), efd_(efd),
	  priority_(V4L2_PRIORITY_DEFAULT)
{
	proxy_->open(this);

	if (path[0] != '/') {
		if (dirfd == AT_FDCWD) {
			char *cwd = getcwd(nullptr, 0);
			if (cwd) {
				description_ = std::string(cwd) + "/";
				free(cwd);
			} else {
				description_ = std::string("(unreachable)/");
			}
		} else {
			description_ = "(dirfd:" + std::to_string(dirfd) + ")/";
		}
	}

	description_ += std::string(path) + " (fd:" + std::to_string(efd) + ")";
}

V4L2CameraFile::~V4L2CameraFile()
{
	proxy_->close(this);
}

const std::string &V4L2CameraFile::description() const
{
	return description_;
}
ss="hl opt">["indent"] * 4) self.state["need_indent"] = False if self.state["need_space"]: self.fout.write(' ') self.state["need_space"] = False self.fout.write(c) self.state["skipnewline"] = False def process_char(self, c): if c == '{': self.newline() self.write(c) self.state["indent"] += 1 self.newline() elif c == '}': self.state["indent"] -= 1 self.newline() self.write(c) elif c == '[': self.newline() self.write(c) self.state["indent"] += 1 self.newline() self.state["inarray"] = [True] + self.state["inarray"] self.state["arraycount"] = [0] + self.state["arraycount"] elif c == ']': self.state["indent"] -= 1 self.newline() self.state["inarray"].pop(0) self.state["arraycount"].pop(0) self.write(c) elif c == ':': self.write(c) self.state["need_space"] = True elif c == ',': if not self.state["inarray"][0]: self.write(c) self.newline() else: self.write(c) self.state["arraycount"][0] += 1 if self.state["arraycount"][0] == 16: self.state["arraycount"][0] = 0 self.newline() else: self.state["need_space"] = True elif c.isspace(): pass else: self.write(c) def print(self, string): for c in string: self.process_char(c) self.newline() def pretty_print_json(str_in, output_filename): with open(output_filename, "w") as fout: printer = JSONPrettyPrinter(fout) printer.print(str_in) if __name__ == '__main__': if len(sys.argv) != 2: print("Usage: %s filename" % sys.argv[0]) sys.exit(1) input_filename = sys.argv[1] with open(input_filename, "r") as fin: printer = JSONPrettyPrinter(sys.stdout) printer.print(fin.read())