blob: 281d3e75abea6b1ed079011c7856745fe63b93bf [file] [log] [blame]
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -08001/*
2 * Copyright (C) 2015 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//#define LOG_NDEBUG 0
18#define LOG_TAG "NdkCameraDevice"
19#define ATRACE_TAG ATRACE_TAG_CAMERA
20
21#include <utils/Log.h>
22#include <utils/Trace.h>
23
24#include <NdkCameraDevice.h>
Yin-Chia Yehead91462016-01-06 16:45:08 -080025#include "impl/ACameraCaptureSession.h"
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080026
27using namespace android;
28
29EXPORT
30camera_status_t ACameraDevice_close(ACameraDevice* device) {
31 ATRACE_CALL();
32 if (device == nullptr) {
33 ALOGE("%s: invalid argument! device is null", __FUNCTION__);
34 return ACAMERA_ERROR_INVALID_PARAMETER;
35 }
36 delete device;
37 return ACAMERA_OK;
38}
39
40EXPORT
41const char* ACameraDevice_getId(const ACameraDevice* device) {
42 ATRACE_CALL();
43 if (device == nullptr) {
44 ALOGE("%s: invalid argument! device is null", __FUNCTION__);
45 return nullptr;
46 }
47 return device->getId();
48}
49
50EXPORT
51camera_status_t ACameraDevice_createCaptureRequest(
52 const ACameraDevice* device,
53 ACameraDevice_request_template templateId,
54 ACaptureRequest** request) {
55 ATRACE_CALL();
56 if (device == nullptr || request == nullptr) {
Yin-Chia Yehead91462016-01-06 16:45:08 -080057 ALOGE("%s: invalid argument! device %p request %p",
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080058 __FUNCTION__, device, request);
59 return ACAMERA_ERROR_INVALID_PARAMETER;
60 }
61 switch (templateId) {
62 case TEMPLATE_PREVIEW:
63 case TEMPLATE_STILL_CAPTURE:
64 case TEMPLATE_RECORD:
65 case TEMPLATE_VIDEO_SNAPSHOT:
66 case TEMPLATE_ZERO_SHUTTER_LAG:
67 case TEMPLATE_MANUAL:
68 break;
69 default:
70 ALOGE("%s: unknown template ID %d", __FUNCTION__, templateId);
71 return ACAMERA_ERROR_INVALID_PARAMETER;
72 }
73 return device->createCaptureRequest(templateId, request);
74}
75
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080076EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -080077camera_status_t ACaptureSessionOutputContainer_create(
78 /*out*/ACaptureSessionOutputContainer** out) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080079 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080080 if (out == nullptr) {
81 ALOGE("%s: Error: out null", __FUNCTION__);
82 return ACAMERA_ERROR_INVALID_PARAMETER;
83 }
84 *out = new ACaptureSessionOutputContainer();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080085 return ACAMERA_OK;
86}
87
88EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -080089void ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer* container) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080090 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080091 if (container != nullptr) {
92 delete container;
93 }
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080094 return;
95}
96
97EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -080098camera_status_t ACaptureSessionOutput_create(
99 ANativeWindow* window, /*out*/ACaptureSessionOutput** out) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800100 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800101 if (window == nullptr || out == nullptr) {
102 ALOGE("%s: Error: bad argument. window %p, out %p",
103 __FUNCTION__, window, out);
104 return ACAMERA_ERROR_INVALID_PARAMETER;
105 }
106 *out = new ACaptureSessionOutput(window);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800107 return ACAMERA_OK;
108}
109
110EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -0800111void ACaptureSessionOutput_free(ACaptureSessionOutput* output) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800112 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800113 if (output != nullptr) {
114 delete output;
115 }
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800116 return;
117}
118
119EXPORT
120camera_status_t ACaptureSessionOutputContainer_add(
Yin-Chia Yehead91462016-01-06 16:45:08 -0800121 ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800122 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800123 if (container == nullptr || output == nullptr) {
124 ALOGE("%s: Error: invalid input: container %p, output %p",
125 __FUNCTION__, container, output);
126 return ACAMERA_ERROR_INVALID_PARAMETER;
127 }
128 auto pair = container->mOutputs.insert(*output);
129 if (!pair.second) {
130 ALOGW("%s: output %p already exists!", __FUNCTION__, output);
131 }
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800132 return ACAMERA_OK;
133}
134
135EXPORT
136camera_status_t ACaptureSessionOutputContainer_remove(
Yin-Chia Yehead91462016-01-06 16:45:08 -0800137 ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800138 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800139 if (container == nullptr || output == nullptr) {
140 ALOGE("%s: Error: invalid input: container %p, output %p",
141 __FUNCTION__, container, output);
142 return ACAMERA_ERROR_INVALID_PARAMETER;
143 }
144 container->mOutputs.erase(*output);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800145 return ACAMERA_OK;
146}
147
148EXPORT
149camera_status_t ACameraDevice_createCaptureSession(
Yin-Chia Yehead91462016-01-06 16:45:08 -0800150 ACameraDevice* device,
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800151 const ACaptureSessionOutputContainer* outputs,
Yin-Chia Yehead91462016-01-06 16:45:08 -0800152 const ACameraCaptureSession_stateCallbacks* callbacks,
153 /*out*/ACameraCaptureSession** session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800154 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800155 if (device == nullptr || outputs == nullptr || callbacks == nullptr || session == nullptr) {
156 ALOGE("%s: Error: invalid input: device %p, outputs %p, callbacks %p, session %p",
157 __FUNCTION__, device, outputs, callbacks, session);
158 return ACAMERA_ERROR_INVALID_PARAMETER;
159 }
160 return device->createCaptureSession(outputs, callbacks, session);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800161}