Advertisement
Guest User

for raspicam

a guest
Jul 9th, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.24 KB | None | 0 0
  1. diff --git a/host_applications/linux/apps/raspicam/RaspiCamControl.c b/host_applications/linux/apps/raspicam/RaspiCamControl.c
  2. index 9d7b249..0acb53d 100755
  3. --- a/host_applications/linux/apps/raspicam/RaspiCamControl.c
  4. +++ b/host_applications/linux/apps/raspicam/RaspiCamControl.c
  5. @@ -61,6 +61,18 @@ static XREF_T exposure_map[] =
  6.  
  7. static const int exposure_map_size = sizeof(exposure_map) / sizeof(exposure_map[0]);
  8.  
  9. +/// Structure to cross reference flicker avoid strings against the MMAL parameter equivalent
  10. +static XREF_T flicker_avoid_map[] =
  11. +{
  12. + {"off", MMAL_PARAM_FLICKERAVOID_OFF},
  13. + {"auto", MMAL_PARAM_FLICKERAVOID_AUTO},
  14. + {"50hz", MMAL_PARAM_FLICKERAVOID_50HZ},
  15. + {"60hz", MMAL_PARAM_FLICKERAVOID_60HZ},
  16. + {"max", MMAL_PARAM_FLICKERAVOID_MAX}
  17. +};
  18. +
  19. +static const int flicker_avoid_map_size = sizeof(flicker_avoid_map) / sizeof(flicker_avoid_map[0]);
  20. +
  21. /// Structure to cross reference awb strings against the MMAL parameter equivalent
  22. static XREF_T awb_map[] =
  23. {
  24. @@ -160,6 +172,7 @@ static const int stereo_mode_map_size = sizeof(stereo_mode_map)/sizeof(stereo_mo
  25. #define CommandStereoDecimate 22
  26. #define CommandStereoSwap 23
  27. #define CommandAnnotateExtras 24
  28. +#define CommandFlicker 25
  29.  
  30. static COMMAND_LIST cmdline_commands[] =
  31. {
  32. @@ -171,6 +184,7 @@ static COMMAND_LIST cmdline_commands[] =
  33. {CommandVideoStab, "-vstab", "vs", "Turn on video stabilisation", 0},
  34. {CommandEVComp, "-ev", "ev", "Set EV compensation - steps of 1/6 stop", 1},
  35. {CommandExposure, "-exposure", "ex", "Set exposure mode (see Notes)", 1},
  36. + {CommandFlicker, "-flicker", "fl", "Set flicker avoid mode (off, auto, 50hz, 60hz, max)", 1},
  37. {CommandAWB, "-awb", "awb","Set AWB mode (see Notes)", 1},
  38. {CommandImageFX, "-imxfx", "ifx","Set image effect (see Notes)", 1},
  39. {CommandColourFX, "-colfx", "cfx","Set colour effect (U:V)", 1},
  40. @@ -442,6 +456,22 @@ static MMAL_PARAM_EXPOSUREMODE_T exposure_mode_from_string(const char *str)
  41. }
  42.  
  43. /**
  44. + * Convert string to the MMAL parameter for flicker avoid mode
  45. + * @param str Incoming string to match
  46. + * @return MMAL parameter matching the string, or the AUTO option if no match found
  47. + */
  48. +static MMAL_PARAM_FLICKERAVOID_T flicker_avoid_mode_from_string(const char *str)
  49. +{
  50. + int i = raspicli_map_xref(str, flicker_avoid_map, flicker_avoid_map_size);
  51. +
  52. + if( i != -1)
  53. + return (MMAL_PARAM_FLICKERAVOID_T)i;
  54. +
  55. + vcos_log_error("Unknown flicker avoid mode: %s", str);
  56. + return MMAL_PARAM_FLICKERAVOID_AUTO;
  57. +}
  58. +
  59. +/**
  60. * Convert string to the MMAL parameter for AWB mode
  61. * @param str Incoming string to match
  62. * @return MMAL parameter matching the string, or the AUTO option if no match found
  63. @@ -581,6 +611,11 @@ int raspicamcontrol_parse_cmdline(RASPICAM_CAMERA_PARAMETERS *params, const char
  64. params->exposureMode = exposure_mode_from_string(arg2);
  65. used = 2;
  66. break;
  67. +
  68. + case CommandFlicker : // flicker avoid mode - needs string
  69. + params->flickerAvoidMode = flicker_avoid_mode_from_string(arg2);
  70. + used = 2;
  71. + break;
  72.  
  73. case CommandAWB : // AWB mode - needs single number parameter
  74. params->awbMode = awb_mode_from_string(arg2);
  75. @@ -783,6 +818,13 @@ void raspicamcontrol_display_help()
  76. {
  77. fprintf(stdout, ",%s", exposure_map[i].mode);
  78. }
  79. +
  80. + fprintf(stdout, "\n\nFlicker avoid mode options :\n%s", flicker_avoid_map[0].mode );
  81. +
  82. + for (i=1;i<flicker_avoid_map_size;i++)
  83. + {
  84. + fprintf(stdout, ",%s", flicker_avoid_map[i].mode);
  85. + }
  86.  
  87. fprintf(stdout, "\n\nAWB mode options :\n%s", awb_map[0].mode );
  88.  
  89. @@ -824,6 +866,7 @@ void raspicamcontrol_display_help()
  90. void raspicamcontrol_dump_parameters(const RASPICAM_CAMERA_PARAMETERS *params)
  91. {
  92. const char *exp_mode = raspicli_unmap_xref(params->exposureMode, exposure_map, exposure_map_size);
  93. + const char *fl_mode = raspicli_unmap_xref(params->flickerAvoidMode, flicker_avoid_map, flicker_avoid_map_size);
  94. const char *awb_mode = raspicli_unmap_xref(params->awbMode, awb_map, awb_map_size);
  95. const char *image_effect = raspicli_unmap_xref(params->imageEffect, imagefx_map, imagefx_map_size);
  96. const char *metering_mode = raspicli_unmap_xref(params->exposureMeterMode, metering_mode_map, metering_mode_map_size);
  97. @@ -831,6 +874,7 @@ void raspicamcontrol_dump_parameters(const RASPICAM_CAMERA_PARAMETERS *params)
  98. fprintf(stderr, "Sharpness %d, Contrast %d, Brightness %d\n", params->sharpness, params->contrast, params->brightness);
  99. fprintf(stderr, "Saturation %d, ISO %d, Video Stabilisation %s, Exposure compensation %d\n", params->saturation, params->ISO, params->videoStabilisation ? "Yes": "No", params->exposureCompensation);
  100. fprintf(stderr, "Exposure Mode '%s', AWB Mode '%s', Image Effect '%s'\n", exp_mode, awb_mode, image_effect);
  101. + fprintf(stderr, "Flicker Avoid Mode '%s'\n", fl_mode);
  102. fprintf(stderr, "Metering Mode '%s', Colour Effect Enabled %s with U = %d, V = %d\n", metering_mode, params->colourEffects.enable ? "Yes":"No", params->colourEffects.u, params->colourEffects.v);
  103. fprintf(stderr, "Rotation %d, hflip %s, vflip %s\n", params->rotation, params->hflip ? "Yes":"No",params->vflip ? "Yes":"No");
  104. fprintf(stderr, "ROI x %lf, y %f, w %f h %f\n", params->roi.x, params->roi.y, params->roi.w, params->roi.h);
  105. @@ -889,6 +933,7 @@ void raspicamcontrol_set_defaults(RASPICAM_CAMERA_PARAMETERS *params)
  106. params->videoStabilisation = 0;
  107. params->exposureCompensation = 0;
  108. params->exposureMode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  109. + params->flickerAvoidMode = MMAL_PARAM_FLICKERAVOID_AUTO;
  110. params->exposureMeterMode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  111. params->awbMode = MMAL_PARAM_AWBMODE_AUTO;
  112. params->imageEffect = MMAL_PARAM_IMAGEFX_NONE;
  113. @@ -937,6 +982,7 @@ int raspicamcontrol_get_all_parameters(MMAL_COMPONENT_T *camera, RASPICAM_CAMERA
  114. params->videoStabilisation = raspicamcontrol_get_video_stabilisation(camera);
  115. params->exposureCompensation = raspicamcontrol_get_exposure_compensation(camera);
  116. params->exposureMode = raspicamcontrol_get_exposure_mode(camera);
  117. + params->flickerAvoidMode = raspicamcontrol_get_flicker_avoid_mode(camera);
  118. params->awbMode = raspicamcontrol_get_awb_mode(camera);
  119. params->imageEffect = raspicamcontrol_get_image_effect(camera);
  120. params->colourEffects = raspicamcontrol_get_colour_effect(camera);
  121. @@ -963,6 +1009,7 @@ int raspicamcontrol_set_all_parameters(MMAL_COMPONENT_T *camera, const RASPICAM_
  122. result += raspicamcontrol_set_video_stabilisation(camera, params->videoStabilisation);
  123. result += raspicamcontrol_set_exposure_compensation(camera, params->exposureCompensation);
  124. result += raspicamcontrol_set_exposure_mode(camera, params->exposureMode);
  125. + result += raspicamcontrol_set_flicker_avoid_mode(camera, params->flickerAvoidMode);
  126. result += raspicamcontrol_set_metering_mode(camera, params->exposureMeterMode);
  127. result += raspicamcontrol_set_awb_mode(camera, params->awbMode);
  128. result += raspicamcontrol_set_awb_gains(camera, params->awb_gains_r, params->awb_gains_b);
  129. @@ -1186,6 +1233,29 @@ int raspicamcontrol_set_exposure_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_EXPOS
  130.  
  131.  
  132. /**
  133. + * Set flicker avoid mode for images
  134. + * @param camera Pointer to camera component
  135. + * @param mode Exposure mode to set from
  136. + * - MMAL_PARAM_FLICKERAVOID_OFF,
  137. + * - MMAL_PARAM_FLICKERAVOID_AUTO,
  138. + * - MMAL_PARAM_FLICKERAVOID_50HZ,
  139. + * - MMAL_PARAM_FLICKERAVOID_60HZ,
  140. + * - MMAL_PARAM_FLICKERAVOID_MAX,
  141. + *
  142. + * @return 0 if successful, non-zero if any parameters out of range
  143. + */
  144. +int raspicamcontrol_set_flicker_avoid_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_FLICKERAVOID_T mode)
  145. +{
  146. + MMAL_PARAMETER_FLICKERAVOID_T fl_mode = {{MMAL_PARAMETER_FLICKER_AVOID,sizeof(fl_mode)}, mode};
  147. +
  148. + if (!camera)
  149. + return 1;
  150. +
  151. + return mmal_status_to_int(mmal_port_parameter_set(camera->control, &fl_mode.hdr));
  152. +}
  153. +
  154. +
  155. +/**
  156. * Set the aWB (auto white balance) mode for images
  157. * @param camera Pointer to camera component
  158. * @param awb_mode Value to set from
  159. diff --git a/host_applications/linux/apps/raspicam/RaspiCamControl.h b/host_applications/linux/apps/raspicam/RaspiCamControl.h
  160. index 7ec4a96..f006a89 100644
  161. --- a/host_applications/linux/apps/raspicam/RaspiCamControl.h
  162. +++ b/host_applications/linux/apps/raspicam/RaspiCamControl.h
  163. @@ -46,6 +46,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  164. MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  165. MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  166. *
  167. + * Flicker Avoid Mode
  168. + * MMAL_PARAM_FLICKERAVOID_OFF,
  169. + MMAL_PARAM_FLICKERAVOID_AUTO,
  170. + MMAL_PARAM_FLICKERAVOID_50HZ,
  171. + MMAL_PARAM_FLICKERAVOID_60HZ,
  172. + MMAL_PARAM_FLICKERAVOID_MAX,
  173. + *
  174. * AWB Mode
  175. * MMAL_PARAM_AWBMODE_OFF,
  176. MMAL_PARAM_AWBMODE_AUTO,
  177. @@ -142,6 +149,7 @@ typedef struct raspicam_camera_parameters_s
  178. MMAL_PARAM_IMAGEFX_T imageEffect;
  179. MMAL_PARAMETER_IMAGEFX_PARAMETERS_T imageEffectsParameters;
  180. MMAL_PARAM_COLOURFX_T colourEffects;
  181. + MMAL_PARAM_FLICKERAVOID_T flickerAvoidMode;
  182. int rotation; /// 0-359
  183. int hflip; /// 0 or 1
  184. int vflip; /// 0 or 1
  185. @@ -188,6 +196,7 @@ int raspicamcontrol_set_metering_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_EXPOS
  186. int raspicamcontrol_set_video_stabilisation(MMAL_COMPONENT_T *camera, int vstabilisation);
  187. int raspicamcontrol_set_exposure_compensation(MMAL_COMPONENT_T *camera, int exp_comp);
  188. int raspicamcontrol_set_exposure_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_EXPOSUREMODE_T mode);
  189. +int raspicamcontrol_set_flicker_avoid_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_FLICKERAVOID_T mode);
  190. int raspicamcontrol_set_awb_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_AWBMODE_T awb_mode);
  191. int raspicamcontrol_set_awb_gains(MMAL_COMPONENT_T *camera, float r_gain, float b_gain);
  192. int raspicamcontrol_set_imageFX(MMAL_COMPONENT_T *camera, MMAL_PARAM_IMAGEFX_T imageFX);
  193. @@ -214,9 +223,12 @@ int raspicamcontrol_get_video_stabilisation(MMAL_COMPONENT_T *camera);
  194. int raspicamcontrol_get_exposure_compensation(MMAL_COMPONENT_T *camera);
  195. MMAL_PARAM_THUMBNAIL_CONFIG_T raspicamcontrol_get_thumbnail_parameters(MMAL_COMPONENT_T *camera);
  196. MMAL_PARAM_EXPOSUREMODE_T raspicamcontrol_get_exposure_mode(MMAL_COMPONENT_T *camera);
  197. +MMAL_PARAM_FLICKERAVOID_T raspicamcontrol_get_flicker_avoid_mode(MMAL_COMPONENT_T *camera);
  198. MMAL_PARAM_AWBMODE_T raspicamcontrol_get_awb_mode(MMAL_COMPONENT_T *camera);
  199. MMAL_PARAM_IMAGEFX_T raspicamcontrol_get_imageFX(MMAL_COMPONENT_T *camera);
  200. MMAL_PARAM_COLOURFX_T raspicamcontrol_get_colourFX(MMAL_COMPONENT_T *camera);
  201.  
  202.  
  203. +
  204. +
  205. #endif /* RASPICAMCONTROL_H_ */
  206. diff --git a/host_applications/linux/apps/raspicam/RaspiVid.c b/host_applications/linux/apps/raspicam/RaspiVid.c
  207. index 9651976..e48eb69 100755
  208. --- a/host_applications/linux/apps/raspicam/RaspiVid.c
  209. +++ b/host_applications/linux/apps/raspicam/RaspiVid.c
  210. @@ -79,6 +79,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  211. #include "interface/mmal/util/mmal_util_params.h"
  212. #include "interface/mmal/util/mmal_default_components.h"
  213. #include "interface/mmal/util/mmal_connection.h"
  214. +#include "interface/mmal/mmal_parameters_camera.h"
  215.  
  216. #include "RaspiCamControl.h"
  217. #include "RaspiPreview.h"
  218. @@ -257,6 +258,20 @@ static XREF_T level_map[] =
  219. static int level_map_size = sizeof(level_map) / sizeof(level_map[0]);
  220.  
  221.  
  222. +/// Structure to cross reference flicker avoid strings against the MMAL parameter equivalent
  223. +/// TODO: duplicates a structure from RaspiCamControl.c
  224. +static XREF_T flicker_avoid_map[] =
  225. +{
  226. + {"off", MMAL_PARAM_FLICKERAVOID_OFF},
  227. + {"auto", MMAL_PARAM_FLICKERAVOID_AUTO},
  228. + {"50hz", MMAL_PARAM_FLICKERAVOID_50HZ},
  229. + {"60hz", MMAL_PARAM_FLICKERAVOID_60HZ},
  230. + {"max", MMAL_PARAM_FLICKERAVOID_MAX}
  231. +};
  232. +
  233. +static const int flicker_avoid_map_size = sizeof(flicker_avoid_map) / sizeof(flicker_avoid_map[0]);
  234. +
  235. +
  236. static XREF_T initial_map[] =
  237. {
  238. {"record", 0},
  239. @@ -323,6 +338,7 @@ static void display_valid_parameters(char *app_name);
  240. #define CommandRaw 32
  241. #define CommandRawFormat 33
  242. #define CommandNetListen 34
  243. +#define CommandFlickerAvoid 35
  244.  
  245. static COMMAND_LIST cmdline_commands[] =
  246. {
  247. @@ -338,6 +354,7 @@ static COMMAND_LIST cmdline_commands[] =
  248. { CommandTimeout, "-timeout", "t", "Time (in ms) to capture for. If not specified, set to 5s. Zero to disable", 1 },
  249. { CommandDemoMode, "-demo", "d", "Run a demo mode (cycle through range of camera options, no capture)", 1},
  250. { CommandFramerate, "-framerate", "fps","Specify the frames per second to record", 1},
  251. + { CommandFlickerAvoid, "-flicker", "fl", "Select flicker avoid mode (off, auto, 50hz, 60hz, max). Default: auto", 0},
  252. { CommandPreviewEnc, "-penc", "e", "Display preview image *after* encoding (shows compression artifacts)", 0},
  253. { CommandIntraPeriod, "-intra", "g", "Specify the intra refresh period (key frame rate/GoP size). Zero to produce an initial I-frame and then just P-frames.", 1},
  254. { CommandProfile, "-profile", "pf", "Specify H264 profile to use for encoding", 1},
  255. @@ -633,7 +650,18 @@ static int parse_cmdline(int argc, const char **argv, RASPIVID_STATE *state)
  256. valid = 0;
  257. break;
  258. }
  259. +
  260. + case CommandFlickerAvoid: // flicker avoid mode
  261. + {
  262. + state->camera_parameters.flickerAvoidMode = raspicli_map_xref(argv[i + 1], flicker_avoid_map, flicker_avoid_map_size);
  263.  
  264. + if( state->camera_parameters.flickerAvoidMode == -1)
  265. + state->camera_parameters.flickerAvoidMode = MMAL_PARAM_FLICKERAVOID_AUTO;
  266. +
  267. + i++;
  268. + break;
  269. + }
  270. +
  271. case CommandPreviewEnc:
  272. state->immutableInput = 0;
  273. break;
  274. @@ -1767,6 +1795,7 @@ static MMAL_STATUS_T create_camera_component(RASPIVID_STATE *state)
  275. goto error;
  276. }
  277.  
  278. + // Note: this sets lots of parameters that were not individually addressed before.
  279. raspicamcontrol_set_all_parameters(camera, &state->camera_parameters);
  280.  
  281. state->camera_component = camera;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement