2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FMedia_VideoSourceAdapter.cpp
20 * @brief This file contains the implementation of the %FMedia_VideoSourceAdapter class.
24 #include <unique_ptr.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseColIList.h>
27 #include "FMedia_VideoSourceAdapter.h"
28 #include "FMedia_CameraCapability.h"
29 #include "FMedia_CameraImpl.h"
30 #include "FMedia_CamPtrUtil.h"
32 //#define _SAFE_VIDEO_FORMAT_
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Graphics;
38 namespace Tizen { namespace Media
41 _VideoSourceAdapter::_VideoSourceAdapter(const Tizen::Media::_CameraImpl &cameraImpl)
43 __pSource = const_cast<_CameraImpl*>(&cameraImpl);
44 __sourceType = _VIDEO_SOURCE_CAMERA;
45 __recommendPreviewFormat = CAMERA_PIXEL_FORMAT_NV12;
48 _VideoSourceAdapter::~_VideoSourceAdapter()
52 Tizen::Base::Collection::IList*
53 _VideoSourceAdapter::GetSupportedRecordingResolutionListN(void) const
55 std::unique_ptr <IList, _ListPtrUtil::Remover> pResolutionList (null, _ListPtrUtil::remover);
57 if (__sourceType == _VIDEO_SOURCE_CAMERA)
59 _CameraImpl* pCameraImpl = null;
60 _CameraOperationType operation = _COP_NONE;
61 _ResultType itemType = _RESULT_NONE;
63 pCameraImpl = dynamic_cast<_CameraImpl*>(__pSource);
64 SysTryReturn(NID_MEDIA, pCameraImpl != null, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. This is not the camera object.");
65 operation = pCameraImpl->GetSelection() == CAMERA_PRIMARY ? _COP_PRIMARY_RECORDING_RESOLUTION : _COP_SECONDARY_RECORDING_RESOLUTION;
67 pResolutionList.reset(_CameraCapability::GetListN(operation, itemType));
68 SysTryReturn(NID_MEDIA, pResolutionList.get() != null, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Supported list was wrong.");
69 SysTryReturn(NID_MEDIA, pResolutionList->GetCount() > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. The list was empty.");
70 SysTryReturn(NID_MEDIA, itemType == _RESULT_DIMENSION_LIST, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. The list items are wrong.");
73 return pResolutionList.release();
76 Tizen::Base::Collection::IListT<camera_pixel_format_e>*
77 _VideoSourceAdapter::GetSupportedRecordingFormatListN(void) const
80 std::unique_ptr <ArrayListT<camera_pixel_format_e>, _ListPtrUtil::Remover> pListT (null, _ListPtrUtil::remover);
81 camera_pixel_format_e recommendPreviewFormat = CAMERA_PIXEL_FORMAT_NV12;
83 if (__sourceType == _VIDEO_SOURCE_CAMERA)
85 pListT.reset(new (std::nothrow) ArrayListT<camera_pixel_format_e>());
86 SysTryReturn(NID_MEDIA, pListT.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. out of memory");
88 r = pListT->Construct();
89 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating", GetErrorMessage(r));
91 // This means that the device supports recommeded format for the recording.
92 recommendPreviewFormat = __recommendPreviewFormat;
93 r = pListT->Add(recommendPreviewFormat);
94 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating", GetErrorMessage(r));
97 return pListT.release();
100 Tizen::Base::Collection::IListT<int>*
101 _VideoSourceAdapter::GetSupportedFrameRateListN(const Tizen::Graphics::Dimension& dim) const
103 std::unique_ptr <IListT<int>, _ListPtrUtil::Remover> pFpsListT (null, _ListPtrUtil::remover);
105 if (__sourceType == _VIDEO_SOURCE_CAMERA)
107 _CameraImpl* pCameraImpl = null;
109 pCameraImpl = dynamic_cast<_CameraImpl*>(__pSource);
110 SysTryReturn(NID_MEDIA, pCameraImpl != null, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. This is not the camera object.");
112 pFpsListT.reset(pCameraImpl->GetSupportedPreviewFrameRateListN(dim));
113 SysTryReturn(NID_MEDIA, pFpsListT.get() != null, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Supported list was wrong.");
114 SysTryReturn(NID_MEDIA, pFpsListT->GetCount() > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. The list was empty.");
116 return pFpsListT.release();
120 Tizen::Graphics::Dimension
121 _VideoSourceAdapter::GetSourceResolution(void) const
123 Dimension resolution;
125 if (__sourceType == _VIDEO_SOURCE_CAMERA)
127 _CameraImpl* pCameraImpl = null;
128 pCameraImpl = dynamic_cast<_CameraImpl*>(__pSource);
129 SysTryCatch(NID_MEDIA, pCameraImpl != null, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. This is not the camera object.");
131 resolution = pCameraImpl->GetPreviewResolution();
137 return Dimension(0, 0);
141 _VideoSourceAdapter::HasRecordingResolutionRestriction(void) const
143 bool restriction = false;
145 if (__sourceType == _VIDEO_SOURCE_CAMERA)
154 _VideoSourceAdapter::SetRecommendPreviewFormat(_CameraHandle cameraHandle)
156 int err = MM_SUCCESS;
157 result r = E_SUCCESS;
158 #if defined _SAFE_VIDEO_FORMAT_
159 camera_pixel_format_e recommendPreviewFormat = CAMERA_PIXEL_FORMAT_I420;
161 camera_pixel_format_e recommendPreviewFormat = CAMERA_PIXEL_FORMAT_NV12;
163 err = camera_get_preview_format(cameraHandle, &recommendPreviewFormat);
164 SysTryCatch(NID_MEDIA, err == MM_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Getting the Recommend Preview Format error.");
166 __recommendPreviewFormat = recommendPreviewFormat;
167 err = camera_set_preview_format(cameraHandle, __recommendPreviewFormat);
169 SysLog(NID_MEDIA, "the Recommend Preview Format:%d", __recommendPreviewFormat);