RaspiCamControl.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2013, Broadcom Europe Ltd
3 Copyright (c) 2013, James Hughes
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the copyright holder nor the
14  names of its contributors may be used to endorse or promote products
15  derived from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #if defined(__arm__) || defined(__aarch64__)
30 
31 #include <memory.h>
32 #include <stdio.h>
33 
34 #include "interface/vcos/vcos.h"
35 
36 #include "RaspiCamControl.h"
37 #include "interface/mmal/mmal.h"
38 #include "interface/mmal/mmal_logging.h"
39 #include "interface/mmal/util/mmal_default_components.h"
40 #include "interface/mmal/util/mmal_util.h"
41 #include "interface/mmal/util/mmal_util_params.h"
42 #include "interface/vmcs_host/vc_vchi_gencmd.h"
43 
45 typedef struct xref_t {
46  char const* mode;
47  int mmal_mode;
48 } XREF_T;
49 
52 static XREF_T exposure_map[] = { { "off", MMAL_PARAM_EXPOSUREMODE_OFF },
53  { "auto", MMAL_PARAM_EXPOSUREMODE_AUTO },
54  { "night", MMAL_PARAM_EXPOSUREMODE_NIGHT },
55  { "nightpreview", MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW },
56  { "backlight", MMAL_PARAM_EXPOSUREMODE_BACKLIGHT },
57  { "spotlight", MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT },
58  { "sports", MMAL_PARAM_EXPOSUREMODE_SPORTS },
59  { "snow", MMAL_PARAM_EXPOSUREMODE_SNOW },
60  { "beach", MMAL_PARAM_EXPOSUREMODE_BEACH },
61  { "verylong", MMAL_PARAM_EXPOSUREMODE_VERYLONG },
62  { "fixedfps", MMAL_PARAM_EXPOSUREMODE_FIXEDFPS },
63  { "antishake", MMAL_PARAM_EXPOSUREMODE_ANTISHAKE },
64  { "fireworks", MMAL_PARAM_EXPOSUREMODE_FIREWORKS } };
65 
66 static const int exposure_map_size = sizeof(exposure_map) / sizeof(exposure_map[0]);
67 
70 static XREF_T awb_map[] = { { "off", MMAL_PARAM_AWBMODE_OFF },
71  { "auto", MMAL_PARAM_AWBMODE_AUTO },
72  { "sun", MMAL_PARAM_AWBMODE_SUNLIGHT },
73  { "cloud", MMAL_PARAM_AWBMODE_CLOUDY },
74  { "shade", MMAL_PARAM_AWBMODE_SHADE },
75  { "tungsten", MMAL_PARAM_AWBMODE_TUNGSTEN },
76  { "fluorescent", MMAL_PARAM_AWBMODE_FLUORESCENT },
77  { "incandescent", MMAL_PARAM_AWBMODE_INCANDESCENT },
78  { "flash", MMAL_PARAM_AWBMODE_FLASH },
79  { "horizon", MMAL_PARAM_AWBMODE_HORIZON } };
80 
81 static const int awb_map_size = sizeof(awb_map) / sizeof(awb_map[0]);
82 
85 static XREF_T imagefx_map[] = { { "none", MMAL_PARAM_IMAGEFX_NONE },
86  { "negative", MMAL_PARAM_IMAGEFX_NEGATIVE },
87  { "solarise", MMAL_PARAM_IMAGEFX_SOLARIZE },
88  { "sketch", MMAL_PARAM_IMAGEFX_SKETCH },
89  { "denoise", MMAL_PARAM_IMAGEFX_DENOISE },
90  { "emboss", MMAL_PARAM_IMAGEFX_EMBOSS },
91  { "oilpaint", MMAL_PARAM_IMAGEFX_OILPAINT },
92  { "hatch", MMAL_PARAM_IMAGEFX_HATCH },
93  { "gpen", MMAL_PARAM_IMAGEFX_GPEN },
94  { "pastel", MMAL_PARAM_IMAGEFX_PASTEL },
95  { "watercolour", MMAL_PARAM_IMAGEFX_WATERCOLOUR },
96  { "film", MMAL_PARAM_IMAGEFX_FILM },
97  { "blur", MMAL_PARAM_IMAGEFX_BLUR },
98  { "saturation", MMAL_PARAM_IMAGEFX_SATURATION },
99  { "colourswap", MMAL_PARAM_IMAGEFX_COLOURSWAP },
100  { "washedout", MMAL_PARAM_IMAGEFX_WASHEDOUT },
101  { "posterise", MMAL_PARAM_IMAGEFX_POSTERISE },
102  { "colourpoint", MMAL_PARAM_IMAGEFX_COLOURPOINT },
103  { "colourbalance", MMAL_PARAM_IMAGEFX_COLOURBALANCE },
104  { "cartoon", MMAL_PARAM_IMAGEFX_CARTOON } };
105 
106 static const int imagefx_map_size = sizeof(imagefx_map) / sizeof(imagefx_map[0]);
107 
108 static XREF_T metering_mode_map[] = { { "average", MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE },
109  { "spot", MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT },
110  { "backlit", MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT },
111  { "matrix", MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX } };
112 
113 static const int metering_mode_map_size = sizeof(metering_mode_map) / sizeof(metering_mode_map[0]);
114 
115 #define CommandSharpness 0
116 #define CommandContrast 1
117 #define CommandBrightness 2
118 #define CommandSaturation 3
119 #define CommandISO 4
120 #define CommandVideoStab 5
121 #define CommandEVComp 6
122 #define CommandExposure 7
123 #define CommandAWB 8
124 #define CommandImageFX 9
125 #define CommandColourFX 10
126 #define CommandMeterMode 11
127 #define CommandRotation 12
128 #define CommandHFlip 13
129 #define CommandVFlip 14
130 #define CommandROI 15
131 
132 #define parameter_reset -99999
133 
141 static int update_cycle_parameter(int* option, int min, int max, int increment) {
142  vcos_assert(option);
143  if (!option)
144  return 0;
145 
146  if (*option == parameter_reset)
147  *option = min - increment;
148 
149  *option += increment;
150 
151  if (*option > max) {
152  *option = parameter_reset;
153  return 0;
154  } else
155  return 1;
156 }
157 
170 int raspicamcontrol_cycle_test(MMAL_COMPONENT_T& camera) {
171  static int parameter = 0;
172  static int parameter_option = parameter_reset; // which value the parameter currently has
173 
174  // We are going to cycle through all the relevant entries in the parameter
175  // block and send options to the camera.
176  if (parameter == 0) {
177  // sharpness
178  if (update_cycle_parameter(&parameter_option, -100, 100, 10))
179  raspicamcontrol_set_sharpness(camera, parameter_option);
180  else {
182  parameter++;
183  }
184  } else if (parameter == 1) {
185  // contrast
186  if (update_cycle_parameter(&parameter_option, -100, 100, 10))
187  raspicamcontrol_set_contrast(camera, parameter_option);
188  else {
189  raspicamcontrol_set_contrast(camera, 0);
190  parameter++;
191  }
192  } else if (parameter == 2) {
193  // brightness
194  if (update_cycle_parameter(&parameter_option, 0, 100, 10))
195  raspicamcontrol_set_brightness(camera, parameter_option);
196  else {
197  raspicamcontrol_set_brightness(camera, 50);
198  parameter++;
199  }
200  } else if (parameter == 3) {
201  // contrast
202  if (update_cycle_parameter(&parameter_option, -100, 100, 10))
203  raspicamcontrol_set_saturation(camera, parameter_option);
204  else {
205  parameter++;
207  }
208  } else if (parameter == 4) {
209  // EV
210  if (update_cycle_parameter(&parameter_option, -10, 10, 4))
211  raspicamcontrol_set_exposure_compensation(camera, parameter_option);
212  else {
214  parameter++;
215  }
216  } else if (parameter == 5) {
217  // MMAL_PARAM_EXPOSUREMODE_T
218  if (update_cycle_parameter(&parameter_option, 0, exposure_map_size, 1))
219  raspicamcontrol_set_exposure_mode(camera, (MMAL_PARAM_EXPOSUREMODE_T)exposure_map[parameter_option].mmal_mode);
220  else {
221  raspicamcontrol_set_exposure_mode(camera, MMAL_PARAM_EXPOSUREMODE_AUTO);
222  parameter++;
223  }
224  } else if (parameter == 6) {
225  // MMAL_PARAM_AWB_T
226  if (update_cycle_parameter(&parameter_option, 0, awb_map_size, 1))
227  raspicamcontrol_set_awb_mode(camera, (MMAL_PARAM_AWBMODE_T)awb_map[parameter_option].mmal_mode);
228  else {
229  raspicamcontrol_set_awb_mode(camera, MMAL_PARAM_AWBMODE_AUTO);
230  parameter++;
231  }
232  }
233  if (parameter == 7) {
234  // MMAL_PARAM_IMAGEFX_T
235  if (update_cycle_parameter(&parameter_option, 0, imagefx_map_size, 1))
236  raspicamcontrol_set_imageFX(camera, (MMAL_PARAM_IMAGEFX_T)imagefx_map[parameter_option].mmal_mode);
237  else {
238  raspicamcontrol_set_imageFX(camera, MMAL_PARAM_IMAGEFX_NONE);
239  parameter++;
240  }
241  }
242  if (parameter == 8) {
243  MMAL_PARAM_COLOURFX_T colfx = { 0, 0, 0 };
244  switch (parameter_option) {
245  case parameter_reset:
246  parameter_option = 1;
247  colfx.u = 128;
248  colfx.v = 128;
249  break;
250  case 1:
251  parameter_option = 2;
252  colfx.u = 100;
253  colfx.v = 200;
254  break;
255  case 2:
256  parameter_option = parameter_reset;
257  colfx.enable = 0;
258  parameter++;
259  break;
260  }
261  raspicamcontrol_set_colourFX(camera, &colfx);
262  }
263 
264  // Orientation
265  if (parameter == 9) {
266  switch (parameter_option) {
267  case parameter_reset:
268  raspicamcontrol_set_rotation(camera, 90);
269  parameter_option = 1;
270  break;
271 
272  case 1:
273  raspicamcontrol_set_rotation(camera, 180);
274  parameter_option = 2;
275  break;
276 
277  case 2:
278  raspicamcontrol_set_rotation(camera, 270);
279  parameter_option = 3;
280  break;
281 
282  case 3: {
283  raspicamcontrol_set_rotation(camera, 0);
284  raspicamcontrol_set_flips(camera, 1, 0);
285  parameter_option = 4;
286  break;
287  }
288  case 4: {
289  raspicamcontrol_set_flips(camera, 0, 1);
290  parameter_option = 5;
291  break;
292  }
293  case 5: {
294  raspicamcontrol_set_flips(camera, 1, 1);
295  parameter_option = 6;
296  break;
297  }
298  case 6: {
299  raspicamcontrol_set_flips(camera, 0, 0);
300  parameter_option = parameter_reset;
301  parameter++;
302  break;
303  }
304  }
305  }
306 
307  if (parameter == 10) {
308  parameter = 1;
309  return 0;
310  }
311 
312  return 1;
313 }
314 
322 static int map_xref(const char* str, const XREF_T* map, int num_refs) {
323  int i;
324 
325  for (i = 0; i < num_refs; i++) {
326  if (!strcasecmp(str, map[i].mode)) {
327  return map[i].mmal_mode;
328  }
329  }
330  return -1;
331 }
332 
340 static const char* unmap_xref(const int en, XREF_T* map, int num_refs) {
341  int i;
342 
343  for (i = 0; i < num_refs; i++) {
344  if (en == map[i].mmal_mode) {
345  return map[i].mode;
346  }
347  }
348  return NULL;
349 }
350 
357 /*static*/ MMAL_PARAM_EXPOSUREMODE_T exposure_mode_from_string(const char* str) {
358  int i = map_xref(str, exposure_map, exposure_map_size);
359 
360  if (i != -1)
361  return (MMAL_PARAM_EXPOSUREMODE_T)i;
362 
363  vcos_log_error("Unknown exposure mode: %s", str);
364  return MMAL_PARAM_EXPOSUREMODE_AUTO;
365 }
366 
373 MMAL_PARAM_AWBMODE_T awb_mode_from_string(const char* str) {
374  int i = map_xref(str, awb_map, awb_map_size);
375 
376  if (i != -1)
377  return (MMAL_PARAM_AWBMODE_T)i;
378 
379  vcos_log_error("Unknown awb mode: %s", str);
380  return MMAL_PARAM_AWBMODE_AUTO;
381 }
382 
389 MMAL_PARAM_IMAGEFX_T imagefx_mode_from_string(const char* str) {
390  int i = map_xref(str, imagefx_map, imagefx_map_size);
391 
392  if (i != -1)
393  return (MMAL_PARAM_IMAGEFX_T)i;
394 
395  vcos_log_error("Unknown image fx: %s", str);
396  return MMAL_PARAM_IMAGEFX_NONE;
397 }
398 
405 MMAL_PARAM_EXPOSUREMETERINGMODE_T metering_mode_from_string(const char* str) {
406  int i = map_xref(str, metering_mode_map, metering_mode_map_size);
407 
408  if (i != -1)
409  return (MMAL_PARAM_EXPOSUREMETERINGMODE_T)i;
410 
411  vcos_log_error("Unknown metering mode: %s", str);
412  return MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
413 }
414 
422  const char* exp_mode = unmap_xref(params.exposureMode, exposure_map, exposure_map_size);
423  const char* awb_mode = unmap_xref(params.awbMode, awb_map, awb_map_size);
424  const char* image_effect = unmap_xref(params.imageEffect, imagefx_map, imagefx_map_size);
425  const char* metering_mode = unmap_xref(params.exposureMeterMode, metering_mode_map, metering_mode_map_size);
426 
427  fprintf(stderr, "Sharpness %d, Contrast %d, Brightness %d\n", params.sharpness, params.contrast, params.brightness);
428  fprintf(stderr, "Saturation %d, ISO %d, Video Stabilisation %s, Exposure "
429  "compensation %d\n",
430  params.saturation, params.ISO, params.videoStabilisation ? "Yes" : "No", params.exposureCompensation);
431  fprintf(stderr, "Exposure Mode '%s', AWB Mode '%s', Image Effect '%s'\n", exp_mode, awb_mode, image_effect);
432  fprintf(stderr, "Metering Mode '%s', Colour Effect Enabled %s with U = %d, V = %d\n", metering_mode,
433  params.colourEffects.enable ? "Yes" : "No", params.colourEffects.u, params.colourEffects.v);
434  fprintf(stderr, "Rotation %d, hflip %s, vflip %s\n", params.rotation, params.hflip ? "Yes" : "No",
435  params.vflip ? "Yes" : "No");
436  fprintf(stderr, "ROI x %lf, y %f, w %f h %f\n", params.roi.x, params.roi.y, params.roi.w, params.roi.h);
437 }
438 
446 int mmal_status_to_int(MMAL_STATUS_T status) {
447  if (status == MMAL_SUCCESS)
448  return 0;
449  else {
450  switch (status) {
451  case MMAL_ENOMEM:
452  vcos_log_error("Out of memory");
453  break;
454  case MMAL_ENOSPC:
455  vcos_log_error("Out of resources (other than memory)");
456  break;
457  case MMAL_EINVAL:
458  vcos_log_error("Argument is invalid");
459  break;
460  case MMAL_ENOSYS:
461  vcos_log_error("Function not implemented");
462  break;
463  case MMAL_ENOENT:
464  vcos_log_error("No such file or directory");
465  break;
466  case MMAL_ENXIO:
467  vcos_log_error("No such device or address");
468  break;
469  case MMAL_EIO:
470  vcos_log_error("I/O error");
471  break;
472  case MMAL_ESPIPE:
473  vcos_log_error("Illegal seek");
474  break;
475  case MMAL_ECORRUPT:
476  vcos_log_error("Data is corrupt \attention FIXME: not POSIX");
477  break;
478  case MMAL_ENOTREADY:
479  vcos_log_error("Component is not ready \attention FIXME: not POSIX");
480  break;
481  case MMAL_ECONFIG:
482  vcos_log_error("Component is not configured \attention FIXME: not POSIX");
483  break;
484  case MMAL_EISCONN:
485  vcos_log_error("Port is already connected ");
486  break;
487  case MMAL_ENOTCONN:
488  vcos_log_error("Port is disconnected");
489  break;
490  case MMAL_EAGAIN:
491  vcos_log_error("Resource temporarily unavailable. Try again later");
492  break;
493  case MMAL_EFAULT:
494  vcos_log_error("Bad address");
495  break;
496  default:
497  vcos_log_error("Unknown status error");
498  break;
499  }
500 
501  return 1;
502  }
503 }
504 
510  params.sharpness = 0;
511  params.contrast = 0;
512  params.brightness = 50;
513  params.saturation = 0;
514  params.ISO = 400;
515  params.videoStabilisation = 0;
516  params.exposureCompensation = 0;
517  params.exposureMode = MMAL_PARAM_EXPOSUREMODE_AUTO;
518  params.exposureMeterMode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
519  params.awbMode = MMAL_PARAM_AWBMODE_AUTO;
520  // params.imageEffect = MMAL_PARAM_IMAGEFX_SATURATION;
521  params.imageEffect = MMAL_PARAM_IMAGEFX_NONE;
522  params.colourEffects.enable = 0;
523  params.colourEffects.u = 128;
524  params.colourEffects.v = 128;
525  params.rotation = 0;
526  params.hflip = params.vflip = 0;
527  params.roi.x = params.roi.y = 0.0;
528  params.roi.w = params.roi.h = 1.0;
529  params.shutter_speed = 0; // automatic
530 }
531 
538 int raspicamcontrol_set_all_parameters(MMAL_COMPONENT_T& camera, const RASPICAM_CAMERA_PARAMETERS& params) {
539  int result;
540 
541  result = raspicamcontrol_set_saturation(camera, params.saturation);
542  result += raspicamcontrol_set_sharpness(camera, params.sharpness);
543  result += raspicamcontrol_set_contrast(camera, params.contrast);
544  result += raspicamcontrol_set_brightness(camera, params.brightness);
545  result += raspicamcontrol_set_ISO(camera, params.ISO);
548  result += raspicamcontrol_set_exposure_mode(camera, params.exposureMode);
549  result += raspicamcontrol_set_metering_mode(camera, params.exposureMeterMode);
550  result += raspicamcontrol_set_awb_mode(camera, params.awbMode);
551  result += raspicamcontrol_set_imageFX(camera, params.imageEffect);
552  result += raspicamcontrol_set_colourFX(camera, &params.colourEffects);
553  // result += raspicamcontrol_set_thumbnail_parameters(camera,
554  // &params.thumbnailConfig); TODO Not working for some reason
555  result += raspicamcontrol_set_rotation(camera, params.rotation);
556  result += raspicamcontrol_set_flips(camera, params.hflip, params.vflip);
557  result += raspicamcontrol_set_ROI(camera, params.roi);
558  result += raspicamcontrol_set_shutter_speed(camera, params.shutter_speed);
559  return result;
560 }
561 
568 int raspicamcontrol_set_saturation(MMAL_COMPONENT_T& camera, int saturation) {
569  int ret = 0;
570 
571  if (saturation >= -100 && saturation <= 100) {
572  MMAL_RATIONAL_T value = { saturation, 100 };
573  ret = mmal_status_to_int(mmal_port_parameter_set_rational(camera.control, MMAL_PARAMETER_SATURATION, value));
574  } else {
575  vcos_log_error("Invalid saturation value");
576  ret = 1;
577  }
578 
579  return ret;
580 }
581 
587 int raspicamcontrol_set_sharpness(MMAL_COMPONENT_T& camera, int sharpness) {
588  int ret = 0;
589 
590  if (sharpness >= -100 && sharpness <= 100) {
591  MMAL_RATIONAL_T value = { sharpness, 100 };
592  ret = mmal_status_to_int(mmal_port_parameter_set_rational(camera.control, MMAL_PARAMETER_SHARPNESS, value));
593  } else {
594  vcos_log_error("Invalid sharpness value");
595  ret = 1;
596  }
597 
598  return ret;
599 }
600 
607 int raspicamcontrol_set_contrast(MMAL_COMPONENT_T& camera, int contrast) {
608  int ret = 0;
609 
610  if (contrast >= -100 && contrast <= 100) {
611  MMAL_RATIONAL_T value = { contrast, 100 };
612  ret = mmal_status_to_int(mmal_port_parameter_set_rational(camera.control, MMAL_PARAMETER_CONTRAST, value));
613  } else {
614  vcos_log_error("Invalid contrast value");
615  ret = 1;
616  }
617 
618  return ret;
619 }
620 
627 int raspicamcontrol_set_brightness(MMAL_COMPONENT_T& camera, int brightness) {
628  int ret = 0;
629 
630  if (brightness >= 0 && brightness <= 100) {
631  MMAL_RATIONAL_T value = { brightness, 100 };
632  ret = mmal_status_to_int(mmal_port_parameter_set_rational(camera.control, MMAL_PARAMETER_BRIGHTNESS, value));
633  } else {
634  vcos_log_error("Invalid brightness value");
635  ret = 1;
636  }
637 
638  return ret;
639 }
640 
647 int raspicamcontrol_set_ISO(MMAL_COMPONENT_T& camera, int ISO) {
648  return mmal_status_to_int(mmal_port_parameter_set_uint32(camera.control, MMAL_PARAMETER_ISO, ISO));
649 }
650 
661 int raspicamcontrol_set_metering_mode(MMAL_COMPONENT_T& camera, MMAL_PARAM_EXPOSUREMETERINGMODE_T m_mode) {
662  MMAL_PARAMETER_EXPOSUREMETERINGMODE_T meter_mode = { { MMAL_PARAMETER_EXP_METERING_MODE, sizeof(meter_mode) },
663  m_mode };
664 
665  return mmal_status_to_int(mmal_port_parameter_set(camera.control, &meter_mode.hdr));
666 }
667 
674 int raspicamcontrol_set_video_stabilisation(MMAL_COMPONENT_T& camera, int vstabilisation) {
675  return mmal_status_to_int(
676  mmal_port_parameter_set_boolean(camera.control, MMAL_PARAMETER_VIDEO_STABILISATION, vstabilisation));
677 }
678 
685 int raspicamcontrol_set_exposure_compensation(MMAL_COMPONENT_T& camera, int exp_comp) {
686  return mmal_status_to_int(mmal_port_parameter_set_int32(camera.control, MMAL_PARAMETER_EXPOSURE_COMP, exp_comp));
687 }
688 
709 int raspicamcontrol_set_exposure_mode(MMAL_COMPONENT_T& camera, MMAL_PARAM_EXPOSUREMODE_T mode) {
710  MMAL_PARAMETER_EXPOSUREMODE_T exp_mode = { { MMAL_PARAMETER_EXPOSURE_MODE, sizeof(exp_mode) }, mode };
711 
712  return mmal_status_to_int(mmal_port_parameter_set(camera.control, &exp_mode.hdr));
713 }
714 
731 int raspicamcontrol_set_awb_mode(MMAL_COMPONENT_T& camera, MMAL_PARAM_AWBMODE_T awb_mode) {
732  MMAL_PARAMETER_AWBMODE_T param = { { MMAL_PARAMETER_AWB_MODE, sizeof(param) }, awb_mode };
733 
734  return mmal_status_to_int(mmal_port_parameter_set(camera.control, &param.hdr));
735 }
736 
766 int raspicamcontrol_set_imageFX(MMAL_COMPONENT_T& camera, MMAL_PARAM_IMAGEFX_T imageFX) {
767  MMAL_PARAMETER_IMAGEFX_T imgFX = { { MMAL_PARAMETER_IMAGE_EFFECT, sizeof(imgFX) }, imageFX };
768 
769  return mmal_status_to_int(mmal_port_parameter_set(camera.control, &imgFX.hdr));
770 }
771 
772 /* TODO :what to do with the image effects parameters?
773  MMAL_PARAMETER_IMAGEFX_PARAMETERS_T imfx_param =
774 {{MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,sizeof(imfx_param)}, imageFX, 0, {0}};
775 mmal_port_parameter_set(camera.control, &imfx_param.hdr);
776  */
777 
785 int raspicamcontrol_set_colourFX(MMAL_COMPONENT_T& camera, const MMAL_PARAM_COLOURFX_T* colourFX) {
786  MMAL_PARAMETER_COLOURFX_T colfx = { { MMAL_PARAMETER_COLOUR_EFFECT, sizeof(colfx) }, 0, 0, 0 };
787 
788  colfx.enable = colourFX->enable;
789  colfx.u = colourFX->u;
790  colfx.v = colourFX->v;
791 
792  return mmal_status_to_int(mmal_port_parameter_set(camera.control, &colfx.hdr));
793 }
794 
802 int raspicamcontrol_set_rotation(MMAL_COMPONENT_T& camera, int rotation) {
803  int ret;
804  int my_rotation = ((rotation % 360) / 90) * 90;
805 
806  ret = mmal_port_parameter_set_int32(camera.output[0], MMAL_PARAMETER_ROTATION, my_rotation);
807  mmal_port_parameter_set_int32(camera.output[1], MMAL_PARAMETER_ROTATION, my_rotation);
808  mmal_port_parameter_set_int32(camera.output[2], MMAL_PARAMETER_ROTATION, my_rotation);
809 
810  return ret;
811 }
812 
821 int raspicamcontrol_set_flips(MMAL_COMPONENT_T& camera, int hflip, int vflip) {
822  MMAL_PARAMETER_MIRROR_T mirror = { { MMAL_PARAMETER_MIRROR, sizeof(MMAL_PARAMETER_MIRROR_T) },
823  MMAL_PARAM_MIRROR_NONE };
824 
825  if (hflip && vflip)
826  mirror.value = MMAL_PARAM_MIRROR_BOTH;
827  else if (hflip)
828  mirror.value = MMAL_PARAM_MIRROR_HORIZONTAL;
829  else if (vflip)
830  mirror.value = MMAL_PARAM_MIRROR_VERTICAL;
831 
832  mmal_port_parameter_set(camera.output[0], &mirror.hdr);
833  mmal_port_parameter_set(camera.output[1], &mirror.hdr);
834  return mmal_port_parameter_set(camera.output[2], &mirror.hdr);
835 }
836 
844 int raspicamcontrol_set_ROI(MMAL_COMPONENT_T& camera, PARAM_FLOAT_RECT_T rect) {
845  MMAL_PARAMETER_INPUT_CROP_T crop = { { MMAL_PARAMETER_INPUT_CROP, sizeof(MMAL_PARAMETER_INPUT_CROP_T) } };
846 
847  crop.rect.x = (65536 * rect.x);
848  crop.rect.y = (65536 * rect.y);
849  crop.rect.width = (65536 * rect.w);
850  crop.rect.height = (65536 * rect.h);
851 
852  return mmal_port_parameter_set(camera.control, &crop.hdr);
853 }
854 
861 int raspicamcontrol_set_shutter_speed(MMAL_COMPONENT_T& camera, int shutter_speed) {
862  return mmal_status_to_int(
863  mmal_port_parameter_set_uint32(camera.control, MMAL_PARAMETER_SHUTTER_SPEED, shutter_speed));
864 }
865 
871 /*static int raspicamcontrol_get_mem_gpu(void)
872 {
873  char response[80] = "";
874  int gpu_mem = 0;
875  if (vc_gencmd(response, sizeof response, "get_mem gpu") == 0)
876  vc_gencmd_number_property(response, "gpu", &gpu_mem);
877  return gpu_mem;
878 }*/
879 
885 /*static void raspicamcontrol_get_camera(int *supported, int *detected)
886 {
887  char response[80] = "";
888  if (vc_gencmd(response, sizeof response, "get_camera") == 0)
889  {
890  if (supported)
891  vc_gencmd_number_property(response, "supported", supported);
892  if (detected)
893  vc_gencmd_number_property(response, "detected", detected);
894  }
895 }*/
896 
903 void raspicamcontrol_check_configuration(int min_gpu_mem) {
904  int gpu_mem = 256; // raspicamcontrol_get_mem_gpu();
905  int supported = 1, detected = 1;
906  // raspicamcontrol_get_camera(&supported, &detected);
907  if (!supported)
908  vcos_log_error("Camera is not enabled in this build. Try running \"sudo "
909  "raspi-config\" and ensure that \"camera\" has been enabled\n");
910  else if (gpu_mem < min_gpu_mem)
911  vcos_log_error("Only %dM of gpu_mem is configured. Try running \"sudo "
912  "raspi-config\" and ensure that \"memory_split\" has a value of %d "
913  "or greater\n",
914  gpu_mem, min_gpu_mem);
915  else if (!detected)
916  vcos_log_error("Camera is not detected. Please check carefully the camera module "
917  "is installed correctly\n");
918  else
919  vcos_log_error("Failed to run camera app. Please check for firmware updates\n");
920 }
921 
922 #endif // __arm__ || __aarch64__
MMAL_PARAM_AWBMODE_T awbMode
MMAL_PARAM_COLOURFX_T colourEffects
bool param(const std::string &param_name, T &param_val, const T &default_val)
int raspicamcontrol_set_sharpness(MMAL_COMPONENT_T &camera, int sharpness)
int exposureCompensation
0 or 1 (false or true)
int raspicamcontrol_set_exposure_compensation(MMAL_COMPONENT_T &camera, int exp_comp)
int raspicamcontrol_set_shutter_speed(MMAL_COMPONENT_T &camera, int shutter_speed)
PARAM_FLOAT_RECT_T roi
0 or 1
MMAL_PARAM_IMAGEFX_T imageEffect
int raspicamcontrol_set_brightness(MMAL_COMPONENT_T &camera, int brightness)
MMAL_PARAM_EXPOSUREMETERINGMODE_T exposureMeterMode
int raspicamcontrol_set_video_stabilisation(MMAL_COMPONENT_T &camera, int vstabilisation)
void raspicamcontrol_dump_parameters(const RASPICAM_CAMERA_PARAMETERS &params)
void raspicamcontrol_check_configuration(int min_gpu_mem)
MMAL_PARAM_EXPOSUREMODE_T exposure_mode_from_string(const char *str)
int raspicamcontrol_set_exposure_mode(MMAL_COMPONENT_T &camera, MMAL_PARAM_EXPOSUREMODE_T mode)
void raspicamcontrol_set_defaults(RASPICAM_CAMERA_PARAMETERS &params)
int raspicamcontrol_set_ROI(MMAL_COMPONENT_T &camera, PARAM_FLOAT_RECT_T rect)
int raspicamcontrol_set_flips(MMAL_COMPONENT_T &camera, int hflip, int vflip)
int raspicamcontrol_set_awb_mode(MMAL_COMPONENT_T &camera, MMAL_PARAM_AWBMODE_T awb_mode)
MMAL_PARAM_EXPOSUREMODE_T exposureMode
-10 to +10 ?
int raspicamcontrol_set_ISO(MMAL_COMPONENT_T &camera, int ISO)
struct contain camera settings
int videoStabilisation
TODO : what range?
MMAL_PARAM_AWBMODE_T awb_mode_from_string(const char *str)
int raspicamcontrol_set_all_parameters(MMAL_COMPONENT_T &camera, const RASPICAM_CAMERA_PARAMETERS &params)
int raspicamcontrol_set_rotation(MMAL_COMPONENT_T &camera, int rotation)
int raspicamcontrol_set_imageFX(MMAL_COMPONENT_T &camera, MMAL_PARAM_IMAGEFX_T imageFX)
int u
Turn colourFX on or off.
int raspicamcontrol_set_metering_mode(MMAL_COMPONENT_T &camera, MMAL_PARAM_EXPOSUREMETERINGMODE_T mode)
int raspicamcontrol_cycle_test(MMAL_COMPONENT_T &camera)
int raspicamcontrol_set_colourFX(MMAL_COMPONENT_T &camera, const MMAL_PARAM_COLOURFX_T *colourFX)
int raspicamcontrol_set_contrast(MMAL_COMPONENT_T &camera, int contrast)
int raspicamcontrol_set_saturation(MMAL_COMPONENT_T &camera, int saturation)


raspicam_node
Author(s):
autogenerated on Sun Jul 5 2020 03:45:18