Tizen 2.0 Release
[framework/osp/media.git] / src / FMedia_CameraCoordinator.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                        FMedia_CameraCoordinator.h
20  * @brief                       This header file contains the declarations of the %_CameraCoordinator class.
21  *
22  */
23
24 #ifndef _FMEDIA_INTERNAL_CAMERA_COORDINATOR_H_
25 #define _FMEDIA_INTERNAL_CAMERA_COORDINATOR_H_
26
27 #include <camera.h>
28 #include <recorder.h>
29 #include <FBaseColLinkedListT.h>
30 #include <FBaseColHashMapT.h>
31 #include <FMediaCameraTypes.h>
32 #include <FMediaRecorderTypes.h>
33 #include "FMedia_CameraTypes.h"
34 #include "FMedia_RecorderTypes.h"
35 #include "FMedia_CameraRefHelper.h"
36
37 namespace Tizen { namespace Media
38 {
39 class _ICameraCoordinatorListener;
40 class _CameraCoordinatorSafeHashMapT;
41
42 /**
43  * @class       _CameraCoordinator
44  * @brief       This class implements the _CameraCoordinator class.
45  *
46  */
47 class _CameraCoordinator
48         : public _CameraRefHelper
49 {
50 public:
51         /**
52         * Get the instance of _CameraCoordinator.
53         *
54         * @return               The _CameraCoordinator instance
55         * @param[in]    cameraDevice                    The camera device id.
56         * @exception    E_SUCCESS                               The method is successful.
57         * @exception    E_SYSTEM                                A system error has occurred.
58         * @exception    E_DEVICE_BUSY                   The device cannot be approached because of other operations.
59         * @exception    E_DEVICE_UNAVAILABLE    The device is unavailable.
60         */
61         static _CameraCoordinator* AddInstance(_CameraDeviceType cameraDevice);
62
63         /**
64         * Get the instance of _CameraCoordinator.
65         *
66         * @return               The _CameraCoordinator instance
67         * @param[in]    recorderDevice                  The recorder device id.
68         * @exception    E_SUCCESS                               The method is successful.
69         * @exception    E_SYSTEM                                A system error has occurred.
70         * @exception    E_DEVICE_BUSY                   The device cannot be approached because of other operations.
71         * @exception    E_DEVICE_UNAVAILABLE    The device is unavailable.
72         */
73         static _CameraCoordinator* AddInstance(_RecorderDeviceType recorderDevice);
74
75         /**
76         * Release the specific _CameraCoordinator.
77         *
78         * @param[in]    cameraDevice                    The camera device type
79         */
80         static void Release(_CameraDeviceType cameraDevice);
81
82         /**
83         * Release the specific _CameraCoordinator.
84         *
85         * @param[in]    recorderDevice                  The recorder device type
86         */
87         static void Release(_RecorderDeviceType recorderDevice);
88
89         /**
90         * Check whether it has the instance.
91         *
92         * @return               The _CameraCoordinator instance
93         * @param[in]    cameraDevice                    The camera device id.
94         * @exception    E_SUCCESS                               The method is successful.
95         * @exception    E_SYSTEM                                A system error has occurred.
96         * @exception    E_DEVICE_BUSY                   The device cannot be approached because of other operations.
97         * @exception    E_DEVICE_UNAVAILABLE    The device is unavailable.
98         */
99         static _CameraCoordinator* HasInstance(_CameraDeviceType cameraDevice);
100
101         /**
102         * Check whether it has the instance.
103         *
104         * @return               The _CameraCoordinator instance
105         * @param[in]    recorderDevice                  The recorder device id.
106         * @exception    E_SUCCESS                               The method is successful.
107         * @exception    E_SYSTEM                                A system error has occurred.
108         * @exception    E_DEVICE_BUSY                   The device cannot be approached because of other operations.
109         * @exception    E_DEVICE_UNAVAILABLE    The device is unavailable.
110         */
111         static _CameraCoordinator* HasInstance(_RecorderDeviceType recorderDevice);
112
113         /**
114         * Adds the listener to this object. @n
115         * Added listeners are called after this object's callbacks are called from the camera.
116         *
117         * @return               An error code
118         * @param[in]    listener                                        A listener instance
119         * @exception    E_SUCCESS                               The method is successful.
120         * @exception    E_SYSTEM                                A system error has occurred.
121         */
122         result AddCameraCoordinatorListener(_ICameraCoordinatorListener& listener);
123
124         /**
125         * Removes the listener from this object. @n
126         *
127         * @return               An error code
128         * @param[in]    listener                                        A listener instance
129         * @exception    E_SUCCESS                               The method is successful.
130         * @exception    E_SYSTEM                                A system error has occurred.
131         */
132         result RemoveCameraCoordinatorListener(_ICameraCoordinatorListener& listener);
133
134         /**
135         * Gets the mode.
136         *
137         * @return                  The camera mode
138         */
139         _CameraMode GetMode(void) const;
140
141         /**
142         * Gets the camera device selection.
143         *
144         * @return                  The camera device selection
145         */
146         _CameraDeviceType GetCameraDevice(void) const;
147
148         /**
149         * Gets the camera handle
150         *
151         * @return                  The camera handle
152         */
153         _CameraHandle GetCameraHandle(void) const;
154
155         /**
156         * Gets the recorder handle
157         *
158         * @return                  The recorder handle
159         */
160         _RecorderHandle GetRecorderHandle(void) const;
161
162         /**
163         * Notifies the mode changing status to _ICameraCoordinatorListener
164         *
165         * @return               An error code
166         * @param[in]    mode                    camera mode
167         * @remarks      This mtehod calls _ICameraCoordinatorListener::::OnCameraCoordinatorModeChangePrepared().
168         *                       This method will call every _ICameraCoordinatorListener which are registered to _CameraCoordinator.
169         */
170         result NotifyModeChangePrepared(_CameraMode mode);
171
172         /**
173         * Notifies the mode changed status to _ICameraCoordinatorListener
174         *
175         * @return               An error code
176         * @param[in]    mode                    camera mode
177         * @remarks      This mtehod calls _ICameraCoordinatorListener::::OnCameraCoordinatorModeChanged().
178         *                       This method will call every _ICameraCoordinatorListener which are registered to _CameraCoordinator.
179         */
180         result NotifyModeChanged(_CameraMode mode);
181
182         /**
183         * Start the preview.
184         *
185         * @return               An error code
186         * @param[in]    mode                                            The mode to set
187         * @exception    E_SUCCESS                                       The method is successful.
188         * @exception    E_INVALID_STATE                         This instance is in an invalid state for this method.
189         */
190         result StartMmPreview(void);
191
192         /**
193         * Stop the preview.
194         *
195         * @return               An error code
196         * @param[in]    mode                                            The mode to set
197         * @exception    E_SUCCESS                                       The method is successful.
198         * @exception    E_INVALID_STATE                         This instance is in an invalid state for this method.
199         */
200         result StopMmPreview(void);
201
202         /**
203         * Changes the camcorder mode.
204         *
205         * @return               An error code
206         * @param[in]    mode                                            The mode to set
207         * @param[in]    callback                                                The flag to call the callback
208         * @exception    E_SUCCESS                                       The method is successful.
209         * @exception    E_INVALID_STATE                         This instance is in an invalid state for this method.
210         * @exception    E_DEVICE_BUSY                           The device cannot be approached because of other operations.
211         * @exception    E_DEVICE_UNAVAILABLE            The device is unavailable.
212         * @exception    E_DEVICE_FAILED                         The device operation has failed.
213         * @exception    E_UNSUPPORTED_OPERATION  This operation is not supported.
214         */
215         result ChangeMode(_CameraMode mode, bool callback);
216
217         /**
218         * Check if the change mode can be calmly.
219         *
220         * @return               The flag of calm change mode
221         * @param[in]    mode                                            The mode to set
222         */
223         bool IsCalmChangeMode(_CameraMode mode);
224
225         /**
226         * Set source format.
227         *
228         * @return          An error code
229         * @param[in]    pixelFormat                      camera's preview format
230         */
231         result SetCameraSourceFormat(camera_pixel_format_e pixelFormat);
232
233         /**
234         * Get source format.
235         *
236         * @return          camera's preview format
237         */
238         camera_pixel_format_e GetCameraSourceFormat(void) const;
239
240         /**
241         * Captures the current image data from the camera sensor.
242         *
243         * @return               An error code
244         * @param[in]    capturingCb                                     The capture callback
245         * @param[in]    completedCb                             The capture completed callback
246         * @param[in]    pUserData                                       The user data
247         * @exception    E_SUCCESS                                       The method is successful.
248         * @exception    E_INVALID_STATE                         This instance is in an invalid state for this method.
249         * @exception    E_DEVICE_BUSY                           The device cannot be approached because of other operations.
250         * @exception    E_DEVICE_UNAVAILABLE            The device is unavailable.
251         * @exception    E_DEVICE_FAILED                         The device operation has failed.
252         * @exception    E_UNSUPPORTED_OPERATION  This operation is not supported.
253         * @exception    E_OUT_OF_MEMORY                         The memory is insufficient.
254         */
255         result StartCapture(camera_capturing_cb capturingCb , camera_capture_completed_cb completedCb , void *pUserData);
256
257         /**
258         * Start recording.
259         *
260         * @return               An error code
261         */
262         result StartRecord(void);
263
264         /**
265         * Sets the orientation of the recorder.
266         *
267         * @return               An error code
268         */
269         void SetRecordingOrientation(RecordingRotation rotation);
270
271         /**
272         * Sets the orientation of the camera.
273         *
274         * @return               An error code
275         */
276         void SetCameraOrientation(CameraExifOrientation orientation);
277
278 private:
279         friend class _CameraCoordinatorSafeHashMapT;
280         /**
281          * This is the default constructor for this class.
282          *
283          * @remarks             After creating an instance of this class, the Construct() method must be called explicitly to
284          * initialize this instance.
285          * @see                 Construct()
286          */
287         _CameraCoordinator(void);
288
289         /**
290          * This is the destructor for this class. @n
291          * All allocated resources are deallocated by this method. This method should be called in the same thread
292          * where the Construct() method is called.
293          *
294          * @see                 Construct()
295          */
296         virtual ~_CameraCoordinator(void);
297
298         /**
299         * Initializes this instance of _CameraCoordinator.
300         *
301         * @return               An error code
302         * @param[in]    cameraDevice                    The camera device id.
303         * @exception    E_SUCCESS                               The method is successful.
304         * @exception    E_SYSTEM                                A system error has occurred.
305         * @exception    E_DEVICE_BUSY                   The device cannot be approached because of other operations.
306         * @exception    E_DEVICE_UNAVAILABLE    The device is unavailable.
307         */
308         result Construct(_CameraDeviceType cameraDevice);
309
310         /**
311         * Add the recorder
312         *
313         * @return               An error code
314         * @param[in]    recorderDevice                  The recorder device id.
315         * @exception    E_SUCCESS                               The method is successful.
316         * @exception    E_SYSTEM                                A system error has occurred.
317         */
318         result AddRecorder(_RecorderDeviceType recorderDevice);
319
320         /**
321         * Remove the recorder
322         *
323         * @param[in]    recorderDevice                  The recorder device id.
324         * @exception    E_SUCCESS                               The method is successful.
325         * @exception    E_SYSTEM                                A system error has occurred.
326         */
327         void RemoveRecorder(_RecorderDeviceType recorderDevice);
328
329         /**
330         * Converts the error from camera to Result.
331         *
332         * @return          An error code
333         * @param[in]    err                      camera error
334         */
335         result ConvertResult(int err) const;
336
337         /**
338         * Change the state.
339         *
340         * @return          An error code
341         * @param[in]    destState                        camera's destinationed state
342         * @remarks      This method makes the camera's state change. @n
343         *                       Acccording to this, Camera's state is changed.
344         */
345         result ChangeCameraStateTo(camera_state_e destState);
346
347         /**
348         * Gets the camera's state.
349         *
350         * @return                  The state
351         */
352         camera_state_e GetCameraState(void) const;
353
354         /**
355         * Gets the recorder's state.
356         *
357         * @return                  The state
358         */
359         recorder_state_e GetRecorderState(void) const;
360
361         /**
362         * Change the state.
363         *
364         * @return          An error code
365         * @param[in]    destState                        recorder's destinationed state
366         * @remarks      This method makes the camera's state change. @n
367         *                       acccording to this, VideoRecorder and AudioRecorder's state is changed.
368         */
369         result ChangeRecorderStateTo(recorder_state_e destState);
370
371         /**
372         * Sets the orientation of the recorder.
373         *
374         * @return               An error code
375         * @param[in]    rotation                        The rotation of the recorder
376         * @exception    E_SUCCESS                       The method is successful.
377         * @exception    E_INVALID_STATE         This method is invalid for the current state of this instance.
378         * @exception    E_INVALID_ARG           The specified @c rotation is not supported.
379         */
380         result SetRecordingOrientationAttr(RecordingRotation rotation);
381
382         /**
383         * Sets the orientation of the camera.
384         *
385         * @return               An error code
386         * @param[in]    orientation                     The orientation of the camera
387         * @exception    E_SUCCESS                       The method is successful.
388         * @exception    E_INVALID_STATE         This method is invalid for the current state of this instance.
389         * @exception    E_INVALID_ARG           The specified @c rotation is not supported.
390         */
391         result SetCameraOrientationAttr(CameraExifOrientation orientation);
392
393         _CameraCoordinator(const _CameraCoordinator& rhs);
394         _CameraCoordinator& operator =(const _CameraCoordinator& rhs);
395
396         _CameraDeviceType __cameraDevice;
397         _CameraHandle __cameraHandle;
398         _RecorderHandle __recorderHandle;
399         _CameraMode __mode;
400         Tizen::Base::Collection::LinkedListT <_ICameraCoordinatorListener*>* __pListenerList;
401         int __orientationFlag;
402         CameraExifOrientation __cameraOrientation;
403         RecordingRotation __recordingRotation;
404
405         static _CameraCoordinatorSafeHashMapT* __pMap;
406 };
407
408 /**
409 * @class        _CameraCoordinatorSafeHashMapT
410 * @brief        This class is for handling safe HashMap.
411 *
412 */
413 class _CameraCoordinatorSafeHashMapT
414         : public Tizen::Base::Collection::HashMapT<_CameraDeviceType, _CameraCoordinator*>
415         , public virtual Tizen::Base::Collection::ICollectionT <Tizen::Base::Collection::MapEntryT <_CameraDeviceType, _CameraCoordinator*> >
416 {
417 public:
418         _CameraCoordinatorSafeHashMapT(void);
419         virtual ~_CameraCoordinatorSafeHashMapT(void);
420         void RemoveItems(void);
421
422 private:
423         _CameraCoordinatorSafeHashMapT(const _CameraCoordinatorSafeHashMapT& rhs);
424         _CameraCoordinatorSafeHashMapT& operator =(const _CameraCoordinatorSafeHashMapT& rhs);
425 };
426
427 }}
428 #endif