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_PREVIEW_WINDOW_H
18 #define HW_EMULATOR_CAMERA_PREVIEW_WINDOW_H
21 * Contains declaration of a class PreviewWindow that encapsulates functionality
22 * of a preview window set via set_preview_window camera HAL API.
27 class EmulatedCameraDevice;
29 /* Encapsulates functionality of a preview window set via set_preview_window
32 * Objects of this class are contained in EmulatedCamera objects, and handle
33 * relevant camera API callbacks.
37 /* Constructs PreviewWindow instance. */
40 /* Destructs PreviewWindow instance. */
43 /***************************************************************************
45 **************************************************************************/
48 /* Actual handler for camera_device_ops_t::set_preview_window callback.
49 * This method is called by the containing emulated camera object when it is
50 * handing the camera_device_ops_t::set_preview_window callback.
52 * window - Preview window to set. This parameter might be NULL, which
53 * indicates preview window reset.
54 * preview_fps - Preview's frame frequency. This parameter determins when
55 * a frame received via onNextFrameAvailable call will be pushed to
56 * the preview window. If 'window' parameter passed to this method is
57 * NULL, this parameter is ignored.
59 * NO_ERROR on success, or an appropriate error status.
61 status_t setPreviewWindow(struct preview_stream_ops* window,
64 /* Starts the preview.
65 * This method is called by the containing emulated camera object when it is
66 * handing the camera_device_ops_t::start_preview callback.
68 status_t startPreview();
71 * This method is called by the containing emulated camera object when it is
72 * handing the camera_device_ops_t::start_preview callback.
76 /* Checks if preview is enabled. */
77 inline bool isPreviewEnabled()
79 return mPreviewEnabled;
82 /****************************************************************************
84 ***************************************************************************/
87 /* Next frame is available in the camera device.
88 * This is a notification callback that is invoked by the camera device when
89 * a new frame is available.
90 * Note that most likely this method is called in context of a worker thread
91 * that camera device has created for frame capturing.
93 * frame - Captured frame, or NULL if camera device didn't pull the frame
94 * yet. If NULL is passed in this parameter use GetCurrentFrame method
95 * of the camera device class to obtain the next frame. Also note that
96 * the size of the frame that is passed here (as well as the frame
97 * returned from the GetCurrentFrame method) is defined by the current
98 * frame settings (width + height + pixel format) for the camera device.
99 * timestamp - Frame's timestamp.
100 * camera_dev - Camera device instance that delivered the frame.
102 void onNextFrameAvailable(const void* frame,
104 EmulatedCameraDevice* camera_dev);
106 /***************************************************************************
108 **************************************************************************/
111 /* Adjusts cached dimensions of the preview window frame according to the
112 * frame dimensions used by the camera device.
114 * When preview is started, it's not known (hard to define) what are going
115 * to be the dimensions of the frames that are going to be displayed. Plus,
116 * it might be possible, that such dimensions can be changed on the fly. So,
117 * in order to be always in sync with frame dimensions, this method is
118 * called for each frame passed to onNextFrameAvailable method, in order to
119 * properly adjust frame dimensions, used by the preview window.
120 * Note that this method must be called while object is locked.
122 * camera_dev - Camera device, prpviding frames displayed in the preview
125 * true if cached dimensions have been adjusted, or false if cached
126 * dimensions match device's frame dimensions.
128 bool adjustPreviewDimensions(EmulatedCameraDevice* camera_dev);
130 /* Checks if it's the time to push new frame to the preview window.
131 * Note that this method must be called while object is locked. */
132 bool isPreviewTime();
134 /***************************************************************************
136 **************************************************************************/
139 /* Locks this instance for data changes. */
142 /* Preview window instance. */
143 preview_stream_ops* mPreviewWindow;
145 /* Timestamp (abs. microseconds) when last frame has been pushed to the
147 uint64_t mLastPreviewed;
149 /* Preview frequency in microseconds. */
150 uint32_t mPreviewAfter;
153 * Cached preview window frame dimensions.
156 int mPreviewFrameWidth;
157 int mPreviewFrameHeight;
159 /* Preview status. */
160 bool mPreviewEnabled;
163 }; /* namespace android */
165 #endif /* HW_EMULATOR_CAMERA_PREVIEW_WINDOW_H */