| 1 | /* |
| 2 | * Copyright (C) 2013 Canonical Ltd |
| 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 | * Authored by: Thomas Voss <thomas.voss@canonical.com> |
| 17 | */ |
| 18 | |
| 19 | #ifndef CAMERA_COMPATIBILITY_LAYER_H_ |
| 20 | #define CAMERA_COMPATIBILITY_LAYER_H_ |
| 21 | |
| 22 | #include <stdint.h> |
| 23 | #include <unistd.h> |
| 24 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| 29 | // Forward declarations |
| 30 | struct SfSurface; |
| 31 | |
| 32 | typedef enum |
| 33 | { |
| 34 | // This camera has higher quality and features like high resolution and flash |
| 35 | BACK_FACING_CAMERA_TYPE, |
| 36 | // The camera that is on the same side as the touch display. Usually used for video calls |
| 37 | FRONT_FACING_CAMERA_TYPE |
| 38 | } CameraType; |
| 39 | |
| 40 | struct CameraControl; |
| 41 | |
| 42 | typedef void (*on_msg_error)(void* context); |
| 43 | typedef void (*on_msg_shutter)(void* context); |
| 44 | typedef void (*on_msg_focus)(void* context); |
| 45 | typedef void (*on_msg_zoom)(void* context, int32_t new_zoom_level); |
| 46 | |
| 47 | typedef void (*on_data_raw_image)(void* data, uint32_t data_size, void* context); |
| 48 | typedef void (*on_data_compressed_image)(void* data, uint32_t data_size, void* context); |
| 49 | typedef void (*on_preview_texture_needs_update)(void* context); |
| 50 | |
| 51 | struct CameraControlListener |
| 52 | { |
| 53 | // Called whenever an error occurs while the camera HAL executes a command |
| 54 | on_msg_error on_msg_error_cb; |
| 55 | // Called while taking a picture when the shutter has been triggered |
| 56 | on_msg_shutter on_msg_shutter_cb; |
| 57 | // Called while focusing |
| 58 | on_msg_focus on_msg_focus_cb; |
| 59 | // Called while zooming |
| 60 | on_msg_zoom on_msg_zoom_cb; |
| 61 | |
| 62 | // Raw image data (Bayer pattern) is reported over this callback |
| 63 | on_data_raw_image on_data_raw_image_cb; |
| 64 | // JPEG-compressed image is reported over this callback |
| 65 | on_data_compressed_image on_data_compressed_image_cb; |
| 66 | |
| 67 | // If a texture has been set as a destination for preview frames, |
| 68 | // this callback is invoked whenever a new buffer from the camera is available |
| 69 | // and needs to be uploaded to the texture by means of calling |
| 70 | // android_camera_update_preview_texture. Please note that this callback can |
| 71 | // be invoked on any thread, and android_camera_update_preview_texture must only |
| 72 | // be called on the thread that setup the EGL/GL context. |
| 73 | on_preview_texture_needs_update on_preview_texture_needs_update_cb; |
| 74 | |
| 75 | void* context; |
| 76 | }; |
| 77 | |
| 78 | // Initializes a connection to the camera, returns NULL on error. |
| 79 | struct CameraControl* android_camera_connect_to(CameraType camera_type, struct CameraControlListener* listener); |
| 80 | |
| 81 | // Disconnects the camera and deletes the pointer |
| 82 | void android_camera_disconnect(struct CameraControl* control); |
| 83 | |
| 84 | int android_camera_lock(struct CameraControl* control); |
| 85 | int android_camera_unlock(struct CameraControl* control); |
| 86 | |
| 87 | // Deletes the CameraControl |
| 88 | void android_camera_delete(struct CameraControl* control); |
| 89 | |
| 90 | // Passes the rotation r of the display in [°] relative to the camera to the camera HAL. r \in [0, 359]. |
| 91 | void android_camera_set_display_orientation(struct CameraControl* control, int32_t clockwise_rotation_degree); |
| 92 | |
| 93 | // Prepares the camera HAL to display preview images to the |
| 94 | // supplied surface/texture in a H/W-acclerated way. New frames |
| 95 | // are reported via the |
| 96 | // 'on_preview_texture_needs_update'-callback, and clients of this |
| 97 | // API should invoke android_camera_update_preview_texture |
| 98 | // subsequently. Please note that the texture is bound automatically by the underlying |
| 99 | // implementation. |
| 100 | void android_camera_set_preview_texture(struct CameraControl* control, int texture_id); |
| 101 | |
| 102 | // Reads out the transformation matrix that needs to be applied when displaying the texture |
| 103 | void android_camera_get_preview_texture_transformation(struct CameraControl* control, float m[16]); |
| 104 | |
| 105 | // Updates the texture to the last received frame and binds the texture |
| 106 | void android_camera_update_preview_texture(struct CameraControl* control); |
| 107 | |
| 108 | // Prepares the camera HAL to display preview images to the supplied surface/texture in a H/W-acclerated way. |
| 109 | void android_camera_set_preview_surface(struct CameraControl* control, struct SfSurface* surface); |
| 110 | |
| 111 | // Starts the camera preview |
| 112 | void android_camera_start_preview(struct CameraControl* control); |
| 113 | |
| 114 | // Stops the camera preview |
| 115 | void android_camera_stop_preview(struct CameraControl* control); |
| 116 | |
| 117 | // Starts an autofocus operation of the camera, results are reported via callback. |
| 118 | void android_camera_start_autofocus(struct CameraControl* control); |
| 119 | |
| 120 | // Stops an ongoing autofocus operation. |
| 121 | void android_camera_stop_autofocus(struct CameraControl* control); |
| 122 | |
| 123 | // Starts a zooming operation, zoom values are absolute, valid values [1, \infty]. |
| 124 | void android_camera_start_zoom(struct CameraControl* control, int32_t zoom); |
| 125 | |
| 126 | // Stops an ongoing zoom operation. |
| 127 | void android_camera_stop_zoom(struct CameraControl* control); |
| 128 | |
| 129 | // Adjust the zoom level immediately as opposed to smoothly zoomin gin. |
| 130 | void android_camera_set_zoom(struct CameraControl* control, int32_t zoom); |
| 131 | |
| 132 | // Takes a picture and reports back image data via |
| 133 | // callback. Please note that this stops the preview and thus, the |
| 134 | // preview needs to be restarted after the picture operation has |
| 135 | // completed. Ideally, this is done from the raw data callback. |
| 136 | void android_camera_take_snapshot(struct CameraControl* control); |
| 137 | |
| 138 | #ifdef __cplusplus |
| 139 | } |
| 140 | #endif |
| 141 | |
| 142 | #endif // CAMERA_COMPATIBILITY_LAYER_H_ |