--------------------------------------------------------------------------------
How to use the Camera API
To use the Camera API, to capture a still image for example, a client application must have the UserEnvironment capability listed in its .mmp project file. It can then call the CCamera::NewL() function to get a CCamera object. The application can then call the CCamera functions on the CCamera object to specify, for example zoom, flash or contrast and to capture an image. The application must supply an MCameraObserver-derived object to receive callbacks when, for instance, an image is ready. If the UserEnvironment security capability is absent CCamera::NewL() will leave with KErrPermissionDenied.
Camera control
Once a client application has obtained a camera object, to actually use the camera the application must call the CCamera::Reserve() function, then CCamera::PowerOn(). The client is informed that power on is complete by MCameraObserver::PowerOnComplete().
No other client can use the camera once CCamera::Reserve() has been called successfully. If another client wishes to use the camera, it must call the CCamera::NewDuplicateL() factory function. Note that this function can be called only with the handle of an existing camera object. This allows, for example, a video conferencing application to have a camera object open for control of its functions and for the multimedia system to have another camera object open for reading frames of data.
The client application can now specify the image format and then capture still / video images or use the view finder.
Specifying image format
Before a client application captures still, or video, images it can first specify the required image format. There may be complicated dependencies between frame sizes and formats, so the required format must be specified as follows:
Select the format from those available from either the TCameraInfo::iImageFrameFormatsSupported or TCameraInfo::iVideoFrameFormatsSupported bitfield for still or video images respectively.
Select the required size using either CCamera::EnumerateCaptureSizes() or CCamera::EnumerateVideoFrameSizes() for still or video images respectively. Note that not all possible sizes are guaranteed to be supported for any given format. Unsupported sizes will be returned as (0,0).
For video capture, select the frame rate using CCamera::EnumerateVideoFrameRates(). Again, not all rates are guaranteed to be supported if dependencies exist in the device between the format, size, exposure mode and rate. Unsupported rates are returned as 0.
--------------------------------------------------------------------------------
Capturing still images
Still image capture involves transferring the current image from the camera to the client via MCameraObserver::ImageReady().
A client calls CCamera::PrepareImageCaptureL() to set image format, size and clipping rectangle. This must be called at least once before requesting images to allow the camera device to allocate any resources necessary for capturing images. The client then calls CCamera::CaptureImage() to capture an image which MCameraObserver::ImageReady() returns. Any errors that occur during image capture are also returned to the client, in which case no valid image data is returned.
Capturing video images
Video capture involves the following:
Before video can be captured, a client calls the CCamera::PrepareVideoCaptureL() function to initialise the required resources. This function enables the client application to set the number of buffers to use and the number of frames per buffer. Buffers are then filled as frames become available. Once a buffer has been filled it is passed to the client via MCameraObserver::FrameBufferReady(). Once the data has been used the buffer should be released by calling the MFrameBuffer::Release() function.
If an error occurs during video capture, the client is notified through MCameraObserver::FrameBufferReady() in which case no valid frame data is returned. If the error is fatal to the process of capturing video, such as the camera being switched off, then video capture stops and outstanding buffers are deleted by the camera object.
If the available number of frame buffers is exceeded, there are no further callbacks until the client application calls MFrameBuffer::Release(). After this, MCameraObserver::FrameBufferReady() will be called again with the MFrameBuffer::iIndexOfFirstFrameInBuffer member set to reflect the current frame. This allows the client to calculate the number of frames dropped if they recorded the previous buffer's value of MFrameBuffer::iIndexOfFirstFrameInBuffer.
Using a view finder
The view finder can, if supported, transfer frames from the camera directly to the display memory at a location of the client's choosing. Alternatively, if supported, the user may implement a view finder function themselves using a bitmap-based alternative.
A client calls the following functions as required:
CCamera::StartViewFinderDirectL() to transfer view finder data to a specified portion of the screen using direct screen access.
CCamera::StartViewFinderBitmapsL() to transfer view finder data as a bitmap.
CCamera::SetViewFinderMirrorL() to specify view finder mirroring on or off. Mirroring flips the image horizontally so that the user can use the device as a virtual mirror.
CCamera::StopViewFinder() to stop transfer of view finder data to the screen.
--------------------------------------------------------------------------------
See also
Introduction to the Onboard Camera API
How to implement the Camera API