summaryrefslogtreecommitdiff
path: root/src/gstreamer/meson.build
AgeCommit message (Collapse)Author
2020-05-13licenses: License all meson files under CC0-1.0Laurent Pinchart
In an attempt to clarify the license terms of all files in the libcamera project, the build system files deserve particular attention. While they describe how the binaries are created, they are not themselves transformed into any part of binary distributions of the software, and thus don't influence the copyright on the binary packages. They are however subject to copyright, and thus influence the distribution terms of the source packages. Most of the meson.build files would not meet the threshold of originality criteria required for copyright protection. Some of the more complex meson.build files may be eligible for copyright protection. To avoid any ambiguity and uncertainty, state our intent to not assert copyrights on the build system files by putting them in the public domain with the CC0-1.0 license. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Acked-by: Giulio Benetti <giulio.benetti@micronovasrl.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Acked-by: Naushir Patuck <naush@raspberrypi.com> Acked-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Acked-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Acked-by: Paul Elder <paul.elder@ideasonboard.com> Acked-by: Show Liu <show.liu@linaro.org>
2020-03-07gst: Fix GLib detectionLaurent Pinchart
Commit 17cccc68a88f ("Add GStreamer plugin and element skeleton") has gained a last minute fix for a clang compilation error with GLib prior to v2.63.0. The fix wasn't properly tested, and failed to check the GLib dependency correctly. This resulted in compilation of the GStreamer element to always be disabled. Fix this by changing the GLib package name from 'glib' to 'glib-2.0'. Fixes: 17cccc68a88f ("Add GStreamer plugin and element skeleton") Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
2020-03-07gst: Turn the top-level plugin file gstlibcamera.c into a C++ fileLaurent Pinchart
The top-level plugin file gstlibcamera.c is the only C source file in the whole libcamera GStreamer element. To avoid specifying both C and C++ compiler arguments in the future, turn it into a C++ file. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
2020-03-07gst: Add a pool and an allocator implementationNicolas Dufresne
This is needed to track the lifetime of the FrameBufferAllocator in relation to the GstBuffer/GstMemory objects travelling inside GStreamer. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07gst: Add pads to the sourceNicolas Dufresne
This simply adds the boiler plate for pads on the source element. The design is that we have one pad, called "src", that will always be present, and then more pads can be requested prior in READY or less state. Initially pads have one property "stream-role" that let you decide which role this pad will have. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07gst: Add initial device providerNicolas Dufresne
This feature is used with GstDeviceMonitor in order to enumerate and monitor devices to be used with the source element. The resulting GstDevice implementation is also used by application to abstract the configuration of the source element. Implementation notes: - libcamera does not support polling yet - The device ID isn't unique in libcamera yet - The "name" property does not yet exist in libcamerasrc yet Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07gst: Add utility to convert StreamFormats to GstCapsNicolas Dufresne
This transforms the basic information found in StreamFormats to GstCaps. This can be handy to reply to early caps query or inside a device provider. Note that we ignored generated range as they are harmful to caps negotiation. We also don't simplify the caps for readability reasons, so some of the discrete value may be included in a range. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07Add GStreamer plugin and element skeletonNicolas Dufresne
This implements the GStreamer plugin interface and adds libcamerasrc element feature to it. This is just enough to allow plugin introspection. gst-inspect-1.0 build/src/gstreamer/libgstlibcamera.so Plugin Details: Name libcamera Description libcamera capture plugin Filename build/src/gstreamer/libgstlibcamera.so Version 0.0.0+1042-6c9f16d3-dirty License LGPL Source module libcamera Binary package libcamera Origin URL https://libcamera.org libcamerasrc: libcamera Source 1 features: GST_PLUGIN_PATH=$(pwd)/build/src/gstreamer gst-inspect-1.0 libcamerasrc Factory Details: Rank primary (256) Long-name libcamera Source Klass Source/Video Description Linux Camera source using libcamera Author Nicolas Dufresne <nicolas.dufresne@collabora.com Plugin Details: Name libcamera Description libcamera capture plugin Filename /home/nicolas/Sources/libcamera/build/src/gstreamer/libgstlibcamera.so Version 0.0.0+1042-6c9f16d3-dirty License LGPL Source module libcamera Binary package libcamera Origin URL https://libcamera.org GObject +----GInitiallyUnowned +----GstObject +----GstElement +----GstLibcameraSrc Pad Templates: none Element has no clocking capabilities. Element has no URI handling capabilities. Pads: none Element Properties: name : The name of the object flags: accès en lecture, accès en écriture, 0x2000 String. Default: "libcamerasrc0" parent : The parent of the object flags: accès en lecture, accès en écriture, 0x2000 Object of type "GstObject" Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> [Silence -Wunused-function warning for older GLib versions] Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
href='#n336'>336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2020, Google Inc.
 *
 * file.cpp - File I/O operations tests
 */

