1 /*
2  * Copyright (C) 2017 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_EMULATOR_CAMERA_EMULATED_FAKE_CAMERA_ROTATE_DEVICE_H
18 #define HW_EMULATOR_CAMERA_EMULATED_FAKE_CAMERA_ROTATE_DEVICE_H
19 
20 /*
21  * Contains declaration of a class EmulatedFakeRotatingCameraDevice that encapsulates
22  * a fake camera device.
23  */
24 
25 #include "Converters.h"
26 #include "EmulatedCameraDevice.h"
27 
28 #include <EGL/egl.h>
29 #include <GLES/gl.h>
30 #include <GLES/glext.h>
31 
32 namespace android {
33 
34 class EmulatedFakeCamera;
35 
36 /* Encapsulates a fake camera device.
37  * Fake camera device emulates a camera device by providing frames containing
38  * an image rendered by opengl, that takes rotating input from host
39  */
40 class EmulatedFakeRotatingCameraDevice : public EmulatedCameraDevice {
41 public:
42     /* Constructs EmulatedFakeRotatingCameraDevice instance. */
43     explicit EmulatedFakeRotatingCameraDevice(EmulatedFakeCamera* camera_hal);
44 
45     /* Destructs EmulatedFakeRotatingCameraDevice instance. */
46     ~EmulatedFakeRotatingCameraDevice();
47 
48     /***************************************************************************
49      * Emulated camera device abstract interface implementation.
50      * See declarations of these methods in EmulatedCameraDevice class for
51      * information on each of these methods.
52      **************************************************************************/
53 
54 public:
55     /* Connects to the camera device.
56      * Since there is no real device to connect to, this method does nothing,
57      * but changes the state.
58      */
59     status_t connectDevice();
60 
61     /* Disconnects from the camera device.
62      * Since there is no real device to disconnect from, this method does
63      * nothing, but changes the state.
64      */
65     status_t disconnectDevice();
66 
67     /* Starts the camera device. */
68     status_t startDevice(int width, int height, uint32_t pix_fmt);
69 
70     /* Stops the camera device. */
71     status_t stopDevice();
72 
73 
74 protected:
75     /* Implementation of the frame production routine. */
76     bool produceFrame(void* buffer, int64_t* timestamp) override;
77 
78     /****************************************************************************
79      * Fake camera device private API
80      ***************************************************************************/
81 
82 private:
83 
84     void fillBuffer(void* buffer);
85     void render(int width, int height);
86     int init_gl_surface(int width, int height);
87     void get_eye_x_y_z(float* x, float* y, float*z);
88     void get_yawing(float* x, float* y, float*z);
89     void read_rotation_vector(double *yaw, double* pitch, double* roll);
90     void read_sensor();
91     void init_sensor();
92     void free_gl_surface(void);
93     void update_scene(float width, float height);
94     void create_texture_dotx(int width, int height);
95 
96     bool mOpenglReady = false;
97     EGLDisplay mEglDisplay;
98     EGLSurface mEglSurface;
99     EGLContext mEglContext;
100     GLuint mTexture;
101     uint8_t* mPixelBuf;// = new uint8_t[width * height * kGlBytesPerPixel];;
102     int mSensorPipe = -1;
103     enum SENSOR_VALUE_TYPE {
104         SENSOR_VALUE_ACCEL_X=0,
105         SENSOR_VALUE_ACCEL_Y=1,
106         SENSOR_VALUE_ACCEL_Z=2,
107         SENSOR_VALUE_MAGNETIC_X=3,
108         SENSOR_VALUE_MAGNETIC_Y=4,
109         SENSOR_VALUE_MAGNETIC_Z=5,
110         SENSOR_VALUE_ROTATION_X=6,
111         SENSOR_VALUE_ROTATION_Y=7,
112         SENSOR_VALUE_ROTATION_Z=8,
113     };
114 
115     float mSensorValues[9] = {0};
116 
117 };
118 
119 }; /* namespace android */
120 
121 #endif  /* HW_EMULATOR_CAMERA_EMULATED_FAKE_CAMERA_ROTATE_DEVICE_H */
122