File: EmulatedCamera2.h

package info (click to toggle)
anbox 0.0~git20190124-1
  • links: PTS, VCS
  • area: contrib
  • in suites: buster
  • size: 22,000 kB
  • sloc: cpp: 76,190; ansic: 7,434; sh: 1,350; xml: 818; java: 780; python: 390; makefile: 35; lisp: 7
file content (274 lines) | stat: -rw-r--r-- 9,832 bytes parent folder | download | duplicates (2)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
 * Copyright (C) 2012 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_CAMERA2_H
#define HW_EMULATOR_CAMERA_EMULATED_CAMERA2_H

/*
 * Contains declaration of a class EmulatedCamera that encapsulates
 * functionality common to all version 2.0 emulated camera devices.  Instances
 * of this class (for each emulated camera) are created during the construction
 * of the EmulatedCameraFactory instance.  This class serves as an entry point
 * for all camera API calls that defined by camera2_device_ops_t API.
 */

#include "hardware/camera2.h"
#include "system/camera_metadata.h"
#include "EmulatedBaseCamera.h"
#include <utils/Thread.h>
#include <utils/Mutex.h>

namespace android {

/* Encapsulates functionality common to all version 2.0 emulated camera devices
 *
 * Note that EmulatedCameraFactory instantiates object of this class just once,
 * when EmulatedCameraFactory instance gets constructed. Connection to /
 * disconnection from the actual camera device is handled by calls to
 * connectDevice(), and closeCamera() methods of this class that are invoked in
 * response to hw_module_methods_t::open, and camera_device::close callbacks.
 */
class EmulatedCamera2 : public camera2_device, public EmulatedBaseCamera {
public:
    /* Constructs EmulatedCamera2 instance.
     * Param:
     *  cameraId - Zero based camera identifier, which is an index of the camera
     *      instance in camera factory's array.
     *  module - Emulated camera HAL module descriptor.
     */
    EmulatedCamera2(int cameraId,
            struct hw_module_t* module);

    /* Destructs EmulatedCamera2 instance. */
    virtual ~EmulatedCamera2();

    /****************************************************************************
     * Abstract API
     ***************************************************************************/

public:

    /****************************************************************************
     * Public API
     ***************************************************************************/

public:
    virtual status_t Initialize();

    /****************************************************************************
     * Camera module API and generic hardware device API implementation
     ***************************************************************************/

public:
    virtual status_t connectCamera(hw_device_t** device);

    virtual status_t closeCamera();

    virtual status_t getCameraInfo(struct camera_info* info) = 0;

    /****************************************************************************
     * Camera API implementation.
     * These methods are called from the camera API callback routines.
     ***************************************************************************/

protected:
    /** Request input queue notification */
    virtual int requestQueueNotify();

    /** Count of requests in flight */
    virtual int getInProgressCount();

    /** Cancel all captures in flight */
    virtual int flushCapturesInProgress();

    virtual int constructDefaultRequest(
        int request_template,
        camera_metadata_t **request);

    /** Output stream creation and management */
    virtual int allocateStream(
            uint32_t width,
            uint32_t height,
            int format,
            const camera2_stream_ops_t *stream_ops,
            uint32_t *stream_id,
            uint32_t *format_actual,
            uint32_t *usage,
            uint32_t *max_buffers);

    virtual int registerStreamBuffers(
            uint32_t stream_id,
            int num_buffers,
            buffer_handle_t *buffers);

    virtual int releaseStream(uint32_t stream_id);

    /** Input stream creation and management */
    virtual int allocateReprocessStream(
            uint32_t width,
            uint32_t height,
            uint32_t format,
            const camera2_stream_in_ops_t *reprocess_stream_ops,
            uint32_t *stream_id,
            uint32_t *consumer_usage,
            uint32_t *max_buffers);

    virtual int allocateReprocessStreamFromStream(
            uint32_t output_stream_id,
            const camera2_stream_in_ops_t *reprocess_stream_ops,
            uint32_t *stream_id);

    virtual int releaseReprocessStream(uint32_t stream_id);

    /** 3A action triggering */
    virtual int triggerAction(uint32_t trigger_id,
            int32_t ext1, int32_t ext2);