#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

#include "libcamera/internal/file.h"

#include "test.h"

using namespace std;
using namespace libcamera;

class FileTest : public Test
{
protected:
	int init()
	{
		fileName_ = "/tmp/libcamera.test.XXXXXX";
		int fd = mkstemp(&fileName_.front());
		if (fd == -1)
			return TestFail;

		close(fd);
		unlink(fileName_.c_str());

		return TestPass;
	}

	int run()
	{
		/* Test static functions. */
		if (!File::exists("/dev/null")) {
			cerr << "Valid file not found" << endl;
			return TestFail;
		}

		if (File::exists("/dev/null/invalid")) {
			cerr << "Invalid file should not exist" << endl;
			return TestFail;
		}

		if (File::exists("/dev")) {
			cerr << "Directories should not be treated as files" << endl;
			return TestFail;
		}

		/* Test unnamed file. */
		File file;

		if (!file.fileName().empty()) {
			cerr << "Unnamed file has non-empty file name" << endl;
			return TestFail;
		}

		if (file.exists()) {
			cerr << "Unnamed file exists" << endl;
			return TestFail;
		}

		if (file.isOpen()) {
			cerr << "File is open after construction" << endl;
			return TestFail;
		}

		if (file.openMode() != File::NotOpen) {
			cerr << "File has invalid open mode after construction"
			     << endl;
			return TestFail;
		}

		if (file.size() >= 0) {
			cerr << "Unnamed file has a size" << endl;
			return TestFail;
		}

		if (file.open(File::ReadWrite)) {
			cerr << "Opening unnamed file succeeded" << endl;
			return TestFail;
		}

		if (file.error() == 0) {
			cerr << "Open failure didn't set error" << endl;
			return TestFail;
		}

		/* Test named file referring to an invalid file. */
		file.setFileName("/dev/null/invalid");

		if (file.fileName() != "/dev/null/invalid") {
			cerr << "File reports incorrect file name" << endl;
			return TestFail;
		}

		if (file.exists()) {
			cerr << "Invalid file exists" << endl;
			return TestFail;
		}

		if (file.isOpen()) {
			cerr << "Invalid file is open after construction" << endl;
			return TestFail;
		}

		if (file.openMode() != File::NotOpen) {
			cerr << "Invalid file has invalid open mode after construction"
			     << endl;
			return TestFail;
		}

		if (file.size() >= 0) {
			cerr << "Invalid file has a size" << endl;
			return TestFail;
		}

		if (file.open(File::ReadWrite)) {
			cerr << "Opening invalid file succeeded" << endl;
			return TestFail;
		}

		/* Test named file referring to a valid file. */
		file.setFileName("/dev/null");

		if (!file.exists()) {
			cerr << "Valid file does not exist" << endl;
			return TestFail;
		}

		if (file.isOpen()) {
			cerr << "Valid file is open after construction" << endl;
			return TestFail;
		}

		if (file.openMode() != File::NotOpen) {
			cerr << "Valid file has invalid open mode after construction"
			     << endl;
			return TestFail;
		}

		if (file.size() >= 0) {
			cerr << "Invalid file has a size" << endl;
			return TestFail;
		}

		/* Test open and close. */
		if (!file.open(File::ReadWrite)) {
			cerr << "Opening file failed" << endl;
			return TestFail;
		}

		if (!file.isOpen()) {
			cerr << "Open file reported as closed" << endl;
			return TestFail;
		}

		if (file.openMode() != File::ReadWrite) {
			cerr << "Open file has invalid open mode" << endl;
			return TestFail;
		}

		file.close();

		if (file.isOpen()) {
			cerr << "Closed file reported as open" << endl;
			return TestFail;
		}

		if (file.openMode() != File::NotOpen) {
			cerr << "Closed file has invalid open mode" << endl;
			return TestFail;
		}

		/* Test size(). */
		file.setFileName("/proc/self/exe");

		if (file.size() >= 0) {
			cerr << "File has valid size before open" << endl;
			return TestFail;
		}

		file.open(File::ReadOnly);

		ssize_t size = file.size();
		if (size <= 0) {
			cerr << "File has invalid size after open" << endl;
			return TestFail;
		}

		file.close();

		/* Test file creation. */
		file.setFileName(fileName_);

		if (file.exists()) {
			cerr << "Temporary file already exists" << endl;
			return TestFail;
		}

		if (file.open(File::ReadOnly)) {
			cerr << "Read-only open succeeded on nonexistent file" << endl;
			return TestFail;
		}

		if (!file.open(File::WriteOnly)) {
			cerr << "Write-only open failed on nonexistent file" << endl;
			return TestFail;
		}

		if (!file.exists()) {
			cerr << "Write-only open failed to create file" << endl;
			return TestFail;
		}

		file.close();

		/* Test read and write. */
		std::array<uint8_t, 256> buffer = { 0 };

		strncpy(reinterpret_cast<char *>(buffer.data()), "libcamera",
			buffer.size());

		if (file.read(buffer) >= 0) {
			cerr << "Read succeeded on closed file" << endl;
			return TestFail;
		}

		if (file.write(buffer) >= 0) {
			cerr << "Write succeeded on closed file" << endl;
			return TestFail;
		}

		file.open(File::ReadOnly);

		if (file.write(buffer) >= 0) {
			cerr << "Write succeeded on read-only file" << endl;
			return TestFail;
		}

		file.close();

		file.open(File::ReadWrite);

		if (file.write({ buffer.data(), 9 }) != 9) {
			cerr << "Write test failed" << endl;
			return TestFail;
		}

		if (file.read(buffer) != 0) {
			cerr << "Read at end of file test failed" << endl;
			return TestFail;
		}

		if (file.seek(0) != 0) {
			cerr << "Seek test failed" << endl;
			return TestFail;
		}

		if (file.read(buffer) != 9) {
			cerr << "Read test failed" << endl;
			return TestFail;
		}

		if (file.pos() != 9) {
			cerr << "Position test failed" << endl;
			return TestFail;
		}

		file.close();

		/* Test mapping and unmapping. */
		file.setFileName("/proc/self/exe");
		file.open(File::ReadOnly);

		Span<uint8_t> data = file.map();
		if (data.empty()) {
			cerr << "Mapping of complete file failed" << endl;
			return TestFail;
		}

		if (data.size() != static_cast<size_t>(size)) {
			cerr << "Mapping  of complete file has invalid size" << endl;
			return TestFail;
		}

		if (!file.unmap(data.data())) {
			cerr << "Unmapping of complete file failed" << endl;
			return TestFail;
		}

		data = file.map(4096, 8192);
		if (data.empty()) {
			cerr << "Mapping of file region failed" << endl;
			return TestFail;
		}

		if (data.size() != 8192) {
			cerr << "Mapping of file region has invalid size" << endl;
			return TestFail;
		}

		if (!file.unmap(data.data())) {
			cerr << "Unmapping of file region failed" << endl;
			return TestFail;
		}

		file.close();

		/* Test private mapping. */
		file.setFileName(fileName_);
		file.open(File::ReadWrite);

		data = file.map(0, -1, File::MapPrivate);
		if (data.empty()) {
			cerr << "Private mapping failed" << endl;
			return TestFail;
		}

		std::string str{ reinterpret_cast<char *>(data.data()), data.size() };
		if (str != "libcamera") {
			cerr << "Invalid contents of private mapping" << endl;
			return TestFail;
		}

		memcpy(data.data(), "LIBCAMERA", 9);

		if (!file.unmap(data.data())) {
			cerr << "Private unmapping failed" << endl;
			return TestFail;
		}

		data = file.map();

		str = { reinterpret_cast<char *>(data.data()), data.size() };
		if (str != "libcamera") {
			cerr << "Private mapping changed file contents" << endl;
			return TestFail;
		}

		/* Test shared mapping. */
		data = file.map();
		if (data.empty()) {
			cerr << "Shared mapping failed" << endl;
			return TestFail;
		}

		memcpy(data.data(), "LIBCAMERA", 9);

		if (!file.unmap(data.data())) {
			cerr << "Shared unmapping failed" << endl;
			return TestFail;
		}

		data = file.map();

		str = { reinterpret_cast<char *>(data.data()), data.size() };
		if (str != "LIBCAMERA") {
			cerr << "Shared mapping failed to change file contents"
			     << endl;
			return TestFail;
		}

		return TestPass;
	}

	void cleanup()
	{
		unlink(fileName_.c_str());
	}

private:
	std::string fileName_;
};

TEST_REGISTER(FileTest)