2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FMedia_CameraCoordinator.h
20 * @brief This header file contains the declarations of the %_CameraCoordinator class.
24 #ifndef _FMEDIA_INTERNAL_CAMERA_COORDINATOR_H_
25 #define _FMEDIA_INTERNAL_CAMERA_COORDINATOR_H_
27 #include <unique_ptr.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"
39 namespace Tizen { namespace Media
41 class _ICameraCoordinatorListener;
42 class _CameraCoordinatorSafeHashMapT;
45 * @class _CameraCoordinator
46 * @brief This class implements the _CameraCoordinator class.
49 class _CameraCoordinator
50 : public _CameraRefHelper
54 * Get the instance of _CameraCoordinator.
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.
63 static _CameraCoordinator* AddInstance(_CameraDeviceType cameraDevice);
66 * Get the instance of _CameraCoordinator.
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.
75 static _CameraCoordinator* AddInstance(_RecorderDeviceType recorderDevice);
78 * Release the specific _CameraCoordinator.
80 * @param[in] cameraDevice The camera device type
82 static void Release(_CameraDeviceType cameraDevice);
85 * Release the specific _CameraCoordinator.
87 * @param[in] recorderDevice The recorder device type
89 static void Release(_RecorderDeviceType recorderDevice);
92 * Check whether it has the instance.
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.
101 static _CameraCoordinator* HasInstance(_CameraDeviceType cameraDevice);
104 * Check whether it has the instance.
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.
113 static _CameraCoordinator* HasInstance(_RecorderDeviceType recorderDevice);
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.
122 virtual ~_CameraCoordinator(void);
125 * Adds the listener to this object. @n
126 * Added listeners are called after this object's callbacks are called from the camera.
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.
133 result AddCameraCoordinatorListener(_ICameraCoordinatorListener& listener);
136 * Removes the listener from this object. @n
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.
143 result RemoveCameraCoordinatorListener(_ICameraCoordinatorListener& listener);
148 * @return The camera mode
150 _CameraMode GetMode(void) const;
153 * Gets the camera device selection.
155 * @return The camera device selection
157 _CameraDeviceType GetCameraDevice(void) const;
160 * Gets the camera handle
162 * @return The camera handle
164 _CameraHandle GetCameraHandle(void) const;
167 * Gets the recorder handle
169 * @return The recorder handle
171 _RecorderHandle GetRecorderHandle(void) const;
174 * Notifies the mode changing status to _ICameraCoordinatorListener
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.
181 result NotifyModeChangePrepared(_CameraMode mode);
184 * Notifies the mode changed status to _ICameraCoordinatorListener
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.
191 result NotifyModeChanged(_CameraMode mode);
195 * Notifies the other _ICameraCoordinatorListener is removed
197 * @return An error code
198 * @param[in] mode camera mode
199 * @remarks This mtehod calls _ICameraCoordinatorListener::::OnCameraCoordinatorOtherRemoved().
200 * This method will call every _ICameraCoordinatorListener which are registered to _CameraCoordinator.
202 result NotifyOtherRemoved(void);
207 * @return An error code
208 * @param[in] mode The mode to set
209 * @exception E_SUCCESS The method is successful.
210 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
212 result StartMmPreview(void);
217 * @return An error code
218 * @param[in] mode The mode to set
219 * @exception E_SUCCESS The method is successful.
220 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
222 result StopMmPreview(void);
225 * Create videorecorder handle.
227 * @return An error code
228 * @exception E_SUCCESS The method is successful.
229 * @exception E_SYSTEM A system error has occurred.
231 result CreateVideoRecorder(void);
234 * Destory videorecorder handle.
236 * @return An error code
237 * @exception E_SUCCESS The method is successful.
238 * @exception E_SYSTEM A system error has occurred.
240 result DestroyVideoRecorder(void);
243 * Change camera source prview format.
245 * @return An error code
246 * @exception E_SUCCESS The method is successful.
247 * @exception E_SYSTEM A system error has occurred.
249 result ChangeFormat(_CameraMode mode, bool callback, camera_pixel_format_e reloadCameraPreviewFormat);
253 * Changes the camcorder mode.
255 * @return An error code
256 * @param[in] mode The mode to set
257 * @param[in] callback The flag to call the callback
258 * @exception E_SUCCESS The method is successful.
259 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
260 * @exception E_DEVICE_BUSY The device cannot be approached because of other operations.
261 * @exception E_DEVICE_UNAVAILABLE The device is unavailable.
262 * @exception E_DEVICE_FAILED The device operation has failed.
263 * @exception E_UNSUPPORTED_OPERATION This operation is not supported.
265 result ChangeMode(_CameraMode mode, bool callback);
268 * Check if the change mode can be calmly.
270 * @return The flag of calm change mode
271 * @param[in] mode The mode to set
273 bool IsCalmChangeMode(_CameraMode mode);
278 * @return An error code
279 * @param[in] pixelFormat camera's preview format
281 result SetCameraSourceFormat(camera_pixel_format_e pixelFormat);
286 * @return camera's preview format
288 camera_pixel_format_e GetCameraSourceFormat(void) const;
291 * Captures the current image data from the camera sensor.
293 * @return An error code
294 * @param[in] capturingCb The capture callback
295 * @param[in] completedCb The capture completed callback
296 * @param[in] pUserData The user data
297 * @exception E_SUCCESS The method is successful.
298 * @exception E_INVALID_STATE This instance is in an invalid state for this method.
299 * @exception E_DEVICE_BUSY The device cannot be approached because of other operations.
300 * @exception E_DEVICE_UNAVAILABLE The device is unavailable.
301 * @exception E_DEVICE_FAILED The device operation has failed.
302 * @exception E_UNSUPPORTED_OPERATION This operation is not supported.
303 * @exception E_OUT_OF_MEMORY The memory is insufficient.
305 result StartCapture(camera_capturing_cb capturingCb , camera_capture_completed_cb completedCb , void *pUserData);
310 * @return An error code
312 result StartRecord(void);
315 * Sets the orientation of the recorder.
317 * @return An error code
319 void SetRecordingOrientation(RecordingRotation rotation);
322 * Sets the orientation of the camera.
324 * @return An error code
326 void SetCameraOrientation(CameraExifOrientation orientation);
329 * Gets the reloaded preview format of the camera.
331 * @return An error code
333 camera_pixel_format_e GetReloadPreviewFormat(void) const;
336 friend class _CameraCoordinatorSafeHashMapT;
338 * This is the default constructor for this class.
340 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to
341 * initialize this instance.
344 _CameraCoordinator(void);
347 * Initializes this instance of _CameraCoordinator.
349 * @return An error code
350 * @param[in] cameraDevice The camera device id.
351 * @exception E_SUCCESS The method is successful.
352 * @exception E_SYSTEM A system error has occurred.
353 * @exception E_DEVICE_BUSY The device cannot be approached because of other operations.
354 * @exception E_DEVICE_UNAVAILABLE The device is unavailable.
356 result Construct(_CameraDeviceType cameraDevice);
361 * @return An error code
362 * @param[in] recorderDevice The recorder device id.
363 * @exception E_SUCCESS The method is successful.
364 * @exception E_SYSTEM A system error has occurred.
366 result AddRecorder(_RecorderDeviceType recorderDevice);
369 * Remove the recorder
371 * @param[in] recorderDevice The recorder device id.
372 * @exception E_SUCCESS The method is successful.
373 * @exception E_SYSTEM A system error has occurred.
375 void RemoveRecorder(_RecorderDeviceType recorderDevice);
378 * Converts the error from camera to Result.
380 * @return An error code
381 * @param[in] err camera error
383 result ConvertResult(int err) const;
388 * @return An error code
389 * @param[in] destState camera's destinationed state
390 * @remarks This method makes the camera's state change. @n
391 * Acccording to this, Camera's state is changed.
393 result ChangeCameraStateTo(camera_state_e destState);
396 * Gets the camera's state.
400 camera_state_e GetCameraState(void) const;
403 * Gets the recorder's state.
407 recorder_state_e GetRecorderState(void) const;
412 * @return An error code
413 * @param[in] destState recorder's destinationed state
414 * @remarks This method makes the camera's state change. @n
415 * acccording to this, VideoRecorder and AudioRecorder's state is changed.
417 result ChangeRecorderStateTo(recorder_state_e destState);
420 * Sets the orientation of the recorder.
422 * @return An error code
423 * @param[in] rotation The rotation of the recorder
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.
428 result SetRecordingOrientationAttr(RecordingRotation rotation);
431 * Sets the orientation of the camera.
433 * @return An error code
434 * @param[in] orientation The orientation of the camera
435 * @exception E_SUCCESS The method is successful.
436 * @exception E_INVALID_STATE This method is invalid for the current state of this instance.
437 * @exception E_INVALID_ARG The specified @c rotation is not supported.
439 result SetCameraOrientationAttr(CameraExifOrientation orientation);
441 _CameraCoordinator(const _CameraCoordinator& rhs);
442 _CameraCoordinator& operator =(const _CameraCoordinator& rhs);
444 _CameraDeviceType __cameraDevice;
445 _CameraHandle __cameraHandle;
446 _RecorderHandle __recorderHandle;
448 std::unique_ptr<Tizen::Base::Collection::LinkedListT <_ICameraCoordinatorListener*>, _ListPtrUtil::Remover> __pListenerList;
449 int __orientationFlag;
450 CameraExifOrientation __cameraOrientation;
451 RecordingRotation __recordingRotation;
452 camera_pixel_format_e __reloadCameraPreviewFormat;
454 static _CameraCoordinatorSafeHashMapT* __pMap;
458 * @class _CameraCoordinatorSafeHashMapT
459 * @brief This class is for handling safe HashMap.
462 class _CameraCoordinatorSafeHashMapT
463 : public Tizen::Base::Collection::HashMapT<_CameraDeviceType, _CameraCoordinator*>
464 , public virtual Tizen::Base::Collection::ICollectionT <Tizen::Base::Collection::MapEntryT <_CameraDeviceType, _CameraCoordinator*> >
467 _CameraCoordinatorSafeHashMapT(void);
468 virtual ~_CameraCoordinatorSafeHashMapT(void);
469 void RemoveItems(void);
472 _CameraCoordinatorSafeHashMapT(const _CameraCoordinatorSafeHashMapT& rhs);
473 _CameraCoordinatorSafeHashMapT& operator =(const _CameraCoordinatorSafeHashMapT& rhs);