Merge tizen_2.1 into tizen_2.2
[platform/framework/native/media.git] / src / FMedia_VideoRecorderImpl.cpp
index dd51612..3856937 100755 (executable)
@@ -38,6 +38,9 @@
 #include "FMedia_RecorderCapability.h"
 #include "FMedia_CamPtrUtil.h"
 #include "FMedia_AudioStreamCoordinator.h"
+#include "FMedia_RecorderRef.h"
+
+//#define _VIDEO_RECORDER_ROTATION_
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -73,8 +76,9 @@ static const _VideoCommandStateTable _VIDEO_COMMAND_STATE[] =
        {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_PAUSED, _RECORDER_STATE_REASON_NORMAL, recorder_pause, RECORDER_STATE_PAUSING },
        {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL, recorder_commit, RECORDER_STATE_STOPPING },
        {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_CANCEL, recorder_cancel, RECORDER_STATE_STOPPING },
-       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_SIZE_REACHED, recorder_commit, RECORDER_STATE_RECORDING },
-       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_TIME_REACHED, recorder_commit, RECORDER_STATE_RECORDING },
+       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_SIZE_REACHED, recorder_commit, RECORDER_STATE_STOPPING },
+       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_TIME_REACHED, recorder_commit, RECORDER_STATE_STOPPING },
+       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_OUT_OF_STORAGE, recorder_commit, RECORDER_STATE_STOPPING },
        {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_RECORDING, _RECORDER_STATE_REASON_NORMAL, recorder_start, RECORDER_STATE_STARTING },
        {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL, recorder_commit, RECORDER_STATE_STOPPING },
        {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_CANCEL, recorder_cancel, RECORDER_STATE_STOPPING },
@@ -87,21 +91,21 @@ typedef struct
        recorder_state_e postState;
        _RecorderStateChangeReason reason;
        _RecorderEventType event;
-       RecorderErrorReason error;
+       result r;
 }_VideoCallbackEventTable;
 
 static const _VideoCallbackEventTable _VIDEO_CALLBACK_EVENT[] =
 {
-       {::RECORDER_STATE_READY, ::RECORDER_STATE_RECORDING, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_RECORDING_STARTED, RECORDER_ERROR_NONE },
-       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_PAUSED, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_PAUSED, RECORDER_ERROR_NONE },
-       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_STOPPED, RECORDER_ERROR_NONE },
-       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_CANCEL, _RECORDER_EVENT_CANCELED, RECORDER_ERROR_NONE },
-       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_SIZE_REACHED, _RECORDER_EVENT_ENDOF_FILESIZE, RECORDER_ERROR_NONE },
-       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_TIME_REACHED, _RECORDER_EVENT_ENDOF_RECTIME, RECORDER_ERROR_NONE },
-       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_OUT_OF_STORAGE, _RECORDER_EVENT_ERROR, RECORDER_ERROR_OUT_OF_STORAGE },
-       {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_RECORDING, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_RECORDING_STARTED, RECORDER_ERROR_NONE },
-       {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_STOPPED, RECORDER_ERROR_NONE },
-//     {::RECORDER_STATE_READY, ::RECORDER_STATE_CREATED, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_CLOSED, RECORDER_ERROR_NONE },
+       {::RECORDER_STATE_READY, ::RECORDER_STATE_RECORDING, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_RECORDING_STARTED, E_SUCCESS },
+       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_PAUSED, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_PAUSED, E_SUCCESS },
+       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_STOPPED, E_SUCCESS },
+       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_CANCEL, _RECORDER_EVENT_CANCELED, E_SUCCESS },
+       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_SIZE_REACHED, _RECORDER_EVENT_ENDOF_FILESIZE, E_SUCCESS },
+       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_TIME_REACHED, _RECORDER_EVENT_ENDOF_RECTIME, E_SUCCESS },
+       {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_OUT_OF_STORAGE, _RECORDER_EVENT_STOPPED, E_SUCCESS },
+       {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_RECORDING, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_RECORDING_STARTED, E_SUCCESS },
+       {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_STOPPED, E_SUCCESS },
+//     {::RECORDER_STATE_READY, ::RECORDER_STATE_CREATED, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_CLOSED, E_SUCCESS },
 };
 
 typedef struct
@@ -122,10 +126,9 @@ static const _CodecValTable _CODEC_VAL_TABLE[] =
        {null,                                          CODEC_NONE,     CODEC_NONE,     MEDIA_CONTAINER_NONE}
 };
 
-bool _VideoRecorderImpl::__isUsed = false;
-
 _VideoRecorderImpl::_VideoRecorderImpl(void)
        : __pCoordinator(null)
+       , __pRecorderRef(null)
        , __pVideoRecorderEvent(null)
        , __pVideoRecorderEventListener(null)
        , __pVideoSourceAdapter(null)
