-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathNative_Camera.h
More file actions
77 lines (59 loc) · 2.29 KB
/
Copy pathNative_Camera.h
File metadata and controls
77 lines (59 loc) · 2.29 KB
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
#ifndef OPENCV_NDK_NATIVE_CAMERA_H
#define OPENCV_NDK_NATIVE_CAMERA_H
#include "Util.h"
#include <camera/NdkCameraDevice.h>
#include <camera/NdkCameraManager.h>
#include <media/NdkImageReader.h>
#include <android/native_window.h>
enum camera_type {
BACK_CAMERA, FRONT_CAMERA
};
// TODO - reasonable actions with callbacks
// Camera Callbacks
static void CameraDeviceOnDisconnected(void *context, ACameraDevice *device) {
LOGI("Camera(id: %s) is diconnected.\n", ACameraDevice_getId(device));
}
static void CameraDeviceOnError(void *context, ACameraDevice *device,
int error) {
LOGE("Error(code: %d) on Camera(id: %s).\n", error,
ACameraDevice_getId(device));
}
// Capture Callbacks
static void CaptureSessionOnReady(void *context,
ACameraCaptureSession *session) {
LOGI("Session is ready.\n");
}
static void CaptureSessionOnActive(void *context,
ACameraCaptureSession *session) {
LOGI("Session is activated.\n");
}
// This class was created since if you want to alternate cameras
// you need to do a proper cleanup and setup and creating a
// separate class was the best OOP move
class Native_Camera {
public:
explicit Native_Camera(camera_type type);
~Native_Camera();
bool MatchCaptureSizeRequest(ImageFormat *resView, int32_t width, int32_t height);
bool CreateCaptureSession(ANativeWindow *window);
int32_t GetCameraCount() { return m_camera_id_list->numCameras; }
uint32_t GetOrientation() { return m_camera_orientation; };
private:
// Camera variables
ACameraDevice *m_camera_device;
ACaptureRequest *m_capture_request;
ACameraOutputTarget *m_camera_output_target;
ACaptureSessionOutput *m_session_output;
ACaptureSessionOutputContainer *m_capture_session_output_container;
ACameraCaptureSession *m_capture_session;
ACameraDevice_StateCallbacks m_device_state_callbacks;
ACameraCaptureSession_stateCallbacks m_capture_session_state_callbacks;
ACameraManager *m_camera_manager;
uint32_t m_camera_orientation;
ACameraIdList *m_camera_id_list = NULL;
const char *m_selected_camera_id = NULL;
bool m_camera_ready;
int32_t backup_width = 480;
int32_t backup_height = 720;
};
#endif //OPENCV_NDK_NATIVE_CAMERA_H