Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/host_applications/linux/apps/raspicam/RaspiCamControl.c b/host_applications/linux/apps/raspicam/RaspiCamControl.c
- index 9d7b249..0acb53d 100755
- --- a/host_applications/linux/apps/raspicam/RaspiCamControl.c
- +++ b/host_applications/linux/apps/raspicam/RaspiCamControl.c
- @@ -61,6 +61,18 @@ static XREF_T exposure_map[] =
- static const int exposure_map_size = sizeof(exposure_map) / sizeof(exposure_map[0]);
- +/// Structure to cross reference flicker avoid strings against the MMAL parameter equivalent
- +static XREF_T flicker_avoid_map[] =
- +{
- + {"off", MMAL_PARAM_FLICKERAVOID_OFF},
- + {"auto", MMAL_PARAM_FLICKERAVOID_AUTO},
- + {"50hz", MMAL_PARAM_FLICKERAVOID_50HZ},
- + {"60hz", MMAL_PARAM_FLICKERAVOID_60HZ},
- + {"max", MMAL_PARAM_FLICKERAVOID_MAX}
- +};
- +
- +static const int flicker_avoid_map_size = sizeof(flicker_avoid_map) / sizeof(flicker_avoid_map[0]);
- +
- /// Structure to cross reference awb strings against the MMAL parameter equivalent
- static XREF_T awb_map[] =
- {
- @@ -160,6 +172,7 @@ static const int stereo_mode_map_size = sizeof(stereo_mode_map)/sizeof(stereo_mo
- #define CommandStereoDecimate 22
- #define CommandStereoSwap 23
- #define CommandAnnotateExtras 24
- +#define CommandFlicker 25
- static COMMAND_LIST cmdline_commands[] =
- {
- @@ -171,6 +184,7 @@ static COMMAND_LIST cmdline_commands[] =
- {CommandVideoStab, "-vstab", "vs", "Turn on video stabilisation", 0},
- {CommandEVComp, "-ev", "ev", "Set EV compensation - steps of 1/6 stop", 1},
- {CommandExposure, "-exposure", "ex", "Set exposure mode (see Notes)", 1},
- + {CommandFlicker, "-flicker", "fl", "Set flicker avoid mode (off, auto, 50hz, 60hz, max)", 1},
- {CommandAWB, "-awb", "awb","Set AWB mode (see Notes)", 1},
- {CommandImageFX, "-imxfx", "ifx","Set image effect (see Notes)", 1},
- {CommandColourFX, "-colfx", "cfx","Set colour effect (U:V)", 1},
- @@ -442,6 +456,22 @@ static MMAL_PARAM_EXPOSUREMODE_T exposure_mode_from_string(const char *str)
- }
- /**
- + * Convert string to the MMAL parameter for flicker avoid mode
- + * @param str Incoming string to match
- + * @return MMAL parameter matching the string, or the AUTO option if no match found
- + */
- +static MMAL_PARAM_FLICKERAVOID_T flicker_avoid_mode_from_string(const char *str)
- +{
- + int i = raspicli_map_xref(str, flicker_avoid_map, flicker_avoid_map_size);
- +
- + if( i != -1)
- + return (MMAL_PARAM_FLICKERAVOID_T)i;
- +
- + vcos_log_error("Unknown flicker avoid mode: %s", str);
- + return MMAL_PARAM_FLICKERAVOID_AUTO;
- +}
- +
- +/**
- * Convert string to the MMAL parameter for AWB mode
- * @param str Incoming string to match
- * @return MMAL parameter matching the string, or the AUTO option if no match found
- @@ -581,6 +611,11 @@ int raspicamcontrol_parse_cmdline(RASPICAM_CAMERA_PARAMETERS *params, const char
- params->exposureMode = exposure_mode_from_string(arg2);
- used = 2;
- break;
- +
- + case CommandFlicker : // flicker avoid mode - needs string
- + params->flickerAvoidMode = flicker_avoid_mode_from_string(arg2);
- + used = 2;
- + break;
- case CommandAWB : // AWB mode - needs single number parameter
- params->awbMode = awb_mode_from_string(arg2);
- @@ -783,6 +818,13 @@ void raspicamcontrol_display_help()
- {
- fprintf(stdout, ",%s", exposure_map[i].mode);
- }
- +
- + fprintf(stdout, "\n\nFlicker avoid mode options :\n%s", flicker_avoid_map[0].mode );
- +
- + for (i=1;i<flicker_avoid_map_size;i++)
- + {
- + fprintf(stdout, ",%s", flicker_avoid_map[i].mode);
- + }
- fprintf(stdout, "\n\nAWB mode options :\n%s", awb_map[0].mode );
- @@ -824,6 +866,7 @@ void raspicamcontrol_display_help()
- void raspicamcontrol_dump_parameters(const RASPICAM_CAMERA_PARAMETERS *params)
- {
- const char *exp_mode = raspicli_unmap_xref(params->exposureMode, exposure_map, exposure_map_size);
- + const char *fl_mode = raspicli_unmap_xref(params->flickerAvoidMode, flicker_avoid_map, flicker_avoid_map_size);
- const char *awb_mode = raspicli_unmap_xref(params->awbMode, awb_map, awb_map_size);
- const char *image_effect = raspicli_unmap_xref(params->imageEffect, imagefx_map, imagefx_map_size);
- const char *metering_mode = raspicli_unmap_xref(params->exposureMeterMode, metering_mode_map, metering_mode_map_size);
- @@ -831,6 +874,7 @@ void raspicamcontrol_dump_parameters(const RASPICAM_CAMERA_PARAMETERS *params)
- fprintf(stderr, "Sharpness %d, Contrast %d, Brightness %d\n", params->sharpness, params->contrast, params->brightness);
- fprintf(stderr, "Saturation %d, ISO %d, Video Stabilisation %s, Exposure compensation %d\n", params->saturation, params->ISO, params->videoStabilisation ? "Yes": "No", params->exposureCompensation);
- fprintf(stderr, "Exposure Mode '%s', AWB Mode '%s', Image Effect '%s'\n", exp_mode, awb_mode, image_effect);
- + fprintf(stderr, "Flicker Avoid Mode '%s'\n", fl_mode);
- 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);
- fprintf(stderr, "Rotation %d, hflip %s, vflip %s\n", params->rotation, params->hflip ? "Yes":"No",params->vflip ? "Yes":"No");
- fprintf(stderr, "ROI x %lf, y %f, w %f h %f\n", params->roi.x, params->roi.y, params->roi.w, params->roi.h);
- @@ -889,6 +933,7 @@ void raspicamcontrol_set_defaults(RASPICAM_CAMERA_PARAMETERS *params)
- params->videoStabilisation = 0;
- params->exposureCompensation = 0;
- params->exposureMode = MMAL_PARAM_EXPOSUREMODE_AUTO;
- + params->flickerAvoidMode = MMAL_PARAM_FLICKERAVOID_AUTO;
- params->exposureMeterMode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
- params->awbMode = MMAL_PARAM_AWBMODE_AUTO;
- params->imageEffect = MMAL_PARAM_IMAGEFX_NONE;
- @@ -937,6 +982,7 @@ int raspicamcontrol_get_all_parameters(MMAL_COMPONENT_T *camera, RASPICAM_CAMERA
- params->videoStabilisation = raspicamcontrol_get_video_stabilisation(camera);
- params->exposureCompensation = raspicamcontrol_get_exposure_compensation(camera);
- params->exposureMode = raspicamcontrol_get_exposure_mode(camera);
- + params->flickerAvoidMode = raspicamcontrol_get_flicker_avoid_mode(camera);
- params->awbMode = raspicamcontrol_get_awb_mode(camera);
- params->imageEffect = raspicamcontrol_get_image_effect(camera);
- params->colourEffects = raspicamcontrol_get_colour_effect(camera);
- @@ -963,6 +1009,7 @@ int raspicamcontrol_set_all_parameters(MMAL_COMPONENT_T *camera, const RASPICAM_
- result += raspicamcontrol_set_video_stabilisation(camera, params->videoStabilisation);
- result += raspicamcontrol_set_exposure_compensation(camera, params->exposureCompensation);
- result += raspicamcontrol_set_exposure_mode(camera, params->exposureMode);
- + result += raspicamcontrol_set_flicker_avoid_mode(camera, params->flickerAvoidMode);
- result += raspicamcontrol_set_metering_mode(camera, params->exposureMeterMode);
- result += raspicamcontrol_set_awb_mode(camera, params->awbMode);
- result += raspicamcontrol_set_awb_gains(camera, params->awb_gains_r, params->awb_gains_b);
- @@ -1186,6 +1233,29 @@ int raspicamcontrol_set_exposure_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_EXPOS
- /**
- + * Set flicker avoid mode for images
- + * @param camera Pointer to camera component
- + * @param mode Exposure mode to set from
- + * - MMAL_PARAM_FLICKERAVOID_OFF,
- + * - MMAL_PARAM_FLICKERAVOID_AUTO,
- + * - MMAL_PARAM_FLICKERAVOID_50HZ,
- + * - MMAL_PARAM_FLICKERAVOID_60HZ,
- + * - MMAL_PARAM_FLICKERAVOID_MAX,
- + *
- + * @return 0 if successful, non-zero if any parameters out of range
- + */
- +int raspicamcontrol_set_flicker_avoid_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_FLICKERAVOID_T mode)
- +{
- + MMAL_PARAMETER_FLICKERAVOID_T fl_mode = {{MMAL_PARAMETER_FLICKER_AVOID,sizeof(fl_mode)}, mode};
- +
- + if (!camera)
- + return 1;
- +
- + return mmal_status_to_int(mmal_port_parameter_set(camera->control, &fl_mode.hdr));
- +}
- +
- +
- +/**
- * Set the aWB (auto white balance) mode for images
- * @param camera Pointer to camera component
- * @param awb_mode Value to set from
- diff --git a/host_applications/linux/apps/raspicam/RaspiCamControl.h b/host_applications/linux/apps/raspicam/RaspiCamControl.h
- index 7ec4a96..f006a89 100644
- --- a/host_applications/linux/apps/raspicam/RaspiCamControl.h
- +++ b/host_applications/linux/apps/raspicam/RaspiCamControl.h
- @@ -46,6 +46,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
- MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
- *
- + * Flicker Avoid Mode
- + * MMAL_PARAM_FLICKERAVOID_OFF,
- + MMAL_PARAM_FLICKERAVOID_AUTO,
- + MMAL_PARAM_FLICKERAVOID_50HZ,
- + MMAL_PARAM_FLICKERAVOID_60HZ,
- + MMAL_PARAM_FLICKERAVOID_MAX,
- + *
- * AWB Mode
- * MMAL_PARAM_AWBMODE_OFF,
- MMAL_PARAM_AWBMODE_AUTO,
- @@ -142,6 +149,7 @@ typedef struct raspicam_camera_parameters_s
- MMAL_PARAM_IMAGEFX_T imageEffect;
- MMAL_PARAMETER_IMAGEFX_PARAMETERS_T imageEffectsParameters;
- MMAL_PARAM_COLOURFX_T colourEffects;
- + MMAL_PARAM_FLICKERAVOID_T flickerAvoidMode;
- int rotation; /// 0-359
- int hflip; /// 0 or 1
- int vflip; /// 0 or 1
- @@ -188,6 +196,7 @@ int raspicamcontrol_set_metering_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_EXPOS
- int raspicamcontrol_set_video_stabilisation(MMAL_COMPONENT_T *camera, int vstabilisation);
- int raspicamcontrol_set_exposure_compensation(MMAL_COMPONENT_T *camera, int exp_comp);
- int raspicamcontrol_set_exposure_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_EXPOSUREMODE_T mode);
- +int raspicamcontrol_set_flicker_avoid_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_FLICKERAVOID_T mode);
- int raspicamcontrol_set_awb_mode(MMAL_COMPONENT_T *camera, MMAL_PARAM_AWBMODE_T awb_mode);
- int raspicamcontrol_set_awb_gains(MMAL_COMPONENT_T *camera, float r_gain, float b_gain);
- int raspicamcontrol_set_imageFX(MMAL_COMPONENT_T *camera, MMAL_PARAM_IMAGEFX_T imageFX);
- @@ -214,9 +223,12 @@ int raspicamcontrol_get_video_stabilisation(MMAL_COMPONENT_T *camera);
- int raspicamcontrol_get_exposure_compensation(MMAL_COMPONENT_T *camera);
- MMAL_PARAM_THUMBNAIL_CONFIG_T raspicamcontrol_get_thumbnail_parameters(MMAL_COMPONENT_T *camera);
- MMAL_PARAM_EXPOSUREMODE_T raspicamcontrol_get_exposure_mode(MMAL_COMPONENT_T *camera);
- +MMAL_PARAM_FLICKERAVOID_T raspicamcontrol_get_flicker_avoid_mode(MMAL_COMPONENT_T *camera);
- MMAL_PARAM_AWBMODE_T raspicamcontrol_get_awb_mode(MMAL_COMPONENT_T *camera);
- MMAL_PARAM_IMAGEFX_T raspicamcontrol_get_imageFX(MMAL_COMPONENT_T *camera);
- MMAL_PARAM_COLOURFX_T raspicamcontrol_get_colourFX(MMAL_COMPONENT_T *camera);
- +
- +
- #endif /* RASPICAMCONTROL_H_ */
- diff --git a/host_applications/linux/apps/raspicam/RaspiVid.c b/host_applications/linux/apps/raspicam/RaspiVid.c
- index 9651976..e48eb69 100755
- --- a/host_applications/linux/apps/raspicam/RaspiVid.c
- +++ b/host_applications/linux/apps/raspicam/RaspiVid.c
- @@ -79,6 +79,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- #include "interface/mmal/util/mmal_util_params.h"
- #include "interface/mmal/util/mmal_default_components.h"
- #include "interface/mmal/util/mmal_connection.h"
- +#include "interface/mmal/mmal_parameters_camera.h"
- #include "RaspiCamControl.h"
- #include "RaspiPreview.h"
- @@ -257,6 +258,20 @@ static XREF_T level_map[] =
- static int level_map_size = sizeof(level_map) / sizeof(level_map[0]);
- +/// Structure to cross reference flicker avoid strings against the MMAL parameter equivalent
- +/// TODO: duplicates a structure from RaspiCamControl.c
- +static XREF_T flicker_avoid_map[] =
- +{
- + {"off", MMAL_PARAM_FLICKERAVOID_OFF},
- + {"auto", MMAL_PARAM_FLICKERAVOID_AUTO},
- + {"50hz", MMAL_PARAM_FLICKERAVOID_50HZ},
- + {"60hz", MMAL_PARAM_FLICKERAVOID_60HZ},
- + {"max", MMAL_PARAM_FLICKERAVOID_MAX}
- +};
- +
- +static const int flicker_avoid_map_size = sizeof(flicker_avoid_map) / sizeof(flicker_avoid_map[0]);
- +
- +
- static XREF_T initial_map[] =
- {
- {"record", 0},
- @@ -323,6 +338,7 @@ static void display_valid_parameters(char *app_name);
- #define CommandRaw 32
- #define CommandRawFormat 33
- #define CommandNetListen 34
- +#define CommandFlickerAvoid 35
- static COMMAND_LIST cmdline_commands[] =
- {
- @@ -338,6 +354,7 @@ static COMMAND_LIST cmdline_commands[] =
- { CommandTimeout, "-timeout", "t", "Time (in ms) to capture for. If not specified, set to 5s. Zero to disable", 1 },
- { CommandDemoMode, "-demo", "d", "Run a demo mode (cycle through range of camera options, no capture)", 1},
- { CommandFramerate, "-framerate", "fps","Specify the frames per second to record", 1},
- + { CommandFlickerAvoid, "-flicker", "fl", "Select flicker avoid mode (off, auto, 50hz, 60hz, max). Default: auto", 0},
- { CommandPreviewEnc, "-penc", "e", "Display preview image *after* encoding (shows compression artifacts)", 0},
- { 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},
- { CommandProfile, "-profile", "pf", "Specify H264 profile to use for encoding", 1},
- @@ -633,7 +650,18 @@ static int parse_cmdline(int argc, const char **argv, RASPIVID_STATE *state)
- valid = 0;
- break;
- }
- +
- + case CommandFlickerAvoid: // flicker avoid mode
- + {
- + state->camera_parameters.flickerAvoidMode = raspicli_map_xref(argv[i + 1], flicker_avoid_map, flicker_avoid_map_size);
- + if( state->camera_parameters.flickerAvoidMode == -1)
- + state->camera_parameters.flickerAvoidMode = MMAL_PARAM_FLICKERAVOID_AUTO;
- +
- + i++;
- + break;
- + }
- +
- case CommandPreviewEnc:
- state->immutableInput = 0;
- break;
- @@ -1767,6 +1795,7 @@ static MMAL_STATUS_T create_camera_component(RASPIVID_STATE *state)
- goto error;
- }
- + // Note: this sets lots of parameters that were not individually addressed before.
- raspicamcontrol_set_all_parameters(camera, &state->camera_parameters);
- state->camera_component = camera;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement