| Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 1 | /* | 
 | 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 "NdkCaptureRequest" | 
 | 19 | #define ATRACE_TAG ATRACE_TAG_CAMERA | 
 | 20 |  | 
 | 21 | #include <utils/Log.h> | 
 | 22 | #include <utils/Trace.h> | 
 | 23 |  | 
 | 24 | #include "NdkCaptureRequest.h" | 
 | 25 | #include "impl/ACameraMetadata.h" | 
 | 26 | #include "impl/ACaptureRequest.h" | 
 | 27 |  | 
 | 28 | EXPORT | 
 | 29 | camera_status_t ACameraOutputTarget_create( | 
 | 30 |         ANativeWindow* window, ACameraOutputTarget** out) { | 
 | 31 |     ATRACE_CALL(); | 
 | 32 |     if (window == nullptr) { | 
 | 33 |         ALOGE("%s: Error: input window is null", __FUNCTION__); | 
 | 34 |         return ACAMERA_ERROR_INVALID_PARAMETER; | 
 | 35 |     } | 
 | 36 |     *out = new ACameraOutputTarget(window); | 
 | 37 |     return ACAMERA_OK; | 
 | 38 | } | 
 | 39 |  | 
 | 40 | EXPORT | 
 | 41 | void ACameraOutputTarget_free(ACameraOutputTarget* target) { | 
 | 42 |     ATRACE_CALL(); | 
 | 43 |     if (target != nullptr) { | 
 | 44 |         delete target; | 
 | 45 |     } | 
 | 46 |     return; | 
 | 47 | } | 
 | 48 |  | 
 | 49 | EXPORT | 
 | 50 | camera_status_t ACaptureRequest_addTarget( | 
 | 51 |         ACaptureRequest* req, const ACameraOutputTarget* target) { | 
 | 52 |     ATRACE_CALL(); | 
 | 53 |     if (req == nullptr || req->targets == nullptr || target == nullptr) { | 
| Yunlian Jiang | 2169303 | 2016-11-15 17:52:15 -0800 | [diff] [blame^] | 54 |         void* req_targets; | 
 | 55 |         if (req != nullptr) | 
 | 56 |             req_targets = req->targets; | 
 | 57 |         else | 
 | 58 |             req_targets = nullptr; | 
| Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 59 |         ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p", | 
| Yunlian Jiang | 2169303 | 2016-11-15 17:52:15 -0800 | [diff] [blame^] | 60 |                 __FUNCTION__, req, req_targets, target); | 
| Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 61 |         return ACAMERA_ERROR_INVALID_PARAMETER; | 
 | 62 |     } | 
 | 63 |     auto pair = req->targets->mOutputs.insert(*target); | 
 | 64 |     if (!pair.second) { | 
| Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 65 |         ALOGW("%s: target %p already exists!", __FUNCTION__, target); | 
| Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 66 |     } | 
 | 67 |     return ACAMERA_OK; | 
 | 68 | } | 
 | 69 |  | 
 | 70 | EXPORT | 
 | 71 | camera_status_t ACaptureRequest_removeTarget( | 
 | 72 |         ACaptureRequest* req, const ACameraOutputTarget* target) { | 
 | 73 |     ATRACE_CALL(); | 
 | 74 |     if (req == nullptr || req->targets == nullptr || target == nullptr) { | 
| Yunlian Jiang | 2169303 | 2016-11-15 17:52:15 -0800 | [diff] [blame^] | 75 |         void* req_targets; | 
 | 76 |         if (req != nullptr) | 
 | 77 |             req_targets = req->targets; | 
 | 78 |         else | 
 | 79 |             req_targets = nullptr; | 
| Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 80 |         ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p", | 
| Yunlian Jiang | 2169303 | 2016-11-15 17:52:15 -0800 | [diff] [blame^] | 81 |                 __FUNCTION__, req, req_targets, target); | 
| Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 82 |         return ACAMERA_ERROR_INVALID_PARAMETER; | 
 | 83 |     } | 
 | 84 |     req->targets->mOutputs.erase(*target); | 
 | 85 |     return ACAMERA_OK; | 
 | 86 | } | 
 | 87 |  | 
 | 88 | EXPORT | 
 | 89 | camera_status_t ACaptureRequest_getConstEntry( | 
 | 90 |         const ACaptureRequest* req, uint32_t tag, ACameraMetadata_const_entry* entry) { | 
 | 91 |     ATRACE_CALL(); | 
 | 92 |     if (req == nullptr || entry == nullptr) { | 
 | 93 |         ALOGE("%s: invalid argument! req 0x%p, tag 0x%x, entry 0x%p", | 
 | 94 |                __FUNCTION__, req, tag, entry); | 
 | 95 |         return ACAMERA_ERROR_INVALID_PARAMETER; | 
 | 96 |     } | 
 | 97 |     return req->settings->getConstEntry(tag, entry); | 
 | 98 | } | 
 | 99 |  | 
| Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 100 | EXPORT | 
 | 101 | camera_status_t ACaptureRequest_getAllTags( | 
 | 102 |         const ACaptureRequest* req, /*out*/int32_t* numTags, /*out*/const uint32_t** tags) { | 
 | 103 |     ATRACE_CALL(); | 
 | 104 |     if (req == nullptr || numTags == nullptr || tags == nullptr) { | 
 | 105 |         ALOGE("%s: invalid argument! request %p, numTags %p, tags %p", | 
 | 106 |                __FUNCTION__, req, numTags, tags); | 
 | 107 |         return ACAMERA_ERROR_INVALID_PARAMETER; | 
 | 108 |     } | 
 | 109 |     return req->settings->getTags(numTags, tags); | 
 | 110 | } | 
 | 111 |  | 
| Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 112 | #define SET_ENTRY(NAME,NDK_TYPE)                                                        \ | 
 | 113 | EXPORT                                                                                  \ | 
 | 114 | camera_status_t ACaptureRequest_setEntry_##NAME(                                        \ | 
 | 115 |         ACaptureRequest* req, uint32_t tag, uint32_t count, const NDK_TYPE* data) {     \ | 
 | 116 |     ATRACE_CALL();                                                                      \ | 
 | 117 |     if (req == nullptr || (count > 0 && data == nullptr)) {                             \ | 
 | 118 |         ALOGE("%s: invalid argument! req %p, tag 0x%x, count %d, data 0x%p",            \ | 
 | 119 |                __FUNCTION__, req, tag, count, data);                                    \ | 
 | 120 |         return ACAMERA_ERROR_INVALID_PARAMETER;                                         \ | 
 | 121 |     }                                                                                   \ | 
 | 122 |     return req->settings->update(tag, count, data);                                     \ | 
 | 123 | } | 
 | 124 |  | 
 | 125 | SET_ENTRY(u8,uint8_t) | 
 | 126 | SET_ENTRY(i32,int32_t) | 
 | 127 | SET_ENTRY(float,float) | 
 | 128 | SET_ENTRY(double,double) | 
 | 129 | SET_ENTRY(i64,int64_t) | 
 | 130 | SET_ENTRY(rational,ACameraMetadata_rational) | 
 | 131 |  | 
 | 132 | #undef SET_ENTRY | 
 | 133 |  | 
 | 134 | EXPORT | 
 | 135 | void ACaptureRequest_free(ACaptureRequest* request) { | 
 | 136 |     ATRACE_CALL(); | 
 | 137 |     if (request == nullptr) { | 
 | 138 |         return; | 
 | 139 |     } | 
 | 140 |     delete request->settings; | 
 | 141 |     delete request->targets; | 
 | 142 |     delete request; | 
 | 143 |     return; | 
 | 144 | } |