Camera: Switch camera2 to auto-gen C++ binder interfaces
- Move camera service AIDL files to frameworks/av
- Build C++ interface stubs with AIDL tools
- Add necessary native-side parcelables and update existing ones
- Remove manually-written stubs, rearrange remaining manual stubs
- Adjust implementations to work with auto-generated stubs
- Adjust method signatures for auto-gen differences
- Add rich error messages using binder::Status
Bug: 25091611
Change-Id: I6f69f34b9d1a3f8d1fb7db87357363f8fa8483ff
diff --git a/camera/Android.mk b/camera/Android.mk
index de23953..b0df7c4 100644
--- a/camera/Android.mk
+++ b/camera/Android.mk
@@ -18,7 +18,24 @@
LOCAL_PATH := $(CAMERA_CLIENT_LOCAL_PATH)
-LOCAL_SRC_FILES:= \
+LOCAL_AIDL_INCLUDES := \
+ frameworks/av/camera/aidl \
+ frameworks/base/core/java \
+ frameworks/native/aidl/gui
+
+# AIDL files for camera interfaces
+# The headers for these interfaces will be available to any modules that
+# include libcamera_client, at the path "aidl/package/path/BnFoo.h"
+
+LOCAL_SRC_FILES := \
+ aidl/android/hardware/ICameraService.aidl \
+ aidl/android/hardware/ICameraServiceListener.aidl \
+ aidl/android/hardware/camera2/ICameraDeviceCallbacks.aidl \
+ aidl/android/hardware/camera2/ICameraDeviceUser.aidl
+
+# Source for camera interface parcelables, and manually-written interfaces
+
+LOCAL_SRC_FILES += \
Camera.cpp \
CameraMetadata.cpp \
CameraParameters.cpp \
@@ -26,15 +43,12 @@
CameraParameters2.cpp \
ICamera.cpp \
ICameraClient.cpp \
- ICameraService.cpp \
- ICameraServiceListener.cpp \
ICameraServiceProxy.cpp \
ICameraRecordingProxy.cpp \
ICameraRecordingProxyListener.cpp \
- camera2/ICameraDeviceUser.cpp \
- camera2/ICameraDeviceCallbacks.cpp \
camera2/CaptureRequest.cpp \
camera2/OutputConfiguration.cpp \
+ camera2/SubmitInfo.cpp \
CameraBase.cpp \
CameraUtils.cpp \
VendorTagDescriptor.cpp
@@ -53,6 +67,11 @@
system/media/camera/include \
system/media/private/camera/include \
frameworks/native/include/media/openmax \
+ frameworks/av/include/camera
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := \
+ system/media/camera/include \
+ frameworks/av/include/camera
LOCAL_MODULE:= libcamera_client
diff --git a/camera/Camera.cpp b/camera/Camera.cpp
index 1289348..8d7a107 100644
--- a/camera/Camera.cpp
+++ b/camera/Camera.cpp
@@ -24,10 +24,10 @@
#include <binder/IServiceManager.h>
#include <binder/IMemory.h>
-#include <camera/Camera.h>
-#include <camera/ICameraRecordingProxyListener.h>
-#include <camera/ICameraService.h>
-#include <camera/ICamera.h>
+#include <Camera.h>
+#include <ICameraRecordingProxyListener.h>
+#include <android/hardware/ICameraService.h>
+#include <android/hardware/ICamera.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/Surface.h>
@@ -40,10 +40,10 @@
}
CameraTraits<Camera>::TCamConnectService CameraTraits<Camera>::fnConnectService =
- &ICameraService::connect;
+ &::android::hardware::ICameraService::connect;
// construct a camera client from an existing camera remote
-sp<Camera> Camera::create(const sp<ICamera>& camera)
+sp<Camera> Camera::create(const sp<::android::hardware::ICamera>& camera)
{
ALOGV("create");
if (camera == 0) {
@@ -84,21 +84,23 @@
{
ALOGV("%s: connect legacy camera device", __FUNCTION__);
sp<Camera> c = new Camera(cameraId);
- sp<ICameraClient> cl = c;
+ sp<::android::hardware::ICameraClient> cl = c;
status_t status = NO_ERROR;
- const sp<ICameraService>& cs = CameraBaseT::getCameraService();
+ const sp<::android::hardware::ICameraService>& cs = CameraBaseT::getCameraService();
- if (cs != 0) {
- status = cs.get()->connectLegacy(cl, cameraId, halVersion, clientPackageName,
- clientUid, /*out*/c->mCamera);
+ binder::Status ret;
+ if (cs != nullptr) {
+ ret = cs.get()->connectLegacy(cl, cameraId, halVersion, clientPackageName,
+ clientUid, /*out*/&(c->mCamera));
}
- if (status == OK && c->mCamera != 0) {
+ if (ret.isOk() && c->mCamera != nullptr) {
IInterface::asBinder(c->mCamera)->linkToDeath(c);
c->mStatus = NO_ERROR;
camera = c;
} else {
- ALOGW("An error occurred while connecting to camera %d: %d (%s)",
- cameraId, status, strerror(-status));
+ ALOGW("An error occurred while connecting to camera %d: %s", cameraId,
+ (cs != nullptr) ? "Service not available" : ret.toString8().string());
+ status = -EINVAL;
c.clear();
}
return status;
@@ -107,21 +109,21 @@
status_t Camera::reconnect()
{
ALOGV("reconnect");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->connect(this);
}
status_t Camera::lock()
{
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->lock();
}
status_t Camera::unlock()
{
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->unlock();
}
@@ -130,7 +132,7 @@
status_t Camera::setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)
{
ALOGV("setPreviewTarget(%p)", bufferProducer.get());
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
ALOGD_IF(bufferProducer == 0, "app passed NULL surface");
return c->setPreviewTarget(bufferProducer);
@@ -139,7 +141,7 @@
status_t Camera::setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer)
{
ALOGV("setVideoTarget(%p)", bufferProducer.get());
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
ALOGD_IF(bufferProducer == 0, "app passed NULL video surface");
return c->setVideoTarget(bufferProducer);
@@ -149,7 +151,7 @@
status_t Camera::startPreview()
{
ALOGV("startPreview");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->startPreview();
}
@@ -157,7 +159,7 @@
status_t Camera::setVideoBufferMode(int32_t videoBufferMode)
{
ALOGV("setVideoBufferMode: %d", videoBufferMode);
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->setVideoBufferMode(videoBufferMode);
}
@@ -166,7 +168,7 @@
status_t Camera::startRecording()
{
ALOGV("startRecording");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->startRecording();
}
@@ -175,7 +177,7 @@
void Camera::stopPreview()
{
ALOGV("stopPreview");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return;
c->stopPreview();
}
@@ -188,7 +190,7 @@
Mutex::Autolock _l(mLock);
mRecordingProxyListener.clear();
}
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return;
c->stopRecording();
}
@@ -197,7 +199,7 @@
void Camera::releaseRecordingFrame(const sp<IMemory>& mem)
{
ALOGV("releaseRecordingFrame");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return;
c->releaseRecordingFrame(mem);
}
@@ -206,7 +208,7 @@
bool Camera::previewEnabled()
{
ALOGV("previewEnabled");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return false;
return c->previewEnabled();
}
@@ -215,7 +217,7 @@
bool Camera::recordingEnabled()
{
ALOGV("recordingEnabled");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return false;
return c->recordingEnabled();
}
@@ -223,7 +225,7 @@
status_t Camera::autoFocus()
{
ALOGV("autoFocus");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->autoFocus();
}
@@ -231,7 +233,7 @@
status_t Camera::cancelAutoFocus()
{
ALOGV("cancelAutoFocus");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->cancelAutoFocus();
}
@@ -240,7 +242,7 @@
status_t Camera::takePicture(int msgType)
{
ALOGV("takePicture: 0x%x", msgType);
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->takePicture(msgType);
}
@@ -249,7 +251,7 @@
status_t Camera::setParameters(const String8& params)
{
ALOGV("setParameters");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->setParameters(params);
}
@@ -259,7 +261,7 @@
{
ALOGV("getParameters");
String8 params;
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c != 0) params = mCamera->getParameters();
return params;
}
@@ -268,7 +270,7 @@
status_t Camera::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
{
ALOGV("sendCommand");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->sendCommand(cmd, arg1, arg2);
}
@@ -288,7 +290,7 @@
void Camera::setPreviewCallbackFlags(int flag)
{
ALOGV("setPreviewCallbackFlags");
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return;
mCamera->setPreviewCallbackFlag(flag);
}
@@ -296,7 +298,7 @@
status_t Camera::setPreviewCallbackTarget(
const sp<IGraphicBufferProducer>& callbackProducer)
{
- sp <ICamera> c = mCamera;
+ sp <::android::hardware::ICamera> c = mCamera;
if (c == 0) return NO_INIT;
return c->setPreviewCallbackTarget(callbackProducer);
}
diff --git a/camera/CameraBase.cpp b/camera/CameraBase.cpp
index 9ee7ae5..9aa0b4e 100644
--- a/camera/CameraBase.cpp
+++ b/camera/CameraBase.cpp
@@ -21,12 +21,13 @@
#include <utils/threads.h>
#include <utils/Mutex.h>
+#include <android/hardware/ICameraService.h>
+
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/IMemory.h>
#include <camera/CameraBase.h>
-#include <camera/ICameraService.h>
// needed to instantiate
#include <camera/Camera.h>
@@ -35,8 +36,28 @@
namespace android {
+namespace hardware {
+
+status_t CameraInfo::writeToParcel(Parcel* parcel) const {
+ status_t res;
+ res = parcel->writeInt32(facing);
+ if (res != OK) return res;
+ res = parcel->writeInt32(orientation);
+ return res;
+}
+
+status_t CameraInfo::readFromParcel(const Parcel* parcel) {
+ status_t res;
+ res = parcel->readInt32(&facing);
+ if (res != OK) return res;
+ res = parcel->readInt32(&orientation);
+ return res;
+}
+
+}
+
namespace {
- sp<ICameraService> gCameraService;
+ sp<::android::hardware::ICameraService> gCameraService;
const int kCameraServicePollDelay = 500000; // 0.5s
const char* kCameraServiceName = "media.camera";
@@ -65,7 +86,7 @@
// establish binder interface to camera service
template <typename TCam, typename TCamTraits>
-const sp<ICameraService>& CameraBase<TCam, TCamTraits>::getCameraService()
+const sp<::android::hardware::ICameraService>& CameraBase<TCam, TCamTraits>::getCameraService()
{
Mutex::Autolock _l(gLock);
if (gCameraService.get() == 0) {
@@ -83,7 +104,7 @@
gDeathNotifier = new DeathNotifier();
}
binder->linkToDeath(gDeathNotifier);
- gCameraService = interface_cast<ICameraService>(binder);
+ gCameraService = interface_cast<::android::hardware::ICameraService>(binder);
}
ALOGE_IF(gCameraService == 0, "no CameraService!?");
return gCameraService;
@@ -98,18 +119,20 @@
sp<TCam> c = new TCam(cameraId);
sp<TCamCallbacks> cl = c;
status_t status = NO_ERROR;
- const sp<ICameraService>& cs = getCameraService();
+ const sp<::android::hardware::ICameraService>& cs = getCameraService();
- if (cs != 0) {
+ binder::Status ret;
+ if (cs != nullptr) {
TCamConnectService fnConnectService = TCamTraits::fnConnectService;
- status = (cs.get()->*fnConnectService)(cl, cameraId, clientPackageName, clientUid,
- clientPid, /*out*/ c->mCamera);
+ ret = (cs.get()->*fnConnectService)(cl, cameraId, clientPackageName, clientUid,
+ clientPid, /*out*/ &c->mCamera);
}
- if (status == OK && c->mCamera != 0) {
+ if (ret.isOk() && c->mCamera != nullptr) {
IInterface::asBinder(c->mCamera)->linkToDeath(c);
c->mStatus = NO_ERROR;
} else {
- ALOGW("An error occurred while connecting to camera: %d", cameraId);
+ ALOGW("An error occurred while connecting to camera %d: %s", cameraId,
+ (cs != nullptr) ? "Service not available" : ret.toString8().string());
c.clear();
}
return c;
@@ -182,38 +205,50 @@
template <typename TCam, typename TCamTraits>
int CameraBase<TCam, TCamTraits>::getNumberOfCameras() {
- const sp<ICameraService> cs = getCameraService();
+ const sp<::android::hardware::ICameraService> cs = getCameraService();
if (!cs.get()) {
// as required by the public Java APIs
return 0;
}
- return cs->getNumberOfCameras();
+ int32_t count;
+ binder::Status res = cs->getNumberOfCameras(
+ ::android::hardware::ICameraService::CAMERA_TYPE_BACKWARD_COMPATIBLE,
+ &count);
+ if (!res.isOk()) {
+ ALOGE("Error reading number of cameras: %s",
+ res.toString8().string());
+ count = 0;
+ }
+ return count;
}
// this can be in BaseCamera but it should be an instance method
template <typename TCam, typename TCamTraits>
status_t CameraBase<TCam, TCamTraits>::getCameraInfo(int cameraId,
- struct CameraInfo* cameraInfo) {
- const sp<ICameraService>& cs = getCameraService();
+ struct hardware::CameraInfo* cameraInfo) {
+ const sp<::android::hardware::ICameraService>& cs = getCameraService();
if (cs == 0) return UNKNOWN_ERROR;
- return cs->getCameraInfo(cameraId, cameraInfo);
+ binder::Status res = cs->getCameraInfo(cameraId, cameraInfo);
+ return res.isOk() ? OK : res.serviceSpecificErrorCode();
}
template <typename TCam, typename TCamTraits>
status_t CameraBase<TCam, TCamTraits>::addServiceListener(
- const sp<ICameraServiceListener>& listener) {
- const sp<ICameraService>& cs = getCameraService();
+ const sp<::android::hardware::ICameraServiceListener>& listener) {
+ const sp<::android::hardware::ICameraService>& cs = getCameraService();
if (cs == 0) return UNKNOWN_ERROR;
- return cs->addListener(listener);
+ binder::Status res = cs->addListener(listener);
+ return res.isOk() ? OK : res.serviceSpecificErrorCode();
}
template <typename TCam, typename TCamTraits>
status_t CameraBase<TCam, TCamTraits>::removeServiceListener(
- const sp<ICameraServiceListener>& listener) {
- const sp<ICameraService>& cs = getCameraService();
+ const sp<::android::hardware::ICameraServiceListener>& listener) {
+ const sp<::android::hardware::ICameraService>& cs = getCameraService();
if (cs == 0) return UNKNOWN_ERROR;
- return cs->removeListener(listener);
+ binder::Status res = cs->removeListener(listener);
+ return res.isOk() ? OK : res.serviceSpecificErrorCode();
}
template class CameraBase<Camera>;
diff --git a/camera/CameraMetadata.cpp b/camera/CameraMetadata.cpp
index 46bcc1d..fad57ba 100644
--- a/camera/CameraMetadata.cpp
+++ b/camera/CameraMetadata.cpp
@@ -621,7 +621,7 @@
return res;
}
-status_t CameraMetadata::readFromParcel(Parcel *parcel) {
+status_t CameraMetadata::readFromParcel(const Parcel *parcel) {
ALOGV("%s: parcel = %p", __FUNCTION__, parcel);
diff --git a/camera/CaptureResult.cpp b/camera/CaptureResult.cpp
index 4e36160..58d9b43 100644
--- a/camera/CaptureResult.cpp
+++ b/camera/CaptureResult.cpp
@@ -26,7 +26,7 @@
return requestId >= 0;
}
-status_t CaptureResultExtras::readFromParcel(Parcel *parcel) {
+status_t CaptureResultExtras::readFromParcel(const Parcel *parcel) {
if (parcel == NULL) {
ALOGE("%s: Null parcel", __FUNCTION__);
return BAD_VALUE;
diff --git a/camera/ICamera.cpp b/camera/ICamera.cpp
index 1dd8912..37b0a10 100644
--- a/camera/ICamera.cpp
+++ b/camera/ICamera.cpp
@@ -22,12 +22,14 @@
#include <sys/types.h>
#include <binder/Parcel.h>
#include <camera/CameraUtils.h>
-#include <camera/ICamera.h>
+#include <android/hardware/ICamera.h>
+#include <android/hardware/ICameraClient.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/Surface.h>
#include <media/hardware/HardwareAPI.h>
namespace android {
+namespace hardware {
enum {
DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
@@ -63,13 +65,14 @@
}
// disconnect from camera service
- void disconnect()
+ binder::Status disconnect()
{
ALOGV("disconnect");
Parcel data, reply;
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
remote()->transact(DISCONNECT, data, &reply);
reply.readExceptionCode();
+ return binder::Status::ok();
}
// pass the buffered IGraphicBufferProducer to the camera service
@@ -467,4 +470,5 @@
// ----------------------------------------------------------------------------
-}; // namespace android
+} // namespace hardware
+} // namespace android
diff --git a/camera/ICameraClient.cpp b/camera/ICameraClient.cpp
index 4282f9a..d058138 100644
--- a/camera/ICameraClient.cpp
+++ b/camera/ICameraClient.cpp
@@ -21,10 +21,11 @@
#include <stdint.h>
#include <sys/types.h>
#include <camera/CameraUtils.h>
-#include <camera/ICameraClient.h>
+#include <android/hardware/ICameraClient.h>
#include <media/hardware/HardwareAPI.h>
namespace android {
+namespace hardware {
enum {
NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
@@ -150,5 +151,5 @@
// ----------------------------------------------------------------------------
-}; // namespace android
-
+} // namespace hardware
+} // namespace android
diff --git a/camera/ICameraService.cpp b/camera/ICameraService.cpp
deleted file mode 100644
index 4a042a6..0000000
--- a/camera/ICameraService.cpp
+++ /dev/null
@@ -1,536 +0,0 @@
-/*
-**
-** Copyright 2008, 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_TAG "BpCameraService"
-#include <utils/Log.h>
-#include <utils/Errors.h>
-#include <utils/String16.h>
-
-#include <inttypes.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <binder/Parcel.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-
-#include <camera/ICameraService.h>
-#include <camera/ICameraServiceListener.h>
-#include <camera/ICamera.h>
-#include <camera/ICameraClient.h>
-#include <camera/camera2/ICameraDeviceUser.h>
-#include <camera/camera2/ICameraDeviceCallbacks.h>
-#include <camera/CameraMetadata.h>
-#include <camera/VendorTagDescriptor.h>
-
-namespace android {
-
-namespace {
-
-enum {
- EX_SECURITY = -1,
- EX_BAD_PARCELABLE = -2,
- EX_ILLEGAL_ARGUMENT = -3,
- EX_NULL_POINTER = -4,
- EX_ILLEGAL_STATE = -5,
- EX_HAS_REPLY_HEADER = -128, // special; see below
-};
-
-static bool readExceptionCode(Parcel& reply) {
- int32_t exceptionCode = reply.readExceptionCode();
-
- if (exceptionCode != 0) {
- const char* errorMsg;
- switch(exceptionCode) {
- case EX_SECURITY:
- errorMsg = "Security";
- break;
- case EX_BAD_PARCELABLE:
- errorMsg = "BadParcelable";
- break;
- case EX_NULL_POINTER:
- errorMsg = "NullPointer";
- break;
- case EX_ILLEGAL_STATE:
- errorMsg = "IllegalState";
- break;
- // Binder should be handling this code inside Parcel::readException
- // but lets have a to-string here anyway just in case.
- case EX_HAS_REPLY_HEADER:
- errorMsg = "HasReplyHeader";
- break;
- default:
- errorMsg = "Unknown";
- }
-
- ALOGE("Binder transmission error %s (%d)", errorMsg, exceptionCode);
- return true;
- }
-
- return false;
-}
-
-};
-
-class BpCameraService: public BpInterface<ICameraService>
-{
-public:
- BpCameraService(const sp<IBinder>& impl)
- : BpInterface<ICameraService>(impl)
- {
- }
-
- // get number of cameras available that support standard camera operations
- virtual int32_t getNumberOfCameras()
- {
- return getNumberOfCameras(CAMERA_TYPE_BACKWARD_COMPATIBLE);
- }
-
- // get number of cameras available of a given type
- virtual int32_t getNumberOfCameras(int type)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- data.writeInt32(type);
- remote()->transact(BnCameraService::GET_NUMBER_OF_CAMERAS, data, &reply);
-
- if (readExceptionCode(reply)) return 0;
- return reply.readInt32();
- }
-
- // get information about a camera
- virtual status_t getCameraInfo(int cameraId,
- struct CameraInfo* cameraInfo) {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- data.writeInt32(cameraId);
- remote()->transact(BnCameraService::GET_CAMERA_INFO, data, &reply);
-
- if (readExceptionCode(reply)) return -EPROTO;
- status_t result = reply.readInt32();
- if (reply.readInt32() != 0) {
- cameraInfo->facing = reply.readInt32();
- cameraInfo->orientation = reply.readInt32();
- }
- return result;
- }
-
- // get camera characteristics (static metadata)
- virtual status_t getCameraCharacteristics(int cameraId,
- CameraMetadata* cameraInfo) {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- data.writeInt32(cameraId);
- remote()->transact(BnCameraService::GET_CAMERA_CHARACTERISTICS, data, &reply);
-
- if (readExceptionCode(reply)) return -EPROTO;
- status_t result = reply.readInt32();
-
- CameraMetadata out;
- if (reply.readInt32() != 0) {
- out.readFromParcel(&reply);
- }
-
- if (cameraInfo != NULL) {
- cameraInfo->swap(out);
- }
-
- return result;
- }
-
- // Get enumeration and description of vendor tags for camera
- virtual status_t getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescriptor>& desc) {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- remote()->transact(BnCameraService::GET_CAMERA_VENDOR_TAG_DESCRIPTOR, data, &reply);
-
- if (readExceptionCode(reply)) return -EPROTO;
- status_t result = reply.readInt32();
-
- if (reply.readInt32() != 0) {
- sp<VendorTagDescriptor> d;
- if (VendorTagDescriptor::createFromParcel(&reply, /*out*/d) == OK) {
- desc = d;
- }
- }
- return result;
- }
-
- // connect to camera service (android.hardware.Camera)
- virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
- const String16 &clientPackageName, int clientUid, int clientPid,
- /*out*/
- sp<ICamera>& device)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- data.writeStrongBinder(IInterface::asBinder(cameraClient));
- data.writeInt32(cameraId);
- data.writeString16(clientPackageName);
- data.writeInt32(clientUid);
- data.writeInt32(clientPid);
-
- status_t status;
- status = remote()->transact(BnCameraService::CONNECT, data, &reply);
- if (status != OK) return status;
-
- if (readExceptionCode(reply)) return -EPROTO;
- status = reply.readInt32();
- if (reply.readInt32() != 0) {
- device = interface_cast<ICamera>(reply.readStrongBinder());
- }
- return status;
- }
-
- // connect to camera service (android.hardware.Camera)
- virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId,
- int halVersion,
- const String16 &clientPackageName, int clientUid,
- /*out*/sp<ICamera>& device)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- data.writeStrongBinder(IInterface::asBinder(cameraClient));
- data.writeInt32(cameraId);
- data.writeInt32(halVersion);
- data.writeString16(clientPackageName);
- data.writeInt32(clientUid);
-
- status_t status;
- status = remote()->transact(BnCameraService::CONNECT_LEGACY, data, &reply);
- if (status != OK) return status;
-
- if (readExceptionCode(reply)) return -EPROTO;
- status = reply.readInt32();
- if (reply.readInt32() != 0) {
- device = interface_cast<ICamera>(reply.readStrongBinder());
- }
- return status;
- }
-
- virtual status_t setTorchMode(const String16& cameraId, bool enabled,
- const sp<IBinder>& clientBinder)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- data.writeString16(cameraId);
- data.writeInt32(enabled ? 1 : 0);
- data.writeStrongBinder(clientBinder);
- remote()->transact(BnCameraService::SET_TORCH_MODE, data, &reply);
-
- if (readExceptionCode(reply)) return -EPROTO;
- return reply.readInt32();
- }
-
- // connect to camera service (android.hardware.camera2.CameraDevice)
- virtual status_t connectDevice(
- const sp<ICameraDeviceCallbacks>& cameraCb,
- int cameraId,
- const String16& clientPackageName,
- int clientUid,
- /*out*/
- sp<ICameraDeviceUser>& device)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- data.writeStrongBinder(IInterface::asBinder(cameraCb));
- data.writeInt32(cameraId);
- data.writeString16(clientPackageName);
- data.writeInt32(clientUid);
-
- status_t status;
- status = remote()->transact(BnCameraService::CONNECT_DEVICE, data, &reply);
- if (status != OK) return status;
-
- if (readExceptionCode(reply)) return -EPROTO;
- status = reply.readInt32();
- if (reply.readInt32() != 0) {
- device = interface_cast<ICameraDeviceUser>(reply.readStrongBinder());
- }
- return status;
- }
-
- virtual status_t addListener(const sp<ICameraServiceListener>& listener)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- data.writeStrongBinder(IInterface::asBinder(listener));
- remote()->transact(BnCameraService::ADD_LISTENER, data, &reply);
-
- if (readExceptionCode(reply)) return -EPROTO;
- return reply.readInt32();
- }
-
- virtual status_t removeListener(const sp<ICameraServiceListener>& listener)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- data.writeStrongBinder(IInterface::asBinder(listener));
- remote()->transact(BnCameraService::REMOVE_LISTENER, data, &reply);
-
- if (readExceptionCode(reply)) return -EPROTO;
- return reply.readInt32();
- }
-
- virtual status_t getLegacyParameters(int cameraId, String16* parameters) {
- if (parameters == NULL) {
- ALOGE("%s: parameters must not be null", __FUNCTION__);
- return BAD_VALUE;
- }
-
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
-
- data.writeInt32(cameraId);
- remote()->transact(BnCameraService::GET_LEGACY_PARAMETERS, data, &reply);
- if (readExceptionCode(reply)) return -EPROTO;
-
- status_t res = data.readInt32();
- int32_t length = data.readInt32(); // -1 means null
- if (length > 0) {
- *parameters = data.readString16();
- } else {
- *parameters = String16();
- }
-
- return res;
- }
-
- virtual status_t supportsCameraApi(int cameraId, int apiVersion) {
- Parcel data, reply;
-
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- data.writeInt32(cameraId);
- data.writeInt32(apiVersion);
- remote()->transact(BnCameraService::SUPPORTS_CAMERA_API, data, &reply);
- if (readExceptionCode(reply)) return -EPROTO;
-
- status_t res = data.readInt32();
- return res;
- }
-
- virtual void notifySystemEvent(int32_t eventId, const int32_t* args, size_t len) {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
- data.writeInt32(eventId);
- data.writeInt32Array(len, args);
- remote()->transact(BnCameraService::NOTIFY_SYSTEM_EVENT, data, &reply,
- IBinder::FLAG_ONEWAY);
- }
-
-};
-
-IMPLEMENT_META_INTERFACE(CameraService, "android.hardware.ICameraService");
-
-// ----------------------------------------------------------------------
-
-status_t BnCameraService::onTransact(
- uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
- switch(code) {
- case GET_NUMBER_OF_CAMERAS: {
- CHECK_INTERFACE(ICameraService, data, reply);
- reply->writeNoException();
- reply->writeInt32(getNumberOfCameras(data.readInt32()));
- return NO_ERROR;
- } break;
- case GET_CAMERA_INFO: {
- CHECK_INTERFACE(ICameraService, data, reply);
- CameraInfo cameraInfo = CameraInfo();
- memset(&cameraInfo, 0, sizeof(cameraInfo));
- status_t result = getCameraInfo(data.readInt32(), &cameraInfo);
- reply->writeNoException();
- reply->writeInt32(result);
-
- // Fake a parcelable object here
- reply->writeInt32(1); // means the parcelable is included
- reply->writeInt32(cameraInfo.facing);
- reply->writeInt32(cameraInfo.orientation);
- return NO_ERROR;
- } break;
- case GET_CAMERA_CHARACTERISTICS: {
- CHECK_INTERFACE(ICameraService, data, reply);
- CameraMetadata info;
- status_t result = getCameraCharacteristics(data.readInt32(), &info);
- reply->writeNoException();
- reply->writeInt32(result);
-
- // out-variables are after exception and return value
- reply->writeInt32(1); // means the parcelable is included
- info.writeToParcel(reply);
- return NO_ERROR;
- } break;
- case GET_CAMERA_VENDOR_TAG_DESCRIPTOR: {
- CHECK_INTERFACE(ICameraService, data, reply);
- sp<VendorTagDescriptor> d;
- status_t result = getCameraVendorTagDescriptor(d);
- reply->writeNoException();
- reply->writeInt32(result);
-
- // out-variables are after exception and return value
- if (d == NULL) {
- reply->writeInt32(0);
- } else {
- reply->writeInt32(1); // means the parcelable is included
- d->writeToParcel(reply);
- }
- return NO_ERROR;
- } break;
- case CONNECT: {
- CHECK_INTERFACE(ICameraService, data, reply);
- sp<ICameraClient> cameraClient =
- interface_cast<ICameraClient>(data.readStrongBinder());
- int32_t cameraId = data.readInt32();
- const String16 clientName = data.readString16();
- int32_t clientUid = data.readInt32();
- int32_t clientPid = data.readInt32();
- sp<ICamera> camera;
- status_t status = connect(cameraClient, cameraId,
- clientName, clientUid, clientPid, /*out*/camera);
- reply->writeNoException();
- reply->writeInt32(status);
- if (camera != NULL) {
- reply->writeInt32(1);
- reply->writeStrongBinder(IInterface::asBinder(camera));
- } else {
- reply->writeInt32(0);
- }
- return NO_ERROR;
- } break;
- case CONNECT_DEVICE: {
- CHECK_INTERFACE(ICameraService, data, reply);
- sp<ICameraDeviceCallbacks> cameraClient =
- interface_cast<ICameraDeviceCallbacks>(data.readStrongBinder());
- int32_t cameraId = data.readInt32();
- const String16 clientName = data.readString16();
- int32_t clientUid = data.readInt32();
- sp<ICameraDeviceUser> camera;
- status_t status = connectDevice(cameraClient, cameraId,
- clientName, clientUid, /*out*/camera);
- reply->writeNoException();
- reply->writeInt32(status);
- if (camera != NULL) {
- reply->writeInt32(1);
- reply->writeStrongBinder(IInterface::asBinder(camera));
- } else {
- reply->writeInt32(0);
- }
- return NO_ERROR;
- } break;
- case ADD_LISTENER: {
- CHECK_INTERFACE(ICameraService, data, reply);
- sp<ICameraServiceListener> listener =
- interface_cast<ICameraServiceListener>(data.readStrongBinder());
- reply->writeNoException();
- reply->writeInt32(addListener(listener));
- return NO_ERROR;
- } break;
- case REMOVE_LISTENER: {
- CHECK_INTERFACE(ICameraService, data, reply);
- sp<ICameraServiceListener> listener =
- interface_cast<ICameraServiceListener>(data.readStrongBinder());
- reply->writeNoException();
- reply->writeInt32(removeListener(listener));
- return NO_ERROR;
- } break;
- case GET_LEGACY_PARAMETERS: {
- CHECK_INTERFACE(ICameraService, data, reply);
- int cameraId = data.readInt32();
- String16 parameters;
-
- reply->writeNoException();
- // return value
- reply->writeInt32(getLegacyParameters(cameraId, ¶meters));
- // out parameters
- reply->writeInt32(1); // parameters is always available
- reply->writeString16(parameters);
- return NO_ERROR;
- } break;
- case SUPPORTS_CAMERA_API: {
- CHECK_INTERFACE(ICameraService, data, reply);
- int cameraId = data.readInt32();
- int apiVersion = data.readInt32();
-
- reply->writeNoException();
- // return value
- reply->writeInt32(supportsCameraApi(cameraId, apiVersion));
- return NO_ERROR;
- } break;
- case CONNECT_LEGACY: {
- CHECK_INTERFACE(ICameraService, data, reply);
- sp<ICameraClient> cameraClient =
- interface_cast<ICameraClient>(data.readStrongBinder());
- int32_t cameraId = data.readInt32();
- int32_t halVersion = data.readInt32();
- const String16 clientName = data.readString16();
- int32_t clientUid = data.readInt32();
- sp<ICamera> camera;
- status_t status = connectLegacy(cameraClient, cameraId, halVersion,
- clientName, clientUid, /*out*/camera);
- reply->writeNoException();
- reply->writeInt32(status);
- if (camera != NULL) {
- reply->writeInt32(1);
- reply->writeStrongBinder(IInterface::asBinder(camera));
- } else {
- reply->writeInt32(0);
- }
- return NO_ERROR;
- } break;
- case SET_TORCH_MODE: {
- CHECK_INTERFACE(ICameraService, data, reply);
- String16 cameraId = data.readString16();
- bool enabled = data.readInt32() != 0 ? true : false;
- const sp<IBinder> clientBinder = data.readStrongBinder();
- status_t status = setTorchMode(cameraId, enabled, clientBinder);
- reply->writeNoException();
- reply->writeInt32(status);
- return NO_ERROR;
- } break;
- case NOTIFY_SYSTEM_EVENT: {
- CHECK_INTERFACE(ICameraService, data, reply);
- int32_t eventId = data.readInt32();
- int32_t len = data.readInt32();
- if (len < 0) {
- ALOGE("%s: Received poorly formatted length in binder request: notifySystemEvent.",
- __FUNCTION__);
- return FAILED_TRANSACTION;
- }
- if (len > 512) {
- ALOGE("%s: Length %" PRIi32 " too long in binder request: notifySystemEvent.",
- __FUNCTION__, len);
- return FAILED_TRANSACTION;
- }
- int32_t events[len];
- memset(events, 0, sizeof(int32_t) * len);
- status_t status = data.read(events, sizeof(int32_t) * len);
- if (status != NO_ERROR) {
- ALOGE("%s: Received poorly formatted binder request: notifySystemEvent.",
- __FUNCTION__);
- return FAILED_TRANSACTION;
- }
- notifySystemEvent(eventId, events, len);
- return NO_ERROR;
- } break;
- default:
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/camera/ICameraServiceListener.cpp b/camera/ICameraServiceListener.cpp
deleted file mode 100644
index 0010325..0000000
--- a/camera/ICameraServiceListener.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
-**
-** Copyright 2013, 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.
-*/
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <binder/Parcel.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-
-#include <camera/ICameraServiceListener.h>
-
-namespace android {
-
-namespace {
- enum {
- STATUS_CHANGED = IBinder::FIRST_CALL_TRANSACTION,
- TORCH_STATUS_CHANGED,
- };
-}; // namespace anonymous
-
-class BpCameraServiceListener: public BpInterface<ICameraServiceListener>
-{
-
-public:
- BpCameraServiceListener(const sp<IBinder>& impl)
- : BpInterface<ICameraServiceListener>(impl)
- {
- }
-
- virtual void onStatusChanged(Status status, int32_t cameraId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraServiceListener::getInterfaceDescriptor());
-
- data.writeInt32(static_cast<int32_t>(status));
- data.writeInt32(cameraId);
-
- remote()->transact(STATUS_CHANGED,
- data,
- &reply,
- IBinder::FLAG_ONEWAY);
- }
-
- virtual void onTorchStatusChanged(TorchStatus status, const String16 &cameraId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraServiceListener::getInterfaceDescriptor());
-
- data.writeInt32(static_cast<int32_t>(status));
- data.writeString16(cameraId);
-
- remote()->transact(TORCH_STATUS_CHANGED,
- data,
- &reply,
- IBinder::FLAG_ONEWAY);
- }
-};
-
-IMPLEMENT_META_INTERFACE(CameraServiceListener, "android.hardware.ICameraServiceListener");
-
-// ----------------------------------------------------------------------
-
-status_t BnCameraServiceListener::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
- uint32_t flags) {
- switch(code) {
- case STATUS_CHANGED: {
- CHECK_INTERFACE(ICameraServiceListener, data, reply);
-
- Status status = static_cast<Status>(data.readInt32());
- int32_t cameraId = data.readInt32();
-
- onStatusChanged(status, cameraId);
-
- return NO_ERROR;
- } break;
- case TORCH_STATUS_CHANGED: {
- CHECK_INTERFACE(ICameraServiceListener, data, reply);
-
- TorchStatus status = static_cast<TorchStatus>(data.readInt32());
- String16 cameraId = data.readString16();
-
- onTorchStatusChanged(status, cameraId);
-
- return NO_ERROR;
- } break;
- default:
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/camera/VendorTagDescriptor.cpp b/camera/VendorTagDescriptor.cpp
index dce313a..de69a5b 100644
--- a/camera/VendorTagDescriptor.cpp
+++ b/camera/VendorTagDescriptor.cpp
@@ -46,7 +46,9 @@
static Mutex sLock;
static sp<VendorTagDescriptor> sGlobalVendorTagDescriptor;
-VendorTagDescriptor::VendorTagDescriptor() {}
+namespace hardware {
+namespace camera2 {
+namespace params {
VendorTagDescriptor::~VendorTagDescriptor() {
size_t len = mReverseMapping.size();
@@ -55,90 +57,46 @@
}
}
-status_t VendorTagDescriptor::createDescriptorFromOps(const vendor_tag_ops_t* vOps,
- /*out*/
- sp<VendorTagDescriptor>& descriptor) {
- if (vOps == NULL) {
- ALOGE("%s: vendor_tag_ops argument was NULL.", __FUNCTION__);
- return BAD_VALUE;
- }
-
- int tagCount = vOps->get_tag_count(vOps);
- if (tagCount < 0 || tagCount > INT32_MAX) {
- ALOGE("%s: tag count %d from vendor ops is invalid.", __FUNCTION__, tagCount);
- return BAD_VALUE;
- }
-
- Vector<uint32_t> tagArray;
- LOG_ALWAYS_FATAL_IF(tagArray.resize(tagCount) != tagCount,
- "%s: too many (%u) vendor tags defined.", __FUNCTION__, tagCount);
-
- vOps->get_all_tags(vOps, /*out*/tagArray.editArray());
-
- sp<VendorTagDescriptor> desc = new VendorTagDescriptor();
- desc->mTagCount = tagCount;
-
- SortedVector<String8> sections;
- KeyedVector<uint32_t, String8> tagToSectionMap;
-
- for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
- uint32_t tag = tagArray[i];
- if (tag < CAMERA_METADATA_VENDOR_TAG_BOUNDARY) {
- ALOGE("%s: vendor tag %d not in vendor tag section.", __FUNCTION__, tag);
- return BAD_VALUE;
- }
- const char *tagName = vOps->get_tag_name(vOps, tag);
- if (tagName == NULL) {
- ALOGE("%s: no tag name defined for vendor tag %d.", __FUNCTION__, tag);
- return BAD_VALUE;
- }
- desc->mTagToNameMap.add(tag, String8(tagName));
- const char *sectionName = vOps->get_section_name(vOps, tag);
- if (sectionName == NULL) {
- ALOGE("%s: no section name defined for vendor tag %d.", __FUNCTION__, tag);
- return BAD_VALUE;
- }
-
- String8 sectionString(sectionName);
-
- sections.add(sectionString);
- tagToSectionMap.add(tag, sectionString);
-
- int tagType = vOps->get_tag_type(vOps, tag);
- if (tagType < 0 || tagType >= NUM_TYPES) {
- ALOGE("%s: tag type %d from vendor ops does not exist.", __FUNCTION__, tagType);
- return BAD_VALUE;
- }
- desc->mTagToTypeMap.add(tag, tagType);
- }
-
- desc->mSections = sections;
-
- for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
- uint32_t tag = tagArray[i];
- String8 sectionString = tagToSectionMap.valueFor(tag);
-
- // Set up tag to section index map
- ssize_t index = sections.indexOf(sectionString);
- LOG_ALWAYS_FATAL_IF(index < 0, "index %zd must be non-negative", index);
- desc->mTagToSectionMap.add(tag, static_cast<uint32_t>(index));
-
- // Set up reverse mapping
- ssize_t reverseIndex = -1;
- if ((reverseIndex = desc->mReverseMapping.indexOfKey(sectionString)) < 0) {
- KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>();
- reverseIndex = desc->mReverseMapping.add(sectionString, nameMapper);
- }
- desc->mReverseMapping[reverseIndex]->add(desc->mTagToNameMap.valueFor(tag), tag);
- }
-
- descriptor = desc;
- return OK;
+VendorTagDescriptor::VendorTagDescriptor() :
+ mTagCount(0),
+ mVendorOps({nullptr}) {
}
-status_t VendorTagDescriptor::createFromParcel(const Parcel* parcel,
- /*out*/
- sp<VendorTagDescriptor>& descriptor) {
+VendorTagDescriptor::VendorTagDescriptor(const VendorTagDescriptor& src) {
+ copyFrom(src);
+}
+
+VendorTagDescriptor& VendorTagDescriptor::operator=(const VendorTagDescriptor& rhs) {
+ copyFrom(rhs);
+ return *this;
+}
+
+void VendorTagDescriptor::copyFrom(const VendorTagDescriptor& src) {
+ if (this == &src) return;
+
+ size_t len = mReverseMapping.size();
+ for (size_t i = 0; i < len; ++i) {
+ delete mReverseMapping[i];
+ }
+ mReverseMapping.clear();
+
+ len = src.mReverseMapping.size();
+ // Have to copy KeyedVectors inside mReverseMapping
+ for (size_t i = 0; i < len; ++i) {
+ KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>();
+ *nameMapper = *(src.mReverseMapping.valueAt(i));
+ mReverseMapping.add(src.mReverseMapping.keyAt(i), nameMapper);
+ }
+ // Everything else is simple
+ mTagToNameMap = src.mTagToNameMap;
+ mTagToSectionMap = src.mTagToSectionMap;
+ mTagToTypeMap = src.mTagToTypeMap;
+ mSections = src.mSections;
+ mTagCount = src.mTagCount;
+ mVendorOps = src.mVendorOps;
+}
+
+status_t VendorTagDescriptor::readFromParcel(const Parcel* parcel) {
status_t res = OK;
if (parcel == NULL) {
ALOGE("%s: parcel argument was NULL.", __FUNCTION__);
@@ -156,8 +114,7 @@
return BAD_VALUE;
}
- sp<VendorTagDescriptor> desc = new VendorTagDescriptor();
- desc->mTagCount = tagCount;
+ mTagCount = tagCount;
uint32_t tag, sectionIndex;
uint32_t maxSectionIndex = 0;
@@ -197,9 +154,9 @@
maxSectionIndex = (maxSectionIndex >= sectionIndex) ? maxSectionIndex : sectionIndex;
allTags.add(tag);
- desc->mTagToNameMap.add(tag, tagName);
- desc->mTagToSectionMap.add(tag, sectionIndex);
- desc->mTagToTypeMap.add(tag, tagType);
+ mTagToNameMap.add(tag, tagName);
+ mTagToSectionMap.add(tag, sectionIndex);
+ mTagToTypeMap.add(tag, tagType);
}
if (res != OK) {
@@ -217,7 +174,7 @@
__FUNCTION__, sectionCount, (maxSectionIndex + 1));
return BAD_VALUE;
}
- LOG_ALWAYS_FATAL_IF(desc->mSections.setCapacity(sectionCount) <= 0,
+ LOG_ALWAYS_FATAL_IF(mSections.setCapacity(sectionCount) <= 0,
"Vector capacity must be positive");
for (size_t i = 0; i < sectionCount; ++i) {
String8 sectionName = parcel->readString8();
@@ -226,7 +183,7 @@
__FUNCTION__, i);
return NOT_ENOUGH_DATA;
}
- desc->mSections.add(sectionName);
+ mSections.add(sectionName);
}
}
@@ -235,17 +192,16 @@
// Set up reverse mapping
for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
uint32_t tag = allTags[i];
- String8 sectionString = desc->mSections[desc->mTagToSectionMap.valueFor(tag)];
+ String8 sectionString = mSections[mTagToSectionMap.valueFor(tag)];
ssize_t reverseIndex = -1;
- if ((reverseIndex = desc->mReverseMapping.indexOfKey(sectionString)) < 0) {
+ if ((reverseIndex = mReverseMapping.indexOfKey(sectionString)) < 0) {
KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>();
- reverseIndex = desc->mReverseMapping.add(sectionString, nameMapper);
+ reverseIndex = mReverseMapping.add(sectionString, nameMapper);
}
- desc->mReverseMapping[reverseIndex]->add(desc->mTagToNameMap.valueFor(tag), tag);
+ mReverseMapping[reverseIndex]->add(mTagToNameMap.valueFor(tag), tag);
}
- descriptor = desc;
return res;
}
@@ -377,6 +333,92 @@
}
+} // namespace params
+} // namespace camera2
+} // namespace hardware
+
+
+status_t VendorTagDescriptor::createDescriptorFromOps(const vendor_tag_ops_t* vOps,
+ /*out*/
+ sp<VendorTagDescriptor>& descriptor) {
+ if (vOps == NULL) {
+ ALOGE("%s: vendor_tag_ops argument was NULL.", __FUNCTION__);
+ return BAD_VALUE;
+ }
+
+ int tagCount = vOps->get_tag_count(vOps);
+ if (tagCount < 0 || tagCount > INT32_MAX) {
+ ALOGE("%s: tag count %d from vendor ops is invalid.", __FUNCTION__, tagCount);
+ return BAD_VALUE;
+ }
+
+ Vector<uint32_t> tagArray;
+ LOG_ALWAYS_FATAL_IF(tagArray.resize(tagCount) != tagCount,
+ "%s: too many (%u) vendor tags defined.", __FUNCTION__, tagCount);
+
+ vOps->get_all_tags(vOps, /*out*/tagArray.editArray());
+
+ sp<VendorTagDescriptor> desc = new VendorTagDescriptor();
+ desc->mTagCount = tagCount;
+
+ SortedVector<String8> sections;
+ KeyedVector<uint32_t, String8> tagToSectionMap;
+
+ for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
+ uint32_t tag = tagArray[i];
+ if (tag < CAMERA_METADATA_VENDOR_TAG_BOUNDARY) {
+ ALOGE("%s: vendor tag %d not in vendor tag section.", __FUNCTION__, tag);
+ return BAD_VALUE;
+ }
+ const char *tagName = vOps->get_tag_name(vOps, tag);
+ if (tagName == NULL) {
+ ALOGE("%s: no tag name defined for vendor tag %d.", __FUNCTION__, tag);
+ return BAD_VALUE;
+ }
+ desc->mTagToNameMap.add(tag, String8(tagName));
+ const char *sectionName = vOps->get_section_name(vOps, tag);
+ if (sectionName == NULL) {
+ ALOGE("%s: no section name defined for vendor tag %d.", __FUNCTION__, tag);
+ return BAD_VALUE;
+ }
+
+ String8 sectionString(sectionName);
+
+ sections.add(sectionString);
+ tagToSectionMap.add(tag, sectionString);
+
+ int tagType = vOps->get_tag_type(vOps, tag);
+ if (tagType < 0 || tagType >= NUM_TYPES) {
+ ALOGE("%s: tag type %d from vendor ops does not exist.", __FUNCTION__, tagType);
+ return BAD_VALUE;
+ }
+ desc->mTagToTypeMap.add(tag, tagType);
+ }
+
+ desc->mSections = sections;
+
+ for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
+ uint32_t tag = tagArray[i];
+ String8 sectionString = tagToSectionMap.valueFor(tag);
+
+ // Set up tag to section index map
+ ssize_t index = sections.indexOf(sectionString);
+ LOG_ALWAYS_FATAL_IF(index < 0, "index %zd must be non-negative", index);
+ desc->mTagToSectionMap.add(tag, static_cast<uint32_t>(index));
+
+ // Set up reverse mapping
+ ssize_t reverseIndex = -1;
+ if ((reverseIndex = desc->mReverseMapping.indexOfKey(sectionString)) < 0) {
+ KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>();
+ reverseIndex = desc->mReverseMapping.add(sectionString, nameMapper);
+ }
+ desc->mReverseMapping[reverseIndex]->add(desc->mTagToNameMap.valueFor(tag), tag);
+ }
+
+ descriptor = desc;
+ return OK;
+}
+
status_t VendorTagDescriptor::setAsGlobalVendorTagDescriptor(const sp<VendorTagDescriptor>& desc) {
status_t res = OK;
Mutex::Autolock al(sLock);
diff --git a/camera/aidl/android/hardware/CameraInfo.aidl b/camera/aidl/android/hardware/CameraInfo.aidl
new file mode 100644
index 0000000..c6a3a61
--- /dev/null
+++ b/camera/aidl/android/hardware/CameraInfo.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package android.hardware;
+
+/** @hide */
+parcelable CameraInfo cpp_header "camera/CameraBase.h";
diff --git a/camera/aidl/android/hardware/ICamera.aidl b/camera/aidl/android/hardware/ICamera.aidl
new file mode 100644
index 0000000..f9db842
--- /dev/null
+++ b/camera/aidl/android/hardware/ICamera.aidl
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package android.hardware;
+
+/** @hide */
+interface ICamera
+{
+ /**
+ * Only one call exposed, for ICameraService testing purposes
+ *
+ * Keep up-to-date with frameworks/av/include/camera/ICamera.h
+ */
+ void disconnect();
+}
diff --git a/camera/aidl/android/hardware/ICameraClient.aidl b/camera/aidl/android/hardware/ICameraClient.aidl
new file mode 100644
index 0000000..808edee
--- /dev/null
+++ b/camera/aidl/android/hardware/ICameraClient.aidl
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package android.hardware;
+
+/** @hide */
+interface ICameraClient
+{
+ // For now, empty because there is a manual implementation
+}
diff --git a/camera/aidl/android/hardware/ICameraService.aidl b/camera/aidl/android/hardware/ICameraService.aidl
new file mode 100644
index 0000000..e94fd0c
--- /dev/null
+++ b/camera/aidl/android/hardware/ICameraService.aidl
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package android.hardware;
+
+import android.hardware.ICamera;
+import android.hardware.ICameraClient;
+import android.hardware.camera2.ICameraDeviceUser;
+import android.hardware.camera2.ICameraDeviceCallbacks;
+import android.hardware.camera2.params.VendorTagDescriptor;
+import android.hardware.camera2.impl.CameraMetadataNative;
+import android.hardware.ICameraServiceListener;
+import android.hardware.CameraInfo;
+
+/**
+ * Binder interface for the native camera service running in mediaserver.
+ *
+ * @hide
+ */
+interface ICameraService
+{
+ /**
+ * All camera service and device Binder calls may return a
+ * ServiceSpecificException with the following error codes
+ */
+ const int ERROR_PERMISSION_DENIED = 1;
+ const int ERROR_ALREADY_EXISTS = 2;
+ const int ERROR_ILLEGAL_ARGUMENT = 3;
+ const int ERROR_DISCONNECTED = 4;
+ const int ERROR_TIMED_OUT = 5;
+ const int ERROR_DISABLED = 6;
+ const int ERROR_CAMERA_IN_USE = 7;
+ const int ERROR_MAX_CAMERAS_IN_USE = 8;
+ const int ERROR_DEPRECATED_HAL = 9;
+ const int ERROR_INVALID_OPERATION = 10;
+
+ /**
+ * Types for getNumberOfCameras
+ */
+ const int CAMERA_TYPE_BACKWARD_COMPATIBLE = 0;
+ const int CAMERA_TYPE_ALL = 1;
+
+ /**
+ * Return the number of camera devices available in the system
+ */
+ int getNumberOfCameras(int type);
+
+ /**
+ * Fetch basic camera information for a camera device
+ */
+ CameraInfo getCameraInfo(int cameraId);
+
+ /**
+ * Default UID/PID values for non-privileged callers of
+ * connect(), connectDevice(), and connectLegacy()
+ */
+ const int USE_CALLING_UID = -1;
+ const int USE_CALLING_PID = -1;
+
+ /**
+ * Open a camera device through the old camera API
+ */
+ ICamera connect(ICameraClient client,
+ int cameraId,
+ String opPackageName,
+ int clientUid, int clientPid);
+
+ /**
+ * Open a camera device through the new camera API
+ * Only supported for device HAL versions >= 3.2
+ */
+ ICameraDeviceUser connectDevice(ICameraDeviceCallbacks callbacks,
+ int cameraId,
+ String opPackageName,
+ int clientUid);
+
+ /**
+ * halVersion constant for connectLegacy
+ */
+ const int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1;
+
+ /**
+ * Open a camera device in legacy mode, if supported by the camera module HAL.
+ */
+ ICamera connectLegacy(ICameraClient client,
+ int cameraId,
+ int halVersion,
+ String opPackageName,
+ int clientUid);
+
+ /**
+ * Add/remove listeners for changes to camera device and flashlight state
+ */
+ void addListener(ICameraServiceListener listener);
+ void removeListener(ICameraServiceListener listener);
+
+ /**
+ * Read the static camera metadata for a camera device.
+ * Only supported for device HAL versions >= 3.2
+ */
+ CameraMetadataNative getCameraCharacteristics(int cameraId);
+
+ /**
+ * Read in the vendor tag descriptors from the camera module HAL.
+ * Intended to be used by the native code of CameraMetadataNative to correctly
+ * interpret camera metadata with vendor tags.
+ */
+ VendorTagDescriptor getCameraVendorTagDescriptor();
+
+ /**
+ * Read the legacy camera1 parameters into a String
+ */
+ String getLegacyParameters(int cameraId);
+
+ /**
+ * apiVersion constants for supportsCameraApi
+ */
+ const int API_VERSION_1 = 1;
+ const int API_VERSION_2 = 2;
+
+ // Determines if a particular API version is supported directly
+ boolean supportsCameraApi(int cameraId, int apiVersion);
+
+ void setTorchMode(String CameraId, boolean enabled, IBinder clientBinder);
+
+ /**
+ * Notify the camera service of a system event. Should only be called from system_server.
+ *
+ * Callers require the android.permission.CAMERA_SEND_SYSTEM_EVENTS permission.
+ */
+ const int EVENT_NONE = 0;
+ const int EVENT_USER_SWITCHED = 1;
+ oneway void notifySystemEvent(int eventId, in int[] args);
+}
diff --git a/camera/aidl/android/hardware/ICameraServiceListener.aidl b/camera/aidl/android/hardware/ICameraServiceListener.aidl
new file mode 100644
index 0000000..4e2a8c7
--- /dev/null
+++ b/camera/aidl/android/hardware/ICameraServiceListener.aidl
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package android.hardware;
+
+/** @hide */
+interface ICameraServiceListener
+{
+
+ /**
+ * Initial status will be transmitted with onStatusChange immediately
+ * after this listener is added to the service listener list.
+ *
+ * Allowed transitions:
+ *
+ * (Any) -> NOT_PRESENT
+ * NOT_PRESENT -> PRESENT
+ * NOT_PRESENT -> ENUMERATING
+ * ENUMERATING -> PRESENT
+ * PRESENT -> NOT_AVAILABLE
+ * NOT_AVAILABLE -> PRESENT
+ *
+ * A state will never immediately transition back to itself.
+ *
+ * The enums must match the values in
+ * include/hardware/camera_common.h when applicable
+ */
+ // Device physically unplugged
+ const int STATUS_NOT_PRESENT = 0;
+ // Device physically has been plugged in and the camera can be used exlusively
+ const int STATUS_PRESENT = 1;
+ // Device physically has been plugged in but it will not be connect-able until enumeration is
+ // complete
+ const int STATUS_ENUMERATING = 2;
+ // Camera is in use by another app and cannot be used exclusively
+ const int STATUS_NOT_AVAILABLE = -2;
+
+ // Use to initialize variables only
+ const int STATUS_UNKNOWN = -1;
+
+ oneway void onStatusChanged(int status, int cameraId);
+
+ /**
+ * The torch mode status of a camera.
+ *
+ * Initial status will be transmitted with onTorchStatusChanged immediately
+ * after this listener is added to the service listener list.
+ *
+ * The enums must match the values in
+ * include/hardware/camera_common.h
+ */
+ // The camera's torch mode has become not available to use via
+ // setTorchMode().
+ const int TORCH_STATUS_NOT_AVAILABLE = 0;
+ // The camera's torch mode is off and available to be turned on via
+ // setTorchMode().
+ const int TORCH_STATUS_AVAILABLE_OFF = 1;
+ // The camera's torch mode is on and available to be turned off via
+ // setTorchMode().
+ const int TORCH_STATUS_AVAILABLE_ON = 2;
+
+ // Use to initialize variables only
+ const int TORCH_STATUS_UNKNOWN = -1;
+
+ oneway void onTorchStatusChanged(int status, String cameraId);
+}
diff --git a/camera/aidl/android/hardware/ICameraServiceProxy.aidl b/camera/aidl/android/hardware/ICameraServiceProxy.aidl
new file mode 100644
index 0000000..0e654d5
--- /dev/null
+++ b/camera/aidl/android/hardware/ICameraServiceProxy.aidl
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+package android.hardware;
+
+/**
+ * Binder interface for the camera service proxy running in system_server.
+ *
+ * Keep in sync with frameworks/av/include/camera/ICameraServiceProxy.h
+ *
+ * @hide
+ */
+interface ICameraServiceProxy
+{
+ /**
+ * Ping the service proxy to update the valid users for the camera service.
+ */
+ oneway void pingForUserUpdate();
+
+ /**
+ * Update the status of a camera device
+ */
+ oneway void notifyCameraState(String cameraId, int newCameraState);
+}
diff --git a/camera/aidl/android/hardware/camera2/CaptureRequest.aidl b/camera/aidl/android/hardware/camera2/CaptureRequest.aidl
new file mode 100644
index 0000000..9931fc7
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/CaptureRequest.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package android.hardware.camera2;
+
+/** @hide */
+parcelable CaptureRequest cpp_header "camera/camera2/CaptureRequest.h";
diff --git a/camera/aidl/android/hardware/camera2/ICameraDeviceCallbacks.aidl b/camera/aidl/android/hardware/camera2/ICameraDeviceCallbacks.aidl
new file mode 100644
index 0000000..ab57db5
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/ICameraDeviceCallbacks.aidl
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+package android.hardware.camera2;
+
+import android.hardware.camera2.impl.CameraMetadataNative;
+import android.hardware.camera2.impl.CaptureResultExtras;
+
+/** @hide */
+interface ICameraDeviceCallbacks
+{
+ // Error codes for onDeviceError
+ const int ERROR_CAMERA_INVALID_ERROR = -1; // To indicate all invalid error codes
+ const int ERROR_CAMERA_DISCONNECTED = 0;
+ const int ERROR_CAMERA_DEVICE = 1;
+ const int ERROR_CAMERA_SERVICE = 2;
+ const int ERROR_CAMERA_REQUEST = 3;
+ const int ERROR_CAMERA_RESULT = 4;
+ const int ERROR_CAMERA_BUFFER = 5;
+
+ oneway void onDeviceError(int errorCode, in CaptureResultExtras resultExtras);
+ oneway void onDeviceIdle();
+ oneway void onCaptureStarted(in CaptureResultExtras resultExtras, long timestamp);
+ oneway void onResultReceived(in CameraMetadataNative result,
+ in CaptureResultExtras resultExtras);
+ oneway void onPrepared(int streamId);
+}
diff --git a/camera/aidl/android/hardware/camera2/ICameraDeviceUser.aidl b/camera/aidl/android/hardware/camera2/ICameraDeviceUser.aidl
new file mode 100644
index 0000000..250f15e
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/ICameraDeviceUser.aidl
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package android.hardware.camera2;
+
+import android.hardware.camera2.CaptureRequest;
+import android.hardware.camera2.impl.CameraMetadataNative;
+import android.hardware.camera2.params.OutputConfiguration;
+import android.hardware.camera2.utils.SubmitInfo;
+import android.view.Surface;
+
+/** @hide */
+interface ICameraDeviceUser
+{
+ void disconnect();
+
+ const int NO_IN_FLIGHT_REPEATING_FRAMES = -1;
+
+ SubmitInfo submitRequest(in CaptureRequest request, boolean streaming);
+ SubmitInfo submitRequestList(in CaptureRequest[] requestList, boolean streaming);
+
+ /**
+ * Cancel the repeating request specified by requestId
+ * Returns the frame number of the last frame that will be produced from this
+ * repeating request, or NO_IN_FLIGHT_REPEATING_FRAMES if no frames were produced
+ * by this repeating request
+ */
+ long cancelRequest(int requestId);
+
+ /**
+ * Begin the device configuration.
+ *
+ * <p>
+ * beginConfigure must be called before any call to deleteStream, createStream,
+ * or endConfigure. It is not valid to call this when the device is not idle.
+ * <p>
+ */
+ void beginConfigure();
+
+ /**
+ * End the device configuration.
+ *
+ * <p>
+ * endConfigure must be called after stream configuration is complete (i.e. after
+ * a call to beginConfigure and subsequent createStream/deleteStream calls). This
+ * must be called before any requests can be submitted.
+ * <p>
+ */
+ void endConfigure(boolean isConstrainedHighSpeed);
+
+ void deleteStream(int streamId);
+
+ /**
+ * Create an output stream
+ *
+ * <p>Create an output stream based on the given output configuration</p>
+ *
+ * @param outputConfiguration size, format, and other parameters for the stream
+ * @return new stream ID
+ */
+ int createStream(in OutputConfiguration outputConfiguration);
+
+ /**
+ * Create an input stream
+ *
+ * <p>Create an input stream of width, height, and format</p>
+ *
+ * @param width Width of the input buffers
+ * @param height Height of the input buffers
+ * @param format Format of the input buffers. One of HAL_PIXEL_FORMAT_*.
+ *
+ * @return new stream ID
+ */
+ int createInputStream(int width, int height, int format);
+
+ /**
+ * Get the surface of the input stream.
+ *
+ * <p>It's valid to call this method only after a stream configuration is completed
+ * successfully and the stream configuration includes a input stream.</p>
+ *
+ * @param surface An output argument for the surface of the input stream buffer queue.
+ */
+ Surface getInputSurface();
+
+ // Keep in sync with public API in
+ // frameworks/base/core/java/android/hardware/camera2/CameraDevice.java
+ const int TEMPLATE_PREVIEW = 1;
+ const int TEMPLATE_STILL_CAPTURE = 2;
+ const int TEMPLATE_RECORD = 3;
+ const int TEMPLATE_VIDEO_SNAPSHOT = 4;
+ const int TEMPLATE_ZERO_SHUTTER_LAG = 5;
+ const int TEMPLATE_MANUAL = 6;
+
+ CameraMetadataNative createDefaultRequest(int templateId);
+
+ CameraMetadataNative getCameraInfo();
+
+ void waitUntilIdle();
+
+ long flush();
+
+ void prepare(int streamId);
+
+ void tearDown(int streamId);
+
+ void prepare2(int maxCount, int streamId);
+}
diff --git a/camera/aidl/android/hardware/camera2/impl/CameraMetadataNative.aidl b/camera/aidl/android/hardware/camera2/impl/CameraMetadataNative.aidl
new file mode 100644
index 0000000..507f575
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/impl/CameraMetadataNative.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package android.hardware.camera2.impl;
+
+/** @hide */
+parcelable CameraMetadataNative cpp_header "camera/CameraMetadata.h";
diff --git a/camera/aidl/android/hardware/camera2/impl/CaptureResultExtras.aidl b/camera/aidl/android/hardware/camera2/impl/CaptureResultExtras.aidl
new file mode 100644
index 0000000..5f47eda
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/impl/CaptureResultExtras.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+package android.hardware.camera2.impl;
+
+/** @hide */
+parcelable CaptureResultExtras cpp_header "camera/CaptureResult.h";
diff --git a/camera/aidl/android/hardware/camera2/params/OutputConfiguration.aidl b/camera/aidl/android/hardware/camera2/params/OutputConfiguration.aidl
new file mode 100644
index 0000000..a8ad832
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/params/OutputConfiguration.aidl
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+package android.hardware.camera2.params;
+
+/** @hide */
+parcelable OutputConfiguration cpp_header "camera/camera2/OutputConfiguration.h";
diff --git a/camera/aidl/android/hardware/camera2/params/VendorTagDescriptor.aidl b/camera/aidl/android/hardware/camera2/params/VendorTagDescriptor.aidl
new file mode 100644
index 0000000..9ee4263
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/params/VendorTagDescriptor.aidl
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+package android.hardware.camera2.params;
+
+/** @hide */
+parcelable VendorTagDescriptor cpp_header "camera/VendorTagDescriptor.h";
diff --git a/camera/aidl/android/hardware/camera2/utils/SubmitInfo.aidl b/camera/aidl/android/hardware/camera2/utils/SubmitInfo.aidl
new file mode 100644
index 0000000..57531ad
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/utils/SubmitInfo.aidl
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+package android.hardware.camera2.utils;
+
+/** @hide */
+parcelable SubmitInfo cpp_header "camera/camera2/SubmitInfo.h";
diff --git a/camera/camera2/CaptureRequest.cpp b/camera/camera2/CaptureRequest.cpp
index 4217bc6..fb43708 100644
--- a/camera/camera2/CaptureRequest.cpp
+++ b/camera/camera2/CaptureRequest.cpp
@@ -25,8 +25,10 @@
#include <gui/Surface.h>
namespace android {
+namespace hardware {
+namespace camera2 {
-status_t CaptureRequest::readFromParcel(Parcel* parcel) {
+status_t CaptureRequest::readFromParcel(const Parcel* parcel) {
if (parcel == NULL) {
ALOGE("%s: Null parcel", __FUNCTION__);
return BAD_VALUE;
@@ -130,4 +132,6 @@
return OK;
}
-}; // namespace android
+} // namespace camera2
+} // namespace hardware
+} // namespace android
diff --git a/camera/camera2/ICameraDeviceCallbacks.cpp b/camera/camera2/ICameraDeviceCallbacks.cpp
deleted file mode 100644
index f599879..0000000
--- a/camera/camera2/ICameraDeviceCallbacks.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
-**
-** Copyright 2013, 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 "ICameraDeviceCallbacks"
-#include <utils/Log.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <binder/Parcel.h>
-#include <gui/IGraphicBufferProducer.h>
-#include <gui/Surface.h>
-#include <utils/Mutex.h>
-
-#include <camera/camera2/ICameraDeviceCallbacks.h>
-#include "camera/CameraMetadata.h"
-#include "camera/CaptureResult.h"
-
-namespace android {
-
-enum {
- CAMERA_ERROR = IBinder::FIRST_CALL_TRANSACTION,
- CAMERA_IDLE,
- CAPTURE_STARTED,
- RESULT_RECEIVED,
- PREPARED
-};
-
-class BpCameraDeviceCallbacks: public BpInterface<ICameraDeviceCallbacks>
-{
-public:
- BpCameraDeviceCallbacks(const sp<IBinder>& impl)
- : BpInterface<ICameraDeviceCallbacks>(impl)
- {
- }
-
- void onDeviceError(CameraErrorCode errorCode, const CaptureResultExtras& resultExtras)
- {
- ALOGV("onDeviceError");
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
- data.writeInt32(static_cast<int32_t>(errorCode));
- data.writeInt32(1); // to mark presence of CaptureResultExtras object
- resultExtras.writeToParcel(&data);
- remote()->transact(CAMERA_ERROR, data, &reply, IBinder::FLAG_ONEWAY);
- data.writeNoException();
- }
-
- void onDeviceIdle()
- {
- ALOGV("onDeviceIdle");
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
- remote()->transact(CAMERA_IDLE, data, &reply, IBinder::FLAG_ONEWAY);
- data.writeNoException();
- }
-
- void onCaptureStarted(const CaptureResultExtras& result, int64_t timestamp)
- {
- ALOGV("onCaptureStarted");
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
- data.writeInt32(1); // to mark presence of CaptureResultExtras object
- result.writeToParcel(&data);
- data.writeInt64(timestamp);
- remote()->transact(CAPTURE_STARTED, data, &reply, IBinder::FLAG_ONEWAY);
- data.writeNoException();
- }
-
- void onResultReceived(const CameraMetadata& metadata,
- const CaptureResultExtras& resultExtras) {
- ALOGV("onResultReceived");
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
- data.writeInt32(1); // to mark presence of metadata object
- metadata.writeToParcel(&data);
- data.writeInt32(1); // to mark presence of CaptureResult object
- resultExtras.writeToParcel(&data);
- remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY);
- data.writeNoException();
- }
-
- void onPrepared(int streamId)
- {
- ALOGV("onPrepared");
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor());
- data.writeInt32(streamId);
- remote()->transact(PREPARED, data, &reply, IBinder::FLAG_ONEWAY);
- data.writeNoException();
- }
-
-};
-
-IMPLEMENT_META_INTERFACE(CameraDeviceCallbacks,
- "android.hardware.camera2.ICameraDeviceCallbacks");
-
-// ----------------------------------------------------------------------
-
-status_t BnCameraDeviceCallbacks::onTransact(
- uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
- ALOGV("onTransact - code = %d", code);
- switch(code) {
- case CAMERA_ERROR: {
- ALOGV("onDeviceError");
- CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
- CameraErrorCode errorCode =
- static_cast<CameraErrorCode>(data.readInt32());
- CaptureResultExtras resultExtras;
- if (data.readInt32() != 0) {
- resultExtras.readFromParcel(const_cast<Parcel*>(&data));
- } else {
- ALOGE("No CaptureResultExtras object is present!");
- }
- onDeviceError(errorCode, resultExtras);
- data.readExceptionCode();
- return NO_ERROR;
- } break;
- case CAMERA_IDLE: {
- ALOGV("onDeviceIdle");
- CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
- onDeviceIdle();
- data.readExceptionCode();
- return NO_ERROR;
- } break;
- case CAPTURE_STARTED: {
- ALOGV("onCaptureStarted");
- CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
- CaptureResultExtras result;
- if (data.readInt32() != 0) {
- result.readFromParcel(const_cast<Parcel*>(&data));
- } else {
- ALOGE("No CaptureResultExtras object is present in result!");
- }
- int64_t timestamp = data.readInt64();
- onCaptureStarted(result, timestamp);
- data.readExceptionCode();
- return NO_ERROR;
- } break;
- case RESULT_RECEIVED: {
- ALOGV("onResultReceived");
- CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
- CameraMetadata metadata;
- if (data.readInt32() != 0) {
- metadata.readFromParcel(const_cast<Parcel*>(&data));
- } else {
- ALOGW("No metadata object is present in result");
- }
- CaptureResultExtras resultExtras;
- if (data.readInt32() != 0) {
- resultExtras.readFromParcel(const_cast<Parcel*>(&data));
- } else {
- ALOGW("No capture result extras object is present in result");
- }
- onResultReceived(metadata, resultExtras);
- data.readExceptionCode();
- return NO_ERROR;
- } break;
- case PREPARED: {
- ALOGV("onPrepared");
- CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply);
- CaptureResultExtras result;
- int streamId = data.readInt32();
- onPrepared(streamId);
- data.readExceptionCode();
- return NO_ERROR;
- } break;
- default:
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/camera/camera2/ICameraDeviceUser.cpp b/camera/camera2/ICameraDeviceUser.cpp
deleted file mode 100644
index 2a9fd2b..0000000
--- a/camera/camera2/ICameraDeviceUser.cpp
+++ /dev/null
@@ -1,626 +0,0 @@
-/*
-**
-** Copyright 2013, 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 "ICameraDeviceUser"
-#include <utils/Log.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <binder/Parcel.h>
-#include <camera/camera2/ICameraDeviceUser.h>
-#include <gui/IGraphicBufferProducer.h>
-#include <gui/Surface.h>
-#include <camera/CameraMetadata.h>
-#include <camera/camera2/CaptureRequest.h>
-#include <camera/camera2/OutputConfiguration.h>
-
-namespace android {
-
-typedef Parcel::WritableBlob WritableBlob;
-typedef Parcel::ReadableBlob ReadableBlob;
-
-enum {
- DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
- SUBMIT_REQUEST,
- SUBMIT_REQUEST_LIST,
- CANCEL_REQUEST,
- BEGIN_CONFIGURE,
- END_CONFIGURE,
- DELETE_STREAM,
- CREATE_STREAM,
- CREATE_INPUT_STREAM,
- GET_INPUT_SURFACE,
- CREATE_DEFAULT_REQUEST,
- GET_CAMERA_INFO,
- WAIT_UNTIL_IDLE,
- FLUSH,
- PREPARE,
- TEAR_DOWN,
- PREPARE2
-};
-
-namespace {
- // Read empty strings without printing a false error message.
- String16 readMaybeEmptyString16(const Parcel& parcel) {
- size_t len;
- const char16_t* str = parcel.readString16Inplace(&len);
- if (str != NULL) {
- return String16(str, len);
- } else {
- return String16();
- }
- }
-};
-
-class BpCameraDeviceUser : public BpInterface<ICameraDeviceUser>
-{
-public:
- BpCameraDeviceUser(const sp<IBinder>& impl)
- : BpInterface<ICameraDeviceUser>(impl)
- {
- }
-
- // disconnect from camera service
- void disconnect()
- {
- ALOGV("disconnect");
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- remote()->transact(DISCONNECT, data, &reply);
- reply.readExceptionCode();
- }
-
- virtual int submitRequest(sp<CaptureRequest> request, bool repeating,
- int64_t *lastFrameNumber)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-
- // arg0 = CaptureRequest
- if (request != 0) {
- data.writeInt32(1);
- request->writeToParcel(&data);
- } else {
- data.writeInt32(0);
- }
-
- // arg1 = streaming (bool)
- data.writeInt32(repeating);
-
- remote()->transact(SUBMIT_REQUEST, data, &reply);
-
- reply.readExceptionCode();
- status_t res = reply.readInt32();
-
- status_t resFrameNumber = BAD_VALUE;
- if (reply.readInt32() != 0) {
- if (lastFrameNumber != NULL) {
- resFrameNumber = reply.readInt64(lastFrameNumber);
- }
- }
-
- if (res < 0 || (resFrameNumber != NO_ERROR)) {
- res = FAILED_TRANSACTION;
- }
- return res;
- }
-
- virtual int submitRequestList(List<sp<CaptureRequest> > requestList, bool repeating,
- int64_t *lastFrameNumber)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-
- data.writeInt32(requestList.size());
-
- for (List<sp<CaptureRequest> >::iterator it = requestList.begin();
- it != requestList.end(); ++it) {
- sp<CaptureRequest> request = *it;
- if (request != 0) {
- data.writeInt32(1);
- if (request->writeToParcel(&data) != OK) {
- return BAD_VALUE;
- }
- } else {
- data.writeInt32(0);
- }
- }
-
- data.writeInt32(repeating);
-
- remote()->transact(SUBMIT_REQUEST_LIST, data, &reply);
-
- reply.readExceptionCode();
- status_t res = reply.readInt32();
-
- status_t resFrameNumber = BAD_VALUE;
- if (reply.readInt32() != 0) {
- if (lastFrameNumber != NULL) {
- resFrameNumber = reply.readInt64(lastFrameNumber);
- }
- }
- if (res < 0 || (resFrameNumber != NO_ERROR)) {
- res = FAILED_TRANSACTION;
- }
- return res;
- }
-
- virtual status_t cancelRequest(int requestId, int64_t *lastFrameNumber)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- data.writeInt32(requestId);
-
- remote()->transact(CANCEL_REQUEST, data, &reply);
-
- reply.readExceptionCode();
- status_t res = reply.readInt32();
-
- status_t resFrameNumber = BAD_VALUE;
- if (reply.readInt32() != 0) {
- if (lastFrameNumber != NULL) {
- resFrameNumber = reply.readInt64(lastFrameNumber);
- }
- }
- if ((res != NO_ERROR) || (resFrameNumber != NO_ERROR)) {
- res = FAILED_TRANSACTION;
- }
- return res;
- }
-
- virtual status_t beginConfigure()
- {
- ALOGV("beginConfigure");
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- remote()->transact(BEGIN_CONFIGURE, data, &reply);
- reply.readExceptionCode();
- return reply.readInt32();
- }
-
- virtual status_t endConfigure(bool isConstrainedHighSpeed)
- {
- ALOGV("endConfigure");
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- data.writeInt32(isConstrainedHighSpeed);
-
- remote()->transact(END_CONFIGURE, data, &reply);
- reply.readExceptionCode();
- return reply.readInt32();
- }
-
- virtual status_t deleteStream(int streamId)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- data.writeInt32(streamId);
-
- remote()->transact(DELETE_STREAM, data, &reply);
-
- reply.readExceptionCode();
- return reply.readInt32();
- }
-
- virtual status_t createStream(const OutputConfiguration& outputConfiguration)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- if (outputConfiguration.getGraphicBufferProducer() != NULL) {
- data.writeInt32(1); // marker that OutputConfiguration is not null. Mimic aidl behavior
- outputConfiguration.writeToParcel(data);
- } else {
- data.writeInt32(0);
- }
- remote()->transact(CREATE_STREAM, data, &reply);
-
- reply.readExceptionCode();
- return reply.readInt32();
- }
-
- virtual status_t createInputStream(int width, int height, int format)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- data.writeInt32(width);
- data.writeInt32(height);
- data.writeInt32(format);
-
- remote()->transact(CREATE_INPUT_STREAM, data, &reply);
-
- reply.readExceptionCode();
- return reply.readInt32();
- }
-
- // get the buffer producer of the input stream
- virtual status_t getInputBufferProducer(
- sp<IGraphicBufferProducer> *producer) {
- if (producer == NULL) {
- return BAD_VALUE;
- }
-
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
-
- remote()->transact(GET_INPUT_SURFACE, data, &reply);
-
- reply.readExceptionCode();
- status_t result = reply.readInt32() ;
- if (result != OK) {
- return result;
- }
-
- sp<IGraphicBufferProducer> bp = NULL;
- if (reply.readInt32() != 0) {
- String16 name = readMaybeEmptyString16(reply);
- bp = interface_cast<IGraphicBufferProducer>(
- reply.readStrongBinder());
- }
-
- *producer = bp;
-
- return *producer == NULL ? INVALID_OPERATION : OK;
- }
-
- // Create a request object from a template.
- virtual status_t createDefaultRequest(int templateId,
- /*out*/
- CameraMetadata* request)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- data.writeInt32(templateId);
- remote()->transact(CREATE_DEFAULT_REQUEST, data, &reply);
-
- reply.readExceptionCode();
- status_t result = reply.readInt32();
-
- CameraMetadata out;
- if (reply.readInt32() != 0) {
- out.readFromParcel(&reply);
- }
-
- if (request != NULL) {
- request->swap(out);
- }
- return result;
- }
-
-
- virtual status_t getCameraInfo(CameraMetadata* info)
- {
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- remote()->transact(GET_CAMERA_INFO, data, &reply);
-
- reply.readExceptionCode();
- status_t result = reply.readInt32();
-
- CameraMetadata out;
- if (reply.readInt32() != 0) {
- out.readFromParcel(&reply);
- }
-
- if (info != NULL) {
- info->swap(out);
- }
-
- return result;
- }
-
- virtual status_t waitUntilIdle()
- {
- ALOGV("waitUntilIdle");
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- remote()->transact(WAIT_UNTIL_IDLE, data, &reply);
- reply.readExceptionCode();
- return reply.readInt32();
- }
-
- virtual status_t flush(int64_t *lastFrameNumber)
- {
- ALOGV("flush");
- Parcel data, reply;
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- remote()->transact(FLUSH, data, &reply);
- reply.readExceptionCode();
- status_t res = reply.readInt32();
-
- status_t resFrameNumber = BAD_VALUE;
- if (reply.readInt32() != 0) {
- if (lastFrameNumber != NULL) {
- resFrameNumber = reply.readInt64(lastFrameNumber);
- }
- }
- if ((res != NO_ERROR) || (resFrameNumber != NO_ERROR)) {
- res = FAILED_TRANSACTION;
- }
- return res;
- }
-
- virtual status_t prepare(int streamId)
- {
- ALOGV("prepare");
- Parcel data, reply;
-
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- data.writeInt32(streamId);
-
- remote()->transact(PREPARE, data, &reply);
-
- reply.readExceptionCode();
- return reply.readInt32();
- }
-
- virtual status_t prepare2(int maxCount, int streamId)
- {
- ALOGV("prepare2");
- Parcel data, reply;
-
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- data.writeInt32(maxCount);
- data.writeInt32(streamId);
-
- remote()->transact(PREPARE2, data, &reply);
-
- reply.readExceptionCode();
- return reply.readInt32();
- }
-
- virtual status_t tearDown(int streamId)
- {
- ALOGV("tearDown");
- Parcel data, reply;
-
- data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor());
- data.writeInt32(streamId);
-
- remote()->transact(TEAR_DOWN, data, &reply);
-
- reply.readExceptionCode();
- return reply.readInt32();
- }
-
-private:
-
-
-};
-
-IMPLEMENT_META_INTERFACE(CameraDeviceUser,
- "android.hardware.camera2.ICameraDeviceUser");
-
-// ----------------------------------------------------------------------
-
-status_t BnCameraDeviceUser::onTransact(
- uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
- switch(code) {
- case DISCONNECT: {
- ALOGV("DISCONNECT");
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
- disconnect();
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case SUBMIT_REQUEST: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
- // arg0 = request
- sp<CaptureRequest> request;
- if (data.readInt32() != 0) {
- request = new CaptureRequest();
- request->readFromParcel(const_cast<Parcel*>(&data));
- }
-
- // arg1 = streaming (bool)
- bool repeating = data.readInt32();
-
- // return code: requestId (int32)
- reply->writeNoException();
- int64_t lastFrameNumber = -1;
- reply->writeInt32(submitRequest(request, repeating, &lastFrameNumber));
- reply->writeInt32(1);
- reply->writeInt64(lastFrameNumber);
-
- return NO_ERROR;
- } break;
- case SUBMIT_REQUEST_LIST: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
- List<sp<CaptureRequest> > requestList;
- int requestListSize = data.readInt32();
- for (int i = 0; i < requestListSize; i++) {
- if (data.readInt32() != 0) {
- sp<CaptureRequest> request = new CaptureRequest();
- if (request->readFromParcel(const_cast<Parcel*>(&data)) != OK) {
- return BAD_VALUE;
- }
- requestList.push_back(request);
- } else {
- sp<CaptureRequest> request = 0;
- requestList.push_back(request);
- ALOGE("A request is missing. Sending in null request.");
- }
- }
-
- bool repeating = data.readInt32();
-
- reply->writeNoException();
- int64_t lastFrameNumber = -1;
- reply->writeInt32(submitRequestList(requestList, repeating, &lastFrameNumber));
- reply->writeInt32(1);
- reply->writeInt64(lastFrameNumber);
-
- return NO_ERROR;
- } break;
- case CANCEL_REQUEST: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
- int requestId = data.readInt32();
- reply->writeNoException();
- int64_t lastFrameNumber = -1;
- reply->writeInt32(cancelRequest(requestId, &lastFrameNumber));
- reply->writeInt32(1);
- reply->writeInt64(lastFrameNumber);
- return NO_ERROR;
- } break;
- case DELETE_STREAM: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
- int streamId = data.readInt32();
- reply->writeNoException();
- reply->writeInt32(deleteStream(streamId));
- return NO_ERROR;
- } break;
- case CREATE_STREAM: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
- status_t ret = BAD_VALUE;
- if (data.readInt32() != 0) {
- OutputConfiguration outputConfiguration(data);
- ret = createStream(outputConfiguration);
- } else {
- ALOGE("%s: cannot take an empty OutputConfiguration", __FUNCTION__);
- }
-
- reply->writeNoException();
- ALOGV("%s: CREATE_STREAM: write noException", __FUNCTION__);
- reply->writeInt32(ret);
- ALOGV("%s: CREATE_STREAM: write ret = %d", __FUNCTION__, ret);
-
- return NO_ERROR;
- } break;
- case CREATE_INPUT_STREAM: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
- int width, height, format;
-
- width = data.readInt32();
- height = data.readInt32();
- format = data.readInt32();
- status_t ret = createInputStream(width, height, format);
-
- reply->writeNoException();
- reply->writeInt32(ret);
- return NO_ERROR;
-
- } break;
- case GET_INPUT_SURFACE: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
- sp<IGraphicBufferProducer> bp;
- status_t ret = getInputBufferProducer(&bp);
- sp<IBinder> b(IInterface::asBinder(ret == OK ? bp : NULL));
-
- reply->writeNoException();
- reply->writeInt32(ret);
- reply->writeInt32(1);
- reply->writeString16(String16("camera input")); // name of surface
- reply->writeStrongBinder(b);
-
- return NO_ERROR;
- } break;
- case CREATE_DEFAULT_REQUEST: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
- int templateId = data.readInt32();
-
- CameraMetadata request;
- status_t ret;
- ret = createDefaultRequest(templateId, &request);
-
- reply->writeNoException();
- reply->writeInt32(ret);
-
- // out-variables are after exception and return value
- reply->writeInt32(1); // to mark presence of metadata object
- request.writeToParcel(const_cast<Parcel*>(reply));
-
- return NO_ERROR;
- } break;
- case GET_CAMERA_INFO: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
-
- CameraMetadata info;
- status_t ret;
- ret = getCameraInfo(&info);
-
- reply->writeNoException();
- reply->writeInt32(ret);
-
- // out-variables are after exception and return value
- reply->writeInt32(1); // to mark presence of metadata object
- info.writeToParcel(reply);
-
- return NO_ERROR;
- } break;
- case WAIT_UNTIL_IDLE: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
- reply->writeNoException();
- reply->writeInt32(waitUntilIdle());
- return NO_ERROR;
- } break;
- case FLUSH: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
- reply->writeNoException();
- int64_t lastFrameNumber = -1;
- reply->writeInt32(flush(&lastFrameNumber));
- reply->writeInt32(1);
- reply->writeInt64(lastFrameNumber);
- return NO_ERROR;
- }
- case BEGIN_CONFIGURE: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
- reply->writeNoException();
- reply->writeInt32(beginConfigure());
- return NO_ERROR;
- } break;
- case END_CONFIGURE: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
- bool isConstrainedHighSpeed = data.readInt32();
- reply->writeNoException();
- reply->writeInt32(endConfigure(isConstrainedHighSpeed));
- return NO_ERROR;
- } break;
- case PREPARE: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
- int streamId = data.readInt32();
- reply->writeNoException();
- reply->writeInt32(prepare(streamId));
- return NO_ERROR;
- } break;
- case TEAR_DOWN: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
- int streamId = data.readInt32();
- reply->writeNoException();
- reply->writeInt32(tearDown(streamId));
- return NO_ERROR;
- } break;
- case PREPARE2: {
- CHECK_INTERFACE(ICameraDeviceUser, data, reply);
- int maxCount = data.readInt32();
- int streamId = data.readInt32();
- reply->writeNoException();
- reply->writeInt32(prepare2(maxCount, streamId));
- return NO_ERROR;
- } break;
- default:
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/camera/camera2/OutputConfiguration.cpp b/camera/camera2/OutputConfiguration.cpp
index 3505154..2c2c90b 100644
--- a/camera/camera2/OutputConfiguration.cpp
+++ b/camera/camera2/OutputConfiguration.cpp
@@ -16,9 +16,12 @@
*/
#define LOG_TAG "OutputConfiguration"
+//#define LOG_NDEBUG 0
+
#include <utils/Log.h>
#include <camera/camera2/OutputConfiguration.h>
+#include <gui/Surface.h>
#include <binder/Parcel.h>
namespace android {
@@ -27,17 +30,6 @@
const int OutputConfiguration::INVALID_ROTATION = -1;
const int OutputConfiguration::INVALID_SET_ID = -1;
-// Read empty strings without printing a false error message.
-String16 OutputConfiguration::readMaybeEmptyString16(const Parcel& parcel) {
- size_t len;
- const char16_t* str = parcel.readString16Inplace(&len);
- if (str != NULL) {
- return String16(str, len);
- } else {
- return String16();
- }
-}
-
sp<IGraphicBufferProducer> OutputConfiguration::getGraphicBufferProducer() const {
return mGbp;
}
@@ -50,33 +42,48 @@
return mSurfaceSetID;
}
-OutputConfiguration::OutputConfiguration(const Parcel& parcel) {
- status_t err;
+OutputConfiguration::OutputConfiguration() :
+ mRotation(INVALID_ROTATION),
+ mSurfaceSetID(INVALID_SET_ID) {
+}
+
+OutputConfiguration::OutputConfiguration(const Parcel& parcel) :
+ mRotation(INVALID_ROTATION),
+ mSurfaceSetID(INVALID_SET_ID) {
+ readFromParcel(&parcel);
+}
+
+status_t OutputConfiguration::readFromParcel(const Parcel* parcel) {
+ status_t err = OK;
int rotation = 0;
- if ((err = parcel.readInt32(&rotation)) != OK) {
+
+ if (parcel == nullptr) return BAD_VALUE;
+
+ if ((err = parcel->readInt32(&rotation)) != OK) {
ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
- mGbp = NULL;
- mRotation = INVALID_ROTATION;
- return;
+ return err;
}
int setID = INVALID_SET_ID;
- if ((err = parcel.readInt32(&setID)) != OK) {
+ if ((err = parcel->readInt32(&setID)) != OK) {
ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
- mGbp = NULL;
- mSurfaceSetID = INVALID_SET_ID;
- return;
+ return err;
}
- String16 name = readMaybeEmptyString16(parcel);
- const sp<IGraphicBufferProducer>& gbp =
- interface_cast<IGraphicBufferProducer>(parcel.readStrongBinder());
- mGbp = gbp;
+ view::Surface surfaceShim;
+ if ((err = surfaceShim.readFromParcel(parcel)) != OK) {
+ ALOGE("%s: Failed to read surface from parcel", __FUNCTION__);
+ return err;
+ }
+
+ mGbp = surfaceShim.graphicBufferProducer;
mRotation = rotation;
mSurfaceSetID = setID;
ALOGV("%s: OutputConfiguration: bp = %p, name = %s", __FUNCTION__,
- gbp.get(), String8(name).string());
+ mGbp.get(), String8(surfaceShim.name).string());
+
+ return err;
}
OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
@@ -86,16 +93,25 @@
mSurfaceSetID = surfaceSetID;
}
-status_t OutputConfiguration::writeToParcel(Parcel& parcel) const {
+status_t OutputConfiguration::writeToParcel(Parcel* parcel) const {
- parcel.writeInt32(mRotation);
- parcel.writeInt32(mSurfaceSetID);
- parcel.writeString16(String16("unknown_name")); // name of surface
- sp<IBinder> b(IInterface::asBinder(mGbp));
- parcel.writeStrongBinder(b);
+ if (parcel == nullptr) return BAD_VALUE;
+ status_t err = OK;
+
+ err = parcel->writeInt32(mRotation);
+ if (err != OK) return err;
+
+ err = parcel->writeInt32(mSurfaceSetID);
+ if (err != OK) return err;
+
+ view::Surface surfaceShim;
+ surfaceShim.name = String16("unknown_name"); // name of surface
+ surfaceShim.graphicBufferProducer = mGbp;
+
+ err = surfaceShim.writeToParcel(parcel);
+ if (err != OK) return err;
return OK;
}
}; // namespace android
-
diff --git a/camera/camera2/SubmitInfo.cpp b/camera/camera2/SubmitInfo.cpp
new file mode 100644
index 0000000..d739c79
--- /dev/null
+++ b/camera/camera2/SubmitInfo.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+
+#include "camera/camera2/SubmitInfo.h"
+
+namespace android {
+namespace hardware {
+namespace camera2 {
+namespace utils {
+
+status_t SubmitInfo::writeToParcel(Parcel *parcel) const {
+ status_t res;
+ if (parcel == nullptr) return BAD_VALUE;
+
+ res = parcel->writeInt32(mRequestId);
+ if (res != OK) return res;
+
+ res = parcel->writeInt64(mLastFrameNumber);
+ return res;
+}
+
+status_t SubmitInfo::readFromParcel(const Parcel *parcel) {
+ status_t res;
+ if (parcel == nullptr) return BAD_VALUE;
+
+ res = parcel->readInt32(&mRequestId);
+ if (res != OK) return res;
+
+ res = parcel->readInt64(&mLastFrameNumber);
+ return res;
+}
+
+} // namespace utils
+} // namespace camera2
+} // namespace hardware
+} // namespace android
diff --git a/camera/cameraserver/Android.mk b/camera/cameraserver/Android.mk
index 4d8339c..0207505 100644
--- a/camera/cameraserver/Android.mk
+++ b/camera/cameraserver/Android.mk
@@ -23,11 +23,8 @@
libcameraservice \
libcutils \
libutils \
- libbinder
-
-LOCAL_C_INCLUDES := \
- frameworks/av/services/camera/libcameraservice \
- system/media/camera/include
+ libbinder \
+ libcamera_client
LOCAL_MODULE:= cameraserver
LOCAL_32_BIT_ONLY := true
diff --git a/camera/ndk/Android.mk b/camera/ndk/Android.mk
index 8e84e40..e43bb2c 100644
--- a/camera/ndk/Android.mk
+++ b/camera/ndk/Android.mk
@@ -34,9 +34,8 @@
LOCAL_MODULE:= libcamera2ndk
LOCAL_C_INCLUDES := \
- system/media/camera/include \
frameworks/av/include/camera/ndk \
- frameworks/av/include/ndk \
+ frameworks/av/include/ndk
LOCAL_CFLAGS += -fvisibility=hidden -D EXPORT='__attribute__ ((visibility ("default")))'
diff --git a/camera/ndk/NdkCameraManager.cpp b/camera/ndk/NdkCameraManager.cpp
index 7d9f84b..ff15263 100644
--- a/camera/ndk/NdkCameraManager.cpp
+++ b/camera/ndk/NdkCameraManager.cpp
@@ -24,6 +24,8 @@
#include <NdkCameraManager.h>
#include "impl/ACameraManager.h"
+using namespace android;
+
EXPORT
ACameraManager* ACameraManager_create() {
ATRACE_CALL();
diff --git a/camera/ndk/impl/ACameraDevice.cpp b/camera/ndk/impl/ACameraDevice.cpp
index 5f89fa3..1ab6af8 100644
--- a/camera/ndk/impl/ACameraDevice.cpp
+++ b/camera/ndk/impl/ACameraDevice.cpp
@@ -20,6 +20,8 @@
#include <vector>
#include <utility>
#include <inttypes.h>
+#include <android/hardware/ICameraService.h>
+#include <camera2/SubmitInfo.h>
#include <gui/Surface.h>
#include "ACameraDevice.h"
#include "ACameraMetadata.h"
@@ -117,13 +119,14 @@
return ACAMERA_ERROR_CAMERA_DISCONNECTED;
}
CameraMetadata rawRequest;
- status_t remoteRet = mRemote->createDefaultRequest(templateId, &rawRequest);
- if (remoteRet == BAD_VALUE) {
+ binder::Status remoteRet = mRemote->createDefaultRequest(templateId, &rawRequest);
+ if (remoteRet.serviceSpecificErrorCode() ==
+ hardware::ICameraService::ERROR_ILLEGAL_ARGUMENT) {
ALOGW("Create capture request failed! template %d is not supported on this device",
templateId);
return ACAMERA_ERROR_UNSUPPORTED;
- } else if (remoteRet != OK) {
- ALOGE("Create capture request failed! error %d", remoteRet);
+ } else if (!remoteRet.isOk()) {
+ ALOGE("Create capture request failed: %s", remoteRet.toString8().string());
return ACAMERA_ERROR_UNKNOWN;
}
ACaptureRequest* outReq = new ACaptureRequest();
@@ -201,8 +204,8 @@
return ret;
}
- // Form List/Vector of capture request
- List<sp<CaptureRequest> > requestList;
+ // Form two vectors of capture request, one for internal tracking
+ std::vector<hardware::camera2::CaptureRequest> requestList;
Vector<sp<CaptureRequest> > requestsV;
requestsV.setCapacity(numRequests);
for (int i = 0; i < numRequests; i++) {
@@ -216,7 +219,7 @@
ALOGE("Capture request without output target cannot be submitted!");
return ACAMERA_ERROR_INVALID_PARAMETER;
}
- requestList.push_back(req);
+ requestList.push_back(*(req.get()));
requestsV.push_back(req);
}
@@ -228,10 +231,11 @@
}
}
- int sequenceId;
- int64_t lastFrameNumber;
-
- sequenceId = mRemote->submitRequestList(requestList, isRepeating, &lastFrameNumber);
+ binder::Status remoteRet;
+ hardware::camera2::utils::SubmitInfo info;
+ remoteRet = mRemote->submitRequestList(requestList, isRepeating, &info);
+ int sequenceId = info.mRequestId;
+ int64_t lastFrameNumber = info.mLastFrameNumber;
if (sequenceId < 0) {
ALOGE("Camera %s submit request remote failure: ret %d", getId(), sequenceId);
return ACAMERA_ERROR_UNKNOWN;
@@ -371,9 +375,9 @@
mRepeatingSequenceId = REQUEST_ID_NONE;
int64_t lastFrameNumber;
- status_t remoteRet = mRemote->cancelRequest(repeatingSequenceId, &lastFrameNumber);
- if (remoteRet != OK) {
- ALOGE("Stop repeating request fails in remote! ret %d", remoteRet);
+ binder::Status remoteRet = mRemote->cancelRequest(repeatingSequenceId, &lastFrameNumber);
+ if (!remoteRet.isOk()) {
+ ALOGE("Stop repeating request fails in remote: %s", remoteRet.toString8().string());
return ACAMERA_ERROR_UNKNOWN;
}
checkRepeatingSequenceCompleteLocked(repeatingSequenceId, lastFrameNumber);
@@ -394,9 +398,9 @@
return ACAMERA_ERROR_INVALID_OPERATION;
}
- status_t remoteRet = mRemote->waitUntilIdle();
- if (remoteRet != OK) {
- ALOGE("Camera device %s waitUntilIdle failed! ret %d", getId(), remoteRet);
+ binder::Status remoteRet = mRemote->waitUntilIdle();
+ if (!remoteRet.isOk()) {
+ ALOGE("Camera device %s waitUntilIdle failed: %s", getId(), remoteRet.toString8().string());
// TODO: define a function to convert status_t -> camera_status_t
return ACAMERA_ERROR_UNKNOWN;
}
@@ -508,17 +512,18 @@
}
mIdle = true;
- status_t remoteRet = mRemote->beginConfigure();
- if (remoteRet != ACAMERA_OK) {
- ALOGE("Camera device %s begin configure failed, ret %d", getId(), remoteRet);
+ binder::Status remoteRet = mRemote->beginConfigure();
+ if (!remoteRet.isOk()) {
+ ALOGE("Camera device %s begin configure failed: %s", getId(), remoteRet.toString8().string());
return ACAMERA_ERROR_UNKNOWN;
}
// delete to-be-deleted streams
for (auto streamId : deleteList) {
remoteRet = mRemote->deleteStream(streamId);
- if (remoteRet != ACAMERA_OK) {
- ALOGE("Camera device %s fails to remove stream %d", getId(), streamId);
+ if (!remoteRet.isOk()) {
+ ALOGE("Camera device %s failed to remove stream %d: %s", getId(), streamId,
+ remoteRet.toString8().string());
return ACAMERA_ERROR_UNKNOWN;
}
mConfiguredOutputs.erase(streamId);
@@ -526,21 +531,23 @@
// add new streams
for (auto outConfig : addSet) {
- remoteRet = mRemote->createStream(outConfig);
- if (remoteRet < 0) {
- ALOGE("Camera device %s fails to create stream", getId());
+ int streamId;
+ remoteRet = mRemote->createStream(outConfig, &streamId);
+ if (!remoteRet.isOk()) {
+ ALOGE("Camera device %s failed to create stream: %s", getId(),
+ remoteRet.toString8().string());
return ACAMERA_ERROR_UNKNOWN;
}
- int streamId = remoteRet; // Weird, right?
mConfiguredOutputs.insert(std::make_pair(streamId, outConfig));
}
- remoteRet = mRemote->endConfigure();
- if (remoteRet == BAD_VALUE) {
- ALOGE("Camera device %s cannnot support app output configuration", getId());
+ remoteRet = mRemote->endConfigure(/*isConstrainedHighSpeed*/ false);
+ if (remoteRet.serviceSpecificErrorCode() == hardware::ICameraService::ERROR_ILLEGAL_ARGUMENT) {
+ ALOGE("Camera device %s cannnot support app output configuration: %s", getId(),
+ remoteRet.toString8().string());
return ACAMERA_ERROR_STREAM_CONFIGURE_FAIL;
- } else if (remoteRet != ACAMERA_OK) {
- ALOGE("Camera device %s end configure failed, ret %d", getId(), remoteRet);
+ } else if (!remoteRet.isOk()) {
+ ALOGE("Camera device %s end configure failed: %s", getId(), remoteRet.toString8().string());
return ACAMERA_ERROR_UNKNOWN;
}
@@ -548,7 +555,7 @@
}
void
-CameraDevice::setRemoteDevice(sp<ICameraDeviceUser> remote) {
+CameraDevice::setRemoteDevice(sp<hardware::camera2::ICameraDeviceUser> remote) {
Mutex::Autolock _l(mDeviceLock);
mRemote = remote;
}
@@ -615,14 +622,14 @@
void
CameraDevice::onCaptureErrorLocked(
- ICameraDeviceCallbacks::CameraErrorCode errorCode,
+ int32_t errorCode,
const CaptureResultExtras& resultExtras) {
int sequenceId = resultExtras.requestId;
int64_t frameNumber = resultExtras.frameNumber;
int32_t burstId = resultExtras.burstId;
// No way to report buffer error now
- if (errorCode == ICameraDeviceCallbacks::CameraErrorCode::ERROR_CAMERA_BUFFER) {
+ if (errorCode == hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER) {
ALOGE("Camera %s Lost output buffer for frame %" PRId64,
getId(), frameNumber);
return;
@@ -646,7 +653,7 @@
failure->reason = CAPTURE_FAILURE_REASON_ERROR;
failure->sequenceId = sequenceId;
failure->wasImageCaptured = (errorCode ==
- ICameraDeviceCallbacks::CameraErrorCode::ERROR_CAMERA_RESULT);
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_RESULT);
sp<AMessage> msg = new AMessage(kWhatCaptureFail, mHandler);
msg->setPointer(kContextKey, cbh.mCallbacks.context);
@@ -999,21 +1006,21 @@
/**
* Camera service callback implementation
*/
-void
+binder::Status
CameraDevice::ServiceCallback::onDeviceError(
- CameraErrorCode errorCode,
+ int32_t errorCode,
const CaptureResultExtras& resultExtras) {
ALOGD("Device error received, code %d, frame number %" PRId64 ", request ID %d, subseq ID %d",
errorCode, resultExtras.frameNumber, resultExtras.requestId, resultExtras.burstId);
-
+ binder::Status ret = binder::Status::ok();
sp<CameraDevice> dev = mDevice.promote();
if (dev == nullptr) {
- return; // device has been closed
+ return ret; // device has been closed
}
Mutex::Autolock _l(dev->mDeviceLock);
if (dev->mRemote == nullptr) {
- return; // device has been closed
+ return ret; // device has been closed
}
switch (errorCode) {
case ERROR_CAMERA_DISCONNECTED:
@@ -1061,24 +1068,26 @@
dev->onCaptureErrorLocked(errorCode, resultExtras);
break;
}
+ return ret;
}
-void
+binder::Status
CameraDevice::ServiceCallback::onDeviceIdle() {
ALOGV("Camera is now idle");
+ binder::Status ret = binder::Status::ok();
sp<CameraDevice> dev = mDevice.promote();
if (dev == nullptr) {
- return; // device has been closed
+ return ret; // device has been closed
}
Mutex::Autolock _l(dev->mDeviceLock);
if (dev->isClosed() || dev->mRemote == nullptr) {
- return;
+ return ret;
}
if (dev->mIdle) {
// Already in idle state. Possibly other thread did waitUntilIdle
- return;
+ return ret;
}
if (dev->mCurrentSession != nullptr) {
@@ -1086,7 +1095,7 @@
if (dev->mBusySession != dev->mCurrentSession) {
ALOGE("Current session != busy session");
dev->setCameraDeviceErrorLocked(ACAMERA_ERROR_CAMERA_DEVICE);
- return;
+ return ret;
}
sp<AMessage> msg = new AMessage(kWhatSessionStateCb, dev->mHandler);
msg->setPointer(kContextKey, dev->mBusySession->mUserSessionCallback.context);
@@ -1098,19 +1107,22 @@
msg->post();
}
dev->mIdle = true;
+ return ret;
}
-void
+binder::Status
CameraDevice::ServiceCallback::onCaptureStarted(
const CaptureResultExtras& resultExtras,
int64_t timestamp) {
+ binder::Status ret = binder::Status::ok();
+
sp<CameraDevice> dev = mDevice.promote();
if (dev == nullptr) {
- return; // device has been closed
+ return ret; // device has been closed
}
Mutex::Autolock _l(dev->mDeviceLock);
if (dev->isClosed() || dev->mRemote == nullptr) {
- return;
+ return ret;
}
int sequenceId = resultExtras.requestId;
@@ -1136,15 +1148,18 @@
msg->setInt64(kTimeStampKey, timestamp);
msg->post();
}
+ return ret;
}
-void
+binder::Status
CameraDevice::ServiceCallback::onResultReceived(
const CameraMetadata& metadata,
const CaptureResultExtras& resultExtras) {
+ binder::Status ret = binder::Status::ok();
+
sp<CameraDevice> dev = mDevice.promote();
if (dev == nullptr) {
- return; // device has been closed
+ return ret; // device has been closed
}
int sequenceId = resultExtras.requestId;
int64_t frameNumber = resultExtras.frameNumber;
@@ -1157,7 +1172,7 @@
Mutex::Autolock _l(dev->mDeviceLock);
if (dev->mRemote == nullptr) {
- return; // device has been disconnected
+ return ret; // device has been disconnected
}
if (dev->isClosed()) {
@@ -1165,7 +1180,7 @@
dev->mFrameNumberTracker.updateTracker(frameNumber, /*isError*/false);
}
// early return to avoid callback sent to closed devices
- return;
+ return ret;
}
CameraMetadata metadataCopy = metadata;
@@ -1201,12 +1216,14 @@
dev->mFrameNumberTracker.updateTracker(frameNumber, /*isError*/false);
dev->checkAndFireSequenceCompleteLocked();
}
+
+ return ret;
}
-void
+binder::Status
CameraDevice::ServiceCallback::onPrepared(int) {
// Prepare not yet implemented in NDK
- return;
+ return binder::Status::ok();
}
} // namespace android
diff --git a/camera/ndk/impl/ACameraDevice.h b/camera/ndk/impl/ACameraDevice.h
index b73e621..46243b9 100644
--- a/camera/ndk/impl/ACameraDevice.h
+++ b/camera/ndk/impl/ACameraDevice.h
@@ -26,20 +26,18 @@
#include <utils/List.h>
#include <utils/Vector.h>
+#include <android/hardware/camera2/BnCameraDeviceCallbacks.h>
+#include <android/hardware/camera2/ICameraDeviceUser.h>
#include <media/stagefright/foundation/ALooper.h>
#include <media/stagefright/foundation/AHandler.h>
#include <media/stagefright/foundation/AMessage.h>
#include <camera/CaptureResult.h>
-#include <camera/camera2/ICameraDeviceCallbacks.h>
-#include <camera/camera2/ICameraDeviceUser.h>
#include <camera/camera2/OutputConfiguration.h>
#include <camera/camera2/CaptureRequest.h>
#include <NdkCameraDevice.h>
#include "ACameraMetadata.h"
-using namespace android;
-
namespace android {
// Wrap ACameraCaptureFailure so it can be ref-counter
@@ -64,24 +62,26 @@
/*out*/ACameraCaptureSession** session);
// Callbacks from camera service
- class ServiceCallback : public BnCameraDeviceCallbacks {
+ class ServiceCallback : public hardware::camera2::BnCameraDeviceCallbacks {
public:
ServiceCallback(CameraDevice* device) : mDevice(device) {}
- void onDeviceError(CameraErrorCode errorCode,
+ binder::Status onDeviceError(int32_t errorCode,
const CaptureResultExtras& resultExtras) override;
- void onDeviceIdle() override;
- void onCaptureStarted(const CaptureResultExtras& resultExtras,
+ binder::Status onDeviceIdle() override;
+ binder::Status onCaptureStarted(const CaptureResultExtras& resultExtras,
int64_t timestamp) override;
- void onResultReceived(const CameraMetadata& metadata,
+ binder::Status onResultReceived(const CameraMetadata& metadata,
const CaptureResultExtras& resultExtras) override;
- void onPrepared(int streamId) override;
+ binder::Status onPrepared(int streamId) override;
private:
const wp<CameraDevice> mDevice;
};
- inline sp<ICameraDeviceCallbacks> getServiceCallback() { return mServiceCallback; };
+ inline sp<hardware::camera2::ICameraDeviceCallbacks> getServiceCallback() {
+ return mServiceCallback;
+ };
// Camera device is only functional after remote being set
- void setRemoteDevice(sp<ICameraDeviceUser> remote);
+ void setRemoteDevice(sp<hardware::camera2::ICameraDeviceUser> remote);
inline ACameraDevice* getWrapper() const { return mWrapper; };
@@ -155,14 +155,14 @@
bool mInError;
camera_status_t mError;
void onCaptureErrorLocked(
- ICameraDeviceCallbacks::CameraErrorCode errorCode,
+ int32_t errorCode,
const CaptureResultExtras& resultExtras);
bool mIdle;
// This will avoid a busy session being deleted before it's back to idle state
sp<ACameraCaptureSession> mBusySession;
- sp<ICameraDeviceUser> mRemote;
+ sp<hardware::camera2::ICameraDeviceUser> mRemote;
// Looper thread to handle callback to app
sp<ALooper> mCbLooper;
@@ -294,17 +294,17 @@
/***********************
* Device interal APIs *
***********************/
- inline sp<ICameraDeviceCallbacks> getServiceCallback() {
+ inline android::sp<android::hardware::camera2::ICameraDeviceCallbacks> getServiceCallback() {
return mDevice->getServiceCallback();
};
// Camera device is only functional after remote being set
- inline void setRemoteDevice(sp<ICameraDeviceUser> remote) {
+ inline void setRemoteDevice(android::sp<android::hardware::camera2::ICameraDeviceUser> remote) {
mDevice->setRemoteDevice(remote);
}
private:
- sp<CameraDevice> mDevice;
+ android::sp<android::CameraDevice> mDevice;
};
#endif // _ACAMERA_DEVICE_H
diff --git a/camera/ndk/impl/ACameraManager.cpp b/camera/ndk/impl/ACameraManager.cpp
index ed5c3ba..6fa0864 100644
--- a/camera/ndk/impl/ACameraManager.cpp
+++ b/camera/ndk/impl/ACameraManager.cpp
@@ -71,7 +71,7 @@
mCameraService.clear();
}
-sp<ICameraService> CameraManagerGlobal::getCameraService() {
+sp<hardware::ICameraService> CameraManagerGlobal::getCameraService() {
Mutex::Autolock _l(mLock);
if (mCameraService.get() == nullptr) {
sp<IServiceManager> sm = defaultServiceManager();
@@ -88,7 +88,7 @@
mDeathNotifier = new DeathNotifier(this);
}
binder->linkToDeath(mDeathNotifier);
- mCameraService = interface_cast<ICameraService>(binder);
+ mCameraService = interface_cast<hardware::ICameraService>(binder);
// Setup looper thread to perfrom availiability callbacks
if (mCbLooper == nullptr) {
@@ -111,22 +111,23 @@
mCameraService->addListener(mCameraServiceListener);
// setup vendor tags
- sp<VendorTagDescriptor> desc;
- status_t ret = mCameraService->getCameraVendorTagDescriptor(/*out*/desc);
+ sp<VendorTagDescriptor> desc = new VendorTagDescriptor();
+ binder::Status ret = mCameraService->getCameraVendorTagDescriptor(/*out*/desc.get());
- if (ret == OK) {
- ret = VendorTagDescriptor::setAsGlobalVendorTagDescriptor(desc);
- if (ret != OK) {
+ if (ret.isOk()) {
+ status_t err = VendorTagDescriptor::setAsGlobalVendorTagDescriptor(desc);
+ if (err != OK) {
ALOGE("%s: Failed to set vendor tag descriptors, received error %s (%d)",
- __FUNCTION__, strerror(-ret), ret);
+ __FUNCTION__, strerror(-err), err);
}
- } else if (ret == -EOPNOTSUPP) {
+ } else if (ret.serviceSpecificErrorCode() ==
+ hardware::ICameraService::ERROR_DEPRECATED_HAL) {
ALOGW("%s: Camera HAL too old; does not support vendor tags",
__FUNCTION__);
VendorTagDescriptor::clearGlobalVendorTagDescriptor();
} else {
- ALOGE("%s: Failed to get vendor tag descriptors, received error %s (%d)",
- __FUNCTION__, strerror(-ret), ret);
+ ALOGE("%s: Failed to get vendor tag descriptors: %s",
+ __FUNCTION__, ret.toString8().string());
}
}
ALOGE_IF(mCameraService == nullptr, "no CameraService!?");
@@ -142,7 +143,7 @@
for (auto pair : cm->mDeviceStatusMap) {
int32_t cameraId = pair.first;
cm->onStatusChangedLocked(
- ICameraServiceListener::STATUS_NOT_PRESENT, cameraId);
+ CameraServiceListener::STATUS_NOT_PRESENT, cameraId);
}
cm->mCameraService.clear();
// TODO: consider adding re-connect call here?
@@ -158,7 +159,7 @@
if (pair.second) {
for (auto pair : mDeviceStatusMap) {
int32_t cameraId = pair.first;
- Status status = pair.second;
+ int32_t status = pair.second;
sp<AMessage> msg = new AMessage(kWhatSendSingleCallback, mHandler);
ACameraManager_AvailabilityCallback cb = isStatusAvailable(status) ?
@@ -178,21 +179,21 @@
mCallbacks.erase(cb);
}
-bool CameraManagerGlobal::validStatus(Status status) {
+bool CameraManagerGlobal::validStatus(int32_t status) {
switch (status) {
- case ICameraServiceListener::STATUS_NOT_PRESENT:
- case ICameraServiceListener::STATUS_PRESENT:
- case ICameraServiceListener::STATUS_ENUMERATING:
- case ICameraServiceListener::STATUS_NOT_AVAILABLE:
+ case hardware::ICameraServiceListener::STATUS_NOT_PRESENT:
+ case hardware::ICameraServiceListener::STATUS_PRESENT:
+ case hardware::ICameraServiceListener::STATUS_ENUMERATING:
+ case hardware::ICameraServiceListener::STATUS_NOT_AVAILABLE:
return true;
default:
return false;
}
}
-bool CameraManagerGlobal::isStatusAvailable(Status status) {
+bool CameraManagerGlobal::isStatusAvailable(int32_t status) {
switch (status) {
- case ICameraServiceListener::STATUS_PRESENT:
+ case hardware::ICameraServiceListener::STATUS_PRESENT:
return true;
default:
return false;
@@ -239,31 +240,32 @@
}
}
-void CameraManagerGlobal::CameraServiceListener::onStatusChanged(
- Status status, int32_t cameraId) {
+binder::Status CameraManagerGlobal::CameraServiceListener::onStatusChanged(
+ int32_t status, int32_t cameraId) {
sp<CameraManagerGlobal> cm = mCameraManager.promote();
- if (cm == nullptr) {
+ if (cm != nullptr) {
+ cm->onStatusChanged(status, cameraId);
+ } else {
ALOGE("Cannot deliver status change. Global camera manager died");
- return;
}
- cm->onStatusChanged(status, cameraId);
+ return binder::Status::ok();
}
void CameraManagerGlobal::onStatusChanged(
- Status status, int32_t cameraId) {
+ int32_t status, int32_t cameraId) {
Mutex::Autolock _l(mLock);
onStatusChangedLocked(status, cameraId);
}
void CameraManagerGlobal::onStatusChangedLocked(
- Status status, int32_t cameraId) {
+ int32_t status, int32_t cameraId) {
if (!validStatus(status)) {
ALOGE("%s: Invalid status %d", __FUNCTION__, status);
return;
}
bool firstStatus = (mDeviceStatusMap.count(cameraId) == 0);
- Status oldStatus = firstStatus ?
+ int32_t oldStatus = firstStatus ?
status : // first status
mDeviceStatusMap[cameraId];
@@ -296,19 +298,28 @@
if (mCachedCameraIdList.numCameras == kCameraIdListNotInit) {
int numCameras = 0;
Vector<char *> cameraIds;
- sp<ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
+ sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
if (cs == nullptr) {
ALOGE("%s: Cannot reach camera service!", __FUNCTION__);
return ACAMERA_ERROR_CAMERA_DISCONNECTED;
}
// Get number of cameras
- int numAllCameras = cs->getNumberOfCameras(ICameraService::CAMERA_TYPE_ALL);
+ int numAllCameras = 0;
+ binder::Status serviceRet = cs->getNumberOfCameras(hardware::ICameraService::CAMERA_TYPE_ALL,
+ &numAllCameras);
+ if (!serviceRet.isOk()) {
+ ALOGE("%s: Error getting camera count: %s", __FUNCTION__,
+ serviceRet.toString8().string());
+ numAllCameras = 0;
+ }
// Filter API2 compatible cameras and push to cameraIds
for (int i = 0; i < numAllCameras; i++) {
// TODO: Only suppot HALs that supports API2 directly now
- status_t camera2Support = cs->supportsCameraApi(i, ICameraService::API_VERSION_2);
+ bool camera2Support = false;
+ serviceRet = cs->supportsCameraApi(i, hardware::ICameraService::API_VERSION_2,
+ &camera2Support);
char buf[kMaxCameraIdLen];
- if (camera2Support == OK) {
+ if (camera2Support) {
numCameras++;
mCameraIds.insert(i);
snprintf(buf, sizeof(buf), "%d", i);
@@ -401,15 +412,16 @@
ALOGE("%s: Camera ID %s does not exist!", __FUNCTION__, cameraIdStr);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
- sp<ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
+ sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
if (cs == nullptr) {
ALOGE("%s: Cannot reach camera service!", __FUNCTION__);
return ACAMERA_ERROR_CAMERA_DISCONNECTED;
}
CameraMetadata rawMetadata;
- status_t serviceRet = cs->getCameraCharacteristics(cameraId, &rawMetadata);
- if (serviceRet != OK) {
- ALOGE("Get camera characteristics from camera service failed! Err %d", ret);
+ binder::Status serviceRet = cs->getCameraCharacteristics(cameraId, &rawMetadata);
+ if (!serviceRet.isOk()) {
+ ALOGE("Get camera characteristics from camera service failed: %s",
+ serviceRet.toString8().string());
return ACAMERA_ERROR_UNKNOWN; // should not reach here
}
@@ -436,24 +448,23 @@
ACameraDevice* device = new ACameraDevice(cameraId, callback, std::move(chars));
- sp<ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
+ sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
if (cs == nullptr) {
ALOGE("%s: Cannot reach camera service!", __FUNCTION__);
return ACAMERA_ERROR_CAMERA_DISCONNECTED;
}
int id = atoi(cameraId);
- sp<ICameraDeviceCallbacks> callbacks = device->getServiceCallback();
- sp<ICameraDeviceUser> deviceRemote;
+ sp<hardware::camera2::ICameraDeviceCallbacks> callbacks = device->getServiceCallback();
+ sp<hardware::camera2::ICameraDeviceUser> deviceRemote;
// No way to get package name from native.
// Send a zero length package name and let camera service figure it out from UID
- status_t serviceRet = cs->connectDevice(
+ binder::Status serviceRet = cs->connectDevice(
callbacks, id, String16(""),
- ICameraService::USE_CALLING_UID, /*out*/deviceRemote);
+ hardware::ICameraService::USE_CALLING_UID, /*out*/&deviceRemote);
- if (serviceRet != OK) {
- ALOGE("%s: connect camera device failed! err %d", __FUNCTION__, serviceRet);
- // TODO: generate better error message here
+ if (!serviceRet.isOk()) {
+ ALOGE("%s: connect camera device failed: %s", __FUNCTION__, serviceRet.toString8().string());
delete device;
return ACAMERA_ERROR_CAMERA_DISCONNECTED;
}
@@ -476,4 +487,3 @@
delete[] mCachedCameraIdList.cameraIds;
}
}
-
diff --git a/camera/ndk/impl/ACameraManager.h b/camera/ndk/impl/ACameraManager.h
index b68685d..3f2262f 100644
--- a/camera/ndk/impl/ACameraManager.h
+++ b/camera/ndk/impl/ACameraManager.h
@@ -19,9 +19,9 @@
#include "NdkCameraManager.h"
+#include <android/hardware/ICameraService.h>
+#include <android/hardware/BnCameraServiceListener.h>
#include <camera/CameraMetadata.h>
-#include <camera/ICameraService.h>
-#include <camera/ICameraServiceListener.h>
#include <binder/IServiceManager.h>
#include <utils/StrongPointer.h>
#include <utils/Mutex.h>
@@ -33,8 +33,6 @@
#include <set>
#include <map>
-using namespace android;
-
namespace android {
/**
@@ -47,7 +45,7 @@
class CameraManagerGlobal final : public RefBase {
public:
static CameraManagerGlobal& getInstance();
- sp<ICameraService> getCameraService();
+ sp<hardware::ICameraService> getCameraService();
void registerAvailabilityCallback(
const ACameraManager_AvailabilityCallbacks *callback);
@@ -55,7 +53,7 @@
const ACameraManager_AvailabilityCallbacks *callback);
private:
- sp<ICameraService> mCameraService;
+ sp<hardware::ICameraService> mCameraService;
const int kCameraServicePollDelay = 500000; // 0.5s
const char* kCameraServiceName = "media.camera";
Mutex mLock;
@@ -71,13 +69,16 @@
};
sp<DeathNotifier> mDeathNotifier;
- class CameraServiceListener final : public BnCameraServiceListener {
+ class CameraServiceListener final : public hardware::BnCameraServiceListener {
public:
CameraServiceListener(CameraManagerGlobal* cm) : mCameraManager(cm) {}
- virtual void onStatusChanged(Status status, int32_t cameraId);
+ virtual binder::Status onStatusChanged(int32_t status, int32_t cameraId);
// Torch API not implemented yet
- virtual void onTorchStatusChanged(TorchStatus, const String16&) {};
+ virtual binder::Status onTorchStatusChanged(int32_t, const String16&) {
+ return binder::Status::ok();
+ }
+
private:
const wp<CameraManagerGlobal> mCameraManager;
};
@@ -132,15 +133,14 @@
sp<CallbackHandler> mHandler;
sp<ALooper> mCbLooper; // Looper thread where callbacks actually happen on
- typedef ICameraServiceListener::Status Status;
- void onStatusChanged(Status status, int32_t cameraId);
- void onStatusChangedLocked(Status status, int32_t cameraId);
+ void onStatusChanged(int32_t status, int32_t cameraId);
+ void onStatusChangedLocked(int32_t status, int32_t cameraId);
// Utils for status
- static bool validStatus(Status status);
- static bool isStatusAvailable(Status status);
+ static bool validStatus(int32_t status);
+ static bool isStatusAvailable(int32_t status);
// Map camera_id -> status
- std::map<int32_t, Status> mDeviceStatusMap;
+ std::map<int32_t, int32_t> mDeviceStatusMap;
// For the singleton instance
static Mutex sLock;
@@ -158,7 +158,7 @@
struct ACameraManager {
ACameraManager() :
mCachedCameraIdList({kCameraIdListNotInit, nullptr}),
- mGlobalManager(&(CameraManagerGlobal::getInstance())) {}
+ mGlobalManager(&(android::CameraManagerGlobal::getInstance())) {}
~ACameraManager();
camera_status_t getCameraIdList(ACameraIdList** cameraIdList);
static void deleteCameraIdList(ACameraIdList* cameraIdList);
@@ -175,10 +175,10 @@
enum {
kCameraIdListNotInit = -1
};
- Mutex mLock;
+ android::Mutex mLock;
std::set<int> mCameraIds; // Init by getOrCreateCameraIdListLocked
ACameraIdList mCachedCameraIdList; // Init by getOrCreateCameraIdListLocked
- sp<CameraManagerGlobal> mGlobalManager;
+ android::sp<android::CameraManagerGlobal> mGlobalManager;
};
#endif //_ACAMERA_MANAGER_H
diff --git a/camera/tests/Android.mk b/camera/tests/Android.mk
index 3777d94..cde26dd 100644
--- a/camera/tests/Android.mk
+++ b/camera/tests/Android.mk
@@ -32,12 +32,9 @@
libbinder
LOCAL_C_INCLUDES += \
- system/media/camera/include \
system/media/private/camera/include \
system/media/camera/tests \
frameworks/av/services/camera/libcameraservice \
- frameworks/av/include/camera \
- frameworks/native/include \
LOCAL_CFLAGS += -Wall -Wextra
diff --git a/camera/tests/CameraBinderTests.cpp b/camera/tests/CameraBinderTests.cpp
index a36d2f9..0b687b4 100644
--- a/camera/tests/CameraBinderTests.cpp
+++ b/camera/tests/CameraBinderTests.cpp
@@ -32,12 +32,15 @@
#include <hardware/gralloc.h>
#include <camera/CameraMetadata.h>
-#include <camera/ICameraService.h>
-#include <camera/ICameraServiceListener.h>
+#include <android/hardware/ICameraService.h>
+#include <android/hardware/ICameraServiceListener.h>
+#include <android/hardware/BnCameraServiceListener.h>
+#include <android/hardware/camera2/ICameraDeviceUser.h>
+#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
+#include <android/hardware/camera2/BnCameraDeviceCallbacks.h>
#include <camera/camera2/CaptureRequest.h>
-#include <camera/camera2/ICameraDeviceUser.h>
-#include <camera/camera2/ICameraDeviceCallbacks.h>
#include <camera/camera2/OutputConfiguration.h>
+#include <camera/camera2/SubmitInfo.h>
#include <gui/BufferItemConsumer.h>
#include <gui/IGraphicBufferProducer.h>
@@ -60,25 +63,27 @@
#define IDLE_TIMEOUT 2000000000 // ns
// Stub listener implementation
-class TestCameraServiceListener : public BnCameraServiceListener {
- std::map<String16, TorchStatus> mCameraTorchStatuses;
- std::map<int32_t, Status> mCameraStatuses;
+class TestCameraServiceListener : public hardware::BnCameraServiceListener {
+ std::map<String16, int32_t> mCameraTorchStatuses;
+ std::map<int32_t, int32_t> mCameraStatuses;
mutable Mutex mLock;
mutable Condition mCondition;
mutable Condition mTorchCondition;
public:
virtual ~TestCameraServiceListener() {};
- virtual void onStatusChanged(Status status, int32_t cameraId) {
+ virtual binder::Status onStatusChanged(int32_t status, int32_t cameraId) {
Mutex::Autolock l(mLock);
mCameraStatuses[cameraId] = status;
mCondition.broadcast();
+ return binder::Status::ok();
};
- virtual void onTorchStatusChanged(TorchStatus status, const String16& cameraId) {
+ virtual binder::Status onTorchStatusChanged(int32_t status, const String16& cameraId) {
Mutex::Autolock l(mLock);
mCameraTorchStatuses[cameraId] = status;
mTorchCondition.broadcast();
+ return binder::Status::ok();
};
bool waitForNumCameras(size_t num) const {
@@ -96,7 +101,7 @@
return true;
};
- bool waitForTorchState(TorchStatus status, int32_t cameraId) const {
+ bool waitForTorchState(int32_t status, int32_t cameraId) const {
Mutex::Autolock l(mLock);
const auto& iter = mCameraTorchStatuses.find(String16(String8::format("%d", cameraId)));
@@ -116,27 +121,27 @@
return true;
};
- TorchStatus getTorchStatus(int32_t cameraId) const {
+ int32_t getTorchStatus(int32_t cameraId) const {
Mutex::Autolock l(mLock);
const auto& iter = mCameraTorchStatuses.find(String16(String8::format("%d", cameraId)));
if (iter == mCameraTorchStatuses.end()) {
- return ICameraServiceListener::TORCH_STATUS_UNKNOWN;
+ return hardware::ICameraServiceListener::TORCH_STATUS_UNKNOWN;
}
return iter->second;
};
- Status getStatus(int32_t cameraId) const {
+ int32_t getStatus(int32_t cameraId) const {
Mutex::Autolock l(mLock);
const auto& iter = mCameraStatuses.find(cameraId);
if (iter == mCameraStatuses.end()) {
- return ICameraServiceListener::STATUS_UNKNOWN;
+ return hardware::ICameraServiceListener::STATUS_UNKNOWN;
}
return iter->second;
};
};
// Callback implementation
-class TestCameraDeviceCallbacks : public BnCameraDeviceCallbacks {
+class TestCameraDeviceCallbacks : public hardware::camera2::BnCameraDeviceCallbacks {
public:
enum Status {
IDLE,
@@ -149,8 +154,8 @@
protected:
bool mError;
- Status mLastStatus;
- mutable std::vector<Status> mStatusesHit;
+ int32_t mLastStatus;
+ mutable std::vector<int32_t> mStatusesHit;
mutable Mutex mLock;
mutable Condition mStatusCondition;
public:
@@ -158,7 +163,7 @@
virtual ~TestCameraDeviceCallbacks() {}
- virtual void onDeviceError(CameraErrorCode errorCode,
+ virtual binder::Status onDeviceError(int errorCode,
const CaptureResultExtras& resultExtras) {
(void) resultExtras;
ALOGE("%s: onDeviceError occurred with: %d", __FUNCTION__, static_cast<int>(errorCode));
@@ -167,16 +172,18 @@
mLastStatus = ERROR;
mStatusesHit.push_back(mLastStatus);
mStatusCondition.broadcast();
+ return binder::Status::ok();
}
- virtual void onDeviceIdle() {
+ virtual binder::Status onDeviceIdle() {
Mutex::Autolock l(mLock);
mLastStatus = IDLE;
mStatusesHit.push_back(mLastStatus);
mStatusCondition.broadcast();
+ return binder::Status::ok();
}
- virtual void onCaptureStarted(const CaptureResultExtras& resultExtras,
+ virtual binder::Status onCaptureStarted(const CaptureResultExtras& resultExtras,
int64_t timestamp) {
(void) resultExtras;
(void) timestamp;
@@ -184,10 +191,11 @@
mLastStatus = RUNNING;
mStatusesHit.push_back(mLastStatus);
mStatusCondition.broadcast();
+ return binder::Status::ok();
}
- virtual void onResultReceived(const CameraMetadata& metadata,
+ virtual binder::Status onResultReceived(const CameraMetadata& metadata,
const CaptureResultExtras& resultExtras) {
(void) metadata;
(void) resultExtras;
@@ -195,14 +203,16 @@
mLastStatus = SENT_RESULT;
mStatusesHit.push_back(mLastStatus);
mStatusCondition.broadcast();
+ return binder::Status::ok();
}
- virtual void onPrepared(int streamId) {
+ virtual binder::Status onPrepared(int streamId) {
(void) streamId;
Mutex::Autolock l(mLock);
mLastStatus = PREPARED;
mStatusesHit.push_back(mLastStatus);
mStatusCondition.broadcast();
+ return binder::Status::ok();
}
// Test helper functions:
@@ -269,89 +279,106 @@
gDeathNotifier = new DeathNotifier();
}
binder->linkToDeath(gDeathNotifier);
- sp<ICameraService> service = interface_cast<ICameraService>(binder);
+ sp<hardware::ICameraService> service =
+ interface_cast<hardware::ICameraService>(binder);
+ binder::Status res;
- int32_t numCameras = service->getNumberOfCameras(ICameraService::CAMERA_TYPE_ALL);
+ int32_t numCameras = 0;
+ res = service->getNumberOfCameras(hardware::ICameraService::CAMERA_TYPE_ALL, &numCameras);
+ EXPECT_TRUE(res.isOk()) << res;
EXPECT_LE(0, numCameras);
// Check listener binder calls
sp<TestCameraServiceListener> listener(new TestCameraServiceListener());
- EXPECT_EQ(OK, service->addListener(listener));
+ res = service->addListener(listener);
+ EXPECT_TRUE(res.isOk()) << res;
EXPECT_TRUE(listener->waitForNumCameras(numCameras));
for (int32_t i = 0; i < numCameras; i++) {
+ bool isSupported = false;
+ res = service->supportsCameraApi(i,
+ hardware::ICameraService::API_VERSION_2, &isSupported);
+ EXPECT_TRUE(res.isOk()) << res;
+
// We only care about binder calls for the Camera2 API. Camera1 is deprecated.
- status_t camera2Support = service->supportsCameraApi(i, ICameraService::API_VERSION_2);
- if (camera2Support != OK) {
- EXPECT_EQ(-EOPNOTSUPP, camera2Support);
+ if (!isSupported) {
continue;
}
// Check metadata binder call
CameraMetadata metadata;
- EXPECT_EQ(OK, service->getCameraCharacteristics(i, &metadata));
+ res = service->getCameraCharacteristics(i, &metadata);
+ EXPECT_TRUE(res.isOk()) << res;
EXPECT_FALSE(metadata.isEmpty());
// Make sure we're available, or skip device tests otherwise
- ICameraServiceListener::Status s = listener->getStatus(i);
- EXPECT_EQ(ICameraServiceListener::STATUS_AVAILABLE, s);
- if (s != ICameraServiceListener::STATUS_AVAILABLE) {
+ int32_t s = listener->getStatus(i);
+ EXPECT_EQ(::android::hardware::ICameraServiceListener::STATUS_PRESENT, s);
+ if (s != ::android::hardware::ICameraServiceListener::STATUS_PRESENT) {
continue;
}
// Check connect binder calls
sp<TestCameraDeviceCallbacks> callbacks(new TestCameraDeviceCallbacks());
- sp<ICameraDeviceUser> device;
- EXPECT_EQ(OK, service->connectDevice(callbacks, i, String16("meeeeeeeee!"),
- ICameraService::USE_CALLING_UID, /*out*/device));
+ sp<hardware::camera2::ICameraDeviceUser> device;
+ res = service->connectDevice(callbacks, i, String16("meeeeeeeee!"),
+ hardware::ICameraService::USE_CALLING_UID, /*out*/&device);
+ EXPECT_TRUE(res.isOk()) << res;
ASSERT_NE(nullptr, device.get());
device->disconnect();
EXPECT_FALSE(callbacks->hadError());
- ICameraServiceListener::TorchStatus torchStatus = listener->getTorchStatus(i);
- if (torchStatus == ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF) {
+ int32_t torchStatus = listener->getTorchStatus(i);
+ if (torchStatus == hardware::ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF) {
// Check torch calls
- EXPECT_EQ(OK, service->setTorchMode(String16(String8::format("%d", i)),
- /*enabled*/true, callbacks));
+ res = service->setTorchMode(String16(String8::format("%d", i)),
+ /*enabled*/true, callbacks);
+ EXPECT_TRUE(res.isOk()) << res;
EXPECT_TRUE(listener->waitForTorchState(
- ICameraServiceListener::TORCH_STATUS_AVAILABLE_ON, i));
- EXPECT_EQ(OK, service->setTorchMode(String16(String8::format("%d", i)),
- /*enabled*/false, callbacks));
+ hardware::ICameraServiceListener::TORCH_STATUS_AVAILABLE_ON, i));
+ res = service->setTorchMode(String16(String8::format("%d", i)),
+ /*enabled*/false, callbacks);
+ EXPECT_TRUE(res.isOk()) << res;
EXPECT_TRUE(listener->waitForTorchState(
- ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF, i));
+ hardware::ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF, i));
}
}
- EXPECT_EQ(OK, service->removeListener(listener));
+ res = service->removeListener(listener);
+ EXPECT_TRUE(res.isOk()) << res;
}
// Test fixture for client focused binder tests
class CameraClientBinderTest : public testing::Test {
protected:
- sp<ICameraService> service;
+ sp<hardware::ICameraService> service;
int32_t numCameras;
- std::vector<std::pair<sp<TestCameraDeviceCallbacks>, sp<ICameraDeviceUser>>> openDeviceList;
+ std::vector<std::pair<sp<TestCameraDeviceCallbacks>, sp<hardware::camera2::ICameraDeviceUser>>>
+ openDeviceList;
sp<TestCameraServiceListener> serviceListener;
- std::pair<sp<TestCameraDeviceCallbacks>, sp<ICameraDeviceUser>> openNewDevice(int deviceId) {
-
+ std::pair<sp<TestCameraDeviceCallbacks>, sp<hardware::camera2::ICameraDeviceUser>>
+ openNewDevice(int deviceId) {
sp<TestCameraDeviceCallbacks> callbacks(new TestCameraDeviceCallbacks());
- sp<ICameraDeviceUser> device;
+ sp<hardware::camera2::ICameraDeviceUser> device;
{
SCOPED_TRACE("openNewDevice");
- EXPECT_EQ(OK, service->connectDevice(callbacks, deviceId, String16("meeeeeeeee!"),
- ICameraService::USE_CALLING_UID, /*out*/device));
+ binder::Status res = service->connectDevice(callbacks, deviceId, String16("meeeeeeeee!"),
+ hardware::ICameraService::USE_CALLING_UID, /*out*/&device);
+ EXPECT_TRUE(res.isOk()) << res;
}
auto p = std::make_pair(callbacks, device);
openDeviceList.push_back(p);
return p;
}
- void closeDevice(std::pair<sp<TestCameraDeviceCallbacks>, sp<ICameraDeviceUser>>& p) {
+ void closeDevice(std::pair<sp<TestCameraDeviceCallbacks>,
+ sp<hardware::camera2::ICameraDeviceUser>>& p) {
if (p.second.get() != nullptr) {
- p.second->disconnect();
+ binder::Status res = p.second->disconnect();
+ EXPECT_TRUE(res.isOk()) << res;
{
SCOPED_TRACE("closeDevice");
EXPECT_FALSE(p.first->hadError());
@@ -367,10 +394,11 @@
ProcessState::self()->startThreadPool();
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder = sm->getService(String16("media.camera"));
- service = interface_cast<ICameraService>(binder);
+ service = interface_cast<hardware::ICameraService>(binder);
serviceListener = new TestCameraServiceListener();
service->addListener(serviceListener);
- numCameras = service->getNumberOfCameras();
+ service->getNumberOfCameras(hardware::ICameraService::CAMERA_TYPE_BACKWARD_COMPATIBLE,
+ &numCameras);
}
virtual void TearDown() {
@@ -385,19 +413,19 @@
TEST_F(CameraClientBinderTest, CheckBinderCameraDeviceUser) {
ASSERT_NOT_NULL(service);
-
EXPECT_TRUE(serviceListener->waitForNumCameras(numCameras));
for (int32_t i = 0; i < numCameras; i++) {
// Make sure we're available, or skip device tests otherwise
- ICameraServiceListener::Status s = serviceListener->getStatus(i);
- EXPECT_EQ(ICameraServiceListener::STATUS_AVAILABLE, s);
- if (s != ICameraServiceListener::STATUS_AVAILABLE) {
+ int32_t s = serviceListener->getStatus(i);
+ EXPECT_EQ(hardware::ICameraServiceListener::STATUS_PRESENT, s);
+ if (s != hardware::ICameraServiceListener::STATUS_PRESENT) {
continue;
}
+ binder::Status res;
auto p = openNewDevice(i);
sp<TestCameraDeviceCallbacks> callbacks = p.first;
- sp<ICameraDeviceUser> device = p.second;
+ sp<hardware::camera2::ICameraDeviceUser> device = p.second;
// Setup a buffer queue; I'm just using the vendor opaque format here as that is
// guaranteed to be present
@@ -418,50 +446,65 @@
OutputConfiguration output(gbProducer, /*rotation*/0);
// Can we configure?
- EXPECT_EQ(OK, device->beginConfigure());
- status_t streamId = device->createStream(output);
+ res = device->beginConfigure();
+ EXPECT_TRUE(res.isOk()) << res;
+ status_t streamId;
+ res = device->createStream(output, &streamId);
+ EXPECT_TRUE(res.isOk()) << res;
EXPECT_LE(0, streamId);
- EXPECT_EQ(OK, device->endConfigure());
+ res = device->endConfigure(/*isConstrainedHighSpeed*/ false);
+ EXPECT_TRUE(res.isOk()) << res;
EXPECT_FALSE(callbacks->hadError());
// Can we make requests?
CameraMetadata requestTemplate;
- EXPECT_EQ(OK, device->createDefaultRequest(/*preview template*/1,
- /*out*/&requestTemplate));
- sp<CaptureRequest> request(new CaptureRequest());
- request->mMetadata = requestTemplate;
- request->mSurfaceList.add(surface);
- request->mIsReprocess = false;
+ res = device->createDefaultRequest(/*preview template*/1,
+ /*out*/&requestTemplate);
+ EXPECT_TRUE(res.isOk()) << res;
+
+ hardware::camera2::CaptureRequest request;
+ request.mMetadata = requestTemplate;
+ request.mSurfaceList.add(surface);
+ request.mIsReprocess = false;
int64_t lastFrameNumber = 0;
int64_t lastFrameNumberPrev = 0;
callbacks->clearStatus();
- int requestId = device->submitRequest(request, /*streaming*/true, /*out*/&lastFrameNumber);
+
+ hardware::camera2::utils::SubmitInfo info;
+ res = device->submitRequest(request, /*streaming*/true, /*out*/&info);
+ EXPECT_TRUE(res.isOk()) << res;
EXPECT_TRUE(callbacks->waitForStatus(TestCameraDeviceCallbacks::SENT_RESULT));
- EXPECT_LE(0, requestId);
+ EXPECT_LE(0, info.mRequestId);
// Can we stop requests?
- EXPECT_EQ(OK, device->cancelRequest(requestId, /*out*/&lastFrameNumber));
+ res = device->cancelRequest(info.mRequestId, /*out*/&lastFrameNumber);
+ EXPECT_TRUE(res.isOk()) << res;
EXPECT_TRUE(callbacks->waitForIdle());
EXPECT_FALSE(callbacks->hadError());
// Can we do it again?
- lastFrameNumberPrev = lastFrameNumber;
+ lastFrameNumberPrev = info.mLastFrameNumber;
lastFrameNumber = 0;
requestTemplate.clear();
- EXPECT_EQ(OK, device->createDefaultRequest(/*preview template*/1,
- /*out*/&requestTemplate));
- sp<CaptureRequest> request2(new CaptureRequest());
- request2->mMetadata = requestTemplate;
- request2->mSurfaceList.add(surface);
- request2->mIsReprocess = false;
+ res = device->createDefaultRequest(hardware::camera2::ICameraDeviceUser::TEMPLATE_PREVIEW,
+ /*out*/&requestTemplate);
+ EXPECT_TRUE(res.isOk()) << res;
+ hardware::camera2::CaptureRequest request2;
+ request2.mMetadata = requestTemplate;
+ request2.mSurfaceList.add(surface);
+ request2.mIsReprocess = false;
callbacks->clearStatus();
- int requestId2 = device->submitRequest(request2, /*streaming*/true,
- /*out*/&lastFrameNumber);
- EXPECT_EQ(-1, lastFrameNumber);
+ hardware::camera2::utils::SubmitInfo info2;
+ res = device->submitRequest(request2, /*streaming*/true,
+ /*out*/&info2);
+ EXPECT_TRUE(res.isOk()) << res;
+ EXPECT_EQ(hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES,
+ info2.mLastFrameNumber);
lastFrameNumber = 0;
EXPECT_TRUE(callbacks->waitForStatus(TestCameraDeviceCallbacks::SENT_RESULT));
- EXPECT_LE(0, requestId2);
- EXPECT_EQ(OK, device->cancelRequest(requestId2, /*out*/&lastFrameNumber));
+ EXPECT_LE(0, info2.mRequestId);
+ res = device->cancelRequest(info2.mRequestId, /*out*/&lastFrameNumber);
+ EXPECT_TRUE(res.isOk()) << res;
EXPECT_TRUE(callbacks->waitForIdle());
EXPECT_LE(lastFrameNumberPrev, lastFrameNumber);
sleep(/*second*/1); // allow some time for errors to show up, if any
@@ -472,36 +515,44 @@
lastFrameNumber = 0;
requestTemplate.clear();
CameraMetadata requestTemplate2;
- EXPECT_EQ(OK, device->createDefaultRequest(/*preview template*/1,
- /*out*/&requestTemplate));
- EXPECT_EQ(OK, device->createDefaultRequest(/*preview template*/1,
- /*out*/&requestTemplate2));
- sp<CaptureRequest> request3(new CaptureRequest());
- sp<CaptureRequest> request4(new CaptureRequest());
- request3->mMetadata = requestTemplate;
- request3->mSurfaceList.add(surface);
- request3->mIsReprocess = false;
- request4->mMetadata = requestTemplate2;
- request4->mSurfaceList.add(surface);
- request4->mIsReprocess = false;
- List<sp<CaptureRequest>> requestList;
+ res = device->createDefaultRequest(hardware::camera2::ICameraDeviceUser::TEMPLATE_PREVIEW,
+ /*out*/&requestTemplate);
+ EXPECT_TRUE(res.isOk()) << res;
+ res = device->createDefaultRequest(hardware::camera2::ICameraDeviceUser::TEMPLATE_PREVIEW,
+ /*out*/&requestTemplate2);
+ EXPECT_TRUE(res.isOk()) << res;
+ android::hardware::camera2::CaptureRequest request3;
+ android::hardware::camera2::CaptureRequest request4;
+ request3.mMetadata = requestTemplate;
+ request3.mSurfaceList.add(surface);
+ request3.mIsReprocess = false;
+ request4.mMetadata = requestTemplate2;
+ request4.mSurfaceList.add(surface);
+ request4.mIsReprocess = false;
+ std::vector<hardware::camera2::CaptureRequest> requestList;
requestList.push_back(request3);
requestList.push_back(request4);
callbacks->clearStatus();
- int requestId3 = device->submitRequestList(requestList, /*streaming*/false,
- /*out*/&lastFrameNumber);
- EXPECT_LE(0, requestId3);
+ hardware::camera2::utils::SubmitInfo info3;
+ res = device->submitRequestList(requestList, /*streaming*/false,
+ /*out*/&info3);
+ EXPECT_TRUE(res.isOk()) << res;
+ EXPECT_LE(0, info3.mRequestId);
EXPECT_TRUE(callbacks->waitForStatus(TestCameraDeviceCallbacks::SENT_RESULT));
EXPECT_TRUE(callbacks->waitForIdle());
- EXPECT_LE(lastFrameNumberPrev, lastFrameNumber);
+ EXPECT_LE(lastFrameNumberPrev, info3.mLastFrameNumber);
sleep(/*second*/1); // allow some time for errors to show up, if any
EXPECT_FALSE(callbacks->hadError());
// Can we unconfigure?
- EXPECT_EQ(OK, device->beginConfigure());
- EXPECT_EQ(OK, device->deleteStream(streamId));
- EXPECT_EQ(OK, device->endConfigure());
+ res = device->beginConfigure();
+ EXPECT_TRUE(res.isOk()) << res;
+ res = device->deleteStream(streamId);
+ EXPECT_TRUE(res.isOk()) << res;
+ res = device->endConfigure(/*isConstrainedHighSpeed*/ false);
+ EXPECT_TRUE(res.isOk()) << res;
+
sleep(/*second*/1); // allow some time for errors to show up, if any
EXPECT_FALSE(callbacks->hadError());
diff --git a/camera/tests/VendorTagDescriptorTests.cpp b/camera/tests/VendorTagDescriptorTests.cpp
index 9082dbf..75cfb73 100644
--- a/camera/tests/VendorTagDescriptorTests.cpp
+++ b/camera/tests/VendorTagDescriptorTests.cpp
@@ -53,27 +53,27 @@
extern "C" {
-static int zero_get_tag_count(const vendor_tag_ops_t* vOps) {
+static int zero_get_tag_count(const vendor_tag_ops_t*) {
return 0;
}
-static int default_get_tag_count(const vendor_tag_ops_t* vOps) {
+static int default_get_tag_count(const vendor_tag_ops_t*) {
return VENDOR_TAG_COUNT_ERR;
}
-static void default_get_all_tags(const vendor_tag_ops_t* vOps, uint32_t* tagArray) {
+static void default_get_all_tags(const vendor_tag_ops_t*, uint32_t*) {
//Noop
}
-static const char* default_get_section_name(const vendor_tag_ops_t* vOps, uint32_t tag) {
+static const char* default_get_section_name(const vendor_tag_ops_t*, uint32_t) {
return VENDOR_SECTION_NAME_ERR;
}
-static const char* default_get_tag_name(const vendor_tag_ops_t* vOps, uint32_t tag) {
+static const char* default_get_tag_name(const vendor_tag_ops_t*, uint32_t) {
return VENDOR_TAG_NAME_ERR;
}
-static int default_get_tag_type(const vendor_tag_ops_t* vOps, uint32_t tag) {
+static int default_get_tag_type(const vendor_tag_ops_t*, uint32_t) {
return VENDOR_TAG_TYPE_ERR;
}
@@ -141,7 +141,8 @@
// Check whether parcel read/write succeed
EXPECT_EQ(OK, vDescOriginal->writeToParcel(&p));
p.setDataPosition(0);
- ASSERT_EQ(OK, VendorTagDescriptor::createFromParcel(&p, vDescParceled));
+
+ ASSERT_EQ(OK, vDescParceled->readFromParcel(&p));
// Ensure consistent tag count
int tagCount = vDescOriginal->getTagCount();
@@ -197,7 +198,6 @@
EXPECT_EQ(VENDOR_TAG_TYPE_ERR, vDesc->getTagType(BAD_TAG));
// Make sure global can be set/cleared
- const vendor_tag_ops_t *fakeOps = &fakevendor_ops;
sp<VendorTagDescriptor> prevGlobal = VendorTagDescriptor::getGlobalVendorTagDescriptor();
VendorTagDescriptor::clearGlobalVendorTagDescriptor();
@@ -208,4 +208,3 @@
EXPECT_EQ(OK, VendorTagDescriptor::setAsGlobalVendorTagDescriptor(prevGlobal));
EXPECT_EQ(prevGlobal, VendorTagDescriptor::getGlobalVendorTagDescriptor());
}
-
diff --git a/include/camera/Camera.h b/include/camera/Camera.h
index f19d296..b45bbfc 100644
--- a/include/camera/Camera.h
+++ b/include/camera/Camera.h
@@ -18,13 +18,15 @@
#define ANDROID_HARDWARE_CAMERA_H
#include <utils/Timers.h>
+
+#include <android/hardware/ICameraService.h>
+
#include <gui/IGraphicBufferProducer.h>
#include <system/camera.h>
-#include <camera/ICameraClient.h>
#include <camera/ICameraRecordingProxy.h>
#include <camera/ICameraRecordingProxyListener.h>
-#include <camera/ICameraService.h>
-#include <camera/ICamera.h>
+#include <camera/android/hardware/ICamera.h>
+#include <camera/android/hardware/ICameraClient.h>
#include <camera/CameraBase.h>
namespace android {
@@ -48,31 +50,32 @@
template <>
struct CameraTraits<Camera>
{
- typedef CameraListener TCamListener;
- typedef ICamera TCamUser;
- typedef ICameraClient TCamCallbacks;
- typedef status_t (ICameraService::*TCamConnectService)(const sp<ICameraClient>&,
- int, const String16&, int, int,
- /*out*/
- sp<ICamera>&);
+ typedef CameraListener TCamListener;
+ typedef ::android::hardware::ICamera TCamUser;
+ typedef ::android::hardware::ICameraClient TCamCallbacks;
+ typedef ::android::binder::Status(::android::hardware::ICameraService::*TCamConnectService)
+ (const sp<::android::hardware::ICameraClient>&,
+ int, const String16&, int, int,
+ /*out*/
+ sp<::android::hardware::ICamera>*);
static TCamConnectService fnConnectService;
};
class Camera :
public CameraBase<Camera>,
- public BnCameraClient
+ public ::android::hardware::BnCameraClient
{
public:
enum {
- USE_CALLING_UID = ICameraService::USE_CALLING_UID
+ USE_CALLING_UID = ::android::hardware::ICameraService::USE_CALLING_UID
};
enum {
- USE_CALLING_PID = ICameraService::USE_CALLING_PID
+ USE_CALLING_PID = ::android::hardware::ICameraService::USE_CALLING_PID
};
// construct a camera client from an existing remote
- static sp<Camera> create(const sp<ICamera>& camera);
+ static sp<Camera> create(const sp<::android::hardware::ICamera>& camera);
static sp<Camera> connect(int cameraId,
const String16& clientPackageName,
int clientUid, int clientPid);
diff --git a/include/camera/CameraBase.h b/include/camera/CameraBase.h
index d8561ed..0692a27 100644
--- a/include/camera/CameraBase.h
+++ b/include/camera/CameraBase.h
@@ -18,13 +18,18 @@
#define ANDROID_HARDWARE_CAMERA_BASE_H
#include <utils/Mutex.h>
-#include <camera/ICameraService.h>
struct camera_frame_metadata;
namespace android {
-struct CameraInfo {
+namespace hardware {
+
+
+class ICameraService;
+class ICameraServiceListener;
+
+struct CameraInfo : public android::Parcelable {
/**
* The direction that the camera faces to. It should be CAMERA_FACING_BACK
* or CAMERA_FACING_FRONT.
@@ -44,8 +49,17 @@
* right of the screen, the value should be 270.
*/
int orientation;
+
+ virtual status_t writeToParcel(Parcel* parcel) const;
+ virtual status_t readFromParcel(const Parcel* parcel);
+
};
+} // namespace hardware
+
+using hardware::CameraInfo;
+
+
template <typename TCam>
struct CameraTraits {
};
@@ -70,13 +84,13 @@
static status_t getCameraInfo(int cameraId,
/*out*/
- struct CameraInfo* cameraInfo);
+ struct hardware::CameraInfo* cameraInfo);
static status_t addServiceListener(
- const sp<ICameraServiceListener>& listener);
+ const sp<::android::hardware::ICameraServiceListener>& listener);
static status_t removeServiceListener(
- const sp<ICameraServiceListener>& listener);
+ const sp<::android::hardware::ICameraServiceListener>& listener);
sp<TCamUser> remote();
@@ -101,7 +115,7 @@
virtual void binderDied(const wp<IBinder>& who);
// helper function to obtain camera service handle
- static const sp<ICameraService>& getCameraService();
+ static const sp<::android::hardware::ICameraService>& getCameraService();
sp<TCamUser> mCamera;
status_t mStatus;
diff --git a/include/camera/CameraMetadata.h b/include/camera/CameraMetadata.h
index 953d711..db400de 100644
--- a/include/camera/CameraMetadata.h
+++ b/include/camera/CameraMetadata.h
@@ -20,14 +20,14 @@
#include "system/camera_metadata.h"
#include <utils/String8.h>
#include <utils/Vector.h>
+#include <binder/Parcelable.h>
namespace android {
-class Parcel;
/**
* A convenience wrapper around the C-based camera_metadata_t library.
*/
-class CameraMetadata {
+class CameraMetadata: public Parcelable {
public:
/** Creates an empty object; best used when expecting to acquire contents
* from elsewhere */
@@ -186,8 +186,8 @@
*/
// Metadata object is unchanged when reading from parcel fails.
- status_t readFromParcel(Parcel *parcel);
- status_t writeToParcel(Parcel *parcel) const;
+ virtual status_t readFromParcel(const Parcel *parcel) override;
+ virtual status_t writeToParcel(Parcel *parcel) const override;
/**
* Caller becomes the owner of the new metadata
@@ -227,6 +227,15 @@
};
-}; // namespace android
+namespace hardware {
+namespace camera2 {
+namespace impl {
+using ::android::CameraMetadata;
+typedef CameraMetadata CameraMetadataNative;
+}
+}
+}
+
+} // namespace android
#endif
diff --git a/include/camera/CaptureResult.h b/include/camera/CaptureResult.h
index 0be7d6f..ff0e3d3 100644
--- a/include/camera/CaptureResult.h
+++ b/include/camera/CaptureResult.h
@@ -18,15 +18,21 @@
#define ANDROID_HARDWARE_CAPTURERESULT_H
#include <utils/RefBase.h>
+#include <binder/Parcelable.h>
#include <camera/CameraMetadata.h>
+
namespace android {
+namespace hardware {
+namespace camera2 {
+namespace impl {
+
/**
* CaptureResultExtras is a structure to encapsulate various indices for a capture result.
* These indices are framework-internal and not sent to the HAL.
*/
-struct CaptureResultExtras {
+struct CaptureResultExtras : public android::Parcelable {
/**
* An integer to index the request sequence that this result belongs to.
*/
@@ -75,9 +81,14 @@
*/
bool isValid();
- status_t readFromParcel(Parcel* parcel);
- status_t writeToParcel(Parcel* parcel) const;
+ virtual status_t readFromParcel(const Parcel* parcel) override;
+ virtual status_t writeToParcel(Parcel* parcel) const override;
};
+} // namespace impl
+} // namespace camera2
+} // namespace hardware
+
+using hardware::camera2::impl::CaptureResultExtras;
struct CaptureResult : public virtual LightRefBase<CaptureResult> {
CameraMetadata mMetadata;
diff --git a/include/camera/ICameraService.h b/include/camera/ICameraService.h
deleted file mode 100644
index d568b4d..0000000
--- a/include/camera/ICameraService.h
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-#ifndef ANDROID_HARDWARE_ICAMERASERVICE_H
-#define ANDROID_HARDWARE_ICAMERASERVICE_H
-
-#include <utils/RefBase.h>
-#include <binder/IInterface.h>
-#include <binder/Parcel.h>
-
-namespace android {
-
-class ICamera;
-class ICameraClient;
-class ICameraServiceListener;
-class ICameraDeviceUser;
-class ICameraDeviceCallbacks;
-class CameraMetadata;
-class VendorTagDescriptor;
-class String16;
-
-class ICameraService : public IInterface
-{
-public:
- /**
- * Keep up-to-date with ICameraService.aidl in frameworks/base
- */
- enum {
- GET_NUMBER_OF_CAMERAS = IBinder::FIRST_CALL_TRANSACTION,
- GET_CAMERA_INFO,
- CONNECT,
- CONNECT_DEVICE,
- ADD_LISTENER,
- REMOVE_LISTENER,
- GET_CAMERA_CHARACTERISTICS,
- GET_CAMERA_VENDOR_TAG_DESCRIPTOR,
- GET_LEGACY_PARAMETERS,
- SUPPORTS_CAMERA_API,
- CONNECT_LEGACY,
- SET_TORCH_MODE,
- NOTIFY_SYSTEM_EVENT,
- };
-
- enum {
- USE_CALLING_PID = -1
- };
-
- enum {
- USE_CALLING_UID = -1
- };
-
- enum {
- API_VERSION_1 = 1,
- API_VERSION_2 = 2,
- };
-
- enum {
- CAMERA_TYPE_BACKWARD_COMPATIBLE = 0,
- CAMERA_TYPE_ALL = 1,
- };
-
- enum {
- CAMERA_HAL_API_VERSION_UNSPECIFIED = -1
- };
-
- /**
- * Keep up-to-date with declarations in
- * frameworks/base/services/core/java/com/android/server/camera/CameraService.java
- *
- * These event codes are intended to be used with the notifySystemEvent call.
- */
- enum {
- NO_EVENT = 0,
- USER_SWITCHED,
- };
-
-public:
- DECLARE_META_INTERFACE(CameraService);
-
- // Get the number of cameras that support basic color camera operation
- // (type CAMERA_TYPE_BACKWARD_COMPATIBLE)
- virtual int32_t getNumberOfCameras() = 0;
- // Get the number of cameras of the specified type, one of CAMERA_TYPE_*
- // enums
- virtual int32_t getNumberOfCameras(int cameraType) = 0;
- virtual status_t getCameraInfo(int cameraId,
- /*out*/
- struct CameraInfo* cameraInfo) = 0;
-
- virtual status_t getCameraCharacteristics(int cameraId,
- /*out*/
- CameraMetadata* cameraInfo) = 0;
-
- virtual status_t getCameraVendorTagDescriptor(
- /*out*/
- sp<VendorTagDescriptor>& desc) = 0;
-
- // Returns 'OK' if operation succeeded
- // - Errors: ALREADY_EXISTS if the listener was already added
- virtual status_t addListener(const sp<ICameraServiceListener>& listener)
- = 0;
- // Returns 'OK' if operation succeeded
- // - Errors: BAD_VALUE if specified listener was not in the listener list
- virtual status_t removeListener(const sp<ICameraServiceListener>& listener)
- = 0;
- /**
- * clientPackageName, clientUid, and clientPid are used for permissions checking. If
- * clientUid == USE_CALLING_UID, then the calling UID is used instead. If
- * clientPid == USE_CALLING_PID, then the calling PID is used instead. Only
- * trusted callers can set a clientUid and clientPid other than USE_CALLING_UID and
- * USE_CALLING_UID respectively.
- */
- virtual status_t connect(const sp<ICameraClient>& cameraClient,
- int cameraId,
- const String16& clientPackageName,
- int clientUid,
- int clientPid,
- /*out*/
- sp<ICamera>& device) = 0;
-
- virtual status_t connectDevice(
- const sp<ICameraDeviceCallbacks>& cameraCb,
- int cameraId,
- const String16& clientPackageName,
- int clientUid,
- /*out*/
- sp<ICameraDeviceUser>& device) = 0;
-
- virtual status_t getLegacyParameters(
- int cameraId,
- /*out*/
- String16* parameters) = 0;
-
- /**
- * Returns OK if device supports camera2 api,
- * returns -EOPNOTSUPP if it doesn't.
- */
- virtual status_t supportsCameraApi(
- int cameraId, int apiVersion) = 0;
-
- /**
- * Connect the device as a legacy device for a given HAL version.
- * For halVersion, use CAMERA_API_DEVICE_VERSION_* for a particular
- * version, or CAMERA_HAL_API_VERSION_UNSPECIFIED for a service-selected version.
- */
- virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient,
- int cameraId, int halVersion,
- const String16& clientPackageName,
- int clientUid,
- /*out*/
- sp<ICamera>& device) = 0;
-
- /**
- * Turn on or off a camera's torch mode. Torch mode will be turned off by
- * camera service if the lastest client binder that turns it on dies.
- *
- * return values:
- * 0: on a successful operation.
- * -ENOSYS: the camera device doesn't support this operation. It it returned
- * if and only if android.flash.into.available is false.
- * -EBUSY: the camera device is opened.
- * -EINVAL: camera_id is invalid or clientBinder is NULL when enabling a
- * torch mode.
- */
- virtual status_t setTorchMode(const String16& cameraId, bool enabled,
- const sp<IBinder>& clientBinder) = 0;
-
- /**
- * Notify the camera service of a system event. Should only be called from system_server.
- */
- virtual void notifySystemEvent(int32_t eventId, const int32_t* args, size_t length) = 0;
-};
-
-// ----------------------------------------------------------------------------
-
-class BnCameraService: public BnInterface<ICameraService>
-{
-public:
- virtual status_t onTransact( uint32_t code,
- const Parcel& data,
- Parcel* reply,
- uint32_t flags = 0);
-};
-
-}; // namespace android
-
-#endif
diff --git a/include/camera/ICameraServiceListener.h b/include/camera/ICameraServiceListener.h
deleted file mode 100644
index 709ff31..0000000
--- a/include/camera/ICameraServiceListener.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#ifndef ANDROID_HARDWARE_ICAMERASERVICE_LISTENER_H
-#define ANDROID_HARDWARE_ICAMERASERVICE_LISTENER_H
-
-#include <utils/RefBase.h>
-#include <binder/IInterface.h>
-#include <binder/Parcel.h>
-#include <hardware/camera_common.h>
-
-namespace android {
-
-class ICameraServiceListener : public IInterface
-{
- /**
- * Keep up-to-date with ICameraServiceListener.aidl in frameworks/base
- */
-public:
-
- /**
- * Initial status will be transmitted with onStatusChange immediately
- * after this listener is added to the service listener list.
- *
- * Allowed transitions:
- *
- * (Any) -> NOT_PRESENT
- * NOT_PRESENT -> PRESENT
- * NOT_PRESENT -> ENUMERATING
- * ENUMERATING -> PRESENT
- * PRESENT -> NOT_AVAILABLE
- * NOT_AVAILABLE -> PRESENT
- *
- * A state will never immediately transition back to itself.
- */
- enum Status {
- // Device physically unplugged
- STATUS_NOT_PRESENT = CAMERA_DEVICE_STATUS_NOT_PRESENT,
- // Device physically has been plugged in
- // and the camera can be used exlusively
- STATUS_PRESENT = CAMERA_DEVICE_STATUS_PRESENT,
- // Device physically has been plugged in
- // but it will not be connect-able until enumeration is complete
- STATUS_ENUMERATING = CAMERA_DEVICE_STATUS_ENUMERATING,
-
- // Camera can be used exclusively
- STATUS_AVAILABLE = STATUS_PRESENT, // deprecated, will be removed
-
- // Camera is in use by another app and cannot be used exclusively
- STATUS_NOT_AVAILABLE = 0x80000000,
-
- // Use to initialize variables only
- STATUS_UNKNOWN = 0xFFFFFFFF,
- };
-
- /**
- * The torch mode status of a camera.
- *
- * Initial status will be transmitted with onTorchStatusChanged immediately
- * after this listener is added to the service listener list.
- *
- * The enums should be set to values matching
- * include/hardware/camera_common.h
- */
- enum TorchStatus {
- // The camera's torch mode has become not available to use via
- // setTorchMode().
- TORCH_STATUS_NOT_AVAILABLE = TORCH_MODE_STATUS_NOT_AVAILABLE,
- // The camera's torch mode is off and available to be turned on via
- // setTorchMode().
- TORCH_STATUS_AVAILABLE_OFF = TORCH_MODE_STATUS_AVAILABLE_OFF,
- // The camera's torch mode is on and available to be turned off via
- // setTorchMode().
- TORCH_STATUS_AVAILABLE_ON = TORCH_MODE_STATUS_AVAILABLE_ON,
-
- // Use to initialize variables only
- TORCH_STATUS_UNKNOWN = 0xFFFFFFFF,
- };
-
- DECLARE_META_INTERFACE(CameraServiceListener);
-
- virtual void onStatusChanged(Status status, int32_t cameraId) = 0;
-
- virtual void onTorchStatusChanged(TorchStatus status, const String16& cameraId) = 0;
-};
-
-// ----------------------------------------------------------------------------
-
-class BnCameraServiceListener : public BnInterface<ICameraServiceListener>
-{
-public:
- virtual status_t onTransact( uint32_t code,
- const Parcel& data,
- Parcel* reply,
- uint32_t flags = 0);
-};
-
-}; // namespace android
-
-#endif
diff --git a/include/camera/VendorTagDescriptor.h b/include/camera/VendorTagDescriptor.h
index 1758acf..4c1cab6 100644
--- a/include/camera/VendorTagDescriptor.h
+++ b/include/camera/VendorTagDescriptor.h
@@ -16,6 +16,7 @@
#ifndef VENDOR_TAG_DESCRIPTOR_H
+#include <binder/Parcelable.h>
#include <utils/Vector.h>
#include <utils/KeyedVector.h>
#include <utils/String8.h>
@@ -26,18 +27,27 @@
namespace android {
-class Parcel;
+class VendorTagDescriptor;
+
+namespace hardware {
+namespace camera2 {
+namespace params {
/**
* VendorTagDescriptor objects are parcelable containers for the vendor tag
* definitions provided, and are typically used to pass the vendor tag
* information enumerated by the HAL to clients of the camera service.
*/
-class VendorTagDescriptor
- : public LightRefBase<VendorTagDescriptor> {
+class VendorTagDescriptor : public Parcelable {
public:
virtual ~VendorTagDescriptor();
+ VendorTagDescriptor();
+ VendorTagDescriptor(const VendorTagDescriptor& src);
+ VendorTagDescriptor& operator=(const VendorTagDescriptor& rhs);
+
+ void copyFrom(const VendorTagDescriptor& src);
+
/**
* The following 'get*' methods implement the corresponding
* functions defined in
@@ -64,9 +74,9 @@
*
* Returns OK on success, or a negative error code.
*/
- status_t writeToParcel(
+ virtual status_t writeToParcel(
/*out*/
- Parcel* parcel) const;
+ Parcel* parcel) const override;
/**
* Convenience method to get a vector containing all vendor tag
@@ -86,48 +96,14 @@
*/
void dump(int fd, int verbosity, int indentation) const;
- // Static methods:
-
/**
- * Create a VendorTagDescriptor object from the given parcel.
+ * Read values VendorTagDescriptor object from the given parcel.
*
* Returns OK on success, or a negative error code.
*/
- static status_t createFromParcel(const Parcel* parcel,
- /*out*/
- sp<VendorTagDescriptor>& descriptor);
+ virtual status_t readFromParcel(const Parcel* parcel) override;
- /**
- * Create a VendorTagDescriptor object from the given vendor_tag_ops_t
- * struct.
- *
- * Returns OK on success, or a negative error code.
- */
- static status_t createDescriptorFromOps(const vendor_tag_ops_t* vOps,
- /*out*/
- sp<VendorTagDescriptor>& descriptor);
-
- /**
- * Sets the global vendor tag descriptor to use for this process.
- * Camera metadata operations that access vendor tags will use the
- * vendor tag definitions set this way.
- *
- * Returns OK on success, or a negative error code.
- */
- static status_t setAsGlobalVendorTagDescriptor(const sp<VendorTagDescriptor>& desc);
-
- /**
- * Clears the global vendor tag descriptor used by this process.
- */
- static void clearGlobalVendorTagDescriptor();
-
- /**
- * Returns the global vendor tag descriptor used by this process.
- * This will contain NULL if no vendor tags are defined.
- */
- static sp<VendorTagDescriptor> getGlobalVendorTagDescriptor();
protected:
- VendorTagDescriptor();
KeyedVector<String8, KeyedVector<String8, uint32_t>*> mReverseMapping;
KeyedVector<uint32_t, String8> mTagToNameMap;
KeyedVector<uint32_t, uint32_t> mTagToSectionMap; // Value is offset in mSections
@@ -135,11 +111,61 @@
SortedVector<String8> mSections;
// must be int32_t to be compatible with Parcel::writeInt32
int32_t mTagCount;
- private:
+
vendor_tag_ops mVendorOps;
};
+} /* namespace params */
+} /* namespace camera2 */
+} /* namespace hardware */
+
+/**
+ * This version of VendorTagDescriptor must be stored in Android sp<>, and adds support for using it
+ * as a global tag descriptor.
+ *
+ * It's a child class of the basic hardware::camera2::params::VendorTagDescriptor since basic
+ * Parcelable objects cannot require being kept in an sp<> and still work with auto-generated AIDL
+ * interface implementations.
+ */
+class VendorTagDescriptor :
+ public ::android::hardware::camera2::params::VendorTagDescriptor,
+ public LightRefBase<VendorTagDescriptor> {
+
+ public:
+
+ /**
+ * Create a VendorTagDescriptor object from the given vendor_tag_ops_t
+ * struct.
+ *
+ * Returns OK on success, or a negative error code.
+ */
+ static status_t createDescriptorFromOps(const vendor_tag_ops_t* vOps,
+ /*out*/
+ sp<VendorTagDescriptor>& descriptor);
+
+ /**
+ * Sets the global vendor tag descriptor to use for this process.
+ * Camera metadata operations that access vendor tags will use the
+ * vendor tag definitions set this way.
+ *
+ * Returns OK on success, or a negative error code.
+ */
+ static status_t setAsGlobalVendorTagDescriptor(const sp<VendorTagDescriptor>& desc);
+
+ /**
+ * Returns the global vendor tag descriptor used by this process.
+ * This will contain NULL if no vendor tags are defined.
+ */
+ static sp<VendorTagDescriptor> getGlobalVendorTagDescriptor();
+
+ /**
+ * Clears the global vendor tag descriptor used by this process.
+ */
+ static void clearGlobalVendorTagDescriptor();
+
+};
} /* namespace android */
+
#define VENDOR_TAG_DESCRIPTOR_H
#endif /* VENDOR_TAG_DESCRIPTOR_H */
diff --git a/include/camera/ICamera.h b/include/camera/android/hardware/ICamera.h
similarity index 96%
rename from include/camera/ICamera.h
rename to include/camera/android/hardware/ICamera.h
index e35c3a4..322b741 100644
--- a/include/camera/ICamera.h
+++ b/include/camera/android/hardware/ICamera.h
@@ -21,15 +21,18 @@
#include <binder/IInterface.h>
#include <binder/Parcel.h>
#include <binder/IMemory.h>
+#include <binder/Status.h>
#include <utils/String8.h>
-#include <camera/Camera.h>
namespace android {
-class ICameraClient;
class IGraphicBufferProducer;
class Surface;
+namespace hardware {
+
+class ICameraClient;
+
class ICamera: public IInterface
{
/**
@@ -47,7 +50,7 @@
DECLARE_META_INTERFACE(Camera);
- virtual void disconnect() = 0;
+ virtual binder::Status disconnect() = 0;
// connect new client with existing camera remote
virtual status_t connect(const sp<ICameraClient>& client) = 0;
@@ -141,6 +144,7 @@
uint32_t flags = 0);
};
-}; // namespace android
+} // namespace hardware
+} // namespace android
#endif
diff --git a/include/camera/ICameraClient.h b/include/camera/android/hardware/ICameraClient.h
similarity index 93%
rename from include/camera/ICameraClient.h
rename to include/camera/android/hardware/ICameraClient.h
index 1584dba..d7f9a75 100644
--- a/include/camera/ICameraClient.h
+++ b/include/camera/android/hardware/ICameraClient.h
@@ -25,12 +25,10 @@
#include <system/camera.h>
namespace android {
+namespace hardware {
class ICameraClient: public IInterface
{
- /**
- * Keep up-to-date with ICameraClient.aidl in frameworks/base
- */
public:
DECLARE_META_INTERFACE(CameraClient);
@@ -51,6 +49,7 @@
uint32_t flags = 0);
};
-}; // namespace android
+} // namespace hardware
+} // namespace android
#endif
diff --git a/include/camera/camera2/CaptureRequest.h b/include/camera/camera2/CaptureRequest.h
index 1dd15c4..c989f26 100644
--- a/include/camera/camera2/CaptureRequest.h
+++ b/include/camera/camera2/CaptureRequest.h
@@ -19,15 +19,17 @@
#include <utils/RefBase.h>
#include <utils/Vector.h>
+#include <binder/Parcelable.h>
#include <camera/CameraMetadata.h>
namespace android {
class Surface;
-struct CaptureRequest : public RefBase {
-public:
+namespace hardware {
+namespace camera2 {
+struct CaptureRequest : public Parcelable {
CameraMetadata mMetadata;
Vector<sp<Surface> > mSurfaceList;
bool mIsReprocess;
@@ -35,9 +37,20 @@
/**
* Keep impl up-to-date with CaptureRequest.java in frameworks/base
*/
- status_t readFromParcel(Parcel* parcel);
- status_t writeToParcel(Parcel* parcel) const;
+ status_t readFromParcel(const Parcel* parcel) override;
+ status_t writeToParcel(Parcel* parcel) const override;
};
-}; // namespace android
+
+} // namespace camera2
+} // namespace hardware
+
+struct CaptureRequest :
+ public RefBase, public hardware::camera2::CaptureRequest {
+ public:
+ // Same as android::hardware::camera2::CaptureRequest, except that you can
+ // put this in an sp<>
+};
+
+} // namespace android
#endif
diff --git a/include/camera/camera2/ICameraDeviceCallbacks.h b/include/camera/camera2/ICameraDeviceCallbacks.h
deleted file mode 100644
index c57b39f..0000000
--- a/include/camera/camera2/ICameraDeviceCallbacks.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#ifndef ANDROID_HARDWARE_PHOTOGRAPHY_CALLBACKS_H
-#define ANDROID_HARDWARE_PHOTOGRAPHY_CALLBACKS_H
-
-#include <utils/RefBase.h>
-#include <binder/IInterface.h>
-#include <binder/Parcel.h>
-#include <binder/IMemory.h>
-#include <utils/Timers.h>
-#include <system/camera.h>
-
-#include <camera/CaptureResult.h>
-
-namespace android {
-class CameraMetadata;
-
-
-class ICameraDeviceCallbacks : public IInterface
-{
- /**
- * Keep up-to-date with ICameraDeviceCallbacks.aidl in frameworks/base
- */
-public:
- DECLARE_META_INTERFACE(CameraDeviceCallbacks);
-
- /**
- * Error codes for CAMERA_MSG_ERROR
- */
- enum CameraErrorCode {
- ERROR_CAMERA_INVALID_ERROR = -1, // To indicate all invalid error codes
- ERROR_CAMERA_DISCONNECTED = 0,
- ERROR_CAMERA_DEVICE = 1,
- ERROR_CAMERA_SERVICE = 2,
- ERROR_CAMERA_REQUEST = 3,
- ERROR_CAMERA_RESULT = 4,
- ERROR_CAMERA_BUFFER = 5,
- };
-
- // One way
- virtual void onDeviceError(CameraErrorCode errorCode,
- const CaptureResultExtras& resultExtras) = 0;
-
- // One way
- virtual void onDeviceIdle() = 0;
-
- // One way
- virtual void onCaptureStarted(const CaptureResultExtras& resultExtras,
- int64_t timestamp) = 0;
-
- // One way
- virtual void onResultReceived(const CameraMetadata& metadata,
- const CaptureResultExtras& resultExtras) = 0;
-
- // One way
- virtual void onPrepared(int streamId) = 0;
-};
-
-// ----------------------------------------------------------------------------
-
-class BnCameraDeviceCallbacks : public BnInterface<ICameraDeviceCallbacks>
-{
-public:
- virtual status_t onTransact( uint32_t code,
- const Parcel& data,
- Parcel* reply,
- uint32_t flags = 0);
-};
-
-}; // namespace android
-
-#endif
diff --git a/include/camera/camera2/ICameraDeviceUser.h b/include/camera/camera2/ICameraDeviceUser.h
deleted file mode 100644
index 4d8eb53..0000000
--- a/include/camera/camera2/ICameraDeviceUser.h
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#ifndef ANDROID_HARDWARE_PHOTOGRAPHY_ICAMERADEVICEUSER_H
-#define ANDROID_HARDWARE_PHOTOGRAPHY_ICAMERADEVICEUSER_H
-
-#include <binder/IInterface.h>
-#include <binder/Parcel.h>
-#include <utils/List.h>
-
-struct camera_metadata;
-
-namespace android {
-
-class ICameraDeviceUserClient;
-class IGraphicBufferProducer;
-class CaptureRequest;
-class CameraMetadata;
-class OutputConfiguration;
-
-enum {
- NO_IN_FLIGHT_REPEATING_FRAMES = -1,
-};
-
-class ICameraDeviceUser : public IInterface
-{
- /**
- * Keep up-to-date with ICameraDeviceUser.aidl in frameworks/base
- */
-public:
- DECLARE_META_INTERFACE(CameraDeviceUser);
-
- virtual void disconnect() = 0;
-
- /**
- * Request Handling
- **/
-
- /**
- * For streaming requests, output lastFrameNumber is the last frame number
- * of the previous repeating request.
- * For non-streaming requests, output lastFrameNumber is the expected last
- * frame number of the current request.
- */
- virtual int submitRequest(sp<CaptureRequest> request,
- bool streaming = false,
- /*out*/
- int64_t* lastFrameNumber = NULL) = 0;
-
- /**
- * For streaming requests, output lastFrameNumber is the last frame number
- * of the previous repeating request.
- * For non-streaming requests, output lastFrameNumber is the expected last
- * frame number of the current request.
- */
- virtual int submitRequestList(List<sp<CaptureRequest> > requestList,
- bool streaming = false,
- /*out*/
- int64_t* lastFrameNumber = NULL) = 0;
-
- /**
- * Output lastFrameNumber is the last frame number of the previous repeating request.
- */
- virtual status_t cancelRequest(int requestId,
- /*out*/
- int64_t* lastFrameNumber = NULL) = 0;
-
- /**
- * Begin the device configuration.
- *
- * <p>
- * beginConfigure must be called before any call to deleteStream, createStream,
- * or endConfigure. It is not valid to call this when the device is not idle.
- * <p>
- */
- virtual status_t beginConfigure() = 0;
-
- /**
- * End the device configuration.
- *
- * <p>
- * endConfigure must be called after stream configuration is complete (i.e. after
- * a call to beginConfigure and subsequent createStream/deleteStream calls). This
- * must be called before any requests can be submitted.
- * <p>
- */
- virtual status_t endConfigure(bool isConstrainedHighSpeed = false) = 0;
-
- virtual status_t deleteStream(int streamId) = 0;
-
- virtual status_t createStream(const OutputConfiguration& outputConfiguration) = 0;
-
- /**
- * Create an input stream of width, height, and format (one of
- * HAL_PIXEL_FORMAT_*)
- *
- * Return stream ID if it's a non-negative value. status_t if it's a
- * negative value.
- */
- virtual status_t createInputStream(int width, int height, int format) = 0;
-
- // get the buffer producer of the input stream
- virtual status_t getInputBufferProducer(
- sp<IGraphicBufferProducer> *producer) = 0;
-
- // Create a request object from a template.
- virtual status_t createDefaultRequest(int templateId,
- /*out*/
- CameraMetadata* request) = 0;
- // Get static camera metadata
- virtual status_t getCameraInfo(/*out*/
- CameraMetadata* info) = 0;
-
- // Wait until all the submitted requests have finished processing
- virtual status_t waitUntilIdle() = 0;
-
- /**
- * Flush all pending and in-progress work as quickly as possible.
- * Output lastFrameNumber is the last frame number of the previous repeating request.
- */
- virtual status_t flush(/*out*/
- int64_t* lastFrameNumber = NULL) = 0;
-
- /**
- * Preallocate buffers for a given output stream asynchronously.
- */
- virtual status_t prepare(int streamId) = 0;
-
- /**
- * Preallocate up to maxCount buffers for a given output stream asynchronously.
- */
- virtual status_t prepare2(int maxCount, int streamId) = 0;
-
- /**
- * Free all unused buffers for a given output stream.
- */
- virtual status_t tearDown(int streamId) = 0;
-
-};
-
-// ----------------------------------------------------------------------------
-
-class BnCameraDeviceUser: public BnInterface<ICameraDeviceUser>
-{
-public:
- virtual status_t onTransact( uint32_t code,
- const Parcel& data,
- Parcel* reply,
- uint32_t flags = 0);
-};
-
-}; // namespace android
-
-#endif
diff --git a/include/camera/camera2/OutputConfiguration.h b/include/camera/camera2/OutputConfiguration.h
index 137d98c..72a3753 100644
--- a/include/camera/camera2/OutputConfiguration.h
+++ b/include/camera/camera2/OutputConfiguration.h
@@ -18,12 +18,17 @@
#define ANDROID_HARDWARE_CAMERA2_OUTPUTCONFIGURATION_H
#include <gui/IGraphicBufferProducer.h>
+#include <binder/Parcelable.h>
namespace android {
class Surface;
-class OutputConfiguration {
+namespace hardware {
+namespace camera2 {
+namespace params {
+
+class OutputConfiguration : public android::Parcelable {
public:
static const int INVALID_ROTATION;
@@ -35,9 +40,18 @@
/**
* Keep impl up-to-date with OutputConfiguration.java in frameworks/base
*/
- status_t writeToParcel(Parcel& parcel) const;
+ virtual status_t writeToParcel(Parcel* parcel) const override;
+
+ virtual status_t readFromParcel(const Parcel* parcel) override;
+
+ // getGraphicBufferProducer will be NULL
+ // getRotation will be INVALID_ROTATION
+ // getSurfaceSetID will be INVALID_SET_ID
+ OutputConfiguration();
+
// getGraphicBufferProducer will be NULL if error occurred
// getRotation will be INVALID_ROTATION if error occurred
+ // getSurfaceSetID will be INVALID_SET_ID if error occurred
OutputConfiguration(const Parcel& parcel);
OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
@@ -45,7 +59,8 @@
bool operator == (const OutputConfiguration& other) const {
return (mGbp == other.mGbp &&
- mRotation == other.mRotation);
+ mRotation == other.mRotation &&
+ mSurfaceSetID == other.mSurfaceSetID);
}
bool operator != (const OutputConfiguration& other) const {
return !(*this == other);
@@ -53,6 +68,9 @@
bool operator < (const OutputConfiguration& other) const {
if (*this == other) return false;
if (mGbp != other.mGbp) return mGbp < other.mGbp;
+ if (mSurfaceSetID != other.mSurfaceSetID) {
+ return mSurfaceSetID < other.mSurfaceSetID;
+ }
return mRotation < other.mRotation;
}
bool operator > (const OutputConfiguration& other) const {
@@ -64,8 +82,15 @@
int mRotation;
int mSurfaceSetID;
// helper function
- static String16 readMaybeEmptyString16(const Parcel& parcel);
+ static String16 readMaybeEmptyString16(const Parcel* parcel);
};
+} // namespace params
+} // namespace camera2
+} // namespace hardware
+
+
+using hardware::camera2::params::OutputConfiguration;
+
}; // namespace android
#endif
diff --git a/include/camera/camera2/SubmitInfo.h b/include/camera/camera2/SubmitInfo.h
new file mode 100644
index 0000000..3b47b32
--- /dev/null
+++ b/include/camera/camera2/SubmitInfo.h
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+#ifndef ANDROID_HARDWARE_CAMERA2_UTIL_SUBMITINFO_H
+#define ANDROID_HARDWARE_CAMERA2_UTIL_SUBMITINFO_H
+
+#include <binder/Parcel.h>
+#include <binder/Parcelable.h>
+
+namespace android {
+namespace hardware {
+namespace camera2 {
+namespace utils {
+
+struct SubmitInfo : public android::Parcelable {
+public:
+
+ int32_t mRequestId;
+ int64_t mLastFrameNumber;
+
+ virtual status_t writeToParcel(Parcel *parcel) const override;
+ virtual status_t readFromParcel(const Parcel* parcel) override;
+
+};
+
+} // namespace utils
+} // namespace camera2
+} // namespace hardware
+} // namespace android
+
+#endif
diff --git a/include/media/IMediaRecorder.h b/include/media/IMediaRecorder.h
index caa6592..68a65f0 100644
--- a/include/media/IMediaRecorder.h
+++ b/include/media/IMediaRecorder.h
@@ -23,7 +23,9 @@
namespace android {
class Surface;
+namespace hardware {
class ICamera;
+}
class ICameraRecordingProxy;
class IMediaRecorderClient;
class IGraphicBufferConsumer;
@@ -34,7 +36,7 @@
public:
DECLARE_META_INTERFACE(MediaRecorder);
- virtual status_t setCamera(const sp<ICamera>& camera,
+ virtual status_t setCamera(const sp<hardware::ICamera>& camera,
const sp<ICameraRecordingProxy>& proxy) = 0;
virtual status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface) = 0;
virtual status_t setVideoSource(int vs) = 0;
diff --git a/include/media/MediaRecorderBase.h b/include/media/MediaRecorderBase.h
index c05d782..5195993 100644
--- a/include/media/MediaRecorderBase.h
+++ b/include/media/MediaRecorderBase.h
@@ -42,7 +42,7 @@
virtual status_t setVideoEncoder(video_encoder ve) = 0;
virtual status_t setVideoSize(int width, int height) = 0;
virtual status_t setVideoFrameRate(int frames_per_second) = 0;
- virtual status_t setCamera(const sp<ICamera>& camera,
+ virtual status_t setCamera(const sp<hardware::ICamera>& camera,
const sp<ICameraRecordingProxy>& proxy) = 0;
virtual status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface) = 0;
virtual status_t setOutputFile(int fd, int64_t offset, int64_t length) = 0;
diff --git a/include/media/mediarecorder.h b/include/media/mediarecorder.h
index 64e3660..c3f39a2 100644
--- a/include/media/mediarecorder.h
+++ b/include/media/mediarecorder.h
@@ -29,12 +29,15 @@
class Surface;
class IMediaRecorder;
-class ICamera;
class ICameraRecordingProxy;
class IGraphicBufferProducer;
struct PersistentSurface;
class Surface;
+namespace hardware {
+class ICamera;
+}
+
typedef void (*media_completion_f)(status_t status, void *cookie);
enum video_source {
@@ -216,7 +219,8 @@
void died();
status_t initCheck();
- status_t setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy);
+ status_t setCamera(const sp<hardware::ICamera>& camera,
+ const sp<ICameraRecordingProxy>& proxy);
status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface);
status_t setVideoSource(int vs);
status_t setAudioSource(int as);
diff --git a/include/media/stagefright/CameraSource.h b/include/media/stagefright/CameraSource.h
index 64c3044..2fe592e 100644
--- a/include/media/stagefright/CameraSource.h
+++ b/include/media/stagefright/CameraSource.h
@@ -20,7 +20,8 @@
#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/MediaSource.h>
-#include <camera/ICamera.h>
+#include <camera/android/hardware/ICamera.h>
+#include <camera/ICameraRecordingProxy.h>
#include <camera/ICameraRecordingProxyListener.h>
#include <camera/CameraParameters.h>
#include <gui/BufferItemConsumer.h>
@@ -78,7 +79,7 @@
*
* @return NULL on error.
*/
- static CameraSource *CreateFromCamera(const sp<ICamera> &camera,
+ static CameraSource *CreateFromCamera(const sp<hardware::ICamera> &camera,
const sp<ICameraRecordingProxy> &proxy,
int32_t cameraId,
const String16& clientName,
@@ -200,7 +201,7 @@
// Time between capture of two frames.
int64_t mTimeBetweenFrameCaptureUs;
- CameraSource(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
+ CameraSource(const sp<hardware::ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
int32_t cameraId, const String16& clientName, uid_t clientUid, pid_t clientPid,
Size videoSize, int32_t frameRate,
const sp<IGraphicBufferProducer>& surface,
@@ -263,12 +264,12 @@
// Process a buffer item received in BufferQueueListener.
void processBufferQueueFrame(const BufferItem& buffer);
- status_t init(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
+ status_t init(const sp<hardware::ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
int32_t cameraId, const String16& clientName, uid_t clientUid, pid_t clientPid,
Size videoSize, int32_t frameRate, bool storeMetaDataInVideoBuffers);
status_t initWithCameraAccess(
- const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
+ const sp<hardware::ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
int32_t cameraId, const String16& clientName, uid_t clientUid, pid_t clientPid,
Size videoSize, int32_t frameRate, bool storeMetaDataInVideoBuffers);
@@ -276,7 +277,7 @@
status_t initBufferQueue(uint32_t width, uint32_t height, uint32_t format,
android_dataspace dataSpace, uint32_t bufferCount);
- status_t isCameraAvailable(const sp<ICamera>& camera,
+ status_t isCameraAvailable(const sp<hardware::ICamera>& camera,
const sp<ICameraRecordingProxy>& proxy,
int32_t cameraId,
const String16& clientName,
diff --git a/include/media/stagefright/CameraSourceTimeLapse.h b/include/media/stagefright/CameraSourceTimeLapse.h
index 1023027..77c9b8f 100644
--- a/include/media/stagefright/CameraSourceTimeLapse.h
+++ b/include/media/stagefright/CameraSourceTimeLapse.h
@@ -26,14 +26,17 @@
namespace android {
+namespace hardware {
class ICamera;
+}
+
class IMemory;
class Camera;
class CameraSourceTimeLapse : public CameraSource {
public:
static CameraSourceTimeLapse *CreateFromCamera(
- const sp<ICamera> &camera,
+ const sp<hardware::ICamera> &camera,
const sp<ICameraRecordingProxy> &proxy,
int32_t cameraId,
const String16& clientName,
@@ -110,7 +113,7 @@
status_t mLastReadStatus;
CameraSourceTimeLapse(
- const sp<ICamera> &camera,
+ const sp<hardware::ICamera> &camera,
const sp<ICameraRecordingProxy> &proxy,
int32_t cameraId,
const String16& clientName,
diff --git a/media/libmedia/IMediaRecorder.cpp b/media/libmedia/IMediaRecorder.cpp
index 0eea820..cded55c 100644
--- a/media/libmedia/IMediaRecorder.cpp
+++ b/media/libmedia/IMediaRecorder.cpp
@@ -23,7 +23,8 @@
#include <utils/Log.h>
#include <binder/Parcel.h>
-#include <camera/ICamera.h>
+#include <camera/android/hardware/ICamera.h>
+#include <camera/ICameraRecordingProxy.h>
#include <media/IMediaRecorderClient.h>
#include <media/IMediaRecorder.h>
#include <gui/Surface.h>
@@ -67,7 +68,7 @@
{
}
- status_t setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy)
+ status_t setCamera(const sp<hardware::ICamera>& camera, const sp<ICameraRecordingProxy>& proxy)
{
ALOGV("setCamera(%p,%p)", camera.get(), proxy.get());
Parcel data, reply;
@@ -479,9 +480,10 @@
case SET_CAMERA: {
ALOGV("SET_CAMERA");
CHECK_INTERFACE(IMediaRecorder, data, reply);
- sp<ICamera> camera = interface_cast<ICamera>(data.readStrongBinder());
+ sp<hardware::ICamera> camera =
+ interface_cast<hardware::ICamera>(data.readStrongBinder());
sp<ICameraRecordingProxy> proxy =
- interface_cast<ICameraRecordingProxy>(data.readStrongBinder());
+ interface_cast<ICameraRecordingProxy>(data.readStrongBinder());
reply->writeInt32(setCamera(camera, proxy));
return NO_ERROR;
} break;
diff --git a/media/libmedia/mediarecorder.cpp b/media/libmedia/mediarecorder.cpp
index bfdf41d..de3b214 100644
--- a/media/libmedia/mediarecorder.cpp
+++ b/media/libmedia/mediarecorder.cpp
@@ -32,7 +32,8 @@
namespace android {
-status_t MediaRecorder::setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy)
+status_t MediaRecorder::setCamera(const sp<hardware::ICamera>& camera,
+ const sp<ICameraRecordingProxy>& proxy)
{
ALOGV("setCamera(%p,%p)", camera.get(), proxy.get());
if (mMediaRecorder == NULL) {
diff --git a/media/libmediaplayerservice/Android.mk b/media/libmediaplayerservice/Android.mk
index 81f2af3..7f41143 100644
--- a/media/libmediaplayerservice/Android.mk
+++ b/media/libmediaplayerservice/Android.mk
@@ -51,6 +51,7 @@
$(TOP)/frameworks/av/media/libstagefright/rtsp \
$(TOP)/frameworks/av/media/libstagefright/wifi-display \
$(TOP)/frameworks/av/media/libstagefright/webm \
+ $(TOP)/frameworks/av/include/camera \
$(TOP)/frameworks/native/include/media/openmax \
$(TOP)/external/tremolo/Tremolo \
diff --git a/media/libmediaplayerservice/MediaRecorderClient.cpp b/media/libmediaplayerservice/MediaRecorderClient.cpp
index 3b4e148..73abe99 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.cpp
+++ b/media/libmediaplayerservice/MediaRecorderClient.cpp
@@ -76,7 +76,7 @@
-status_t MediaRecorderClient::setCamera(const sp<ICamera>& camera,
+status_t MediaRecorderClient::setCamera(const sp<hardware::ICamera>& camera,
const sp<ICameraRecordingProxy>& proxy)
{
ALOGV("setCamera");
diff --git a/media/libmediaplayerservice/MediaRecorderClient.h b/media/libmediaplayerservice/MediaRecorderClient.h
index c0d9c4c..5a080df 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.h
+++ b/media/libmediaplayerservice/MediaRecorderClient.h
@@ -30,7 +30,7 @@
class MediaRecorderClient : public BnMediaRecorder
{
public:
- virtual status_t setCamera(const sp<ICamera>& camera,
+ virtual status_t setCamera(const sp<hardware::ICamera>& camera,
const sp<ICameraRecordingProxy>& proxy);
virtual status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface);
virtual status_t setVideoSource(int vs);
diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp
index b335d09..26362ec 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.cpp
+++ b/media/libmediaplayerservice/StagefrightRecorder.cpp
@@ -22,6 +22,8 @@
#include "WebmWriter.h"
#include "StagefrightRecorder.h"
+#include <android/hardware/ICamera.h>
+
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
@@ -42,7 +44,6 @@
#include <media/stagefright/MetaData.h>
#include <media/stagefright/MediaCodecSource.h>
#include <media/MediaProfiles.h>
-#include <camera/ICamera.h>
#include <camera/CameraParameters.h>
#include <utils/Errors.h>
@@ -215,7 +216,7 @@
return OK;
}
-status_t StagefrightRecorder::setCamera(const sp<ICamera> &camera,
+status_t StagefrightRecorder::setCamera(const sp<hardware::ICamera> &camera,
const sp<ICameraRecordingProxy> &proxy) {
ALOGV("setCamera");
if (camera == 0) {
diff --git a/media/libmediaplayerservice/StagefrightRecorder.h b/media/libmediaplayerservice/StagefrightRecorder.h
index 761e987..a73197f 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.h
+++ b/media/libmediaplayerservice/StagefrightRecorder.h
@@ -53,7 +53,7 @@
virtual status_t setVideoEncoder(video_encoder ve);
virtual status_t setVideoSize(int width, int height);
virtual status_t setVideoFrameRate(int frames_per_second);
- virtual status_t setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy);
+ virtual status_t setCamera(const sp<hardware::ICamera>& camera, const sp<ICameraRecordingProxy>& proxy);
virtual status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface);
virtual status_t setInputSurface(const sp<IGraphicBufferConsumer>& surface);
virtual status_t setOutputFile(int fd, int64_t offset, int64_t length);
@@ -73,7 +73,7 @@
virtual sp<IGraphicBufferProducer> querySurfaceMediaSource() const;
private:
- sp<ICamera> mCamera;
+ sp<hardware::ICamera> mCamera;
sp<ICameraRecordingProxy> mCameraProxy;
sp<IGraphicBufferProducer> mPreviewSurface;
sp<IGraphicBufferConsumer> mPersistentSurface;
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/CameraSource.cpp
index 4f88d9c..15fa573 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -141,14 +141,14 @@
size.width = -1;
size.height = -1;
- sp<ICamera> camera;
+ sp<hardware::ICamera> camera;
return new CameraSource(camera, NULL, 0, clientName, Camera::USE_CALLING_UID,
Camera::USE_CALLING_PID, size, -1, NULL, false);
}
// static
CameraSource *CameraSource::CreateFromCamera(
- const sp<ICamera>& camera,
+ const sp<hardware::ICamera>& camera,
const sp<ICameraRecordingProxy>& proxy,
int32_t cameraId,
const String16& clientName,
@@ -166,7 +166,7 @@
}
CameraSource::CameraSource(
- const sp<ICamera>& camera,
+ const sp<hardware::ICamera>& camera,
const sp<ICameraRecordingProxy>& proxy,
int32_t cameraId,
const String16& clientName,
@@ -206,7 +206,7 @@
}
status_t CameraSource::isCameraAvailable(
- const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
+ const sp<hardware::ICamera>& camera, const sp<ICameraRecordingProxy>& proxy,
int32_t cameraId, const String16& clientName, uid_t clientUid, pid_t clientPid) {
if (camera == 0) {
@@ -489,7 +489,7 @@
* @return OK if no error.
*/
status_t CameraSource::init(
- const sp<ICamera>& camera,
+ const sp<hardware::ICamera>& camera,
const sp<ICameraRecordingProxy>& proxy,
int32_t cameraId,
const String16& clientName,
@@ -581,7 +581,7 @@
}
status_t CameraSource::initWithCameraAccess(
- const sp<ICamera>& camera,
+ const sp<hardware::ICamera>& camera,
const sp<ICameraRecordingProxy>& proxy,
int32_t cameraId,
const String16& clientName,
@@ -630,18 +630,18 @@
}
// By default, store real data in video buffers.
- mVideoBufferMode = ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV;
+ mVideoBufferMode = hardware::ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV;
if (storeMetaDataInVideoBuffers) {
- if (OK == mCamera->setVideoBufferMode(ICamera::VIDEO_BUFFER_MODE_BUFFER_QUEUE)) {
- mVideoBufferMode = ICamera::VIDEO_BUFFER_MODE_BUFFER_QUEUE;
+ if (OK == mCamera->setVideoBufferMode(hardware::ICamera::VIDEO_BUFFER_MODE_BUFFER_QUEUE)) {
+ mVideoBufferMode = hardware::ICamera::VIDEO_BUFFER_MODE_BUFFER_QUEUE;
} else if (OK == mCamera->setVideoBufferMode(
- ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_METADATA)) {
- mVideoBufferMode = ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_METADATA;
+ hardware::ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_METADATA)) {
+ mVideoBufferMode = hardware::ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_METADATA;
}
}
- if (mVideoBufferMode == ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV) {
- err = mCamera->setVideoBufferMode(ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV);
+ if (mVideoBufferMode == hardware::ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV) {
+ err = mCamera->setVideoBufferMode(hardware::ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV);
if (err != OK) {
ALOGE("%s: Setting video buffer mode to VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV failed: "
"%s (err=%d)", __FUNCTION__, strerror(-err), err);
@@ -686,7 +686,7 @@
int64_t token = IPCThreadState::self()->clearCallingIdentity();
status_t err;
- if (mVideoBufferMode == ICamera::VIDEO_BUFFER_MODE_BUFFER_QUEUE) {
+ if (mVideoBufferMode == hardware::ICamera::VIDEO_BUFFER_MODE_BUFFER_QUEUE) {
// Initialize buffer queue.
err = initBufferQueue(mVideoSize.width, mVideoSize.height, mEncoderFormat,
(android_dataspace_t)mEncoderDataSpace,
@@ -894,7 +894,7 @@
void CameraSource::releaseRecordingFrame(const sp<IMemory>& frame) {
ALOGV("releaseRecordingFrame");
- if (mVideoBufferMode == ICamera::VIDEO_BUFFER_MODE_BUFFER_QUEUE) {
+ if (mVideoBufferMode == hardware::ICamera::VIDEO_BUFFER_MODE_BUFFER_QUEUE) {
// Return the buffer to buffer queue in VIDEO_BUFFER_MODE_BUFFER_QUEUE mode.
ssize_t offset;
size_t size;
@@ -1165,8 +1165,8 @@
// Output buffers will contain metadata if camera sends us buffer in metadata mode or via
// buffer queue.
- return (mVideoBufferMode == ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_METADATA ||
- mVideoBufferMode == ICamera::VIDEO_BUFFER_MODE_BUFFER_QUEUE);
+ return (mVideoBufferMode == hardware::ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_METADATA ||
+ mVideoBufferMode == hardware::ICamera::VIDEO_BUFFER_MODE_BUFFER_QUEUE);
}
CameraSource::ProxyListener::ProxyListener(const sp<CameraSource>& source) {
diff --git a/media/libstagefright/CameraSourceTimeLapse.cpp b/media/libstagefright/CameraSourceTimeLapse.cpp
index 202ec42..fd1b88c 100644
--- a/media/libstagefright/CameraSourceTimeLapse.cpp
+++ b/media/libstagefright/CameraSourceTimeLapse.cpp
@@ -35,7 +35,7 @@
// static
CameraSourceTimeLapse *CameraSourceTimeLapse::CreateFromCamera(
- const sp<ICamera> &camera,
+ const sp<hardware::ICamera> &camera,
const sp<ICameraRecordingProxy> &proxy,
int32_t cameraId,
const String16& clientName,
@@ -64,7 +64,7 @@
}
CameraSourceTimeLapse::CameraSourceTimeLapse(
- const sp<ICamera>& camera,
+ const sp<hardware::ICamera>& camera,
const sp<ICameraRecordingProxy>& proxy,
int32_t cameraId,
const String16& clientName,
diff --git a/media/mediaserver/Android.mk b/media/mediaserver/Android.mk
index 107d2b6..2cec5d2 100644
--- a/media/mediaserver/Android.mk
+++ b/media/mediaserver/Android.mk
@@ -14,7 +14,8 @@
main_mediaserver.cpp
LOCAL_SHARED_LIBRARIES := \
- libcamera_metadata\
+ libcamera_metadata \
+ libcamera_client \
libcameraservice \
libresourcemanagerservice \
libcutils \
diff --git a/media/mediaserver/main_mediaserver.cpp b/media/mediaserver/main_mediaserver.cpp
index e9dede9..ecddc48 100644
--- a/media/mediaserver/main_mediaserver.cpp
+++ b/media/mediaserver/main_mediaserver.cpp
@@ -25,7 +25,6 @@
#include "RegisterExtensions.h"
// from LOCAL_C_INCLUDES
-#include "CameraService.h"
#include "IcuUtils.h"
#include "MediaPlayerService.h"
#include "ResourceManagerService.h"
diff --git a/services/camera/libcameraservice/Android.mk b/services/camera/libcameraservice/Android.mk
index d416353..bb3a685 100644
--- a/services/camera/libcameraservice/Android.mk
+++ b/services/camera/libcameraservice/Android.mk
@@ -20,7 +20,9 @@
include $(CLEAR_VARS)
-LOCAL_SRC_FILES:= \
+# Camera service source
+
+LOCAL_SRC_FILES := \
CameraService.cpp \
CameraFlashlight.cpp \
common/Camera2ClientBase.cpp \
@@ -67,11 +69,12 @@
libjpeg
LOCAL_C_INCLUDES += \
- system/media/camera/include \
system/media/private/camera/include \
frameworks/native/include/media/openmax \
external/jpeg
+LOCAL_EXPORT_C_INCLUDE_DIRS := \
+ frameworks/av/services/camera/libcameraservice
LOCAL_CFLAGS += -Wall -Wextra
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index f0bcc0b..7446c3e 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -28,6 +28,9 @@
#include <inttypes.h>
#include <pthread.h>
+#include <android/hardware/ICamera.h>
+#include <android/hardware/ICameraClient.h>
+
#include <binder/AppOpsManager.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
@@ -63,6 +66,9 @@
namespace android {
+using binder::Status;
+using namespace hardware;
+
// ----------------------------------------------------------------------------
// Logging support -- this is for debugging only
// Use "adb shell dumpsys media.camera -v 1" to change it.
@@ -75,6 +81,17 @@
android_atomic_write(level, &gLogLevel);
}
+// Convenience methods for constructing binder::Status objects for error returns
+
+#define STATUS_ERROR(errorCode, errorString) \
+ binder::Status::fromServiceSpecificError(errorCode, \
+ String8::format("%s:%d: %s", __FUNCTION__, __LINE__, errorString))
+
+#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
+ binder::Status::fromServiceSpecificError(errorCode, \
+ String8::format("%s:%d: " errorString, __FUNCTION__, __LINE__, \
+ __VA_ARGS__))
+
// ----------------------------------------------------------------------------
extern "C" {
@@ -100,7 +117,7 @@
sp<CameraService> cs = const_cast<CameraService*>(
static_cast<const CameraService*>(callbacks));
- ICameraServiceListener::TorchStatus status;
+ int32_t status;
switch (new_status) {
case TORCH_MODE_STATUS_NOT_AVAILABLE:
status = ICameraServiceListener::TORCH_STATUS_NOT_AVAILABLE;
@@ -130,8 +147,8 @@
CameraService::CameraService() :
mEventLog(DEFAULT_EVENT_LOG_LENGTH),
- mSoundRef(0), mModule(nullptr),
- mNumberOfCameras(0), mNumberOfNormalCameras(0) {
+ mNumberOfCameras(0), mNumberOfNormalCameras(0),
+ mSoundRef(0), mModule(nullptr) {
ALOGI("CameraService started (pid=%d)", getpid());
gCameraService = this;
@@ -291,9 +308,9 @@
return;
}
- ICameraServiceListener::Status oldStatus = state->getStatus();
+ int32_t oldStatus = state->getStatus();
- if (oldStatus == static_cast<ICameraServiceListener::Status>(newStatus)) {
+ if (oldStatus == static_cast<int32_t>(newStatus)) {
ALOGE("%s: State transition to the same status %#x not allowed", __FUNCTION__, newStatus);
return;
}
@@ -317,7 +334,8 @@
clientToDisconnect = removeClientLocked(id);
// Notify the client of disconnection
- clientToDisconnect->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
+ clientToDisconnect->notifyError(
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
CaptureResultExtras{});
}
@@ -333,27 +351,27 @@
}
} else {
- if (oldStatus == ICameraServiceListener::Status::STATUS_NOT_PRESENT) {
+ if (oldStatus == ICameraServiceListener::STATUS_NOT_PRESENT) {
logDeviceAdded(id, String8::format("Device status changed from %d to %d", oldStatus,
newStatus));
}
- updateStatus(static_cast<ICameraServiceListener::Status>(newStatus), id);
+ updateStatus(static_cast<int32_t>(newStatus), id);
}
}
void CameraService::onTorchStatusChanged(const String8& cameraId,
- ICameraServiceListener::TorchStatus newStatus) {
+ int32_t newStatus) {
Mutex::Autolock al(mTorchStatusMutex);
onTorchStatusChangedLocked(cameraId, newStatus);
}
void CameraService::onTorchStatusChangedLocked(const String8& cameraId,
- ICameraServiceListener::TorchStatus newStatus) {
+ int32_t newStatus) {
ALOGI("%s: Torch status changed for cameraId=%s, newStatus=%d",
__FUNCTION__, cameraId.string(), newStatus);
- ICameraServiceListener::TorchStatus status;
+ int32_t status;
status_t res = getTorchStatusLocked(cameraId, &status);
if (res) {
ALOGE("%s: cannot get torch status of camera %s: %s (%d)",
@@ -407,41 +425,45 @@
}
}
-int32_t CameraService::getNumberOfCameras() {
- ATRACE_CALL();
- return getNumberOfCameras(CAMERA_TYPE_BACKWARD_COMPATIBLE);
-}
-
-int32_t CameraService::getNumberOfCameras(int type) {
+Status CameraService::getNumberOfCameras(int32_t type, int32_t* numCameras) {
ATRACE_CALL();
switch (type) {
case CAMERA_TYPE_BACKWARD_COMPATIBLE:
- return mNumberOfNormalCameras;
+ *numCameras = mNumberOfNormalCameras;
+ break;
case CAMERA_TYPE_ALL:
- return mNumberOfCameras;
+ *numCameras = mNumberOfCameras;
+ break;
default:
- ALOGW("%s: Unknown camera type %d, returning 0",
+ ALOGW("%s: Unknown camera type %d",
__FUNCTION__, type);
- return 0;
+ return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+ "Unknown camera type %d", type);
}
+ return Status::ok();
}
-status_t CameraService::getCameraInfo(int cameraId,
- struct CameraInfo* cameraInfo) {
+Status CameraService::getCameraInfo(int cameraId,
+ CameraInfo* cameraInfo) {
ATRACE_CALL();
if (!mModule) {
- return -ENODEV;
+ return STATUS_ERROR(ERROR_DISCONNECTED,
+ "Camera subsystem is not available");
}
if (cameraId < 0 || cameraId >= mNumberOfCameras) {
- return BAD_VALUE;
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT,
+ "CameraId is not valid");
}
struct camera_info info;
- status_t rc = filterGetInfoErrorCode(
+ Status rc = filterGetInfoErrorCode(
mModule->getCameraInfo(cameraId, &info));
- cameraInfo->facing = info.facing;
- cameraInfo->orientation = info.orientation;
+
+ if (rc.isOk()) {
+ cameraInfo->facing = info.facing;
+ cameraInfo->orientation = info.orientation;
+ }
return rc;
}
@@ -455,28 +477,33 @@
return ret;
}
-status_t CameraService::generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo) {
+Status CameraService::generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo) {
ATRACE_CALL();
- status_t ret = OK;
+
+ Status ret = Status::ok();
+
struct CameraInfo info;
- if ((ret = getCameraInfo(cameraId, &info)) != OK) {
+ if (!(ret = getCameraInfo(cameraId, &info)).isOk()) {
return ret;
}
CameraMetadata shimInfo;
int32_t orientation = static_cast<int32_t>(info.orientation);
- if ((ret = shimInfo.update(ANDROID_SENSOR_ORIENTATION, &orientation, 1)) != OK) {
- return ret;
+ status_t rc;
+ if ((rc = shimInfo.update(ANDROID_SENSOR_ORIENTATION, &orientation, 1)) != OK) {
+ return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+ "Error updating metadata: %d (%s)", rc, strerror(-rc));
}
uint8_t facing = (info.facing == CAMERA_FACING_FRONT) ?
ANDROID_LENS_FACING_FRONT : ANDROID_LENS_FACING_BACK;
- if ((ret = shimInfo.update(ANDROID_LENS_FACING, &facing, 1)) != OK) {
- return ret;
+ if ((rc = shimInfo.update(ANDROID_LENS_FACING, &facing, 1)) != OK) {
+ return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+ "Error updating metadata: %d (%s)", rc, strerror(-rc));
}
CameraParameters shimParams;
- if ((ret = getLegacyParametersLazy(cameraId, /*out*/&shimParams)) != OK) {
+ if (!(ret = getLegacyParametersLazy(cameraId, /*out*/&shimParams)).isOk()) {
// Error logged by callee
return ret;
}
@@ -517,49 +544,54 @@
streamConfigs.add(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT);
}
- if ((ret = shimInfo.update(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
+ if ((rc = shimInfo.update(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
streamConfigs.array(), streamConfigSize)) != OK) {
- return ret;
+ return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+ "Error updating metadata: %d (%s)", rc, strerror(-rc));
}
int64_t fakeMinFrames[0];
// TODO: Fixme, don't fake min frame durations.
- if ((ret = shimInfo.update(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,
+ if ((rc = shimInfo.update(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,
fakeMinFrames, 0)) != OK) {
- return ret;
+ return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+ "Error updating metadata: %d (%s)", rc, strerror(-rc));
}
int64_t fakeStalls[0];
// TODO: Fixme, don't fake stall durations.
- if ((ret = shimInfo.update(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS,
+ if ((rc = shimInfo.update(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS,
fakeStalls, 0)) != OK) {
- return ret;
+ return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+ "Error updating metadata: %d (%s)", rc, strerror(-rc));
}
*cameraInfo = shimInfo;
- return OK;
+ return ret;
}
-status_t CameraService::getCameraCharacteristics(int cameraId,
+Status CameraService::getCameraCharacteristics(int cameraId,
CameraMetadata* cameraInfo) {
ATRACE_CALL();
if (!cameraInfo) {
ALOGE("%s: cameraInfo is NULL", __FUNCTION__);
- return BAD_VALUE;
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "cameraInfo is NULL");
}
if (!mModule) {
ALOGE("%s: camera hardware module doesn't exist", __FUNCTION__);
- return -ENODEV;
+ return STATUS_ERROR(ERROR_DISCONNECTED,
+ "Camera subsystem is not available");;
}
if (cameraId < 0 || cameraId >= mNumberOfCameras) {
ALOGE("%s: Invalid camera id: %d", __FUNCTION__, cameraId);
- return BAD_VALUE;
+ return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+ "Invalid camera id: %d", cameraId);
}
int facing;
- status_t ret = OK;
+ Status ret;
if (mModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_0 ||
getDeviceVersion(cameraId, &facing) < CAMERA_DEVICE_API_VERSION_3_0) {
/**
@@ -572,17 +604,16 @@
*/
ALOGI("%s: Switching to HAL1 shim implementation...", __FUNCTION__);
- if ((ret = generateShimMetadata(cameraId, cameraInfo)) != OK) {
- return ret;
- }
-
+ ret = generateShimMetadata(cameraId, cameraInfo);
} else {
/**
* Normal HAL 2.1+ codepath.
*/
struct camera_info info;
ret = filterGetInfoErrorCode(mModule->getCameraInfo(cameraId, &info));
- *cameraInfo = info.static_camera_characteristics;
+ if (ret.isOk()) {
+ *cameraInfo = info.static_camera_characteristics;
+ }
}
return ret;
@@ -619,15 +650,17 @@
return INT_MAX - procState;
}
-status_t CameraService::getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescriptor>& desc) {
+Status CameraService::getCameraVendorTagDescriptor(
+ /*out*/
+ hardware::camera2::params::VendorTagDescriptor* desc) {
ATRACE_CALL();
if (!mModule) {
ALOGE("%s: camera hardware module doesn't exist", __FUNCTION__);
- return -ENODEV;
+ return STATUS_ERROR(ERROR_DISCONNECTED, "Camera subsystem not available");
}
- desc = VendorTagDescriptor::getGlobalVendorTagDescriptor();
- return OK;
+ *desc = *(VendorTagDescriptor::getGlobalVendorTagDescriptor().get());
+ return Status::ok();
}
int CameraService::getDeviceVersion(int cameraId, int* facing) {
@@ -651,15 +684,21 @@
return deviceVersion;
}
-status_t CameraService::filterGetInfoErrorCode(status_t err) {
+Status CameraService::filterGetInfoErrorCode(status_t err) {
switch(err) {
case NO_ERROR:
+ return Status::ok();
case -EINVAL:
- return err;
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT,
+ "CameraId is not valid for HAL module");
+ case -ENODEV:
+ return STATUS_ERROR(ERROR_DISCONNECTED,
+ "Camera device not available");
default:
- break;
+ return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+ "Camera HAL encountered error %d: %s",
+ err, strerror(-err));
}
- return -ENODEV;
}
bool CameraService::setUpVendorTags() {
@@ -699,20 +738,12 @@
return true;
}
-status_t CameraService::makeClient(const sp<CameraService>& cameraService,
- const sp<IInterface>& cameraCb, const String16& packageName, const String8& cameraId,
+Status CameraService::makeClient(const sp<CameraService>& cameraService,
+ const sp<IInterface>& cameraCb, const String16& packageName, int cameraId,
int facing, int clientPid, uid_t clientUid, int servicePid, bool legacyMode,
int halVersion, int deviceVersion, apiLevel effectiveApiLevel,
/*out*/sp<BasicClient>* client) {
- // TODO: Update CameraClients + HAL interface to use strings for Camera IDs
- int id = cameraIdToInt(cameraId);
- if (id == -1) {
- ALOGE("%s: Invalid camera ID %s, cannot convert to integer.", __FUNCTION__,
- cameraId.string());
- return BAD_VALUE;
- }
-
if (halVersion < 0 || halVersion == deviceVersion) {
// Default path: HAL version is unspecified by caller, create CameraClient
// based on device version reported by the HAL.
@@ -720,11 +751,13 @@
case CAMERA_DEVICE_API_VERSION_1_0:
if (effectiveApiLevel == API_1) { // Camera1 API route
sp<ICameraClient> tmp = static_cast<ICameraClient*>(cameraCb.get());
- *client = new CameraClient(cameraService, tmp, packageName, id, facing,
+ *client = new CameraClient(cameraService, tmp, packageName, cameraId, facing,
clientPid, clientUid, getpid(), legacyMode);
} else { // Camera2 API route
ALOGW("Camera using old HAL version: %d", deviceVersion);
- return -EOPNOTSUPP;
+ return STATUS_ERROR_FMT(ERROR_DEPRECATED_HAL,
+ "Camera device \"%d\" HAL version %d does not support camera2 API",
+ cameraId, deviceVersion);
}
break;
case CAMERA_DEVICE_API_VERSION_3_0:
@@ -733,19 +766,21 @@
case CAMERA_DEVICE_API_VERSION_3_3:
if (effectiveApiLevel == API_1) { // Camera1 API route
sp<ICameraClient> tmp = static_cast<ICameraClient*>(cameraCb.get());
- *client = new Camera2Client(cameraService, tmp, packageName, id, facing,
+ *client = new Camera2Client(cameraService, tmp, packageName, cameraId, facing,
clientPid, clientUid, servicePid, legacyMode);
} else { // Camera2 API route
- sp<ICameraDeviceCallbacks> tmp =
- static_cast<ICameraDeviceCallbacks*>(cameraCb.get());
- *client = new CameraDeviceClient(cameraService, tmp, packageName, id,
+ sp<hardware::camera2::ICameraDeviceCallbacks> tmp =
+ static_cast<hardware::camera2::ICameraDeviceCallbacks*>(cameraCb.get());
+ *client = new CameraDeviceClient(cameraService, tmp, packageName, cameraId,
facing, clientPid, clientUid, servicePid);
}
break;
default:
// Should not be reachable
ALOGE("Unknown camera device HAL version: %d", deviceVersion);
- return INVALID_OPERATION;
+ return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+ "Camera device \"%d\" has unknown HAL version %d",
+ cameraId, deviceVersion);
}
} else {
// A particular HAL version is requested by caller. Create CameraClient
@@ -754,17 +789,19 @@
halVersion == CAMERA_DEVICE_API_VERSION_1_0) {
// Only support higher HAL version device opened as HAL1.0 device.
sp<ICameraClient> tmp = static_cast<ICameraClient*>(cameraCb.get());
- *client = new CameraClient(cameraService, tmp, packageName, id, facing,
+ *client = new CameraClient(cameraService, tmp, packageName, cameraId, facing,
clientPid, clientUid, servicePid, legacyMode);
} else {
// Other combinations (e.g. HAL3.x open as HAL2.x) are not supported yet.
ALOGE("Invalid camera HAL version %x: HAL %x device can only be"
" opened as HAL %x device", halVersion, deviceVersion,
CAMERA_DEVICE_API_VERSION_1_0);
- return INVALID_OPERATION;
+ return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+ "Camera device \"%d\" (HAL version %d) cannot be opened as HAL version %d",
+ cameraId, deviceVersion, halVersion);
}
}
- return NO_ERROR;
+ return Status::ok();
}
String8 CameraService::toString(std::set<userid_t> intSet) {
@@ -781,33 +818,35 @@
return s;
}
-status_t CameraService::initializeShimMetadata(int cameraId) {
+Status CameraService::initializeShimMetadata(int cameraId) {
int uid = getCallingUid();
String16 internalPackageName("cameraserver");
String8 id = String8::format("%d", cameraId);
- status_t ret = NO_ERROR;
+ Status ret = Status::ok();
sp<Client> tmp = nullptr;
- if ((ret = connectHelper<ICameraClient,Client>(sp<ICameraClient>{nullptr}, id,
- static_cast<int>(CAMERA_HAL_API_VERSION_UNSPECIFIED), internalPackageName, uid,
- USE_CALLING_PID, API_1, false, true, tmp)) != NO_ERROR) {
- ALOGE("%s: Error %d (%s) initializing shim metadata.", __FUNCTION__, ret, strerror(ret));
- return ret;
+ if (!(ret = connectHelper<ICameraClient,Client>(
+ sp<ICameraClient>{nullptr}, id, static_cast<int>(CAMERA_HAL_API_VERSION_UNSPECIFIED),
+ internalPackageName, uid, USE_CALLING_PID,
+ API_1, /*legacyMode*/ false, /*shimUpdateOnly*/ true,
+ /*out*/ tmp)
+ ).isOk()) {
+ ALOGE("%s: Error initializing shim metadata: %s", __FUNCTION__, ret.toString8().string());
}
- return NO_ERROR;
+ return ret;
}
-status_t CameraService::getLegacyParametersLazy(int cameraId,
+Status CameraService::getLegacyParametersLazy(int cameraId,
/*out*/
CameraParameters* parameters) {
ALOGV("%s: for cameraId: %d", __FUNCTION__, cameraId);
- status_t ret = 0;
+ Status ret = Status::ok();
if (parameters == NULL) {
ALOGE("%s: parameters must not be null", __FUNCTION__);
- return BAD_VALUE;
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Parameters must not be null");
}
String8 id = String8::format("%d", cameraId);
@@ -819,19 +858,20 @@
auto cameraState = getCameraState(id);
if (cameraState == nullptr) {
ALOGE("%s: Invalid camera ID: %s", __FUNCTION__, id.string());
- return BAD_VALUE;
+ return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+ "Invalid camera ID: %s", id.string());
}
CameraParameters p = cameraState->getShimParams();
if (!p.isEmpty()) {
*parameters = p;
- return NO_ERROR;
+ return ret;
}
}
int64_t token = IPCThreadState::self()->clearCallingIdentity();
ret = initializeShimMetadata(cameraId);
IPCThreadState::self()->restoreCallingIdentity(token);
- if (ret != NO_ERROR) {
+ if (!ret.isOk()) {
// Error already logged by callee
return ret;
}
@@ -843,18 +883,19 @@
auto cameraState = getCameraState(id);
if (cameraState == nullptr) {
ALOGE("%s: Invalid camera ID: %s", __FUNCTION__, id.string());
- return BAD_VALUE;
+ return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+ "Invalid camera ID: %s", id.string());
}
CameraParameters p = cameraState->getShimParams();
if (!p.isEmpty()) {
*parameters = p;
- return NO_ERROR;
+ return ret;
}
}
ALOGE("%s: Parameters were not initialized, or were empty. Device may not be present.",
__FUNCTION__);
- return INVALID_OPERATION;
+ return STATUS_ERROR(ERROR_INVALID_OPERATION, "Unable to initialize legacy parameters");
}
// Can camera service trust the caller based on the calling UID?
@@ -868,8 +909,8 @@
}
}
-status_t CameraService::validateConnectLocked(const String8& cameraId, /*inout*/int& clientUid,
- /*inout*/int& clientPid) const {
+Status CameraService::validateConnectLocked(const String8& cameraId,
+ const String8& clientName8, /*inout*/int& clientUid, /*inout*/int& clientPid) const {
int callingPid = getCallingPid();
int callingUid = getCallingUid();
@@ -880,7 +921,11 @@
} else if (!isTrustedCallingUid(callingUid)) {
ALOGE("CameraService::connect X (calling PID %d, calling UID %d) rejected "
"(don't trust clientUid %d)", callingPid, callingUid, clientUid);
- return PERMISSION_DENIED;
+ return STATUS_ERROR_FMT(ERROR_PERMISSION_DENIED,
+ "Untrusted caller (calling PID %d, UID %d) trying to "
+ "forward camera access to camera %s for client %s (PID %d, UID %d)",
+ callingPid, callingUid, cameraId.string(),
+ clientName8.string(), clientUid, clientPid);
}
// Check if we can trust clientPid
@@ -889,14 +934,20 @@
} else if (!isTrustedCallingUid(callingUid)) {
ALOGE("CameraService::connect X (calling PID %d, calling UID %d) rejected "
"(don't trust clientPid %d)", callingPid, callingUid, clientPid);
- return PERMISSION_DENIED;
+ return STATUS_ERROR_FMT(ERROR_PERMISSION_DENIED,
+ "Untrusted caller (calling PID %d, UID %d) trying to "
+ "forward camera access to camera %s for client %s (PID %d, UID %d)",
+ callingPid, callingUid, cameraId.string(),
+ clientName8.string(), clientUid, clientPid);
}
// If it's not calling from cameraserver, check the permission.
if (callingPid != getpid() &&
!checkPermission(String16("android.permission.CAMERA"), clientPid, clientUid)) {
ALOGE("Permission Denial: can't use the camera pid=%d, uid=%d", clientPid, clientUid);
- return PERMISSION_DENIED;
+ return STATUS_ERROR_FMT(ERROR_PERMISSION_DENIED,
+ "Caller \"%s\" (PID %d, UID %d) cannot open camera \"%s\" without camera permission",
+ clientName8.string(), clientUid, clientPid, cameraId.string());
}
// Only use passed in clientPid to check permission. Use calling PID as the client PID that's
@@ -906,13 +957,15 @@
if (!mModule) {
ALOGE("CameraService::connect X (PID %d) rejected (camera HAL module not loaded)",
callingPid);
- return -ENODEV;
+ return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
+ "No camera HAL module available to open camera device \"%s\"", cameraId.string());
}
if (getCameraState(cameraId) == nullptr) {
ALOGE("CameraService::connect X (PID %d) rejected (invalid camera ID %s)", callingPid,
cameraId.string());
- return -ENODEV;
+ return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
+ "No camera device with ID \"%s\" available", cameraId.string());
}
userid_t clientUserId = multiuser_get_user_id(clientUid);
@@ -923,10 +976,24 @@
ALOGE("CameraService::connect X (PID %d) rejected (cannot connect from "
"device user %d, currently allowed device users: %s)", callingPid, clientUserId,
toString(mAllowedUsers).string());
- return PERMISSION_DENIED;
+ return STATUS_ERROR_FMT(ERROR_PERMISSION_DENIED,
+ "Callers from device user %d are not currently allowed to connect to camera \"%s\"",
+ clientUserId, cameraId.string());
}
- return checkIfDeviceIsUsable(cameraId);
+ status_t err = checkIfDeviceIsUsable(cameraId);
+ if (err != NO_ERROR) {
+ switch(err) {
+ case -ENODEV:
+ case -EBUSY:
+ return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
+ "No camera device with ID \"%s\" currently available", cameraId.string());
+ default:
+ return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+ "Unknown error connecting to ID \"%s\"", cameraId.string());
+ }
+ }
+ return Status::ok();
}
status_t CameraService::checkIfDeviceIsUsable(const String8& cameraId) const {
@@ -938,7 +1005,7 @@
return -ENODEV;
}
- ICameraServiceListener::Status currentStatus = cameraState->getStatus();
+ int32_t currentStatus = cameraState->getStatus();
if (currentStatus == ICameraServiceListener::STATUS_NOT_PRESENT) {
ALOGE("CameraService::connect X (PID %d) rejected (camera %s is not connected)",
callingPid, cameraId.string());
@@ -1015,11 +1082,6 @@
}
}
- // Return error if the device was unplugged or removed by the HAL for some reason
- if ((ret = checkIfDeviceIsUsable(cameraId)) != NO_ERROR) {
- return ret;
- }
-
// Get current active client PIDs
std::vector<int> ownerPids(mActiveClientManager.getAllOwners());
ownerPids.push_back(clientPid);
@@ -1046,6 +1108,7 @@
if (state == nullptr) {
ALOGE("CameraService::connect X (PID %d) rejected (no camera device with ID %s)",
clientPid, cameraId.string());
+ // Should never get here because validateConnectLocked should have errored out
return BAD_VALUE;
}
@@ -1118,7 +1181,7 @@
getCameraPriorityFromProcState(priorities[priorities.size() - 1])));
// Notify the client of disconnection
- clientSp->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
+ clientSp->notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
CaptureResultExtras());
}
}
@@ -1170,39 +1233,41 @@
return NO_ERROR;
}
-status_t CameraService::connect(
+Status CameraService::connect(
const sp<ICameraClient>& cameraClient,
int cameraId,
const String16& clientPackageName,
int clientUid,
int clientPid,
/*out*/
- sp<ICamera>& device) {
+ sp<ICamera>* device) {
ATRACE_CALL();
- status_t ret = NO_ERROR;
+ Status ret = Status::ok();
String8 id = String8::format("%d", cameraId);
sp<Client> client = nullptr;
- ret = connectHelper<ICameraClient,Client>(cameraClient, id, CAMERA_HAL_API_VERSION_UNSPECIFIED,
- clientPackageName, clientUid, clientPid, API_1, false, false, /*out*/client);
+ ret = connectHelper<ICameraClient,Client>(cameraClient, id,
+ CAMERA_HAL_API_VERSION_UNSPECIFIED, clientPackageName, clientUid, clientPid, API_1,
+ /*legacyMode*/ false, /*shimUpdateOnly*/ false,
+ /*out*/client);
- if(ret != NO_ERROR) {
+ if(!ret.isOk()) {
logRejected(id, getCallingPid(), String8(clientPackageName),
- String8::format("%s (%d)", strerror(-ret), ret));
+ ret.toString8());
return ret;
}
- device = client;
- return NO_ERROR;
+ *device = client;
+ return ret;
}
-status_t CameraService::connectLegacy(
+Status CameraService::connectLegacy(
const sp<ICameraClient>& cameraClient,
int cameraId, int halVersion,
const String16& clientPackageName,
int clientUid,
/*out*/
- sp<ICamera>& device) {
+ sp<ICamera>* device) {
ATRACE_CALL();
String8 id = String8::format("%d", cameraId);
@@ -1215,61 +1280,68 @@
* it's a particular version in which case the HAL must supported
* the open_legacy call
*/
- ALOGE("%s: camera HAL module version %x doesn't support connecting to legacy HAL devices!",
- __FUNCTION__, apiVersion);
+ String8 msg = String8::format("Camera HAL module version %x too old for connectLegacy!",
+ apiVersion);
+ ALOGE("%s: %s",
+ __FUNCTION__, msg.string());
logRejected(id, getCallingPid(), String8(clientPackageName),
- String8("HAL module version doesn't support legacy HAL connections"));
- return INVALID_OPERATION;
+ msg);
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, msg.string());
}
- status_t ret = NO_ERROR;
+ Status ret = Status::ok();
sp<Client> client = nullptr;
- ret = connectHelper<ICameraClient,Client>(cameraClient, id, halVersion, clientPackageName,
- clientUid, USE_CALLING_PID, API_1, true, false, /*out*/client);
+ ret = connectHelper<ICameraClient,Client>(cameraClient, id, halVersion,
+ clientPackageName, clientUid, USE_CALLING_PID, API_1,
+ /*legacyMode*/ true, /*shimUpdateOnly*/ false,
+ /*out*/client);
- if(ret != NO_ERROR) {
+ if(!ret.isOk()) {
logRejected(id, getCallingPid(), String8(clientPackageName),
- String8::format("%s (%d)", strerror(-ret), ret));
+ ret.toString8());
return ret;
}
- device = client;
- return NO_ERROR;
+ *device = client;
+ return ret;
}
-status_t CameraService::connectDevice(
- const sp<ICameraDeviceCallbacks>& cameraCb,
+Status CameraService::connectDevice(
+ const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
int cameraId,
const String16& clientPackageName,
int clientUid,
/*out*/
- sp<ICameraDeviceUser>& device) {
+ sp<hardware::camera2::ICameraDeviceUser>* device) {
ATRACE_CALL();
- status_t ret = NO_ERROR;
+ Status ret = Status::ok();
String8 id = String8::format("%d", cameraId);
sp<CameraDeviceClient> client = nullptr;
- ret = connectHelper<ICameraDeviceCallbacks,CameraDeviceClient>(cameraCb, id,
- CAMERA_HAL_API_VERSION_UNSPECIFIED, clientPackageName, clientUid, USE_CALLING_PID,
- API_2, false, false, /*out*/client);
+ ret = connectHelper<hardware::camera2::ICameraDeviceCallbacks,CameraDeviceClient>(cameraCb, id,
+ CAMERA_HAL_API_VERSION_UNSPECIFIED, clientPackageName,
+ clientUid, USE_CALLING_PID, API_2,
+ /*legacyMode*/ false, /*shimUpdateOnly*/ false,
+ /*out*/client);
- if(ret != NO_ERROR) {
+ if(!ret.isOk()) {
logRejected(id, getCallingPid(), String8(clientPackageName),
- String8::format("%s (%d)", strerror(-ret), ret));
+ ret.toString8());
return ret;
}
- device = client;
- return NO_ERROR;
+ *device = client;
+ return ret;
}
-status_t CameraService::setTorchMode(const String16& cameraId, bool enabled,
+Status CameraService::setTorchMode(const String16& cameraId, bool enabled,
const sp<IBinder>& clientBinder) {
ATRACE_CALL();
if (enabled && clientBinder == nullptr) {
ALOGE("%s: torch client binder is NULL", __FUNCTION__);
- return -EINVAL;
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT,
+ "Torch client Binder is null");
}
String8 id = String8(cameraId.string());
@@ -1279,35 +1351,47 @@
auto state = getCameraState(id);
if (state == nullptr) {
ALOGE("%s: camera id is invalid %s", __FUNCTION__, id.string());
- return -EINVAL;
+ return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+ "Camera ID \"%s\" is a not valid camera ID", id.string());
}
- ICameraServiceListener::Status cameraStatus = state->getStatus();
+ int32_t cameraStatus = state->getStatus();
if (cameraStatus != ICameraServiceListener::STATUS_PRESENT &&
cameraStatus != ICameraServiceListener::STATUS_NOT_AVAILABLE) {
ALOGE("%s: camera id is invalid %s", __FUNCTION__, id.string());
- return -EINVAL;
+ return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+ "Camera ID \"%s\" is a not valid camera ID", id.string());
}
{
Mutex::Autolock al(mTorchStatusMutex);
- ICameraServiceListener::TorchStatus status;
- status_t res = getTorchStatusLocked(id, &status);
- if (res) {
+ int32_t status;
+ status_t err = getTorchStatusLocked(id, &status);
+ if (err != OK) {
+ if (err == NAME_NOT_FOUND) {
+ return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+ "Camera \"%s\" does not have a flash unit", id.string());
+ }
ALOGE("%s: getting current torch status failed for camera %s",
__FUNCTION__, id.string());
- return -EINVAL;
+ return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+ "Error updating torch status for camera \"%s\": %s (%d)", id.string(),
+ strerror(-err), err);
}
if (status == ICameraServiceListener::TORCH_STATUS_NOT_AVAILABLE) {
if (cameraStatus == ICameraServiceListener::STATUS_NOT_AVAILABLE) {
ALOGE("%s: torch mode of camera %s is not available because "
"camera is in use", __FUNCTION__, id.string());
- return -EBUSY;
+ return STATUS_ERROR_FMT(ERROR_CAMERA_IN_USE,
+ "Torch for camera \"%s\" is not available due to an existing camera user",
+ id.string());
} else {
ALOGE("%s: torch mode of camera %s is not available due to "
"insufficient resources", __FUNCTION__, id.string());
- return -EUSERS;
+ return STATUS_ERROR_FMT(ERROR_MAX_CAMERAS_IN_USE,
+ "Torch for camera \"%s\" is not available due to insufficient resources",
+ id.string());
}
}
}
@@ -1325,12 +1409,25 @@
}
}
- status_t res = mFlashlight->setTorchMode(id, enabled);
+ status_t err = mFlashlight->setTorchMode(id, enabled);
- if (res) {
- ALOGE("%s: setting torch mode of camera %s to %d failed. %s (%d)",
- __FUNCTION__, id.string(), enabled, strerror(-res), res);
- return res;
+ if (err != OK) {
+ int32_t errorCode;
+ String8 msg;
+ switch (err) {
+ case -ENOSYS:
+ msg = String8::format("Camera \"%s\" has no flashlight",
+ id.string());
+ errorCode = ERROR_ILLEGAL_ARGUMENT;
+ break;
+ default:
+ msg = String8::format(
+ "Setting torch mode of camera \"%s\" to %d failed: %s (%d)",
+ id.string(), enabled, strerror(-err), err);
+ errorCode = ERROR_INVALID_OPERATION;
+ }
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(errorCode, msg.string());
}
{
@@ -1350,34 +1447,36 @@
}
}
- return OK;
+ return Status::ok();
}
-void CameraService::notifySystemEvent(int32_t eventId, const int32_t* args, size_t length) {
+Status CameraService::notifySystemEvent(int32_t eventId,
+ const std::vector<int32_t>& args) {
ATRACE_CALL();
switch(eventId) {
- case ICameraService::USER_SWITCHED: {
- doUserSwitch(/*newUserIds*/args, /*length*/length);
+ case ICameraService::EVENT_USER_SWITCHED: {
+ doUserSwitch(/*newUserIds*/ args);
break;
}
- case ICameraService::NO_EVENT:
+ case ICameraService::EVENT_NONE:
default: {
ALOGW("%s: Received invalid system event from system_server: %d", __FUNCTION__,
eventId);
break;
}
}
+ return Status::ok();
}
-status_t CameraService::addListener(const sp<ICameraServiceListener>& listener) {
+Status CameraService::addListener(const sp<ICameraServiceListener>& listener) {
ATRACE_CALL();
ALOGV("%s: Add listener %p", __FUNCTION__, listener.get());
if (listener == nullptr) {
ALOGE("%s: Listener must not be null", __FUNCTION__);
- return BAD_VALUE;
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Null listener given to addListener");
}
Mutex::Autolock lock(mServiceLock);
@@ -1388,7 +1487,7 @@
if (IInterface::asBinder(it) == IInterface::asBinder(listener)) {
ALOGW("%s: Tried to add listener %p which was already subscribed",
__FUNCTION__, listener.get());
- return ALREADY_EXISTS;
+ return STATUS_ERROR(ERROR_ALREADY_EXISTS, "Listener already registered");
}
}
@@ -1417,17 +1516,17 @@
}
}
- return OK;
+ return Status::ok();
}
-status_t CameraService::removeListener(const sp<ICameraServiceListener>& listener) {
+Status CameraService::removeListener(const sp<ICameraServiceListener>& listener) {
ATRACE_CALL();
ALOGV("%s: Remove listener %p", __FUNCTION__, listener.get());
if (listener == 0) {
ALOGE("%s: Listener must not be null", __FUNCTION__);
- return BAD_VALUE;
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Null listener given to removeListener");
}
Mutex::Autolock lock(mServiceLock);
@@ -1437,7 +1536,7 @@
for (auto it = mListenerList.begin(); it != mListenerList.end(); it++) {
if (IInterface::asBinder(*it) == IInterface::asBinder(listener)) {
mListenerList.erase(it);
- return OK;
+ return Status::ok();
}
}
}
@@ -1445,23 +1544,23 @@
ALOGW("%s: Tried to remove a listener %p which was not subscribed",
__FUNCTION__, listener.get());
- return BAD_VALUE;
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Unregistered listener given to removeListener");
}
-status_t CameraService::getLegacyParameters(int cameraId, /*out*/String16* parameters) {
+Status CameraService::getLegacyParameters(int cameraId, /*out*/String16* parameters) {
ATRACE_CALL();
ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId);
if (parameters == NULL) {
ALOGE("%s: parameters must not be null", __FUNCTION__);
- return BAD_VALUE;
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Parameters must not be null");
}
- status_t ret = 0;
+ Status ret = Status::ok();
CameraParameters shimParams;
- if ((ret = getLegacyParametersLazy(cameraId, /*out*/&shimParams)) != OK) {
+ if (!(ret = getLegacyParametersLazy(cameraId, /*out*/&shimParams)).isOk()) {
// Error logged by caller
return ret;
}
@@ -1471,10 +1570,10 @@
*parameters = shimParamsString16;
- return OK;
+ return ret;
}
-status_t CameraService::supportsCameraApi(int cameraId, int apiVersion) {
+Status CameraService::supportsCameraApi(int cameraId, int apiVersion, bool *isSupported) {
ATRACE_CALL();
ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId);
@@ -1484,40 +1583,48 @@
case API_VERSION_2:
break;
default:
- ALOGE("%s: Bad API version %d", __FUNCTION__, apiVersion);
- return BAD_VALUE;
+ String8 msg = String8::format("Unknown API version %d", apiVersion);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, msg.string());
}
int facing = -1;
int deviceVersion = getDeviceVersion(cameraId, &facing);
switch(deviceVersion) {
- case CAMERA_DEVICE_API_VERSION_1_0:
- case CAMERA_DEVICE_API_VERSION_3_0:
- case CAMERA_DEVICE_API_VERSION_3_1:
- if (apiVersion == API_VERSION_2) {
- ALOGV("%s: Camera id %d uses HAL prior to HAL3.2, doesn't support api2 without shim",
+ case CAMERA_DEVICE_API_VERSION_1_0:
+ case CAMERA_DEVICE_API_VERSION_3_0:
+ case CAMERA_DEVICE_API_VERSION_3_1:
+ if (apiVersion == API_VERSION_2) {
+ ALOGV("%s: Camera id %d uses HAL version %d <3.2, doesn't support api2 without shim",
+ __FUNCTION__, cameraId, deviceVersion);
+ *isSupported = false;
+ } else { // if (apiVersion == API_VERSION_1) {
+ ALOGV("%s: Camera id %d uses older HAL before 3.2, but api1 is always supported",
+ __FUNCTION__, cameraId);
+ *isSupported = true;
+ }
+ break;
+ case CAMERA_DEVICE_API_VERSION_3_2:
+ case CAMERA_DEVICE_API_VERSION_3_3:
+ ALOGV("%s: Camera id %d uses HAL3.2 or newer, supports api1/api2 directly",
__FUNCTION__, cameraId);
- return -EOPNOTSUPP;
- } else { // if (apiVersion == API_VERSION_1) {
- ALOGV("%s: Camera id %d uses older HAL before 3.2, but api1 is always supported",
- __FUNCTION__, cameraId);
- return OK;
+ *isSupported = true;
+ break;
+ case -1: {
+ String8 msg = String8::format("Unknown camera ID %d", cameraId);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, msg.string());
}
- case CAMERA_DEVICE_API_VERSION_3_2:
- case CAMERA_DEVICE_API_VERSION_3_3:
- ALOGV("%s: Camera id %d uses HAL3.2 or newer, supports api1/api2 directly",
- __FUNCTION__, cameraId);
- return OK;
- case -1:
- ALOGE("%s: Invalid camera id %d", __FUNCTION__, cameraId);
- return BAD_VALUE;
- default:
- ALOGE("%s: Unknown camera device HAL version: %d", __FUNCTION__, deviceVersion);
- return INVALID_OPERATION;
+ default: {
+ String8 msg = String8::format("Unknown device version %d for device %d",
+ deviceVersion, cameraId);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(ERROR_INVALID_OPERATION, msg.string());
+ }
}
- return OK;
+ return Status::ok();
}
void CameraService::removeByClient(const BasicClient* client) {
@@ -1554,7 +1661,8 @@
evicted.push_back(clientSp);
// Notify the client of disconnection
- clientSp->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
+ clientSp->notifyError(
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
CaptureResultExtras());
}
}
@@ -1679,19 +1787,19 @@
return clientDescriptorPtr->getValue();
}
-void CameraService::doUserSwitch(const int32_t* newUserId, size_t length) {
+void CameraService::doUserSwitch(const std::vector<int32_t>& newUserIds) {
// Acquire mServiceLock and prevent other clients from connecting
std::unique_ptr<AutoConditionLock> lock =
AutoConditionLock::waitAndAcquire(mServiceLockWrapper);
std::set<userid_t> newAllowedUsers;
- for (size_t i = 0; i < length; i++) {
- if (newUserId[i] < 0) {
+ for (size_t i = 0; i < newUserIds.size(); i++) {
+ if (newUserIds[i] < 0) {
ALOGE("%s: Bad user ID %d given during user switch, ignoring.",
- __FUNCTION__, newUserId[i]);
+ __FUNCTION__, newUserIds[i]);
return;
}
- newAllowedUsers.insert(static_cast<userid_t>(newUserId[i]));
+ newAllowedUsers.insert(static_cast<userid_t>(newUserIds[i]));
}
@@ -1817,7 +1925,7 @@
// Permission checks
switch (code) {
- case BnCameraService::NOTIFY_SYSTEM_EVENT: {
+ case BnCameraService::NOTIFYSYSTEMEVENT: {
if (pid != selfPid) {
// Ensure we're being called by system_server, or similar process with
// permissions to notify the camera service about system events
@@ -1979,9 +2087,10 @@
mDestructionStarted = true;
}
-void CameraService::BasicClient::disconnect() {
+binder::Status CameraService::BasicClient::disconnect() {
+ binder::Status res = Status::ok();
if (mDisconnected) {
- return;
+ return res;
}
mDisconnected = true;
@@ -1999,6 +2108,8 @@
// client shouldn't be able to call into us anymore
mClientPid = 0;
+
+ return res;
}
status_t CameraService::BasicClient::dump(int, const Vector<String16>&) {
@@ -2080,7 +2191,7 @@
mClientPackageName);
mOpsActive = false;
- auto rejected = {ICameraServiceListener::STATUS_NOT_PRESENT,
+ std::initializer_list<int32_t> rejected = {ICameraServiceListener::STATUS_NOT_PRESENT,
ICameraServiceListener::STATUS_ENUMERATING};
// Transition to PRESENT if the camera is not in either of the rejected states
@@ -2131,7 +2242,7 @@
// and to prevent further calls by client.
mClientPid = getCallingPid();
CaptureResultExtras resultExtras; // a dummy result (invalid)
- notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_SERVICE, resultExtras);
+ notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_SERVICE, resultExtras);
disconnect();
}
}
@@ -2149,7 +2260,7 @@
return sp<Client>{nullptr};
}
-void CameraService::Client::notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+void CameraService::Client::notifyError(int32_t errorCode,
const CaptureResultExtras& resultExtras) {
(void) errorCode;
(void) resultExtras;
@@ -2161,9 +2272,9 @@
}
// NOTE: function is idempotent
-void CameraService::Client::disconnect() {
+binder::Status CameraService::Client::disconnect() {
ALOGV("Client::disconnect");
- BasicClient::disconnect();
+ return BasicClient::disconnect();
}
bool CameraService::Client::canCastToApiClient(apiLevel level) const {
@@ -2192,7 +2303,7 @@
CameraService::CameraState::~CameraState() {}
-ICameraServiceListener::Status CameraService::CameraState::getStatus() const {
+int32_t CameraService::CameraState::getStatus() const {
Mutex::Autolock lock(mStatusLock);
return mStatus;
}
@@ -2554,12 +2665,12 @@
__FUNCTION__);
}
-void CameraService::updateStatus(ICameraServiceListener::Status status, const String8& cameraId) {
+void CameraService::updateStatus(int32_t status, const String8& cameraId) {
updateStatus(status, cameraId, {});
}
-void CameraService::updateStatus(ICameraServiceListener::Status status, const String8& cameraId,
- std::initializer_list<ICameraServiceListener::Status> rejectSourceStates) {
+void CameraService::updateStatus(int32_t status, const String8& cameraId,
+ std::initializer_list<int32_t> rejectSourceStates) {
// Do not lock mServiceLock here or can get into a deadlock from
// connect() -> disconnect -> updateStatus
@@ -2574,15 +2685,15 @@
// Update the status for this camera state, then send the onStatusChangedCallbacks to each
// of the listeners with both the mStatusStatus and mStatusListenerLock held
state->updateStatus(status, cameraId, rejectSourceStates, [this]
- (const String8& cameraId, ICameraServiceListener::Status status) {
+ (const String8& cameraId, int32_t status) {
if (status != ICameraServiceListener::STATUS_ENUMERATING) {
// Update torch status if it has a flash unit.
Mutex::Autolock al(mTorchStatusMutex);
- ICameraServiceListener::TorchStatus torchStatus;
+ int32_t torchStatus;
if (getTorchStatusLocked(cameraId, &torchStatus) !=
NAME_NOT_FOUND) {
- ICameraServiceListener::TorchStatus newTorchStatus =
+ int32_t newTorchStatus =
status == ICameraServiceListener::STATUS_PRESENT ?
ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF :
ICameraServiceListener::TORCH_STATUS_NOT_AVAILABLE;
@@ -2612,7 +2723,7 @@
status_t CameraService::getTorchStatusLocked(
const String8& cameraId,
- ICameraServiceListener::TorchStatus *status) const {
+ int32_t *status) const {
if (!status) {
return BAD_VALUE;
}
@@ -2627,12 +2738,12 @@
}
status_t CameraService::setTorchStatusLocked(const String8& cameraId,
- ICameraServiceListener::TorchStatus status) {
+ int32_t status) {
ssize_t index = mTorchStatusMap.indexOfKey(cameraId);
if (index == NAME_NOT_FOUND) {
return BAD_VALUE;
}
- ICameraServiceListener::TorchStatus& item =
+ int32_t& item =
mTorchStatusMap.editValueAt(index);
item = status;
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index 66de77f..e29b01c 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -17,25 +17,22 @@
#ifndef ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
#define ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
+#include <android/hardware/BnCameraService.h>
+#include <android/hardware/ICameraServiceListener.h>
+
#include <cutils/multiuser.h>
#include <utils/Vector.h>
#include <utils/KeyedVector.h>
#include <binder/AppOpsManager.h>
#include <binder/BinderService.h>
#include <binder/IAppOpsCallback.h>
-#include <camera/ICameraService.h>
#include <camera/ICameraServiceProxy.h>
#include <hardware/camera.h>
-#include <camera/ICamera.h>
-#include <camera/ICameraClient.h>
-#include <camera/camera2/ICameraDeviceUser.h>
-#include <camera/camera2/ICameraDeviceCallbacks.h>
#include <camera/VendorTagDescriptor.h>
#include <camera/CaptureResult.h>
#include <camera/CameraParameters.h>
-#include <camera/ICameraServiceListener.h>
#include "CameraFlashlight.h"
#include "common/CameraModule.h"
@@ -58,7 +55,7 @@
class CameraService :
public BinderService<CameraService>,
- public BnCameraService,
+ public ::android::hardware::BnCameraService,
public IBinder::DeathRecipient,
public camera_module_callbacks_t
{
@@ -101,55 +98,58 @@
virtual void onDeviceStatusChanged(camera_device_status_t cameraId,
camera_device_status_t newStatus);
virtual void onTorchStatusChanged(const String8& cameraId,
- ICameraServiceListener::TorchStatus
- newStatus);
+ int32_t newStatus);
/////////////////////////////////////////////////////////////////////
// ICameraService
- virtual int32_t getNumberOfCameras(int type);
- virtual int32_t getNumberOfCameras();
+ virtual binder::Status getNumberOfCameras(int32_t type, int32_t* numCameras);
- virtual status_t getCameraInfo(int cameraId,
- struct CameraInfo* cameraInfo);
- virtual status_t getCameraCharacteristics(int cameraId,
- CameraMetadata* cameraInfo);
- virtual status_t getCameraVendorTagDescriptor(/*out*/ sp<VendorTagDescriptor>& desc);
-
- virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
- const String16& clientPackageName, int clientUid, int clientPid,
+ virtual binder::Status getCameraInfo(int cameraId,
+ hardware::CameraInfo* cameraInfo);
+ virtual binder::Status getCameraCharacteristics(int cameraId,
+ CameraMetadata* cameraInfo);
+ virtual binder::Status getCameraVendorTagDescriptor(
/*out*/
- sp<ICamera>& device);
+ hardware::camera2::params::VendorTagDescriptor* desc);
- virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId,
- int halVersion, const String16& clientPackageName, int clientUid,
+ virtual binder::Status connect(const sp<hardware::ICameraClient>& cameraClient,
+ int32_t cameraId, const String16& clientPackageName,
+ int32_t clientUid, int clientPid,
/*out*/
- sp<ICamera>& device);
+ sp<hardware::ICamera>* device);
- virtual status_t connectDevice(
- const sp<ICameraDeviceCallbacks>& cameraCb,
- int cameraId,
- const String16& clientPackageName,
- int clientUid,
+ virtual binder::Status connectLegacy(const sp<hardware::ICameraClient>& cameraClient,
+ int32_t cameraId, int32_t halVersion,
+ const String16& clientPackageName, int32_t clientUid,
/*out*/
- sp<ICameraDeviceUser>& device);
+ sp<hardware::ICamera>* device);
- virtual status_t addListener(const sp<ICameraServiceListener>& listener);
- virtual status_t removeListener(
- const sp<ICameraServiceListener>& listener);
+ virtual binder::Status connectDevice(
+ const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb, int32_t cameraId,
+ const String16& clientPackageName, int32_t clientUid,
+ /*out*/
+ sp<hardware::camera2::ICameraDeviceUser>* device);
- virtual status_t getLegacyParameters(
- int cameraId,
+ virtual binder::Status addListener(const sp<hardware::ICameraServiceListener>& listener);
+ virtual binder::Status removeListener(
+ const sp<hardware::ICameraServiceListener>& listener);
+
+ virtual binder::Status getLegacyParameters(
+ int32_t cameraId,
/*out*/
String16* parameters);
- virtual status_t setTorchMode(const String16& cameraId, bool enabled,
+ virtual binder::Status setTorchMode(const String16& cameraId, bool enabled,
const sp<IBinder>& clientBinder);
- virtual void notifySystemEvent(int32_t eventId, const int32_t* args, size_t length);
+ virtual binder::Status notifySystemEvent(int32_t eventId,
+ const std::vector<int32_t>& args);
// OK = supports api of that version, -EOPNOTSUPP = does not support
- virtual status_t supportsCameraApi(
- int cameraId, int apiVersion);
+ virtual binder::Status supportsCameraApi(
+ int32_t cameraId, int32_t apiVersion,
+ /*out*/
+ bool *isSupported);
// Extra permissions checks
virtual status_t onTransact(uint32_t code, const Parcel& data,
@@ -185,35 +185,35 @@
/////////////////////////////////////////////////////////////////////
// Shared utilities
- static status_t filterGetInfoErrorCode(status_t err);
+ static binder::Status filterGetInfoErrorCode(status_t err);
/////////////////////////////////////////////////////////////////////
// CameraClient functionality
class BasicClient : public virtual RefBase {
public:
- virtual status_t initialize(CameraModule *module) = 0;
- virtual void disconnect();
+ virtual status_t initialize(CameraModule *module) = 0;
+ virtual binder::Status disconnect();
// because we can't virtually inherit IInterface, which breaks
// virtual inheritance
- virtual sp<IBinder> asBinderWrapper() = 0;
+ virtual sp<IBinder> asBinderWrapper() = 0;
// Return the remote callback binder object (e.g. ICameraDeviceCallbacks)
- sp<IBinder> getRemote() {
+ sp<IBinder> getRemote() {
return mRemoteBinder;
}
// Disallows dumping over binder interface
- virtual status_t dump(int fd, const Vector<String16>& args);
+ virtual status_t dump(int fd, const Vector<String16>& args);
// Internal dump method to be called by CameraService
- virtual status_t dumpClient(int fd, const Vector<String16>& args) = 0;
+ virtual status_t dumpClient(int fd, const Vector<String16>& args) = 0;
// Return the package name for this client
virtual String16 getPackageName() const;
// Notify client about a fatal error
- virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+ virtual void notifyError(int32_t errorCode,
const CaptureResultExtras& resultExtras) = 0;
// Get the UID of the application client using this
@@ -282,14 +282,14 @@
virtual void opChanged(int32_t op, const String16& packageName);
}; // class BasicClient
- class Client : public BnCamera, public BasicClient
+ class Client : public hardware::BnCamera, public BasicClient
{
public:
- typedef ICameraClient TCamCallbacks;
+ typedef hardware::ICameraClient TCamCallbacks;
// ICamera interface (see ICamera for details)
- virtual void disconnect();
- virtual status_t connect(const sp<ICameraClient>& client) = 0;
+ virtual binder::Status disconnect();
+ virtual status_t connect(const sp<hardware::ICameraClient>& client) = 0;
virtual status_t lock() = 0;
virtual status_t unlock() = 0;
virtual status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)=0;
@@ -314,7 +314,7 @@
// Interface used by CameraService
Client(const sp<CameraService>& cameraService,
- const sp<ICameraClient>& cameraClient,
+ const sp<hardware::ICameraClient>& cameraClient,
const String16& clientPackageName,
int cameraId,
int cameraFacing,
@@ -324,7 +324,7 @@
~Client();
// return our camera client
- const sp<ICameraClient>& getRemoteCallback() {
+ const sp<hardware::ICameraClient>& getRemoteCallback() {
return mRemoteCallback;
}
@@ -332,7 +332,7 @@
return asBinder(this);
}
- virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+ virtual void notifyError(int32_t errorCode,
const CaptureResultExtras& resultExtras);
// Check what API level is used for this client. This is used to determine which
@@ -345,7 +345,7 @@
// Initialized in constructor
// - The app-side Binder interface to receive callbacks from us
- sp<ICameraClient> mRemoteCallback;
+ sp<hardware::ICameraClient> mRemoteCallback;
}; // class Client
@@ -432,12 +432,12 @@
*
* This method acquires mStatusLock.
*/
- ICameraServiceListener::Status getStatus() const;
+ int32_t getStatus() const;
/**
* This function updates the status for this camera device, unless the given status
* is in the given list of rejected status states, and execute the function passed in
- * with a signature onStatusUpdateLocked(const String8&, ICameraServiceListener::Status)
+ * with a signature onStatusUpdateLocked(const String8&, int32_t)
* if the status has changed.
*
* This method is idempotent, and will not result in the function passed to
@@ -445,8 +445,8 @@
* This method aquires mStatusLock.
*/
template<class Func>
- void updateStatus(ICameraServiceListener::Status status, const String8& cameraId,
- std::initializer_list<ICameraServiceListener::Status> rejectSourceStates,
+ void updateStatus(int32_t status, const String8& cameraId,
+ std::initializer_list<int32_t> rejectSourceStates,
Func onStatusUpdatedLocked);
/**
@@ -477,7 +477,7 @@
private:
const String8 mId;
- ICameraServiceListener::Status mStatus; // protected by mStatusLock
+ int32_t mStatus; // protected by mStatusLock
const int mCost;
std::set<String8> mConflicting;
mutable Mutex mStatusLock;
@@ -488,8 +488,8 @@
virtual void onFirstRef();
// Check if we can connect, before we acquire the service lock.
- status_t validateConnectLocked(const String8& cameraId, /*inout*/int& clientUid,
- /*inout*/int& clientPid) const;
+ binder::Status validateConnectLocked(const String8& cameraId, const String8& clientName8,
+ /*inout*/int& clientUid, /*inout*/int& clientPid) const;
// Handle active client evictions, and update service state.
// Only call with with mServiceLock held.
@@ -501,8 +501,9 @@
// Single implementation shared between the various connect calls
template<class CALLBACK, class CLIENT>
- status_t connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId, int halVersion,
- const String16& clientPackageName, int clientUid, int clientPid,
+ binder::Status connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId,
+ int halVersion, const String16& clientPackageName,
+ int clientUid, int clientPid,
apiLevel effectiveApiLevel, bool legacyMode, bool shimUpdateOnly,
/*out*/sp<CLIENT>& device);
@@ -583,7 +584,7 @@
/**
* Handle a notification that the current device user has changed.
*/
- void doUserSwitch(const int32_t* newUserId, size_t length);
+ void doUserSwitch(const std::vector<int32_t>& newUserIds);
/**
* Add an event log message.
@@ -651,7 +652,7 @@
CameraModule* mModule;
// Guarded by mStatusListenerMutex
- std::vector<sp<ICameraServiceListener>> mListenerList;
+ std::vector<sp<hardware::ICameraServiceListener>> mListenerList;
Mutex mStatusListenerLock;
/**
@@ -662,9 +663,9 @@
* This method must be idempotent.
* This method acquires mStatusLock and mStatusListenerLock.
*/
- void updateStatus(ICameraServiceListener::Status status, const String8& cameraId,
- std::initializer_list<ICameraServiceListener::Status> rejectedSourceStates);
- void updateStatus(ICameraServiceListener::Status status, const String8& cameraId);
+ void updateStatus(int32_t status, const String8& cameraId,
+ std::initializer_list<int32_t> rejectedSourceStates);
+ void updateStatus(int32_t status, const String8& cameraId);
// flashlight control
sp<CameraFlashlight> mFlashlight;
@@ -675,7 +676,7 @@
// guard mTorchUidMap
Mutex mTorchUidMapMutex;
// camera id -> torch status
- KeyedVector<String8, ICameraServiceListener::TorchStatus> mTorchStatusMap;
+ KeyedVector<String8, int32_t> mTorchStatusMap;
// camera id -> torch client binder
// only store the last client that turns on each camera's torch mode
KeyedVector<String8, sp<IBinder>> mTorchClientMap;
@@ -688,15 +689,15 @@
// handle torch mode status change and invoke callbacks. mTorchStatusMutex
// should be locked.
void onTorchStatusChangedLocked(const String8& cameraId,
- ICameraServiceListener::TorchStatus newStatus);
+ int32_t newStatus);
// get a camera's torch status. mTorchStatusMutex should be locked.
status_t getTorchStatusLocked(const String8 &cameraId,
- ICameraServiceListener::TorchStatus *status) const;
+ int32_t *status) const;
// set a camera's torch status. mTorchStatusMutex should be locked.
status_t setTorchStatusLocked(const String8 &cameraId,
- ICameraServiceListener::TorchStatus status);
+ int32_t status);
// IBinder::DeathRecipient implementation
virtual void binderDied(const wp<IBinder> &who);
@@ -708,25 +709,25 @@
/**
* Initialize and cache the metadata used by the HAL1 shim for a given cameraId.
*
- * Returns OK on success, or a negative error code.
+ * Sets Status to a service-specific error on failure
*/
- status_t initializeShimMetadata(int cameraId);
+ binder::Status initializeShimMetadata(int cameraId);
/**
* Get the cached CameraParameters for the camera. If they haven't been
* cached yet, then initialize them for the first time.
*
- * Returns OK on success, or a negative error code.
+ * Sets Status to a service-specific error on failure
*/
- status_t getLegacyParametersLazy(int cameraId, /*out*/CameraParameters* parameters);
+ binder::Status getLegacyParametersLazy(int cameraId, /*out*/CameraParameters* parameters);
/**
* Generate the CameraCharacteristics metadata required by the Camera2 API
* from the available HAL1 CameraParameters and CameraInfo.
*
- * Returns OK on success, or a negative error code.
+ * Sets Status to a service-specific error on failure
*/
- status_t generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo);
+ binder::Status generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo);
static int getCallingPid();
@@ -742,8 +743,8 @@
*/
static int getCameraPriorityFromProcState(int procState);
- static status_t makeClient(const sp<CameraService>& cameraService,
- const sp<IInterface>& cameraCb, const String16& packageName, const String8& cameraId,
+ static binder::Status makeClient(const sp<CameraService>& cameraService,
+ const sp<IInterface>& cameraCb, const String16& packageName, int cameraId,
int facing, int clientPid, uid_t clientUid, int servicePid, bool legacyMode,
int halVersion, int deviceVersion, apiLevel effectiveApiLevel,
/*out*/sp<BasicClient>* client);
@@ -758,12 +759,12 @@
};
template<class Func>
-void CameraService::CameraState::updateStatus(ICameraServiceListener::Status status,
+void CameraService::CameraState::updateStatus(int32_t status,
const String8& cameraId,
- std::initializer_list<ICameraServiceListener::Status> rejectSourceStates,
+ std::initializer_list<int32_t> rejectSourceStates,
Func onStatusUpdatedLocked) {
Mutex::Autolock lock(mStatusLock);
- ICameraServiceListener::Status oldStatus = mStatus;
+ int32_t oldStatus = mStatus;
mStatus = status;
if (oldStatus == status) {
@@ -773,9 +774,9 @@
ALOGV("%s: Status has changed for camera ID %s from %#x to %#x", __FUNCTION__,
cameraId.string(), oldStatus, status);
- if (oldStatus == ICameraServiceListener::STATUS_NOT_PRESENT &&
- (status != ICameraServiceListener::STATUS_PRESENT &&
- status != ICameraServiceListener::STATUS_ENUMERATING)) {
+ if (oldStatus == hardware::ICameraServiceListener::STATUS_NOT_PRESENT &&
+ (status != hardware::ICameraServiceListener::STATUS_PRESENT &&
+ status != hardware::ICameraServiceListener::STATUS_ENUMERATING)) {
ALOGW("%s: From NOT_PRESENT can only transition into PRESENT or ENUMERATING",
__FUNCTION__);
@@ -800,13 +801,22 @@
onStatusUpdatedLocked(cameraId, status);
}
+#define STATUS_ERROR(errorCode, errorString) \
+ binder::Status::fromServiceSpecificError(errorCode, \
+ String8::format("%s:%d: %s", __FUNCTION__, __LINE__, errorString))
+
+#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
+ binder::Status::fromServiceSpecificError(errorCode, \
+ String8::format("%s:%d: " errorString, __FUNCTION__, __LINE__, __VA_ARGS__))
+
template<class CALLBACK, class CLIENT>
-status_t CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId,
+binder::Status CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId,
int halVersion, const String16& clientPackageName, int clientUid, int clientPid,
apiLevel effectiveApiLevel, bool legacyMode, bool shimUpdateOnly,
/*out*/sp<CLIENT>& device) {
- status_t ret = NO_ERROR;
+ binder::Status ret = binder::Status::ok();
+
String8 clientName8(clientPackageName);
ALOGI("CameraService::connect call (PID %d \"%s\", camera ID %s) for HAL version %s and "
@@ -821,14 +831,16 @@
AutoConditionLock::waitAndAcquire(mServiceLockWrapper, DEFAULT_CONNECT_TIMEOUT_NS);
if (lock == nullptr) {
- ALOGE("CameraService::connect X (PID %d) rejected (too many other clients connecting)."
+ ALOGE("CameraService::connect (PID %d) rejected (too many other clients connecting)."
, clientPid);
- return -EBUSY;
+ return STATUS_ERROR_FMT(ERROR_MAX_CAMERAS_IN_USE,
+ "Cannot open camera %s for \"%s\" (PID %d): Too many other clients connecting",
+ cameraId.string(), clientName8.string(), clientPid);
}
// Enforce client permissions and do basic sanity checks
- if((ret = validateConnectLocked(cameraId, /*inout*/clientUid, /*inout*/clientPid)) !=
- NO_ERROR) {
+ if(!(ret = validateConnectLocked(cameraId, clientName8,
+ /*inout*/clientUid, /*inout*/clientPid)).isOk()) {
return ret;
}
@@ -837,22 +849,37 @@
if (shimUpdateOnly) {
auto cameraState = getCameraState(cameraId);
if (cameraState != nullptr) {
- if (!cameraState->getShimParams().isEmpty()) return NO_ERROR;
+ if (!cameraState->getShimParams().isEmpty()) return ret;
}
}
+ status_t err;
+
sp<BasicClient> clientTmp = nullptr;
std::shared_ptr<resource_policy::ClientDescriptor<String8, sp<BasicClient>>> partial;
- if ((ret = handleEvictionsLocked(cameraId, clientPid, effectiveApiLevel,
+ if ((err = handleEvictionsLocked(cameraId, clientPid, effectiveApiLevel,
IInterface::asBinder(cameraCb), clientName8, /*out*/&clientTmp,
/*out*/&partial)) != NO_ERROR) {
- return ret;
+ switch (err) {
+ case -ENODEV:
+ return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
+ "No camera device with ID \"%s\" currently available",
+ cameraId.string());
+ case -EBUSY:
+ return STATUS_ERROR_FMT(ERROR_CAMERA_IN_USE,
+ "Higher-priority client using camera, ID \"%s\" currently unavailable",
+ cameraId.string());
+ default:
+ return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+ "Unexpected error %s (%d) opening camera \"%s\"",
+ strerror(-err), err, cameraId.string());
+ }
}
if (clientTmp.get() != nullptr) {
// Handle special case for API1 MediaRecorder where the existing client is returned
device = static_cast<CLIENT*>(clientTmp.get());
- return NO_ERROR;
+ return ret;
}
// give flashlight a chance to close devices if necessary.
@@ -863,15 +890,16 @@
if (id == -1) {
ALOGE("%s: Invalid camera ID %s, cannot get device version from HAL.", __FUNCTION__,
cameraId.string());
- return BAD_VALUE;
+ return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+ "Bad camera ID \"%s\" passed to camera open", cameraId.string());
}
int facing = -1;
int deviceVersion = getDeviceVersion(id, /*out*/&facing);
sp<BasicClient> tmp = nullptr;
- if((ret = makeClient(this, cameraCb, clientPackageName, cameraId, facing, clientPid,
+ if(!(ret = makeClient(this, cameraCb, clientPackageName, id, facing, clientPid,
clientUid, getpid(), legacyMode, halVersion, deviceVersion, effectiveApiLevel,
- /*out*/&tmp)) != NO_ERROR) {
+ /*out*/&tmp)).isOk()) {
return ret;
}
client = static_cast<CLIENT*>(tmp.get());
@@ -879,9 +907,11 @@
LOG_ALWAYS_FATAL_IF(client.get() == nullptr, "%s: CameraService in invalid state",
__FUNCTION__);
- if ((ret = client->initialize(mModule)) != OK) {
+ if ((err = client->initialize(mModule)) != OK) {
ALOGE("%s: Could not initialize client from HAL module.", __FUNCTION__);
- return ret;
+ return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+ "Failed to initialize camera \"%s\": %s (%d)", cameraId.string(),
+ strerror(-err), err);
}
// Update shim paremeters for legacy clients
@@ -914,9 +944,12 @@
// Important: release the mutex here so the client can call back into the service from its
// destructor (can be at the end of the call)
device = client;
- return NO_ERROR;
+ return ret;
}
+#undef STATUS_ERROR_FMT
+#undef STATUS_ERROR
+
} // namespace android
#endif
diff --git a/services/camera/libcameraservice/api1/Camera2Client.cpp b/services/camera/libcameraservice/api1/Camera2Client.cpp
index 5ac5743..4eb7b03 100644
--- a/services/camera/libcameraservice/api1/Camera2Client.cpp
+++ b/services/camera/libcameraservice/api1/Camera2Client.cpp
@@ -24,6 +24,7 @@
#include <cutils/properties.h>
#include <gui/Surface.h>
+#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
#include "api1/Camera2Client.h"
@@ -46,7 +47,7 @@
// Interface used by CameraService
Camera2Client::Camera2Client(const sp<CameraService>& cameraService,
- const sp<ICameraClient>& cameraClient,
+ const sp<hardware::ICameraClient>& cameraClient,
const String16& clientPackageName,
int cameraId,
int cameraFacing,
@@ -367,15 +368,16 @@
// ICamera interface
-void Camera2Client::disconnect() {
+binder::Status Camera2Client::disconnect() {
ATRACE_CALL();
Mutex::Autolock icl(mBinderSerializationLock);
+ binder::Status res = binder::Status::ok();
// Allow both client and the cameraserver to disconnect at all times
int callingPid = getCallingPid();
- if (callingPid != mClientPid && callingPid != mServicePid) return;
+ if (callingPid != mClientPid && callingPid != mServicePid) return res;
- if (mDevice == 0) return;
+ if (mDevice == 0) return res;
ALOGV("Camera %d: Shutting down", mCameraId);
@@ -389,7 +391,7 @@
{
SharedParameters::Lock l(mParameters);
- if (l.mParameters.state == Parameters::DISCONNECTED) return;
+ if (l.mParameters.state == Parameters::DISCONNECTED) return res;
l.mParameters.state = Parameters::DISCONNECTED;
}
@@ -430,9 +432,11 @@
mDevice.clear();
CameraService::Client::disconnect();
+
+ return res;
}
-status_t Camera2Client::connect(const sp<ICameraClient>& client) {
+status_t Camera2Client::connect(const sp<hardware::ICameraClient>& client) {
ATRACE_CALL();
ALOGV("%s: E", __FUNCTION__);
Mutex::Autolock icl(mBinderSerializationLock);
@@ -1682,22 +1686,22 @@
}
}
-void Camera2Client::notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+void Camera2Client::notifyError(int32_t errorCode,
const CaptureResultExtras& resultExtras) {
int32_t err = CAMERA_ERROR_UNKNOWN;
switch(errorCode) {
- case ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED:
+ case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED:
err = CAMERA_ERROR_RELEASED;
break;
- case ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE:
+ case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE:
err = CAMERA_ERROR_UNKNOWN;
break;
- case ICameraDeviceCallbacks::ERROR_CAMERA_SERVICE:
+ case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_SERVICE:
err = CAMERA_ERROR_SERVER_DIED;
break;
- case ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST:
- case ICameraDeviceCallbacks::ERROR_CAMERA_RESULT:
- case ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER:
+ case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST:
+ case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_RESULT:
+ case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER:
ALOGW("%s: Received recoverable error %d from HAL - ignoring, requestId %" PRId32,
__FUNCTION__, errorCode, resultExtras.requestId);
return;
diff --git a/services/camera/libcameraservice/api1/Camera2Client.h b/services/camera/libcameraservice/api1/Camera2Client.h
index 9155e43..12ee157 100644
--- a/services/camera/libcameraservice/api1/Camera2Client.h
+++ b/services/camera/libcameraservice/api1/Camera2Client.h
@@ -53,8 +53,8 @@
* ICamera interface (see ICamera for details)
*/
- virtual void disconnect();
- virtual status_t connect(const sp<ICameraClient>& client);
+ virtual binder::Status disconnect();
+ virtual status_t connect(const sp<hardware::ICameraClient>& client);
virtual status_t lock();
virtual status_t unlock();
virtual status_t setPreviewTarget(
@@ -77,7 +77,7 @@
virtual status_t setParameters(const String8& params);
virtual String8 getParameters() const;
virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
- virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+ virtual void notifyError(int32_t errorCode,
const CaptureResultExtras& resultExtras);
virtual status_t setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer);
@@ -86,7 +86,7 @@
*/
Camera2Client(const sp<CameraService>& cameraService,
- const sp<ICameraClient>& cameraClient,
+ const sp<hardware::ICameraClient>& cameraClient,
const String16& clientPackageName,
int cameraId,
int cameraFacing,
diff --git a/services/camera/libcameraservice/api1/CameraClient.cpp b/services/camera/libcameraservice/api1/CameraClient.cpp
index 8ab9a65..37f4c8f 100644
--- a/services/camera/libcameraservice/api1/CameraClient.cpp
+++ b/services/camera/libcameraservice/api1/CameraClient.cpp
@@ -34,7 +34,7 @@
}
CameraClient::CameraClient(const sp<CameraService>& cameraService,
- const sp<ICameraClient>& cameraClient,
+ const sp<hardware::ICameraClient>& cameraClient,
const String16& clientPackageName,
int cameraId, int cameraFacing,
int clientPid, int clientUid,
@@ -193,7 +193,7 @@
}
// connect a new client to the camera
-status_t CameraClient::connect(const sp<ICameraClient>& client) {
+status_t CameraClient::connect(const sp<hardware::ICameraClient>& client) {
int callingPid = getCallingPid();
LOG1("connect E (pid %d)", callingPid);
Mutex::Autolock lock(mLock);
@@ -229,20 +229,21 @@
}
}
-void CameraClient::disconnect() {
+binder::Status CameraClient::disconnect() {
int callingPid = getCallingPid();
LOG1("disconnect E (pid %d)", callingPid);
Mutex::Autolock lock(mLock);
+ binder::Status res = binder::Status::ok();
// Allow both client and the cameraserver to disconnect at all times
if (callingPid != mClientPid && callingPid != mServicePid) {
ALOGW("different client - don't disconnect");
- return;
+ return res;
}
// Make sure disconnect() is done once and once only, whether it is called
// from the user directly, or called by the destructor.
- if (mHardware == 0) return;
+ if (mHardware == 0) return res;
LOG1("hardware teardown");
// Before destroying mHardware, we must make sure it's in the
@@ -268,6 +269,8 @@
CameraService::Client::disconnect();
LOG1("disconnect X (pid %d)", callingPid);
+
+ return res;
}
// ----------------------------------------------------------------------------
@@ -797,7 +800,7 @@
mCameraService->playSound(CameraService::SOUND_SHUTTER);
}
- sp<ICameraClient> c = mRemoteCallback;
+ sp<hardware::ICameraClient> c = mRemoteCallback;
if (c != 0) {
mLock.unlock();
c->notifyCallback(CAMERA_MSG_SHUTTER, 0, 0);
@@ -834,7 +837,7 @@
}
// hold a strong pointer to the client
- sp<ICameraClient> c = mRemoteCallback;
+ sp<hardware::ICameraClient> c = mRemoteCallback;
// clear callback flags if no client or one-shot mode
if (c == 0 || (mPreviewCallbackFlag & CAMERA_FRAME_CALLBACK_FLAG_ONE_SHOT_MASK)) {
@@ -864,7 +867,7 @@
void CameraClient::handlePostview(const sp<IMemory>& mem) {
disableMsgType(CAMERA_MSG_POSTVIEW_FRAME);
- sp<ICameraClient> c = mRemoteCallback;
+ sp<hardware::ICameraClient> c = mRemoteCallback;
mLock.unlock();
if (c != 0) {
c->dataCallback(CAMERA_MSG_POSTVIEW_FRAME, mem, NULL);
@@ -879,7 +882,7 @@
size_t size;
sp<IMemoryHeap> heap = mem->getMemory(&offset, &size);
- sp<ICameraClient> c = mRemoteCallback;
+ sp<hardware::ICameraClient> c = mRemoteCallback;
mLock.unlock();
if (c != 0) {
c->dataCallback(CAMERA_MSG_RAW_IMAGE, mem, NULL);
@@ -890,7 +893,7 @@
void CameraClient::handleCompressedPicture(const sp<IMemory>& mem) {
disableMsgType(CAMERA_MSG_COMPRESSED_IMAGE);
- sp<ICameraClient> c = mRemoteCallback;
+ sp<hardware::ICameraClient> c = mRemoteCallback;
mLock.unlock();
if (c != 0) {
c->dataCallback(CAMERA_MSG_COMPRESSED_IMAGE, mem, NULL);
@@ -900,7 +903,7 @@
void CameraClient::handleGenericNotify(int32_t msgType,
int32_t ext1, int32_t ext2) {
- sp<ICameraClient> c = mRemoteCallback;
+ sp<hardware::ICameraClient> c = mRemoteCallback;
mLock.unlock();
if (c != 0) {
c->notifyCallback(msgType, ext1, ext2);
@@ -909,7 +912,7 @@
void CameraClient::handleGenericData(int32_t msgType,
const sp<IMemory>& dataPtr, camera_frame_metadata_t *metadata) {
- sp<ICameraClient> c = mRemoteCallback;
+ sp<hardware::ICameraClient> c = mRemoteCallback;
mLock.unlock();
if (c != 0) {
c->dataCallback(msgType, dataPtr, metadata);
@@ -918,7 +921,7 @@
void CameraClient::handleGenericDataTimestamp(nsecs_t timestamp,
int32_t msgType, const sp<IMemory>& dataPtr) {
- sp<ICameraClient> c = mRemoteCallback;
+ sp<hardware::ICameraClient> c = mRemoteCallback;
mLock.unlock();
if (c != 0) {
c->dataCallbackTimestamp(timestamp, msgType, dataPtr);
@@ -926,7 +929,7 @@
}
void CameraClient::copyFrameAndPostCopiedFrame(
- int32_t msgType, const sp<ICameraClient>& client,
+ int32_t msgType, const sp<hardware::ICameraClient>& client,
const sp<IMemoryHeap>& heap, size_t offset, size_t size,
camera_frame_metadata_t *metadata) {
LOG2("copyFrameAndPostCopiedFrame");
diff --git a/services/camera/libcameraservice/api1/CameraClient.h b/services/camera/libcameraservice/api1/CameraClient.h
index 9b32774..603fd17 100644
--- a/services/camera/libcameraservice/api1/CameraClient.h
+++ b/services/camera/libcameraservice/api1/CameraClient.h
@@ -33,8 +33,8 @@
{
public:
// ICamera interface (see ICamera for details)
- virtual void disconnect();
- virtual status_t connect(const sp<ICameraClient>& client);
+ virtual binder::Status disconnect();
+ virtual status_t connect(const sp<hardware::ICameraClient>& client);
virtual status_t lock();
virtual status_t unlock();
virtual status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer);
@@ -59,7 +59,7 @@
// Interface used by CameraService
CameraClient(const sp<CameraService>& cameraService,
- const sp<ICameraClient>& cameraClient,
+ const sp<hardware::ICameraClient>& cameraClient,
const String16& clientPackageName,
int cameraId,
int cameraFacing,
@@ -116,7 +116,7 @@
void copyFrameAndPostCopiedFrame(
int32_t msgType,
- const sp<ICameraClient>& client,
+ const sp<hardware::ICameraClient>& client,
const sp<IMemoryHeap>& heap,
size_t offset, size_t size,
camera_frame_metadata_t *metadata);
diff --git a/services/camera/libcameraservice/api1/client2/Parameters.cpp b/services/camera/libcameraservice/api1/client2/Parameters.cpp
index 7a97396..d4022cd 100644
--- a/services/camera/libcameraservice/api1/client2/Parameters.cpp
+++ b/services/camera/libcameraservice/api1/client2/Parameters.cpp
@@ -30,7 +30,7 @@
#include "Parameters.h"
#include "system/camera.h"
#include "hardware/camera_common.h"
-#include <camera/ICamera.h>
+#include <android/hardware/ICamera.h>
#include <media/MediaProfiles.h>
#include <media/mediarecorder.h>
@@ -873,7 +873,7 @@
// Set up initial state for non-Camera.Parameters state variables
videoFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
videoDataSpace = HAL_DATASPACE_BT709;
- videoBufferMode = ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV;
+ videoBufferMode = hardware::ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV;
playShutterSound = true;
enableFaceDetect = false;
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
index 7be5696..6f9bc7c 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
@@ -28,14 +28,26 @@
#include "common/CameraDeviceBase.h"
#include "api2/CameraDeviceClient.h"
+// Convenience methods for constructing binder::Status objects for error returns
+#define STRINGIZE_IMPL(x) #x
+#define STRINGIZE(x) STRINGIZE_IMPL(x)
+
+#define STATUS_ERROR(errorCode, errorString) \
+ binder::Status::fromServiceSpecificError(errorCode, \
+ String8(STRINGIZE(__FUNCTION__) ":" STRINGIZE(__LINE__) ":" # errorString))
+
+#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
+ binder::Status::fromServiceSpecificError(errorCode, \
+ String8::format(STRINGIZE(__FUNCTION__) ":" STRINGIZE(__LINE__) ":" # errorString, \
+ __VA_ARGS__))
namespace android {
using namespace camera2;
CameraDeviceClientBase::CameraDeviceClientBase(
const sp<CameraService>& cameraService,
- const sp<ICameraDeviceCallbacks>& remoteCallback,
+ const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
const String16& clientPackageName,
int cameraId,
int cameraFacing,
@@ -56,13 +68,13 @@
// Interface used by CameraService
CameraDeviceClient::CameraDeviceClient(const sp<CameraService>& cameraService,
- const sp<ICameraDeviceCallbacks>& remoteCallback,
- const String16& clientPackageName,
- int cameraId,
- int cameraFacing,
- int clientPid,
- uid_t clientUid,
- int servicePid) :
+ const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
+ const String16& clientPackageName,
+ int cameraId,
+ int cameraFacing,
+ int clientPid,
+ uid_t clientUid,
+ int servicePid) :
Camera2ClientBase(cameraService, remoteCallback, clientPackageName,
cameraId, cameraFacing, clientPid, clientUid, servicePid),
mInputStream(),
@@ -98,68 +110,77 @@
CameraDeviceClient::~CameraDeviceClient() {
}
-status_t CameraDeviceClient::submitRequest(sp<CaptureRequest> request,
- bool streaming,
- /*out*/
- int64_t* lastFrameNumber) {
- List<sp<CaptureRequest> > requestList;
- requestList.push_back(request);
- return submitRequestList(requestList, streaming, lastFrameNumber);
+binder::Status CameraDeviceClient::submitRequest(
+ const hardware::camera2::CaptureRequest& request,
+ bool streaming,
+ /*out*/
+ hardware::camera2::utils::SubmitInfo *submitInfo) {
+ std::vector<hardware::camera2::CaptureRequest> requestList = { request };
+ return submitRequestList(requestList, streaming, submitInfo);
}
-status_t CameraDeviceClient::submitRequestList(List<sp<CaptureRequest> > requests,
- bool streaming, int64_t* lastFrameNumber) {
+binder::Status CameraDeviceClient::submitRequestList(
+ const std::vector<hardware::camera2::CaptureRequest>& requests,
+ bool streaming,
+ /*out*/
+ hardware::camera2::utils::SubmitInfo *submitInfo) {
ATRACE_CALL();
ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
- status_t res;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ binder::Status res = binder::Status::ok();
+ status_t err;
+ if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
+ return res;
+ }
Mutex::Autolock icl(mBinderSerializationLock);
- if (!mDevice.get()) return DEAD_OBJECT;
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
if (requests.empty()) {
ALOGE("%s: Camera %d: Sent null request. Rejecting request.",
__FUNCTION__, mCameraId);
- return BAD_VALUE;
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
}
List<const CameraMetadata> metadataRequestList;
- int32_t requestId = mRequestIdCounter;
+ submitInfo->mRequestId = mRequestIdCounter;
uint32_t loopCounter = 0;
- for (List<sp<CaptureRequest> >::iterator it = requests.begin(); it != requests.end(); ++it) {
- sp<CaptureRequest> request = *it;
- if (request == 0) {
- ALOGE("%s: Camera %d: Sent null request.",
- __FUNCTION__, mCameraId);
- return BAD_VALUE;
- } else if (request->mIsReprocess) {
+ for (auto&& request: requests) {
+ if (request.mIsReprocess) {
if (!mInputStream.configured) {
ALOGE("%s: Camera %d: no input stream is configured.", __FUNCTION__, mCameraId);
- return BAD_VALUE;
+ return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "No input configured for camera %d but request is for reprocessing",
+ mCameraId);
} else if (streaming) {
ALOGE("%s: Camera %d: streaming reprocess requests not supported.", __FUNCTION__,
mCameraId);
- return BAD_VALUE;
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "Repeating reprocess requests not supported");
}
}
- CameraMetadata metadata(request->mMetadata);
+ CameraMetadata metadata(request.mMetadata);
if (metadata.isEmpty()) {
ALOGE("%s: Camera %d: Sent empty metadata packet. Rejecting request.",
__FUNCTION__, mCameraId);
- return BAD_VALUE;
- } else if (request->mSurfaceList.isEmpty()) {
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "Request settings are empty");
+ } else if (request.mSurfaceList.isEmpty()) {
ALOGE("%s: Camera %d: Requests must have at least one surface target. "
- "Rejecting request.", __FUNCTION__, mCameraId);
- return BAD_VALUE;
+ "Rejecting request.", __FUNCTION__, mCameraId);
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "Request has no output targets");
}
if (!enforceRequestPermissions(metadata)) {
// Callee logs
- return PERMISSION_DENIED;
+ return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
+ "Caller does not have permission to change restricted controls");
}
/**
@@ -167,9 +188,8 @@
* the capture request's list of surface targets
*/
Vector<int32_t> outputStreamIds;
- outputStreamIds.setCapacity(request->mSurfaceList.size());
- for (size_t i = 0; i < request->mSurfaceList.size(); ++i) {
- sp<Surface> surface = request->mSurfaceList[i];
+ outputStreamIds.setCapacity(request.mSurfaceList.size());
+ for (sp<Surface> surface : request.mSurfaceList) {
if (surface == 0) continue;
sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
@@ -178,69 +198,80 @@
// Trying to submit request with surface that wasn't created
if (idx == NAME_NOT_FOUND) {
ALOGE("%s: Camera %d: Tried to submit a request with a surface that"
- " we have not called createStream on",
- __FUNCTION__, mCameraId);
- return BAD_VALUE;
+ " we have not called createStream on",
+ __FUNCTION__, mCameraId);
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "Request targets Surface that is not part of current capture session");
}
int streamId = mStreamMap.valueAt(idx);
outputStreamIds.push_back(streamId);
ALOGV("%s: Camera %d: Appending output stream %d to request",
- __FUNCTION__, mCameraId, streamId);
+ __FUNCTION__, mCameraId, streamId);
}
metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS, &outputStreamIds[0],
outputStreamIds.size());
- if (request->mIsReprocess) {
+ if (request.mIsReprocess) {
metadata.update(ANDROID_REQUEST_INPUT_STREAMS, &mInputStream.id, 1);
}
- metadata.update(ANDROID_REQUEST_ID, &requestId, /*size*/1);
+ metadata.update(ANDROID_REQUEST_ID, &(submitInfo->mRequestId), /*size*/1);
loopCounter++; // loopCounter starts from 1
ALOGV("%s: Camera %d: Creating request with ID %d (%d of %zu)",
- __FUNCTION__, mCameraId, requestId, loopCounter, requests.size());
+ __FUNCTION__, mCameraId, submitInfo->mRequestId, loopCounter, requests.size());
metadataRequestList.push_back(metadata);
}
mRequestIdCounter++;
if (streaming) {
- res = mDevice->setStreamingRequestList(metadataRequestList, lastFrameNumber);
- if (res != OK) {
- ALOGE("%s: Camera %d: Got error %d after trying to set streaming "
- "request", __FUNCTION__, mCameraId, res);
+ err = mDevice->setStreamingRequestList(metadataRequestList, &(submitInfo->mLastFrameNumber));
+ if (err != OK) {
+ String8 msg = String8::format(
+ "Camera %d: Got error %s (%d) after trying to set streaming request",
+ mCameraId, strerror(-err), err);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
+ msg.string());
} else {
- mStreamingRequestList.push_back(requestId);
+ mStreamingRequestList.push_back(submitInfo->mRequestId);
}
} else {
- res = mDevice->captureList(metadataRequestList, lastFrameNumber);
- if (res != OK) {
- ALOGE("%s: Camera %d: Got error %d after trying to set capture",
- __FUNCTION__, mCameraId, res);
+ err = mDevice->captureList(metadataRequestList, &(submitInfo->mLastFrameNumber));
+ if (err != OK) {
+ String8 msg = String8::format(
+ "Camera %d: Got error %s (%d) after trying to submit capture request",
+ mCameraId, strerror(-err), err);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
+ msg.string());
}
- ALOGV("%s: requestId = %d ", __FUNCTION__, requestId);
+ ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
}
ALOGV("%s: Camera %d: End of function", __FUNCTION__, mCameraId);
- if (res == OK) {
- return requestId;
- }
-
return res;
}
-status_t CameraDeviceClient::cancelRequest(int requestId, int64_t* lastFrameNumber) {
+binder::Status CameraDeviceClient::cancelRequest(
+ int requestId,
+ /*out*/
+ int64_t* lastFrameNumber) {
ATRACE_CALL();
ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
- status_t res;
+ status_t err;
+ binder::Status res;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
- if (!mDevice.get()) return DEAD_OBJECT;
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
Vector<int>::iterator it, end;
for (it = mStreamingRequestList.begin(), end = mStreamingRequestList.end();
@@ -251,29 +282,34 @@
}
if (it == end) {
- ALOGE("%s: Camera%d: Did not find request id %d in list of streaming "
- "requests", __FUNCTION__, mCameraId, requestId);
- return BAD_VALUE;
+ String8 msg = String8::format("Camera %d: Did not find request ID %d in list of "
+ "streaming requests", mCameraId, requestId);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
}
- res = mDevice->clearStreamingRequest(lastFrameNumber);
+ err = mDevice->clearStreamingRequest(lastFrameNumber);
- if (res == OK) {
+ if (err == OK) {
ALOGV("%s: Camera %d: Successfully cleared streaming request",
__FUNCTION__, mCameraId);
mStreamingRequestList.erase(it);
+ } else {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+ "Camera %d: Error clearing streaming request: %s (%d)",
+ mCameraId, strerror(-err), err);
}
return res;
}
-status_t CameraDeviceClient::beginConfigure() {
+binder::Status CameraDeviceClient::beginConfigure() {
// TODO: Implement this.
ALOGV("%s: Not implemented yet.", __FUNCTION__);
- return OK;
+ return binder::Status::ok();
}
-status_t CameraDeviceClient::endConfigure(bool isConstrainedHighSpeed) {
+binder::Status CameraDeviceClient::endConfigure(bool isConstrainedHighSpeed) {
ALOGV("%s: ending configure (%d input stream, %zu output streams)",
__FUNCTION__, mInputStream.configured ? 1 : 0, mStreamMap.size());
@@ -290,33 +326,46 @@
}
}
if (!isConstrainedHighSpeedSupported) {
- ALOGE("%s: Camera %d: Try to create a constrained high speed configuration on a device"
- " that doesn't support it.",
- __FUNCTION__, mCameraId);
- return INVALID_OPERATION;
+ String8 msg = String8::format(
+ "Camera %d: Try to create a constrained high speed configuration on a device"
+ " that doesn't support it.", mCameraId);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ msg.string());
}
}
- status_t res;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
- if (!mDevice.get()) return DEAD_OBJECT;
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
- return mDevice->configureStreams(isConstrainedHighSpeed);
+ status_t err = mDevice->configureStreams(isConstrainedHighSpeed);
+ if (err != OK) {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+ "Camera %d: Error configuring streams: %s (%d)",
+ mCameraId, strerror(-err), err);
+ }
+
+ return res;
}
-status_t CameraDeviceClient::deleteStream(int streamId) {
+binder::Status CameraDeviceClient::deleteStream(int streamId) {
ATRACE_CALL();
ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
- status_t res;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
- if (!mDevice.get()) return DEAD_OBJECT;
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
bool isInput = false;
ssize_t index = NAME_NOT_FOUND;
@@ -333,20 +382,22 @@
}
if (index == NAME_NOT_FOUND) {
- ALOGW("%s: Camera %d: Invalid stream ID (%d) specified, no stream "
- "created yet", __FUNCTION__, mCameraId, streamId);
- return BAD_VALUE;
+ String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no such "
+ "stream created yet", mCameraId, streamId);
+ ALOGW("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
}
}
// Also returns BAD_VALUE if stream ID was not valid
- res = mDevice->deleteStream(streamId);
+ status_t err = mDevice->deleteStream(streamId);
- if (res == BAD_VALUE) {
- ALOGE("%s: Camera %d: Unexpected BAD_VALUE when deleting stream, but we"
- " already checked and the stream ID (%d) should be valid.",
- __FUNCTION__, mCameraId, streamId);
- } else if (res == OK) {
+ if (err != OK) {
+ String8 msg = String8::format("Camera %d: Unexpected error %s (%d) when deleting stream %d",
+ mCameraId, strerror(-err), err, streamId);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
+ } else {
if (isInput) {
mInputStream.configured = false;
} else {
@@ -357,44 +408,50 @@
return res;
}
-status_t CameraDeviceClient::createStream(const OutputConfiguration &outputConfiguration)
-{
+binder::Status CameraDeviceClient::createStream(
+ const hardware::camera2::params::OutputConfiguration &outputConfiguration,
+ /*out*/
+ int32_t* newStreamId) {
ATRACE_CALL();
- status_t res;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
-
sp<IGraphicBufferProducer> bufferProducer = outputConfiguration.getGraphicBufferProducer();
if (bufferProducer == NULL) {
ALOGE("%s: bufferProducer must not be null", __FUNCTION__);
- return BAD_VALUE;
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
}
- if (!mDevice.get()) return DEAD_OBJECT;
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
// Don't create multiple streams for the same target surface
{
ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
if (index != NAME_NOT_FOUND) {
- ALOGW("%s: Camera %d: Buffer producer already has a stream for it "
- "(ID %zd)",
- __FUNCTION__, mCameraId, index);
- return ALREADY_EXISTS;
+ String8 msg = String8::format("Camera %d: Surface already has a stream created for it "
+ "(ID %zd)", mCameraId, index);
+ ALOGW("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.string());
}
}
+ status_t err;
+
// HACK b/10949105
// Query consumer usage bits to set async operation mode for
// GLConsumer using controlledByApp parameter.
bool useAsync = false;
int32_t consumerUsage;
- if ((res = bufferProducer->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS,
+ if ((err = bufferProducer->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS,
&consumerUsage)) != OK) {
- ALOGE("%s: Camera %d: Failed to query consumer usage", __FUNCTION__,
- mCameraId);
- return res;
+ String8 msg = String8::format("Camera %d: Failed to query Surface consumer usage: %s (%d)",
+ mCameraId, strerror(-err), err);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
}
if (consumerUsage & GraphicBuffer::USAGE_HW_TEXTURE) {
ALOGW("%s: Camera %d: Forcing asynchronous mode for stream",
@@ -417,26 +474,30 @@
int width, height, format;
android_dataspace dataSpace;
- if ((res = anw->query(anw, NATIVE_WINDOW_WIDTH, &width)) != OK) {
- ALOGE("%s: Camera %d: Failed to query Surface width", __FUNCTION__,
- mCameraId);
- return res;
+ if ((err = anw->query(anw, NATIVE_WINDOW_WIDTH, &width)) != OK) {
+ String8 msg = String8::format("Camera %d: Failed to query Surface width: %s (%d)",
+ mCameraId, strerror(-err), err);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
}
- if ((res = anw->query(anw, NATIVE_WINDOW_HEIGHT, &height)) != OK) {
- ALOGE("%s: Camera %d: Failed to query Surface height", __FUNCTION__,
- mCameraId);
- return res;
+ if ((err = anw->query(anw, NATIVE_WINDOW_HEIGHT, &height)) != OK) {
+ String8 msg = String8::format("Camera %d: Failed to query Surface height: %s (%d)",
+ mCameraId, strerror(-err), err);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
}
- if ((res = anw->query(anw, NATIVE_WINDOW_FORMAT, &format)) != OK) {
- ALOGE("%s: Camera %d: Failed to query Surface format", __FUNCTION__,
- mCameraId);
- return res;
+ if ((err = anw->query(anw, NATIVE_WINDOW_FORMAT, &format)) != OK) {
+ String8 msg = String8::format("Camera %d: Failed to query Surface format: %s (%d)",
+ mCameraId, strerror(-err), err);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
}
- if ((res = anw->query(anw, NATIVE_WINDOW_DEFAULT_DATASPACE,
+ if ((err = anw->query(anw, NATIVE_WINDOW_DEFAULT_DATASPACE,
reinterpret_cast<int*>(&dataSpace))) != OK) {
- ALOGE("%s: Camera %d: Failed to query Surface dataSpace", __FUNCTION__,
- mCameraId);
- return res;
+ String8 msg = String8::format("Camera %d: Failed to query Surface dataspace: %s (%d)",
+ mCameraId, strerror(-err), err);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
}
// FIXME: remove this override since the default format should be
@@ -451,18 +512,22 @@
// Round dimensions to the nearest dimensions available for this format
if (flexibleConsumer && !CameraDeviceClient::roundBufferDimensionNearest(width, height,
format, dataSpace, mDevice->info(), /*out*/&width, /*out*/&height)) {
- ALOGE("%s: No stream configurations with the format %#x defined, failed to create stream.",
- __FUNCTION__, format);
- return BAD_VALUE;
+ String8 msg = String8::format("Camera %d: No supported stream configurations with "
+ "format %#x defined, failed to create output stream", mCameraId, format);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
}
int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
- res = mDevice->createStream(surface, width, height, format, dataSpace,
- static_cast<camera3_stream_rotation_t>
- (outputConfiguration.getRotation()),
- &streamId, outputConfiguration.getSurfaceSetID());
+ err = mDevice->createStream(surface, width, height, format, dataSpace,
+ static_cast<camera3_stream_rotation_t>(outputConfiguration.getRotation()),
+ &streamId, outputConfiguration.getSurfaceSetID());
- if (res == OK) {
+ if (err != OK) {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+ "Camera %d: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
+ mCameraId, width, height, format, dataSpace, strerror(-err), err);
+ } else {
mStreamMap.add(binder, streamId);
ALOGV("%s: Camera %d: Successfully created a new stream ID %d",
@@ -473,49 +538,56 @@
* rotate the camera stream for preview use cases.
*/
int32_t transform = 0;
- res = getRotationTransformLocked(&transform);
+ err = getRotationTransformLocked(&transform);
- if (res != OK) {
+ if (err != OK) {
// Error logged by getRotationTransformLocked.
- return res;
+ return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
+ "Unable to calculate rotation transform for new stream");
}
- res = mDevice->setStreamTransform(streamId, transform);
- if (res != OK) {
- ALOGE("%s: Failed to set stream transform (stream id %d)",
- __FUNCTION__, streamId);
- return res;
+ err = mDevice->setStreamTransform(streamId, transform);
+ if (err != OK) {
+ String8 msg = String8::format("Failed to set stream transform (stream id %d)",
+ streamId);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
}
- return streamId;
+ *newStreamId = streamId;
}
return res;
}
-status_t CameraDeviceClient::createInputStream(int width, int height,
- int format) {
+binder::Status CameraDeviceClient::createInputStream(
+ int width, int height, int format,
+ /*out*/
+ int32_t* newStreamId) {
ATRACE_CALL();
ALOGV("%s (w = %d, h = %d, f = 0x%x)", __FUNCTION__, width, height, format);
- status_t res;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
- if (!mDevice.get()) return DEAD_OBJECT;
+
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
if (mInputStream.configured) {
- ALOGE("%s: Camera %d: Already has an input stream "
- " configuration. (ID %zd)", __FUNCTION__, mCameraId,
- mInputStream.id);
- return ALREADY_EXISTS;
+ String8 msg = String8::format("Camera %d: Already has an input stream "
+ "configured (ID %zd)", mCameraId, mInputStream.id);
+ ALOGE("%s: %s", __FUNCTION__, msg.string() );
+ return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.string());
}
int streamId = -1;
- res = mDevice->createInputStream(width, height, format, &streamId);
- if (res == OK) {
+ status_t err = mDevice->createInputStream(width, height, format, &streamId);
+ if (err == OK) {
mInputStream.configured = true;
mInputStream.width = width;
mInputStream.height = height;
@@ -523,27 +595,42 @@
mInputStream.id = streamId;
ALOGV("%s: Camera %d: Successfully created a new input stream ID %d",
- __FUNCTION__, mCameraId, streamId);
+ __FUNCTION__, mCameraId, streamId);
- return streamId;
+ *newStreamId = streamId;
+ } else {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+ "Camera %d: Error creating new input stream: %s (%d)", mCameraId,
+ strerror(-err), err);
}
return res;
}
-status_t CameraDeviceClient::getInputBufferProducer(
- /*out*/sp<IGraphicBufferProducer> *producer) {
- status_t res;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
- if (producer == NULL) {
- return BAD_VALUE;
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
+
+ if (inputSurface == NULL) {
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
}
Mutex::Autolock icl(mBinderSerializationLock);
- if (!mDevice.get()) return DEAD_OBJECT;
-
- return mDevice->getInputBufferProducer(producer);
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
+ sp<IGraphicBufferProducer> producer;
+ status_t err = mDevice->getInputBufferProducer(&producer);
+ if (err != OK) {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+ "Camera %d: Error getting input Surface: %s (%d)",
+ mCameraId, strerror(-err), err);
+ } else {
+ inputSurface->name = String16("CameraInput");
+ inputSurface->graphicBufferProducer = producer;
+ }
+ return res;
}
bool CameraDeviceClient::roundBufferDimensionNearest(int32_t width, int32_t height,
@@ -604,42 +691,52 @@
}
// Create a request object from a template.
-status_t CameraDeviceClient::createDefaultRequest(int templateId,
- /*out*/
- CameraMetadata* request)
+binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
+ /*out*/
+ hardware::camera2::impl::CameraMetadataNative* request)
{
ATRACE_CALL();
ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
- status_t res;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
- if (!mDevice.get()) return DEAD_OBJECT;
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
CameraMetadata metadata;
- if ( (res = mDevice->createDefaultRequest(templateId, &metadata) ) == OK &&
+ status_t err;
+ if ( (err = mDevice->createDefaultRequest(templateId, &metadata) ) == OK &&
request != NULL) {
request->swap(metadata);
+ } else {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+ "Camera %d: Error creating default request for template %d: %s (%d)",
+ mCameraId, templateId, strerror(-err), err);
}
-
return res;
}
-status_t CameraDeviceClient::getCameraInfo(/*out*/CameraMetadata* info)
+binder::Status CameraDeviceClient::getCameraInfo(
+ /*out*/
+ hardware::camera2::impl::CameraMetadataNative* info)
{
ATRACE_CALL();
ALOGV("%s", __FUNCTION__);
- status_t res = OK;
+ binder::Status res;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
- if (!mDevice.get()) return DEAD_OBJECT;
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
if (info != NULL) {
*info = mDevice->info(); // static camera metadata
@@ -649,51 +746,68 @@
return res;
}
-status_t CameraDeviceClient::waitUntilIdle()
+binder::Status CameraDeviceClient::waitUntilIdle()
{
ATRACE_CALL();
ALOGV("%s", __FUNCTION__);
- status_t res = OK;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
- if (!mDevice.get()) return DEAD_OBJECT;
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
// FIXME: Also need check repeating burst.
if (!mStreamingRequestList.isEmpty()) {
- ALOGE("%s: Camera %d: Try to waitUntilIdle when there are active streaming requests",
- __FUNCTION__, mCameraId);
- return INVALID_OPERATION;
+ String8 msg = String8::format(
+ "Camera %d: Try to waitUntilIdle when there are active streaming requests",
+ mCameraId);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
}
- res = mDevice->waitUntilDrained();
+ status_t err = mDevice->waitUntilDrained();
+ if (err != OK) {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+ "Camera %d: Error waiting to drain: %s (%d)",
+ mCameraId, strerror(-err), err);
+ }
ALOGV("%s Done", __FUNCTION__);
-
return res;
}
-status_t CameraDeviceClient::flush(int64_t* lastFrameNumber) {
+binder::Status CameraDeviceClient::flush(
+ /*out*/
+ int64_t* lastFrameNumber) {
ATRACE_CALL();
ALOGV("%s", __FUNCTION__);
- status_t res = OK;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
- if (!mDevice.get()) return DEAD_OBJECT;
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
mStreamingRequestList.clear();
- return mDevice->flush(lastFrameNumber);
+ status_t err = mDevice->flush(lastFrameNumber);
+ if (err != OK) {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+ "Camera %d: Error flushing device: %s (%d)", mCameraId, strerror(-err), err);
+ }
+ return res;
}
-status_t CameraDeviceClient::prepare(int streamId) {
+binder::Status CameraDeviceClient::prepare(int streamId) {
ATRACE_CALL();
ALOGV("%s", __FUNCTION__);
- status_t res = OK;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
@@ -707,24 +821,33 @@
}
if (index == NAME_NOT_FOUND) {
- ALOGW("%s: Camera %d: Invalid stream ID (%d) specified, no stream "
- "created yet", __FUNCTION__, mCameraId, streamId);
- return BAD_VALUE;
+ String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no stream "
+ "with that ID exists", mCameraId, streamId);
+ ALOGW("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
}
// Also returns BAD_VALUE if stream ID was not valid, or stream already
// has been used
- res = mDevice->prepare(streamId);
-
+ status_t err = mDevice->prepare(streamId);
+ if (err == BAD_VALUE) {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "Camera %d: Stream %d has already been used, and cannot be prepared",
+ mCameraId, streamId);
+ } else if (err != OK) {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+ "Camera %d: Error preparing stream %d: %s (%d)", mCameraId, streamId,
+ strerror(-err), err);
+ }
return res;
}
-status_t CameraDeviceClient::prepare2(int maxCount, int streamId) {
+binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
ATRACE_CALL();
ALOGV("%s", __FUNCTION__);
- status_t res = OK;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
@@ -738,30 +861,41 @@
}
if (index == NAME_NOT_FOUND) {
- ALOGW("%s: Camera %d: Invalid stream ID (%d) specified, no stream created yet",
- __FUNCTION__, mCameraId, streamId);
- return BAD_VALUE;
+ String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no stream "
+ "with that ID exists", mCameraId, streamId);
+ ALOGW("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
}
if (maxCount <= 0) {
- ALOGE("%s: Camera %d: Invalid maxCount (%d) specified, must be greater than 0.",
- __FUNCTION__, mCameraId, maxCount);
- return BAD_VALUE;
+ String8 msg = String8::format("Camera %d: maxCount (%d) must be greater than 0",
+ mCameraId, maxCount);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
}
// Also returns BAD_VALUE if stream ID was not valid, or stream already
// has been used
- res = mDevice->prepare(maxCount, streamId);
+ status_t err = mDevice->prepare(maxCount, streamId);
+ if (err == BAD_VALUE) {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "Camera %d: Stream %d has already been used, and cannot be prepared",
+ mCameraId, streamId);
+ } else if (err != OK) {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+ "Camera %d: Error preparing stream %d: %s (%d)", mCameraId, streamId,
+ strerror(-err), err);
+ }
return res;
}
-status_t CameraDeviceClient::tearDown(int streamId) {
+binder::Status CameraDeviceClient::tearDown(int streamId) {
ATRACE_CALL();
ALOGV("%s", __FUNCTION__);
- status_t res = OK;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
Mutex::Autolock icl(mBinderSerializationLock);
@@ -775,14 +909,24 @@
}
if (index == NAME_NOT_FOUND) {
- ALOGW("%s: Camera %d: Invalid stream ID (%d) specified, no stream "
- "created yet", __FUNCTION__, mCameraId, streamId);
- return BAD_VALUE;
+ String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no stream "
+ "with that ID exists", mCameraId, streamId);
+ ALOGW("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
}
// Also returns BAD_VALUE if stream ID was not valid or if the stream is in
// use
- res = mDevice->tearDown(streamId);
+ status_t err = mDevice->tearDown(streamId);
+ if (err == BAD_VALUE) {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ "Camera %d: Stream %d is still in use, cannot be torn down",
+ mCameraId, streamId);
+ } else if (err != OK) {
+ res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+ "Camera %d: Error tearing down stream %d: %s (%d)", mCameraId, streamId,
+ strerror(-err), err);
+ }
return res;
}
@@ -822,10 +966,10 @@
return dumpDevice(fd, args);
}
-void CameraDeviceClient::notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+void CameraDeviceClient::notifyError(int32_t errorCode,
const CaptureResultExtras& resultExtras) {
// Thread safe. Don't bother locking.
- sp<ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
+ sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
if (remoteCb != 0) {
remoteCb->onDeviceError(errorCode, resultExtras);
@@ -834,7 +978,7 @@
void CameraDeviceClient::notifyIdle() {
// Thread safe. Don't bother locking.
- sp<ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
+ sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
if (remoteCb != 0) {
remoteCb->onDeviceIdle();
@@ -845,7 +989,7 @@
void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
nsecs_t timestamp) {
// Thread safe. Don't bother locking.
- sp<ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
+ sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
if (remoteCb != 0) {
remoteCb->onCaptureStarted(resultExtras, timestamp);
}
@@ -854,7 +998,7 @@
void CameraDeviceClient::notifyPrepared(int streamId) {
// Thread safe. Don't bother locking.
- sp<ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
+ sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
if (remoteCb != 0) {
remoteCb->onPrepared(streamId);
}
@@ -893,12 +1037,19 @@
ALOGV("%s", __FUNCTION__);
// Thread-safe. No lock necessary.
- sp<ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
+ sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
if (remoteCb != NULL) {
remoteCb->onResultReceived(result.mMetadata, result.mResultExtras);
}
}
+binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
+ status_t res = checkPid(checkLocation);
+ return (res == OK) ? binder::Status::ok() :
+ STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
+ "Attempt to use camera from a different process than original client");
+}
+
// TODO: move to Camera2ClientBase
bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.h b/services/camera/libcameraservice/api2/CameraDeviceClient.h
index b1d1762..38137a2 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.h
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.h
@@ -17,9 +17,10 @@
#ifndef ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERADEVICECLIENT_H
#define ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERADEVICECLIENT_H
-#include <camera/camera2/ICameraDeviceUser.h>
-#include <camera/camera2/ICameraDeviceCallbacks.h>
+#include <android/hardware/camera2/BnCameraDeviceUser.h>
+#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
#include <camera/camera2/OutputConfiguration.h>
+#include <camera/camera2/SubmitInfo.h>
#include "CameraService.h"
#include "common/FrameProcessorBase.h"
@@ -27,17 +28,19 @@
namespace android {
-struct CameraDeviceClientBase : public CameraService::BasicClient, public BnCameraDeviceUser
+struct CameraDeviceClientBase :
+ public CameraService::BasicClient,
+ public hardware::camera2::BnCameraDeviceUser
{
- typedef ICameraDeviceCallbacks TCamCallbacks;
+ typedef hardware::camera2::ICameraDeviceCallbacks TCamCallbacks;
- const sp<ICameraDeviceCallbacks>& getRemoteCallback() {
+ const sp<hardware::camera2::ICameraDeviceCallbacks>& getRemoteCallback() {
return mRemoteCallback;
}
protected:
CameraDeviceClientBase(const sp<CameraService>& cameraService,
- const sp<ICameraDeviceCallbacks>& remoteCallback,
+ const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
const String16& clientPackageName,
int cameraId,
int cameraFacing,
@@ -45,7 +48,7 @@
uid_t clientUid,
int servicePid);
- sp<ICameraDeviceCallbacks> mRemoteCallback;
+ sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
};
/**
@@ -63,66 +66,77 @@
*/
// Note that the callee gets a copy of the metadata.
- virtual status_t submitRequest(sp<CaptureRequest> request,
- bool streaming = false,
- /*out*/
- int64_t* lastFrameNumber = NULL);
+ virtual binder::Status submitRequest(
+ const hardware::camera2::CaptureRequest& request,
+ bool streaming = false,
+ /*out*/
+ hardware::camera2::utils::SubmitInfo *submitInfo = nullptr);
// List of requests are copied.
- virtual status_t submitRequestList(List<sp<CaptureRequest> > requests,
- bool streaming = false,
- /*out*/
- int64_t* lastFrameNumber = NULL);
- virtual status_t cancelRequest(int requestId,
- /*out*/
- int64_t* lastFrameNumber = NULL);
+ virtual binder::Status submitRequestList(
+ const std::vector<hardware::camera2::CaptureRequest>& requests,
+ bool streaming = false,
+ /*out*/
+ hardware::camera2::utils::SubmitInfo *submitInfo = nullptr);
+ virtual binder::Status cancelRequest(int requestId,
+ /*out*/
+ int64_t* lastFrameNumber = NULL);
- virtual status_t beginConfigure();
+ virtual binder::Status beginConfigure();
- virtual status_t endConfigure(bool isConstrainedHighSpeed = false);
+ virtual binder::Status endConfigure(bool isConstrainedHighSpeed = false);
// Returns -EBUSY if device is not idle
- virtual status_t deleteStream(int streamId);
+ virtual binder::Status deleteStream(int streamId);
- virtual status_t createStream(const OutputConfiguration &outputConfiguration);
+ virtual binder::Status createStream(
+ const hardware::camera2::params::OutputConfiguration &outputConfiguration,
+ /*out*/
+ int32_t* newStreamId = NULL);
// Create an input stream of width, height, and format.
- virtual status_t createInputStream(int width, int height, int format);
+ virtual binder::Status createInputStream(int width, int height, int format,
+ /*out*/
+ int32_t* newStreamId = NULL);
// Get the buffer producer of the input stream
- virtual status_t getInputBufferProducer(
- /*out*/sp<IGraphicBufferProducer> *producer);
+ virtual binder::Status getInputSurface(
+ /*out*/
+ view::Surface *inputSurface);
// Create a request object from a template.
- virtual status_t createDefaultRequest(int templateId,
- /*out*/
- CameraMetadata* request);
+ virtual binder::Status createDefaultRequest(int templateId,
+ /*out*/
+ hardware::camera2::impl::CameraMetadataNative* request);
// Get the static metadata for the camera
// -- Caller owns the newly allocated metadata
- virtual status_t getCameraInfo(/*out*/CameraMetadata* info);
+ virtual binder::Status getCameraInfo(
+ /*out*/
+ hardware::camera2::impl::CameraMetadataNative* cameraCharacteristics);
// Wait until all the submitted requests have finished processing
- virtual status_t waitUntilIdle();
+ virtual binder::Status waitUntilIdle();
// Flush all active and pending requests as fast as possible
- virtual status_t flush(/*out*/
- int64_t* lastFrameNumber = NULL);
+ virtual binder::Status flush(
+ /*out*/
+ int64_t* lastFrameNumber = NULL);
// Prepare stream by preallocating its buffers
- virtual status_t prepare(int streamId);
+ virtual binder::Status prepare(int32_t streamId);
// Tear down stream resources by freeing its unused buffers
- virtual status_t tearDown(int streamId);
+ virtual binder::Status tearDown(int32_t streamId);
// Prepare stream by preallocating up to maxCount of its buffers
- virtual status_t prepare2(int maxCount, int streamId);
+ virtual binder::Status prepare2(int32_t maxCount, int32_t streamId);
/**
* Interface used by CameraService
*/
CameraDeviceClient(const sp<CameraService>& cameraService,
- const sp<ICameraDeviceCallbacks>& remoteCallback,
+ const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
const String16& clientPackageName,
int cameraId,
int cameraFacing,
@@ -142,7 +156,7 @@
*/
virtual void notifyIdle();
- virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+ virtual void notifyError(int32_t errorCode,
const CaptureResultExtras& resultExtras);
virtual void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp);
virtual void notifyPrepared(int streamId);
@@ -167,6 +181,7 @@
static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL;
/** Utility members */
+ binder::Status checkPidStatus(const char* checkLocation);
bool enforceRequestPermissions(CameraMetadata& metadata);
// Find the square of the euclidean distance between two points
diff --git a/services/camera/libcameraservice/common/Camera2ClientBase.cpp b/services/camera/libcameraservice/common/Camera2ClientBase.cpp
index 4a812b4..2cc150d 100644
--- a/services/camera/libcameraservice/common/Camera2ClientBase.cpp
+++ b/services/camera/libcameraservice/common/Camera2ClientBase.cpp
@@ -169,14 +169,15 @@
template <typename TClientBase>
-void Camera2ClientBase<TClientBase>::disconnect() {
+binder::Status Camera2ClientBase<TClientBase>::disconnect() {
ATRACE_CALL();
Mutex::Autolock icl(mBinderSerializationLock);
+ binder::Status res = binder::Status::ok();
// Allow both client and the media server to disconnect at all times
int callingPid = getCallingPid();
if (callingPid != TClientBase::mClientPid &&
- callingPid != TClientBase::mServicePid) return;
+ callingPid != TClientBase::mServicePid) return res;
ALOGV("Camera %d: Shutting down", TClientBase::mCameraId);
@@ -185,6 +186,8 @@
CameraService::BasicClient::disconnect();
ALOGV("Camera %d: Shut down complete complete", TClientBase::mCameraId);
+
+ return res;
}
template <typename TClientBase>
@@ -228,7 +231,7 @@
template <typename TClientBase>
void Camera2ClientBase<TClientBase>::notifyError(
- ICameraDeviceCallbacks::CameraErrorCode errorCode,
+ int32_t errorCode,
const CaptureResultExtras& resultExtras) {
ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode,
resultExtras.requestId);
diff --git a/services/camera/libcameraservice/common/Camera2ClientBase.h b/services/camera/libcameraservice/common/Camera2ClientBase.h
index 81bae7b..6eea2f4 100644
--- a/services/camera/libcameraservice/common/Camera2ClientBase.h
+++ b/services/camera/libcameraservice/common/Camera2ClientBase.h
@@ -38,8 +38,8 @@
/**
* Base binder interface (see ICamera/ICameraDeviceUser for details)
*/
- virtual status_t connect(const sp<TCamCallbacks>& callbacks);
- virtual void disconnect();
+ virtual status_t connect(const sp<TCamCallbacks>& callbacks);
+ virtual binder::Status disconnect();
/**
* Interface used by CameraService
@@ -63,7 +63,7 @@
* CameraDeviceBase::NotificationListener implementation
*/
- virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+ virtual void notifyError(int32_t errorCode,
const CaptureResultExtras& resultExtras);
virtual void notifyIdle();
virtual void notifyShutter(const CaptureResultExtras& resultExtras,
diff --git a/services/camera/libcameraservice/common/CameraDeviceBase.h b/services/camera/libcameraservice/common/CameraDeviceBase.h
index 6fd2b39..ccb3bc8 100644
--- a/services/camera/libcameraservice/common/CameraDeviceBase.h
+++ b/services/camera/libcameraservice/common/CameraDeviceBase.h
@@ -24,7 +24,6 @@
#include <utils/Timers.h>
#include <utils/List.h>
-#include <camera/camera2/ICameraDeviceCallbacks.h>
#include "hardware/camera2.h"
#include "hardware/camera3.h"
#include "camera/CameraMetadata.h"
@@ -32,6 +31,7 @@
#include "common/CameraModule.h"
#include "gui/IGraphicBufferProducer.h"
#include "device3/Camera3StreamInterface.h"
+#include "binder/Status.h"
namespace android {
@@ -195,7 +195,7 @@
// API1 and API2.
// Required for API 1 and 2
- virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+ virtual void notifyError(int32_t errorCode,
const CaptureResultExtras &resultExtras) = 0;
// Required only for API2
diff --git a/services/camera/libcameraservice/device1/CameraHardwareInterface.h b/services/camera/libcameraservice/device1/CameraHardwareInterface.h
index 0fe76e5..bce0762 100644
--- a/services/camera/libcameraservice/device1/CameraHardwareInterface.h
+++ b/services/camera/libcameraservice/device1/CameraHardwareInterface.h
@@ -102,7 +102,9 @@
ALOGI("Opening camera %s", mName.string());
camera_info info;
status_t res = module->getCameraInfo(atoi(mName.string()), &info);
- if (res != OK) return res;
+ if (res != OK) {
+ return res;
+ }
int rc = OK;
if (module->getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_3 &&
diff --git a/services/camera/libcameraservice/device3/Camera3Device.cpp b/services/camera/libcameraservice/device3/Camera3Device.cpp
index 5f990a9..0de956b 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.cpp
+++ b/services/camera/libcameraservice/device3/Camera3Device.cpp
@@ -43,6 +43,8 @@
#include <utils/Trace.h>
#include <utils/Timers.h>
+#include <android/hardware/camera2/ICameraDeviceUser.h>
+
#include "utils/CameraTraces.h"
#include "mediautils/SchedulingPolicyService.h"
#include "device3/Camera3Device.h"
@@ -132,8 +134,7 @@
}
camera_info info;
- res = CameraService::filterGetInfoErrorCode(module->getCameraInfo(
- mId, &info));
+ res = module->getCameraInfo(mId, &info);
if (res != OK) return res;
if (info.device_version != device->common.version) {
@@ -453,7 +454,7 @@
return maxBytesForPointCloud;
}
-ssize_t Camera3Device::getRawOpaqueBufferSize(uint32_t width, uint32_t height) const {
+ssize_t Camera3Device::getRawOpaqueBufferSize(int32_t width, int32_t height) const {
const int PER_CONFIGURATION_SIZE = 3;
const int WIDTH_OFFSET = 0;
const int HEIGHT_OFFSET = 1;
@@ -2021,7 +2022,7 @@
// Notify upstream about a device error
if (mListener != NULL) {
- mListener->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
+ mListener->notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
CaptureResultExtras());
}
@@ -2587,25 +2588,24 @@
// Map camera HAL error codes to ICameraDeviceCallback error codes
// Index into this with the HAL error code
- static const ICameraDeviceCallbacks::CameraErrorCode
- halErrorMap[CAMERA3_MSG_NUM_ERRORS] = {
+ static const int32_t halErrorMap[CAMERA3_MSG_NUM_ERRORS] = {
// 0 = Unused error code
- ICameraDeviceCallbacks::ERROR_CAMERA_INVALID_ERROR,
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_INVALID_ERROR,
// 1 = CAMERA3_MSG_ERROR_DEVICE
- ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
// 2 = CAMERA3_MSG_ERROR_REQUEST
- ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
// 3 = CAMERA3_MSG_ERROR_RESULT
- ICameraDeviceCallbacks::ERROR_CAMERA_RESULT,
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_RESULT,
// 4 = CAMERA3_MSG_ERROR_BUFFER
- ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER
};
- ICameraDeviceCallbacks::CameraErrorCode errorCode =
+ int32_t errorCode =
((msg.error_code >= 0) &&
(msg.error_code < CAMERA3_MSG_NUM_ERRORS)) ?
halErrorMap[msg.error_code] :
- ICameraDeviceCallbacks::ERROR_CAMERA_INVALID_ERROR;
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_INVALID_ERROR;
int streamId = 0;
if (msg.error_stream != NULL) {
@@ -2619,13 +2619,13 @@
CaptureResultExtras resultExtras;
switch (errorCode) {
- case ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE:
+ case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE:
// SET_ERR calls notifyError
SET_ERR("Camera HAL reported serious device error");
break;
- case ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST:
- case ICameraDeviceCallbacks::ERROR_CAMERA_RESULT:
- case ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER:
+ case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST:
+ case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_RESULT:
+ case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER:
{
Mutex::Autolock l(mInFlightLock);
ssize_t idx = mInFlightMap.indexOfKey(msg.frame_number);
@@ -2749,7 +2749,8 @@
mLatestRequestId(NAME_NOT_FOUND),
mCurrentAfTriggerId(0),
mCurrentPreCaptureTriggerId(0),
- mRepeatingLastFrameNumber(NO_IN_FLIGHT_REPEATING_FRAMES),
+ mRepeatingLastFrameNumber(
+ hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES),
mAeLockAvailable(aeLockAvailable) {
mStatusId = statusTracker->addComponent();
}
@@ -2857,7 +2858,7 @@
unpauseForNewRequests();
- mRepeatingLastFrameNumber = NO_IN_FLIGHT_REPEATING_FRAMES;
+ mRepeatingLastFrameNumber = hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES;
return OK;
}
@@ -2878,7 +2879,7 @@
if (lastFrameNumber != NULL) {
*lastFrameNumber = mRepeatingLastFrameNumber;
}
- mRepeatingLastFrameNumber = NO_IN_FLIGHT_REPEATING_FRAMES;
+ mRepeatingLastFrameNumber = hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES;
return OK;
}
@@ -2915,7 +2916,7 @@
// The requestId and burstId fields were set when the request was
// submitted originally (in convertMetadataListToRequestListLocked)
(*it)->mResultExtras.frameNumber = mFrameNumber++;
- listener->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
+ listener->notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
(*it)->mResultExtras);
}
}
@@ -2924,7 +2925,7 @@
if (lastFrameNumber != NULL) {
*lastFrameNumber = mRepeatingLastFrameNumber;
}
- mRepeatingLastFrameNumber = NO_IN_FLIGHT_REPEATING_FRAMES;
+ mRepeatingLastFrameNumber = hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES;
return OK;
}
@@ -3344,7 +3345,7 @@
Mutex::Autolock l(mRequestLock);
if (mListener != NULL) {
mListener->notifyError(
- ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
captureRequest->mResultExtras);
}
}
@@ -3484,7 +3485,7 @@
" %s (%d)", __FUNCTION__, strerror(-res), res);
if (mListener != NULL) {
mListener->notifyError(
- ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
nextRequest->mResultExtras);
}
return NULL;
diff --git a/services/camera/libcameraservice/device3/Camera3Device.h b/services/camera/libcameraservice/device3/Camera3Device.h
index 3848200..bee69ee 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.h
+++ b/services/camera/libcameraservice/device3/Camera3Device.h
@@ -26,7 +26,6 @@
#include <utils/Timers.h>
#include <hardware/camera3.h>
#include <camera/CaptureResult.h>
-#include <camera/camera2/ICameraDeviceUser.h>
#include "common/CameraDeviceBase.h"
#include "device3/StatusTracker.h"
@@ -153,7 +152,7 @@
virtual ssize_t getJpegBufferSize(uint32_t width, uint32_t height) const;
ssize_t getPointCloudBufferSize() const;
- ssize_t getRawOpaqueBufferSize(uint32_t width, uint32_t height) const;
+ ssize_t getRawOpaqueBufferSize(int32_t width, int32_t height) const;
// Methods called by subclasses
void notifyStatus(bool idle); // updates from StatusTracker