Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/camera/camera_android.h
10277 views
1
/**************************************************************************/
2
/* camera_android.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "servers/camera/camera_feed.h"
34
#include "servers/camera_server.h"
35
36
#include <camera/NdkCameraDevice.h>
37
#include <camera/NdkCameraError.h>
38
#include <camera/NdkCameraManager.h>
39
#include <camera/NdkCameraMetadataTags.h>
40
#include <media/NdkImageReader.h>
41
42
class CameraFeedAndroid : public CameraFeed {
43
GDSOFTCLASS(CameraFeedAndroid, CameraFeed);
44
45
private:
46
String camera_id;
47
int32_t orientation;
48
Ref<Image> image_y;
49
Ref<Image> image_uv;
50
Vector<uint8_t> data_y;
51
Vector<uint8_t> data_uv;
52
53
ACameraManager *manager = nullptr;
54
ACameraMetadata *metadata = nullptr;
55
ACameraDevice *device = nullptr;
56
AImageReader *reader = nullptr;
57
ACameraCaptureSession *session = nullptr;
58
ACaptureRequest *request = nullptr;
59
60
void _add_formats();
61
void _set_rotation();
62
63
static void onError(void *context, ACameraDevice *p_device, int error);
64
static void onDisconnected(void *context, ACameraDevice *p_device);
65
static void onImage(void *context, AImageReader *p_reader);
66
static void onSessionReady(void *context, ACameraCaptureSession *session);
67
static void onSessionActive(void *context, ACameraCaptureSession *session);
68
static void onSessionClosed(void *context, ACameraCaptureSession *session);
69
70
protected:
71
public:
72
bool activate_feed() override;
73
void deactivate_feed() override;
74
bool set_format(int p_index, const Dictionary &p_parameters) override;
75
Array get_formats() const override;
76
FeedFormat get_format() const override;
77
78
CameraFeedAndroid(ACameraManager *manager, ACameraMetadata *metadata, const char *id,
79
CameraFeed::FeedPosition position, int32_t orientation);
80
~CameraFeedAndroid() override;
81
};
82
83
class CameraAndroid : public CameraServer {
84
GDSOFTCLASS(CameraAndroid, CameraServer);
85
86
private:
87
ACameraManager *cameraManager = nullptr;
88
89
void update_feeds();
90
void remove_all_feeds();
91
92
public:
93
void set_monitoring_feeds(bool p_monitoring_feeds) override;
94
95
~CameraAndroid();
96
};
97
98