Implement smooth change between Camera and Recorder
authorjs1002.kim <js1002.kim@samsung.com>
Mon, 25 Mar 2013 09:09:13 +0000 (18:09 +0900)
committerjs1002.kim <js1002.kim@samsung.com>
Mon, 25 Mar 2013 09:09:13 +0000 (18:09 +0900)
Change-Id: I06f4d45af8e5dc6783d1686b8ea05a2b9098f877
Signed-off-by: js1002.kim <js1002.kim@samsung.com>
src/FMedia_CameraCoordinator.cpp
src/FMedia_CameraCoordinator.h
src/FMedia_CameraImpl.cpp
src/FMedia_CameraImpl.h
src/FMedia_RecorderSession.cpp
src/FMedia_VideoRecorderImpl.cpp
src/FMedia_VideoSourceAdapter.cpp
src/FMedia_VideoSourceAdapter.h

index 8cbe446..8c472e1 100755 (executable)
@@ -123,6 +123,7 @@ _CameraCoordinator::_CameraCoordinator()
        , __orientationFlag(0)
        , __cameraOrientation(CAMERA_EXIF_ORIENTATION_TOP_LEFT)
        , __recordingRotation(RECORDING_ROTATION_NONE)
+       , __reloadCameraPreviewFormat(::CAMERA_PIXEL_FORMAT_I420)
 {
 }
 
@@ -524,6 +525,212 @@ CATCH:
 }
 
 result
