enable dual camera
authorKyungYoun <ky99.won@samsung.com>
Mon, 20 May 2013 05:36:35 +0000 (14:36 +0900)
committerKyungYoun <ky99.won@samsung.com>
Mon, 20 May 2013 06:09:10 +0000 (15:09 +0900)
Change-Id: I3919564edf4782bbff800c7e32787895be1787f9
Signed-off-by: KyungYoun <ky99.won@samsung.com>
24 files changed:
CMakeLists.txt
src/FMedia_AudioRecorderImpl.cpp
src/FMedia_AudioRecorderImpl.h
src/FMedia_CamRef.cpp [new file with mode: 0755]
src/FMedia_CamRef.h [new file with mode: 0755]
src/FMedia_CameraCapability.cpp
src/FMedia_CameraCapability.h
src/FMedia_CameraCapabilitySession.cpp
src/FMedia_CameraCoordinator.cpp
src/FMedia_CameraCoordinator.h
src/FMedia_CameraImpl.cpp
src/FMedia_CameraImpl.h
src/FMedia_CameraManager.cpp
src/FMedia_CameraManager.h
src/FMedia_CameraRef.cpp [new file with mode: 0755]
src/FMedia_CameraRef.h [new file with mode: 0755]
src/FMedia_CapabilityImpl.cpp
src/FMedia_RecorderManager.cpp
src/FMedia_RecorderManager.h
src/FMedia_RecorderRef.cpp [new file with mode: 0755]
src/FMedia_RecorderRef.h [new file with mode: 0755]
src/FMedia_VideoRecorderImpl.cpp
src/FMedia_VideoRecorderImpl.h
src/inc/FMedia_CapabilityImpl.h

index 10ef142..8817fef 100755 (executable)
@@ -94,6 +94,9 @@ SET (${this_target}_SOURCE_FILES
        src/FMedia_CameraManager.cpp
        src/FMedia_CameraCapabilitySession.cpp
        src/FMedia_CameraBuffer.cpp
+       src/FMedia_CamRef.cpp
+       src/FMedia_CameraRef.cpp
+       src/FMedia_RecorderRef.cpp
        src/FMediaAudioRecorder.cpp
        src/FMedia_AudioRecorderImpl.cpp
        src/FMedia_AudioRecorderEvent.cpp
index 63c304c..85e0d81 100755 (executable)
@@ -35,6 +35,7 @@
 #include "FMedia_RecorderManager.h"
 #include "FMedia_CamPtrUtil.h"
 #include "FMedia_AudioStreamCoordinator.h"
+#include "FMedia_RecorderRef.h"
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -96,10 +97,9 @@ static const _AudioCallbackEventTable _AUDIO_CALLBACK_EVENT[] =
        {::RECORDER_STATE_READY, ::RECORDER_STATE_CREATED, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_CLOSED, RECORDER_ERROR_NONE },
 };
 
-bool _AudioRecorderImpl::__isUsed = false;
-
 _AudioRecorderImpl::_AudioRecorderImpl(void)
-       : __pAudioRecorderEvent(null)
+       : __pRecorderRef(null)
+       , __pAudioRecorderEvent(null)
        , __pAudioRecorderEventListener(null)
        , __pRecorderManager(null)
        , __isConstructed(false)
@@ -140,11 +140,6 @@ _AudioRecorderImpl::~_AudioRecorderImpl(void)
                _RecorderManager::Release(_RECORDER_DEVICE_AUDIO);
        }
 
-       if (__isConstructed)
-       {
-               __isUsed = false;
-       }
-
        SysLog(NID_MEDIA, "Destroyed");
 }
 
@@ -158,13 +153,18 @@ _AudioRecorderImpl::Construct(IAudioRecorderEventListener& listener)
 
        SysLog(NID_MEDIA, "Starting Audio Recorder construct.");
 
-       SysTryReturn(NID_MEDIA, !__isUsed, E_DEVICE_BUSY, E_DEVICE_BUSY,
-                               "[E_DEVICE_BUSY] _AudioRecorderImpl is now being used.");
        SysTryReturn(NID_MEDIA, !__isConstructed, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] AudioRecorder is in an invalid state. A device is already constructed.");
 
+       // 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, _RECORDER_DEVICE_AUDIO);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
        //Create Event
        __pAudioRecorderEvent.reset(new (std::nothrow) _AudioRecorderEvent());
-       SysTryReturn(NID_MEDIA, __pAudioRecorderEvent.get() !=null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryReturn(NID_MEDIA, __pAudioRecorderEvent.get() !=null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
        r = __pAudioRecorderEvent->Construct(*this);
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -174,7 +174,7 @@ _AudioRecorderImpl::Construct(IAudioRecorderEventListener& listener)
 
        // 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));
@@ -182,23 +182,16 @@ _AudioRecorderImpl::Construct(IAudioRecorderEventListener& listener)
        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 capability
-       r = pCapabilityImpl->GetValue(String(L"AudioRecorder.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
-       }
-
        __pRecorderManager = _RecorderManager::AddInstance(_RECORDER_DEVICE_AUDIO);
        r = GetLastResult();
        SysTryCatch(NID_MEDIA, __pRecorderManager != null, , r, "[%s] audio recorder creation failed");
-
        __handle = __pRecorderManager->GetHandle();
 
+       // Get the audio stream fps
+       r = pCapabilityImpl->GetValue(AUDIORECORDER_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);
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] audio recorder set message callback failed.", GetErrorMessage(r));
@@ -225,7 +218,6 @@ _AudioRecorderImpl::Construct(IAudioRecorderEventListener& listener)
 
        SetState(RECORDER_STATE_INITIALIZED);
        __isConstructed = true;
-       __isUsed = true;
        return r;
 
 CATCH:
@@ -246,7 +238,9 @@ CATCH:
                __pAudioRecorderEventListener = null;
        }
 
+       __pRecorderRef.reset(null);
        __pAudioRecorderEvent.reset(null);
+       __pAudioStreamCoordinator.reset(null);
 
        return r;
 }
@@ -670,7 +664,7 @@ _AudioRecorderImpl::GetSupportedCodecListN(void) const
        SysTryReturn(NID_MEDIA, pIntegerList->GetCount() > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  The list is 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));
@@ -708,7 +702,7 @@ _AudioRecorderImpl::GetSupportedContainerListN(void) const
        SysTryReturn(NID_MEDIA, pIntegerList->GetCount() > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  The list is 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));
