From a140a6efea1db7837984b3578755cfa4eaa8d92d Mon Sep 17 00:00:00 2001 From: Igor Murashkin Date: Thu, 21 Feb 2013 14:45:03 -0800 Subject: ProCamera: add waitForFrameBuffer/waitForFrameResult blocking calls Change-Id: I851d41aeecaa15245d5b9d622132e8706d6e292c --- include/camera/ProCamera.h | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'include/camera') diff --git a/include/camera/ProCamera.h b/include/camera/ProCamera.h index 11904f9..f813c1c 100644 --- a/include/camera/ProCamera.h +++ b/include/camera/ProCamera.h @@ -24,8 +24,12 @@ #include #include #include +#include #include +#include +#include + struct camera_metadata; namespace android { @@ -62,6 +66,20 @@ public: * free_camera_metadata. */ virtual void onResultReceived(int32_t frameId, camera_metadata* result) = 0; + + + // A new frame buffer has been received for this stream. + // -- This callback only fires for createStreamCpu streams + // -- Use buf.timestamp to correlate with metadata's android.sensor.timestamp + // -- The buffer should be accessed with CpuConsumer::lockNextBuffer + // and CpuConsumer::unlockBuffer + virtual void onFrameAvailable(int streamId, + const sp& cpuConsumer) { + } + + virtual bool useOnFrameAvailable() { + return false; + } }; class ProCamera : public BnProCameraCallbacks, public IBinder::DeathRecipient @@ -161,6 +179,7 @@ public: status_t createStreamCpu(int width, int height, int format, int heapCount, /*out*/ + sp* cpuConsumer, int* streamId); // Create a request object from a template. @@ -174,6 +193,24 @@ public: // Get static camera metadata camera_metadata* getCameraInfo(int cameraId); + // Blocks until a frame is available (CPU streams only) + // - Obtain the frame data by calling CpuConsumer::lockNextBuffer + // - Release the frame data after use with CpuConsumer::unlockBuffer + // Error codes: + // -ETIMEDOUT if it took too long to get a frame + status_t waitForFrameBuffer(int streamId); + + // Blocks until a metadata result is available + // - Obtain the metadata by calling consumeFrameMetadata() + // Error codes: + // -ETIMEDOUT if it took too long to get a frame + status_t waitForFrameMetadata(); + + // Get the latest metadata. This is destructive. + // - Calling this repeatedly will produce empty metadata objects. + // - Use waitForFrameMetadata to sync until new data is available. + CameraMetadata consumeFrameMetadata(); + sp remote(); protected: @@ -249,6 +286,7 @@ private: StreamInfo(int streamId) { this->streamID = streamId; cpuStream = false; + frameReady = false; } StreamInfo() { @@ -261,10 +299,15 @@ private: sp cpuConsumer; sp frameAvailableListener; sp stc; + bool frameReady; }; + Condition mWaitCondition; + Mutex mWaitMutex; + static const nsecs_t mWaitTimeout = 1000000000; // 1sec KeyedVector mStreams; - + bool mMetadataReady; + CameraMetadata mLatestMetadata; void onFrameAvailable(int streamId); -- cgit v1.1