@@ -170,17 +173,19 @@ _VideoRecorderImpl::~_VideoRecorderImpl(void)
        }
        if (__pCoordinator != null)
        {
-               __pCoordinator->ChangeMode(_CAMERA_MODE_IMAGE, false);
+               if (__pVideoSourceAdapter.get() != null)
+               {
+                       if (__pVideoSourceAdapter->GetUserPreviewFormat() != __pCoordinator->GetCameraSourceFormat())
+                       {
+                               __pCoordinator->ChangeFormat(_CAMERA_MODE_IMAGE, true, __pVideoSourceAdapter->GetUserPreviewFormat());
+                       }
+               }
+               __pCoordinator->DestroyVideoRecorder();
                __pCoordinator->RemoveCameraCoordinatorListener(*this);
 
                _CameraCoordinator::Release(__deviceType);
        }
 
-       if ( __isConstructed )
-       {
-               __isUsed = false;
-       }
-
        SysLog(NID_MEDIA, "video recorder Destroyed");
 }
 
@@ -190,25 +195,32 @@ _VideoRecorderImpl::Construct(IVideoRecorderEventListener& listener, const Camer
        result r = E_SUCCESS;
        Tizen::Media::Camera* pCamera = null;
        Tizen::Media::_CameraImpl* pCamImpl = null;
-       _CameraHandle cameraHandle = MM_INVALID_HANDLE;
        int err = MM_SUCCESS;
        int streamFps = 0;
        _CapabilityImpl* pCapabilityImpl = null;
 
-       SysTryReturn(NID_MEDIA, !__isUsed, E_DEVICE_BUSY, E_DEVICE_BUSY, "[E_DEVICE_BUSY] _VideoRecorderImpl is now being used.");
        SysTryReturn(NID_MEDIA, !__isConstructed, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state. A device is already constructed.");
        SysLog(NID_MEDIA, "video recorder construct");
 
        pCamera = const_cast<Tizen::Media::Camera*>(&camera);
        pCamImpl = _CameraImpl::GetInstance(pCamera);
+       __deviceType = (pCamImpl->GetSelection() == CAMERA_PRIMARY ? _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA
+               : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA);
+
+       // Register this object to _RecorderRef
+       __pRecorderRef.reset(new (std::nothrow) _RecorderRef());
+       SysTryCatch(NID_MEDIA, __pRecorderRef.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
+
+       r = __pRecorderRef->Construct(*this, __deviceType);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
        // Source Adapter
        __pVideoSourceAdapter.reset(new (std::nothrow) _VideoSourceAdapter(*pCamImpl));
-       SysTryCatch(NID_MEDIA, __pVideoSourceAdapter.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryCatch(NID_MEDIA, __pVideoSourceAdapter.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        // Create Event
        __pVideoRecorderEvent.reset(new (std::nothrow) _VideoRecorderEvent());
-       SysTryCatch(NID_MEDIA, __pVideoRecorderEvent.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryCatch(NID_MEDIA, __pVideoRecorderEvent.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = __pVideoRecorderEvent->Construct(*this);
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -219,28 +231,11 @@ _VideoRecorderImpl::Construct(IVideoRecorderEventListener& listener, const Camer
 
        // Create audio stream coordinator
        __pAudioStreamCoordinator.reset(new (std::nothrow) _AudioStreamCoordinator());
-       SysTryCatch(NID_MEDIA, __pAudioStreamCoordinator.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.      The object is not created.");
+       SysTryCatch(NID_MEDIA, __pAudioStreamCoordinator.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = __pAudioStreamCoordinator->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
-       // Get the capability
-       pCapabilityImpl = _CapabilityImpl::GetInstance();
-       SysTryCatch(NID_MEDIA, pCapabilityImpl != null, r= E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Capability is not obtained.");
-
-       r = pCapabilityImpl->GetValue(String(L"VideoRecorder.Device.fps"), streamFps);
-       //SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
-
-       streamFps = 50;
-
-       if (streamFps != 0)
-       {
-               __audioStreamTimeDuration = (1000/streamFps); //Time duration in milisec
-       }
-
-       __deviceType = (pCamImpl->GetSelection() == CAMERA_PRIMARY ? _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA
-               : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA);
-
        __pCoordinator = _CameraCoordinator::AddInstance(__deviceType);
        r = GetLastResult();
        SysTryCatch(NID_MEDIA, __pCoordinator != null, , r, "[E_OBJ_NOT_FOUND] _CameraCoordinator instance is not available.");
@@ -249,13 +244,19 @@ _VideoRecorderImpl::Construct(IVideoRecorderEventListener& listener, const Camer
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
        //If the reload flag is true, the __handle will be updated in the OnCameraCoordinatorModeChangePrepared(), otherwise the __handle should be updated manually.
-       r = __pCoordinator->ChangeMode(_CAMERA_MODE_VIDEO, false);              // Do not reload. The __mmSourceFormat is not set yet.
-       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder Mode change failed.", GetErrorMessage(r));
+       r = __pCoordinator->CreateVideoRecorder();              // Do not reload. The __mmSourceFormat is not set yet.
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] CreateVideoRecorder  failed.", GetErrorMessage(r));
 
        __handle = __pCoordinator->GetRecorderHandle();
-       cameraHandle = __pCoordinator->GetCameraHandle();
-       r = __pVideoSourceAdapter->SetRecommendPreviewFormat(cameraHandle);
-       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video adapter SetRecommendPreviewFormat failed.", GetErrorMessage(r));
+
+       // Get the capability
+       pCapabilityImpl = _CapabilityImpl::GetInstance();
+       SysTryCatch(NID_MEDIA, pCapabilityImpl != null, r= E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Capability is not obtained.");
+
+       // Get the audio stream fps
+       r = pCapabilityImpl->GetValue(VIDEORECORDER_DEVICE_FPS, streamFps);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS && streamFps > 0, , r, "[%s] Propagating. fps:%d", GetErrorMessage(r), streamFps);
+       __audioStreamTimeDuration = (1000/streamFps); //Time duration in milisec
 
        err = recorder_set_state_changed_cb(__handle, StateChangedCb, this);
        r = ConvertResult(err);
@@ -282,7 +283,6 @@ _VideoRecorderImpl::Construct(IVideoRecorderEventListener& listener, const Camer
 
        SetState(RECORDER_STATE_INITIALIZED);
        __isConstructed = true;
-       __isUsed = true;
 
        return r;
 
@@ -300,8 +300,15 @@ CATCH:
        if (__pCoordinator != null)
        {
                __pCoordinator->RemoveCameraCoordinatorListener(*this);
+               _CameraCoordinator::Release(__deviceType);
+               __pCoordinator = null;
        }
 
+       __pRecorderRef.reset(null);
+       __pVideoSourceAdapter.reset(null);
+       __pVideoRecorderEvent.reset(null);
+       __pAudioStreamCoordinator.reset(null);
+
        return r;
 }
 
@@ -355,31 +362,25 @@ _VideoRecorderImpl::CreateVideoFile(const Tizen::Base::String& mediaLocalPath, b
 
        state = GetState();
        SysTryReturn(NID_MEDIA, state == RECORDER_STATE_INITIALIZED || state == RECORDER_STATE_CLOSED,
-                               E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state.");
+                               E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state(%d).", state);
 
        std::unique_ptr<char[]> pFileName (_StringConverter::CopyToCharArrayN(mediaLocalPath));
        SysTryCatch(NID_MEDIA, pFileName.get() != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(mediaLocalPath) is used.  File name is null.");
-       SysLog(NID_MEDIA, "File Path : %s\n, overwrite:%d", pFileName.get(), overwrite);
+       SysSecureLog(NID_MEDIA, "File Path : %s\n, overwrite:%d", pFileName.get(), overwrite);
 
        r = _RecorderUtil::PrepareFile(mediaLocalPath, overwrite);
-       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder prepare file failed. mediaLocalPath:%s, overwirte:%d",
+       SysSecureTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder prepare file failed. mediaLocalPath:%s, overwirte:%d",
                           GetErrorMessage(r), pFileName.get(), overwrite);
 
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               err = recorder_set_filename(__handle, pFileName.get());
-               r = ConvertResult(err);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
-       }
+       err = recorder_set_filename(__handle, pFileName.get());
+       r = ConvertResult(err);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
        SetState(RECORDER_STATE_OPENED);
 
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               // re-configuration for new recorder handle
-               r = ReloadConfiguration(_RELOAD_FORMAT | _RELOAD_QUALITY | _RELOAD_MAX_TIME | _RELOAD_INIT | _RELOAD_ROTATION);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration failed", GetErrorMessage(r));
-       }
+       // re-configuration for new recorder handle
+       r = ReloadConfiguration(_RELOAD_FORMAT | _RELOAD_QUALITY | _RELOAD_MAX_TIME | _RELOAD_INIT | _RELOAD_ROTATION);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration failed", GetErrorMessage(r));
 
        __filePath = mediaLocalPath;
        return r;
@@ -398,13 +399,14 @@ _VideoRecorderImpl::Close(void)
 
        state = GetState();
        SysTryReturn(
-               NID_MEDIA, state == RECORDER_STATE_OPENED || state == RECORDER_STATE_STOPPED
+               NID_MEDIA, state == RECORDER_STATE_OPENED || state == RECORDER_STATE_STOPPED || state == RECORDER_STATE_STOPPING
                || state == RECORDER_STATE_ENDOF_FILE || state == RECORDER_STATE_ERROR
                           , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d", state);
 
        // Just send closed event
        r = GetEvent()->SendEvent(_RECORDER_EVENT_CLOSED, RECORDER_ERROR_NONE, E_SUCCESS);
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+       SetStateChangeReason(_RECORDER_STATE_REASON_NORMAL);
 
        return r;
 
@@ -424,6 +426,7 @@ _VideoRecorderImpl::Record(void)
        SysTryReturn(NID_MEDIA, state == RECORDER_STATE_OPENED || state == RECORDER_STATE_PAUSED
                           , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d",     state);
 
+       SysTryReturn(NID_MEDIA, __pVideoSourceAdapter.get() != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  The source is deleted.");
        if (__pVideoSourceAdapter->HasRecordingResolutionRestriction())
        {
                SysTryReturn(NID_MEDIA, __recordingResolution == __pVideoSourceAdapter->GetSourceResolution()
@@ -442,16 +445,17 @@ _VideoRecorderImpl::Record(void)
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Camera mode change failed.", GetErrorMessage(r));
 
                // If the preview data format is changed, the properties should be set again.
-               r = __pCoordinator->ChangeMode(_CAMERA_MODE_VIDEO, true);
+               r = __pCoordinator->ChangeFormat(_CAMERA_MODE_VIDEO, true, __mmSourceFormat);
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder Mode change failed.", GetErrorMessage(r));
        }
        else if ( __pCoordinator->GetMode() != _CAMERA_MODE_VIDEO )
        {
-               SysLog(NID_MEDIA, "Current mode is IMAGE. It should be moved to VIDEO mode.");
+               SysLog(NID_MEDIA, "Current Preview mm format format is default mm format format (%d). ", __pCoordinator->GetCameraSourceFormat());
 
                __mmSourceFormat = __pCoordinator->GetCameraSourceFormat();
-               r = __pCoordinator->ChangeMode(_CAMERA_MODE_VIDEO, true);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder Mode change failed.", GetErrorMessage(r));
+
+               r = ReloadConfiguration(_RELOAD_FORMAT | _RELOAD_QUALITY | _RELOAD_MAX_TIME | _RELOAD_FILE_PATH | _RELOAD_CALLBACK | _RELOAD_MUTE | _RELOAD_ROTATION);
+               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
        }
 
        mmState = GetMmState();
@@ -463,21 +467,21 @@ _VideoRecorderImpl::Record(void)
 
                r = __pCoordinator->StartRecord();
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder start failed.", GetErrorMessage(r));
-               __stateChangeReason = _RECORDER_STATE_REASON_NORMAL;
+               SetStateChangeReason(_RECORDER_STATE_REASON_NORMAL);
                SetState(RECORDER_STATE_STARTING);
                break;
 
        case ::RECORDER_STATE_READY:
                r = __pCoordinator->StartRecord();
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder start failed.", GetErrorMessage(r));
-               __stateChangeReason = _RECORDER_STATE_REASON_NORMAL;
+               SetStateChangeReason(_RECORDER_STATE_REASON_NORMAL);
                SetState(RECORDER_STATE_STARTING);
                break;
 
        case ::RECORDER_STATE_PAUSED:
                r = __pCoordinator->StartRecord();
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder resume failed.", GetErrorMessage(r));
-               __stateChangeReason = _RECORDER_STATE_REASON_NORMAL;
+               SetStateChangeReason(_RECORDER_STATE_REASON_NORMAL);
                SetState(RECORDER_STATE_STARTING);
                break;
 
@@ -590,11 +594,8 @@ _VideoRecorderImpl::SetMaxRecordingTime(long msTime)
        SysTryReturn(NID_MEDIA, msTime > 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] msTime is out of range. msTime:%d must be greater than 0.",
                                msTime);
 
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               r = SetMaxRecordingTimeAttr(msTime);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder set max recording time failed. msTime:%ls", GetErrorMessage(r), msTime);
-       }
+       r = SetMaxRecordingTimeAttr(msTime);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder set max recording time failed. msTime:%ls", GetErrorMessage(r), msTime);
        // For reload and Get the exact value
        __maxTime = msTime;
 
@@ -634,22 +635,16 @@ _VideoRecorderImpl::SetCodec(const Tizen::Base::String& codec)
        SysTryCatch(NID_MEDIA, audioCodec != CODEC_NONE && videoCodec != CODEC_NONE, r = E_UNSUPPORTED_CODEC, E_UNSUPPORTED_CODEC
                , "[E_UNSUPPORTED_CODEC]. This codec(%ls) is not supported in the device.\n", codec.GetPointer());
 
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               r = SetFormatAttr(audioCodec, videoCodec, container);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] File format set  failed. audioCodec:0x%x videoCodec:0x%x  container:0x%x",
+       r = SetFormatAttr(audioCodec, videoCodec, container);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] File format set  failed. audioCodec:0x%x videoCodec:0x%x  container:0x%x",
                                GetErrorMessage(r), audioCodec, videoCodec, videoCodec);
-       }
        __audioCodec = audioCodec;
        __videoCodec = videoCodec;
        __container = container;
 
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               // Call the dependency function.
-               r = ReloadConfiguration(_RELOAD_QUALITY);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration.", GetErrorMessage(r));
-       }
+       // Call the dependency function.
+       r = ReloadConfiguration(_RELOAD_QUALITY);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration.", GetErrorMessage(r));
 
 CATCH:
        return r;
@@ -673,7 +668,7 @@ _VideoRecorderImpl::GetSupportedCodecListN(void) const
        SysTryReturn(NID_MEDIA, pCapImpl != null, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  Get capability information failed.");
 
        std::unique_ptr<ArrayList, _ListPtrUtil::Remover> pCodecList (new (std::nothrow) Tizen::Base::Collection::ArrayList(), _ListPtrUtil::remover);
-       SysTryCatch(NID_MEDIA, pCodecList.get() !=null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryCatch(NID_MEDIA, pCodecList.get() !=null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = pCodecList->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder get attribute failed.", GetErrorMessage(r));
@@ -713,22 +708,18 @@ _VideoRecorderImpl::SetFormat(VideoRecordingFormat format)
        SysTryCatch(NID_MEDIA, audioCodec != CODEC_NONE && videoCodec != CODEC_NONE, r = E_UNSUPPORTED_CODEC, E_UNSUPPORTED_CODEC
                , "[E_UNSUPPORTED_CODEC]. This format(%d) is not supported in the device.\n", format);
 
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               r = SetFormatAttr(audioCodec, videoCodec, container);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] File format set  failed. audioCodec:0x%x videoCodec:0x%x  container:0x%x",
-                               GetErrorMessage(r), audioCodec, videoCodec, videoCodec);
-       }
+       r = SetFormatAttr(audioCodec, videoCodec, container);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] File format set  failed. audioCodec:0x%x videoCodec:0x%x  container:0x%x",
+                       GetErrorMessage(r), audioCodec, videoCodec, videoCodec);
+
        __format = format;
        __audioCodec = audioCodec;
        __videoCodec = videoCodec;
        __container = container;
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               // Call the dependency function.
-               r = ReloadConfiguration(_RELOAD_QUALITY);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration.", GetErrorMessage(r));
-       }
+       // Call the dependency function.
+       r = ReloadConfiguration(_RELOAD_QUALITY);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration.", GetErrorMessage(r));
+
        return r;
 
 CATCH:
@@ -777,22 +768,17 @@ _VideoRecorderImpl::SetFormat(CodecType audioCodec, CodecType videoCodec, MediaC
                           audioCodec, videoCodec,
                           container);
 
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               r = SetFormatAttr(audioCodec, videoCodec, container);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] File format set  failed. audioCodec:0x%x videoCodec:0x%x  container:0x%x",
+       r = SetFormatAttr(audioCodec, videoCodec, container);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] File format set  failed. audioCodec:0x%x videoCodec:0x%x  container:0x%x",
                                GetErrorMessage(r), audioCodec, videoCodec, videoCodec);
-       }
+
        __audioCodec = audioCodec;
        __videoCodec = videoCodec;
        __container = container;
 
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               // Call the dependency function.
-               r = ReloadConfiguration(_RELOAD_QUALITY);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration.", GetErrorMessage(r));
-       }
+       // Call the dependency function.
+       r = ReloadConfiguration(_RELOAD_QUALITY);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration.", GetErrorMessage(r));
 
 CATCH:
        return r;