+_CameraCoordinator::CreateVideoRecorder(void)
+{
+       result r = E_SUCCESS;
+       _RecorderDeviceType recorderDevice = _RECORDER_DEVICE_NONE;
+       SysLog(NID_MEDIA, "enter.");
+
+       // Start recorder
+       if ( __recorderHandle == MM_INVALID_HANDLE )
+       {
+               recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
+               _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
+               r = AddRecorder(recorderDevice);                // recorder_create() will be called.
+               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+               __mode = _CAMERA_MODE_VIDEO;
+       }
+       return r;
+CATCH:
+       return r;
+}
+
+result
+_CameraCoordinator::DestroyVideoRecorder(void)
+{
+       result r = E_SUCCESS;
+       int err = MM_SUCCESS;
+       recorder_state_e recorderState = ::RECORDER_STATE_NONE;
+       _RecorderDeviceType recorderDevice = _RECORDER_DEVICE_NONE;
+       SysLog(NID_MEDIA, "enter.");
+
+       if ( __recorderHandle != MM_INVALID_HANDLE )
+       {
+               recorderState = GetRecorderState();
+               // Stop the recorder
+               switch (recorderState)
+               {
+               case ::RECORDER_STATE_NONE:
+                       break;
+
+               case ::RECORDER_STATE_CREATED:
+                       //fall through
+               case ::RECORDER_STATE_READY:
+                       recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
+                               _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
+                       RemoveRecorder(recorderDevice);
+                       __mode = _CAMERA_MODE_IMAGE;
+                       break;
+
+               case ::RECORDER_STATE_RECORDING:
+                       //fall through
+               case ::RECORDER_STATE_PAUSED:
+                       err = recorder_cancel(__recorderHandle);
+                       r = ConvertResult(err);
+                       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+                       recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
+                               _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
+                       RemoveRecorder(recorderDevice);
+                       __mode = _CAMERA_MODE_IMAGE;
+                       break;
+
+               default:
+                       break;
+               }
+       }
+
+       return r;
+CATCH:
+       return r;
+}
+
+
+result
+_CameraCoordinator::ChangeFormat(_CameraMode mode, bool callback, camera_pixel_format_e reloadCameraPreviewFormat)
+{
+       result r = E_SUCCESS;
+       int err = MM_SUCCESS;
+       _RecorderDeviceType recorderDevice = _RECORDER_DEVICE_NONE;
+       camera_state_e cameraState = ::CAMERA_STATE_NONE;
+       recorder_state_e recorderState = ::RECORDER_STATE_NONE;
+       SysLog(NID_MEDIA, "enter. mode:%d, callback:%d,         reloadCameraPreviewFormat:%d", mode, callback, reloadCameraPreviewFormat);
+
+       if (mode == _CAMERA_MODE_VIDEO)
+       {
+               cameraState = GetCameraState();
+
+               switch (cameraState)
+               {
+               case ::CAMERA_STATE_CREATED:
+                       //fall through
+               case ::CAMERA_STATE_NONE:
+                       break;
+
+               case ::CAMERA_STATE_PREVIEW:
+                       //fall through
+               case ::CAMERA_STATE_CAPTURED:
+                       r = ChangeCameraStateTo(::CAMERA_STATE_CREATED);
+                       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+                       break;
+
+               case ::CAMERA_STATE_CAPTURING:
+                       r = E_INVALID_STATE;
+                       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);
+                       goto CATCH;
+                       break;
+
+               default:
+                       break;
+               }
+
+               __mode = _CAMERA_MODE_VIDEO;
+               __reloadCameraPreviewFormat = reloadCameraPreviewFormat;
+               if (callback)
+               {
+                       r = NotifyModeChangePrepared(mode);
+                       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+               }
+
+               switch (cameraState)
+               {
+               case ::CAMERA_STATE_NONE:
+                       //fall through
+               case ::CAMERA_STATE_CREATED:
+                       break;
+
+               case ::CAMERA_STATE_PREVIEW:
+                       r = ChangeRecorderStateTo(::RECORDER_STATE_READY);
+                       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+                       break;
+
+               case ::CAMERA_STATE_CAPTURED:
+               default:
+                       break;
+               }
+       }
+       else if ( mode == _CAMERA_MODE_IMAGE )
+       {
+               recorderState = GetRecorderState();
+
+               switch (recorderState)
+               {
+               case ::RECORDER_STATE_NONE:
+                       break;
+               case ::RECORDER_STATE_CREATED:
+                       __mode = _CAMERA_MODE_IMAGE;
+                       __reloadCameraPreviewFormat = reloadCameraPreviewFormat;
+                       if (callback)
+                       {
+                               r = NotifyModeChangePrepared(mode);
+                               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+                       }
+                       break;
+
+               case ::RECORDER_STATE_READY:
+                       r = ChangeRecorderStateTo(::RECORDER_STATE_CREATED);
+                       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
+                       __mode = _CAMERA_MODE_IMAGE;
+                       __reloadCameraPreviewFormat = reloadCameraPreviewFormat;
+                       if (callback)
+                       {
+                               r = NotifyModeChangePrepared(mode);
+                               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+                       }
+                       r = ChangeCameraStateTo(::CAMERA_STATE_PREVIEW);
+                       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+                       break;
+
+               case ::RECORDER_STATE_RECORDING:
+                       //fall through
+               case ::RECORDER_STATE_PAUSED:
+                       err = recorder_cancel(__recorderHandle);                // TODO
+                       r = ConvertResult(err);
+                       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
+                       r = ChangeRecorderStateTo(::RECORDER_STATE_CREATED);
+                       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+                       recorderDevice = __cameraDevice == _CAMERA_DEVICE_PRIMARY ?
+                               _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA;
+
+                       __mode = _CAMERA_MODE_IMAGE;
+                       __reloadCameraPreviewFormat = reloadCameraPreviewFormat;
+                       if (callback)
+                       {
+                               r = NotifyModeChangePrepared(mode);
+                               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+                       }
+                       r = ChangeCameraStateTo(::CAMERA_STATE_PREVIEW);
+                       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+                       break;
+
+               default:
+                       break;
+               }
+       }
+
+       if (callback)
+       {
+               // Notify that the mode is changed to callback camera and video recorder's configurations.
+               r = NotifyModeChanged(mode);
+               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+       }
+       return r;
+CATCH:
+       return r;
+}
+
+result
 _CameraCoordinator::ChangeMode(_CameraMode mode, bool callback)
 {
        result r = E_SUCCESS;
@@ -972,6 +1179,7 @@ _CameraCoordinator::StartCapture(camera_capturing_cb capturingCb , camera_captur
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
        }
 
+       __mode = _CAMERA_MODE_IMAGE;
        err = camera_start_capture(__cameraHandle, capturingCb, completedCb, pUserData);
        r = ConvertResult(err);
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Camera capture failed.", GetErrorMessage(r));
@@ -996,6 +1204,7 @@ _CameraCoordinator::StartRecord(void)
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
        }
 
