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 "NdkCameraManager" 19 #define ATRACE_TAG ATRACE_TAG_CAMERA 20 21 #include <utils/Log.h> 22 #include <utils/Trace.h> 23 24 #include <NdkCameraManager.h> 25 #include "impl/ACameraManager.h" 26 27 using namespace android; 28 29 EXPORT 30 ACameraManager* ACameraManager_create() { 31 ATRACE_CALL(); 32 return new ACameraManager(); 33 } 34 35 EXPORT 36 void ACameraManager_delete(ACameraManager* manager) { 37 ATRACE_CALL(); 38 if (manager != nullptr) { 39 delete manager; 40 } 41 } 42 43 EXPORT 44 camera_status_t ACameraManager_getCameraIdList( 45 ACameraManager* manager, ACameraIdList** cameraIdList) { 46 ATRACE_CALL(); 47 if (manager == nullptr || cameraIdList == nullptr) { 48 ALOGE("%s: invalid argument! manager %p, cameraIdList %p", 49 __FUNCTION__, manager, cameraIdList); 50 return ACAMERA_ERROR_INVALID_PARAMETER; 51 } 52 return manager->getCameraIdList(cameraIdList); 53 } 54 55 EXPORT 56 void ACameraManager_deleteCameraIdList(ACameraIdList* cameraIdList) { 57 ATRACE_CALL(); 58 if (cameraIdList != nullptr) { 59 ACameraManager::deleteCameraIdList(cameraIdList); 60 } 61 } 62 63 EXPORT 64 camera_status_t ACameraManager_registerAvailabilityCallback( 65 ACameraManager*, const ACameraManager_AvailabilityCallbacks *callback) { 66 ATRACE_CALL(); 67 if (callback == nullptr) { 68 ALOGE("%s: invalid argument! callback is null!", __FUNCTION__); 69 return ACAMERA_ERROR_INVALID_PARAMETER; 70 } 71 if (callback->onCameraAvailable == nullptr || callback->onCameraUnavailable == nullptr) { 72 ALOGE("%s: invalid argument! callback %p, " 73 "onCameraAvailable %p, onCameraUnavailable %p", 74 __FUNCTION__, callback, 75 callback->onCameraAvailable, callback->onCameraUnavailable); 76 return ACAMERA_ERROR_INVALID_PARAMETER; 77 } 78 CameraManagerGlobal::getInstance().registerAvailabilityCallback(callback); 79 return ACAMERA_OK; 80 } 81 82 EXPORT 83 camera_status_t ACameraManager_unregisterAvailabilityCallback( 84 ACameraManager*, const ACameraManager_AvailabilityCallbacks *callback) { 85 ATRACE_CALL(); 86 if (callback == nullptr) { 87 ALOGE("%s: invalid argument! callback is null!", __FUNCTION__); 88 return ACAMERA_ERROR_INVALID_PARAMETER; 89 } 90 if (callback->onCameraAvailable == nullptr || callback->onCameraUnavailable == nullptr) { 91 ALOGE("%s: invalid argument! callback %p, " 92 "onCameraAvailable %p, onCameraUnavailable %p", 93 __FUNCTION__, callback, 94 callback->onCameraAvailable, callback->onCameraUnavailable); 95 return ACAMERA_ERROR_INVALID_PARAMETER; 96 } 97 CameraManagerGlobal::getInstance().unregisterAvailabilityCallback(callback); 98 return ACAMERA_OK; 99 } 100 101 EXPORT 102 camera_status_t ACameraManager_getCameraCharacteristics( 103 ACameraManager* mgr, const char* cameraId, ACameraMetadata** chars){ 104 ATRACE_CALL(); 105 if (mgr == nullptr || cameraId == nullptr || chars == nullptr) { 106 ALOGE("%s: invalid argument! mgr %p cameraId %p chars %p", 107 __FUNCTION__, mgr, cameraId, chars); 108 return ACAMERA_ERROR_INVALID_PARAMETER; 109 } 110 return mgr->getCameraCharacteristics(cameraId, chars); 111 } 112 113 EXPORT 114 camera_status_t ACameraManager_openCamera( 115 ACameraManager* mgr, const char* cameraId, 116 ACameraDevice_StateCallbacks* callback, 117 /*out*/ACameraDevice** device) { 118 ATRACE_CALL(); 119 if (mgr == nullptr || cameraId == nullptr || callback == nullptr || device == nullptr) { 120 ALOGE("%s: invalid argument! mgr %p cameraId %p callback %p device %p", 121 __FUNCTION__, mgr, cameraId, callback, device); 122 return ACAMERA_ERROR_INVALID_PARAMETER; 123 } 124 return mgr->openCamera(cameraId, callback, device); 125 } 126