summaryrefslogtreecommitdiff
path: root/test/libtest/buffer_source.cpp
blob: ee87c8cd821c373ff16f494a5e89a3af956a80aa (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
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
92
93
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2020, Google Inc.
 *
 * A provider of external buffers, suitable for use in tests.
 */

#include "buffer_source.h"

#include <iostream>
#include <memory>

#include "libcamera/internal/device_enumerator.h"

#include "test.h"

BufferSource::BufferSource()
{
}

BufferSource::~BufferSource()
{
	if (media_)
		media_->release();
}

int BufferSource::allocate(const StreamConfiguration &config)
{
	/* Locate and open the video device. */
	std::string videoDeviceName = "vivid-000-vid-out";

	std::unique_ptr<DeviceEnumerator> enumerator =
		DeviceEnumerator::create();
	if (!enumerator) {
		std::cout << "Failed to create device enumerator" << std::endl;
		return TestFail;
	}

	if (enumerator->enumerate()) {
		std::cout << "Failed to enumerate media devices" << std::endl;
		return TestFail;
	}

	DeviceMatch dm("vivid");
	dm.add(videoDeviceName);

	media_ = enumerator->search(dm);
	if (!media_) {
		std::cout << "No vivid output device available" << std::endl;
		return TestSkip;
	}

	std::unique_ptr<V4L2VideoDevice> video{ V4L2VideoDevice::fromEntityName(media_.get(), videoDeviceName) };
	if (!video) {
		std::cout << "Failed to get video device from entity "
			  << videoDeviceName << std::endl;
		return TestFail;
	}

	if (video->open()) {
		std::cout << "Unable to open " << videoDeviceName << std::endl;
		return TestFail;
	}

	/* Configure the format. */
	V4L2DeviceFormat format;
	if (video->getFormat(&format)) {
		std::cout << "Failed to get format on output device" << std::endl;
		return TestFail;
	}

	format.size = config.size;
	format.fourcc = V4L2PixelFormat::fromPixelFormat(config.pixelFormat,
							 false);
	if (video->setFormat(&format)) {
		std::cout << "Failed to set format on output device" << std::endl;
		return TestFail;
	}

	if (video->allocateBuffers(config.bufferCount, &buffers_) < 0) {
		std::cout << "Failed to allocate buffers" << std::endl;
		return TestFail;
	}

	video->close();

	return TestPass;
}

const std::vector<std::unique_ptr<FrameBuffer>> &BufferSource::buffers()
{
	return buffers_;
}
t; transform="rotate(-90,154.17883,111.5966)" style="stroke-width:1.5875;stroke-dasharray:none"> <rect style="fill:none;stroke:#000000;stroke-width:1.5875;stroke-dasharray:none;paint-order:markers stroke fill" id="rect3" width="40.994682" height="43.605846" x="134.16664" y="157.24184" /> <ellipse style="fill:none;stroke:#000000;stroke-width:1.5875;stroke-dasharray:none;paint-order:markers stroke fill" id="path3" cx="140.15703" cy="176.44627" rx="1.889045" ry="1.925626" /> </g> <path style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.5875;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1" d="M 124.34796,19.830188 124.55432,202.34478 71.238559,110.53322 Z" id="path4" sodipodi:nodetypes="cccc" /> <path style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.5875;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1" d="m 75.951119,65.022101 21.58135,-0.0285" id="path5" /> <path style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.5875;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1" d="m 75.771439,49.199448 31.330301,-0.0959" id="path6" /> <path style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.5875;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1" d="M 75.771589,70.361261 75.550979,45.079158" id="path7" /> <path style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.5875;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1" d="m 75.678569,69.597131 -5.37579,0.0701 -0.0561,-23.777873 5.31581,-0.0553" id="path8" /> <path style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.5875;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1" d="m 68.198499,70.580871 -0.0254,-25.254853" id="path7-5" sodipodi:nodetypes="cc" /> <path style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.5875;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1" d="m 68.880799,69.755251 -5.42669,0.0455 -0.0561,-23.777873 5.31581,-0.0553" id="path8-9" sodipodi:nodetypes="cccc" /> </g> </svg>