Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef ANDROID_CAMERA_CAMERA_CAPTURE_H
     18 #define ANDROID_CAMERA_CAMERA_CAPTURE_H
     19 
     20 /*
     21  * Contains declarations for video capturing API that is used by the camera
     22  * emulator.
     23  */
     24 
     25 #include "camera-common.h"
     26 
     27 /* Initializes camera device descriptor, and connects to the camera device.
     28  * Param:
     29  *  name - On Linux contains name of the device to be used to capture video.
     30  *    On Windows contains name to assign to the capturing window. This parameter
     31  *    can be NULL, in which case '/dev/video0' will be used as device name on
     32  *    Linux, or 'AndroidEmulatorVC' on Windows.
     33  *  inp_channel - On Linux defines input channel to use when communicating with
     34  *    the camera driver. On Windows contains an index (up to 10) of the driver
     35  *    to use to communicate with the camera device.
     36  * Return:
     37  *  Initialized camera device descriptor on success, or NULL on failure.
     38  */
     39 extern CameraDevice* camera_device_open(const char* name, int inp_channel);
     40 
     41 /* Starts capturing frames from the camera device.
     42  * Param:
     43  *  cd - Camera descriptor representing a camera device opened in
     44  *    camera_device_open routine.
     45  *  pixel_format - Defines pixel format for the captured frames. Must be one of
     46  *      the formats, supported by the camera device.
     47  *  width, height - Frame dimensions for the captured video frame. Must match
     48  *      dimensions supported by the camera for the pixel format defined by the
     49  *      'pixel_format' parameter.
     50  * Return:
     51  *  0 on success, or non-zero value on failure.
     52  */
     53 extern int camera_device_start_capturing(CameraDevice* cd,
     54                                          uint32_t pixel_format,
     55                                          int frame_width,
     56                                          int frame_height);
     57 
     58 /* Stops capturing frames from the camera device.
     59  * Param:
     60  *  cd - Camera descriptor representing a camera device opened in
     61  *    camera_device_open routine.
     62  * Return:
     63  *  0 on success, or non-zero value on failure.
     64  */
     65 extern int camera_device_stop_capturing(CameraDevice* cd);
     66 
     67 /* Captures a frame from the camera device.
     68  * Param:
     69  *  cd - Camera descriptor representing a camera device opened in
     70  *    camera_device_open routine.
     71  *  framebuffers - Array of framebuffers where to read the frame. Size of this
     72  *      array is defined by the 'fbs_num' parameter. Note that the caller must
     73  *      make sure that buffers are large enough to contain entire frame captured
     74  *      from the device.
     75  *  fbs_num - Number of entries in the 'framebuffers' array.
     76  * Return:
     77  *  0 on success, or non-zero value on failure. There is a special vaule 1
     78  *  returned from this routine which indicates that frames were not available in
     79  *  the device. This value is returned on Linux implementation when frame ioctl
     80  *  has returned EAGAIN error. The client should respond to this value by
     81  *  repeating the read, rather than reporting an error.
     82  */
     83 extern int camera_device_read_frame(CameraDevice* cd,
     84                                     ClientFrameBuffer* framebuffers,
     85                                     int fbs_num);
     86 
     87 /* Closes camera device, opened in camera_device_open routine.
     88  * Param:
     89  *  cd - Camera descriptor representing a camera device opened in
     90  *    camera_device_open routine.
     91  */
     92 extern void camera_device_close(CameraDevice* cd);
     93 
     94 /* Enumerates camera devices connected to the host, and collects information
     95  * about each device.
     96  * Apparently, camera framework in the guest will only accept the the YV12
     97  * (V4L2_PIX_FMT_YVU420) pixel format. So, we don't really need to report all the
     98  * pixel formats, supported by the camera device back to the guest. We can simpy
     99  * pick any format that is supported by the device, and collect frame dimensions
    100  * available for it. The only thing we can do is to specifically check, if camera
    101  * support YV12, and choose it, in order to spare some CPU cycles on the
    102  * conversion.
    103  * Param:
    104  *  cis - An allocated array where to store informaion about found camera
    105  *      devices. For each found camera device an entry will be initialized in the
    106  *      array. It's responsibility of the caller to free the memory allocated for
    107  *      the entries.
    108  *  max - Maximum number of entries that can fit into the array.
    109  * Return:
    110  *  Number of entries added to the 'cis' array on success, or < 0 on failure.
    111  */
    112 extern int enumerate_camera_devices(CameraInfo* cis, int max);
    113 
    114 #endif  /* ANDROID_CAMERA_CAMERA_CAPTURE_H */
    115