44924db1642182d4042d25c726d0215b12058dde
[platform/framework/native/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 <unique_ptr.h>
28 #include <camera.h>
29 #include <recorder.h>
30 #include <FBaseColLinkedListT.h>
31 #include <FBaseColHashMapT.h>
32 #include <FMediaCameraTypes.h>
33 #include <FMediaRecorderTypes.h>
34 #include "FMedia_CameraTypes.h"
35 #include "FMedia_RecorderTypes.h"
36 #include "FMedia_CameraRefHelper.h"
37 #include "FMedia_CamPtrUtil.h"
38
39 namespace Tizen { namespace Media
40 {
41 class _ICameraCoordinatorListener;
42 class _CameraCoordinatorSafeHashMapT;
43
44 /**
45  * @class       _CameraCoordinator
46  * @brief       This class implements the _CameraCoordinator class.
47  *
48  */
49 class _CameraCoordinator
50         : public _CameraRefHelper
51 {
52 public:
53         /**
54         * Get the instance of _CameraCoordinator.
55         *
56         * @return               The _CameraCoordinator instance
57         * @param[in]    cameraDevice                    The camera device id.
58         * @exception    E_SUCCESS                               The method is successful.
59         * @exception    E_SYSTEM                                A system error has occurred.
60         * @exception    E_DEVICE_BUSY                   The device cannot be approached because of other operations.
61         * @exception    E_DEVICE_UNAVAILABLE    The device is unavailable.
62         */
63         static _CameraCoordinator* AddInstance(_CameraDeviceType cameraDevice);
64
65         /**
66         * Get the instance of _CameraCoordinator.
67         *
68         * @return               The _CameraCoordinator instance
69         * @param[in]    recorderDevice                  The recorder device id.
70         * @exception    E_SUCCESS                               The method is successful.
71         * @exception    E_SYSTEM                                A system error has occurred.
72         * @exception    E_DEVICE_BUSY                   The device cannot be approached because of other operations.
73         * @exception    E_DEVICE_UNAVAILABLE    The device is unavailable.
74         */
75         static _CameraCoordinator* AddInstance(_RecorderDeviceType recorderDevice);
76
77         /**
78         * Release the specific _CameraCoordinator.
79         *
80         * @param[in]    cameraDevice                    The camera device type
81         */
82         static void Release(_CameraDeviceType cameraDevice);
83
84         /**
85         * Release the specific _CameraCoordinator.
86         *
87         * @param[in]    recorderDevice                  The recorder device type
88         */
89         static void Release(_RecorderDeviceType recorderDevice);
90
91         /**
92         * Check whether it has the instance.
93         *
94         * @return               The _CameraCoordinator instance
95         * @param[in]    cameraDevice                    The camera device id.
96         * @exception    E_SUCCESS                               The method is successful.
97         * @exception    E_SYSTEM                                A system error has occurred.
98         * @exception    E_DEVICE_BUSY                   The device cannot be approached because of other operations.
99         * @exception    E_DEVICE_UNAVAILABLE    The device is unavailable.
100         */
101         static _CameraCoordinator* HasInstance(_CameraDeviceType cameraDevice);
102
103         /**
104         * Check whether it has the instance.
105         *
106         * @return               The _CameraCoordinator instance
107         * @param[in]    recorderDevice                  The recorder device id.
108         * @exception    E_SUCCESS                               The method is successful.
109         * @exception    E_SYSTEM                                A system error has occurred.
110         * @exception    E_DEVICE_BUSY                   The device cannot be approached because of other operations.
111         * @exception    E_DEVICE_UNAVAILABLE    The device is unavailable.
112         */
113         static _CameraCoordinator* HasInstance(_RecorderDeviceType recorderDevice);
114
115         /**
116          * This is the destructor for this class. @n
117          * All allocated resources are deallocated by this method. This method should be called in the same thread
118          * where the Construct() method is called.
119          *
120          * @see                 Construct()
121          */
122         virtual ~_CameraCoordinator(void);
123
124         /**
125         * Adds the listener to this object. @n
126         * Added listeners are called after this object's callbacks are called from the camera.
127         *
128         * @return               An error code
129         * @param[in]    listener                                        A listener instance
130         * @exception    E_SUCCESS                               The method is successful.
131         * @exception    E_SYSTEM                                A system error has occurred.
132         */
133         result AddCameraCoordinatorListener(_ICameraCoordinatorListener& listener);
134
135         /**
136         * Removes the listener from this object. @n
137         *
138         * @return               An error code
139         * @param[in]    listener                                        A listener instance
140         * @exception    E_SUCCESS                               The method is successful.
141         * @exception    E_SYSTEM                                A system error has occurred.
142         */
143         result RemoveCameraCoordinatorListener(_ICameraCoordinatorListener& listener);
144
145         /**
146         * Gets the mode.
147         *
148         * @return                  The camera mode
149         */
150         _CameraMode GetMode(void) const;
151
152         /**
153         * Gets the camera device selection.
154         *
155         * @return                  The camera device selection
156         */
157         _CameraDeviceType GetCameraDevice(void) const;
158
159         /**
160         * Gets the camera handle
161         *
162         * @return                  The camera handle
163         */
164         _CameraHandle GetCameraHandle(void) const;
165
166         /**
167         * Gets the recorder handle
168         *
169         * @return                  The recorder handle
170         */
171         _RecorderHandle GetRecorderHandle(void) const;
172
173         /**
174         * Notifies the mode changing status to _ICameraCoordinatorListener
175         *
176         * @return               An error code
177         * @param[in]    mode                    camera mode
178         * @remarks      This mtehod calls _ICameraCoordinatorListener::::OnCameraCoordinatorModeChangePrepared().
179         *                       This method will call every _ICameraCoordinatorListener which are registered to _CameraCoordinator.
180         */
181         result NotifyModeChangePrepared(_CameraMode mode);
182
183         /**
184         * Notifies the mode changed status to _ICameraCoordinatorListener
185         *
186         * @return               An error code
187         * @param[in]    mode                    camera mode
188         * @remarks      This mtehod calls _ICameraCoordinatorListener::::OnCameraCoordinatorModeChanged().
189         *                       This method will call every _ICameraCoordinatorListener which are registered to _CameraCoordinator.
190         */
191         result NotifyModeChanged(_CameraMode mode);
192
193         /**
194         * Start the preview.
195         *
196         * @return               An error code
197         * @param[in]    mode                                            The mode to set
198         * @exception    E_SUCCESS                                       The method is successful.
199         * @exception    E_INVALID_STATE                         This instance is in an invalid state for this method.
200         */
201         result StartMmPreview(void);
202
203         /**
204         * Stop the preview.
205         *
206         * @return               An error code
207         * @param[in]    mode                                            The mode to set
208         * @exception    E_SUCCESS                                       The method is successful.
209         * @exception    E_INVALID_STATE                         This instance is in an invalid state for this method.
210         */
211         result StopMmPreview(void);
212
213         /**
214         * Create videorecorder handle.
215         *
216         * @return               An error code
217         * @exception    E_SUCCESS                               The method is successful.
218         * @exception    E_SYSTEM                                A system error has occurred.
219         */
220         result CreateVideoRecorder(void);
221
222         /**
223         * Destory videorecorder handle.
224         *
225         * @return               An error code
226         * @exception    E_SUCCESS                               The method is successful.
227         * @exception    E_SYSTEM                                A system error has occurred.
228         */
229         result DestroyVideoRecorder(void);
230
231         /**
232         * Change camera source prview format.
233         *
234         * @return               An error code
235         * @exception    E_SUCCESS                               The method is successful.
236         * @exception    E_SYSTEM                                A system error has occurred.
237         */
238         result ChangeFormat(_CameraMode mode, bool callback, camera_pixel_format_e reloadCameraPreviewFormat);
239
240
241         /**
242         * Changes the camcorder mode.
243         *
244         * @return               An error code
245         * @param[in]    mode                                            The mode to set
246         * @param[in]    callback                                                The flag to call the callback
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         */
254         result ChangeMode(_CameraMode mode, bool callback);
255
256         /**
257         * Check if the change mode can be calmly.
258         *
259         * @return               The flag of calm change mode
260         * @param[in]    mode                                            The mode to set
261         */
262         bool IsCalmChangeMode(_CameraMode mode);
263
264         /**
265         * Set source format.
266         *
267         * @return          An error code
268         * @param[in]    pixelFormat                      camera's preview format
269         */
270         result SetCameraSourceFormat(camera_pixel_format_e pixelFormat);
271
272         /**
273         * Get source format.
274         *
275         * @return          camera's preview format
276         */
277         camera_pixel_format_e GetCameraSourceFormat(void) const;
278
279         /**
280         * Captures the current image data from the camera sensor.
281         *
282         * @return               An error code
283         * @param[in]    capturingCb                                     The capture callback
284         * @param[in]    completedCb                             The capture completed callback
285         * @param[in]    pUserData                                       The user data
286         * @exception    E_SUCCESS                                       The method is successful.
287         * @exception    E_INVALID_STATE                         This instance is in an invalid state for this method.
288         * @exception    E_DEVICE_BUSY                           The device cannot be approached because of other operations.
289         * @exception    E_DEVICE_UNAVAILABLE            The device is unavailable.
290         * @exception    E_DEVICE_FAILED                         The device operation has failed.
291         * @exception    E_UNSUPPORTED_OPERATION  This operation is not supported.
292         * @exception    E_OUT_OF_MEMORY                         The memory is insufficient.
293         */
294         result StartCapture(camera_capturing_cb capturingCb , camera_capture_completed_cb completedCb , void *pUserData);
295
296         /**
297         * Start recording.
298         *
299         * @return               An error code
300         */
301         result StartRecord(void);
302
303         /**
304         * Sets the orientation of the recorder.
305         *
306         * @return               An error code
307         */
308         void SetRecordingOrientation(RecordingRotation rotation);
309
310         /**
311         * Sets the orientation of the camera.
312         *
313         * @return               An error code
314         */
315         void SetCameraOrientation(CameraExifOrientation orientation);
316
317         /**
318         * Gets the reloaded preview format of the camera.
319         *
320         * @return               An error code
321         */
322         camera_pixel_format_e GetReloadPreviewFormat(void) const;
323
324 private:
325         friend class _CameraCoordinatorSafeHashMapT;
326         /**
327          * This is the default constructor for this class.
328          *
329          * @remarks             After creating an instance of this class, the Construct() method must be called explicitly to
330          * initialize this instance.
331          * @see                 Construct()
332          */
333         _CameraCoordinator(void);
334
335         /**
336         * Initializes this instance of _CameraCoordinator.
337         *
338         * @return               An error code
339         * @param[in]    cameraDevice                    The camera device id.
340         * @exception    E_SUCCESS                               The method is successful.
341         * @exception    E_SYSTEM                                A system error has occurred.
342         * @exception    E_DEVICE_BUSY                   The device cannot be approached because of other operations.
343         * @exception    E_DEVICE_UNAVAILABLE    The device is unavailable.
344         */
345         result Construct(_CameraDeviceType cameraDevice);
346
347         /**
348         * Add the recorder
349         *
350         * @return               An error code
351         * @param[in]    recorderDevice                  The recorder device id.
352         * @exception    E_SUCCESS                               The method is successful.
353         * @exception    E_SYSTEM                                A system error has occurred.
354         */
355         result AddRecorder(_RecorderDeviceType recorderDevice);
356
357         /**
358         * Remove the recorder
359         *
360         * @param[in]    recorderDevice                  The recorder device id.
361         * @exception    E_SUCCESS                               The method is successful.
362         * @exception    E_SYSTEM                                A system error has occurred.
363         */
364         void RemoveRecorder(_RecorderDeviceType recorderDevice);
365
366         /**
367         * Converts the error from camera to Result.
368         *
369         * @return          An error code
370         * @param[in]    err                      camera error
371         */
372         result ConvertResult(int err) const;
373
374         /**
375         * Change the state.
376         *
377         * @return          An error code
378         * @param[in]    destState                        camera's destinationed state
379         * @remarks      This method makes the camera's state change. @n
380         *                       Acccording to this, Camera's state is changed.
381         */
382         result ChangeCameraStateTo(camera_state_e destState);
383
384         /**
385         * Gets the camera's state.
386         *
387         * @return                  The state
388         */
389         camera_state_e GetCameraState(void) const;
390
391         /**
392         * Gets the recorder's state.
393         *
394         * @return                  The state
395         */
396         recorder_state_e GetRecorderState(void) const;
397
398         /**
399         * Change the state.
400         *
401         * @return          An error code
402         * @param[in]    destState                        recorder's destinationed state
403         * @remarks      This method makes the camera's state change. @n
404         *                       acccording to this, VideoRecorder and AudioRecorder's state is changed.
405         */
406         result ChangeRecorderStateTo(recorder_state_e destState);
407
408         /**
409         * Sets the orientation of the recorder.
410         *
411         * @return               An error code
412         * @param[in]    rotation                        The rotation of the recorder
413         * @exception    E_SUCCESS                       The method is successful.
414         * @exception    E_INVALID_STATE         This method is invalid for the current state of this instance.
415         * @exception    E_INVALID_ARG           The specified @c rotation is not supported.
416         */
417         result SetRecordingOrientationAttr(RecordingRotation rotation);
418
419         /**
420         * Sets the orientation of the camera.
421         *
422         * @return               An error code
423         * @param[in]    orientation                     The orientation of the camera
424         * @exception    E_SUCCESS                       The method is successful.
425         * @exception    E_INVALID_STATE         This method is invalid for the current state of this instance.
426         * @exception    E_INVALID_ARG           The specified @c rotation is not supported.
427         */
428         result SetCameraOrientationAttr(CameraExifOrientation orientation);
429
430         _CameraCoordinator(const _CameraCoordinator& rhs);
431         _CameraCoordinator& operator =(const _CameraCoordinator& rhs);
432
433         _CameraDeviceType __cameraDevice;
434         _CameraHandle __cameraHandle;
435         _RecorderHandle __recorderHandle;
436         _CameraMode __mode;
437         std::unique_ptr<Tizen::Base::Collection::LinkedListT <_ICameraCoordinatorListener*>, _ListPtrUtil::Remover> __pListenerList;
438         int __orientationFlag;
439         CameraExifOrientation __cameraOrientation;
440         RecordingRotation __recordingRotation;
441         camera_pixel_format_e __reloadCameraPreviewFormat;
442
443         static _CameraCoordinatorSafeHashMapT* __pMap;
444 };
445
446 /**
447 * @class        _CameraCoordinatorSafeHashMapT
448 * @brief        This class is for handling safe HashMap.
449 *
450 */
451 class _CameraCoordinatorSafeHashMapT
452         : public Tizen::Base::Collection::HashMapT<_CameraDeviceType, _CameraCoordinator*>
453         , public virtual Tizen::Base::Collection::ICollectionT <Tizen::Base::Collection::MapEntryT <_CameraDeviceType, _CameraCoordinator*> >
454 {
455 public:
456         _CameraCoordinatorSafeHashMapT(void);
457         virtual ~_CameraCoordinatorSafeHashMapT(void);
458         void RemoveItems(void);
459
460 private:
461         _CameraCoordinatorSafeHashMapT(const _CameraCoordinatorSafeHashMapT& rhs);
462         _CameraCoordinatorSafeHashMapT& operator =(const _CameraCoordinatorSafeHashMapT& rhs);
463 };
464
465 }}
466 #endif