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.cpp
20 * @brief This file contains the implementation of the %FMedia_CameraCoordinator class.
23 #include <FBaseSysLog.h>
24 #include "FMedia_CameraManager.h"
25 #include "FMedia_RecorderManager.h"
26 #include "FMedia_CameraCoordinator.h"
27 #include "FMedia_ICameraCoordinatorListener.h"
28 #include "FMedia_CameraUtil.h"
29 #include "FMedia_RecorderUtil.h"
31 //#define _VIDEO_RECORDER_ROTATION_
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
36 namespace Tizen { namespace Media
38 static const int _ORIENTATION_FOR_RECORDING = 0x1;
39 static const int _ORIENTATION_FOR_CAMERA = 0x1 << 1;
41 typedef int (*_CameraFunc)(_CameraHandle mmHandle);
45 camera_state_e prevState;
46 camera_state_e postState;
48 }_CameraStateTransitTable;
50 static const _CameraStateTransitTable _CAMERA_STATE_TRANSIT[] =
52 {::CAMERA_STATE_CREATED, ::CAMERA_STATE_PREVIEW, camera_start_preview },
53 {::CAMERA_STATE_CAPTURED, ::CAMERA_STATE_PREVIEW, camera_start_preview },
54 {::CAMERA_STATE_CAPTURED, ::CAMERA_STATE_CREATED, camera_stop_preview },
55 {::CAMERA_STATE_PREVIEW, ::CAMERA_STATE_CREATED, camera_stop_preview },
58 typedef int (*_RecorderFunc)(_RecorderHandle mmHandle);
62 recorder_state_e prevState;
63 recorder_state_e postState;
65 }_RecorderStateTransitTable;
67 static const _RecorderStateTransitTable _RECORDER_STATE_TRANSIT[] =
69 {::RECORDER_STATE_CREATED, ::RECORDER_STATE_READY, recorder_prepare },
70 {::RECORDER_STATE_READY, ::RECORDER_STATE_RECORDING, recorder_start },
71 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_PAUSED, recorder_pause },
72 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, recorder_commit },
73 // {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, recorder_cancel },
74 {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_READY, recorder_commit },
75 {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_READY, recorder_cancel },
76 {::RECORDER_STATE_READY, ::RECORDER_STATE_CREATED, recorder_unprepare },
79 _CameraCoordinatorSafeHashMapT* _CameraCoordinator::__pMap = null;
81 _CameraCoordinatorSafeHashMapT::_CameraCoordinatorSafeHashMapT(void)
85 _CameraCoordinatorSafeHashMapT::~_CameraCoordinatorSafeHashMapT(void)
88 _CameraCoordinator::__pMap = null;
92 _CameraCoordinatorSafeHashMapT::RemoveItems(void)
94 IListT <_CameraDeviceType>* pList = null;
95 _CameraCoordinator* pCoordinator = null;
99 SysTryReturn(NID_MEDIA, pList != null, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] There is no instance.");
100 for (int i = 0; i < GetCount(); i++)
102 _CameraDeviceType deviceType = _CAMERA_DEVICE_NONE;
103 r = pList->GetAt(i, deviceType);
104 if (IsFailed(r) && deviceType == _CAMERA_DEVICE_NONE)
109 r = GetValue(deviceType, pCoordinator);
110 if (IsFailed(r) && pCoordinator == null)
121 _CameraCoordinator::_CameraCoordinator()
122 : __cameraDevice(_CAMERA_DEVICE_NONE)
123 , __cameraHandle(MM_INVALID_HANDLE)
124 , __recorderHandle(MM_INVALID_HANDLE)
125 , __mode(_CAMERA_MODE_NONE)
126 , __pListenerList(null)
127 , __orientationFlag(0)
128 , __cameraOrientation(CAMERA_EXIF_ORIENTATION_TOP_LEFT)
129 , __recordingRotation(RECORDING_ROTATION_NONE)
133 _CameraCoordinator::~_CameraCoordinator()
135 if (__pListenerList != null)
137 __pListenerList->RemoveAll();
138 delete __pListenerList;
141 _CameraManager::Release(__cameraDevice);
142 SysLog(NID_MEDIA, "Camera manager released");
146 _CameraCoordinator::Construct(_CameraDeviceType cameraDevice)
148 result r = E_SUCCESS;
149 _CameraManager* pCameraManager = null;
150 SysLog(NID_MEDIA, "Enter. camera device:%d", cameraDevice);
152 pCameraManager = _CameraManager::AddInstance(cameraDevice);
154 SysTryReturn(NID_MEDIA, pCameraManager !=null && r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
156 __cameraHandle = pCameraManager->GetHandle();
158 __pListenerList = new (std::nothrow) LinkedListT <_ICameraCoordinatorListener*>();
159 SysTryCatch(NID_MEDIA, __pListenerList !=null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
161 __cameraDevice = cameraDevice;
162 __mode = _CAMERA_MODE_IMAGE;
171 _CameraCoordinator::AddRecorder(_RecorderDeviceType recorderDevice)
173 result r = E_SUCCESS;
174 _RecorderManager* pRecorderManager = null;
175 SysLog(NID_MEDIA, "Enter. recorder device:%d", recorderDevice);
177 pRecorderManager = _RecorderManager::AddInstance(recorderDevice);
179 SysTryCatch(NID_MEDIA, pRecorderManager !=null && r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
181 __recorderHandle = pRecorderManager->GetHandle(); // new recorder handle
190 _CameraCoordinator::RemoveRecorder(_RecorderDeviceType recorderDevice)
192 SysLog(NID_MEDIA, "Enter. recorder device:%d", recorderDevice);
193 _RecorderManager::Release(recorderDevice);
194 __recorderHandle = MM_INVALID_HANDLE;
195 __orientationFlag = __orientationFlag & (~_ORIENTATION_FOR_RECORDING);
199 _CameraCoordinator::AddInstance(_CameraDeviceType cameraDevice)
201 result r = E_SUCCESS;
205 static bool isMapConstructed = false;
206 static _CameraCoordinatorSafeHashMapT map;
207 _CameraCoordinator* pCoordinator = null;
209 SysTryReturn(NID_MEDIA, cameraDevice > _CAMERA_DEVICE_NONE && cameraDevice < _CAMERA_DEVICE_MAX,
210 null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(camderDevice) is used. camderDevice:%d is wrong.", cameraDevice);
212 if (!isMapConstructed)
215 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
216 isMapConstructed = true;
220 r = map.ContainsKey(cameraDevice, out);
221 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
225 r = map.GetValue(cameraDevice, pCoordinator);
226 SysTryCatch(NID_MEDIA, r == E_SUCCESS && pCoordinator != null, , r, "[%s] Propagating.", GetErrorMessage(r));
230 pCoordinator = new (std::nothrow) _CameraCoordinator();
231 SysTryCatch(NID_MEDIA, pCoordinator !=null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
233 r = pCoordinator->Construct(cameraDevice);
234 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
236 r = map.Add(cameraDevice, pCoordinator);
237 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
240 pCoordinator->AddRefCount();
244 if (pCoordinator != null)
252 _CameraCoordinator::AddInstance(_RecorderDeviceType recorderDevice)
254 _CameraCoordinator* pCoordinator = null;
255 _CameraDeviceType cameraDevice = _CAMERA_DEVICE_NONE;
258 switch (recorderDevice)
260 case _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA:
261 cameraDevice = _CAMERA_DEVICE_PRIMARY;
264 case _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA:
265 cameraDevice = _CAMERA_DEVICE_SECONDARY;
272 if (cameraDevice == _CAMERA_DEVICE_NONE)
274 SysLogException(NID_MEDIA, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(recorderDevice) is used. recorderDevice :%d is wrong.", recorderDevice);
278 pCoordinator = AddInstance(cameraDevice);
279 if (pCoordinator == null)
281 SysLogException(NID_MEDIA, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The camera device(%d)'s coordinator is not available.", cameraDevice);
288 _CameraCoordinator::Release(_CameraDeviceType cameraDevice)
290 result r = E_SUCCESS;
294 _CameraCoordinator* pCoordinator = null;
295 r = __pMap->GetValue(cameraDevice, pCoordinator);
296 SysTryReturn(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
298 if (pCoordinator->ReleaseRefCount() == 0)
301 r = __pMap->Remove(cameraDevice);
302 SysTryReturn(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
308 _CameraCoordinator::Release(_RecorderDeviceType recorderDevice)
312 _CameraDeviceType cameraDevice = _CAMERA_DEVICE_NONE;
314 switch (recorderDevice)
316 case _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA:
317 cameraDevice = _CAMERA_DEVICE_PRIMARY;
319 case _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA:
320 cameraDevice = _CAMERA_DEVICE_SECONDARY;
326 Release(cameraDevice);
331 _CameraCoordinator::HasInstance(_CameraDeviceType cameraDevice)
333 result r = E_SUCCESS;
334 _CameraCoordinator* pCoordinator = null;
338 SysTryReturn(NID_MEDIA, cameraDevice > _CAMERA_DEVICE_NONE && cameraDevice < _CAMERA_DEVICE_MAX,
339 null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(camderDevice) is used. camderDevice:%d is wrong.", cameraDevice);
340 SysTryReturn(NID_MEDIA, __pMap != null, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] No coordinator was created.");
342 r = __pMap->ContainsKey(cameraDevice, out);
343 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
344 SysTryCatch(NID_MEDIA, out == true, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Camera device(%d) was not created.", cameraDevice);
346 r = __pMap->GetValue(cameraDevice, pCoordinator);
347 SysTryCatch(NID_MEDIA, r == E_SUCCESS && pCoordinator != null, , r, "[%s] Propagating.", GetErrorMessage(r));
356 _CameraCoordinator::HasInstance(_RecorderDeviceType recorderDevice)
358 _CameraCoordinator* pCoordinator = null;
359 _CameraDeviceType cameraDevice = _CAMERA_DEVICE_NONE;
362 switch (recorderDevice)
364 case _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA:
365 cameraDevice = _CAMERA_DEVICE_PRIMARY;
368 case _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA:
369 cameraDevice = _CAMERA_DEVICE_SECONDARY;
376 if (cameraDevice == _CAMERA_DEVICE_NONE)
378 SysLogException(NID_MEDIA, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(recorderDevice) is used. recorderDevice :%d is wrong.", recorderDevice);
382 pCoordinator = HasInstance(cameraDevice);
383 if (pCoordinator == null)
385 SysLogException(NID_MEDIA, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The camera device(%d)'s coordinator is not available.", cameraDevice);
392 _CameraCoordinator::AddCameraCoordinatorListener(_ICameraCoordinatorListener& listener)
394 result r = E_SUCCESS;
395 r = __pListenerList->Add(&listener);
400 _CameraCoordinator::RemoveCameraCoordinatorListener(_ICameraCoordinatorListener& listener)
402 result r = E_SUCCESS;
403 r = __pListenerList->Remove(&listener);
408 _CameraCoordinator::GetMode(void) const
414 _CameraCoordinator::GetCameraHandle(void) const
416 return __cameraHandle;
420 _CameraCoordinator::GetRecorderHandle(void) const
422 return __recorderHandle;
426 _CameraCoordinator::NotifyModeChangePrepared(_CameraMode mode)
428 result r = E_SUCCESS;
429 IEnumeratorT <_ICameraCoordinatorListener*>* pEnum = null;
430 _ICameraCoordinatorListener* pListener = null;
431 SysLog(NID_MEDIA, "mode:%d", mode);
433 pEnum = __pListenerList->GetEnumeratorN();
435 SysTryCatch(NID_MEDIA, pEnum != null, , r, "[%s] Propagating.", GetErrorMessage(r));
437 while (pEnum->MoveNext() == E_SUCCESS)
439 r = pEnum->GetCurrent(pListener);
440 SysTryCatch(NID_MEDIA, pListener != null && r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM,
441 "[E_SYSTEM] A system error has been occurred. The listener is not proper");
443 r = pListener->OnCameraCoordinatorModeChangePrepared(mode);
444 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
460 _CameraCoordinator::NotifyModeChanged(_CameraMode mode)
462 result r = E_SUCCESS;
463 IEnumeratorT <_ICameraCoordinatorListener*>* pEnum = null;
464 _ICameraCoordinatorListener* pListener = null;
465 SysLog(NID_MEDIA, "mode:%d", mode);
467 pEnum = __pListenerList->GetEnumeratorN();
469 SysTryCatch(NID_MEDIA, pEnum != null, , r, "[%s] Propagating.", GetErrorMessage(r));
471 while (pEnum->MoveNext() == E_SUCCESS)
473 r = pEnum->GetCurrent(pListener);
474 SysTryCatch(NID_MEDIA, pListener != null && r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM,
475 "[E_SYSTEM] A system error has been occurred. The listener is not proper");
477 r = pListener->OnCameraCoordinatorModeChanged(mode);
478 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
494 _CameraCoordinator::StartMmPreview(void)
496 result r = E_SUCCESS;
497 SysLog(NID_MEDIA, "Enter. mode:%d", __mode);
501 case _CAMERA_MODE_IMAGE:
502 r = ChangeCameraStateTo(::CAMERA_STATE_PREVIEW);
503 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
506 case _CAMERA_MODE_VIDEO:
507 r = ChangeRecorderStateTo(::RECORDER_STATE_READY);
508 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
512 SysLogException(NID_MEDIA, E_INVALID_STATE, "[E_INVALID_STATE] Camera is in an invalid state. Camcorder mode :%d is wrong", __mode);
522 _CameraCoordinator::StopMmPreview(void)
524 result r = E_SUCCESS;
525 SysLog(NID_MEDIA, "Enter.");
527 if (__mode == _CAMERA_MODE_IMAGE)
529 r = ChangeCameraStateTo(::CAMERA_STATE_CREATED);
530 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
532 else if (__mode == _CAMERA_MODE_VIDEO)
534 recorder_state_e recorderState = ::RECORDER_STATE_NONE;
535 recorderState = GetRecorderState();
537 switch (recorderState)
539 case ::RECORDER_STATE_RECORDING:
540 r = ChangeRecorderStateTo(::RECORDER_STATE_READY);
541 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
543 r = ChangeRecorderStateTo(::RECORDER_STATE_CREATED);
544 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
547 case ::RECORDER_STATE_READY:
548 r = ChangeRecorderStateTo(::RECORDER_STATE_CREATED);
549 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
554 SysLogException(NID_MEDIA, E_INVALID_STATE, "[E_INVALID_STATE] recorderState is in an invalid state. recorderState:%d", recorderState);
561 SysLogException(NID_MEDIA, E_INVALID_STATE, "[E_INVALID_STATE] CamcorderMode is in an invalid state. mode :%d", __mode);
569 _CameraCoordinator::ChangeMode(_CameraMode mode, bool callback)
571 result r = E_SUCCESS;
572 camera_state_e cameraState = ::CAMERA_STATE_NONE;
573 recorder_state_e recorderState = ::RECORDER_STATE_NONE;
574 _RecorderDeviceType recorderDevice = _RECORDER_DEVICE_NONE;
575 int err = MM_SUCCESS;
577 SysLog(NID_MEDIA, "Mode should be changed. mode:%d", mode);
578 if (mode == _CAMERA_MODE_VIDEO)
580 cameraState = GetCameraState();
584 case ::CAMERA_STATE_CREATED:
586 case ::CAMERA_STATE_NONE:
589 case ::CAMERA_STATE_PREVIEW:
591 case ::CAMERA_STATE_CAPTURED:
592 r = ChangeCameraStateTo(::CAMERA_STATE_CREATED);
593 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
596 case ::CAMERA_STATE_CAPTURING:
598 SysLogException(NID_MEDIA, r, "[E_INVALID_STATE] cameraState(%d) is in an invalid state. While the camera is capturing, the mode cannot be changed.", cameraState);
607 if ( __recorderHandle == MM_INVALID_HANDLE )
609 recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
610 _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
611 r = AddRecorder(recorderDevice); // recorder_create() will be called.
612 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
613 __mode = _CAMERA_MODE_VIDEO;
618 r = NotifyModeChangePrepared(mode);
619 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
624 case ::CAMERA_STATE_NONE:
626 case ::CAMERA_STATE_CREATED:
629 case ::CAMERA_STATE_PREVIEW:
630 r = ChangeRecorderStateTo(::RECORDER_STATE_READY);
631 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
634 case ::CAMERA_STATE_CAPTURED:
639 else if ( mode == _CAMERA_MODE_IMAGE )
641 recorderState = GetRecorderState();
644 switch (recorderState)
646 case ::RECORDER_STATE_NONE:
649 case ::RECORDER_STATE_CREATED:
650 recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
651 _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
652 RemoveRecorder(recorderDevice); // the mode will be changed to IMAGE.
653 __mode = _CAMERA_MODE_IMAGE;
656 case ::RECORDER_STATE_READY:
657 r = ChangeRecorderStateTo(::RECORDER_STATE_CREATED);
658 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
660 recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
661 _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
662 RemoveRecorder(recorderDevice);
663 __mode = _CAMERA_MODE_IMAGE;
666 r = NotifyModeChangePrepared(mode);
667 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
669 r = ChangeCameraStateTo(::CAMERA_STATE_PREVIEW);
670 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
673 case ::RECORDER_STATE_RECORDING:
675 case ::RECORDER_STATE_PAUSED:
676 err = recorder_cancel(__recorderHandle); // TODO
677 r = ConvertResult(err);
678 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
680 r = ChangeRecorderStateTo(::RECORDER_STATE_CREATED);
681 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
682 recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
683 _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
685 RemoveRecorder(recorderDevice);
686 __mode = _CAMERA_MODE_IMAGE;
689 r = NotifyModeChangePrepared(mode);
690 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
692 r = ChangeCameraStateTo(::CAMERA_STATE_PREVIEW);
693 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
703 // Notify that the mode is changed to callback camera and video recorder's configurations.
704 r = NotifyModeChanged(mode);
705 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
715 _CameraCoordinator::IsCalmChangeMode(_CameraMode mode)
717 camera_state_e cameraState = ::CAMERA_STATE_NONE;
718 recorder_state_e recorderState = ::RECORDER_STATE_NONE;
719 bool calmChange = false;
721 if (mode == _CAMERA_MODE_VIDEO)
723 cameraState = GetCameraState();
727 case ::CAMERA_STATE_CREATED:
729 case ::CAMERA_STATE_NONE:
733 case ::CAMERA_STATE_PREVIEW:
735 case ::CAMERA_STATE_CAPTURED:
737 case ::CAMERA_STATE_CAPTURING:
745 else if ( mode == _CAMERA_MODE_IMAGE )
747 recorderState = GetRecorderState();
750 switch (recorderState)
752 case ::RECORDER_STATE_NONE:
754 case ::RECORDER_STATE_CREATED:
758 case ::RECORDER_STATE_READY:
760 case ::RECORDER_STATE_RECORDING:
762 case ::RECORDER_STATE_PAUSED:
771 SysLog(NID_MEDIA, "mode:%d, calm:%d", mode, calmChange);
777 _CameraCoordinator::GetCameraDevice(void) const
779 return __cameraDevice;
783 _CameraCoordinator::GetCameraState(void) const
785 result r = E_SUCCESS;
786 int err = MM_SUCCESS;
787 camera_state_e state = ::CAMERA_STATE_NONE;
789 err = camera_get_state(__cameraHandle, &state);
790 r = ConvertResult(err);
791 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
796 return ::CAMERA_STATE_NONE;
800 _CameraCoordinator::GetRecorderState(void) const
802 result r = E_SUCCESS;
803 int err = MM_SUCCESS;
804 recorder_state_e state = ::RECORDER_STATE_NONE;
806 err = recorder_get_state(__recorderHandle, &state);
807 r = ConvertResult(err);
808 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
813 return ::RECORDER_STATE_NONE;
817 _CameraCoordinator::ConvertResult(int err) const
820 if (err != CAMERA_ERROR_NONE)
822 SysLog(NID_MEDIA, "MM Err:0x%x", err);
826 if (err == CAMERA_ERROR_NONE || err == RECORDER_ERROR_NONE)
830 else if (err == CAMERA_ERROR_INVALID_PARAMETER || err == RECORDER_ERROR_INVALID_PARAMETER)
834 else if (err == CAMERA_ERROR_INVALID_STATE || err == RECORDER_ERROR_INVALID_STATE)
838 else if (err == CAMERA_ERROR_OUT_OF_MEMORY || err == RECORDER_ERROR_OUT_OF_MEMORY)
842 else if (err == CAMERA_ERROR_DEVICE || err == RECORDER_ERROR_DEVICE)
846 else if (err == CAMERA_ERROR_INVALID_OPERATION
847 || err == CAMERA_ERROR_SECURITY_RESTRICTED
848 || err == RECORDER_ERROR_INVALID_OPERATION
849 || err == RECORDER_ERROR_SECURITY_RESTRICTED)
853 else if (err == CAMERA_ERROR_DEVICE_BUSY
854 || err == CAMERA_ERROR_SOUND_POLICY
855 || err == RECORDER_ERROR_SOUND_POLICY)
859 else if (err == CAMERA_ERROR_DEVICE_NOT_FOUND)
861 r = E_DEVICE_UNAVAILABLE;
873 _CameraCoordinator::ChangeCameraStateTo(camera_state_e destState)
875 result r = E_SUCCESS;
876 int tableTotalCount = 0;
878 int err = MM_SUCCESS;
879 camera_state_e preState = ::CAMERA_STATE_NONE;
880 camera_state_e postState = ::CAMERA_STATE_NONE;
882 preState = GetCameraState();
883 tableTotalCount = sizeof(_CAMERA_STATE_TRANSIT) / sizeof(_CAMERA_STATE_TRANSIT[0]);
884 SysLog(NID_MEDIA, " PreState:%d, destState:%d, tableTotalCount:%d", preState, destState, tableTotalCount);
886 for (i = 0; i < tableTotalCount; i++)
888 if (preState == _CAMERA_STATE_TRANSIT[i].prevState && destState == _CAMERA_STATE_TRANSIT[i].postState)
890 if (_CAMERA_STATE_TRANSIT[i].pFunc != null)
893 "Exist the matching state field. loop i:%d, current state:%d, destState:%d", i,
894 preState, destState);
895 err = _CAMERA_STATE_TRANSIT[i].pFunc(__cameraHandle);
896 r = ConvertResult(err);
897 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. i:%d", GetErrorMessage(r), i);
899 // Check whether the retuned states are destinationed states.
900 postState = GetCameraState();
901 SysTryCatch(NID_MEDIA, destState == postState, r = E_INVALID_STATE, E_INVALID_STATE,
902 "[E_INVALID_STATE] camera_state_e of C-API is in an invalid state. result preState:%d, is different from the desired state:%d", postState,
904 SysLog(NID_MEDIA, "[E_SUCCESS] Found. result postState:%d, param destState:%d", postState,
911 SysTryCatch(NID_MEDIA, i != tableTotalCount, r = E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] Not found. ");
915 SysLog(NID_MEDIA, "[%s] Real preState:%d, param destState:%d", GetErrorMessage(r), preState, destState);
920 _CameraCoordinator::ChangeRecorderStateTo(recorder_state_e destState)
922 result r = E_SUCCESS;
923 int tableTotalCount = 0;
925 int err = MM_SUCCESS;
926 recorder_state_e preState = ::RECORDER_STATE_NONE;
927 recorder_state_e postState = ::RECORDER_STATE_NONE;
929 preState = GetRecorderState();
930 tableTotalCount = sizeof(_RECORDER_STATE_TRANSIT) / sizeof(_RECORDER_STATE_TRANSIT[0]);
931 SysLog(NID_MEDIA, " PreState:%d, destState:%d, tableTotalCount:%d", preState, destState, tableTotalCount);
933 for (i = 0; i < tableTotalCount; i++)
935 if (preState == _RECORDER_STATE_TRANSIT[i].prevState && destState == _RECORDER_STATE_TRANSIT[i].postState)
937 if (_RECORDER_STATE_TRANSIT[i].pFunc != null)
940 "Exist the matching state field. loop i:%d, current state:%d, destState:%d", i,
941 preState, destState);
942 err = _RECORDER_STATE_TRANSIT[i].pFunc(__recorderHandle);
943 r = ConvertResult(err);
944 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. i:%d", GetErrorMessage(r), i);
946 // Check whether the retuned states are destinationed states.
947 postState = GetRecorderState();
948 SysTryCatch(NID_MEDIA, destState == postState, r = E_INVALID_STATE, E_INVALID_STATE,
949 "[E_INVALID_STATE] recorder_state_e of C-API is in an invalid state. result preState:%d, is different from the desired state:%d", postState,
951 SysLog(NID_MEDIA, "[E_SUCCESS] Found. result preState:%d, param destState:%d", postState,
958 SysTryCatch(NID_MEDIA, i != tableTotalCount, r = E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] Not found. ");
962 SysLog(NID_MEDIA, "[%s] Real preState:%d, param destState:%d", GetErrorMessage(r), preState, destState);
967 _CameraCoordinator::SetCameraSourceFormat(camera_pixel_format_e pixelFormat)
969 result r = E_SUCCESS;
970 int err = MM_SUCCESS;
971 SysLog(NID_MEDIA, "Camera_pixel_format_e is :%d", pixelFormat);
973 err = camera_set_preview_format(__cameraHandle, pixelFormat);
974 r = ConvertResult(err);
975 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating, pixelFormat:%d", GetErrorMessage(r), pixelFormat);
983 camera_pixel_format_e
984 _CameraCoordinator::GetCameraSourceFormat(void) const
986 result r = E_SUCCESS;
987 int err = MM_SUCCESS;
988 camera_pixel_format_e pixelFormat = CAMERA_PIXEL_FORMAT_INVALID;
990 err = camera_get_preview_format(__cameraHandle, &pixelFormat);
991 r = ConvertResult(err);
992 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
1001 _CameraCoordinator::StartCapture(camera_capturing_cb capturingCb , camera_capture_completed_cb completedCb , void *pUserData)
1003 result r = E_SUCCESS;
1004 int err = MM_SUCCESS;
1006 if (__orientationFlag & _ORIENTATION_FOR_CAMERA)
1008 r = SetCameraOrientationAttr(__cameraOrientation);
1009 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1011 else if (__orientationFlag & _ORIENTATION_FOR_RECORDING) // If recorder setting is remained.
1013 r = SetCameraOrientationAttr(CAMERA_EXIF_ORIENTATION_TOP_LEFT); // To set the init value
1014 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1017 err = camera_start_capture(__cameraHandle, capturingCb, completedCb, pUserData);
1018 r = ConvertResult(err);
1019 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Camera capture failed.", GetErrorMessage(r));
1025 _CameraCoordinator::StartRecord(void)
1027 result r = E_SUCCESS;
1028 int err = MM_SUCCESS;
1030 if (__orientationFlag & _ORIENTATION_FOR_RECORDING)
1032 r = SetRecordingOrientationAttr(__recordingRotation);
1033 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1035 else if (__orientationFlag & _ORIENTATION_FOR_CAMERA) // If recorder setting is remained.
1037 r = SetRecordingOrientationAttr(RECORDING_ROTATION_NONE); // To set the init value
1038 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1041 err = recorder_start(__recorderHandle);
1042 r = ConvertResult(err);
1043 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Recorder record failed.", GetErrorMessage(r));
1049 _CameraCoordinator::SetRecordingOrientation(RecordingRotation rotation)
1051 __orientationFlag = __orientationFlag | _ORIENTATION_FOR_RECORDING;
1052 __recordingRotation = rotation;
1056 _CameraCoordinator::SetCameraOrientation(CameraExifOrientation orientation)
1058 __orientationFlag = __orientationFlag | _ORIENTATION_FOR_CAMERA;
1059 __cameraOrientation = orientation;
1063 _CameraCoordinator::SetRecordingOrientationAttr(RecordingRotation rotation)
1065 result r = E_SUCCESS;
1066 int err = MM_SUCCESS;
1067 #if _VIDEO_RECORDER_ROTATION_
1068 recorder_rotation_e mmAttr = ::RECORDER_ROTATION_NONE;
1069 r = _RecorderUtil::GetMmRotation(rotation, mmAttr);
1070 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. rotation:%d", GetErrorMessage(r), rotation);
1072 err = recorder_attr_set_recording_orientation(__recorderHandle, mmAttr);
1073 r = ConvertResult(err);
1074 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Camcorder set attribute failed. rotation:%d", GetErrorMessage(r), rotation);
1076 CameraRotation cameraRotation = CAMERA_ROTATION_NONE;
1077 r = _RecorderUtil::GetCameraRotation(rotation, cameraRotation);
1078 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. rotation:%d", GetErrorMessage(r), rotation);
1080 camera_attr_tag_orientation_e mmOrientationAttr = CAMERA_ATTR_TAG_ORIENTATION_TOP_LEFT;
1081 r = _CameraUtil::GetMmExifOrientation(cameraRotation, mmOrientationAttr);
1082 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. rotation:%d", GetErrorMessage(r), rotation);
1084 err = camera_attr_set_tag_orientation(__cameraHandle, mmOrientationAttr);
1085 r = ConvertResult(err);
1086 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Camcorder set attribute failed. Mm orientation:%d", GetErrorMessage(r), mmOrientationAttr);
1093 _CameraCoordinator::SetCameraOrientationAttr(CameraExifOrientation orientation)
1095 result r = E_SUCCESS;
1096 int err = MM_SUCCESS;
1097 camera_attr_tag_orientation_e attr = ::CAMERA_ATTR_TAG_ORIENTATION_TOP_LEFT;
1099 r = _CameraUtil::GetMmExifOrientation(orientation, attr);
1100 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. orientation:%d", GetErrorMessage(r), orientation);
1102 err = camera_attr_set_tag_orientation(__cameraHandle, attr);
1103 r = ConvertResult(err);
1104 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. orientation:%d", GetErrorMessage(r), orientation);