ronnie
2023-02-21 452e44bd1ae1c65461db849228ddbad77b42f172
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#ifndef HW_EMULATOR_CAMERA_EMULATED_FAKE_CAMERA_ROTATE_DEVICE_H
#define HW_EMULATOR_CAMERA_EMULATED_FAKE_CAMERA_ROTATE_DEVICE_H
 
/*
 * Contains declaration of a class EmulatedFakeRotatingCameraDevice that encapsulates
 * a fake camera device.
 */
 
#include "Converters.h"
#include "EmulatedCameraDevice.h"
 
#include <EGL/egl.h>
#include <GLES/gl.h>
#include <GLES/glext.h>
 
namespace android {
 
class EmulatedFakeCamera;
 
/* Encapsulates a fake camera device.
 * Fake camera device emulates a camera device by providing frames containing
 * an image rendered by opengl, that takes rotating input from host
 */
class EmulatedFakeRotatingCameraDevice : public EmulatedCameraDevice {
public:
    /* Constructs EmulatedFakeRotatingCameraDevice instance. */
    explicit EmulatedFakeRotatingCameraDevice(EmulatedFakeCamera* camera_hal);
 
    /* Destructs EmulatedFakeRotatingCameraDevice instance. */
    ~EmulatedFakeRotatingCameraDevice();
 
    /***************************************************************************
     * Emulated camera device abstract interface implementation.
     * See declarations of these methods in EmulatedCameraDevice class for
     * information on each of these methods.
     **************************************************************************/
 
public:
    /* Connects to the camera device.
     * Since there is no real device to connect to, this method does nothing,
     * but changes the state.
     */
    status_t connectDevice();
 
    /* Disconnects from the camera device.
     * Since there is no real device to disconnect from, this method does
     * nothing, but changes the state.
     */
    status_t disconnectDevice();
 
    /* Starts the camera device. */
    status_t startDevice(int width, int height, uint32_t pix_fmt);
 
    /* Stops the camera device. */
    status_t stopDevice();
 
 
protected:
    /* Implementation of the frame production routine. */
    bool produceFrame(void* buffer, int64_t* timestamp) override;
 
    /****************************************************************************
     * Fake camera device private API
     ***************************************************************************/
 
private:
 
    void fillBuffer(void* buffer);
    void render(int width, int height);
    int init_gl_surface(int width, int height);
    void get_eye_x_y_z(float* x, float* y, float*z);
    void get_yawing(float* x, float* y, float*z);
    void read_rotation_vector(double *yaw, double* pitch, double* roll);
    void read_sensor();
    void init_sensor();
    void free_gl_surface(void);
    void update_scene(float width, float height);
    void create_texture_dotx(int width, int height);
 
    bool mOpenglReady = false;
    EGLDisplay mEglDisplay;
    EGLSurface mEglSurface;
    EGLContext mEglContext;
    GLuint mTexture;
    uint8_t* mPixelBuf;// = new uint8_t[width * height * kGlBytesPerPixel];;
    int mSensorPipe = -1;
    enum SENSOR_VALUE_TYPE {
        SENSOR_VALUE_ACCEL_X=0,
        SENSOR_VALUE_ACCEL_Y=1,
        SENSOR_VALUE_ACCEL_Z=2,
        SENSOR_VALUE_MAGNETIC_X=3,
        SENSOR_VALUE_MAGNETIC_Y=4,
        SENSOR_VALUE_MAGNETIC_Z=5,
        SENSOR_VALUE_ROTATION_X=6,
        SENSOR_VALUE_ROTATION_Y=7,
        SENSOR_VALUE_ROTATION_Z=8,
    };
 
    float mSensorValues[9] = {0};
 
};
 
}; /* namespace android */
 
#endif  /* HW_EMULATOR_CAMERA_EMULATED_FAKE_CAMERA_ROTATE_DEVICE_H */