Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0dea57fd authored by Yin-Chia Yeh's avatar Yin-Chia Yeh
Browse files

Camera NDK library: first draft

Bug: 23012001

Change-Id: I06d834421289d4dead1c87301a6ee94487ccf023
parent 52a94205
Loading
Loading
Loading
Loading

camera/ndk/Android.mk

0 → 100644
+52 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

LOCAL_PATH:= $(call my-dir)

ifneq ($(TARGET_BUILD_PDK), true)

include $(CLEAR_VARS)

LOCAL_SRC_FILES:=               \
    NdkCameraManager.cpp        \
    NdkCameraMetadata.cpp       \
    NdkCameraDevice.cpp         \
    NdkCaptureRequest.cpp       \
    NdkCameraCaptureSession.cpp \
    impl/ACameraManager.cpp     \
    impl/ACameraMetadata.cpp    \
    impl/ACameraDevice.cpp      \

LOCAL_MODULE:= libcamera2ndk

LOCAL_C_INCLUDES := \
    system/media/camera/include \
    frameworks/av/include/camera/ndk

LOCAL_CFLAGS += -fvisibility=hidden -D EXPORT='__attribute__ ((visibility ("default")))'

LOCAL_SHARED_LIBRARIES := \
    libbinder \
    liblog \
    libutils \
    libandroid_runtime \
    libcamera_client \
    libstagefright_foundation \
    libcutils \

include $(BUILD_SHARED_LIBRARY)

endif
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "NdkCameraCaptureSession"
#define ATRACE_TAG ATRACE_TAG_CAMERA

#include <utils/Log.h>
#include <utils/Mutex.h>
#include <utils/StrongPointer.h>
#include <utils/Trace.h>

#include "NdkCameraDevice.h"

using namespace android;

EXPORT
camera_status_t ACameraCaptureSession_close(ACameraCaptureSession*) {
    ATRACE_CALL();
    return ACAMERA_OK;
}

EXPORT
camera_status_t ACameraCaptureSession_getDevice(
        ACameraCaptureSession*, ACameraDevice **device) {
    ATRACE_CALL();
    // Make sure don't do return garbage if device has been closed
    return ACAMERA_OK;
}

EXPORT
camera_status_t ACameraCaptureSession_capture(
        ACameraCaptureSession*, /*optional*/ACameraCaptureSession_captureCallbacks*,
        int numRequests, const ACaptureRequest* requests) {
    ATRACE_CALL();
    return ACAMERA_OK;
}

EXPORT
camera_status_t ACameraCaptureSession_setRepeatingRequest(
        ACameraCaptureSession*, /*optional*/ACameraCaptureSession_captureCallbacks*,
        int numRequests, const ACaptureRequest* requests) {
    ATRACE_CALL();
    return ACAMERA_OK;
}

EXPORT
camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession*) {
    ATRACE_CALL();
    return ACAMERA_OK;
}

EXPORT
camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession*) {
    ATRACE_CALL();
    return ACAMERA_OK;
}
+125 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "NdkCameraDevice"
#define ATRACE_TAG ATRACE_TAG_CAMERA

#include <utils/Log.h>
#include <utils/Trace.h>

#include <NdkCameraDevice.h>
#include "impl/ACameraDevice.h"

using namespace android;

