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 _CameraCoordinator* pCoordinator = null;
97 std::unique_ptr <IListT <_CameraDeviceType>, _ListPtrUtil::Remover> pList (GetKeysN(), _ListPtrUtil::remover);
98 SysTryReturnVoidResult(NID_MEDIA, pList.get() != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] There is no instance.");
99 for (int i = 0; i < GetCount(); i++)
101 _CameraDeviceType deviceType = _CAMERA_DEVICE_NONE;
102 r = pList->GetAt(i, deviceType);
103 if (IsFailed(r) && deviceType == _CAMERA_DEVICE_NONE)
108 r = GetValue(deviceType, pCoordinator);
109 if (IsFailed(r) && pCoordinator == null)
117 _CameraCoordinator::_CameraCoordinator()
118 : __cameraDevice(_CAMERA_DEVICE_NONE)
119 , __cameraHandle(MM_INVALID_HANDLE)
120 , __recorderHandle(MM_INVALID_HANDLE)
121 , __mode(_CAMERA_MODE_NONE)
122 , __pListenerList(null, _ListPtrUtil::remover)
123 , __orientationFlag(0)
124 , __cameraOrientation(CAMERA_EXIF_ORIENTATION_TOP_LEFT)
125 , __recordingRotation(RECORDING_ROTATION_NONE)
129 _CameraCoordinator::~_CameraCoordinator()
131 _CameraManager::Release(__cameraDevice);
132 SysLog(NID_MEDIA, "Camera manager released");
136 _CameraCoordinator::Construct(_CameraDeviceType cameraDevice)
138 result r = E_SUCCESS;
139 _CameraManager* pCameraManager = null;
140 SysLog(NID_MEDIA, "Enter. camera device:%d", cameraDevice);
142 pCameraManager = _CameraManager::AddInstance(cameraDevice);
144 SysTryReturn(NID_MEDIA, pCameraManager !=null && r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
146 __cameraHandle = pCameraManager->GetHandle();
148 __pListenerList.reset(new (std::nothrow) LinkedListT <_ICameraCoordinatorListener*>());
149 SysTryReturn(NID_MEDIA, __pListenerList.get() !=null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
151 __cameraDevice = cameraDevice;
152 __mode = _CAMERA_MODE_IMAGE;
158 _CameraCoordinator::AddRecorder(_RecorderDeviceType recorderDevice)
160 result r = E_SUCCESS;
161 _RecorderManager* pRecorderManager = null;
162 SysLog(NID_MEDIA, "Enter. recorder device:%d", recorderDevice);
164 pRecorderManager = _RecorderManager::AddInstance(recorderDevice);
166 SysTryCatch(NID_MEDIA, pRecorderManager !=null && r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
168 __recorderHandle = pRecorderManager->GetHandle(); // new recorder handle
177 _CameraCoordinator::RemoveRecorder(_RecorderDeviceType recorderDevice)
179 SysLog(NID_MEDIA, "Enter. recorder device:%d", recorderDevice);
180 _RecorderManager::Release(recorderDevice);
181 __recorderHandle = MM_INVALID_HANDLE;
182 __orientationFlag = __orientationFlag & (~_ORIENTATION_FOR_RECORDING);
186 _CameraCoordinator::AddInstance(_CameraDeviceType cameraDevice)
188 result r = E_SUCCESS;
192 static bool isMapConstructed = false;
193 static _CameraCoordinatorSafeHashMapT map;
194 _CameraCoordinator* pCoordinator = null;
196 SysTryReturn(NID_MEDIA, cameraDevice > _CAMERA_DEVICE_NONE && cameraDevice < _CAMERA_DEVICE_MAX,
197 null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(camderDevice) is used. camderDevice:%d is wrong.", cameraDevice);
199 if (!isMapConstructed)
202 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
203 isMapConstructed = true;
207 r = map.ContainsKey(cameraDevice, out);
208 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
212 r = map.GetValue(cameraDevice, pCoordinator);
213 SysTryReturn(NID_MEDIA, r == E_SUCCESS && pCoordinator != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
217 std::unique_ptr <_CameraCoordinator> pCoord (new (std::nothrow) _CameraCoordinator());
218 SysTryReturn(NID_MEDIA, pCoord.get() !=null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
220 r = pCoord->Construct(cameraDevice);
221 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
223 r = map.Add(cameraDevice, pCoord.get());
224 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
226 pCoordinator = pCoord.release();
229 pCoordinator->AddRefCount();
234 _CameraCoordinator::AddInstance(_RecorderDeviceType recorderDevice)
236 _CameraCoordinator* pCoordinator = null;
237 _CameraDeviceType cameraDevice = _CAMERA_DEVICE_NONE;
240 switch (recorderDevice)
242 case _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA:
243 cameraDevice = _CAMERA_DEVICE_PRIMARY;
246 case _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA:
247 cameraDevice = _CAMERA_DEVICE_SECONDARY;
254 if (cameraDevice == _CAMERA_DEVICE_NONE)
256 SysLogException(NID_MEDIA, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(recorderDevice) is used. recorderDevice :%d is wrong.", recorderDevice);
260 pCoordinator = AddInstance(cameraDevice);
261 if (pCoordinator == null)
263 SysLogException(NID_MEDIA, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The camera device(%d)'s coordinator is not available.", cameraDevice);
270 _CameraCoordinator::Release(_CameraDeviceType cameraDevice)
272 result r = E_SUCCESS;
276 _CameraCoordinator* pCoordinator = null;
277 r = __pMap->GetValue(cameraDevice, pCoordinator);
278 SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
280 if (pCoordinator->ReleaseRefCount() == 0)
283 r = __pMap->Remove(cameraDevice);
284 SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
290 _CameraCoordinator::Release(_RecorderDeviceType recorderDevice)
294 _CameraDeviceType cameraDevice = _CAMERA_DEVICE_NONE;
296 switch (recorderDevice)
298 case _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA:
299 cameraDevice = _CAMERA_DEVICE_PRIMARY;
301 case _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA:
302 cameraDevice = _CAMERA_DEVICE_SECONDARY;
308 Release(cameraDevice);
313 _CameraCoordinator::HasInstance(_CameraDeviceType cameraDevice)
315 result r = E_SUCCESS;
316 _CameraCoordinator* pCoordinator = null;
320 SysTryReturn(NID_MEDIA, cameraDevice > _CAMERA_DEVICE_NONE && cameraDevice < _CAMERA_DEVICE_MAX,
321 null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(camderDevice) is used. camderDevice:%d is wrong.", cameraDevice);
322 SysTryReturn(NID_MEDIA, __pMap != null, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] No coordinator was created.");
324 r = __pMap->ContainsKey(cameraDevice, out);
325 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
326 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);
328 r = __pMap->GetValue(cameraDevice, pCoordinator);
329 SysTryCatch(NID_MEDIA, r == E_SUCCESS && pCoordinator != null, , r, "[%s] Propagating.", GetErrorMessage(r));
338 _CameraCoordinator::HasInstance(_RecorderDeviceType recorderDevice)
340 _CameraCoordinator* pCoordinator = null;
341 _CameraDeviceType cameraDevice = _CAMERA_DEVICE_NONE;
344 switch (recorderDevice)
346 case _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA:
347 cameraDevice = _CAMERA_DEVICE_PRIMARY;
350 case _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA:
351 cameraDevice = _CAMERA_DEVICE_SECONDARY;
358 if (cameraDevice == _CAMERA_DEVICE_NONE)
360 SysLogException(NID_MEDIA, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(recorderDevice) is used. recorderDevice :%d is wrong.", recorderDevice);
364 pCoordinator = HasInstance(cameraDevice);
365 if (pCoordinator == null)
367 SysLogException(NID_MEDIA, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The camera device(%d)'s coordinator is not available.", cameraDevice);
374 _CameraCoordinator::AddCameraCoordinatorListener(_ICameraCoordinatorListener& listener)
376 result r = E_SUCCESS;
377 r = __pListenerList->Add(&listener);
382 _CameraCoordinator::RemoveCameraCoordinatorListener(_ICameraCoordinatorListener& listener)
384 result r = E_SUCCESS;
385 r = __pListenerList->Remove(&listener);
390 _CameraCoordinator::GetMode(void) const
396 _CameraCoordinator::GetCameraHandle(void) const
398 return __cameraHandle;
402 _CameraCoordinator::GetRecorderHandle(void) const
404 return __recorderHandle;
408 _CameraCoordinator::NotifyModeChangePrepared(_CameraMode mode)
410 result r = E_SUCCESS;
411 _ICameraCoordinatorListener* pListener = null;
412 SysLog(NID_MEDIA, "mode:%d", mode);
414 std::unique_ptr <IEnumeratorT <_ICameraCoordinatorListener*> > pEnum (__pListenerList->GetEnumeratorN());
415 SysTryReturn(NID_MEDIA, pEnum.get() != null, GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
417 while (pEnum->MoveNext() == E_SUCCESS)
419 r = pEnum->GetCurrent(pListener);
420 SysTryReturn(NID_MEDIA, pListener != null && r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
421 "[E_SYSTEM] A system error has been occurred. The listener is not proper");
423 r = pListener->OnCameraCoordinatorModeChangePrepared(mode);
424 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
430 _CameraCoordinator::NotifyModeChanged(_CameraMode mode)
432 result r = E_SUCCESS;
433 _ICameraCoordinatorListener* pListener = null;
434 SysLog(NID_MEDIA, "mode:%d", mode);
436 std::unique_ptr <IEnumeratorT <_ICameraCoordinatorListener*> > pEnum (__pListenerList->GetEnumeratorN());
437 SysTryReturn(NID_MEDIA, pEnum.get() != null, GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
439 while (pEnum->MoveNext() == E_SUCCESS)
441 r = pEnum->GetCurrent(pListener);
442 SysTryReturn(NID_MEDIA, pListener != null && r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
443 "[E_SYSTEM] A system error has been occurred. The listener is not proper");
445 r = pListener->OnCameraCoordinatorModeChanged(mode);
446 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
452 _CameraCoordinator::StartMmPreview(void)
454 result r = E_SUCCESS;
455 SysLog(NID_MEDIA, "Enter. mode:%d", __mode);
459 case _CAMERA_MODE_IMAGE:
460 r = ChangeCameraStateTo(::CAMERA_STATE_PREVIEW);
461 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
464 case _CAMERA_MODE_VIDEO:
465 r = ChangeRecorderStateTo(::RECORDER_STATE_READY);
466 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
470 SysLogException(NID_MEDIA, E_INVALID_STATE, "[E_INVALID_STATE] Camera is in an invalid state. Camcorder mode :%d is wrong", __mode);
480 _CameraCoordinator::StopMmPreview(void)
482 result r = E_SUCCESS;
483 SysLog(NID_MEDIA, "Enter.");
485 if (__mode == _CAMERA_MODE_IMAGE)
487 r = ChangeCameraStateTo(::CAMERA_STATE_CREATED);
488 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
490 else if (__mode == _CAMERA_MODE_VIDEO)
492 recorder_state_e recorderState = ::RECORDER_STATE_NONE;
493 recorderState = GetRecorderState();
495 switch (recorderState)
497 case ::RECORDER_STATE_RECORDING:
498 r = ChangeRecorderStateTo(::RECORDER_STATE_READY);
499 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
501 r = ChangeRecorderStateTo(::RECORDER_STATE_CREATED);
502 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
505 case ::RECORDER_STATE_READY:
506 r = ChangeRecorderStateTo(::RECORDER_STATE_CREATED);
507 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
512 SysLogException(NID_MEDIA, E_INVALID_STATE, "[E_INVALID_STATE] recorderState is in an invalid state. recorderState:%d", recorderState);
519 SysLogException(NID_MEDIA, E_INVALID_STATE, "[E_INVALID_STATE] CamcorderMode is in an invalid state. mode :%d", __mode);
527 _CameraCoordinator::ChangeMode(_CameraMode mode, bool callback)
529 result r = E_SUCCESS;
530 camera_state_e cameraState = ::CAMERA_STATE_NONE;
531 recorder_state_e recorderState = ::RECORDER_STATE_NONE;
532 _RecorderDeviceType recorderDevice = _RECORDER_DEVICE_NONE;
533 int err = MM_SUCCESS;
535 SysLog(NID_MEDIA, "Mode should be changed. mode:%d", mode);
536 if (mode == _CAMERA_MODE_VIDEO)
538 cameraState = GetCameraState();
542 case ::CAMERA_STATE_CREATED:
544 case ::CAMERA_STATE_NONE:
547 case ::CAMERA_STATE_PREVIEW:
549 case ::CAMERA_STATE_CAPTURED:
550 r = ChangeCameraStateTo(::CAMERA_STATE_CREATED);
551 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
554 case ::CAMERA_STATE_CAPTURING:
556 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);
565 if ( __recorderHandle == MM_INVALID_HANDLE )
567 recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
568 _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
569 r = AddRecorder(recorderDevice); // recorder_create() will be called.
570 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
571 __mode = _CAMERA_MODE_VIDEO;
576 r = NotifyModeChangePrepared(mode);
577 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
582 case ::CAMERA_STATE_NONE:
584 case ::CAMERA_STATE_CREATED:
587 case ::CAMERA_STATE_PREVIEW:
588 r = ChangeRecorderStateTo(::RECORDER_STATE_READY);
589 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
592 case ::CAMERA_STATE_CAPTURED:
597 else if ( mode == _CAMERA_MODE_IMAGE )
599 recorderState = GetRecorderState();
602 switch (recorderState)
604 case ::RECORDER_STATE_NONE:
607 case ::RECORDER_STATE_CREATED:
608 recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
609 _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
610 RemoveRecorder(recorderDevice); // the mode will be changed to IMAGE.
611 __mode = _CAMERA_MODE_IMAGE;
614 case ::RECORDER_STATE_READY:
615 r = ChangeRecorderStateTo(::RECORDER_STATE_CREATED);
616 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
618 recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
619 _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
620 RemoveRecorder(recorderDevice);
621 __mode = _CAMERA_MODE_IMAGE;
624 r = NotifyModeChangePrepared(mode);
625 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
627 r = ChangeCameraStateTo(::CAMERA_STATE_PREVIEW);
628 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
631 case ::RECORDER_STATE_RECORDING:
633 case ::RECORDER_STATE_PAUSED:
634 err = recorder_cancel(__recorderHandle); // TODO
635 r = ConvertResult(err);
636 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
638 r = ChangeRecorderStateTo(::RECORDER_STATE_CREATED);
639 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
640 recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
641 _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
643 RemoveRecorder(recorderDevice);
644 __mode = _CAMERA_MODE_IMAGE;
647 r = NotifyModeChangePrepared(mode);
648 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
650 r = ChangeCameraStateTo(::CAMERA_STATE_PREVIEW);
651 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
661 // Notify that the mode is changed to callback camera and video recorder's configurations.
662 r = NotifyModeChanged(mode);
663 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
673 _CameraCoordinator::IsCalmChangeMode(_CameraMode mode)
675 camera_state_e cameraState = ::CAMERA_STATE_NONE;
676 recorder_state_e recorderState = ::RECORDER_STATE_NONE;
677 bool calmChange = false;
679 if (mode == _CAMERA_MODE_VIDEO)
681 cameraState = GetCameraState();
685 case ::CAMERA_STATE_CREATED:
687 case ::CAMERA_STATE_NONE:
691 case ::CAMERA_STATE_PREVIEW:
693 case ::CAMERA_STATE_CAPTURED:
695 case ::CAMERA_STATE_CAPTURING:
703 else if ( mode == _CAMERA_MODE_IMAGE )
705 recorderState = GetRecorderState();
708 switch (recorderState)
710 case ::RECORDER_STATE_NONE:
712 case ::RECORDER_STATE_CREATED:
716 case ::RECORDER_STATE_READY:
718 case ::RECORDER_STATE_RECORDING:
720 case ::RECORDER_STATE_PAUSED:
729 SysLog(NID_MEDIA, "mode:%d, calm:%d", mode, calmChange);
735 _CameraCoordinator::GetCameraDevice(void) const
737 return __cameraDevice;
741 _CameraCoordinator::GetCameraState(void) const
743 result r = E_SUCCESS;
744 int err = MM_SUCCESS;
745 camera_state_e state = ::CAMERA_STATE_NONE;
747 err = camera_get_state(__cameraHandle, &state);
748 r = ConvertResult(err);
749 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
754 return ::CAMERA_STATE_NONE;
758 _CameraCoordinator::GetRecorderState(void) const
760 result r = E_SUCCESS;
761 int err = MM_SUCCESS;
762 recorder_state_e state = ::RECORDER_STATE_NONE;
764 err = recorder_get_state(__recorderHandle, &state);
765 r = ConvertResult(err);
766 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
771 return ::RECORDER_STATE_NONE;
775 _CameraCoordinator::ConvertResult(int err) const
778 if (err != CAMERA_ERROR_NONE)
780 SysLog(NID_MEDIA, "MM Err:0x%x", err);
784 if (err == CAMERA_ERROR_NONE || err == RECORDER_ERROR_NONE)
788 else if (err == CAMERA_ERROR_INVALID_PARAMETER || err == RECORDER_ERROR_INVALID_PARAMETER)
792 else if (err == CAMERA_ERROR_INVALID_STATE || err == RECORDER_ERROR_INVALID_STATE)
796 else if (err == CAMERA_ERROR_OUT_OF_MEMORY || err == RECORDER_ERROR_OUT_OF_MEMORY)
800 else if (err == CAMERA_ERROR_DEVICE || err == RECORDER_ERROR_DEVICE)
804 else if (err == CAMERA_ERROR_INVALID_OPERATION
805 || err == CAMERA_ERROR_SECURITY_RESTRICTED
806 || err == RECORDER_ERROR_INVALID_OPERATION
807 || err == RECORDER_ERROR_SECURITY_RESTRICTED)
811 else if (err == CAMERA_ERROR_DEVICE_BUSY
812 || err == CAMERA_ERROR_SOUND_POLICY
813 || err == RECORDER_ERROR_SOUND_POLICY)
817 else if (err == CAMERA_ERROR_DEVICE_NOT_FOUND)
819 r = E_DEVICE_UNAVAILABLE;
831 _CameraCoordinator::ChangeCameraStateTo(camera_state_e destState)
833 result r = E_SUCCESS;
834 int tableTotalCount = 0;
836 int err = MM_SUCCESS;
837 camera_state_e preState = ::CAMERA_STATE_NONE;
838 camera_state_e postState = ::CAMERA_STATE_NONE;
840 preState = GetCameraState();
841 tableTotalCount = sizeof(_CAMERA_STATE_TRANSIT) / sizeof(_CAMERA_STATE_TRANSIT[0]);
842 SysLog(NID_MEDIA, " PreState:%d, destState:%d, tableTotalCount:%d", preState, destState, tableTotalCount);
844 for (i = 0; i < tableTotalCount; i++)
846 if (preState == _CAMERA_STATE_TRANSIT[i].prevState && destState == _CAMERA_STATE_TRANSIT[i].postState)
848 if (_CAMERA_STATE_TRANSIT[i].pFunc != null)
851 "Exist the matching state field. loop i:%d, current state:%d, destState:%d", i,
852 preState, destState);
853 err = _CAMERA_STATE_TRANSIT[i].pFunc(__cameraHandle);
854 r = ConvertResult(err);
855 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. i:%d", GetErrorMessage(r), i);
857 // Check whether the retuned states are destinationed states.
858 postState = GetCameraState();
859 SysTryCatch(NID_MEDIA, destState == postState, r = E_INVALID_STATE, E_INVALID_STATE,
860 "[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,
862 SysLog(NID_MEDIA, "[E_SUCCESS] Found. result postState:%d, param destState:%d", postState,
869 SysTryCatch(NID_MEDIA, i != tableTotalCount, r = E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] Not found. ");
873 SysLog(NID_MEDIA, "[%s] Real preState:%d, param destState:%d", GetErrorMessage(r), preState, destState);
878 _CameraCoordinator::ChangeRecorderStateTo(recorder_state_e destState)
880 result r = E_SUCCESS;
881 int tableTotalCount = 0;
883 int err = MM_SUCCESS;
884 recorder_state_e preState = ::RECORDER_STATE_NONE;
885 recorder_state_e postState = ::RECORDER_STATE_NONE;
887 preState = GetRecorderState();
888 tableTotalCount = sizeof(_RECORDER_STATE_TRANSIT) / sizeof(_RECORDER_STATE_TRANSIT[0]);
889 SysLog(NID_MEDIA, " PreState:%d, destState:%d, tableTotalCount:%d", preState, destState, tableTotalCount);
891 for (i = 0; i < tableTotalCount; i++)
893 if (preState == _RECORDER_STATE_TRANSIT[i].prevState && destState == _RECORDER_STATE_TRANSIT[i].postState)
895 if (_RECORDER_STATE_TRANSIT[i].pFunc != null)
898 "Exist the matching state field. loop i:%d, current state:%d, destState:%d", i,
899 preState, destState);
900 err = _RECORDER_STATE_TRANSIT[i].pFunc(__recorderHandle);
901 r = ConvertResult(err);
902 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. i:%d", GetErrorMessage(r), i);
904 // Check whether the retuned states are destinationed states.
905 postState = GetRecorderState();
906 SysTryCatch(NID_MEDIA, destState == postState, r = E_INVALID_STATE, E_INVALID_STATE,
907 "[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,
909 SysLog(NID_MEDIA, "[E_SUCCESS] Found. result preState:%d, param destState:%d", postState,
916 SysTryCatch(NID_MEDIA, i != tableTotalCount, r = E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] Not found. ");
920 SysLog(NID_MEDIA, "[%s] Real preState:%d, param destState:%d", GetErrorMessage(r), preState, destState);
925 _CameraCoordinator::SetCameraSourceFormat(camera_pixel_format_e pixelFormat)
927 result r = E_SUCCESS;
928 int err = MM_SUCCESS;
929 SysLog(NID_MEDIA, "Camera_pixel_format_e is :%d", pixelFormat);
931 err = camera_set_preview_format(__cameraHandle, pixelFormat);
932 r = ConvertResult(err);
933 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating, pixelFormat:%d", GetErrorMessage(r), pixelFormat);
941 camera_pixel_format_e
942 _CameraCoordinator::GetCameraSourceFormat(void) const
944 result r = E_SUCCESS;
945 int err = MM_SUCCESS;
946 camera_pixel_format_e pixelFormat = CAMERA_PIXEL_FORMAT_INVALID;
948 err = camera_get_preview_format(__cameraHandle, &pixelFormat);
949 r = ConvertResult(err);
950 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
959 _CameraCoordinator::StartCapture(camera_capturing_cb capturingCb , camera_capture_completed_cb completedCb , void *pUserData)
961 result r = E_SUCCESS;
962 int err = MM_SUCCESS;
964 if (__orientationFlag & _ORIENTATION_FOR_CAMERA)
966 r = SetCameraOrientationAttr(__cameraOrientation);
967 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
969 else if (__orientationFlag & _ORIENTATION_FOR_RECORDING) // If recorder setting is remained.
971 r = SetCameraOrientationAttr(CAMERA_EXIF_ORIENTATION_TOP_LEFT); // To set the init value
972 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
975 err = camera_start_capture(__cameraHandle, capturingCb, completedCb, pUserData);
976 r = ConvertResult(err);
977 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Camera capture failed.", GetErrorMessage(r));
983 _CameraCoordinator::StartRecord(void)
985 result r = E_SUCCESS;
986 int err = MM_SUCCESS;
988 if (__orientationFlag & _ORIENTATION_FOR_RECORDING)
990 r = SetRecordingOrientationAttr(__recordingRotation);
991 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
993 else if (__orientationFlag & _ORIENTATION_FOR_CAMERA) // If recorder setting is remained.
995 r = SetRecordingOrientationAttr(RECORDING_ROTATION_NONE); // To set the init value
996 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
999 err = recorder_start(__recorderHandle);
1000 r = ConvertResult(err);
1001 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Recorder record failed.", GetErrorMessage(r));
1007 _CameraCoordinator::SetRecordingOrientation(RecordingRotation rotation)
1009 __orientationFlag = __orientationFlag | _ORIENTATION_FOR_RECORDING;
1010 __recordingRotation = rotation;
1014 _CameraCoordinator::SetCameraOrientation(CameraExifOrientation orientation)
1016 __orientationFlag = __orientationFlag | _ORIENTATION_FOR_CAMERA;
1017 __cameraOrientation = orientation;
1021 _CameraCoordinator::SetRecordingOrientationAttr(RecordingRotation rotation)
1023 result r = E_SUCCESS;
1024 int err = MM_SUCCESS;
1025 #if _VIDEO_RECORDER_ROTATION_
1026 recorder_rotation_e mmAttr = ::RECORDER_ROTATION_NONE;
1027 r = _RecorderUtil::GetMmRotation(rotation, mmAttr);
1028 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. rotation:%d", GetErrorMessage(r), rotation);
1030 err = recorder_attr_set_recording_orientation(__recorderHandle, mmAttr);
1031 r = ConvertResult(err);
1032 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Camcorder set attribute failed. rotation:%d", GetErrorMessage(r), rotation);
1034 CameraRotation cameraRotation = CAMERA_ROTATION_NONE;
1035 r = _RecorderUtil::GetCameraRotation(rotation, cameraRotation);
1036 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. rotation:%d", GetErrorMessage(r), rotation);
1038 camera_attr_tag_orientation_e mmOrientationAttr = CAMERA_ATTR_TAG_ORIENTATION_TOP_LEFT;
1039 r = _CameraUtil::GetMmExifOrientation(cameraRotation, mmOrientationAttr);
1040 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. rotation:%d", GetErrorMessage(r), rotation);
1042 err = camera_attr_set_tag_orientation(__cameraHandle, mmOrientationAttr);
1043 r = ConvertResult(err);
1044 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Camcorder set attribute failed. Mm orientation:%d", GetErrorMessage(r), mmOrientationAttr);
1051 _CameraCoordinator::SetCameraOrientationAttr(CameraExifOrientation orientation)
1053 result r = E_SUCCESS;
1054 int err = MM_SUCCESS;
1055 camera_attr_tag_orientation_e attr = ::CAMERA_ATTR_TAG_ORIENTATION_TOP_LEFT;
1057 r = _CameraUtil::GetMmExifOrientation(orientation, attr);
1058 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. orientation:%d", GetErrorMessage(r), orientation);
1060 err = camera_attr_set_tag_orientation(__cameraHandle, attr);
1061 r = ConvertResult(err);
1062 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. orientation:%d", GetErrorMessage(r), orientation);