Start viewfinder and configure camera settings

After you set the viewfinder mode for you camera, you can start using the imaging datapath, which we refer to as image buffers.

You can choose whether you want to start the camera with the default configuration settings available on the camera after calling camera_set_vf_mode() or you want to configure certain settings before you call camera_start_viewfinder(). It's important to note that there are some manual settings that can't be set until after you call camera_start_viewfinder(). These manual settings, such as contrast or brightness, give more granular control over certain camera settings that aren't possible until the image datapath has started.

Depending on your application, you might want to set up default configuration settings for the viewfinder window before you call camera_start_viewfinder(), such as the rotation of viewfinder, framerates, width, or height. These preconfigured settings are used to help ensure that the video shown is acceptable. For that reason, you should set the specific viewfinder window settings that are optimal under most situations before the image buffers are created. Experimentation is often necessary to determine the appropriate settings for your camera under different conditions. For information about how to set viewfinder window attributes, see Modify viewfinder window attributes.” Note that there are also manual settings, such as ISO and aperture that you can modify. For more information which can help to improve the video, see the Settings on the Camera chapter in this guide.

If you modify the configuration settings after you start the viewfinder, there's a slight delay before the changes get applied to the image buffers from the camera. For example, you can start the viewfinder, show the image buffers from the camera on a display, and then provide settings for the user to adjust them in your application.

When you start the imaging datapath using camera_start_viewfinder(), you can optionally pass these arguments to have read-only access to the image buffers:
Note: If you want to read/write access, you must use event mode. For more information, see about using events, see Using event mode.”
If you don't need to handle when the image buffer first becomes available or status messages, you can set the argument to NULL. For more information about using callbacks, see Using callback mode.”
Here's code snippet of how to use callbacks when you call camera_start_viewfinder():
...
...
void statusCallback(camera_handle_t handle, camera_devstatus_t devstatus, uint16_t extra, void *arg)
{
                // You would normally handle asynchronous events here, but for this example do nothing
                printf("Message:%s", (char*)arg);
}
...
...
int main()
{
camera_handle_t cameraHandle;
camera_set_vf_mode(cameraHandle, CAMERA_VFMODE_VIDEO);
camera_open(CAMERA_UNIT_1, CAMERA_MODE_RW | CAMERA_MODE_ROLL, &cameraHandle);
...
...
//Start the viewfinder
char mymessage[6]="hello\n";
err=camera_start_viewfinder(cameraHandle, NULL, statusCallback, (void*)&mymessage;);

}
...
...        

Modify viewfinder window attributes

Some viewfinder window attributes should be called before you call camera_start_viewfinder() to start the imaging datapath. These settings are usually configured using camera_set_vf_property(). You can retrieve the currently set values using the camera_get_vf_property() and supported values using the camera_get_supported_*() functions. For example, if you wanted to get the supported framerates available for the camera, you call camera_get_supported_vf_framerates(). For example, here's a snippet of how to get the current framerate, retrieve the supported framerates from the camera, and then set the framerate to one of the supported framerates:
...camera_frametype_t format;
double* supportedFrametypes;
double framerate;
int err=0;
...
camera_get_vf_property(cameraHandle,
                       CAMERA_IMGPROP_FRAMERATE, &framerate);
...
printf("The current framerate is %d a\n",  framerate):

//Get three  supported rates for illustrative purposes
supportedFramerates = (double*) malloc(sizeof(double) * 3);
err = camera_get_supported_vf_framerates(handle, format, numSupported, &numSupported, supportedFramerates, &maxMin);

if (err != EOK) {
    printf("Failed to get list of supported framerates: err = %d\n", err);
    free(supportedFramerates);
    return err;
}
//Set the framerate to the first framerate that was retrieved in the array
err = camera_set_vf_property(cameraHandle,
                             CAMERA_IMGPROP_FRAMERATE, supportedFramerates[0]);
if (err != EOK) {
    printf("Failed to set vf properties: err = %d\n", err);
    return err;
} 

Modify image attributes

In addition to the viewfinder windows attributes, you can modify the image attributes, such as contrast, brightness, and hue. These settings can be set before or after you start the viewfinder.

First you should call camera_get_supported_contrast() to determine the contrast settings that are available on the camera. Then using the available contrast settings, call the then call camera_set_contrast() to change the contrast settings before you call start the viewfinder. Changes that are made for image attributes are set immediately.
...
// Connect to the camera and set the viewfinder mode
camera_open(CAMERA_UNIT_1, CAMERA_MODE_RW | CAMERA_MODE_ROLL, &cameraHandle);
camera_set_vf_mode(cameraHandle, CAMERA_VFMODE_VIDEO);

//Call the function with the numask parameter set to zero to get the number of
//supported contrast modes available on the camera
camera_get_supported_contrast(handle, 0, &numSupported, NULL, &maxMin);

//Allocate an array based on the number of supported contrast modes
//The number of modes is put into the numSupported variable.
supportedValues = (int32_t*) malloc(sizeof(int32_t) * numSupported);

//Call function again to get the number supported modes
camera_get_supported_contrast(handle, numSupported, &numSupported, supportedValues, &maxMin);

//Do something to let the user choose
 printf("Select which of the following contrast values you want to use:\n");
 for (i = 0; i < numSupported; i++) {
      printf("\t%d) %d\n", i + 1, supportedValues[i]);
}
fgets(userString, sizeof(userString), stdin);
userValue = atoi(userString);
//Because we added one to present the options to the user.
contrast = supportedValues[userValue - 1];
 
//Clean up memory allocated
free(supportedValues);
camera_set_contrast(camerahandle, contrast);

//Now start the viewfinder
camera_start_viewfinder(camerahandle, NULL, NULL, NULL);
...
...