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_RecorderCapability.cpp
20 * @brief This file contains the implementation of recorder capability header file FMedia_RecorderCapability.h
22 #include <libxml/tree.h>
23 #include <unique_ptr.h>
24 #include <FBaseSysLog.h>
25 #include <FBaseInteger.h>
26 #include <FBaseColArrayList.h>
27 #include <FGrpDimension.h>
28 #include <FMediaTypes.h>
29 #include "FMedia_RecorderTypes.h"
30 #include "FMedia_RecorderCapability.h"
31 #include "FMedia_RecorderUtil.h"
32 #include "FMedia_RecorderSession.h"
33 #include "FMedia_CamPtrUtil.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::System;
40 namespace Tizen { namespace Media
43 const _RecorderCapability::keyServiceMap _RecorderCapability::__SERVICE_MAP[] =
46 _ROP_NONE, _RECORDER_SOURCE_VIDEO, null
49 _VROP_FILE_FORMAT, _RECORDER_SOURCE_VIDEO, GetSupportedVideoFileFormatN
52 _VROP_AUDIO_ENCODER, _RECORDER_SOURCE_VIDEO, GetSupportedAudioEncoderN
55 _VROP_VIDEO_ENCODER, _RECORDER_SOURCE_VIDEO, GetSupportedVideoEncoderN
58 _AROP_FILE_FORMAT, _RECORDER_SOURCE_AUDIO, GetSupportedAudioFileFormatN
61 _AROP_AUDIO_ENCODER, _RECORDER_SOURCE_AUDIO, GetSupportedAudioEncoderN
64 _ROP_MAX, _RECORDER_SOURCE_VIDEO, null
68 _RecorderCapability::_RecorderCapability(void)
72 _RecorderCapability::~_RecorderCapability(void)
76 Tizen::Base::Collection::ArrayList*
77 _RecorderCapability::GetListN(_RecorderOperationType key, _ResultType& itemType)
79 //check key boundary condition
80 SysTryReturn(NID_MEDIA, (key > _ROP_NONE && key < _ROP_MAX), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(KEY) is used. KEY :%d", key);
82 _RecorderSourceType sourceType = __SERVICE_MAP[key].sourceType;
83 _RecorderQueryFunc serviceRoutine = __SERVICE_MAP[key].serviceRoutine;
85 //check service handler for a given key
86 SysTryReturn(NID_MEDIA, serviceRoutine != null, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The query function is not found.");
88 std::unique_ptr<ArrayList, _ListPtrUtil::Remover> pList (null, _ListPtrUtil::remover);
89 Object* pObj = serviceRoutine(sourceType, _QUERY_LIST, itemType);
92 case _RESULT_INTEGER_LIST:
94 case _RESULT_PAIR_INTEGER_LIST:
96 case _RESULT_DIMENSION_LIST:
98 case _RESULT_DOUBLE_LIST:
100 case _RESULT_STRING_LIST:
101 pList.reset(dynamic_cast<ArrayList*>(pObj));
102 SysTryCatch(NID_MEDIA, pList.get() != null, , E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] There is no data list in key = [%d].", key);
103 SysTryCatch(NID_MEDIA, pList->GetCount() > 0, , E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Empty data returned for key = [%d]", key);
104 SysLog(NID_MEDIA, "Valid data returned for key = %d count = %d", key, pList->GetCount());
108 SysLogException(NID_MEDIA, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Supported List is not retrieved. key = [%d]", key);
112 return pList.release();
119 _RecorderCapability::IsSupported(_RecorderOperationType key)
121 //check key boundary condition
122 SysTryReturn(NID_MEDIA, (key > _ROP_NONE && key < _ROP_MAX), false, E_INVALID_ARG, "[E_INVALID_ARG] The key:%d is invalid.", key);
124 _RecorderSourceType sourceType = __SERVICE_MAP[key].sourceType;
125 _RecorderQueryFunc serviceRoutine = __SERVICE_MAP[key].serviceRoutine;
126 _ResultType itemType = _RESULT_NONE;
128 //check service handler for a given key
129 SysTryReturn(NID_MEDIA, serviceRoutine != null, false, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The user list is not found.");
131 std::unique_ptr<ArrayList, _ListPtrUtil::Remover> pList (null, _ListPtrUtil::remover);
132 Object* pObj = serviceRoutine(sourceType, _QUERY_LIST, itemType);
135 case _RESULT_INTEGER_LIST:
137 case _RESULT_DIMENSION_LIST:
139 case _RESULT_DOUBLE_LIST:
141 case _RESULT_STRING_LIST:
142 pList.reset(dynamic_cast<ArrayList*>(pObj));
143 SysTryCatch(NID_MEDIA, pList.get() != null, , E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] There is no data list in key = [%d].", key);
144 SysTryCatch(NID_MEDIA, pList->GetCount()>0, , E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] There is no valid data in key = [%d].", key);
147 case _RESULT_PAIR_INTEGER_LIST:
148 pList.reset(dynamic_cast<ArrayList*>(pObj));
149 SysTryCatch(NID_MEDIA, pList.get() != null, , E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] There is no data list in key = [%d].", key);
151 Integer* pInteger = null;
152 pInteger = dynamic_cast<Integer*>(pList->GetAt(1)); // Get max value;
153 SysTryCatch(NID_MEDIA, pInteger != null, , E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Max value is null for key = [%d].", key);
154 SysTryCatch(NID_MEDIA, pInteger->ToInt() > 0, , E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Max value is %d for key = [%d].", pInteger->ToInt(), key);
159 SysLogException(NID_MEDIA, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] There is no data list in key = [%d].", key);
163 SysLog(NID_MEDIA, "Valid data returned for key = %d count = %d", key, pList->GetCount());
172 _RecorderCapability::GetValueN(_RecorderOperationType key, _QueryType queryType, _ResultType& itemType)
174 Tizen::Base::Object* pValue = null;
176 //check key boundary condition
177 SysTryReturn(NID_MEDIA, (key > _ROP_NONE && key < _ROP_MAX), null, E_INVALID_ARG, "[E_INVALID_ARG] The key:%d is invalid.", key);
178 SysTryReturn(NID_MEDIA, (queryType >= _QUERY_DEFAULT_VALUE && queryType < _QUERY_MAX), null, E_INVALID_ARG, "[E_INVALID_ARG] The query:%d is invalid.", queryType);
180 _RecorderSourceType sourceType = __SERVICE_MAP[key].sourceType;
181 _RecorderQueryFunc serviceRoutine = __SERVICE_MAP[key].serviceRoutine;
183 //check service handler for a given key
184 SysTryReturn(NID_MEDIA, serviceRoutine != null, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The query function is not found.");
186 Object* pObj = serviceRoutine(sourceType, queryType, itemType);
190 case _RESULT_INTEGER:
191 pValue = dynamic_cast<Integer*>(pObj);
192 SysTryReturn(NID_MEDIA, null != pValue, null, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] There is no data list in key = [%d].", key);
195 case _RESULT_DIMENSION:
196 pValue = dynamic_cast<Dimension*>(pObj);
197 SysTryReturn(NID_MEDIA, null != pValue, null, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] There is no data list in key = [%d].", key);
200 case _RESULT_INTEGER_LIST:
202 case _RESULT_PAIR_INTEGER_LIST:
204 case _RESULT_DIMENSION_LIST:
206 case _RESULT_DOUBLE_LIST:
208 case _RESULT_STRING_LIST:
210 SysLogException(NID_MEDIA, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] Default value cannot be retrived. key = [%d], itemType:%d", key, itemType);
214 SysLog(NID_MEDIA, "Valid data returned for key = %d", key);
223 _RecorderCapability::GetSupportedVideoFileFormatN(_RecorderSourceType sourceType, _QueryType queryType, _ResultType& itemType)
225 Object* pfileFormat = null;
226 result r = E_SUCCESS;
227 int err = MM_SUCCESS;
229 _RecorderSession recorderSession;
230 r = recorderSession.Construct(sourceType);
231 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
233 _RecorderHandle recorderHandle = recorderSession.GetHandle();
234 SysTryReturn(NID_MEDIA, recorderHandle != MM_INVALID_HANDLE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Valid handle is not found.");
236 if (queryType == _QUERY_LIST)
238 std::unique_ptr<_MediaSafeArrayList, _ListPtrUtil::Remover> pfileFormatList (new (std::nothrow) _MediaSafeArrayList(), _ListPtrUtil::remover);
239 SysTryReturn(NID_MEDIA, pfileFormatList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
241 err = recorder_foreach_supported_file_format(recorderHandle, SupportedRecorderVideoFileFormatCb, pfileFormatList.get());
242 SysTryReturn(NID_MEDIA, err == MM_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] Getting the capability failed.");
244 itemType = _RESULT_INTEGER_LIST;
245 pfileFormat = pfileFormatList.release();
247 else if (queryType == _QUERY_DEFAULT_VALUE)
249 itemType = _RESULT_INTEGER;
256 _RecorderCapability::GetSupportedAudioFileFormatN(_RecorderSourceType sourceType, _QueryType queryType, _ResultType& itemType)
258 Object* pfileFormat = null;
259 result r = E_SUCCESS;
260 int err = MM_SUCCESS;
262 _RecorderSession recorderSession;
263 r = recorderSession.Construct(sourceType);
264 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
266 _RecorderHandle recorderHandle = recorderSession.GetHandle();
267 SysTryReturn(NID_MEDIA, recorderHandle != MM_INVALID_HANDLE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Valid handle is not found.");
269 if (queryType == _QUERY_LIST)
271 std::unique_ptr<_MediaSafeArrayList, _ListPtrUtil::Remover> pfileFormatList (new (std::nothrow) _MediaSafeArrayList(), _ListPtrUtil::remover);
272 SysTryReturn(NID_MEDIA, pfileFormatList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
274 err = recorder_foreach_supported_file_format(recorderHandle, SupportedRecorderAudioFileFormatCb, pfileFormatList.get());
275 SysTryReturn(NID_MEDIA, err == MM_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] Getting the capability failed.");
277 itemType = _RESULT_INTEGER_LIST;
278 pfileFormat = pfileFormatList.release();
280 else if (queryType == _QUERY_DEFAULT_VALUE)
282 itemType = _RESULT_INTEGER;
290 _RecorderCapability::GetSupportedAudioEncoderN(_RecorderSourceType sourceType, _QueryType queryType, _ResultType& itemType)
292 Object* pAudioEncoder = null;
293 result r = E_SUCCESS;
294 int err = MM_SUCCESS;
296 _RecorderSession recorderSession;
297 r = recorderSession.Construct(sourceType);
298 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
300 _RecorderHandle recorderHandle = recorderSession.GetHandle();
301 SysTryReturn(NID_MEDIA, recorderHandle != MM_INVALID_HANDLE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Valid handle is not found.");
303 if (queryType == _QUERY_LIST)
305 std::unique_ptr<_MediaSafeArrayList, _ListPtrUtil::Remover> pAudioEncoderList (new (std::nothrow) _MediaSafeArrayList(), _ListPtrUtil::remover);
306 SysTryReturn(NID_MEDIA, pAudioEncoderList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
308 err = recorder_foreach_supported_audio_encoder(recorderHandle, SupportedRecorderAudioEncoderCb, pAudioEncoderList.get());
309 SysTryReturn(NID_MEDIA, err == MM_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] Getting the capability failed.");
311 itemType = _RESULT_INTEGER_LIST;
312 pAudioEncoder = pAudioEncoderList.release();
314 else if (queryType == _QUERY_DEFAULT_VALUE)
316 itemType = _RESULT_INTEGER;
319 return pAudioEncoder;
323 _RecorderCapability::GetSupportedVideoEncoderN(_RecorderSourceType sourceType, _QueryType queryType, _ResultType& itemType)
325 Object* pVideoEncoder = null;
326 result r = E_SUCCESS;
327 int err = MM_SUCCESS;
329 _RecorderSession recorderSession;
330 r = recorderSession.Construct(sourceType);
331 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
333 _RecorderHandle recorderHandle = recorderSession.GetHandle();
334 SysTryReturn(NID_MEDIA, recorderHandle != MM_INVALID_HANDLE, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Valid handle is not found.");
336 if (queryType == _QUERY_LIST)
338 std::unique_ptr<_MediaSafeArrayList, _ListPtrUtil::Remover> pVideoEncoderList (new (std::nothrow) _MediaSafeArrayList(), _ListPtrUtil::remover);
339 SysTryReturn(NID_MEDIA, pVideoEncoderList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
341 err = recorder_foreach_supported_video_encoder(recorderHandle, SupportedRecorderVideoEncoderCb, pVideoEncoderList.get());
342 SysTryReturn(NID_MEDIA, err == MM_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] Getting the capability failed.");
344 itemType = _RESULT_INTEGER_LIST;
345 pVideoEncoder = pVideoEncoderList.release();
347 else if (queryType == _QUERY_DEFAULT_VALUE)
349 itemType = _RESULT_INTEGER;
352 return pVideoEncoder;
356 _RecorderCapability::SupportedRecorderVideoFileFormatCb(recorder_file_format_e format, void *pUserData)
358 result r = E_SUCCESS;
359 MediaContainerType formatValue = (MediaContainerType)MEDIA_INVALID_VALUE;
361 _MediaSafeArrayList* pFormatList = static_cast<_MediaSafeArrayList*>(pUserData);
362 SysTryReturn(NID_MEDIA, pFormatList != null, false, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The user list is not found.");
364 r = _RecorderUtil::GetOspVideoContainer((recorder_file_format_e)format, formatValue);
367 std::unique_ptr<Object> pInteger (new (std::nothrow) Integer(formatValue));
368 SysTryReturn(NID_MEDIA, pInteger.get() != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
370 r = pFormatList->AddPtr(std::move(pInteger));
371 SysTryReturn(NID_MEDIA, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
378 _RecorderCapability::SupportedRecorderAudioFileFormatCb(recorder_file_format_e format, void *pUserData)
380 result r = E_SUCCESS;
381 MediaContainerType formatValue = (MediaContainerType)MEDIA_INVALID_VALUE;
383 _MediaSafeArrayList* pFormatList = static_cast<_MediaSafeArrayList*>(pUserData);
384 SysTryReturn(NID_MEDIA, pFormatList != null, false, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The user list is not found.");
386 r = _RecorderUtil::GetOspAudioContainer((recorder_file_format_e)format, formatValue);
389 std::unique_ptr<Object> pInteger (new (std::nothrow) Integer(formatValue));
390 SysTryReturn(NID_MEDIA, pInteger.get() != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
392 r = pFormatList->AddPtr(std::move(pInteger));
393 SysTryReturn(NID_MEDIA, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
400 _RecorderCapability::SupportedRecorderAudioEncoderCb(recorder_audio_codec_e codec, void *pUserData)
402 result r = E_SUCCESS;
403 CodecType audioCodecType = (CodecType)MEDIA_INVALID_VALUE;
405 _MediaSafeArrayList* pAudioEncoderList = static_cast<_MediaSafeArrayList*>(pUserData);
406 SysTryReturn(NID_MEDIA, pAudioEncoderList != null, false, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The user list is not found.");
408 r = _RecorderUtil::GetOspAudioCodec((recorder_audio_codec_e)codec, audioCodecType);
411 std::unique_ptr<Object> pInteger (new (std::nothrow) Integer(audioCodecType));
412 SysTryReturn(NID_MEDIA, pInteger.get() != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
414 r = pAudioEncoderList->AddPtr(std::move(pInteger));
415 SysTryReturn(NID_MEDIA, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
422 _RecorderCapability::SupportedRecorderVideoEncoderCb(recorder_video_codec_e codec, void *pUserData)
424 result r = E_SUCCESS;
425 CodecType videoCodecType = (CodecType)MEDIA_INVALID_VALUE;
427 _MediaSafeArrayList* pVideoEncoderList = static_cast<_MediaSafeArrayList*>(pUserData);
428 SysTryReturn(NID_MEDIA, pVideoEncoderList != null, false, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The user list is not found.");
430 r = _RecorderUtil::GetOspVideoCodec((recorder_video_codec_e)codec, videoCodecType);
433 std::unique_ptr<Object> pInteger (new (std::nothrow) Integer(videoCodecType));
434 SysTryReturn(NID_MEDIA, pInteger.get() != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
436 r = pVideoEncoderList->AddPtr(std::move(pInteger));
437 SysTryReturn(NID_MEDIA, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));