summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libcamera/ipa/raspberrypi.mojom8
-rw-r--r--src/ipa/raspberrypi/raspberrypi.cpp62
-rw-r--r--src/libcamera/pipeline/raspberrypi/raspberrypi.cpp36
3 files changed, 46 insertions, 60 deletions
diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom
index eb427697..fafbd6c0 100644
--- a/include/libcamera/ipa/raspberrypi.mojom
+++ b/include/libcamera/ipa/raspberrypi.mojom
@@ -15,10 +15,6 @@ enum BufferMask {
/* Size of the LS grid allocation. */
const uint32 MaxLsGridSize = 0x8000;
-enum ConfigOutputParameters {
- ConfigSensorParams = 0x01,
-};
-
struct SensorConfig {
uint32 gainDelay;
uint32 exposureDelay;
@@ -40,8 +36,6 @@ struct ConfigInput {
};
struct ConfigOutput {
- uint32 params;
- SensorConfig sensorConfig;
ControlList controls;
};
@@ -51,7 +45,7 @@ struct StartControls {
};
interface IPARPiInterface {
- init(IPASettings settings) => (int32 ret);
+ init(IPASettings settings) => (int32 ret, SensorConfig sensorConfig);
start(StartControls controls) => (StartControls result);
stop();
diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index 7904225a..a5b4b311 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -79,7 +79,7 @@ public:
munmap(lsTable_, ipa::RPi::MaxLsGridSize);
}
- int init(const IPASettings &settings) override;
+ int init(const IPASettings &settings, ipa::RPi::SensorConfig *sensorConfig) override;
void start(const ipa::RPi::StartControls &data,
ipa::RPi::StartControls *result) override;
void stop() override {}
@@ -164,9 +164,35 @@ private:
double maxFrameDuration_;
};
-int IPARPi::init(const IPASettings &settings)
+int IPARPi::init(const IPASettings &settings, ipa::RPi::SensorConfig *sensorConfig)
{
tuningFile_ = settings.configurationFile;
+
+ /*
+ * Load the "helper" for this sensor. This tells us all the device specific stuff
+ * that the kernel driver doesn't. We only do this the first time; we don't need
+ * to re-parse the metadata after a simple mode-switch for no reason.
+ */
+ helper_ = std::unique_ptr<RPiController::CamHelper>(RPiController::CamHelper::Create(settings.sensorModel));
+ if (!helper_) {
+ LOG(IPARPI, Error) << "Could not create camera helper for "
+ << settings.sensorModel;
+ return -EINVAL;
+ }
+
+ /*
+ * Pass out the sensor config to the pipeline handler in order
+ * to setup the staggered writer class.
+ */
+ int gainDelay, exposureDelay, vblankDelay, sensorMetadata;
+ helper_->GetDelays(exposureDelay, gainDelay, vblankDelay);
+ sensorMetadata = helper_->SensorEmbeddedDataPresent();
+
+ sensorConfig->gainDelay = gainDelay;
+ sensorConfig->exposureDelay = exposureDelay;
+ sensorConfig->vblankDelay = vblankDelay;
+ sensorConfig->sensorMetadata = sensorMetadata;
+
return 0;
}
@@ -301,8 +327,6 @@ int IPARPi::configure(const CameraSensorInfo &sensorInfo,
return -1;
}
- result->params = 0;
-
sensorCtrls_ = entityControls.at(0);
ispCtrls_ = entityControls.at(1);
@@ -319,36 +343,6 @@ int IPARPi::configure(const CameraSensorInfo &sensorInfo,
/* Setup a metadata ControlList to output metadata. */
libcameraMetadata_ = ControlList(controls::controls);
- /*
- * Load the "helper" for this sensor. This tells us all the device specific stuff
- * that the kernel driver doesn't. We only do this the first time; we don't need
- * to re-parse the metadata after a simple mode-switch for no reason.
- */
- std::string cameraName(sensorInfo.model);
- if (!helper_) {
- helper_ = std::unique_ptr<RPiController::CamHelper>(RPiController::CamHelper::Create(cameraName));
-
- if (!helper_) {
- LOG(IPARPI, Error) << "Could not create camera helper for "
- << cameraName;
- return -1;
- }
-
- /*
- * Pass out the sensor config to the pipeline handler in order
- * to setup the staggered writer class.
- */
- int gainDelay, exposureDelay, vblankDelay, sensorMetadata;
- helper_->GetDelays(exposureDelay, gainDelay, vblankDelay);
- sensorMetadata = helper_->SensorEmbeddedDataPresent();
-
- result->params |= ipa::RPi::ConfigSensorParams;
- result->sensorConfig.gainDelay = gainDelay;
- result->sensorConfig.exposureDelay = exposureDelay;
- result->sensorConfig.vblankDelay = vblankDelay;
- result->sensorConfig.sensorMetadata = sensorMetadata;
- }
-
/* Re-assemble camera mode using the sensor info. */
setMode(sensorInfo);
diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
index 2c8ae31a..ce199418 100644
--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
@@ -146,7 +146,7 @@ public:
void frameStarted(uint32_t sequence);
- int loadIPA();
+ int loadIPA(ipa::RPi::SensorConfig *sensorConfig);
int configureIPA(const CameraConfiguration *config);
void statsMetadataComplete(uint32_t bufferId, const ControlList &controls);
@@ -1030,11 +1030,24 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator)
if (data->sensor_->init())
return false;
- if (data->loadIPA()) {
+ ipa::RPi::SensorConfig sensorConfig;
+ if (data->loadIPA(&sensorConfig)) {
LOG(RPI, Error) << "Failed to load a suitable IPA library";
return false;
}
+ /*
+ * Setup our delayed control writer with the sensor default
+ * gain and exposure delays. Mark VBLANK for priority write.
+ */
+ std::unordered_map<uint32_t, DelayedControls::ControlParams> params = {
+ { V4L2_CID_ANALOGUE_GAIN, { sensorConfig.gainDelay, false } },
+ { V4L2_CID_EXPOSURE, { sensorConfig.exposureDelay, false } },
+ { V4L2_CID_VBLANK, { sensorConfig.vblankDelay, true } }
+ };
+ data->delayedCtrls_ = std::make_unique<DelayedControls>(data->unicam_[Unicam::Image].dev(), params);
+ data->sensorMetadata_ = sensorConfig.sensorMetadata;
+
/* Register the controls that the Raspberry Pi IPA can handle. */
data->controlInfo_ = RPi::Controls;
/* Initialize the camera properties. */
@@ -1214,7 +1227,7 @@ void RPiCameraData::frameStarted(uint32_t sequence)
delayedCtrls_->applyControls(sequence);
}
-int RPiCameraData::loadIPA()
+int RPiCameraData::loadIPA(ipa::RPi::SensorConfig *sensorConfig)
{
ipa_ = IPAManager::createIPA<ipa::RPi::IPAProxyRPi>(pipe_, 1, 1);
@@ -1230,7 +1243,7 @@ int RPiCameraData::loadIPA()
IPASettings settings(ipa_->configurationFile(sensor_->model() + ".json"),
sensor_->model());
- return ipa_->init(settings);
+ return ipa_->init(settings, sensorConfig);
}
int RPiCameraData::configureIPA(const CameraConfiguration *config)
@@ -1293,21 +1306,6 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)
return -EPIPE;
}
- if (result.params & ipa::RPi::ConfigSensorParams) {
- /*
- * Setup our delayed control writer with the sensor default
- * gain and exposure delays. Mark VBLANK for priority write.
- */
- std::unordered_map<uint32_t, DelayedControls::ControlParams> params = {
- { V4L2_CID_ANALOGUE_GAIN, { result.sensorConfig.gainDelay, false } },
- { V4L2_CID_EXPOSURE, { result.sensorConfig.exposureDelay, false } },
- { V4L2_CID_VBLANK, { result.sensorConfig.vblankDelay, true } }
- };
-
- delayedCtrls_ = std::make_unique<DelayedControls>(unicam_[Unicam::Image].dev(), params);
- sensorMetadata_ = result.sensorConfig.sensorMetadata;
- }
-
if (!result.controls.empty()) {
ControlList &ctrls = result.controls;
unicam_[Unicam::Image].dev()->setControls(&ctrls);
d='n482' href='#n482'>482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * Control handling
 */

#include <libcamera/controls.h>

#include <sstream>
#include <string.h>
#include <string>

#include <libcamera/base/log.h>
#include <libcamera/base/utils.h>

#include "libcamera/internal/control_validator.h"

/**
 * \file controls.h
 * \brief Framework to manage controls related to an object
 *
 * A control is a mean to govern or influence the operation of an object, and in
 * particular of a camera. Every control is defined by a unique numerical ID, a
 * name string and the data type of the value it stores. The libcamera API
 * defines a set of standard controls in the libcamera::controls namespace, as
 * a set of instances of the Control class.
 *
 * The main way for applications to interact with controls is through the
 * ControlList stored in the Request class:
 *
 * \code{.cpp}
 * Request *req = ...;
 * ControlList &controls = req->controls();
 * controls->set(controls::AwbEnable, false);
 * controls->set(controls::ManualExposure, 1000);
 *
 * ...
 *
 * int32_t exposure = controls->get(controls::ManualExposure);
 * \endcode
 *
 * The ControlList::get() and ControlList::set() functions automatically deduce
 * the data type based on the control.
 */

namespace libcamera {

LOG_DEFINE_CATEGORY(Controls)

namespace {

static constexpr size_t ControlValueSize[] = {
	[ControlTypeNone]		= 0,
	[ControlTypeBool]		= sizeof(bool),
	[ControlTypeByte]		= sizeof(uint8_t),
	[ControlTypeUnsigned16]		= sizeof(uint16_t),
	[ControlTypeUnsigned32]		= sizeof(uint32_t),
	[ControlTypeInteger32]		= sizeof(int32_t),
	[ControlTypeInteger64]		= sizeof(int64_t),
	[ControlTypeFloat]		= sizeof(float),
	[ControlTypeString]		= sizeof(char),
	[ControlTypeRectangle]		= sizeof(Rectangle),
	[ControlTypeSize]		= sizeof(Size),
	[ControlTypePoint]		= sizeof(Point),
};

} /* namespace */

/**
 * \enum ControlType
 * \brief Define the data type of a Control
 * \var ControlTypeNone
 * Invalid type, for empty values
 * \var ControlTypeBool
 * The control stores a boolean value
 * \var ControlTypeByte
 * The control stores a byte value as an unsigned 8-bit integer
 * \var ControlTypeUnsigned16
 * The control stores an unsigned 16-bit integer value
 * \var ControlTypeUnsigned32
 * The control stores an unsigned 32-bit integer value
 * \var ControlTypeInteger32
 * The control stores a signed 32-bit integer value
 * \var ControlTypeInteger64
 * The control stores a signed 64-bit integer value
 * \var ControlTypeFloat
 * The control stores a 32-bit floating point value
 * \var ControlTypeString
 * The control stores a string value as an array of char
 */

/**
 * \class ControlValue
 * \brief Abstract type representing the value of a control
 */

/** \todo Revisit the ControlValue layout when stabilizing the ABI */
static_assert(sizeof(ControlValue) == 16, "Invalid size of ControlValue class");

/**
 * \brief Construct an empty ControlValue.
 */
ControlValue::ControlValue()
	: type_(ControlTypeNone), isArray_(false), numElements_(0)
{
}

/**
 * \fn template<typename T> T ControlValue::ControlValue(const T &value)
 * \brief Construct a ControlValue of type T
 * \param[in] value Initial value
 *
 * This function constructs a new instance of ControlValue and stores the \a
 * value inside it. If the type \a T is equivalent to Span<R>, the instance
 * stores an array of values of type \a R. Otherwise the instance stores a
 * single value of type \a T. The numElements() and type() are updated to
 * reflect the stored value.
 */

void ControlValue::release()
{
	std::size_t size = numElements_ * ControlValueSize[type_];

	if (size > sizeof(value_)) {
		delete[] reinterpret_cast<uint8_t *>(storage_);
		storage_ = nullptr;
	}
}

ControlValue::~ControlValue()
{
	release();
}

/**
 * \brief Construct a ControlValue with the content of \a other
 * \param[in] other The ControlValue to copy content from
 */
ControlValue::ControlValue(const ControlValue &other)
	: type_(ControlTypeNone), numElements_(0)
{
	*this = other;
}

/**
 * \brief Replace the content of the ControlValue with a copy of the content
 * of \a other
 * \param[in] other The ControlValue to copy content from
 * \return The ControlValue with its content replaced with the one of \a other
 */
ControlValue &ControlValue::operator=(const ControlValue &other)
{
	set(other.type_, other.isArray_, other.data().data(),
	    other.numElements_, ControlValueSize[other.type_]);
	return *this;
}

/**
 * \fn ControlValue::type()
 * \brief Retrieve the data type of the value
 * \return The value data type
 */

/**
 * \fn ControlValue::isNone()
 * \brief Determine if the value is not initialised
 * \return True if the value type is ControlTypeNone, false otherwise
 */

/**
 * \fn ControlValue::isArray()
 * \brief Determine if the value stores an array
 * \return True if the value stores an array, false otherwise
 */

/**
 * \fn ControlValue::numElements()
 * \brief Retrieve the number of elements stored in the ControlValue
 *
 * For instances storing an array, this function returns the number of elements
 * in the array. For instances storing a string, it returns the length of the
 * string, not counting the terminating '\0'. Otherwise, it returns 1.
 *
 * \return The number of elements stored in the ControlValue
 */

/**
 * \brief Retrieve the raw data of a control value
 * \return The raw data of the control value as a span of uint8_t
 */
Span<const uint8_t> ControlValue::data() const
{
	std::size_t size = numElements_ * ControlValueSize[type_];
	const uint8_t *data = size > sizeof(value_)
			    ? reinterpret_cast<const uint8_t *>(storage_)
			    : reinterpret_cast<const uint8_t *>(&value_);
	return { data, size };
}

/**
 * \copydoc ControlValue::data() const
 */
Span<uint8_t> ControlValue::data()
{
	Span<const uint8_t> data = const_cast<const ControlValue *>(this)->data();
	return { const_cast<uint8_t *>(data.data()), data.size() };
}

/**
 * \brief Assemble and return a string describing the value
 * \return A string describing the ControlValue
 */
std::string ControlValue::toString() const
{
	if (type_ == ControlTypeNone)
		return "<ValueType Error>";

	const uint8_t *data = ControlValue::data().data();

	if (type_ == ControlTypeString)
		return std::string(reinterpret_cast<const char *>(data),
				   numElements_);

	std::string str(isArray_ ? "[ " : "");

	for (unsigned int i = 0; i < numElements_; ++i) {
		switch (type_) {
		case ControlTypeBool: {
			const bool *value = reinterpret_cast<const bool *>(data);
			str += *value ? "true" : "false";
			break;
		}
		case ControlTypeByte: {
			const uint8_t *value = reinterpret_cast<const uint8_t *>(data);
			str += std::to_string(*value);
			break;
		}
		case ControlTypeUnsigned16: {
			const uint16_t *value = reinterpret_cast<const uint16_t *>(data);
			str += std::to_string(*value);
			break;
		}
		case ControlTypeUnsigned32: {
			const uint32_t *value = reinterpret_cast<const uint32_t *>(data);
			str += std::to_string(*value);
			break;
		}
		case ControlTypeInteger32: {
			const int32_t *value = reinterpret_cast<const int32_t *>(data);
			str += std::to_string(*value);
			break;
		}
		case ControlTypeInteger64: {
			const int64_t *value = reinterpret_cast<const int64_t *>(data);
			str += std::to_string(*value);
			break;
		}
		case ControlTypeFloat: {
			const float *value = reinterpret_cast<const float *>(data);
			str += std::to_string(*value);
			break;
		}
		case ControlTypeRectangle: {
			const Rectangle *value = reinterpret_cast<const Rectangle *>(data);
			str += value->toString();
			break;
		}
		case ControlTypeSize: {
			const Size *value = reinterpret_cast<const Size *>(data);
			str += value->toString();
			break;
		}
		case ControlTypePoint: {
			const Point *value = reinterpret_cast<const Point *>(data);
			str += value->toString();
			break;
		}
		case ControlTypeNone:
		case ControlTypeString:
			break;
		}

		if (i + 1 != numElements_)
			str += ", ";

		data += ControlValueSize[type_];
	}

	if (isArray_)
		str += " ]";

	return str;
}

/**
 * \brief Compare ControlValue instances for equality
 * \return True if the values have identical types and values, false otherwise
 */
bool ControlValue::operator==(const ControlValue &other) const
{
	if (type_ != other.type_)
		return false;

	if (numElements_ != other.numElements())