Tizen 2.0 Release
[framework/osp/media.git] / src / FMedia_VideoSourceAdapter.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                        FMedia_VideoSourceAdapter.cpp
20  * @brief                       This file contains the implementation of the %FMedia_VideoSourceAdapter class.
21  *
22  */
23
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"
31
32 //#define _SAFE_VIDEO_FORMAT_
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Graphics;
37
38 namespace Tizen { namespace Media
39 {
40
41 _VideoSourceAdapter::_VideoSourceAdapter(const Tizen::Media::_CameraImpl &cameraImpl)
42 {
43         __pSource = const_cast<_CameraImpl*>(&cameraImpl);
44         __sourceType = _VIDEO_SOURCE_CAMERA;
45         __recommendPreviewFormat = CAMERA_PIXEL_FORMAT_NV12;
46 }
47
48 _VideoSourceAdapter::~_VideoSourceAdapter()
49 {
50 }
51
52 Tizen::Base::Collection::IList*
53 _VideoSourceAdapter::GetSupportedRecordingResolutionListN(void) const
54 {
55         std::unique_ptr <IList, _ListPtrUtil::Remover> pResolutionList (null, _ListPtrUtil::remover);
56
57         if (__sourceType == _VIDEO_SOURCE_CAMERA)
58         {
59                 _CameraImpl* pCameraImpl = null;
60                 _CameraOperationType operation = _COP_NONE;
61                 _ResultType itemType = _RESULT_NONE;
62
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;
66
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.");
71         }
72
73         return pResolutionList.release();
74 }
75
76 Tizen::Base::Collection::IListT<camera_pixel_format_e>*
77 _VideoSourceAdapter::GetSupportedRecordingFormatListN(void) const
78 {
79         result r = E_SUCCESS;
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;
82
83         if (__sourceType == _VIDEO_SOURCE_CAMERA)
84         {
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");
87
88                 r = pListT->Construct();
89                 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating", GetErrorMessage(r));
90
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));
95         }
96
97         return pListT.release();
98 }
99
100 Tizen::Base::Collection::IListT<int>*
101 _VideoSourceAdapter::GetSupportedFrameRateListN(const Tizen::Graphics::Dimension& dim) const
102 {
103         std::unique_ptr <IListT<int>, _ListPtrUtil::Remover> pFpsListT (null, _ListPtrUtil::remover);
104
105         if (__sourceType == _VIDEO_SOURCE_CAMERA)
106         {
107                 _CameraImpl* pCameraImpl = null;
108
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.");
111
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.");
115         }
116         return pFpsListT.release();
117 }
118
119
120 Tizen::Graphics::Dimension
121 _VideoSourceAdapter::GetSourceResolution(void) const
122 {
123         Dimension resolution;
124
125         if (__sourceType == _VIDEO_SOURCE_CAMERA)
126         {
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.");
130
131                 resolution = pCameraImpl->GetPreviewResolution();
132         }
133
134         return resolution;
135
136 CATCH:
137         return Dimension(0, 0);
138 }
139
140 bool
141 _VideoSourceAdapter::HasRecordingResolutionRestriction(void) const
142 {
143         bool restriction = false;
144
145         if (__sourceType == _VIDEO_SOURCE_CAMERA)
146         {
147                 restriction = true;
148         }
149
150         return restriction;
151 }
152
153 result
154 _VideoSourceAdapter::SetRecommendPreviewFormat(_CameraHandle cameraHandle)
155 {
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;
160 #else
161         camera_pixel_format_e recommendPreviewFormat = CAMERA_PIXEL_FORMAT_NV12;
162
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.");
165 #endif
166         __recommendPreviewFormat = recommendPreviewFormat;
167         err = camera_set_preview_format(cameraHandle, __recommendPreviewFormat);
168
169         SysLog(NID_MEDIA, "the Recommend Preview Format:%d", __recommendPreviewFormat);
170         return r;
171 CATCH:
172         return r;
173 }
174 }}