blob: 24ff20ca627614e835bea2f115bbeaed68e65ded [file] [log] [blame]
Chih-Wei Huang0d92eda2012-02-07 16:55:49 +08001/*
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 HW_CAMERA_CAMERA_FACTORY_H
18#define HW_CAMERA_CAMERA_FACTORY_H
19
20#include <string.h>
21#include <hardware/hardware.h>
22#include <hardware/camera.h>
23#include "CameraHardware.h"
24
25namespace android {
26
27/*
28 * Contains declaration of a class CameraFactory that manages cameras
29 * available for the emulation. A global instance of this class is statically
30 * instantiated and initialized when camera emulation HAL is loaded.
31 */
32
33/* Class CameraFactoryManages cameras available.
34 *
35 * When the global static instance of this class is created on the module load,
36 * it enumerates cameras available for the emulation by connecting to the
37 * emulator's 'camera' service. For every camera found out there it creates an
38 * instance of an appropriate class, and stores it an in array of emulated
39 * cameras. In addition to the cameras reported by the emulator, a fake camera
40 * emulator is always created, so there is always at least one camera that is
41 * available.
42 *
43 * Instance of this class is also used as the entry point for the camera HAL API,
44 * including:
45 * - hw_module_methods_t::open entry point
46 * - camera_module_t::get_number_of_cameras entry point
47 * - camera_module_t::get_camera_info entry point
48 *
49 */
50class CameraFactory {
51public:
52 /* Constructs CameraFactory instance.
53 * In this constructor the factory will create and initialize a list of
54 * emulated cameras. All errors that occur on this constructor are reported
55 * via mConstructedOK data member of this class.
56 */
57 CameraFactory();
58
59 /* Destructs CameraFactory instance. */
60 ~CameraFactory();
61
62 /****************************************************************************
63 * Camera HAL API handlers.
64 ***************************************************************************/
65
66public:
67 /* Opens (connects to) a camera device.
68 * This method is called in response to hw_module_methods_t::open callback.
69 */
70 int cameraDeviceOpen(const hw_module_t* module,int camera_id, hw_device_t** device);
71
72 /* Gets emulated camera information.
73 * This method is called in response to camera_module_t::get_camera_info callback.
74 */
Andres Rodriguez937775c2012-04-19 23:38:00 +080075 int getCameraInfo(int camera_id, struct camera_info *info);
Chih-Wei Huang0d92eda2012-02-07 16:55:49 +080076
77 /* Returns the number of available cameras */
Andres Rodriguez937775c2012-04-19 23:38:00 +080078 int getCameraNum();
Chih-Wei Huang0d92eda2012-02-07 16:55:49 +080079
80 /****************************************************************************
81 * Camera HAL API callbacks.
82 ***************************************************************************/
83
84public:
85 /* camera_module_t::get_number_of_cameras callback entry point. */
86 static int get_number_of_cameras(void);
87
88 /* camera_module_t::get_camera_info callback entry point. */
89 static int get_camera_info(int camera_id, struct camera_info *info);
90
91private:
92 /* hw_module_methods_t::open callback entry point. */
93 static int device_open(const hw_module_t* module,
94 const char* name,
95 hw_device_t** device);
96
Andres Rodriguez937775c2012-04-19 23:38:00 +080097 void parseConfig(const char* configFile);
Alberto Panizzobbbfb372013-07-06 18:23:53 +020098 void newCameraConfig(int facing, const char* location, int orientation);
Andres Rodriguez937775c2012-04-19 23:38:00 +080099
Chih-Wei Huang0d92eda2012-02-07 16:55:49 +0800100private:
101
102 /* Camera hardware */
Andres Rodriguez937775c2012-04-19 23:38:00 +0800103 CameraHardware** mCamera;
104 char** mCameraDevices;
Alberto Panizzobbbfb372013-07-06 18:23:53 +0200105 int* mCameraFacing;
Andres Rodriguez937775c2012-04-19 23:38:00 +0800106 int* mCameraOrientation;
107 int mCameraNum;
Chih-Wei Huang0d92eda2012-02-07 16:55:49 +0800108
109public:
110 /* Contains device open entry point, as required by HAL API. */
111 static struct hw_module_methods_t mCameraModuleMethods;
112};
113
114}; /* namespace android */
115
116/* References the global CameraFactory instance. */
117extern android::CameraFactory gCameraFactory;
118
119#endif /* HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H */