The first thing you must do to use the Camera library is to connect to the camera.
To connect to the camera, you use camera_open(), which returns a reference to a camera_handle_t handle. When your application successfully connects and if you receive a valid handle from the Camera API, it confirms that your application can access the specified camera with the requested access mode. Each application can have multiple camera handles open to multiple cameras — up to 16 camera handles open per application. The cameras that are available to the Sensor service are configured in the sensor configuration file. For more information about configuring the sensor configuration file and the Sensor service, see the Sensor chapter in the System Services guide.
You can specify the access using one or more Camera access mode flags flags, which are OR'ed together.
In general, the flags control permissions to the camera and the image buffers, however, CAMERA_MODE_ROLL gives you access to the camera roll. The camera roll is the default directory where the Sensor service puts video files, which is required when you record video. This directory to use as the camera roll is specified using the -r option when you start the Sensor service. For more information about the camera roll, see Understanding the camera roll.
When camera_open() returns successfully (CAMERA_EOK), a valid handle is returned. You must use this handle to make other Camera API calls to the specified camera. Since you have the camera open (connected to it), you must call camera_close() whenever an error occurs when you make Camera API calls. For more information about closing the camera, see Stop viewfinder and close camera.
... ... camera_unit_t unit; camera_unit_t *supportedCameras; uint32_t numSupported; camera_handle_t cameraHandle; // Get how many cameras are supported, which is returned in the reference // to numSupported. if (camera_get_supported_cameras(0, &numSupported, NULL) != CAMERA_EOK){ printf("Failed to get the number of supported cameras\n"); } // Allocate an array big enough to hold unit of all cameras supportedCameras = (camera_unit_t*) malloc(sizeof(camera_unit_t) * numSupported); // Get the list of supported cameras by calling the // camera_get_supported_cameras() again. if (camera_get_supported_cameras(numSupported, &numSupported, supportedCameras) != CAMERA_EOK ){ printf("Failed to get a list of supported cameras\n"); free(supportedCameras); } // We'll just use the first camera that we get. If there are more, we'll ignore it for now printf("assigning to unit\n"); unit = supportedCameras[0]; free(supportedCameras); printf("The number of cameras connected to the system: %d \n. Assigning to camera unit #%d\n", numSupported ,unit); if (camera_open(unit, CAMERA_MODE_RW | CAMERA_MODE_ROLL, &cameraHandle) != CAMERA_EOK) { printf("Failed to connect to the camera\n"); } else { printf("We got a valid camera handle\n"); } ... ...
// Get how many cameras are supported err = camera_get_supported_cameras(0, &numSupported, NULL); if (err != CAMERA_EOK) { printf("Failed to get number of supported cameras: err = %d\n", err); return err; } // Allocate an array big enough to hold unit of all cameras supportedCameras = (camera_unit_t*) malloc(sizeof(camera_unit_t) * numSupported); if (supportedCameras == NULL) { printf("Failed to allocate memory for supported cameras\n"); return ENOMEM; } // Get the list of supported cameras err = camera_get_supported_cameras(numSupported, &numSupported, supportedCameras); if (err != CAMERA_EOK) { printf("Failed to get list of supported cameras: err = %d\n", err); free(supportedCameras); return err; }