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 /* Encapsulates a fake camera device. 35 * Fake camera device emulates a camera device by providing frames containing 36 * an image rendered by opengl, that takes rotating input from host 37 */ 38 class EmulatedFakeRotatingCameraDevice { 39 public: 40 explicit EmulatedFakeRotatingCameraDevice(); 41 42 /* Destructs EmulatedFakeRotatingCameraDevice instance. */ 43 ~EmulatedFakeRotatingCameraDevice(); 44 45 /*************************************************************************** 46 * Emulated camera device abstract interface implementation. 47 * See declarations of these methods in EmulatedCameraDevice class for 48 * information on each of these methods. 49 **************************************************************************/ 50 51 public: 52 /* Connects to the camera device. 53 * Since there is no real device to connect to, this method does nothing, 54 * but changes the state. 55 */ 56 status_t connectDevice(); 57 58 /* Disconnects from the camera device. 59 * Since there is no real device to disconnect from, this method does 60 * nothing, but changes the state. 61 */ 62 status_t disconnectDevice(); 63 64 /* Starts the camera device. */ 65 status_t startDevice(int width, int height, uint32_t pix_fmt); 66 67 /* Stops the camera device. */ 68 status_t stopDevice(); 69 70 71 /* Implementation of the frame production routine. */ 72 bool produceFrame(void* buffer, int64_t* timestamp); 73 74 /**************************************************************************** 75 * Fake camera device private API 76 ***************************************************************************/ 77 private: 78 79 enum EmulatedCameraDeviceState { 80 ECDS_INVALID, 81 /* Object has been constructed. */ 82 ECDS_CONSTRUCTED, 83 /* Object has been initialized. */ 84 ECDS_INITIALIZED, 85 /* Object has been connected to the physical device. */ 86 ECDS_CONNECTED, 87 /* Camera device has been started. */ 88 ECDS_STARTED, 89 }; 90 91 /* Object state. */ 92 EmulatedCameraDeviceState mState; 93 isInitialized()94 inline bool isInitialized() const { 95 return mState != ECDS_CONSTRUCTED; 96 } isConnected()97 inline bool isConnected() const { 98 /* Instance is connected when its status is either"connected", or 99 * "started". */ 100 return mState == ECDS_CONNECTED || mState == ECDS_STARTED; 101 } isStarted()102 inline bool isStarted() const { 103 return mState == ECDS_STARTED; 104 } 105 106 107 Mutex mObjectLock; 108 /* Frame width */ 109 int mFrameWidth; 110 111 /* Frame height */ 112 int mFrameHeight; 113 114 uint32_t mPixelFormat; 115 116 private: 117 118 void fillBuffer(void* buffer); 119 void render(int width, int height); 120 int init_gl_surface(int width, int height); 121 void get_eye_x_y_z(float* x, float* y, float*z); 122 void get_yawing(float* x, float* y, float*z); 123 void read_rotation_vector(double *yaw, double* pitch, double* roll); 124 void read_sensor(); 125 void init_sensor(); 126 void free_gl_surface(void); 127 void update_scene(float width, float height); 128 void create_texture_dotx(int width, int height); 129 130 bool mOpenglReady = false; 131 EGLDisplay mEglDisplay; 132 EGLSurface mEglSurface; 133 EGLContext mEglContext; 134 GLuint mTexture; 135 uint8_t* mPixelBuf;// = new uint8_t[width * height * kGlBytesPerPixel];; 136 int mSensorPipe = -1; 137 enum SENSOR_VALUE_TYPE { 138 SENSOR_VALUE_ACCEL_X=0, 139 SENSOR_VALUE_ACCEL_Y=1, 140 SENSOR_VALUE_ACCEL_Z=2, 141 SENSOR_VALUE_MAGNETIC_X=3, 142 SENSOR_VALUE_MAGNETIC_Y=4, 143 SENSOR_VALUE_MAGNETIC_Z=5, 144 SENSOR_VALUE_ROTATION_X=6, 145 SENSOR_VALUE_ROTATION_Y=7, 146 SENSOR_VALUE_ROTATION_Z=8, 147 }; 148 149 float mSensorValues[9] = {0}; 150 151 }; 152 153 }; /* namespace android */ 154 155 #endif /* HW_EMULATOR_CAMERA_EMULATED_FAKE_CAMERA_ROTATE_DEVICE_H */ 156