+       __mode = _CAMERA_MODE_VIDEO;
        err = recorder_start(__recorderHandle);
        r = ConvertResult(err);
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Recorder record failed.", GetErrorMessage(r));
@@ -1064,4 +1273,10 @@ _CameraCoordinator::SetCameraOrientationAttr(CameraExifOrientation orientation)
        return r;
 }
 
+camera_pixel_format_e
+_CameraCoordinator::GetReloadPreviewFormat(void) const
+{
+       SysLog(NID_MEDIA, "reloadCameraPreviewFormat is :%d", __reloadCameraPreviewFormat);
+       return __reloadCameraPreviewFormat;
+}
 }}
index 3740229..44924db 100755 (executable)
@@ -211,6 +211,34 @@ public:
        result StopMmPreview(void);
 
        /**
+       * Create videorecorder handle.
+       *
+       * @return               An error code
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_SYSTEM                                A system error has occurred.
+       */
+       result CreateVideoRecorder(void);
+
+       /**
+       * Destory videorecorder handle.
+       *
+       * @return               An error code
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_SYSTEM                                A system error has occurred.
+       */
+       result DestroyVideoRecorder(void);
+
+       /**
+       * Change camera source prview format.
+       *
+       * @return               An error code
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_SYSTEM                                A system error has occurred.
+       */
+       result ChangeFormat(_CameraMode mode, bool callback, camera_pixel_format_e reloadCameraPreviewFormat);
+
+
+       /**
        * Changes the camcorder mode.
        *
        * @return               An error code
@@ -286,6 +314,13 @@ public:
        */
        void SetCameraOrientation(CameraExifOrientation orientation);
 
+       /**
+       * Gets the reloaded preview format of the camera.
+       *
+       * @return               An error code
+       */
+       camera_pixel_format_e GetReloadPreviewFormat(void) const;
+
 private:
        friend class _CameraCoordinatorSafeHashMapT;
        /**
@@ -403,6 +438,7 @@ private:
        int __orientationFlag;
        CameraExifOrientation __cameraOrientation;
        RecordingRotation __recordingRotation;
+       camera_pixel_format_e __reloadCameraPreviewFormat;
 
        static _CameraCoordinatorSafeHashMapT* __pMap;
 };
index 5ceb625..d91aa1f 100755 (executable)
@@ -742,6 +742,7 @@ _CameraImpl::Capture(void)
 {
        result r = E_SUCCESS;
        CameraState state = CAMERA_STATE_ERROR;
+       camera_pixel_format_e previewFormat = ::CAMERA_PIXEL_FORMAT_INVALID;
        SysLog(NID_MEDIA, "Camera Capture");
        SysTryReturn(NID_MEDIA, __isPoweredOn == true, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] Camera is in an invalid state. Camera was not powered on.");
 
@@ -750,8 +751,13 @@ _CameraImpl::Capture(void)
 
        if ( __pCoordinator->GetMode() != _CAMERA_MODE_IMAGE )
        {
-               r = __pCoordinator->ChangeMode(_CAMERA_MODE_IMAGE, true);
-               SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+               r = _CameraUtil::GetMmPixelFormat(__previewFormat, previewFormat);
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. __previewFormat:%d", GetErrorMessage(r), __previewFormat);
+               if (previewFormat != __pCoordinator->GetCameraSourceFormat())
+               {
+                       r = __pCoordinator->ChangeFormat(_CAMERA_MODE_IMAGE, true, previewFormat);
+                       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+               }
        }
 
        r = __pCoordinator->StartCapture(CaptureCb, CaptureCompletedCb, this);
@@ -2231,6 +2237,12 @@ _CameraImpl::IsZeroShutterLag(void) const
        return __zeroShutterLag;
 }
 
+Tizen::Graphics::PixelFormat
+_CameraImpl::GetDeviceRecommendPreviewFormat(void) const
+{
+       return __deviceDefaultPreviewFormat;
+}
+
 result
 _CameraImpl::SetProperty(_CameraOperationType operation, int min, int max, int value)
 {
@@ -2434,7 +2446,7 @@ _CameraImpl::ReloadConfiguration(int reload)
        }
        if (reload & _RELOAD_INTERNAL_PREVIEW_FORMAT)
        {
-               err = camera_set_preview_format(__handle, __pCoordinator->GetCameraSourceFormat());
+               err = camera_set_preview_format(__handle, __pCoordinator->GetReloadPreviewFormat());
                r = ConvertResult(err);
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
        }
index 0676305..5b828f3 100755 (executable)
@@ -1200,6 +1200,14 @@ public:
        */
        bool IsZeroShutterLag(void) const;
 
