2 * Copyright (C) 2011 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef HW_EMULATOR_CAMERA_CALLBACK_NOTIFIER_H
18 #define HW_EMULATOR_CAMERA_CALLBACK_NOTIFIER_H
21 * Contains declaration of a class CallbackNotifier that manages callbacks set
22 * via set_callbacks, enable_msg_type, and disable_msg_type camera HAL API.
25 #include <utils/List.h>
29 class EmulatedCameraDevice;
31 /* Manages callbacks set via set_callbacks, enable_msg_type, and disable_msg_type
34 * Objects of this class are contained in EmulatedCamera objects, and handle
35 * relevant camera API callbacks.
36 * Locking considerations. Apparently, it's not allowed to call callbacks
37 * registered in this class, while holding a lock: recursion is quite possible,
38 * which will cause a deadlock.
40 class CallbackNotifier {
42 /* Constructs CallbackNotifier instance. */
45 /* Destructs CallbackNotifier instance. */
48 /****************************************************************************
50 ***************************************************************************/
53 /* Actual handler for camera_device_ops_t::set_callbacks callback.
54 * This method is called by the containing emulated camera object when it is
55 * handing the camera_device_ops_t::set_callbacks callback.
57 void setCallbacks(camera_notify_callback notify_cb,
58 camera_data_callback data_cb,
59 camera_data_timestamp_callback data_cb_timestamp,
60 camera_request_memory get_memory,
63 /* Actual handler for camera_device_ops_t::enable_msg_type callback.
64 * This method is called by the containing emulated camera object when it is
65 * handing the camera_device_ops_t::enable_msg_type callback.
67 void enableMessage(uint msg_type);
69 /* Actual handler for camera_device_ops_t::disable_msg_type callback.
70 * This method is called by the containing emulated camera object when it is
71 * handing the camera_device_ops_t::disable_msg_type callback.
73 void disableMessage(uint msg_type);
75 /* Actual handler for camera_device_ops_t::store_meta_data_in_buffers
76 * callback. This method is called by the containing emulated camera object
77 * when it is handing the camera_device_ops_t::store_meta_data_in_buffers
80 * NO_ERROR on success, or an appropriate error status.
82 status_t storeMetaDataInBuffers(bool enable);
84 /* Enables video recording.
85 * This method is called by the containing emulated camera object when it is
86 * handing the camera_device_ops_t::start_recording callback.
88 * fps - Video frame frequency. This parameter determins when a frame
89 * received via onNextFrameAvailable call will be pushed through the
92 * NO_ERROR on success, or an appropriate error status.
94 status_t enableVideoRecording(int fps);
96 /* Disables video recording.
97 * This method is called by the containing emulated camera object when it is
98 * handing the camera_device_ops_t::stop_recording callback.
100 void disableVideoRecording();
102 /* Releases video frame, sent to the framework.
103 * This method is called by the containing emulated camera object when it is
104 * handing the camera_device_ops_t::release_recording_frame callback.
106 void releaseRecordingFrame(const void* opaque);
108 /* Actual handler for camera_device_ops_t::msg_type_enabled callback.
109 * This method is called by the containing emulated camera object when it is
110 * handing the camera_device_ops_t::msg_type_enabled callback.
111 * Note: this method doesn't grab a lock while checking message status, since
112 * upon exit the status would be undefined anyway. So, grab a lock before
113 * calling this method if you care about persisting a defined message status.
115 * 0 if message is disabled, or non-zero value, if message is enabled.
117 inline int isMessageEnabled(uint msg_type)
119 return mMessageEnabler & msg_type;
122 /* Checks id video recording is enabled.
123 * This method is called by the containing emulated camera object when it is
124 * handing the camera_device_ops_t::recording_enabled callback.
125 * Note: this method doesn't grab a lock while checking video recordin status,
126 * since upon exit the status would be undefined anyway. So, grab a lock
127 * before calling this method if you care about persisting of a defined video
130 * true if video recording is enabled, or false if it is disabled.
132 inline bool isVideoRecordingEnabled()
134 return mVideoRecEnabled;
137 /****************************************************************************
139 ***************************************************************************/
142 /* Resets the callback notifier. */
143 void cleanupCBNotifier();
145 /* Next frame is available in the camera device.
146 * This is a notification callback that is invoked by the camera device when
147 * a new frame is available.
148 * Note that most likely this method is called in context of a worker thread
149 * that camera device has created for frame capturing.
151 * frame - Captured frame, or NULL if camera device didn't pull the frame
152 * yet. If NULL is passed in this parameter use GetCurrentFrame method
153 * of the camera device class to obtain the next frame. Also note that
154 * the size of the frame that is passed here (as well as the frame
155 * returned from the GetCurrentFrame method) is defined by the current
156 * frame settings (width + height + pixel format) for the camera device.
157 * timestamp - Frame's timestamp.
158 * camera_dev - Camera device instance that delivered the frame.
160 void onNextFrameAvailable(const void* frame,
162 EmulatedCameraDevice* camera_dev);
164 /* Entry point for notifications that occur in camera device.
166 * err - CAMERA_ERROR_XXX error code.
168 void onCameraDeviceError(int err);
170 /* Sets, or resets taking picture state.
171 * This state control whether or not to notify the framework about compressed
172 * image, shutter, and other picture related events.
174 void setTakingPicture(bool taking)
176 mTakingPicture = taking;
179 /* Sets JPEG quality used to compress frame during picture taking. */
180 void setJpegQuality(int jpeg_quality)
182 mJpegQuality = jpeg_quality;
185 /****************************************************************************
187 ***************************************************************************/
190 /* Checks if it's time to push new video frame.
191 * Note that this method must be called while object is locked.
193 * timestamp - Timestamp for the new frame. */
194 bool isNewVideoFrameTime(nsecs_t timestamp);
196 /****************************************************************************
198 ***************************************************************************/
201 /* Locks this instance for data change. */
205 * Callbacks, registered in set_callbacks.
208 camera_notify_callback mNotifyCB;
209 camera_data_callback mDataCB;
210 camera_data_timestamp_callback mDataCBTimestamp;
211 camera_request_memory mGetMemoryCB;
214 /* video frame queue for the CameraHeapMemory destruction */
215 List<camera_memory_t*> mCameraMemoryTs;
217 /* Timestamp when last frame has been delivered to the framework. */
218 nsecs_t mLastFrameTimestamp;
220 /* Video frequency in nanosec. */
221 nsecs_t mFrameRefreshFreq;
223 /* Message enabler. */
224 uint32_t mMessageEnabler;
226 /* JPEG quality used to compress frame during picture taking. */
229 /* Video recording status. */
230 bool mVideoRecEnabled;
232 /* Picture taking status. */
236 }; /* namespace android */
238 #endif /* HW_EMULATOR_CAMERA_CALLBACK_NOTIFIER_H */