    /** Custom tag definitions */
    virtual const char* getVendorSectionName(uint32_t tag);
    virtual const char* getVendorTagName(uint32_t tag);
    virtual int         getVendorTagType(uint32_t tag);

    /** Debug methods */

    virtual int dump(int fd);

    /****************************************************************************
     * Camera API callbacks as defined by camera2_device_ops structure.  See
     * hardware/libhardware/include/hardware/camera2.h for information on each
     * of these callbacks. Implemented in this class, these callbacks simply
     * dispatch the call into an instance of EmulatedCamera2 class defined in
     * the 'camera_device2' parameter.
     ***************************************************************************/

private:
    /** Input request queue */
    static int set_request_queue_src_ops(const camera2_device_t *,
            const camera2_request_queue_src_ops *queue_src_ops);
    static int notify_request_queue_not_empty(const camera2_device_t *);

    /** Output frame queue */
    static int set_frame_queue_dst_ops(const camera2_device_t *,
            const camera2_frame_queue_dst_ops *queue_dst_ops);

    /** In-progress request management */
    static int get_in_progress_count(const camera2_device_t *);

    static int flush_captures_in_progress(const camera2_device_t *);

    /** Request template creation */
    static int construct_default_request(const camera2_device_t *,
            int request_template,
            camera_metadata_t **request);

    /** Stream management */
    static int allocate_stream(const camera2_device_t *,
            uint32_t width,
            uint32_t height,
            int format,
            const camera2_stream_ops_t *stream_ops,
            uint32_t *stream_id,
            uint32_t *format_actual,
            uint32_t *usage,
            uint32_t *max_buffers);

    static int register_stream_buffers(const camera2_device_t *,
            uint32_t stream_id,
            int num_buffers,
            buffer_handle_t *buffers);

    static int release_stream(const camera2_device_t *,
            uint32_t stream_id);

    static int allocate_reprocess_stream(const camera2_device_t *,
            uint32_t width,
            uint32_t height,
            uint32_t format,
            const camera2_stream_in_ops_t *reprocess_stream_ops,
            uint32_t *stream_id,
            uint32_t *consumer_usage,
            uint32_t *max_buffers);

    static int allocate_reprocess_stream_from_stream(const camera2_device_t *,
            uint32_t output_stream_id,
            const camera2_stream_in_ops_t *reprocess_stream_ops,
            uint32_t *stream_id);

    static int release_reprocess_stream(const camera2_device_t *,
            uint32_t stream_id);

    /** 3A triggers*/
    static int trigger_action(const camera2_device_t *,
            uint32_t trigger_id,
            int ext1,
            int ext2);

    /** Notifications to application */
    static int set_notify_callback(const camera2_device_t *,
            camera2_notify_callback notify_cb,
            void *user);

    /** Vendor metadata registration */
    static int get_metadata_vendor_tag_ops(const camera2_device_t *,
            vendor_tag_query_ops_t **ops);
    // for get_metadata_vendor_tag_ops
    static const char* get_camera_vendor_section_name(
            const vendor_tag_query_ops_t *,
            uint32_t tag);
    static const char* get_camera_vendor_tag_name(
            const vendor_tag_query_ops_t *,
            uint32_t tag);
    static int get_camera_vendor_tag_type(
            const vendor_tag_query_ops_t *,
            uint32_t tag);

    static int dump(const camera2_device_t *, int fd);

    /** For hw_device_t ops */
    static int close(struct hw_device_t* device);

    /****************************************************************************
     * Data members shared with implementations
     ***************************************************************************/
  protected:
    /** Mutex for calls through camera2 device interface */
    Mutex mMutex;

    bool mStatusPresent;

    const camera2_request_queue_src_ops *mRequestQueueSrc;
    const camera2_frame_queue_dst_ops *mFrameQueueDst;

    struct TagOps : public vendor_tag_query_ops {
        EmulatedCamera2 *parent;
    };
    TagOps      mVendorTagOps;

    void sendNotification(int32_t msgType,
            int32_t ext1, int32_t ext2, int32_t ext3);

    /****************************************************************************
     * Data members
     ***************************************************************************/
  private:
    static camera2_device_ops_t sDeviceOps;
    camera2_notify_callback mNotifyCb;
    void* mNotifyUserPtr;
};

}; /* namespace android */

#endif  /* HW_EMULATOR_CAMERA_EMULATED_CAMERA2_H */