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) { 54 ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p", 55 __FUNCTION__, req, req->targets, target); 56 return ACAMERA_ERROR_INVALID_PARAMETER; 57 } 58 auto pair = req->targets->mOutputs.insert(*target); 59 if (!pair.second) { 60 ALOGW("%s: target %p already exists!", __FUNCTION__, target); 61 } 62 return ACAMERA_OK; 63 } 64 65 EXPORT 66 camera_status_t ACaptureRequest_removeTarget( 67 ACaptureRequest* req, const ACameraOutputTarget* target) { 68 ATRACE_CALL(); 69 if (req == nullptr || req->targets == nullptr || target == nullptr) { 70 ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p", 71 __FUNCTION__, req, req->targets, target); 72 return ACAMERA_ERROR_INVALID_PARAMETER; 73 } 74 req->targets->mOutputs.erase(*target); 75 return ACAMERA_OK; 76 } 77 78 EXPORT 79 camera_status_t ACaptureRequest_getConstEntry( 80 const ACaptureRequest* req, uint32_t tag, ACameraMetadata_const_entry* entry) { 81 ATRACE_CALL(); 82 if (req == nullptr || entry == nullptr) { 83 ALOGE("%s: invalid argument! req 0x%p, tag 0x%x, entry 0x%p", 84 __FUNCTION__, req, tag, entry); 85 return ACAMERA_ERROR_INVALID_PARAMETER; 86 } 87 return req->settings->getConstEntry(tag, entry); 88 } 89 90 EXPORT 91 camera_status_t ACaptureRequest_getAllTags( 92 const ACaptureRequest* req, /*out*/int32_t* numTags, /*out*/const uint32_t** tags) { 93 ATRACE_CALL(); 94 if (req == nullptr || numTags == nullptr || tags == nullptr) { 95 ALOGE("%s: invalid argument! request %p, numTags %p, tags %p", 96 __FUNCTION__, req, numTags, tags); 97 return ACAMERA_ERROR_INVALID_PARAMETER; 98 } 99 return req->settings->getTags(numTags, tags); 100 } 101 102 #define SET_ENTRY(NAME,NDK_TYPE) \ 103 EXPORT \ 104 camera_status_t ACaptureRequest_setEntry_##NAME( \ 105 ACaptureRequest* req, uint32_t tag, uint32_t count, const NDK_TYPE* data) { \ 106 ATRACE_CALL(); \ 107 if (req == nullptr || (count > 0 && data == nullptr)) { \ 108 ALOGE("%s: invalid argument! req %p, tag 0x%x, count %d, data 0x%p", \ 109 __FUNCTION__, req, tag, count, data); \ 110 return ACAMERA_ERROR_INVALID_PARAMETER; \ 111 } \ 112 return req->settings->update(tag, count, data); \ 113 } 114 115 SET_ENTRY(u8,uint8_t) 116 SET_ENTRY(i32,int32_t) 117 SET_ENTRY(float,float) 118 SET_ENTRY(double,double) 119 SET_ENTRY(i64,int64_t) 120 SET_ENTRY(rational,ACameraMetadata_rational) 121 122 #undef SET_ENTRY 123 124 EXPORT 125 void ACaptureRequest_free(ACaptureRequest* request) { 126 ATRACE_CALL(); 127 if (request == nullptr) { 128 return; 129 } 130 delete request->settings; 131 delete request->targets; 132 delete request; 133 return; 134 } 135