+
+       /**
+       * Gets the camera's recommened preview format
+       *
+       * @return          recommened preview format
+       */
+       Tizen::Graphics::PixelFormat GetDeviceRecommendPreviewFormat(void) const;
+
        /**
        * Called when the event is received from the %_ICameraCoordinatorListener object.
        *
index c1c99ec..604f697 100755 (executable)
@@ -51,7 +51,7 @@ _RecorderSession::~_RecorderSession(void)
                {
                        if (__previousCameraMode == _CAMERA_MODE_IMAGE)
                        {
-                               r = __pCoordinator->ChangeMode(_CAMERA_MODE_IMAGE, false);
+                               r = __pCoordinator->DestroyVideoRecorder();
                                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
                        }
                        SysLog(NID_MEDIA, "Release the recorder device:%d", __recorderDevice);
@@ -82,7 +82,7 @@ _RecorderSession::Construct(_RecorderDeviceType recorderDevice)
 
                if (__pCoordinator->GetMode() == _CAMERA_MODE_IMAGE)
                {
-                       r = __pCoordinator->ChangeMode(_CAMERA_MODE_VIDEO, false);
+                       r = __pCoordinator->CreateVideoRecorder();
                        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
                        __previousCameraMode = _CAMERA_MODE_IMAGE;
                }
@@ -145,7 +145,7 @@ _RecorderSession::Construct(_RecorderSourceType recorderSource)
                        if (cameraCount < 2)
                        {
                                targetRecorder = (runningCamera == _CAMERA_DEVICE_PRIMARY ? _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA);
-                               r = __pCoordinator->ChangeMode(_CAMERA_MODE_VIDEO, false);
+                               r = __pCoordinator->CreateVideoRecorder();
                                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
                                __previousCameraMode = _CAMERA_MODE_IMAGE;
                        }
@@ -154,7 +154,7 @@ _RecorderSession::Construct(_RecorderSourceType recorderSource)
                                if(__pCoordinator->IsCalmChangeMode(_CAMERA_MODE_VIDEO))
                                {
                                        targetRecorder = (runningCamera == _CAMERA_DEVICE_PRIMARY ? _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA);
-                                       r = __pCoordinator->ChangeMode(_CAMERA_MODE_VIDEO, false);
+                                       r = __pCoordinator->CreateVideoRecorder();
                                        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
                                        __previousCameraMode = _CAMERA_MODE_IMAGE;
                                }
@@ -172,7 +172,7 @@ _RecorderSession::Construct(_RecorderSourceType recorderSource)
 
                                        if(__pCoordinator->IsCalmChangeMode(_CAMERA_MODE_VIDEO))
                                        {
-                                               r = __pCoordinator->ChangeMode(_CAMERA_MODE_VIDEO, false);
+                                               r = __pCoordinator->CreateVideoRecorder();
                                                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
                                                __previousCameraMode = _CAMERA_MODE_IMAGE;
                                        }
index dd51612..4621f80 100755 (executable)
@@ -170,7 +170,14 @@ _VideoRecorderImpl::~_VideoRecorderImpl(void)
        }
        if (__pCoordinator != null)
        {
-               __pCoordinator->ChangeMode(_CAMERA_MODE_IMAGE, false);
+               if (__pVideoSourceAdapter != null)
+               {
+                       if (__pVideoSourceAdapter->GetUserPreviewFormat() != __pCoordinator->GetCameraSourceFormat())
+                       {
+                               __pCoordinator->ChangeFormat(_CAMERA_MODE_IMAGE, true, __pVideoSourceAdapter->GetUserPreviewFormat());
+                       }
+               }
+               __pCoordinator->DestroyVideoRecorder();
                __pCoordinator->RemoveCameraCoordinatorListener(*this);
 
                _CameraCoordinator::Release(__deviceType);
@@ -190,7 +197,6 @@ _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;
@@ -249,13 +255,10 @@ _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));
 
        err = recorder_set_state_changed_cb(__handle, StateChangedCb, this);
        r = ConvertResult(err);
@@ -355,7 +358,7 @@ _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.");
@@ -365,21 +368,15 @@ _VideoRecorderImpl::CreateVideoFile(const Tizen::Base::String& mediaLocalPath, b
        SysTryCatch(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;
@@ -442,16 +439,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();
@@ -590,11 +588,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 +629,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;
@@ -713,22 +702,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 +762,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;
@@ -970,11 +950,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;
@@ -1074,11 +1051,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,10 +1079,7 @@ _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);
-       }
+       __pCoordinator->SetRecordingOrientation(rotation);
        __rotation = rotation;
 
        return r;
@@ -1264,9 +1236,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));
        }
@@ -1391,19 +1360,8 @@ _VideoRecorderImpl::ErrorCb(recorder_error_e error, recorder_state_e state, void
        SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. pImpl is null.");
        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);
-       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;
 CATCH:
        return;
 }
index 0dfa355..6e1118c 100755 (executable)
@@ -28,8 +28,7 @@
 #include "FMedia_CameraCapability.h"
 #include "FMedia_CameraImpl.h"
 #include "FMedia_CamPtrUtil.h"
-
-//#define _SAFE_VIDEO_FORMAT_
+#include "FMedia_CameraUtil.h"
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -42,7 +41,6 @@ _VideoSourceAdapter::_VideoSourceAdapter(const Tizen::Media::_CameraImpl &camera
 {
        __pSource = const_cast<_CameraImpl*>(&cameraImpl);
        __sourceType = _VIDEO_SOURCE_CAMERA;
-       __recommendPreviewFormat = CAMERA_PIXEL_FORMAT_NV12;
 }
 
 _VideoSourceAdapter::~_VideoSourceAdapter()
@@ -78,10 +76,15 @@ _VideoSourceAdapter::GetSupportedRecordingFormatListN(void) const
 {
        result r = E_SUCCESS;
        std::unique_ptr <ArrayListT<camera_pixel_format_e>, _ListPtrUtil::Remover> pListT (null, _ListPtrUtil::remover);
-       camera_pixel_format_e recommendPreviewFormat = CAMERA_PIXEL_FORMAT_NV12;
+       camera_pixel_format_e recommendPreviewFormat = ::CAMERA_PIXEL_FORMAT_INVALID;
 
        if (__sourceType == _VIDEO_SOURCE_CAMERA)
        {
+               Tizen::Graphics::PixelFormat recommendPreviewPixelFormat;
+               _CameraImpl* pCameraImpl = null;
+               pCameraImpl = dynamic_cast<_CameraImpl*>(__pSource);
+               SysTryReturn(NID_MEDIA, pCameraImpl != null, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  This is not the camera object.");
+
                pListT.reset(new (std::nothrow) ArrayListT<camera_pixel_format_e>());
                SysTryReturn(NID_MEDIA, pListT.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  out of memory");
 
@@ -89,9 +92,16 @@ _VideoSourceAdapter::GetSupportedRecordingFormatListN(void) const
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating", GetErrorMessage(r));
 
                // This means that the device supports recommeded format for the recording.
-               recommendPreviewFormat = __recommendPreviewFormat;
+               recommendPreviewPixelFormat = pCameraImpl->GetDeviceRecommendPreviewFormat();
+               SysLog(NID_MEDIA, "Enter. recommendPreview Osp PixelFormat:%d", recommendPreviewPixelFormat);
+
+               r = _CameraUtil::GetMmPixelFormat(recommendPreviewPixelFormat, recommendPreviewFormat);
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating. previewPixelFormat:%d", GetErrorMessage(r), recommendPreviewFormat);
+
                r = pListT->Add(recommendPreviewFormat);
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating", GetErrorMessage(r));
+
+               SysLog(NID_MEDIA, "recommendPreview MM Format:%d", recommendPreviewFormat);
        }
 
        return pListT.release();
@@ -137,6 +147,32 @@ CATCH:
        return Dimension(0, 0);
 }
 
+camera_pixel_format_e
+_VideoSourceAdapter::GetUserPreviewFormat(void) const
+{
+       result r = E_SUCCESS;
+       Tizen::Graphics::PixelFormat previewPixelFormat;
+       camera_pixel_format_e previewFormat = ::CAMERA_PIXEL_FORMAT_INVALID;
+
+       if (__sourceType == _VIDEO_SOURCE_CAMERA)
+       {
+               _CameraImpl* pCameraImpl = null;
+               pCameraImpl = dynamic_cast<_CameraImpl*>(__pSource);
+               SysTryCatch(NID_MEDIA, pCameraImpl != null, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  This is not the camera object.");
+
+               previewPixelFormat = pCameraImpl->GetPreviewFormat();
+               SysLog(NID_MEDIA, "Enter. previewPixelFormat:%d", previewPixelFormat);
+
+               r = _CameraUtil::GetMmPixelFormat(previewPixelFormat, previewFormat);
+               SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. previewPixelFormat:%d", GetErrorMessage(r), previewPixelFormat);
+       }
+
+       return previewFormat;
+
+CATCH:
+       return previewFormat;
+}
+
 bool
 _VideoSourceAdapter::HasRecordingResolutionRestriction(void) const
 {
@@ -149,26 +185,4 @@ _VideoSourceAdapter::HasRecordingResolutionRestriction(void) const
 
        return restriction;
 }
-
-result
-_VideoSourceAdapter::SetRecommendPreviewFormat(_CameraHandle cameraHandle)
-{
-       int err = MM_SUCCESS;
-       result r = E_SUCCESS;
-#if defined _SAFE_VIDEO_FORMAT_
-       camera_pixel_format_e recommendPreviewFormat = CAMERA_PIXEL_FORMAT_I420;
-#else
-       camera_pixel_format_e recommendPreviewFormat = CAMERA_PIXEL_FORMAT_NV12;
-
-       err = camera_get_preview_format(cameraHandle, &recommendPreviewFormat);
-       SysTryCatch(NID_MEDIA, err == MM_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  Getting the Recommend Preview Format error.");
-#endif
-       __recommendPreviewFormat = recommendPreviewFormat;
-       err = camera_set_preview_format(cameraHandle, __recommendPreviewFormat);
-
-       SysLog(NID_MEDIA, "the Recommend Preview Format:%d", __recommendPreviewFormat);
-       return r;
-CATCH:
-       return r;
-}
 }}
index 6cd05d4..3565a15 100755 (executable)
@@ -113,6 +113,8 @@ public:
        */
        Tizen::Graphics::Dimension GetSourceResolution(void) const;
 
+       camera_pixel_format_e GetUserPreviewFormat(void) const;
+
        /**
        * Check if the source has the restriction of recording resolution.
        *
@@ -120,21 +122,9 @@ public:
        *                               else @c false
        */
        bool HasRecordingResolutionRestriction(void) const;
-       /**
-       * Set the recommended preview format for videorecord.
-       *
-       * @return               An error code
-       * @param[in]    mode                                            _CameraHandle
-       * @exception    E_SUCCESS                               The method is successful.
-       * @exception    E_SYSTEM                                A system error has occurred.
-       * @remarks              The specific error code can be accessed using the GetLastResult() method.
-       */
-       result SetRecommendPreviewFormat(_CameraHandle cameraHandle);
-
 private:
        Tizen::Base::Object* __pSource;
        _VideoSourceType __sourceType;
-       camera_pixel_format_e __recommendPreviewFormat;
 };
 
 }}// Tizen::Media