summaryrefslogtreecommitdiff
path: root/src/android/camera_request.h
blob: 20aba79d50578b8b25eb7109776b3273db7c2f3a (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
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2019-2021, Google Inc.
 *
 * camera_request.h - libcamera Android Camera Request Descriptor
 */

#pragma once

#include <map>
#include <memory>
#include <vector>

#include <libcamera/base/class.h>
#include <libcamera/base/mutex.h>
#include <libcamera/base/unique_fd.h>

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

#include <hardware/camera3.h>

#include "camera_metadata.h"
#include "hal_framebuffer.h"

class CameraBuffer;
class CameraStream;

class Camera3RequestDescriptor
{
public:
	enum class Status {
		Success,
		Error,
	};

	struct StreamBuffer {
		StreamBuffer(CameraStream *stream,
			     const camera3_stream_buffer_t &buffer,
			     Camera3RequestDescriptor *request);
		~StreamBuffer();

		StreamBuffer(StreamBuffer &&);
		StreamBuffer &operator=(StreamBuffer &&);

		CameraStream *stream;
		buffer_handle_t *camera3Buffer;
		std::unique_ptr<HALFrameBuffer> frameBuffer;
		libcamera::UniqueFD fence;
		Status status = Status::Success;
		libcamera::FrameBuffer *internalBuffer = nullptr;
		const libcamera::FrameBuffer *srcBuffer = nullptr;
		std::unique_ptr<CameraBuffer> dstBuffer;
		Camera3RequestDescriptor *request;

	private:
		LIBCAMERA_DISABLE_COPY(StreamBuffer)
	};

	/* Keeps track of streams requiring post-processing. */
	std::map<CameraStream *, StreamBuffer *> pendingStreamsToProcess_
		LIBCAMERA_TSA_GUARDED_BY(streamsProcessMutex_);
	libcamera::Mutex streamsProcessMutex_;

	Camera3RequestDescriptor(libcamera::Camera *camera,
				 const camera3_capture_request_t *camera3Request);
	~Camera3RequestDescriptor();

	bool isPending() const { return !complete_; }

	uint32_t frameNumber_ = 0;

	std::vector<StreamBuffer> buffers_;

	CameraMetadata settings_;
	std::unique_ptr<libcamera::Request> request_;
	std::unique_ptr<CameraMetadata> resultMetadata_;

	bool complete_ = false;
	Status status_ = Status::Success;

private:
	LIBCAMERA_DISABLE_COPY(Camera3RequestDescriptor)
};
ot;List should not contain Brightness control" << endl; return TestFail; } unsigned int count = 0; for (auto iter = list.begin(); iter != list.end(); ++iter) count++; if (count != 0) { cout << "List iteration should not produce any item" << endl; return TestFail; } /* * Set a control, and verify that the list now contains it, and * nothing else. */ list[Brightness] = 255; if (list.empty()) { cout << "List should not be empty" << endl; return TestFail; } if (list.size() != 1) { cout << "List should contain one item" << endl; return TestFail; } if (!list.contains(Brightness)) { cout << "List should contain Brightness control" << endl; return TestFail; } count = 0; for (auto iter = list.begin(); iter != list.end(); ++iter) count++; if (count != 1) { cout << "List iteration should produce one item" << endl; return TestFail; } if (list[Brightness].getInt() != 255) { cout << "Incorrest Brightness control value" << endl; return TestFail; } if (list.contains(Contrast)) { cout << "List should not contain Contract control" << endl; return TestFail; } /* * Set a second control through ControlInfo and retrieve it * through both controlId and ControlInfo. */ const ControlInfoMap &controls = camera_->controls(); const ControlInfo *brightness = &controls.find(Brightness)->second; const ControlInfo *contrast = &controls.find(Contrast)->second; list[brightness] = 64; list[contrast] = 128; if (!list.contains(Contrast) || !list.contains(contrast)) { cout << "List should contain Contrast control" << endl; return TestFail; } /* * Test control value retrieval and update through ControlInfo. */ if (list[brightness].getInt() != 64 || list[contrast].getInt() != 128) { cout << "Failed to retrieve control value" << endl; return TestFail; } list[brightness] = 10; list[contrast] = 20; if (list[brightness].getInt() != 10 || list[contrast].getInt() != 20) { cout << "Failed to update control value" << endl; return TestFail; } /* * Assert that the container has not grown with the control * updated. */ if (list.size() != 2) { cout << "List should contain two elements" << endl; return TestFail; } /* * Test list merging. Create a new list, add two controls with * one overlapping the existing list, merge the lists and clear * the old list. Verify that the new list is empty and that the * new list contains the expected items and values. */ ControlList newList(camera_.get()); newList[Brightness] = 128; newList[Saturation] = 255; newList.update(list); list.clear(); if (list.size() != 0) { cout << "Old List should contain zero items" << endl; return TestFail; } if (!list.empty()) { cout << "Old List should be empty" << endl; return TestFail; } if (newList.size() != 3) { cout << "New list has incorrect size" << endl; return TestFail; } if (!newList.contains(Brightness) || !newList.contains(Contrast) || !newList.contains(Saturation)) { cout << "New list contains incorrect items" << endl; return TestFail; } if (newList[Brightness].getInt() != 10 || newList[Contrast].getInt() != 20 || newList[Saturation].getInt() != 255) { cout << "New list contains incorrect values" << endl; return TestFail; } return TestPass; } void cleanup() { if (camera_) { camera_->release(); camera_.reset(); } cm_->stop(); delete cm_; } private: CameraManager *cm_; std::shared_ptr<Camera> camera_; }; TEST_REGISTER(ControlListTest)