@@ -1091,20 +1085,20 @@ void
 _AudioRecorderImpl::StateChangedCb(recorder_state_e previous, recorder_state_e current, bool byPolicy, void* pUserData)
 {
        result r = E_SUCCESS;
-       _AudioRecorderImpl* pObj = static_cast<_AudioRecorderImpl*>( pUserData);
+       _AudioRecorderImpl* pImpl = static_cast<_AudioRecorderImpl*>( pUserData);
        int tableTotalCount = 0;
        int i = 0;
-       SysTryReturnVoidResult(NID_MEDIA, _AudioRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
-       SysTryReturnVoidResult(NID_MEDIA, pObj != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _AudioRecorderImpl instance is not available. pObj is null.");
+       SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _AudioRecorderImpl 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(_AUDIO_CALLBACK_EVENT) / sizeof(_AUDIO_CALLBACK_EVENT[0]);
 
        for (i = 0; i < tableTotalCount; i++)
        {
-               if (previous == _AUDIO_CALLBACK_EVENT[i].prevState && current == _AUDIO_CALLBACK_EVENT[i].postState && pObj->GetStateChangeReason() == _AUDIO_CALLBACK_EVENT[i].reason)
+               if (previous == _AUDIO_CALLBACK_EVENT[i].prevState && current == _AUDIO_CALLBACK_EVENT[i].postState && pImpl->GetStateChangeReason() == _AUDIO_CALLBACK_EVENT[i].reason)
                {
-                       r = pObj->GetEvent()->SendEvent(_AUDIO_CALLBACK_EVENT[i].event, _AUDIO_CALLBACK_EVENT[i].error, E_SUCCESS);
+                       r = pImpl->GetEvent()->SendEvent(_AUDIO_CALLBACK_EVENT[i].event, _AUDIO_CALLBACK_EVENT[i].error, E_SUCCESS);
                        SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating. i:%d", GetErrorMessage(r), i);
                        break;
                }
@@ -1115,29 +1109,29 @@ _AudioRecorderImpl::StateChangedCb(recorder_state_e previous, recorder_state_e c
 void
 _AudioRecorderImpl::RecordingStatusCb(unsigned long long elapsedTime, unsigned long long fileSize, void *pUserData)
 {
-       _AudioRecorderImpl* pObj = static_cast<_AudioRecorderImpl*>(pUserData);
-       SysTryReturnVoidResult(NID_MEDIA, _AudioRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
-       SysTryReturnVoidResult(NID_MEDIA, pObj != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _AudioRecorderImpl instance is not available. pObj is null.");
+       _AudioRecorderImpl* pImpl = static_cast<_AudioRecorderImpl*>(pUserData);
+       SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _AudioRecorderImpl 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);
 
-       pObj->SetRecordingTime((long)elapsedTime);
-       pObj->SetRecordingSize((long)fileSize);
+       pImpl->SetRecordingTime((long)elapsedTime);
+       pImpl->SetRecordingSize((long)fileSize);
 }
 
 void
 _AudioRecorderImpl::AudioStreamCb(void* pStream, int size, audio_sample_type_e format, int channel, unsigned int timeStamp, void *pUserData)
 {
-       _AudioRecorderImpl* pObj = static_cast<_AudioRecorderImpl*>(pUserData);
+       _AudioRecorderImpl* pImpl = static_cast<_AudioRecorderImpl*>(pUserData);
        int samplingRate =0;
-       SysTryReturnVoidResult(NID_MEDIA, _AudioRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
-       SysTryReturnVoidResult(NID_MEDIA, pObj != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _AudioRecorderImpl instance is not available. pObj is null.");
+       SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _AudioRecorderImpl instance is not available. pImpl 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] _AudioRecorderImpl instance is not available. Stream data is null.");
 
-       if (pObj->__audioStreamCallback == true)
+       if (pImpl->__audioStreamCallback == true)
        {
-               samplingRate = _RecorderUtil::CalculateSampleRate(size, channel, pObj->__audioStreamTimeDuration, _RecorderUtil::GetOspSampleType(format));
-               (pObj->__pAudioStreamCoordinator)->ProcessAudioStreamData((byte*)pStream, size, samplingRate, _RecorderUtil::GetOspChannelType(channel), _RecorderUtil::GetOspSampleType(format));
+               samplingRate = _RecorderUtil::CalculateSampleRate(size, channel, pImpl->__audioStreamTimeDuration, _RecorderUtil::GetOspSampleType(format));
+               (pImpl->__pAudioStreamCoordinator)->ProcessAudioStreamData((byte*)pStream, size, samplingRate, _RecorderUtil::GetOspChannelType(channel), _RecorderUtil::GetOspSampleType(format));
        }
 }
 
@@ -1145,9 +1139,9 @@ void
 _AudioRecorderImpl::LimitReachedCb(recorder_recording_limit_type_e type, void *pUserData)
 {
        result r = E_SUCCESS;
-       _AudioRecorderImpl* pObj = static_cast<_AudioRecorderImpl*>(pUserData);
-       SysTryReturnVoidResult(NID_MEDIA, pObj != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _AudioRecorderImpl instance is not available. pObj is null.");
-       SysTryReturnVoidResult(NID_MEDIA, _AudioRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
+       _AudioRecorderImpl* pImpl = static_cast<_AudioRecorderImpl*>(pUserData);
+       SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _AudioRecorderImpl 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);
 
@@ -1155,24 +1149,24 @@ _AudioRecorderImpl::LimitReachedCb(recorder_recording_limit_type_e type, void *p
        {
        case ::RECORDER_RECORDING_LIMIT_TIME:
        {
-               r = pObj->ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_TIME_REACHED);
+               r = pImpl->ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_TIME_REACHED);
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
        }
                break;
 
        case ::RECORDER_RECORDING_LIMIT_SIZE:
        {
-               r = pObj->ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_SIZE_REACHED);
+               r = pImpl->ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_SIZE_REACHED);
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
        }
                break;
 
        case ::RECORDER_RECORDING_LIMIT_FREE_SPACE:
        {
-               r = pObj->ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_OUT_OF_STORAGE);
+               r = pImpl->ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_OUT_OF_STORAGE);
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
-               r = pObj->GetEvent()->SendEvent(_RECORDER_EVENT_ERROR, RECORDER_ERROR_OUT_OF_STORAGE, E_STORAGE_FULL);
+               r = pImpl->GetEvent()->SendEvent(_RECORDER_EVENT_ERROR, RECORDER_ERROR_OUT_OF_STORAGE, E_STORAGE_FULL);
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
        }
                break;
@@ -1189,13 +1183,13 @@ void
 _AudioRecorderImpl::ErrorCb(recorder_error_e error, recorder_state_e state, void *pUserData)
 {
        result r = E_SUCCESS;
-       _AudioRecorderImpl* pObj = static_cast<_AudioRecorderImpl*>(pUserData);
-       SysTryReturnVoidResult(NID_MEDIA, _AudioRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
-       SysTryReturnVoidResult(NID_MEDIA, pObj != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _AudioRecorderImpl instance is not available. pObj is null.");
+       _AudioRecorderImpl* pImpl = static_cast<_AudioRecorderImpl*>(pUserData);
+       SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _AudioRecorderImpl 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);
 
-       r = pObj->GetEvent()->SendEvent(_RECORDER_EVENT_ERROR, RECORDER_ERROR_DEVICE_FAILED, E_SUCCESS);
+       r = pImpl->GetEvent()->SendEvent(_RECORDER_EVENT_ERROR, RECORDER_ERROR_DEVICE_FAILED, E_SUCCESS);
        SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
 
        return;
@@ -1204,19 +1198,13 @@ _AudioRecorderImpl::ErrorCb(recorder_error_e error, recorder_state_e state, void
 void
 _AudioRecorderImpl::InterruptedCb(recorder_policy_e policy, recorder_state_e previous, recorder_state_e current, void *pUserData)
 {
-       _AudioRecorderImpl* pObj = static_cast<_AudioRecorderImpl*>(pUserData);
-       SysTryReturnVoidResult(NID_MEDIA, _AudioRecorderImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
-       SysTryReturnVoidResult(NID_MEDIA, pObj != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] pObj _AudioRecorderImpl is not available. pObj is null.");
+       _AudioRecorderImpl* pImpl = static_cast<_AudioRecorderImpl*>(pUserData);
+       SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] pImpl _AudioRecorderImpl 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);
 }
 
-bool
-_AudioRecorderImpl::IsAlive(void)
-{
-       return __isUsed;
-}
-
 _AudioRecorderImpl*
 _AudioRecorderImpl::GetInstance(AudioRecorder *pAudioRecorder)
 {
index b8a7aab..fd27e94 100755 (executable)
@@ -33,6 +33,7 @@ namespace Tizen { namespace Media
 {
 class AudioRecorder;
 class IAudioRecorderEventListener;
+class _RecorderRef;
 class _AudioRecorderEvent;
 class _RecorderManager;
 class _AudioStreamCoordinator;
@@ -510,13 +511,6 @@ public:
        static void InterruptedCb(recorder_policy_e policy, recorder_state_e previous, recorder_state_e current, void *pUserData);
 
        /**
-        * Function check fo this object is alive.
-        *
-        * @return              true if the object is alive, otherwise false.
-        */
-       static bool IsAlive(void);
-
-       /**
         * Gets the Impl instance.
         *
         * @return              The pointer to %_AudioRecorderImpl
@@ -595,6 +589,7 @@ private:
        _AudioRecorderImpl(const _AudioRecorderImpl&);
        _AudioRecorderImpl& operator =(const _AudioRecorderImpl& _AudioRecorderImpl);
 
+       std::unique_ptr <_RecorderRef> __pRecorderRef;
        std::unique_ptr <_AudioRecorderEvent> __pAudioRecorderEvent;
        IAudioRecorderEventListener* __pAudioRecorderEventListener;
        _RecorderManager* __pRecorderManager;
@@ -610,7 +605,6 @@ private:
        bool __mute;
        _RecorderHandle __handle;
        _RecorderStateChangeReason __stateChangeReason;
-       static bool __isUsed;
        std::unique_ptr <_AudioStreamCoordinator> __pAudioStreamCoordinator;
        int __audioStreamTimeDuration;
        bool __audioStreamCallback;
diff --git a/src/FMedia_CamRef.cpp b/src/FMedia_CamRef.cpp
new file mode 100755 (executable)
index 0000000..c614ede
--- /dev/null
@@ -0,0 +1,115 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file                       FMedia_CamRef.cpp
+ * @brief                      This file contains the implementation of the %_CamRef class.
+ *
+ */
+
+#include <unique_ptr.h>
+#include <pthread.h>
+#include <FBaseSysLog.h>
+#include "FMedia_CamRef.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+namespace Tizen { namespace Media
+{
+
+IList* _CamRef::__pList = null;
+
+_CamRef::_CamRef(void)
+:__pObj(null)
+{
+}
+
+_CamRef::~_CamRef(void)
+{
+       if (__pObj != null)
+       {
+               UnRegisterObject(*__pObj);
+       }
+}
+
+result
+_CamRef::Construct(const Tizen::Base::Object& obj)
+{
+       result r = E_SUCCESS;
+       r = RegisterObject(obj);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       __pObj = const_cast<Tizen::Base::Object*>(&obj);
+       return r;
+}
+
+void
+_CamRef::InitSingleton()
+{
+       result r = E_SUCCESS;
+       std::unique_ptr <ArrayList> pList (new (std::nothrow) ArrayList());
+       SysTryReturnVoidResult(NID_MEDIA, pList.get() != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+
+       r = pList->Construct();
+       SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       __pList = pList.release();
+       std::atexit(DestroySingleton);
+}
+
+void
+_CamRef::DestroySingleton(void)
+{
+       delete __pList;
+}
+
+bool
+_CamRef::IsAlive(const Tizen::Base::Object& obj)
+{
+       SysTryReturn(NID_MEDIA, __pList != null, false, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Any object was not found.");
+       return __pList->Contains(obj);
+}
+
+result
+_CamRef::RegisterObject(const Tizen::Base::Object& obj)
+{
+       result r = E_SUCCESS;
+
+       static pthread_once_t once_block = PTHREAD_ONCE_INIT;
+       if (!__pList)
+       {
+               pthread_once(&once_block, InitSingleton);
+               r = GetLastResult();
+               SysTryReturn(NID_MEDIA, __pList != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       }
+
+       r = __pList->Add(const_cast<Tizen::Base::Object*>(&obj));
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       return r;
+}
+
+void
+_CamRef::UnRegisterObject(const Tizen::Base::Object& obj)
+{
+       result r = E_SUCCESS;
+       SysTryReturnVoidResult(NID_MEDIA, __pList != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] No object has been registered.");
+
+       r = __pList->Remove(obj);
+       SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+}
+
+}}// Tizen::Media
diff --git a/src/FMedia_CamRef.h b/src/FMedia_CamRef.h
new file mode 100755 (executable)
index 0000000..879f29e
--- /dev/null
@@ -0,0 +1,107 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file                       FMedia_CamRef.h
+ * @brief                      This header file contains the declarations of the %_CamRef class.
+ *
+ */
+
+#ifndef _FMEDIA_INTERNAL_CAM_REF_H_
+#define _FMEDIA_INTERNAL_CAM_REF_H_
+
+#include <FBaseColIList.h>
+#include <FBaseObject.h>
+
+namespace Tizen { namespace Media
+{
+
+/**
+ * @class      _CamRef
+ * @brief      This class implements the _CamRef class.
+ */
+class _CamRef
+       : public Tizen::Base::Object
+{
+public:
+       /**
+        * This is the default constructor for this class.
+        *
+        * @remarks             After creating an instance of this class, the Construct() method must be called explicitly to
+        * initialize this instance.
+        * @see                 Construct()
+        */
+       _CamRef(void);
+
+       /**
+        * This is the destructor for this class.
+        */
+       virtual ~_CamRef(void);
+
+       /**
+       * Initializes this instance of _CamRef.
+       *
+       * @return               An error code
+       * @param[in]    obj                     The object
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_INVALID_ARG   The specified input parameter is invalid.
+       */
+       result Construct(const Tizen::Base::Object& obj);
+
+       /**
+       * Check the object is alive
+       *
+       * @return               The pointer of Object instance
+       * @param[in]    obj                     The object
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_OBJ_NOT_FOUND The specified obj is not found.
+       */
+       static bool IsAlive(const Tizen::Base::Object& obj);
+private:
+       /**
+       * Register an instance of Object to the list.
+       *
+       * @return               An error code
+       * @param[in]    obj                     The object pointer
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_INVALID_ARG   The specified input parameter is invalid.
+       */
+       result RegisterObject(const Tizen::Base::Object& obj);
+
+       /**
+       * Unregister the specific instance of Object from the list.
+       *
+       * @param[in]    obj                     The object pointer
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_OBJ_NOT_FOUND The specified obj is not found.
+       */
+       void UnRegisterObject(const Tizen::Base::Object& obj);
+
+       _CamRef(const _CamRef& rhs);
+       _CamRef& operator =(const _CamRef& rhs);
+
+       Tizen::Base::Object* __pObj;
+
+       static void InitSingleton(void);
+       static void DestroySingleton(void);
+       
+       static Tizen::Base::Collection::IList* __pList;
+};
+
+}}// Tizen::Media
+
+#endif
index 885e20f..d475c0a 100755 (executable)
@@ -313,18 +313,23 @@ _CameraCapability::Construct(_CameraDeviceType cameraDevice)
 }
 
 void
-_CameraCapability::InitSafeHashMapInst()
+_CameraCapability::InitSingleton()
 {
-       static _CameraCapabilitySafeHashMapT map;
        result r = E_SUCCESS;
+       std::unique_ptr <_CameraCapabilitySafeHashMapT> pMap (new (std::nothrow) _CameraCapabilitySafeHashMapT());
+       SysTryReturnVoidResult(NID_MEDIA, pMap.get() != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
 
-       r = map.Construct();
-       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+       r = pMap->Construct();
+       SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       __pMap = &map;
-       return;
-CATCH:
-       __pMap = null;
+       __pMap = pMap.release();
+       std::atexit(DestroySingleton);
+}
+
+void
+_CameraCapability::DestroySingleton(void)
+{
+       delete __pMap;
 }
 
 _CameraCapability*
@@ -343,7 +348,7 @@ _CameraCapability::AddInstance(_CameraDeviceType cameraDevice)
 
        if (!__pMap)
        {
-               pthread_once(&once_block, InitSafeHashMapInst);
+               pthread_once(&once_block, InitSingleton);
                r = GetLastResult();
                SysTryReturn(NID_MEDIA, __pMap != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
        }
index 1deedeb..10f3fa5 100755 (executable)
@@ -597,7 +597,8 @@ private:
        static bool SupportedCameraAttrMeteringModeCb(camera_attr_exposure_mode_e mode, void *pUserData);
        static bool SupportedCameraAttrAfModeCb(camera_attr_af_mode_e mode, void *pUserData);
 
-       static void InitSafeHashMapInst(void);
+       static void InitSingleton(void);
+       static void DestroySingleton(void);
 
        static _CameraCapabilitySafeHashMapT* __pMap;
        static const keyServiceMap __SERVICE_MAP[];
index ec06e77..827da90 100755 (executable)
@@ -40,14 +40,14 @@ _CameraCapabilitySession::_CameraCapabilitySession(void)
 _CameraCapabilitySession::~_CameraCapabilitySession(void)
 {
        _CameraCapability::Release(__cameraDevice);
-       SysLog(NID_MEDIA, "Capability handle released");
+//     SysLog(NID_MEDIA, "Capability handle released");
 }
 
 result
 _CameraCapabilitySession::Construct(_CameraDeviceType cameraDevice)
 {
        result r = E_SUCCESS;
-       SysLog(NID_MEDIA, "Enter. camera device:%d", cameraDevice);
+//     SysLog(NID_MEDIA, "Enter. camera device:%d", cameraDevice);
 
        __pCameraCapability = _CameraCapability::AddInstance(cameraDevice);
        SysTryCatch(NID_MEDIA, __pCameraCapability != null, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  __pCameraCapability instance must not be null.");
index 5862216..ad0e2b7 100755 (executable)
@@ -180,6 +180,26 @@ _CameraCoordinator::RemoveRecorder(_RecorderDeviceType recorderDevice)
        }
 }
 
+void
+_CameraCoordinator::InitSingleton()
+{
+       result r = E_SUCCESS;
+       std::unique_ptr <_CameraCoordinatorSafeHashMapT> pMap (new (std::nothrow) _CameraCoordinatorSafeHashMapT());
+       SysTryReturnVoidResult(NID_MEDIA, pMap.get() != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+
+       r = pMap->Construct();
+       SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       __pMap = pMap.release();
+       std::atexit(DestroySingleton);
+}
+
+void
+_CameraCoordinator::DestroySingleton(void)
+{
+       delete __pMap;
+}
+
 _CameraCoordinator*
 _CameraCoordinator::AddInstance(_CameraDeviceType cameraDevice)
 {
@@ -187,27 +207,25 @@ _CameraCoordinator::AddInstance(_CameraDeviceType cameraDevice)
        bool out = false;
        ClearLastResult();
 
-       static bool isMapConstructed = false;
-       static _CameraCoordinatorSafeHashMapT map;
        _CameraCoordinator* pCoordinator = null;
 
        SysTryReturn(NID_MEDIA, cameraDevice > _CAMERA_DEVICE_NONE && cameraDevice < _CAMERA_DEVICE_MAX,
                                null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(camderDevice) is used. camderDevice:%d is wrong.", cameraDevice);
 
-       if (!isMapConstructed)
+       static pthread_once_t once_block = PTHREAD_ONCE_INIT;
+       if (!__pMap)
        {
-               r = map.Construct();
-               SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-               isMapConstructed = true;
-               __pMap = &map;
+               pthread_once(&once_block, InitSingleton);
+               r = GetLastResult();
+               SysTryReturn(NID_MEDIA, __pMap != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
        }
 
-       r = map.ContainsKey(cameraDevice, out);
+       r = __pMap->ContainsKey(cameraDevice, out);
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
 
        if (out)
        {
-               r = map.GetValue(cameraDevice, pCoordinator);
+               r = __pMap->GetValue(cameraDevice, pCoordinator);
                SysTryReturn(NID_MEDIA, r == E_SUCCESS && pCoordinator != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
        }
        else
@@ -218,7 +236,7 @@ _CameraCoordinator::AddInstance(_CameraDeviceType cameraDevice)
                r = pCoord->Construct(cameraDevice);
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
 
-               r = map.Add(cameraDevice, pCoord.get());
+               r = __pMap->Add(cameraDevice, pCoord.get());
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
 
                pCoordinator = pCoord.release();
index 6dd39ff..c448b8d 100755 (executable)
@@ -412,6 +412,8 @@ private:
        std::unique_ptr<Tizen::Base::Collection::LinkedListT <_ICameraCoordinatorListener*>, _ListPtrUtil::Remover> __pListenerList;
        camera_pixel_format_e __reloadCameraPreviewFormat;
 
+       static void InitSingleton(void);
+       static void DestroySingleton(void);
        static _CameraCoordinatorSafeHashMapT* __pMap;
 };
 
index 9a01324..7ecd107 100755 (executable)
@@ -42,6 +42,7 @@
 #include "FMedia_CameraCoordinator.h"
 #include "FMedia_CapabilityImpl.h"
 #include "FMedia_VideoStreamCoordinator.h"
+#include "FMedia_CameraRef.h"
 
 #define _CAMERA_EVAS_PIXMAP_ 1
 
@@ -93,8 +94,6 @@ static const int _MIN_PROPERTY = 0;
 static const int _MAX_PROPERTY = 9;
 static const int _INVALID_FOCUS_COORDINATE = -1;
 
-bool _CameraImpl::__isUsed = false;
-
 enum _FocusModeOperation
 {
        _FOCUS_MODE_OP_NONE,
@@ -171,6 +170,7 @@ _CameraImpl::_CameraImpl(void)
        , __pCameraCapability(null)
        , __state(CAMERA_STATE_INITIALIZED)
        , __handle(MM_INVALID_HANDLE)
+       , __pCameraRef(null)
        , __pCameraEvent(null)
        , __pVideoStreamCoordinator(null)
        , __pCameraEventListener(null)
@@ -268,11 +268,6 @@ _CameraImpl::~_CameraImpl(void)
                _CameraCapability::Release(__deviceType);
        }
 
-       if ( __isConstructed )
-       {
-               __isUsed = false;
-       }
-
        SysLog(NID_MEDIA, "Destroyed");
 }
 
@@ -281,9 +276,11 @@ _CameraImpl::Construct(ICameraEventListener& listener, CameraSelection camSel)
 {
        result r = E_SUCCESS;
        int err = MM_SUCCESS;
+       int direction = 0;
+       int rotation = 0;
+       int focusPoint = 0;
        SysLog(NID_MEDIA, "Enter. camSel:%d", camSel);
 
-       SysTryReturn(NID_MEDIA, !__isUsed, E_DEVICE_BUSY, E_DEVICE_BUSY, "[E_DEVICE_BUSY] A camera device is already used.");
        SysTryReturn(NID_MEDIA, !__isConstructed, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] _CameraImpl is in an invalid state. A camera device is already constructed.");
        SysTryReturn(NID_MEDIA, camSel >= CAMERA_PRIMARY && camSel <= CAMERA_SECONDARY, E_DEVICE_UNAVAILABLE, E_DEVICE_UNAVAILABLE, "[E_DEVICE_UNAVAILABLE] The camsel(%d)  is invalid.", camSel);
 
@@ -298,16 +295,21 @@ _CameraImpl::Construct(ICameraEventListener& listener, CameraSelection camSel)
        SysTryReturn(NID_MEDIA, camSel < cameraCount, E_UNSUPPORTED_OPERATION, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] The camSel(%d)  is not available.", camSel);
        __selection = camSel;
 
+       __deviceType = (camSel == CAMERA_PRIMARY ? _CAMERA_DEVICE_PRIMARY : _CAMERA_DEVICE_SECONDARY);
+
+       // Register this object to _CameraRef
+       __pCameraRef.reset(new (std::nothrow) _CameraRef());
+       SysTryCatch(NID_MEDIA, __pCameraRef.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.   The object is not created.");
+
+       r = __pCameraRef->Construct(*this, __deviceType);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
        // Get the _CameraCapability.
        // This is just for the performance enhancement by incrementing ref counts of _CameraCapability.
        // It forbiddens creating and deleting the _CameraCapability object repeatedly.
-       __deviceType = (camSel == CAMERA_PRIMARY ? _CAMERA_DEVICE_PRIMARY : _CAMERA_DEVICE_SECONDARY);
        __pCameraCapability = _CameraCapability::AddInstance(__deviceType);
        SysTryReturn(NID_MEDIA, __pCameraCapability != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Capability instance is not available.");
 
-       int direction = 0;
-       int rotation = 0;
-       int focusPoint = 0;
        r = pCapabilityImpl->GetValue(camSel == CAMERA_PRIMARY ? String(L"Camera.Primary.Direction") : String(L"Camera.Secondary.Direction"), direction);
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -321,9 +323,9 @@ _CameraImpl::Construct(ICameraEventListener& listener, CameraSelection camSel)
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
        __supportedFocusPointCount = focusPoint;
 
-// Create Event
+       // Create Event
        __pCameraEvent.reset(new (std::nothrow) _CameraEvent());
-       SysTryReturn(NID_MEDIA, __pCameraEvent.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryReturn(NID_MEDIA, __pCameraEvent.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = __pCameraEvent->Construct(*this);
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -332,23 +334,23 @@ _CameraImpl::Construct(ICameraEventListener& listener, CameraSelection camSel)
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
        __pCameraEventListener = &listener;
 
-// Video stream coordinator
+       // Video stream coordinator
        __pVideoStreamCoordinator.reset(new (std::nothrow) _VideoStreamCoordinator());
-       SysTryReturn(NID_MEDIA, __pVideoStreamCoordinator.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryReturn(NID_MEDIA, __pVideoStreamCoordinator.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = __pVideoStreamCoordinator->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
-// Prepare captured buffer list
+       // Prepare captured buffer list
        __pCaptureBufferQueue.reset(new (std::nothrow) Tizen::Base::Collection::Queue());
-       SysTryCatch(NID_MEDIA, __pCaptureBufferQueue.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, __pCaptureBufferQueue.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = __pCaptureBufferQueue->Construct(_MAX_CAPTURE_BUFFER_COUNT);         // For async panorama shot.
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
-// Prepare preview buffer list
+       // Prepare preview buffer list
        __pPreviewBufferQueue.reset(new (std::nothrow) Tizen::Base::Collection::Queue());
-       SysTryCatch(NID_MEDIA, __pPreviewBufferQueue.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, __pPreviewBufferQueue.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = __pPreviewBufferQueue->Construct(_MAX_PREVIEW_BUFFER_COUNT);         // For async preview data.
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -388,7 +390,6 @@ _CameraImpl::Construct(ICameraEventListener& listener, CameraSelection camSel)
 
        SetState(CAMERA_STATE_INITIALIZED);
        __isConstructed = true;
-       __isUsed = true;
        return r;
 
 CATCH:
@@ -403,6 +404,14 @@ CATCH:
        if (__pCoordinator != null)
        {
                __pCoordinator->RemoveCameraCoordinatorListener(*this);
+               _CameraCoordinator::Release(__deviceType);
+               __pCoordinator = null;
+       }
+
+       if (__pCameraCapability != null)
+       {
+               _CameraCapability::Release(__deviceType);
+               __pCameraCapability = null;
        }
 
        if (__pCameraEventListener != null)
@@ -411,9 +420,11 @@ CATCH:
                __pCameraEventListener = null;
        }
 
+       __pCameraRef.reset(null);
        __pCameraEvent.reset(null);
        __pVideoStreamCoordinator.reset(null);
        __pCaptureBufferQueue.reset(null);
+       __pPreviewBufferQueue.reset(null);
 
        return r;
 }
@@ -1453,7 +1464,7 @@ _CameraImpl::GetAutoFocusPointN(void) const
 
        //Create new list
        std::unique_ptr <_MediaSafeArrayList, _ListPtrUtil::Remover> pFocusPointList (new (std::nothrow) _MediaSafeArrayList(), _ListPtrUtil::remover);
-       SysTryCatch(NID_MEDIA, pFocusPointList.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, pFocusPointList.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = pFocusPointList->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -1522,7 +1533,7 @@ _CameraImpl::GetSupportedCaptureFormatListN(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 <Tizen::Base::Collection::ArrayListT<Tizen::Graphics::PixelFormat>, _ListPtrUtil::Remover> pFormatList (new (std::nothrow) ArrayListT<Tizen::Graphics::PixelFormat>(), _ListPtrUtil::remover);
-       SysTryReturn(NID_MEDIA, pFormatList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryReturn(NID_MEDIA, pFormatList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = pFormatList->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -1596,7 +1607,7 @@ _CameraImpl::GetSupportedPreviewFormatListN(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 <Tizen::Base::Collection::ArrayListT<Tizen::Graphics::PixelFormat>, _ListPtrUtil::Remover> pFormatList (new (std::nothrow) ArrayListT<Tizen::Graphics::PixelFormat>(), _ListPtrUtil::remover);
-       SysTryReturn(NID_MEDIA, pFormatList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryReturn(NID_MEDIA, pFormatList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = pFormatList->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -1726,7 +1737,7 @@ _CameraImpl::GetSupportedPreviewFrameRateListN(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 <Tizen::Base::Collection::ArrayListT<int>, _ListPtrUtil::Remover> pListT (new (std::nothrow) ArrayListT<int>(), _ListPtrUtil::remover);
-       SysTryReturn(NID_MEDIA, pListT.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryReturn(NID_MEDIA, pListT.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = pListT->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -1767,7 +1778,7 @@ _CameraImpl::GetSupportedPreviewFrameRateListN(const Tizen::Graphics::Dimension&
        SysTryReturn(NID_MEDIA, pIntegerList->GetCount() > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.  The list was empty.");
 
        std::unique_ptr <Tizen::Base::Collection::ArrayListT<int>, _ListPtrUtil::Remover> pListT (new (std::nothrow) ArrayListT<int>(), _ListPtrUtil::remover);
-       SysTryCatch(NID_MEDIA, pListT.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, pListT.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = pListT->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -2207,7 +2218,7 @@ _CameraImpl::EnqueueData(_CameraBuffer& cameraBuffer)
        SysTryReturn(NID_MEDIA, cameraBuffer.GetLimit() > 0, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] Propagating. bufferType:%d", GetErrorMessage(r), bufferType);
 
        std::unique_ptr <_CameraBuffer> pCameraBuffer (new (std::nothrow) _CameraBuffer());
-       SysTryReturn(NID_MEDIA, pCameraBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+       SysTryReturn(NID_MEDIA, pCameraBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = pCameraBuffer->Construct(cameraBuffer);
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. bufferType:%d", GetErrorMessage(r), bufferType);
@@ -2438,7 +2449,7 @@ _CameraImpl::GetPropertyListN(const Tizen::Base::String& key) const
        _CapabilityImpl* pCapability = null;
 
        std::unique_ptr <ArrayList, _ListPtrUtil::Remover> pList (new (std::nothrow) ArrayList(), _ListPtrUtil::remover);
-       SysTryCatch(NID_MEDIA, pList.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, pList.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
 
        r = pList->Construct();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -3091,8 +3102,8 @@ void
 _CameraImpl::StateChangedCb(camera_state_e previous, camera_state_e current, bool byPolicy, void *pUserData)
 {
        _CameraImpl* pImpl = static_cast<_CameraImpl*>( pUserData);
-       SysTryReturnVoidResult(NID_MEDIA, _CameraImpl::IsAlive(), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysTryReturnVoidResult(NID_MEDIA, pImpl != null, E_OBJ_NOT_FOUND, "[%s] _CameraImpl instance is not available.", GetErrorMessage(E_OBJ_NOT_FOUND));
+       SysTryReturnVoidResult(NID_MEDIA, _CameraRef::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);
 }
 
@@ -3103,8 +3114,8 @@ _CameraImpl::CaptureCb(camera_image_data_s* pImage, camera_image_data_s *pPostvi
        _CameraImpl* pImpl = static_cast<_CameraImpl*>(pUserData);
        MediaPixelFormat format = MEDIA_PIXEL_FORMAT_NONE;
        double ratio = 0.0;
-       SysTryReturnVoidResult(NID_MEDIA, _CameraImpl::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] _CameraImpl is null.");
+       SysTryReturnVoidResult(NID_MEDIA, _CameraRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        //******************
        //SysTryReturnVoidResult(NID_MEDIA, pImpl->GetState() == CAMERA_STATE_CAPTURING, E_INVALID_STATE, "[E_INVALID_STATE] The camera is already capturing");
        //Commentout : Because it is not guaranteed that CaptureCb API is called after Capture API is completed.
@@ -3157,8 +3168,8 @@ _CameraImpl::CaptureCompletedCb(void *pUserData)
        _CameraImpl* pImpl = static_cast<_CameraImpl*>(pUserData);
        SysLog(NID_MEDIA, "CaptureCompletedCb");
 
-       SysTryReturnVoidResult(NID_MEDIA, _CameraImpl::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] _CameraImpl instance is not available.");
+       SysTryReturnVoidResult(NID_MEDIA, _CameraRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
 
        std::unique_ptr <ByteBuffer> pBuffer (pImpl->DequeueDataN(_CAMERA_BUFFER_CAPTURE));
        if (pBuffer.get() != null)
@@ -3193,8 +3204,8 @@ _CameraImpl::PreviewCb(camera_preview_data_s *pFrame, void *pUserData)
        int queueCount = 0;
        _CameraImpl* pImpl = static_cast<_CameraImpl*>(pUserData);
 
-       SysTryReturnVoidResult(NID_MEDIA, _CameraImpl::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] _CameraImpl instance is not available.");
+       SysTryReturnVoidResult(NID_MEDIA, _CameraRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysTryReturnVoidResult(NID_MEDIA, pFrame != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] camera_preview_data_s instance is not available.");
        SysLog(NID_MEDIA, "Enter. preview format:%d, width:%d, height:%d, num_of_planes:%d", pFrame->format, pFrame->width, pFrame->height, pFrame->num_of_planes);
 
@@ -3331,8 +3342,8 @@ _CameraImpl::InterruptedCb(camera_policy_e policy, camera_state_e previous, came
        result r = E_SUCCESS;
        _CameraImpl* pImpl = static_cast<_CameraImpl*>(pUserData);
        SysLog(NID_MEDIA, "InterruptedCb called, policy is %d, previous state is %d, current state is %d, pUserData address is %x  ", policy, previous, current, pUserData );
-       SysTryReturnVoidResult(NID_MEDIA, _CameraImpl::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] _CameraImpl instance is not available.");
+       SysTryReturnVoidResult(NID_MEDIA, _CameraRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        SysTryReturnVoidResult(NID_MEDIA, pImpl->IsPoweredOn() == true, E_INVALID_OPERATION  ,"The camera is already power-offed");
        r = pImpl->__pCameraEvent->SendEvent(_CAMERA_EVENT_ERROR, CAMERA_ERROR_DEVICE_INTERRUPTED, E_DEVICE_FAILED, null);
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "Sending camera interrupted failed [%s] .", GetErrorMessage(r));
@@ -3346,8 +3357,8 @@ _CameraImpl::ErrorCb(camera_error_e error, camera_state_e current, void *pUserDa
        result r = E_SUCCESS;
        _CameraImpl* pImpl = static_cast<_CameraImpl*>(pUserData);
        SysLog(NID_MEDIA, "ErrorCb called, error is 0x%x, current state is %d, pUserData address is %x  ", error, current, pUserData );
-       SysTryReturnVoidResult(NID_MEDIA, _CameraImpl::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] _CameraImpl instance is not available.");
+       SysTryReturnVoidResult(NID_MEDIA, _CameraRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
        switch (error)
        {
        case ::CAMERA_ERROR_OUT_OF_MEMORY:
@@ -3377,8 +3388,8 @@ _CameraImpl::FocusStateChangedCb(camera_focus_state_e state, void *pUserData)
        CameraErrorReason cameraErrorReason = CAMERA_ERROR_NONE;
        result cameraResult = E_SUCCESS;
        SysLog(NID_MEDIA, "Enter. state is %d.", state);
-       SysTryReturnVoidResult(NID_MEDIA, _CameraImpl::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] _CameraImpl instance is not available.");
+       SysTryReturnVoidResult(NID_MEDIA, _CameraRef::IsAlive(*pImpl), E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
 
        CameraFocusMode focusMode = pImpl->GetFocusMode();
 
@@ -3437,12 +3448,6 @@ CATCH:
        return;
 }
 
-bool
-_CameraImpl::IsAlive(void)
-{
-       return __isUsed;
-}
-
 _CameraImpl*
 _CameraImpl::GetInstance(Camera *pCamera)
 {
index e20406f..cb64cb4 100755 (executable)
@@ -47,6 +47,7 @@ namespace Tizen { namespace Media
 {
 class Camera;
 class ICameraEventListener;
+class _CameraRef;
 class _CameraEvent;
 class _CameraCoordinator;
 class _CameraCapability;
@@ -1331,13 +1332,6 @@ public:
        static void FocusStateChangedCb(camera_focus_state_e state, void *pUserData);
 
        /**
-        *      Function check fo this object is alive.
-        *
-        * @return              true if the object is alive, otherwise false.
-        */
-       static bool IsAlive(void);
-
-       /**
         * Gets the Impl instance.
         *
         * @return              The pointer to %_CameraImpl
@@ -1463,6 +1457,7 @@ private:
        CameraState __state;
        _CameraHandle __handle;
 
+       std::unique_ptr <_CameraRef> __pCameraRef;
        std::unique_ptr <_CameraEvent> __pCameraEvent;
        std::unique_ptr <_VideoStreamCoordinator> __pVideoStreamCoordinator;
        ICameraEventListener* __pCameraEventListener;
@@ -1522,7 +1517,6 @@ private:
        int __focusPoints[2][MAX_FOCUS_POINT];
        int __supportedFocusPointCount;
 
-       static bool __isUsed;
        static const int MAX_CAMERA_PLANE_COUNT = 4;
 };
 
index d3be88a..122cea9 100755 (executable)
@@ -112,18 +112,23 @@ CATCH:
 }
 
 void
-_CameraManager::InitSafeHashMapInst()
+_CameraManager::InitSingleton()
 {
-       static _CameraManagerSafeHashMapT map;
        result r = E_SUCCESS;
+       std::unique_ptr <_CameraManagerSafeHashMapT> pMap (new (std::nothrow) _CameraManagerSafeHashMapT());
+       SysTryReturnVoidResult(NID_MEDIA, pMap.get() != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
 
-       r = map.Construct();
-       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+       r = pMap->Construct();
+       SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       __pMap = &map;
-       return;
-CATCH:
-       __pMap = null;
+       __pMap = pMap.release();
+       std::atexit(DestroySingleton);
+}
+
+void
+_CameraManager::DestroySingleton(void)
+{
+       delete __pMap;
 }
 
 _CameraManager*
@@ -138,7 +143,7 @@ _CameraManager::AddInstance(_CameraDeviceType cameraDevice)
        static pthread_once_t once_block = PTHREAD_ONCE_INIT;
        if (!__pMap)
        {
-               pthread_once(&once_block, InitSafeHashMapInst);
+               pthread_once(&once_block, InitSingleton);
                r = GetLastResult();
                SysTryReturn(NID_MEDIA, __pMap != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
        }
index 4a7ee23..bffab32 100755 (executable)
@@ -108,10 +108,11 @@ private:
        */
        result ConvertResult(int err) const;
 
-       _CameraManager(const _CameraManager& camera);
-       _CameraManager& operator =(const _CameraManager& camera);
+       _CameraManager(const _CameraManager& rhs);
+       _CameraManager& operator =(const _CameraManager& rhs);
 
-       static void InitSafeHashMapInst(void);
+       static void InitSingleton(void);
+       static void DestroySingleton(void);
 
        _CameraHandle __handle;
 
diff --git a/src/FMedia_CameraRef.cpp b/src/FMedia_CameraRef.cpp
new file mode 100755 (executable)
index 0000000..39557b2
--- /dev/null
@@ -0,0 +1,116 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file                       FMedia_CameraRef.cpp
+ * @brief                      This file contains the implementation of the %_CameraRef class.
+ *
+ */
+
+#include <unique_ptr.h>
+#include <pthread.h>
+#include <FBaseSysLog.h>
+#include <FBaseColArrayListT.h>
+#include "FMedia_CameraRef.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+namespace Tizen { namespace Media
+{
+
+IListT<_CameraDeviceType>* _CameraRef::__pList = null;
+
+_CameraRef::_CameraRef(void)
+:__deviceType(_CAMERA_DEVICE_NONE)
+{
+}
+
+_CameraRef::~_CameraRef(void)
+{
+       UnRegisterCamera(__deviceType);
+}
+
+result
+_CameraRef::Construct(const Tizen::Base::Object& obj, _CameraDeviceType deviceType)
+{
+       result r = E_SUCCESS;
+
+       r = _CamRef::Construct(obj);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       r = RegisterCamera(deviceType);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       __deviceType = deviceType;
+       return r;
+}
+
+void
+_CameraRef::InitSingleton(void)
+{
+       result r = E_SUCCESS;
+       std::unique_ptr <ArrayListT<_CameraDeviceType> > pList (new (std::nothrow) ArrayListT<_CameraDeviceType>());
+       SysTryReturnVoidResult(NID_MEDIA, pList.get() != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+
+       r = pList->Construct();
+       SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       __pList = pList.release();
+       std::atexit(DestroySingleton);
+}
+
+void
+_CameraRef::DestroySingleton(void)
+{
+       delete __pList;
+}
+
+result
+_CameraRef::RegisterCamera(_CameraDeviceType deviceType)
+{
+       result r = E_SUCCESS;
+
+       static pthread_once_t once_block = PTHREAD_ONCE_INIT;
+       if (!__pList)
+       {
+               pthread_once(&once_block, InitSingleton);
+               r = GetLastResult();
+               SysTryReturn(NID_MEDIA, __pList != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       }
+
+       // Duplicate camera devices cannot be created.
+       // Separate camera devices can be created.
+       SysTryReturn(NID_MEDIA, __pList->Contains(deviceType) != true, E_DEVICE_BUSY, E_DEVICE_BUSY
+               , "[E_DEVICE_BUSY] The camera%d is under use by other application or already used in this application.", deviceType);
+
+       r = __pList->Add(deviceType);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       return r;
+}
+
+void
+_CameraRef::UnRegisterCamera(_CameraDeviceType deviceType)
+{
+       result r = E_SUCCESS;
+       SysTryReturnVoidResult(NID_MEDIA, __pList != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] No object has been registered.");
+
+       r = __pList->Remove(deviceType);
+       SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+}
+
+}}// Tizen::Media
diff --git a/src/FMedia_CameraRef.h b/src/FMedia_CameraRef.h
new file mode 100755 (executable)
index 0000000..2658589
--- /dev/null
@@ -0,0 +1,101 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file                       FMedia_CameraRef.h
+ * @brief                      This header file contains the declarations of the %_CameraRef class.
+ *
+ */
+
+#ifndef _FMEDIA_INTERNAL_CAMERA_REF_H_
+#define _FMEDIA_INTERNAL_CAMERA_REF_H_
+
+#include <FBaseColIListT.h>
+#include "FMedia_CameraTypes.h"
+#include "FMedia_CamRef.h"
+
+namespace Tizen { namespace Media
+{
+
+/**
+ * @class      _CameraRef
+ * @brief      This class implements the _CameraRef class.
+ */
+class _CameraRef
+       : public _CamRef
+{
+public:
+       /**
+        * This is the default constructor for this class.
+        *
+        * @remarks             After creating an instance of this class, the Construct() method must be called explicitly to
+        * initialize this instance.
+        * @see                 Construct()
+        */
+       _CameraRef(void);
+
+       /**
+        * This is the destructor for this class.
+        */
+       virtual ~_CameraRef(void);
+
+       /**
+       * Initializes this instance of _CameraRef.
+       *
+       * @return               An error code
+       * @param[in]    obj                     The object
+       * @param[in]    deviceType      The camera device type
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_INVALID_ARG   The specified input parameter is invalid.
+       */
+       result Construct(const Tizen::Base::Object& obj, _CameraDeviceType deviceType);
+
+private:
+       /**
+       * Register a camera device to the list.
+       *
+       * @return               An error code
+       * @param[in]    deviceType      The camera device type
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_INVALID_ARG   The specified input parameter is invalid.
+       * @exception    E_DEVICE_BUSY                   The camera is under use by other application or already used in this application.
+       */
+       result RegisterCamera(_CameraDeviceType deviceType);
+
+       /**
+       * Unregister the specific camera device from the list.
+       *
+       * @param[in]    deviceType      The camera device type
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_OBJ_NOT_FOUND The specified device type is not found.
+       */
+       void UnRegisterCamera(_CameraDeviceType deviceType);
+
+       _CameraRef(const _CameraRef& rhs);
+       _CameraRef& operator =(const _CameraRef& rhs);
+
+       _CameraDeviceType __deviceType;
+
+       static void InitSingleton(void);
+       static void DestroySingleton(void);
+       
+       static Tizen::Base::Collection::IListT<_CameraDeviceType>* __pList;
+};
+
+}}// Tizen::Media
+
+#endif
index 0faa30f..57c5f7c 100755 (executable)
@@ -64,21 +64,29 @@ const wchar_t* const VIDEORECORDER_CODEC = L"VideoRecorder.Codec";
 const wchar_t* const CAMERA_PRIMARY_ZOOM_LEVEL = L"Camera.Primary.ZoomLevel";
 const wchar_t* const CAMERA_SECONDARY_ZOOM_LEVEL = L"Camera.Secondary.ZoomLevel";
 
+const wchar_t* const AUDIORECORDER_DEVICE_FPS = L"AudioRecorder.AudioFps";
+const wchar_t* const VIDEORECORDER_DEVICE_FPS = L"VideoRecorder.AudioFps";
+
 _CapabilityImpl* _CapabilityImpl::__pCapabilityImplInst = null;
 
 void
-_CapabilityImpl::InitCapabilityImpl()
+_CapabilityImpl::InitSingleton(void)
 {
-       static _CapabilityImpl capabilityImpl;
        result r = E_SUCCESS;
+       std::unique_ptr <_CapabilityImpl> pCapabilityImpl (new (std::nothrow) _CapabilityImpl());
+       SysTryReturnVoidResult(NID_MEDIA, pCapabilityImpl.get() != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
 
-       r = capabilityImpl.Construct();
-       SysTryCatch(NID_MEDIA, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Propagating.");
+       r = pCapabilityImpl->Construct();
+       SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Capability resource creation failed.");
 
-       __pCapabilityImplInst = &capabilityImpl;
-       return;
-CATCH:
-       __pCapabilityImplInst = null;
+       __pCapabilityImplInst = pCapabilityImpl.release();
+       std::atexit(DestroySingleton);
+}
+
+void
+_CapabilityImpl::DestroySingleton(void)
+{
+       delete __pCapabilityImplInst;
 }
 
 _CapabilityImpl*
@@ -88,7 +96,8 @@ _CapabilityImpl::GetInstance(void)
 
        if (!__pCapabilityImplInst)
        {
-               pthread_once(&once_block, InitCapabilityImpl);
+               pthread_once(&once_block, InitSingleton);
+               SysTryReturn(NID_MEDIA, __pCapabilityImplInst != null, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The instance is not found.");
        }
 
        return __pCapabilityImplInst;
@@ -333,9 +342,9 @@ static _CapabilityCopyMap _COPY_MAP[] =
        { AUDIOOUT_SAMPLE_TYPE, _CapabilityImpl::CopyListInteger, _MEDIA_CAP_CATEGORY_AUDIO },
 
        { AUDIORECORDER_FORMAT, _CapabilityImpl::CopyListString, _MEDIA_CAP_CATEGORY_AUDIO_RECORDER },
-
        { AUDIORECORDER_CODEC_TYPE, _CapabilityImpl::CopyListInteger, _MEDIA_CAP_CATEGORY_AUDIO_RECORDER },
        { AUDIORECORDER_MEDIA_CONTAINER_TYPE, _CapabilityImpl::CopyListInteger, _MEDIA_CAP_CATEGORY_AUDIO_RECORDER },
+       { AUDIORECORDER_DEVICE_FPS, _CapabilityImpl::CopyInteger, _MEDIA_CAP_CATEGORY_AUDIO_RECORDER },
 
        { CAMERA_COUNT, _CapabilityImpl::CopyInteger, _MEDIA_CAP_CATEGORY_PRIMARY_CAMERA },
 
@@ -413,10 +422,10 @@ static _CapabilityCopyMap _COPY_MAP[] =
        { VIDEORECORDER_AUDIO_CODEC, _CapabilityImpl::CopyListString, _MEDIA_CAP_CATEGORY_VIDEO_RECORDER },
        { VIDEORECORDER_FORMAT, _CapabilityImpl::CopyListString, _MEDIA_CAP_CATEGORY_VIDEO_RECORDER },
        { VIDEORECORDER_VIDEO_CODEC, _CapabilityImpl::CopyListString, _MEDIA_CAP_CATEGORY_VIDEO_RECORDER },
-
        { VIDEORECORDER_AUDIO_CODEC_TYPE, _CapabilityImpl::CopyListInteger, _MEDIA_CAP_CATEGORY_VIDEO_RECORDER },
        { VIDEORECORDER_VIDEO_CODEC_TYPE, _CapabilityImpl::CopyListInteger, _MEDIA_CAP_CATEGORY_VIDEO_RECORDER },
        { VIDEORECORDER_MEDIA_CONTAINER_TYPE, _CapabilityImpl::CopyListInteger, _MEDIA_CAP_CATEGORY_VIDEO_RECORDER },
+       { VIDEORECORDER_DEVICE_FPS, _CapabilityImpl::CopyInteger, _MEDIA_CAP_CATEGORY_VIDEO_RECORDER },
 };
 
 result
@@ -890,6 +899,7 @@ static _SectionParsingInfo _PARSING_INFO[] =
        { AUDIOOUT_SAMPLE_TYPE, ParseValueList, _CapabilityImpl::ConvertCharToEnum, _AUDIO_SAMPLE_TYPE_MAP },
 
        { AUDIORECORDER_FORMAT, ParseValueList, _CapabilityImpl::ConvertCharToString, 0 },
+       { AUDIORECORDER_DEVICE_FPS, ParseContent, _CapabilityImpl::ConvertCharToInteger, 0 },
 
 //     { AUDIORECORDER_CODEC_TYPE, ParseValueList, _CapabilityImpl::ConvertCharToEnum, _CODEC_TYPE_MAP},
 //     { AUDIORECORDER_MEDIA_CONTAINER_TYPE, ParseValueList, _CapabilityImpl::ConvertCharToEnum, _MEDIA_CONTAINER_TYPE_MAP},
@@ -970,6 +980,7 @@ static _SectionParsingInfo _PARSING_INFO[] =
        { VIDEORECORDER_AUDIO_CODEC, ParseValueList, _CapabilityImpl::ConvertCharToString, 0 },
        { VIDEORECORDER_FORMAT, ParseValueList, _CapabilityImpl::ConvertCharToString, 0 },
        { VIDEORECORDER_VIDEO_CODEC, ParseValueList, _CapabilityImpl::ConvertCharToString, 0 },
+       { VIDEORECORDER_DEVICE_FPS, ParseContent, _CapabilityImpl::ConvertCharToInteger, 0 },
 
 //     { VIDEORECORDER_AUDIO_CODEC_TYPE, ParseValueList, _CapabilityImpl::ConvertCharToEnum, _CODEC_TYPE_MAP},
 //     { VIDEORECORDER_VIDEO_CODEC_TYPE, ParseValueList, _CapabilityImpl::ConvertCharToEnum, _CODEC_TYPE_MAP},
@@ -1011,7 +1022,6 @@ _CapabilityImpl::ParseSection(xmlNode* pRoot, const String& section)
                                                        String* pKey = null;
                                                        pKey = new (std::nothrow) Tizen::Base::String(key);
                                                        SysTryReturnVoidResult(NID_MEDIA, pKey !=null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The key is not created.");
-
                                                        r = __pMap->Add(*pKey, *pRet);
                                                        SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
                                                }
index aa479c7..94669c0 100755 (executable)
@@ -134,18 +134,23 @@ CATCH:
 }
 
 void
-_RecorderManager::InitSafeHashMapInst()
+_RecorderManager::InitSingleton()
 {
-       static _RecorderManagerSafeHashMapT map;
        result r = E_SUCCESS;
+       std::unique_ptr <_RecorderManagerSafeHashMapT> pMap (new (std::nothrow) _RecorderManagerSafeHashMapT());
+       SysTryReturnVoidResult(NID_MEDIA, pMap.get() != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
 
-       r = map.Construct();
-       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+       r = pMap->Construct();
+       SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       __pMap = &map;
-       return;
-CATCH:
-       __pMap = null;
+       __pMap = pMap.release();
+       std::atexit(DestroySingleton);
+}
+
+void
+_RecorderManager::DestroySingleton(void)
+{
+       delete __pMap;
 }
 
 _RecorderManager*
@@ -162,7 +167,7 @@ _RecorderManager::AddInstance(_RecorderDeviceType recorderDevice)
 
        if (!__pMap)
        {
-               pthread_once(&once_block, InitSafeHashMapInst);
+               pthread_once(&once_block, InitSingleton);
                r = GetLastResult();
                SysTryReturn(NID_MEDIA, __pMap != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
        }
index f19578e..94ab865 100755 (executable)
@@ -119,10 +119,11 @@ private:
        */
        result ConvertResult(int err) const;
 
-       _RecorderManager(const _RecorderManager& camera);
-       _RecorderManager& operator =(const _RecorderManager& camera);
+       _RecorderManager(const _RecorderManager& rhs);
+       _RecorderManager& operator =(const _RecorderManager& rhs);
 
-       static void InitSafeHashMapInst(void);
+       static void InitSingleton(void);
+       static void DestroySingleton(void);
 
        _RecorderHandle __handle;
 
diff --git a/src/FMedia_RecorderRef.cpp b/src/FMedia_RecorderRef.cpp
new file mode 100755 (executable)
index 0000000..c196417
--- /dev/null
@@ -0,0 +1,122 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file                       FMedia_RecorderRef.cpp
+ * @brief                      This file contains the implementation of the %_RecorderRef class.
+ *
+ */
+
+#include <unique_ptr.h>
+#include <pthread.h>
+#include <FBaseSysLog.h>
+#include <FBaseColArrayListT.h>
+#include "FMedia_RecorderRef.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+namespace Tizen { namespace Media
+{
+
+IListT<_RecorderDeviceType>* _RecorderRef::__pList = null;
+
+_RecorderRef::_RecorderRef(void)
+:__deviceType(_RECORDER_DEVICE_NONE)
+{
+}
+
+_RecorderRef::~_RecorderRef(void)
+{
+       UnRegisterRecorder(__deviceType);
+}
+
+result
+_RecorderRef::Construct(const Tizen::Base::Object& obj, _RecorderDeviceType deviceType)
+{
+       result r = E_SUCCESS;
+
+       r = _CamRef::Construct(obj);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       r = RegisterRecorder(deviceType);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       __deviceType = deviceType;
+       return r;
+}
+
+void
+_RecorderRef::InitSingleton(void)
+{
+       result r = E_SUCCESS;
+       std::unique_ptr <ArrayListT<_RecorderDeviceType> > pList (new (std::nothrow) ArrayListT<_RecorderDeviceType>());
+       SysTryReturnVoidResult(NID_MEDIA, pList.get() != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.  The object is not created.");
+
+       r = pList->Construct();
+       SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       __pList = pList.release();
+       std::atexit(DestroySingleton);
+}
+
+void
+_RecorderRef::DestroySingleton(void)
+{
+       delete __pList;
+}
+
+result
+_RecorderRef::RegisterRecorder(_RecorderDeviceType deviceType)
+{
+       result r = E_SUCCESS;
+
+       static pthread_once_t once_block = PTHREAD_ONCE_INIT;
+       if (!__pList)
+       {
+               pthread_once(&once_block, InitSingleton);
+               r = GetLastResult();
+               SysTryReturn(NID_MEDIA, __pList != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       }
+
+/*
+       // Multiple recorder devices cannot be created.
+       if (__pList->GetCount() > 0)
+       {
+               _RecorderDeviceType usedDeviceType = _RECORDER_DEVICE_NONE;
+               r = __pList->GetAt(0, usedDeviceType);
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+               SysLogException(NID_MEDIA, E_DEVICE_BUSY, "[E_DEVICE_BUSY] The recorder%d is under use %d by other application or already used in this application.", deviceType, usedDeviceType);
+               return E_DEVICE_BUSY;
+       }
+*/
+       r = __pList->Add(deviceType);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       return r;
+}
+
+void
+_RecorderRef::UnRegisterRecorder(_RecorderDeviceType deviceType)
+{
+       result r = E_SUCCESS;
+       SysTryReturnVoidResult(NID_MEDIA, __pList != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] No object has been registered.");
+
+       r = __pList->Remove(deviceType);
+       SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+}
+
+}}// Tizen::Media
diff --git a/src/FMedia_RecorderRef.h b/src/FMedia_RecorderRef.h
new file mode 100755 (executable)
index 0000000..60a75e4
--- /dev/null
@@ -0,0 +1,102 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file                       FMedia_RecorderRef.h
+ * @brief                      This header file contains the declarations of the %_RecorderRef class.
+ *
+ */
+
+#ifndef _FMEDIA_INTERNAL_RECORDER_REF_H_
+#define _FMEDIA_INTERNAL_RECORDER_REF_H_
+
+#include <FBaseColIListT.h>
+#include "FMedia_RecorderTypes.h"
+#include "FMedia_CamRef.h"
+
+namespace Tizen { namespace Media
+{
+
+/**
+ * @class      _RecorderRef
+ * @brief      This class implements the _RecorderRef class.
+ */
+class _RecorderRef
+       : public _CamRef
+{
+public:
+       /**
+        * This is the default constructor for this class.
+        *
+        * @remarks             After creating an instance of this class, the Construct() method must be called explicitly to
+        * initialize this instance.
+        * @see                 Construct()
+        */
+       _RecorderRef(void);
+
+       /**
+        * This is the destructor for this class.
+        */
+       virtual ~_RecorderRef(void);
+
+       /**
+       * Initializes this instance of _RecorderRef.
+       *
+       * @return               An error code
+       * @param[in]    obj                     The object
+       * @param[in]    deviceType      The camera device type
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_INVALID_ARG   The specified input parameter is invalid.
+       */
+       result Construct(const Tizen::Base::Object& obj, _RecorderDeviceType deviceType);
+
+private:
+       /**
+       * Register a camera device to the list.
+       *
+       * @return               An error code
+       * @param[in]    deviceType      The camera device type
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_SYSTEM                Internal error.
+       * @exception    E_INVALID_ARG   The specified input parameter is invalid.
+       * @exception    E_DEVICE_BUSY                   The recorder is under use by other application or already used in this application.
+       */
+       result RegisterRecorder(_RecorderDeviceType deviceType);
+
+       /**
+       * Unregister the specific camera device from the list.
+       *
+       * @param[in]    deviceType      The camera device type
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_OBJ_NOT_FOUND The specified device type is not found.
+       */
+       void UnRegisterRecorder(_RecorderDeviceType deviceType);
+
+       _RecorderRef(const _RecorderRef& rhs);
+       _RecorderRef& operator =(const _RecorderRef& rhs);
+
+       _RecorderDeviceType __deviceType;
+
+       static void InitSingleton(void);
+       static void DestroySingleton(void);
+       
+       static Tizen::Base::Collection::IListT<_RecorderDeviceType>* __pList;
+};
+
+}}// Tizen::Media
+
+#endif
index 00af106..1ac2ad2 100755 (executable)
@@ -38,6 +38,7 @@
 #include "FMedia_RecorderCapability.h"
 #include "FMedia_CamPtrUtil.h"
 #include "FMedia_AudioStreamCoordinator.h"
+#include "FMedia_RecorderRef.h"
 
 //#define _VIDEO_RECORDER_ROTATION_
 
@@ -124,10 +125,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)
@@ -185,11 +185,6 @@ _VideoRecorderImpl::~_VideoRecorderImpl(void)
                _CameraCoordinator::Release(__deviceType);
        }
 
-       if ( __isConstructed )
-       {
-               __isUsed = false;
-       }
-
        SysLog(NID_MEDIA, "video recorder Destroyed");
 }
 
@@ -203,20 +198,28 @@ _VideoRecorderImpl::Construct(IVideoRecorderEventListener& listener, const Camer
        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));
@@ -227,28 +230,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.");
@@ -262,6 +248,15 @@ _VideoRecorderImpl::Construct(IVideoRecorderEventListener& listener, const Camer
 
        __handle = __pCoordinator->GetRecorderHandle();
 
+       // 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);
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set message callback failed.", GetErrorMessage(r));
@@ -287,7 +282,6 @@ _VideoRecorderImpl::Construct(IVideoRecorderEventListener& listener, const Camer
 
        SetState(RECORDER_STATE_INITIALIZED);
        __isConstructed = true;
-       __isUsed = true;
 
        return r;
 
@@ -305,8 +299,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;
 }
 
@@ -665,7 +666,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));
@@ -800,7 +801,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));
@@ -837,7 +838,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));
@@ -875,7 +876,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));
@@ -1305,8 +1306,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]);
@@ -1327,8 +1328,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);
 
@@ -1341,8 +1342,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)
@@ -1357,8 +1358,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);
 
@@ -1392,8 +1393,8 @@ _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);
 
        r = pImpl->GetEvent()->SendEvent(_RECORDER_EVENT_ERROR, RECORDER_ERROR_DEVICE_FAILED, E_SUCCESS);
@@ -1406,8 +1407,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);
 }
@@ -1719,12 +1720,6 @@ _VideoRecorderImpl::LoadDefaultConfiguration(int reload)
        return r;
 }
 
-bool
-_VideoRecorderImpl::IsAlive(void)
-{
-       return __isUsed;
-}
-
 _VideoRecorderImpl*
 _VideoRecorderImpl::GetInstance(VideoRecorder *pVideoRecorder)
 {
index aa8a29c..1c42b4c 100755 (executable)
@@ -41,6 +41,7 @@ class _AudioStreamCoordinator;
 class IAudioStreamFilter;
 
 class _CameraCoordinator;
+class _RecorderRef;
 class _VideoRecorderEvent;
 class _VideoSourceAdapter;
 
@@ -637,13 +638,6 @@ public:
        static void InterruptedCb(recorder_policy_e policy, recorder_state_e previous, recorder_state_e current, void *pUserData);
 
        /**
-        * Function check fo this object is alive.
-        *
-        * @return              true if the object is alive, otherwise false.
-        */
-       static bool IsAlive(void);
-
-       /**
         * Gets the Impl instance.
         *
         * @return              The pointer to %_VideoRecorderImpl
@@ -861,6 +855,7 @@ private:
        _VideoRecorderImpl& operator =(const _VideoRecorderImpl& _VideoRecorderImpl);
 
        _CameraCoordinator* __pCoordinator;
+       std::unique_ptr <_RecorderRef> __pRecorderRef;
        std::unique_ptr <_VideoRecorderEvent> __pVideoRecorderEvent;
        IVideoRecorderEventListener* __pVideoRecorderEventListener;
        std::unique_ptr <_VideoSourceAdapter> __pVideoSourceAdapter;
@@ -883,7 +878,6 @@ private:
        camera_pixel_format_e __mmSourceFormat;
        Tizen::Base::String __filePath;
        _RecorderStateChangeReason __stateChangeReason;
-       static bool __isUsed;
        std::unique_ptr <_AudioStreamCoordinator> __pAudioStreamCoordinator;
        int __audioStreamTimeDuration;
        bool __audioStreamCallback;
index 23ceba6..e299e2f 100755 (executable)
@@ -34,10 +34,13 @@ namespace Tizen { namespace Media
 {
 _OSP_EXPORT_ extern const wchar_t* const AUDIORECORDER_CODEC_TYPE;
 _OSP_EXPORT_ extern const wchar_t* const AUDIORECORDER_MEDIA_CONTAINER_TYPE;
+_OSP_EXPORT_ extern const wchar_t* const AUDIORECORDER_DEVICE_FPS;
+
 _OSP_EXPORT_ extern const wchar_t* const VIDEORECORDER_AUDIO_CODEC_TYPE;
 _OSP_EXPORT_ extern const wchar_t* const VIDEORECORDER_VIDEO_CODEC_TYPE;
 _OSP_EXPORT_ extern const wchar_t* const VIDEORECORDER_MEDIA_CONTAINER_TYPE;
 _OSP_EXPORT_ extern const wchar_t* const VIDEORECORDER_CODEC;
+_OSP_EXPORT_ extern const wchar_t* const VIDEORECORDER_DEVICE_FPS;
 
 _OSP_EXPORT_ extern const wchar_t* const CAMERA_PRIMARY_ZOOM_LEVEL;
 _OSP_EXPORT_ extern const wchar_t* const CAMERA_PRIMARY_FOCUS_POINT;
@@ -75,6 +78,20 @@ class _CapabilityImpl
        : public Tizen::Base::Object
 {
 public:
+       /**
+       *       This is the destructor for this class.
+       *
+       *       @see            Construct()
+       */
+       virtual ~_CapabilityImpl(void);
+
+       /**
+       * Get the instance of _CapabilityImpl.
+       *
+       * @return               The _CapabilityImpl instance
+       * @exception    E_SUCCESS                               The method is successful.
+       * @exception    E_SYSTEM                                A system error has occurred.
+       */
        static _CapabilityImpl* GetInstance(void);
 
        /**
@@ -322,15 +339,6 @@ private:
        _CapabilityImpl(void);
 
        /**
-       *       This is the destructor for this class. @n
-       *       Resources are deallocated by this method.
-       *       This method should be called in the same thread as Construct() method
-       *
-       *       @see            Construct()
-       */
-       virtual ~_CapabilityImpl(void);
-
-       /**
        *       copy constructor
        *       @param[in]      src                                     _CapabilityImpl type object
        */
@@ -353,7 +361,8 @@ private:
        */
        result ParseCapability(_MediaCapCategoryType category);
 
-       static void InitCapabilityImpl(void);
+       static void InitSingleton(void);
+       static void DestroySingleton(void);
 
        std::unique_ptr <Tizen::Base::Collection::HashMap> __pMap;
        int __cameraCount;