EXPORT
camera_status_t ACameraDevice_close(ACameraDevice* device) {
    ATRACE_CALL();
    if (device == nullptr) {
        ALOGE("%s: invalid argument! device is null", __FUNCTION__);
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    delete device;
    return ACAMERA_OK;
}

EXPORT
const char* ACameraDevice_getId(const ACameraDevice* device) {
    ATRACE_CALL();
    if (device == nullptr) {
        ALOGE("%s: invalid argument! device is null", __FUNCTION__);
        return nullptr;
    }
    return device->getId();
}

EXPORT
camera_status_t ACameraDevice_createCaptureRequest(
        const ACameraDevice* device,
        ACameraDevice_request_template templateId,
        ACaptureRequest** request) {
    ATRACE_CALL();
    if (device == nullptr || request == nullptr) {
        ALOGE("%s: invalid argument! device 0x%p request 0x%p",
                __FUNCTION__, device, request);
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    switch (templateId) {
        case TEMPLATE_PREVIEW:
        case TEMPLATE_STILL_CAPTURE:
        case TEMPLATE_RECORD:
        case TEMPLATE_VIDEO_SNAPSHOT:
        case TEMPLATE_ZERO_SHUTTER_LAG:
        case TEMPLATE_MANUAL:
            break;
        default:
            ALOGE("%s: unknown template ID %d", __FUNCTION__, templateId);
            return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    return device->createCaptureRequest(templateId, request);
}

struct ACaptureSessionOutputContainer;

struct ACaptureSessionOutput;

EXPORT
camera_status_t ACaptureSessionOutputContainer_create(/*out*/ACaptureSessionOutputContainer**) {
    ATRACE_CALL();
    return ACAMERA_OK;
}

EXPORT
void ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer*) {
    ATRACE_CALL();
    return;
}

EXPORT
camera_status_t ACaptureSessionOutput_create(ANativeWindow*, /*out*/ACaptureSessionOutput**) {
    ATRACE_CALL();
    return ACAMERA_OK;
}

EXPORT
void ACaptureSessionOutput_free(ACaptureSessionOutput*) {
    ATRACE_CALL();
    return;
}

EXPORT
camera_status_t ACaptureSessionOutputContainer_add(
        ACaptureSessionOutputContainer*, const ACaptureSessionOutput*) {
    ATRACE_CALL();
    return ACAMERA_OK;
}

EXPORT
camera_status_t ACaptureSessionOutputContainer_remove(
        ACaptureSessionOutputContainer*, const ACaptureSessionOutput*) {
    ATRACE_CALL();
    return ACAMERA_OK;
}

EXPORT
camera_status_t ACameraDevice_createCaptureSession(
        ACameraDevice*,
        const ACaptureSessionOutputContainer*       outputs,
        const ACameraCaptureSession_stateCallbacks* callbacks) {
    ATRACE_CALL();
    return ACAMERA_OK;
}
+123 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "NdkCameraManager"
#define ATRACE_TAG ATRACE_TAG_CAMERA

#include <utils/Log.h>
#include <utils/Trace.h>

#include <NdkCameraManager.h>
#include "impl/ACameraManager.h"

EXPORT
ACameraManager* ACameraManager_create() {
    ATRACE_CALL();
    return new ACameraManager();
}

EXPORT
void ACameraManager_delete(ACameraManager* manager) {
    ATRACE_CALL();
    if (manager != nullptr) {
        delete manager;
    }
}

EXPORT
camera_status_t ACameraManager_getCameraIdList(
        ACameraManager* manager, ACameraIdList** cameraIdList) {
    ATRACE_CALL();
    if (manager == nullptr || cameraIdList == nullptr) {
        ALOGE("%s: invalid argument! manager 0x%p, cameraIdList 0x%p",
              __FUNCTION__, manager, cameraIdList);
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    return manager->getCameraIdList(cameraIdList);
}

EXPORT
void ACameraManager_deleteCameraIdList(ACameraIdList* cameraIdList) {
    ATRACE_CALL();
    if (cameraIdList != nullptr) {
        ACameraManager::deleteCameraIdList(cameraIdList);
    }
}

EXPORT
camera_status_t ACameraManager_registerAvailabilityCallback(
        ACameraManager*, const ACameraManager_AvailabilityCallbacks *callback) {
    ATRACE_CALL();
    if (callback == nullptr) {
        ALOGE("%s: invalid argument! callback is null!", __FUNCTION__);
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    if (callback->onCameraAvailable == nullptr || callback->onCameraUnavailable == nullptr) {
        ALOGE("%s: invalid argument! callback 0x%p, "
                "onCameraAvailable 0x%p, onCameraUnavailable 0x%p",
               __FUNCTION__, callback,
               callback->onCameraAvailable, callback->onCameraUnavailable);
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    CameraManagerGlobal::getInstance().registerAvailabilityCallback(callback);
    return ACAMERA_OK;
}

EXPORT
camera_status_t ACameraManager_unregisterAvailabilityCallback(
        ACameraManager*, const ACameraManager_AvailabilityCallbacks *callback) {
    ATRACE_CALL();
    if (callback == nullptr) {
        ALOGE("%s: invalid argument! callback is null!", __FUNCTION__);
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    if (callback->onCameraAvailable == nullptr || callback->onCameraUnavailable == nullptr) {
        ALOGE("%s: invalid argument! callback 0x%p, "
                "onCameraAvailable 0x%p, onCameraUnavailable 0x%p",
               __FUNCTION__, callback,
               callback->onCameraAvailable, callback->onCameraUnavailable);
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    CameraManagerGlobal::getInstance().unregisterAvailabilityCallback(callback);
    return ACAMERA_OK;
}

EXPORT
camera_status_t ACameraManager_getCameraCharacteristics(
        ACameraManager* mgr, const char* cameraId, ACameraMetadata** chars){
    ATRACE_CALL();
    if (mgr == nullptr || cameraId == nullptr || chars == nullptr) {
        ALOGE("%s: invalid argument! mgr 0x%p cameraId 0x%p chars 0x%p",
                __FUNCTION__, mgr, cameraId, chars);
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    return mgr->getCameraCharacteristics(cameraId, chars);
}

EXPORT
camera_status_t ACameraManager_openCamera(
        ACameraManager* mgr, const char* cameraId,
        ACameraDevice_StateCallbacks* callback,
        /*out*/ACameraDevice** device) {
    ATRACE_CALL();
    if (mgr == nullptr || cameraId == nullptr || callback == nullptr || device == nullptr) {
        ALOGE("%s: invalid argument! mgr 0x%p cameraId 0x%p callback 0x%p device 0x%p",
                __FUNCTION__, mgr, cameraId, callback, device);
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    return mgr->openCamera(cameraId, callback, device);
}
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "NdkCameraMetadata"
#define ATRACE_TAG ATRACE_TAG_CAMERA

#include <utils/Log.h>
#include <utils/Trace.h>

#include "NdkCameraMetadata.h"
#include "impl/ACameraMetadata.h"

using namespace android;

EXPORT
camera_status_t ACameraMetadata_getConstEntry(
        const ACameraMetadata* acm, uint32_t tag, ACameraMetadata_const_entry* entry) {
    ATRACE_CALL();
    if (acm == nullptr || entry == nullptr) {
        ALOGE("%s: invalid argument! metadata 0x%p, tag 0x%x, entry 0x%p",
               __FUNCTION__, acm, tag, entry);
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    return acm->getConstEntry(tag, entry);
}

EXPORT
ACameraMetadata* ACameraMetadata_copy(const ACameraMetadata* src) {
    ATRACE_CALL();
    if (src == nullptr) {
        ALOGE("%s: src is null!", __FUNCTION__);
        return nullptr;
    }
    return new ACameraMetadata(*src);
}

EXPORT
void ACameraMetadata_free(ACameraMetadata* metadata) {
    ATRACE_CALL();
    if (metadata != nullptr) {
        delete metadata;
    }
}
Loading