diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2014-11-06 17:49:48 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2014-11-06 17:49:48 -0800 |
commit | e1a2df553a6d151807a5da738a3cd853bef908d9 (patch) | |
tree | 9015c1c9ad9ec69f1962657f70fe3df386fbb05a /services/camera/libcameraservice/common | |
parent | bcf093bfef277a8ec0119da9e84e5abac58ad0b1 (diff) | |
parent | 841daebc75fbf5e7fb4dd71cab559b8f4d7150ae (diff) | |
download | frameworks_av-e1a2df553a6d151807a5da738a3cd853bef908d9.zip frameworks_av-e1a2df553a6d151807a5da738a3cd853bef908d9.tar.gz frameworks_av-e1a2df553a6d151807a5da738a3cd853bef908d9.tar.bz2 |
Resolve conflict
Diffstat (limited to 'services/camera/libcameraservice/common')
5 files changed, 168 insertions, 66 deletions
diff --git a/services/camera/libcameraservice/common/Camera2ClientBase.cpp b/services/camera/libcameraservice/common/Camera2ClientBase.cpp index 6a88c87..d6db151 100644 --- a/services/camera/libcameraservice/common/Camera2ClientBase.cpp +++ b/services/camera/libcameraservice/common/Camera2ClientBase.cpp @@ -54,10 +54,13 @@ Camera2ClientBase<TClientBase>::Camera2ClientBase( int servicePid): TClientBase(cameraService, remoteCallback, clientPackageName, cameraId, cameraFacing, clientPid, clientUid, servicePid), - mSharedCameraCallbacks(remoteCallback) + mSharedCameraCallbacks(remoteCallback), + mDeviceVersion(cameraService->getDeviceVersion(cameraId)) { - ALOGI("Camera %d: Opened", cameraId); + ALOGI("Camera %d: Opened. Client: %s (PID %d, UID %d)", cameraId, + String8(clientPackageName).string(), clientPid, clientUid); + mInitialClientPid = clientPid; mDevice = CameraDeviceFactory::createDevice(cameraId); LOG_ALWAYS_FATAL_IF(mDevice == 0, "Device should never be NULL here."); } @@ -111,11 +114,12 @@ Camera2ClientBase<TClientBase>::~Camera2ClientBase() { TClientBase::mDestructionStarted = true; - TClientBase::finishCameraOps(); - disconnect(); - ALOGI("Closed Camera %d", TClientBase::mCameraId); + ALOGI("Closed Camera %d. Client was: %s (PID %d, UID %u)", + TClientBase::mCameraId, + String8(TClientBase::mClientPackageName).string(), + mInitialClientPid, TClientBase::mClientUid); } template <typename TClientBase> @@ -221,10 +225,11 @@ status_t Camera2ClientBase<TClientBase>::connect( /** Device-related methods */ template <typename TClientBase> -void Camera2ClientBase<TClientBase>::notifyError(int errorCode, int arg1, - int arg2) { - ALOGE("Error condition %d reported by HAL, arguments %d, %d", errorCode, - arg1, arg2); +void Camera2ClientBase<TClientBase>::notifyError( + ICameraDeviceCallbacks::CameraErrorCode errorCode, + const CaptureResultExtras& resultExtras) { + ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode, + resultExtras.requestId); } template <typename TClientBase> @@ -233,13 +238,13 @@ void Camera2ClientBase<TClientBase>::notifyIdle() { } template <typename TClientBase> -void Camera2ClientBase<TClientBase>::notifyShutter(int requestId, +void Camera2ClientBase<TClientBase>::notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp) { - (void)requestId; + (void)resultExtras; (void)timestamp; - ALOGV("%s: Shutter notification for request id %d at time %" PRId64, - __FUNCTION__, requestId, timestamp); + ALOGV("%s: Shutter notification for request id %" PRId32 " at time %" PRId64, + __FUNCTION__, resultExtras.requestId, timestamp); } template <typename TClientBase> @@ -279,6 +284,11 @@ int Camera2ClientBase<TClientBase>::getCameraId() const { } template <typename TClientBase> +int Camera2ClientBase<TClientBase>::getCameraDeviceVersion() const { + return mDeviceVersion; +} + +template <typename TClientBase> const sp<CameraDeviceBase>& Camera2ClientBase<TClientBase>::getCameraDevice() { return mDevice; } diff --git a/services/camera/libcameraservice/common/Camera2ClientBase.h b/services/camera/libcameraservice/common/Camera2ClientBase.h index 61e44f0..d198e4e 100644 --- a/services/camera/libcameraservice/common/Camera2ClientBase.h +++ b/services/camera/libcameraservice/common/Camera2ClientBase.h @@ -18,6 +18,7 @@ #define ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_BASE_H #include "common/CameraDeviceBase.h" +#include "camera/CaptureResult.h" namespace android { @@ -61,9 +62,11 @@ public: * CameraDeviceBase::NotificationListener implementation */ - virtual void notifyError(int errorCode, int arg1, int arg2); + virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode, + const CaptureResultExtras& resultExtras); virtual void notifyIdle(); - virtual void notifyShutter(int requestId, nsecs_t timestamp); + virtual void notifyShutter(const CaptureResultExtras& resultExtras, + nsecs_t timestamp); virtual void notifyAutoFocus(uint8_t newState, int triggerId); virtual void notifyAutoExposure(uint8_t newState, int triggerId); virtual void notifyAutoWhitebalance(uint8_t newState, @@ -73,6 +76,7 @@ public: int getCameraId() const; const sp<CameraDeviceBase>& getCameraDevice(); + int getCameraDeviceVersion() const; const sp<CameraService>& getCameraService(); @@ -103,6 +107,9 @@ public: protected: + // The PID provided in the constructor call + pid_t mInitialClientPid; + virtual sp<IBinder> asBinderWrapper() { return IInterface::asBinder(); } @@ -119,6 +126,7 @@ protected: /** CameraDeviceBase instance wrapping HAL2+ entry */ + const int mDeviceVersion; sp<CameraDeviceBase> mDevice; /** Utility members */ diff --git a/services/camera/libcameraservice/common/CameraDeviceBase.h b/services/camera/libcameraservice/common/CameraDeviceBase.h index e80abf1..d26e20c 100644 --- a/services/camera/libcameraservice/common/CameraDeviceBase.h +++ b/services/camera/libcameraservice/common/CameraDeviceBase.h @@ -22,9 +22,13 @@ #include <utils/String16.h> #include <utils/Vector.h> #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" +#include "camera/CaptureResult.h" namespace android { @@ -44,7 +48,7 @@ class CameraDeviceBase : public virtual RefBase { virtual status_t initialize(camera_module_t *module) = 0; virtual status_t disconnect() = 0; - virtual status_t dump(int fd, const Vector<String16>& args) = 0; + virtual status_t dump(int fd, const Vector<String16> &args) = 0; /** * The device's static characteristics metadata buffer @@ -54,19 +58,37 @@ class CameraDeviceBase : public virtual RefBase { /** * Submit request for capture. The CameraDevice takes ownership of the * passed-in buffer. + * Output lastFrameNumber is the expected frame number of this request. */ - virtual status_t capture(CameraMetadata &request) = 0; + virtual status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL) = 0; + + /** + * Submit a list of requests. + * Output lastFrameNumber is the expected last frame number of the list of requests. + */ + virtual status_t captureList(const List<const CameraMetadata> &requests, + int64_t *lastFrameNumber = NULL) = 0; /** * Submit request for streaming. The CameraDevice makes a copy of the * passed-in buffer and the caller retains ownership. + * Output lastFrameNumber is the last frame number of the previous streaming request. + */ + virtual status_t setStreamingRequest(const CameraMetadata &request, + int64_t *lastFrameNumber = NULL) = 0; + + /** + * Submit a list of requests for streaming. + * Output lastFrameNumber is the last frame number of the previous streaming request. */ - virtual status_t setStreamingRequest(const CameraMetadata &request) = 0; + virtual status_t setStreamingRequestList(const List<const CameraMetadata> &requests, + int64_t *lastFrameNumber = NULL) = 0; /** * Clear the streaming request slot. + * Output lastFrameNumber is the last frame number of the previous streaming request. */ - virtual status_t clearStreamingRequest() = 0; + virtual status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL) = 0; /** * Wait until a request with the given ID has been dequeued by the @@ -87,8 +109,7 @@ class CameraDeviceBase : public virtual RefBase { * other formats, the size parameter is ignored. */ virtual status_t createStream(sp<ANativeWindow> consumer, - uint32_t width, uint32_t height, int format, size_t size, - int *id) = 0; + uint32_t width, uint32_t height, int format, int *id) = 0; /** * Create an input reprocess stream that uses buffers from an existing @@ -120,6 +141,18 @@ class CameraDeviceBase : public virtual RefBase { virtual status_t deleteReprocessStream(int id) = 0; /** + * Take the currently-defined set of streams and configure the HAL to use + * them. This is a long-running operation (may be several hundered ms). + * + * The device must be idle (see waitUntilDrained) before calling this. + * + * Returns OK on success; otherwise on error: + * - BAD_VALUE if the set of streams was invalid (e.g. fmts or sizes) + * - INVALID_OPERATION if the device was in the wrong state + */ + virtual status_t configureStreams() = 0; + + /** * Create a metadata buffer with fields that the HAL device believes are * best for the given use case */ @@ -134,6 +167,12 @@ class CameraDeviceBase : public virtual RefBase { virtual status_t waitUntilDrained() = 0; /** + * Get Jpeg buffer size for a given jpeg resolution. + * Negative values are error codes. + */ + virtual ssize_t getJpegBufferSize(uint32_t width, uint32_t height) const = 0; + + /** * Abstract class for HAL notification listeners */ class NotificationListener { @@ -142,11 +181,12 @@ class CameraDeviceBase : public virtual RefBase { // API1 and API2. // Required for API 1 and 2 - virtual void notifyError(int errorCode, int arg1, int arg2) = 0; + virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode, + const CaptureResultExtras &resultExtras) = 0; // Required only for API2 virtual void notifyIdle() = 0; - virtual void notifyShutter(int requestId, + virtual void notifyShutter(const CaptureResultExtras &resultExtras, nsecs_t timestamp) = 0; // Required only for API1 @@ -179,11 +219,12 @@ class CameraDeviceBase : public virtual RefBase { virtual status_t waitForNextFrame(nsecs_t timeout) = 0; /** - * Get next metadata frame from the frame queue. Returns NULL if the queue - * is empty; caller takes ownership of the metadata buffer. - * May be called concurrently to most methods, except for waitForNextFrame + * Get next capture result frame from the result queue. Returns NOT_ENOUGH_DATA + * if the queue is empty; caller takes ownership of the metadata buffer inside + * the capture result object's metadata field. + * May be called concurrently to most methods, except for waitForNextFrame. */ - virtual status_t getNextFrame(CameraMetadata *frame) = 0; + virtual status_t getNextResult(CaptureResult *frame) = 0; /** * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel @@ -224,9 +265,14 @@ class CameraDeviceBase : public virtual RefBase { /** * Flush all pending and in-flight requests. Blocks until flush is * complete. + * Output lastFrameNumber is the last frame number of the previous streaming request. */ - virtual status_t flush() = 0; + virtual status_t flush(int64_t *lastFrameNumber = NULL) = 0; + /** + * Get the HAL device version. + */ + virtual uint32_t getDeviceVersion() = 0; }; }; // namespace android diff --git a/services/camera/libcameraservice/common/FrameProcessorBase.cpp b/services/camera/libcameraservice/common/FrameProcessorBase.cpp index 4d31667..29eb78f 100644 --- a/services/camera/libcameraservice/common/FrameProcessorBase.cpp +++ b/services/camera/libcameraservice/common/FrameProcessorBase.cpp @@ -29,7 +29,17 @@ namespace camera2 { FrameProcessorBase::FrameProcessorBase(wp<CameraDeviceBase> device) : Thread(/*canCallJava*/false), - mDevice(device) { + mDevice(device), + mNumPartialResults(1) { + sp<CameraDeviceBase> cameraDevice = device.promote(); + if (cameraDevice != 0 && + cameraDevice->getDeviceVersion() >= CAMERA_DEVICE_API_VERSION_3_2) { + CameraMetadata staticInfo = cameraDevice->info(); + camera_metadata_entry_t entry = staticInfo.find(ANDROID_REQUEST_PARTIAL_RESULT_COUNT); + if (entry.count > 0) { + mNumPartialResults = entry.data.i32[0]; + } + } } FrameProcessorBase::~FrameProcessorBase() { @@ -37,11 +47,23 @@ FrameProcessorBase::~FrameProcessorBase() { } status_t FrameProcessorBase::registerListener(int32_t minId, - int32_t maxId, wp<FilteredListener> listener, bool quirkSendPartials) { + int32_t maxId, wp<FilteredListener> listener, bool sendPartials) { Mutex::Autolock l(mInputMutex); + List<RangeListener>::iterator item = mRangeListeners.begin(); + while (item != mRangeListeners.end()) { + if (item->minId == minId && + item->maxId == maxId && + item->listener == listener) { + // already registered, just return + ALOGV("%s: Attempt to register the same client twice, ignoring", + __FUNCTION__); + return OK; + } + item++; + } ALOGV("%s: Registering listener for frame id range %d - %d", __FUNCTION__, minId, maxId); - RangeListener rListener = { minId, maxId, listener, quirkSendPartials }; + RangeListener rListener = { minId, maxId, listener, sendPartials }; mRangeListeners.push_back(rListener); return OK; } @@ -99,15 +121,17 @@ bool FrameProcessorBase::threadLoop() { void FrameProcessorBase::processNewFrames(const sp<CameraDeviceBase> &device) { status_t res; ATRACE_CALL(); - CameraMetadata frame; + CaptureResult result; ALOGV("%s: Camera %d: Process new frames", __FUNCTION__, device->getId()); - while ( (res = device->getNextFrame(&frame)) == OK) { + while ( (res = device->getNextResult(&result)) == OK) { + // TODO: instead of getting frame number from metadata, we should read + // this from result.mResultExtras when CameraDeviceBase interface is fixed. camera_metadata_entry_t entry; - entry = frame.find(ANDROID_REQUEST_FRAME_COUNT); + entry = result.mMetadata.find(ANDROID_REQUEST_FRAME_COUNT); if (entry.count == 0) { ALOGE("%s: Camera %d: Error reading frame number", __FUNCTION__, device->getId()); @@ -115,13 +139,13 @@ void FrameProcessorBase::processNewFrames(const sp<CameraDeviceBase> &device) { } ATRACE_INT("cam2_frame", entry.data.i32[0]); - if (!processSingleFrame(frame, device)) { + if (!processSingleFrame(result, device)) { break; } - if (!frame.isEmpty()) { + if (!result.mMetadata.isEmpty()) { Mutex::Autolock al(mLastFrameMutex); - mLastFrame.acquire(frame); + mLastFrame.acquire(result.mMetadata); } } if (res != NOT_ENOUGH_DATA) { @@ -133,32 +157,40 @@ void FrameProcessorBase::processNewFrames(const sp<CameraDeviceBase> &device) { return; } -bool FrameProcessorBase::processSingleFrame(CameraMetadata &frame, - const sp<CameraDeviceBase> &device) { +bool FrameProcessorBase::processSingleFrame(CaptureResult &result, + const sp<CameraDeviceBase> &device) { ALOGV("%s: Camera %d: Process single frame (is empty? %d)", - __FUNCTION__, device->getId(), frame.isEmpty()); - return processListeners(frame, device) == OK; + __FUNCTION__, device->getId(), result.mMetadata.isEmpty()); + return processListeners(result, device) == OK; } -status_t FrameProcessorBase::processListeners(const CameraMetadata &frame, +status_t FrameProcessorBase::processListeners(const CaptureResult &result, const sp<CameraDeviceBase> &device) { ATRACE_CALL(); + camera_metadata_ro_entry_t entry; - // Quirks: Don't deliver partial results to listeners that don't want them - bool quirkIsPartial = false; - entry = frame.find(ANDROID_QUIRKS_PARTIAL_RESULT); - if (entry.count != 0 && - entry.data.u8[0] == ANDROID_QUIRKS_PARTIAL_RESULT_PARTIAL) { - ALOGV("%s: Camera %d: Not forwarding partial result to listeners", - __FUNCTION__, device->getId()); - quirkIsPartial = true; + // Check if this result is partial. + bool isPartialResult = false; + if (device->getDeviceVersion() >= CAMERA_DEVICE_API_VERSION_3_2) { + isPartialResult = result.mResultExtras.partialResultCount < mNumPartialResults; + } else { + entry = result.mMetadata.find(ANDROID_QUIRKS_PARTIAL_RESULT); + if (entry.count != 0 && + entry.data.u8[0] == ANDROID_QUIRKS_PARTIAL_RESULT_PARTIAL) { + ALOGV("%s: Camera %d: This is a partial result", + __FUNCTION__, device->getId()); + isPartialResult = true; + } } - entry = frame.find(ANDROID_REQUEST_ID); + // TODO: instead of getting requestID from CameraMetadata, we should get it + // from CaptureResultExtras. This will require changing Camera2Device. + // Currently Camera2Device uses MetadataQueue to store results, which does not + // include CaptureResultExtras. + entry = result.mMetadata.find(ANDROID_REQUEST_ID); if (entry.count == 0) { - ALOGE("%s: Camera %d: Error reading frame id", - __FUNCTION__, device->getId()); + ALOGE("%s: Camera %d: Error reading frame id", __FUNCTION__, device->getId()); return BAD_VALUE; } int32_t requestId = entry.data.i32[0]; @@ -168,10 +200,10 @@ status_t FrameProcessorBase::processListeners(const CameraMetadata &frame, Mutex::Autolock l(mInputMutex); List<RangeListener>::iterator item = mRangeListeners.begin(); + // Don't deliver partial results to listeners that don't want them while (item != mRangeListeners.end()) { - if (requestId >= item->minId && - requestId < item->maxId && - (!quirkIsPartial || item->quirkSendPartials) ) { + if (requestId >= item->minId && requestId < item->maxId && + (!isPartialResult || item->sendPartials)) { sp<FilteredListener> listener = item->listener.promote(); if (listener == 0) { item = mRangeListeners.erase(item); @@ -183,10 +215,12 @@ status_t FrameProcessorBase::processListeners(const CameraMetadata &frame, item++; } } - ALOGV("Got %zu range listeners out of %zu", listeners.size(), mRangeListeners.size()); + ALOGV("%s: Camera %d: Got %zu range listeners out of %zu", __FUNCTION__, + device->getId(), listeners.size(), mRangeListeners.size()); + List<sp<FilteredListener> >::iterator item = listeners.begin(); for (; item != listeners.end(); item++) { - (*item)->onFrameAvailable(requestId, frame); + (*item)->onResultAvailable(result); } return OK; } diff --git a/services/camera/libcameraservice/common/FrameProcessorBase.h b/services/camera/libcameraservice/common/FrameProcessorBase.h index 89b608a..a618d84 100644 --- a/services/camera/libcameraservice/common/FrameProcessorBase.h +++ b/services/camera/libcameraservice/common/FrameProcessorBase.h @@ -23,6 +23,7 @@ #include <utils/KeyedVector.h> #include <utils/List.h> #include <camera/CameraMetadata.h> +#include <camera/CaptureResult.h> namespace android { @@ -39,16 +40,16 @@ class FrameProcessorBase: public Thread { virtual ~FrameProcessorBase(); struct FilteredListener: virtual public RefBase { - virtual void onFrameAvailable(int32_t requestId, - const CameraMetadata &frame) = 0; + virtual void onResultAvailable(const CaptureResult &result) = 0; }; // Register a listener for a range of IDs [minId, maxId). Multiple listeners - // can be listening to the same range. - // QUIRK: sendPartials controls whether partial results will be sent. + // can be listening to the same range. Registering the same listener with + // the same range of IDs has no effect. + // sendPartials controls whether partial results will be sent. status_t registerListener(int32_t minId, int32_t maxId, wp<FilteredListener> listener, - bool quirkSendPartials = true); + bool sendPartials = true); status_t removeListener(int32_t minId, int32_t maxId, wp<FilteredListener> listener); @@ -66,16 +67,19 @@ class FrameProcessorBase: public Thread { int32_t minId; int32_t maxId; wp<FilteredListener> listener; - bool quirkSendPartials; + bool sendPartials; }; List<RangeListener> mRangeListeners; + // Number of partial result the HAL will potentially send. + int32_t mNumPartialResults; + void processNewFrames(const sp<CameraDeviceBase> &device); - virtual bool processSingleFrame(CameraMetadata &frame, + virtual bool processSingleFrame(CaptureResult &result, const sp<CameraDeviceBase> &device); - status_t processListeners(const CameraMetadata &frame, + status_t processListeners(const CaptureResult &result, const sp<CameraDeviceBase> &device); CameraMetadata mLastFrame; |