@@ -55,50 +55,83 @@ void LibcameraCapturer::InitCamera(int cameraId) {
5555}
5656
5757void LibcameraCapturer::InitControls (Args args) {
58- if (args.gain ) {
59- SetControls (libcamera::controls::ANALOGUE_GAIN_MODE ,
60- libcamera::controls::AnalogueGainModeManual);
61- controls_.set (libcamera::controls::ANALOGUE_GAIN , args.gain );
58+ if (!controls_. get (libcamera::controls::AnalogueGain) && args.gain ) {
59+ controls_. set (libcamera::controls::AnalogueGainMode ,
60+ libcamera::controls::AnalogueGainModeManual);
61+ controls_.set (libcamera::controls::AnalogueGain , args.gain );
6262 }
6363
64- SetControls (libcamera::controls::SHARPNESS, args.sharpness );
65- SetControls (libcamera::controls::CONTRAST, args.contrast );
66- SetControls (libcamera::controls::BRIGHTNESS, args.brightness );
67- SetControls (libcamera::controls::SATURATION, args.saturation );
68- SetControls (libcamera::controls::EXPOSURE_VALUE, args.ev );
64+ if (!controls_.get (libcamera::controls::Sharpness)) {
65+ controls_.set (libcamera::controls::Sharpness, args.sharpness );
66+ }
67+ if (!controls_.get (libcamera::controls::Contrast)) {
68+ controls_.set (libcamera::controls::Contrast, args.contrast );
69+ }
70+ if (!controls_.get (libcamera::controls::Brightness)) {
71+ controls_.set (libcamera::controls::Brightness, args.brightness );
72+ }
73+ if (!controls_.get (libcamera::controls::Saturation)) {
74+ controls_.set (libcamera::controls::Saturation, args.saturation );
75+ }
76+ if (!controls_.get (libcamera::controls::ExposureValue)) {
77+ controls_.set (libcamera::controls::ExposureValue, args.ev );
78+ }
6979
70- if (controls_.contains (libcamera::controls::EXPOSURE_TIME)) {
71- controls_.set (libcamera::controls::EXPOSURE_TIME,
80+ if (controls_.get (libcamera::controls::ExposureTime) && args.shutter ) {
81+ controls_.set (libcamera::controls::ExposureTimeMode,
82+ libcamera::controls::ExposureTimeModeManual);
83+ controls_.set (libcamera::controls::ExposureTime,
7284 args.shutter .get <std::chrono::microseconds>());
7385 }
7486
75- SetControls (libcamera::controls::AE_METERING_MODE, args.ae_metering_mode );
76- SetControls (libcamera::controls::AE_EXPOSURE_MODE, args.ae_mode );
77- SetControls (libcamera::controls::AWB_MODE, args.awb_mode );
78- SetControls (libcamera::controls::draft::NOISE_REDUCTION_MODE, args.denoise_mode );
87+ if (!controls_.get (libcamera::controls::AeMeteringMode)) {
88+ controls_.set (libcamera::controls::AeMeteringMode, args.ae_metering_mode );
89+ }
90+ if (!controls_.get (libcamera::controls::AeExposureMode)) {
91+ controls_.set (libcamera::controls::AeExposureMode, args.ae_mode );
92+ }
93+ if (!controls_.get (libcamera::controls::AwbMode)) {
94+ controls_.set (libcamera::controls::AwbMode, args.awb_mode );
95+ }
96+
97+ if (!controls_.get (libcamera::controls::draft::NoiseReductionMode)) {
98+ controls_.set (libcamera::controls::draft::NoiseReductionMode, args.denoise_mode );
99+ }
79100
80101 if (!controls_.get (libcamera::controls::ColourGains)) {
81102 controls_.set (libcamera::controls::ColourGains,
82103 libcamera::Span<const float , 2 >({args.awb_gain_r , args.awb_gain_b }));
83104 }
84105
85- if (args.af_mode == -1 ) {
86- if (args.lens_position || args.set_default_lens_position ) {
87- args.af_mode = libcamera::controls::AfModeManual;
88- } else {
89- if (camera_->controls ().find (libcamera::controls::AF_MODE) !=
90- camera_->controls ().end () &&
91- camera_->controls ().count (&libcamera::controls::AfMode) > 0 ) {
92- args.af_mode =
93- camera_->controls ().at (&libcamera::controls::AfMode).max ().get <int >();
106+ if (!controls_.get (libcamera::controls::AfMode) &&
107+ camera_->controls ().count (&libcamera::controls::AfMode) > 0 ) {
108+ if (args.af_mode == -1 ) {
109+ if (args.lens_position || args.set_default_lens_position ) {
110+ args.af_mode = libcamera::controls::AfModeManual;
111+ } else {
112+ if (camera_->controls ().find (libcamera::controls::AF_MODE) !=
113+ camera_->controls ().end () &&
114+ camera_->controls ().count (&libcamera::controls::AfMode) > 0 ) {
115+ args.af_mode =
116+ camera_->controls ().at (&libcamera::controls::AfMode).max ().get <int >();
117+ }
94118 }
95119 }
120+ controls_.set (libcamera::controls::AfMode, args.af_mode );
121+ }
122+ if (!controls_.get (libcamera::controls::AfRange) &&
123+ camera_->controls ().count (&libcamera::controls::AfRange) > 0 ) {
124+ controls_.set (libcamera::controls::AF_RANGE, args.af_range_mode );
96125 }
97- SetControls (libcamera::controls::AF_MODE, args.af_mode );
98- SetControls (libcamera::controls::AF_RANGE, args.af_range_mode );
99- SetControls (libcamera::controls::AF_SPEED, args.af_speed_mode );
126+ if (!controls_.get (libcamera::controls::AfSpeed) &&
127+ camera_->controls ().count (&libcamera::controls::AfSpeed) > 0 ) {
100128
101- if (args.af_window_width != 0 && args.af_window_height != 0 ) {
129+ controls_.set (libcamera::controls::AF_SPEED, args.af_speed_mode );
130+ }
131+
132+ if (!controls_.get (libcamera::controls::AfWindows) &&
133+ !controls_.get (libcamera::controls::AfMetering) && args.af_window_width != 0 &&
134+ args.af_window_height != 0 ) {
102135 libcamera::Rectangle sensor_area = camera_->controls ()
103136 .at (&libcamera::controls::ScalerCrop)
104137 .max ()
@@ -111,24 +144,24 @@ void LibcameraCapturer::InitControls(Args args) {
111144 afwindows_rectangle[0 ] = libcamera::Rectangle (x, y, w, h);
112145 afwindows_rectangle[0 ].translateBy (sensor_area.topLeft ());
113146
114- SetControls (libcamera::controls::AF_METERING, libcamera::controls::AfMeteringWindows);
115-
116- if (controls_.contains (libcamera::controls::AF_WINDOWS)) {
117- controls_.set (libcamera::controls::AF_WINDOWS,
118- libcamera::Span<const libcamera::Rectangle>(afwindows_rectangle));
119- }
147+ controls_.set (libcamera::controls::AfMetering, libcamera::controls::AfMeteringWindows);
148+ controls_.set (libcamera::controls::AfWindows,
149+ libcamera::Span<const libcamera::Rectangle>(afwindows_rectangle));
120150 }
121151
122- if (args.af_mode == libcamera::controls::AfModeEnum::AfModeAuto) {
123- SetControls (libcamera::controls::AF_TRIGGER, libcamera::controls::AfTriggerStart);
124- } else if (args.lens_position || args.set_default_lens_position ) {
152+ if (!controls_.get (libcamera::controls::AfTrigger) &&
153+ args.af_mode == libcamera::controls::AfModeEnum::AfModeAuto) {
154+ controls_.set (libcamera::controls::AfTrigger, libcamera::controls::AfTriggerStart);
155+ } else if (!controls_.get (libcamera::controls::LensPosition) &&
156+ camera_->controls ().count (&libcamera::controls::LensPosition) > 0 &&
157+ (args.lens_position || args.set_default_lens_position )) {
125158 float f;
126159 if (args.lens_position ) {
127160 f = args.lens_position .value ();
128161 } else {
129162 f = camera_->controls ().at (&libcamera::controls::LensPosition).def ().get <float >();
130163 }
131- SetControls (libcamera::controls::LENS_POSITION , f);
164+ controls_. set (libcamera::controls::LensPosition , f);
132165 }
133166}
134167
@@ -191,11 +224,8 @@ LibcameraCapturer &LibcameraCapturer::SetFps(int fps) {
191224
192225LibcameraCapturer &LibcameraCapturer::SetControls (int key, int value) {
193226 std::lock_guard<std::mutex> lock (control_mutex_);
194-
195- if (controls_.contains (key) && camera_->controls ().count (key) > 0 ) {
196- controls_.set (key, value);
197- }
198-
227+ DEBUG_PRINT (" Set camera control: %d, %d" , key, value);
228+ controls_.set (key, value);
199229 return *this ;
200230}
201231
0 commit comments