@@ -817,7 +803,7 @@ _VideoRecorderImpl::GetSupportedAudioCodecListN(void) const
        SysTryReturn(NID_MEDIA, pIntegerList->GetCount() > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  The list was empty.");
 
        std::unique_ptr<ArrayListT<CodecType>, _ListPtrUtil::Remover> pAudioCodecList (new (std::nothrow) ArrayListT<CodecType>(), _ListPtrUtil::remover);
-       SysTryReturn(NID_MEDIA, pAudioCodecList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryReturn(NID_MEDIA, pAudioCodecList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = pAudioCodecList->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -854,7 +840,7 @@ _VideoRecorderImpl::GetSupportedVideoCodecListN(void) const
        SysTryReturn(NID_MEDIA, pIntegerList->GetCount() > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  The list was empty.");
 
        std::unique_ptr<ArrayListT<CodecType>, _ListPtrUtil::Remover> pVideoCodecList (new (std::nothrow) ArrayListT<CodecType>(), _ListPtrUtil::remover);
-       SysTryReturn(NID_MEDIA, pVideoCodecList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryReturn(NID_MEDIA, pVideoCodecList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = pVideoCodecList->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -892,7 +878,7 @@ _VideoRecorderImpl::GetSupportedContainerListN(void) const
        SysTryReturn(NID_MEDIA, pIntegerList->GetCount() > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  The list was empty.");
 
        std::unique_ptr<ArrayListT<MediaContainerType>, _ListPtrUtil::Remover> pContainerList (new (std::nothrow) ArrayListT<MediaContainerType>(), _ListPtrUtil::remover);
-       SysTryReturn(NID_MEDIA, pContainerList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryReturn(NID_MEDIA, pContainerList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = pContainerList->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -970,11 +956,8 @@ _VideoRecorderImpl::SetQuality(RecordingQuality quality)
 
        GetFormat(audioCodec, videoCodec, container);
 
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               r = SetQualityAttr(quality, audioCodec, videoCodec);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] set quality failed. quality:%d", GetErrorMessage(r), quality);
-       }
+       r = SetQualityAttr(quality, audioCodec, videoCodec);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] set quality failed. quality:%d", GetErrorMessage(r), quality);
        __quality = quality;
 
        return r;
@@ -1010,6 +993,7 @@ _VideoRecorderImpl::SetRecordingResolution(const Tizen::Graphics::Dimension& res
        SysTryReturn(NID_MEDIA, pList.get() != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  Getting the supported list was failed.\n");
        SysTryReturn(NID_MEDIA, pList->Contains(resolution), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE]. resolution is out of range. This resolution(%d,%d) is not supported in the device.\n", resolution.width, resolution.height);
 
+       SysTryReturn(NID_MEDIA, __pVideoSourceAdapter.get() != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  The source is deleted.");
        if ( __pVideoSourceAdapter->HasRecordingResolutionRestriction())
        {
                Dimension sourceResolution = __pVideoSourceAdapter->GetSourceResolution();
@@ -1074,11 +1058,9 @@ _VideoRecorderImpl::SetMute(bool mute)
                                || state == RECORDER_STATE_STOPPED || state == RECORDER_STATE_PAUSED || state == RECORDER_STATE_RECORDING
                           , E_INVALID_STATE, r, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d.", state);
 
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               r = SetMuteAttr(mute);
-               SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. mute:%d", GetErrorMessage(r), mute);
-       }
+
+       r = SetMuteAttr(mute);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. mute:%d", GetErrorMessage(r), mute);
        __mute = mute;
        return r;
 }
@@ -1104,12 +1086,10 @@ _VideoRecorderImpl::SetRecordingRotation(RecordingRotation rotation)
        SysTryReturn(NID_MEDIA, (rotation >= RECORDING_ROTATION_NONE&& rotation <= RECORDING_ROTATION_270)
                           , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(rotation) is used. The rotation=%d.", rotation);
 
-       if (__handle != MM_INVALID_HANDLE)
-       {
-               __pCoordinator->SetRecordingOrientation(rotation);
-       }
-       __rotation = rotation;
+       r = SetRecordingOrientationAttr(rotation);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s]  propogated", GetErrorMessage(r));
 
+       __rotation = rotation;
        return r;
 }
 
@@ -1182,7 +1162,7 @@ _VideoRecorderImpl::SetQualityAttr(RecordingQuality quality,      CodecType audioCod
                r = ConvertResult(err);
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Bitrate set  failed. attr:%d", GetErrorMessage(r), attrAudioBitrate);
        }
-       r = _RecorderUtil::GetMmVideoQuality(_CameraUtil::ConvertResolutionType(__recordingResolution), quality, attrVideoBitrate);
+       r = _RecorderUtil::GetMmVideoQuality(__recordingResolution, quality, attrVideoBitrate);
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. videoCodec:%d, quality:%d", GetErrorMessage(r), videoCodec, quality);
 
        err = recorder_attr_set_video_encoder_bitrate(__handle, attrVideoBitrate);
@@ -1225,6 +1205,28 @@ CATCH:
 }
 
 result
+_VideoRecorderImpl::SetRecordingOrientationAttr(RecordingRotation rotation)
+{
+       result r = E_SUCCESS;
+       int err = MM_SUCCESS;
+       recorder_rotation_e mmAttr = ::RECORDER_ROTATION_NONE;
+       r = _RecorderUtil::GetMmRotation(rotation, mmAttr);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. rotation:%d", GetErrorMessage(r), rotation);
+
+#if _VIDEO_RECORDER_ROTATION_
+       err = recorder_attr_set_recording_orientation(__handle, mmAttr);
+       r = ConvertResult(err);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Camcorder set attribute failed. rotation:%d", GetErrorMessage(r), rotation);
+#else
+       err = recorder_attr_set_orientation_tag(__handle, mmAttr);
+       r = ConvertResult(err);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Camcorder set attribute failed. rotation:%d", GetErrorMessage(r), rotation);
+#endif
+
+       return r;
+}
+
+result
 _VideoRecorderImpl::SetCallback(void)
 {
        result r = E_SUCCESS;
@@ -1264,9 +1266,6 @@ _VideoRecorderImpl::OnCameraCoordinatorModeChangePrepared(_CameraMode mode)
 
        if ( mode == _CAMERA_MODE_VIDEO )
        {
-               r = __pCoordinator->SetCameraSourceFormat(__mmSourceFormat);
-               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
-
                r = ReloadConfiguration(_RELOAD_FORMAT | _RELOAD_QUALITY);
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
        }
@@ -1293,6 +1292,15 @@ CATCH:
        return r;
 }
 
+result
+_VideoRecorderImpl::OnCameraCoordinatorOtherRemoved(void)
+{
+       result r = E_SUCCESS;
+       SysLog(NID_MEDIA, "Enter.");
+       __pVideoSourceAdapter.reset(null);
+       return r;
+}
+
 void
 _VideoRecorderImpl::StateChangedCb(recorder_state_e previous, recorder_state_e current, bool byPolicy, void* pUserData)
 {
@@ -1300,8 +1308,8 @@ _VideoRecorderImpl::StateChangedCb(recorder_state_e previous, recorder_state_e c
        _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>( pUserData);
        int tableTotalCount = 0;
        int i = 0;
-       SysTryReturnVoidResult(NID_MEDIA, _VideoRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. pImpl is null.");
+       SysTryReturnVoidResult(NID_MEDIA, _CamRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysLog(NID_MEDIA, "State previous:%d, current:%d, byPolicy:%d", previous, current, byPolicy);
 
        tableTotalCount = sizeof(_VIDEO_CALLBACK_EVENT) / sizeof(_VIDEO_CALLBACK_EVENT[0]);
@@ -1310,7 +1318,7 @@ _VideoRecorderImpl::StateChangedCb(recorder_state_e previous, recorder_state_e c
        {
                if (previous == _VIDEO_CALLBACK_EVENT[i].prevState && current == _VIDEO_CALLBACK_EVENT[i].postState && pImpl->GetStateChangeReason() == _VIDEO_CALLBACK_EVENT[i].reason)                //for cancel
                {
-                       r = pImpl->GetEvent()->SendEvent(_VIDEO_CALLBACK_EVENT[i].event, _VIDEO_CALLBACK_EVENT[i].error, E_SUCCESS);
+                       r = pImpl->GetEvent()->SendEvent(_VIDEO_CALLBACK_EVENT[i].event, RECORDER_ERROR_NONE, _VIDEO_CALLBACK_EVENT[i].r);
                        SysLog(NID_MEDIA, "VIDEO_CALLBACK_EVENT(%d) is sent by StateChangedCb", _VIDEO_CALLBACK_EVENT[i].event);
                        SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating. i:%d", GetErrorMessage(r), i);
                        break;
@@ -1322,8 +1330,8 @@ void
 _VideoRecorderImpl::RecordingStatusCb(unsigned long long elapsedTime, unsigned long long fileSize, void *pUserData)
 {
        _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>(pUserData);
-       SysTryReturnVoidResult(NID_MEDIA, _VideoRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. pImpl is null.");
+       SysTryReturnVoidResult(NID_MEDIA, _CamRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
 
        SysLog(NID_MEDIA, "FileSize:%llu,elapsedTime:%llu",fileSize,elapsedTime);
 
@@ -1336,8 +1344,8 @@ _VideoRecorderImpl::AudioStreamCb(void* pStream, int size, audio_sample_type_e f
 {
        _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>(pUserData);
        int samplingRate =0;
-       SysTryReturnVoidResult(NID_MEDIA, _VideoRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. Impl is null.");
+       SysTryReturnVoidResult(NID_MEDIA, _CamRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysTryReturnVoidResult(NID_MEDIA, pStream != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] void instance is not available. pStream is null.");
 
        if (pImpl->__audioStreamCallback == true)
@@ -1352,8 +1360,8 @@ _VideoRecorderImpl::LimitReachedCb(recorder_recording_limit_type_e type, void *p
 {
        result r = E_SUCCESS;
        _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>(pUserData);
-       SysTryReturnVoidResult(NID_MEDIA, _VideoRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. pImpl is null.");
+       SysTryReturnVoidResult(NID_MEDIA, _CamRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
 
        SysLog(NID_MEDIA, "Type:%d", type);
 
@@ -1387,23 +1395,13 @@ _VideoRecorderImpl::ErrorCb(recorder_error_e error, recorder_state_e state, void
 {
        result r = E_SUCCESS;
        _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>(pUserData);
-       SysTryReturnVoidResult(NID_MEDIA, _VideoRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. pImpl is null.");
+       SysTryReturnVoidResult(NID_MEDIA, _CamRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysLog(NID_MEDIA, "Error:%d, state:%d", error, state);
 
-       _CameraCoordinator* __pCoordinator = null;
-       __pCoordinator = _CameraCoordinator::AddInstance(pImpl->GetDeviceType());
-       SysTryCatch(NID_MEDIA, __pCoordinator != null, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _CameraCoordinator instance is not available. Coordinator is not found");
-
-       r = __pCoordinator->ChangeMode(_CAMERA_MODE_IMAGE, true);
+       r = pImpl->GetEvent()->SendEvent(_RECORDER_EVENT_ERROR, pImpl->ConvertErrorReason(error), E_SUCCESS);
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
-
-       _CameraCoordinator::Release(pImpl->GetDeviceType());
-
-       r = pImpl->GetEvent()->SendEvent(_RECORDER_EVENT_ERROR, RECORDER_ERROR_DEVICE_FAILED, E_SUCCESS);
-       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
-
-       return;
+       pImpl->SetStateChangeReason(_RECORDER_STATE_REASON_ERROR);
 CATCH:
        return;
 }
@@ -1412,8 +1410,8 @@ void
 _VideoRecorderImpl::InterruptedCb(recorder_policy_e policy, recorder_state_e previous, recorder_state_e current, void *pUserData)
 {
        _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>(pUserData);
-       SysTryReturnVoidResult(NID_MEDIA, _VideoRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. pImpl is null.");
+       SysTryReturnVoidResult(NID_MEDIA, _CamRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
 
        SysLog(NID_MEDIA, "Policy:%d, previous:%d, current:%d", policy, previous, current);
 }
@@ -1495,6 +1493,32 @@ _VideoRecorderImpl::ConvertResult(int err) const
        return r;
 }
 
+RecorderErrorReason
+_VideoRecorderImpl::ConvertErrorReason(int err) const
+{
+       RecorderErrorReason r = RECORDER_ERROR_NONE;
+       if (err != ::RECORDER_ERROR_NONE)
+       {
+               SysLog(NID_MEDIA, "MM Err:0x%x", err);
+       }
+
+       // Global error
+       if (err == ::RECORDER_ERROR_NONE)
+       {
+               r = RECORDER_ERROR_NONE;
+       }
+       else if (err == 0x80000006)     //temporary code. until out of storage error type is added.
+       {
+               r = RECORDER_ERROR_OUT_OF_STORAGE;
+       }
+       else
+       {
+               r = RECORDER_ERROR_DEVICE_FAILED;
+       }
+
+       return r;
+}
+
 void
 _VideoRecorderImpl::GetCodecString(const CodecType videoCodec, Tizen::Base::String& codec) const
 {
@@ -1550,7 +1574,7 @@ _VideoRecorderImpl::ChangeStateTo(recorder_state_e mmDestState, _RecorderStateCh
                                SysLog(NID_MEDIA, "[E_SUCCESS] Found. result mmState:%d, param mmDestState:%d", postState,
                                                        mmDestState);
 
-                               __stateChangeReason = reason;           //for distinguish between stop and cancel
+                               SetStateChangeReason(reason);           //for distinguish between stop and cancel
                        }
 
                        if (_VIDEO_COMMAND_STATE[i].state >= RECORDER_STATE_INITIALIZED && _VIDEO_COMMAND_STATE[i].state <= RECORDER_STATE_ERROR)
@@ -1575,6 +1599,12 @@ _VideoRecorderImpl::GetStateChangeReason(void) const
        return __stateChangeReason;
 }
 
+void
+_VideoRecorderImpl::SetStateChangeReason(_RecorderStateChangeReason reason)
+{
+       __stateChangeReason = reason;
+}
+
 recorder_state_e
 _VideoRecorderImpl::GetMmState(void) const
 {
@@ -1667,7 +1697,7 @@ _VideoRecorderImpl::ReloadConfiguration(int reload)
                int err = MM_SUCCESS;
                std::unique_ptr<char[]> pFileName (Tizen::Base::_StringConverter::CopyToCharArrayN(__filePath));
                SysTryCatch(NID_MEDIA, pFileName.get() != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(__filePath) is used. File name is null.");
-               SysLog(NID_MEDIA, "File Path : %s\n", pFileName.get());
+               SysSecureLog(NID_MEDIA, "File Path : %s\n", pFileName.get());
 
                err = recorder_set_filename(__handle, pFileName.get());
                r = ConvertResult(err);
@@ -1690,7 +1720,8 @@ _VideoRecorderImpl::ReloadConfiguration(int reload)
        }
        if (reload & _RELOAD_ROTATION)
        {
-               __pCoordinator->SetRecordingOrientation(__rotation);
+               r = SetRecordingOrientationAttr(__rotation);
+               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set orientation failed", GetErrorMessage(r));
        }
 
        return r;
@@ -1717,18 +1748,13 @@ _VideoRecorderImpl::LoadDefaultConfiguration(int reload)
        // Preview resolution
        if (reload & _RELOAD_RECORD_RESOLUTION)
        {
+               SysTryReturn(NID_MEDIA, __pVideoSourceAdapter.get() != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  The source is deleted.");
                __recordingResolution = __pVideoSourceAdapter->GetSourceResolution();
        }
 
        return r;
 }
 
-bool
-_VideoRecorderImpl::IsAlive(void)
-{
-       return __isUsed;
-}
-
 _VideoRecorderImpl*
 _VideoRecorderImpl::GetInstance(VideoRecorder *pVideoRecorder)
 {