通过native实现camera的操作
源码路径:frameworks/av/camera/ndk/
参考的test源码路径:cts/tests/tests/graphics/jni/CameraTestHelpers.cpp
1/*
2 * Copyright 2018 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
18#ifndef ANDROID_CAMERATESTHELPERS_H
19#define ANDROID_CAMERATESTHELPERS_H
20
21// Must come before NdkCameraCaptureSession.h
22#include <camera/NdkCaptureRequest.h>
23
24#include <camera/NdkCameraCaptureSession.h>
25#include <camera/NdkCameraDevice.h>
26#include <camera/NdkCameraError.h>
27#include <camera/NdkCameraManager.h>
28#include <cstdlib>
29#include <cstring>
30#include <jni.h>
31#include <media/NdkImage.h>
32#include <media/NdkImageReader.h>
33
34// A helper class which can be used to initialize/control the camera.
35class CameraHelper {
36public:
37 ~CameraHelper();
38
39 int initCamera(ANativeWindow *imgReaderAnw);
40 bool isCapabilitySupported(
41 acamera_metadata_enum_android_request_available_capabilities_t cap);
42 bool isCameraReady() { return mIsCameraReady; }
43 void closeCamera();
44 int takePicture();
45
46 static void onDeviceDisconnected(void * /*obj*/, ACameraDevice * /*device*/) {
47 }
48 static void onDeviceError(void * /*obj*/, ACameraDevice * /*device*/,
49 int /*errorCode*/) {}
50 static void onSessionClosed(void * /*ob