From 366eef524c35fa9500e9ad7b9335154eaf018baf Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Thu, 17 May 2012 17:58:33 -0700 Subject: [PATCH] EmulatedCamera2: Be more const, like the HAL. Bug: 6243944 Change-Id: I01f67c22b6e54dc49f22c6bc2c665b1db4ff6680 --- .../system/camera/EmulatedCamera2.cpp | 85 +++++++++---------- .../emulator/system/camera/EmulatedCamera2.h | 46 +++++----- .../system/camera/EmulatedFakeCamera2.cpp | 2 +- .../system/camera/EmulatedFakeCamera2.h | 6 +- 4 files changed, 69 insertions(+), 70 deletions(-) diff --git a/tools/emulator/system/camera/EmulatedCamera2.cpp b/tools/emulator/system/camera/EmulatedCamera2.cpp index 4106639e4..1634b2f6b 100644 --- a/tools/emulator/system/camera/EmulatedCamera2.cpp +++ b/tools/emulator/system/camera/EmulatedCamera2.cpp @@ -129,7 +129,7 @@ int EmulatedCamera2::allocateStream( uint32_t width, uint32_t height, int format, - camera2_stream_ops_t *stream_ops, + const camera2_stream_ops_t *stream_ops, uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, @@ -155,7 +155,7 @@ int EmulatedCamera2::allocateReprocessStream( uint32_t width, uint32_t height, uint32_t format, - camera2_stream_in_ops_t *reprocess_stream_ops, + const camera2_stream_in_ops_t *reprocess_stream_ops, uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers) { @@ -205,114 +205,114 @@ int EmulatedCamera2::dump(int fd) { * 'camera_device2' parameter, or set a member value in the same. ***************************************************************************/ -int EmulatedCamera2::set_request_queue_src_ops(struct camera2_device *d, - camera2_request_queue_src_ops *queue_src_ops) { - EmulatedCamera2* ec = static_cast(d); +EmulatedCamera2* getInstance(const camera2_device_t *d) { + const EmulatedCamera2* cec = static_cast(d); + return const_cast(cec); +} + +int EmulatedCamera2::set_request_queue_src_ops(const camera2_device_t *d, + const camera2_request_queue_src_ops *queue_src_ops) { + EmulatedCamera2* ec = getInstance(d); ec->mRequestQueueSrc = queue_src_ops; return NO_ERROR; } -int EmulatedCamera2::notify_request_queue_not_empty(struct camera2_device *d) { - EmulatedCamera2* ec = static_cast(d); +int EmulatedCamera2::notify_request_queue_not_empty(const camera2_device_t *d) { + EmulatedCamera2* ec = getInstance(d); return ec->requestQueueNotify(); } -int EmulatedCamera2::set_frame_queue_dst_ops(struct camera2_device *d, - camera2_frame_queue_dst_ops *queue_dst_ops) { - EmulatedCamera2* ec = static_cast(d); +int EmulatedCamera2::set_frame_queue_dst_ops(const camera2_device_t *d, + const camera2_frame_queue_dst_ops *queue_dst_ops) { + EmulatedCamera2* ec = getInstance(d); ec->mFrameQueueDst = queue_dst_ops; return NO_ERROR; } -int EmulatedCamera2::get_in_progress_count(struct camera2_device *d) { - EmulatedCamera2* ec = static_cast(d); +int EmulatedCamera2::get_in_progress_count(const camera2_device_t *d) { + EmulatedCamera2* ec = getInstance(d); return ec->getInProgressCount(); } -int EmulatedCamera2::flush_captures_in_progress(struct camera2_device *d) { - EmulatedCamera2* ec = static_cast(d); +int EmulatedCamera2::flush_captures_in_progress(const camera2_device_t *d) { + EmulatedCamera2* ec = getInstance(d); return ec->flushCapturesInProgress(); } -int EmulatedCamera2::construct_default_request(struct camera2_device *d, +int EmulatedCamera2::construct_default_request(const camera2_device_t *d, int request_template, camera_metadata_t **request) { - EmulatedCamera2* ec = static_cast(d); + EmulatedCamera2* ec = getInstance(d); return ec->constructDefaultRequest(request_template, request); } -int EmulatedCamera2::allocate_stream(struct camera2_device *d, +int EmulatedCamera2::allocate_stream(const camera2_device_t *d, uint32_t width, uint32_t height, int format, - camera2_stream_ops_t *stream_ops, + const camera2_stream_ops_t *stream_ops, uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, uint32_t *max_buffers) { - EmulatedCamera2* ec = - static_cast(d); + EmulatedCamera2* ec = getInstance(d); return ec->allocateStream(width, height, format, stream_ops, stream_id, format_actual, usage, max_buffers); } -int EmulatedCamera2::register_stream_buffers(struct camera2_device *d, +int EmulatedCamera2::register_stream_buffers(const camera2_device_t *d, uint32_t stream_id, int num_buffers, buffer_handle_t *buffers) { - EmulatedCamera2* ec = - static_cast(d); + EmulatedCamera2* ec = getInstance(d); return ec->registerStreamBuffers(stream_id, num_buffers, buffers); } -int EmulatedCamera2::release_stream(struct camera2_device *d, +int EmulatedCamera2::release_stream(const camera2_device_t *d, uint32_t stream_id) { - EmulatedCamera2* ec = - static_cast(d); + EmulatedCamera2* ec = getInstance(d); return ec->releaseStream(stream_id); } -int EmulatedCamera2::allocate_reprocess_stream(struct camera2_device *d, +int EmulatedCamera2::allocate_reprocess_stream(const camera2_device_t *d, uint32_t width, uint32_t height, uint32_t format, - camera2_stream_in_ops_t *reprocess_stream_ops, + const camera2_stream_in_ops_t *reprocess_stream_ops, uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers) { - EmulatedCamera2* ec = - static_cast(d); + EmulatedCamera2* ec = getInstance(d); return ec->allocateReprocessStream(width, height, format, reprocess_stream_ops, stream_id, consumer_usage, max_buffers); } -int EmulatedCamera2::release_reprocess_stream(struct camera2_device *d, +int EmulatedCamera2::release_reprocess_stream(const camera2_device_t *d, uint32_t stream_id) { - EmulatedCamera2* ec = - static_cast(d); + EmulatedCamera2* ec = getInstance(d); return ec->releaseReprocessStream(stream_id); } -int EmulatedCamera2::trigger_action(camera2_device_t *d, +int EmulatedCamera2::trigger_action(const camera2_device_t *d, uint32_t trigger_id, int ext1, int ext2) { - EmulatedCamera2* ec = static_cast(d); + EmulatedCamera2* ec = getInstance(d); return ec->triggerAction(trigger_id, ext1, ext2); } -int EmulatedCamera2::set_notify_callback(struct camera2_device *d, +int EmulatedCamera2::set_notify_callback(const camera2_device_t *d, camera2_notify_callback notify_cb, void* user) { - EmulatedCamera2* ec = static_cast(d); + EmulatedCamera2* ec = getInstance(d); ec->mNotifyCb = notify_cb; ec->mNotifyUserPtr = user; return NO_ERROR; } -int EmulatedCamera2::get_metadata_vendor_tag_ops(struct camera2_device *d, +int EmulatedCamera2::get_metadata_vendor_tag_ops(const camera2_device_t *d, vendor_tag_query_ops_t **ops) { - EmulatedCamera2* ec = static_cast(d); + EmulatedCamera2* ec = getInstance(d); *ops = static_cast( &ec->mVendorTagOps); return NO_ERROR; @@ -339,16 +339,15 @@ int EmulatedCamera2::get_camera_vendor_tag_type( return ec->getVendorTagType(tag); } -int EmulatedCamera2::dump(struct camera2_device *d, int fd) { - EmulatedCamera2* ec = - static_cast(d); +int EmulatedCamera2::dump(const camera2_device_t *d, int fd) { + EmulatedCamera2* ec = getInstance(d); return ec->dump(fd); } int EmulatedCamera2::close(struct hw_device_t* device) { EmulatedCamera2* ec = static_cast( - reinterpret_cast(device) ); + reinterpret_cast(device) ); if (ec == NULL) { ALOGE("%s: Unexpected NULL camera2 device", __FUNCTION__); return -EINVAL; diff --git a/tools/emulator/system/camera/EmulatedCamera2.h b/tools/emulator/system/camera/EmulatedCamera2.h index 17082b789..2c813a41d 100644 --- a/tools/emulator/system/camera/EmulatedCamera2.h +++ b/tools/emulator/system/camera/EmulatedCamera2.h @@ -101,7 +101,7 @@ protected: uint32_t width, uint32_t height, int format, - camera2_stream_ops_t *stream_ops, + const camera2_stream_ops_t *stream_ops, uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, @@ -119,7 +119,7 @@ protected: uint32_t width, uint32_t height, uint32_t format, - camera2_stream_in_ops_t *reprocess_stream_ops, + const camera2_stream_in_ops_t *reprocess_stream_ops, uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers); @@ -149,68 +149,68 @@ protected: private: /** Input request queue */ - static int set_request_queue_src_ops(camera2_device_t *, - camera2_request_queue_src_ops *queue_src_ops); - static int notify_request_queue_not_empty(camera2_device_t *); + static int set_request_queue_src_ops(const camera2_device_t *, + const camera2_request_queue_src_ops *queue_src_ops); + static int notify_request_queue_not_empty(const camera2_device_t *); /** Output frame queue */ - static int set_frame_queue_dst_ops(camera2_device_t *, - camera2_frame_queue_dst_ops *queue_dst_ops); + static int set_frame_queue_dst_ops(const camera2_device_t *, + const camera2_frame_queue_dst_ops *queue_dst_ops); /** In-progress request management */ - static int get_in_progress_count(camera2_device_t *); + static int get_in_progress_count(const camera2_device_t *); - static int flush_captures_in_progress(camera2_device_t *); + static int flush_captures_in_progress(const camera2_device_t *); /** Request template creation */ - static int construct_default_request(camera2_device_t *, + static int construct_default_request(const camera2_device_t *, int request_template, camera_metadata_t **request); /** Stream management */ - static int allocate_stream(camera2_device_t *, + static int allocate_stream(const camera2_device_t *, uint32_t width, uint32_t height, int format, - camera2_stream_ops_t *stream_ops, + const camera2_stream_ops_t *stream_ops, uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, uint32_t *max_buffers); - static int register_stream_buffers(camera2_device_t *, + static int register_stream_buffers(const camera2_device_t *, uint32_t stream_id, int num_buffers, buffer_handle_t *buffers); - static int release_stream(camera2_device_t *, + static int release_stream(const camera2_device_t *, uint32_t stream_id); - static int allocate_reprocess_stream(camera2_device_t *, + static int allocate_reprocess_stream(const camera2_device_t *, uint32_t width, uint32_t height, uint32_t format, - camera2_stream_in_ops_t *reprocess_stream_ops, + const camera2_stream_in_ops_t *reprocess_stream_ops, uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers); - static int release_reprocess_stream(camera2_device_t *, + static int release_reprocess_stream(const camera2_device_t *, uint32_t stream_id); /** 3A triggers*/ - static int trigger_action(camera2_device_t *, + static int trigger_action(const camera2_device_t *, uint32_t trigger_id, int ext1, int ext2); /** Notifications to application */ - static int set_notify_callback(camera2_device_t *, + static int set_notify_callback(const camera2_device_t *, camera2_notify_callback notify_cb, void *user); /** Vendor metadata registration */ - static int get_metadata_vendor_tag_ops(camera2_device_t *, + static int get_metadata_vendor_tag_ops(const camera2_device_t *, vendor_tag_query_ops_t **ops); // for get_metadata_vendor_tag_ops static const char* get_camera_vendor_section_name( @@ -223,7 +223,7 @@ private: const vendor_tag_query_ops_t *, uint32_t tag); - static int dump(camera2_device_t *, int fd); + static int dump(const camera2_device_t *, int fd); /** For hw_device_t ops */ static int close(struct hw_device_t* device); @@ -232,8 +232,8 @@ private: * Data members shared with implementations ***************************************************************************/ protected: - camera2_request_queue_src_ops *mRequestQueueSrc; - camera2_frame_queue_dst_ops *mFrameQueueDst; + const camera2_request_queue_src_ops *mRequestQueueSrc; + const camera2_frame_queue_dst_ops *mFrameQueueDst; camera2_notify_callback mNotifyCb; void* mNotifyUserPtr; diff --git a/tools/emulator/system/camera/EmulatedFakeCamera2.cpp b/tools/emulator/system/camera/EmulatedFakeCamera2.cpp index c75a26b99..bd4c579a9 100644 --- a/tools/emulator/system/camera/EmulatedFakeCamera2.cpp +++ b/tools/emulator/system/camera/EmulatedFakeCamera2.cpp @@ -600,7 +600,7 @@ int EmulatedFakeCamera2::allocateStream( uint32_t width, uint32_t height, int format, - camera2_stream_ops_t *stream_ops, + const camera2_stream_ops_t *stream_ops, uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, diff --git a/tools/emulator/system/camera/EmulatedFakeCamera2.h b/tools/emulator/system/camera/EmulatedFakeCamera2.h index 18f8ebc60..1f0199c91 100644 --- a/tools/emulator/system/camera/EmulatedFakeCamera2.h +++ b/tools/emulator/system/camera/EmulatedFakeCamera2.h @@ -83,7 +83,7 @@ protected: uint32_t width, uint32_t height, int format, - camera2_stream_ops_t *stream_ops, + const camera2_stream_ops_t *stream_ops, uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, @@ -100,7 +100,7 @@ protected: // uint32_t width, // uint32_t height, // uint32_t format, - // camera2_stream_ops_t *stream_ops, + // const camera2_stream_ops_t *stream_ops, // uint32_t *stream_id, // uint32_t *format_actual, // uint32_t *usage, @@ -238,7 +238,7 @@ private: /** Stream manipulation */ uint32_t mNextStreamId; - camera2_stream_ops_t *mRawStreamOps; + const camera2_stream_ops_t *mRawStreamOps; /** Simulated hardware interfaces */ sp mSensor;