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_VideoRecorderImpl.cpp
20 * @brief This is the implementation file for the %_VideoRecorderImpl class.
23 #include <unique_ptr.h>
26 #include <FBaseInteger.h>
27 #include <FBaseSysLog.h>
28 #include <FBase_StringConverter.h>
29 #include <FMediaVideoRecorder.h>
30 #include "FMedia_CameraImpl.h"
31 #include "FMedia_CapabilityImpl.h"
32 #include "FMedia_CameraCoordinator.h"
33 #include "FMedia_VideoRecorderImpl.h"
34 #include "FMedia_VideoRecorderEvent.h"
35 #include "FMedia_VideoSourceAdapter.h"
36 #include "FMedia_CameraUtil.h"
37 #include "FMedia_RecorderUtil.h"
38 #include "FMedia_RecorderCapability.h"
39 #include "FMedia_CamPtrUtil.h"
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
43 using namespace Tizen::Graphics;
45 namespace Tizen { namespace Media
47 static const int _RELOAD_FORMAT = 0x1;
48 static const int _RELOAD_QUALITY = 0x1 << 1;
49 static const int _RELOAD_MAX_TIME = 0x1 << 2;
50 static const int _RELOAD_RECORD_RESOLUTION = 0x1 << 3;
51 static const int _RELOAD_FILE_PATH = 0x1 << 4;
52 static const int _RELOAD_INIT = 0x1 << 5;
53 static const int _RELOAD_CALLBACK = 0x1 << 6;
54 static const int _RELOAD_MUTE = 0x1 << 7;
55 static const int _RELOAD_ROTATION = 0x1 << 8;
57 typedef int (*_VideoRecorderFunc)(_RecorderHandle mmHandle);
61 recorder_state_e preState;
62 recorder_state_e postState;
63 _RecorderStateChangeReason reason;
64 _VideoRecorderFunc pFunc;
66 }_VideoCommandStateTable;
68 static const _VideoCommandStateTable _VIDEO_COMMAND_STATE[] =
70 {::RECORDER_STATE_CREATED, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL, recorder_prepare, (RecorderState)-1 },
71 {::RECORDER_STATE_READY, ::RECORDER_STATE_RECORDING, _RECORDER_STATE_REASON_NORMAL, recorder_start, RECORDER_STATE_STARTING },
72 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_PAUSED, _RECORDER_STATE_REASON_NORMAL, recorder_pause, RECORDER_STATE_PAUSING },
73 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL, recorder_commit, RECORDER_STATE_STOPPING },
74 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_CANCEL, recorder_cancel, RECORDER_STATE_STOPPING },
75 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_SIZE_REACHED, recorder_commit, RECORDER_STATE_RECORDING },
76 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_TIME_REACHED, recorder_commit, RECORDER_STATE_RECORDING },
77 {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_RECORDING, _RECORDER_STATE_REASON_NORMAL, recorder_start, RECORDER_STATE_STARTING },
78 {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL, recorder_commit, RECORDER_STATE_STOPPING },
79 {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_CANCEL, recorder_cancel, RECORDER_STATE_STOPPING },
80 {::RECORDER_STATE_READY, ::RECORDER_STATE_CREATED, _RECORDER_STATE_REASON_NORMAL, recorder_unprepare, RECORDER_STATE_CLOSING },
85 recorder_state_e prevState;
86 recorder_state_e postState;
87 _RecorderStateChangeReason reason;
88 _RecorderEventType event;
89 RecorderErrorReason error;
90 }_VideoCallbackEventTable;
92 static const _VideoCallbackEventTable _VIDEO_CALLBACK_EVENT[] =
94 {::RECORDER_STATE_READY, ::RECORDER_STATE_RECORDING, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_RECORDING_STARTED, RECORDER_ERROR_NONE },
95 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_PAUSED, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_PAUSED, RECORDER_ERROR_NONE },
96 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_STOPPED, RECORDER_ERROR_NONE },
97 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_CANCEL, _RECORDER_EVENT_CANCELED, RECORDER_ERROR_NONE },
98 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_SIZE_REACHED, _RECORDER_EVENT_ENDOF_FILESIZE, RECORDER_ERROR_NONE },
99 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_TIME_REACHED, _RECORDER_EVENT_ENDOF_RECTIME, RECORDER_ERROR_NONE },
100 {::RECORDER_STATE_RECORDING, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_OUT_OF_STORAGE, _RECORDER_EVENT_ERROR, RECORDER_ERROR_OUT_OF_STORAGE },
101 {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_RECORDING, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_RECORDING_STARTED, RECORDER_ERROR_NONE },
102 {::RECORDER_STATE_PAUSED, ::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_STOPPED, RECORDER_ERROR_NONE },
103 // {::RECORDER_STATE_READY, ::RECORDER_STATE_CREATED, _RECORDER_STATE_REASON_NORMAL, _RECORDER_EVENT_CLOSED, RECORDER_ERROR_NONE },
108 const char* pCodecName;
109 CodecType audioCodec;
110 CodecType videoCodec;
111 MediaContainerType container;
114 static const _CodecValTable _CODEC_VAL_TABLE[] =
116 {"VIDEO_CODEC_NONE", CODEC_NONE, CODEC_NONE, MEDIA_CONTAINER_NONE},
117 {"VIDEO_CODEC_H263", CODEC_AMR_NB, CODEC_H263, MEDIA_CONTAINER_3GP}, //TODO bug reported
118 // {"VIDEO_CODEC_H263", CODEC_AAC, CODEC_H263, MEDIA_CONTAINER_3GP},
119 {"VIDEO_CODEC_MPEG4SP", CODEC_AAC, CODEC_MPEG4, MEDIA_CONTAINER_MP4},
120 {"VIDEO_CODEC_H264", CODEC_AAC, CODEC_H264, MEDIA_CONTAINER_MP4},
121 {null, CODEC_NONE, CODEC_NONE, MEDIA_CONTAINER_NONE}
124 bool _VideoRecorderImpl::__isUsed = false;
126 _VideoRecorderImpl::_VideoRecorderImpl(void)
127 : __pCoordinator(null)
128 , __pVideoRecorderEvent(null)
129 , __pVideoRecorderEventListener(null)
130 , __pVideoSourceAdapter(null)
131 , __isConstructed(false)
132 , __state(RECORDER_STATE_INITIALIZED)
135 , __maxTime(DEFAULT_VIDEORECORDING_TIME)
136 , __format(VIDEORECORDING_FORMAT_DEFAULT)
137 , __audioCodec(CODEC_AAC) // TODO
138 , __videoCodec(CODEC_MPEG4)
139 , __container(MEDIA_CONTAINER_MP4)
140 , __mode(VIDEORECORDER_MODE_VIDEO_WITH_AUDIO)
141 , __quality(RECORDING_QUALITY_MEDIUM)
143 , __rotation(RECORDING_ROTATION_NONE)
144 , __handle(MM_INVALID_HANDLE)
145 ,__deviceType(_RECORDER_DEVICE_NONE)
146 ,__mmSourceFormat(CAMERA_PIXEL_FORMAT_INVALID)
147 ,__stateChangeReason(_RECORDER_STATE_REASON_NORMAL)
149 __recordingResolution.width = 0;
150 __recordingResolution.height = 0;
154 _VideoRecorderImpl::~_VideoRecorderImpl(void)
156 if (__handle != MM_INVALID_HANDLE)
158 int err = ::RECORDER_ERROR_NONE;
159 err = recorder_unset_state_changed_cb(__handle);
160 err = recorder_unset_recording_limit_reached_cb(__handle);
161 err = recorder_unset_error_cb(__handle);
162 err = recorder_unset_recording_status_cb(__handle);
163 err = recorder_unset_interrupted_cb(__handle);
164 __handle = MM_INVALID_HANDLE;
166 if (__pCoordinator != null)
168 __pCoordinator->ChangeMode(_CAMERA_MODE_IMAGE, false);
169 __pCoordinator->RemoveCameraCoordinatorListener(*this);
171 _CameraCoordinator::Release(__deviceType);
174 if (__pVideoSourceAdapter != null)
176 delete __pVideoSourceAdapter;
179 if (__pVideoRecorderEvent != null)
181 delete __pVideoRecorderEvent;
184 if ( __isConstructed )
189 SysLog(NID_MEDIA, "video recorder Destroyed");
193 _VideoRecorderImpl::Construct(IVideoRecorderEventListener& listener, const Camera& camera)
195 result r = E_SUCCESS;
196 Tizen::Media::Camera* pCamera = null;
197 Tizen::Media::_CameraImpl* pCamImpl = null;
198 _CameraHandle cameraHandle = MM_INVALID_HANDLE;
199 int err = MM_SUCCESS;
201 SysTryReturn(NID_MEDIA, !__isUsed, E_DEVICE_BUSY, E_DEVICE_BUSY, "[E_DEVICE_BUSY] _VideoRecorderImpl is now being used.");
202 SysTryReturn(NID_MEDIA, !__isConstructed, E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state. A device is already constructed.");
203 SysLog(NID_MEDIA, "video recorder construct");
205 pCamera = const_cast<Tizen::Media::Camera*>(&camera);
206 pCamImpl = _CameraImpl::GetInstance(pCamera);
209 __pVideoSourceAdapter = new (std::nothrow) _VideoSourceAdapter(*pCamImpl);
210 SysTryCatch(NID_MEDIA, __pVideoSourceAdapter != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
213 __pVideoRecorderEvent = new (std::nothrow) _VideoRecorderEvent();
214 SysTryCatch(NID_MEDIA, __pVideoRecorderEvent != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
216 r = __pVideoRecorderEvent->Construct(*this);
217 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
219 r = __pVideoRecorderEvent->AddListener(listener);
220 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
222 __pVideoRecorderEventListener = &listener;
224 __deviceType = (pCamImpl->GetSelection() == CAMERA_PRIMARY ? _RECORDER_DEVICE_VIDEO_PRIMARY_CAMERA
225 : _RECORDER_DEVICE_VIDEO_SECONDARY_CAMERA);
227 __pCoordinator = _CameraCoordinator::AddInstance(__deviceType);
229 SysTryCatch(NID_MEDIA, __pCoordinator != null, , r, "[E_OBJ_NOT_FOUND] _CameraCoordinator instance is not available.");
231 r = __pCoordinator->AddCameraCoordinatorListener(*this);
232 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
234 //If the reload flag is true, the __handle will be updated in the OnCameraCoordinatorModeChangePrepared(), otherwise the __handle should be updated manually.
235 r = __pCoordinator->ChangeMode(_CAMERA_MODE_VIDEO, false); // Do not reload. The __mmSourceFormat is not set yet.
236 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder Mode change failed.", GetErrorMessage(r));
238 __handle = __pCoordinator->GetRecorderHandle();
239 cameraHandle = __pCoordinator->GetCameraHandle();
240 r = __pVideoSourceAdapter->SetRecommendPreviewFormat(cameraHandle);
241 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video adapter SetRecommendPreviewFormat failed.", GetErrorMessage(r));
243 err = recorder_set_state_changed_cb(__handle, StateChangedCb, this);
244 r = ConvertResult(err);
245 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set message callback failed.", GetErrorMessage(r));
247 err = recorder_set_recording_limit_reached_cb(__handle, LimitReachedCb, this);
248 r = ConvertResult(err);
249 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set limit reached callback failed.", GetErrorMessage(r));
251 err = recorder_set_recording_status_cb(__handle, RecordingStatusCb, this);
252 r = ConvertResult(err);
253 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set recording status callback failed.", GetErrorMessage(r));
255 err = recorder_set_error_cb(__handle, ErrorCb, this);
256 r = ConvertResult(err);
257 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set limit reached callback failed.", GetErrorMessage(r));
259 err = recorder_set_interrupted_cb(__handle, InterruptedCb, this);
260 r = ConvertResult(err);
261 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set limit reached callback failed.", GetErrorMessage(r));
263 r = LoadDefaultConfiguration(_RELOAD_RECORD_RESOLUTION);
264 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
266 SetState(RECORDER_STATE_INITIALIZED);
267 __isConstructed = true;
275 err = recorder_unset_state_changed_cb(__handle);
276 err = recorder_unset_recording_limit_reached_cb(__handle);
277 err = recorder_unset_error_cb(__handle);
278 err = recorder_unset_recording_status_cb(__handle);
279 err = recorder_unset_interrupted_cb(__handle);
280 __handle = MM_INVALID_HANDLE;
283 if (__pCoordinator != null)
285 __pCoordinator->RemoveCameraCoordinatorListener(*this);
288 if (__pVideoSourceAdapter != null)
290 delete __pVideoSourceAdapter;
291 __pVideoSourceAdapter = null;
294 if (__pVideoRecorderEventListener != null)
296 __pVideoRecorderEvent->RemoveListener(*__pVideoRecorderEventListener);
297 __pVideoRecorderEventListener = null;
300 if (__pVideoRecorderEvent != null)
302 delete __pVideoRecorderEvent;
303 __pVideoRecorderEvent = null;
310 _VideoRecorderImpl::CreateVideoFile(const Tizen::Base::String& mediaLocalPath, bool overwrite)
312 result r = E_SUCCESS;
313 RecorderState state = RECORDER_STATE_ERROR;
314 int err = MM_SUCCESS;
315 SysLog(NID_MEDIA, "video recorder create video file");
318 SysTryReturn(NID_MEDIA, state == RECORDER_STATE_INITIALIZED || state == RECORDER_STATE_CLOSED,
319 E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state.");
321 std::unique_ptr<char[]> pFileName (_StringConverter::CopyToCharArrayN(mediaLocalPath));
322 SysTryCatch(NID_MEDIA, pFileName.get() != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(mediaLocalPath) is used. File name is null.");
323 SysLog(NID_MEDIA, "File Path : %s\n, overwrite:%d", pFileName.get(), overwrite);
325 r = _RecorderUtil::PrepareFile(mediaLocalPath, overwrite);
326 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder prepare file failed. mediaLocalPath:%s, overwirte:%d",
327 GetErrorMessage(r), pFileName.get(), overwrite);
329 if (__handle != MM_INVALID_HANDLE)
331 err = recorder_set_filename(__handle, pFileName.get());
332 r = ConvertResult(err);
333 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
336 SetState(RECORDER_STATE_OPENED);
338 if (__handle != MM_INVALID_HANDLE)
340 // re-configuration for new recorder handle
341 r = ReloadConfiguration(_RELOAD_FORMAT | _RELOAD_QUALITY | _RELOAD_MAX_TIME | _RELOAD_INIT | _RELOAD_ROTATION);
342 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration failed", GetErrorMessage(r));
345 __filePath = mediaLocalPath;
354 _VideoRecorderImpl::Close(void)
356 result r = E_SUCCESS;
357 RecorderState state = RECORDER_STATE_ERROR;
358 SysLog(NID_MEDIA, "video recorder close");
362 NID_MEDIA, state == RECORDER_STATE_OPENED || state == RECORDER_STATE_STOPPED
363 || state == RECORDER_STATE_ENDOF_FILE || state == RECORDER_STATE_ERROR
364 , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d", state);
366 // Just send closed event
367 r = GetEvent()->SendEvent(_RECORDER_EVENT_CLOSED, RECORDER_ERROR_NONE, E_SUCCESS);
368 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
377 _VideoRecorderImpl::Record(void)
379 result r = E_SUCCESS;
380 RecorderState state = RECORDER_STATE_ERROR;
381 recorder_state_e mmState = ::RECORDER_STATE_NONE;
382 SysLog(NID_MEDIA, "video recorder record");
385 SysTryReturn(NID_MEDIA, state == RECORDER_STATE_OPENED || state == RECORDER_STATE_PAUSED
386 , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d", state);
388 if (__pVideoSourceAdapter->HasRecordingResolutionRestriction())
390 SysTryReturn(NID_MEDIA, __recordingResolution == __pVideoSourceAdapter->GetSourceResolution()
391 , E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. __recordingResolution(%d,%d) is not same VideoSourceResolution.", __recordingResolution.width, __recordingResolution.height);
394 std::unique_ptr<IListT<camera_pixel_format_e>, _ListPtrUtil::Remover> pSupportedMmSourceFormatList (__pVideoSourceAdapter->GetSupportedRecordingFormatListN(), _ListPtrUtil::remover);
395 SysTryCatch(NID_MEDIA, pSupportedMmSourceFormatList.get() != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Source's supported recording format is empty");
397 // In case of the preview format is not supported to the Video Recorder, regardless of the current mode,
398 // the recorder should be reset and the preview format should be changed for recording supported one.
399 if ( !pSupportedMmSourceFormatList->Contains(__pCoordinator->GetCameraSourceFormat()))
401 SysLog(NID_MEDIA, "Current coordinaotr's mm format(%d) is not supported to record.", __pCoordinator->GetCameraSourceFormat());
402 r = pSupportedMmSourceFormatList->GetAt(0, __mmSourceFormat);
403 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Camera mode change failed.", GetErrorMessage(r));
405 // If the preview data format is changed, the properties should be set again.
406 r = __pCoordinator->ChangeMode(_CAMERA_MODE_VIDEO, true);
407 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder Mode change failed.", GetErrorMessage(r));
409 else if ( __pCoordinator->GetMode() != _CAMERA_MODE_VIDEO )
411 SysLog(NID_MEDIA, "Current mode is IMAGE. It should be moved to VIDEO mode.");
413 __mmSourceFormat = __pCoordinator->GetCameraSourceFormat();
414 r = __pCoordinator->ChangeMode(_CAMERA_MODE_VIDEO, true);
415 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder Mode change failed.", GetErrorMessage(r));
418 mmState = GetMmState();
421 case ::RECORDER_STATE_CREATED:
422 r = ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL);
423 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder init failed.", GetErrorMessage(r));
425 r = __pCoordinator->StartRecord();
426 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder start failed.", GetErrorMessage(r));
427 __stateChangeReason = _RECORDER_STATE_REASON_NORMAL;
428 SetState(RECORDER_STATE_STARTING);
431 case ::RECORDER_STATE_READY:
432 r = __pCoordinator->StartRecord();
433 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder start failed.", GetErrorMessage(r));
434 __stateChangeReason = _RECORDER_STATE_REASON_NORMAL;
435 SetState(RECORDER_STATE_STARTING);
438 case ::RECORDER_STATE_PAUSED:
439 r = __pCoordinator->StartRecord();
440 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder resume failed.", GetErrorMessage(r));
441 __stateChangeReason = _RECORDER_STATE_REASON_NORMAL;
442 SetState(RECORDER_STATE_STARTING);
455 _VideoRecorderImpl::Stop(void)
457 result r = E_SUCCESS;
458 RecorderState state = RECORDER_STATE_ERROR;
459 SysLog(NID_MEDIA, "Enter.");
463 NID_MEDIA, state == RECORDER_STATE_RECORDING || state == RECORDER_STATE_PAUSING || state == RECORDER_STATE_PAUSED
464 || state == RECORDER_STATE_STARTING
465 , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d",
468 r = ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_NORMAL);
469 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder record stop failed.", GetErrorMessage(r));
477 _VideoRecorderImpl::Pause(void)
479 result r = E_SUCCESS;
480 RecorderState state = RECORDER_STATE_ERROR;
481 SysLog(NID_MEDIA, "Enter.");
484 SysTryReturn(NID_MEDIA, state == RECORDER_STATE_RECORDING, E_INVALID_STATE, E_INVALID_STATE,
485 "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d",
488 r = ChangeStateTo(::RECORDER_STATE_PAUSED, _RECORDER_STATE_REASON_NORMAL);
489 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder pause failed.", GetErrorMessage(r));
498 _VideoRecorderImpl::Cancel(void)
500 result r = E_SUCCESS;
501 RecorderState state = RECORDER_STATE_ERROR;
502 SysLog(NID_MEDIA, "Enter.");
506 NID_MEDIA, state == RECORDER_STATE_RECORDING || state == RECORDER_STATE_PAUSING || state == RECORDER_STATE_PAUSED
507 || state == RECORDER_STATE_STARTING, E_INVALID_STATE, E_INVALID_STATE,
508 "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d", state);
510 r = ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_CANCEL);
511 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder cancel failed.", GetErrorMessage(r));
520 _VideoRecorderImpl::GetState(void) const
526 _VideoRecorderImpl::GetRecordingTime(void) const
532 _VideoRecorderImpl::GetRecordingSize(void) const
538 _VideoRecorderImpl::SetMaxRecordingTime(long msTime)
540 result r = E_SUCCESS;
541 RecorderState state = RECORDER_STATE_ERROR;
542 SysLog(NID_MEDIA, "Enter. msTime:%d", msTime);
546 NID_MEDIA, state == RECORDER_STATE_INITIALIZED
547 || state == RECORDER_STATE_OPENED || state == RECORDER_STATE_ENDOF_FILE || state == RECORDER_STATE_CLOSED
548 , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d.",
551 SysTryReturn(NID_MEDIA, msTime > 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] msTime is out of range. msTime:%d must be greater than 0.",
554 if (__handle != MM_INVALID_HANDLE)
556 r = SetMaxRecordingTimeAttr(msTime);
557 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder set max recording time failed. msTime:%ls", GetErrorMessage(r), msTime);
559 // For reload and Get the exact value
569 _VideoRecorderImpl::GetMaxRecordingTime(void) const
575 _VideoRecorderImpl::SetCodec(const Tizen::Base::String& codec)
577 result r = E_SUCCESS;
578 CodecType audioCodec = CODEC_NONE;
579 CodecType videoCodec = CODEC_NONE;
580 MediaContainerType container = MEDIA_CONTAINER_NONE;
581 SysLog(NID_MEDIA, "Enter. codec:%ls", codec.GetPointer());
582 SysTryReturn(NID_MEDIA, !codec.IsEmpty(), E_UNSUPPORTED_CODEC, E_UNSUPPORTED_CODEC, "[E_UNSUPPORTED_CODEC] The codec is empty.\n");
584 RecorderState state = GetState();
585 SysTryReturn(NID_MEDIA, state == RECORDER_STATE_INITIALIZED
586 || state == RECORDER_STATE_OPENED || state == RECORDER_STATE_ENDOF_FILE
587 || state == RECORDER_STATE_CLOSED
588 , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d", state);
590 std::unique_ptr<IList, _ListPtrUtil::Remover> pList (GetSupportedCodecListN(), _ListPtrUtil::remover);
591 SysTryCatch(NID_MEDIA, pList.get() != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Getting the supported list was failed.\n");
592 SysTryCatch(NID_MEDIA, pList->Contains(codec), r = E_UNSUPPORTED_CODEC, E_UNSUPPORTED_CODEC, "[E_UNSUPPORTED_CODEC]. This codec(%ls) is not supported in the device.\n", codec.GetPointer());
594 GetMediaType(codec, audioCodec, videoCodec, container);
595 SysTryCatch(NID_MEDIA, audioCodec != CODEC_NONE && videoCodec != CODEC_NONE, r = E_UNSUPPORTED_CODEC, E_UNSUPPORTED_CODEC
596 , "[E_UNSUPPORTED_CODEC]. This codec(%ls) is not supported in the device.\n", codec.GetPointer());
598 if (__handle != MM_INVALID_HANDLE)
600 r = SetFormatAttr(audioCodec, videoCodec, container);
601 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] File format set failed. audioCodec:0x%x videoCodec:0x%x container:0x%x",
602 GetErrorMessage(r), audioCodec, videoCodec, videoCodec);
604 __audioCodec = audioCodec;
605 __videoCodec = videoCodec;
606 __container = container;
608 if (__handle != MM_INVALID_HANDLE)
610 // Call the dependency function.
611 r = ReloadConfiguration(_RELOAD_QUALITY);
612 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration.", GetErrorMessage(r));
620 _VideoRecorderImpl::GetCodec(void) const
623 GetCodecString(__videoCodec, codec);
627 Tizen::Base::Collection::IList*
628 _VideoRecorderImpl::GetSupportedCodecListN(void) const
630 _CapabilityImpl *pCapImpl = null;
631 result r = E_SUCCESS;
633 pCapImpl = _CapabilityImpl::GetInstance();
634 SysTryReturn(NID_MEDIA, pCapImpl != null, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Get capability information failed.");
636 std::unique_ptr<ArrayList, _ListPtrUtil::Remover> pCodecList (new (std::nothrow) Tizen::Base::Collection::ArrayList(), _ListPtrUtil::remover);
637 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.");
639 r = pCodecList->Construct();
640 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder get attribute failed.", GetErrorMessage(r));
642 r = pCapImpl->GetValueN(VIDEORECORDER_CODEC, *(pCodecList.get()));
643 SysTryCatch(NID_MEDIA, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Converted from '%s'.", GetErrorMessage(r));
644 SysTryCatch(NID_MEDIA, pCodecList.get() != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Supported list was wrong.");
645 SysTryCatch(NID_MEDIA, pCodecList->GetCount() > 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. The list was empty.");
647 return pCodecList.release();
654 _VideoRecorderImpl::SetFormat(VideoRecordingFormat format)
656 result r = E_SUCCESS;
657 RecorderState state = RECORDER_STATE_ERROR;
658 CodecType audioCodec = CODEC_NONE;
659 CodecType videoCodec = CODEC_NONE;
660 MediaContainerType container = MEDIA_CONTAINER_NONE;
661 SysLog(NID_MEDIA, "Enter. format:%d", format);
664 SysTryReturn(NID_MEDIA, state == RECORDER_STATE_INITIALIZED
665 || state == RECORDER_STATE_OPENED || state == RECORDER_STATE_ENDOF_FILE
666 || state == RECORDER_STATE_CLOSED
667 , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d.", state);
669 SysTryReturn(NID_MEDIA, format >= VIDEORECORDING_FORMAT_DEFAULT && format <= VIDEORECORDING_FORMAT_3GP
670 , E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The format(%d) is not supported.\n",
673 GetMediaType(format, audioCodec, videoCodec, container);
674 SysTryCatch(NID_MEDIA, audioCodec != CODEC_NONE && videoCodec != CODEC_NONE, r = E_UNSUPPORTED_CODEC, E_UNSUPPORTED_CODEC
675 , "[E_UNSUPPORTED_CODEC]. This format(%d) is not supported in the device.\n", format);
677 if (__handle != MM_INVALID_HANDLE)
679 r = SetFormatAttr(audioCodec, videoCodec, container);
680 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] File format set failed. audioCodec:0x%x videoCodec:0x%x container:0x%x",
681 GetErrorMessage(r), audioCodec, videoCodec, videoCodec);
684 __audioCodec = audioCodec;
685 __videoCodec = videoCodec;
686 __container = container;
687 if (__handle != MM_INVALID_HANDLE)
689 // Call the dependency function.
690 r = ReloadConfiguration(_RELOAD_QUALITY);
691 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration.", GetErrorMessage(r));
700 _VideoRecorderImpl::GetFormat(void) const
706 _VideoRecorderImpl::SetFormat(CodecType audioCodec, CodecType videoCodec, MediaContainerType container)
708 result r = E_SUCCESS;
709 RecorderState state = RECORDER_STATE_ERROR;
710 bool supported = false;
711 SysLog(NID_MEDIA, "Enter. audioCodec:0x%x, videoCodec:0x%x, container:0x%x", audioCodec, videoCodec, container);
715 NID_MEDIA, state == RECORDER_STATE_INITIALIZED || state == RECORDER_STATE_OPENED || state ==
716 RECORDER_STATE_ENDOF_FILE || state == RECORDER_STATE_CLOSED
717 , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d.",
720 std::unique_ptr<ArrayListT<CodecType>, _ListPtrUtil::Remover> pAudioCodecListT (GetSupportedAudioCodecListN(), _ListPtrUtil::remover);
721 SysTryReturn(NID_MEDIA, pAudioCodecListT.get() != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Getting the supported list was failed.\n");
722 SysTryReturn(NID_MEDIA, pAudioCodecListT->Contains(audioCodec) || audioCodec == CODEC_NONE, E_UNSUPPORTED_CODEC, E_UNSUPPORTED_CODEC,
723 "[E_UNSUPPORTED_CODEC]This AudioCodec(%d) is not supported in the device.\n", audioCodec);
725 std::unique_ptr<ArrayListT<CodecType>, _ListPtrUtil::Remover> pVideoCodecListT (GetSupportedVideoCodecListN(), _ListPtrUtil::remover);
726 SysTryReturn(NID_MEDIA, pVideoCodecListT.get() != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Getting the supported list was failed.\n");
727 SysTryReturn(NID_MEDIA, pVideoCodecListT->Contains(videoCodec), E_UNSUPPORTED_CODEC, E_UNSUPPORTED_CODEC,
728 "[E_UNSUPPORTED_CODEC]This VideoCodec(%d) is not supported in the device.\n", videoCodec);
730 std::unique_ptr<ArrayListT<MediaContainerType>, _ListPtrUtil::Remover> pContainerCodecListT (GetSupportedContainerListN(), _ListPtrUtil::remover);
731 SysTryReturn(NID_MEDIA, pContainerCodecListT.get() != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Getting the supported list was failed.\n");
732 SysTryReturn(NID_MEDIA, pContainerCodecListT->Contains(container), E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
733 "[E_UNSUPPORTED_FORMAT]This Container(%d) is not supported in the device.\n", container);
735 supported = _RecorderUtil::CheckFormat(audioCodec, videoCodec, container);
736 SysTryCatch(NID_MEDIA, supported, r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
737 "[E_UNSUPPORTED_FORMAT] camcorder check foramt failed. audioCodec:0x%x, videoCodec:0x%x, container:0x%x",
738 audioCodec, videoCodec,
741 if (__handle != MM_INVALID_HANDLE)
743 r = SetFormatAttr(audioCodec, videoCodec, container);
744 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] File format set failed. audioCodec:0x%x videoCodec:0x%x container:0x%x",
745 GetErrorMessage(r), audioCodec, videoCodec, videoCodec);
747 __audioCodec = audioCodec;
748 __videoCodec = videoCodec;
749 __container = container;
751 if (__handle != MM_INVALID_HANDLE)
753 // Call the dependency function.
754 r = ReloadConfiguration(_RELOAD_QUALITY);
755 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder reload configuration.", GetErrorMessage(r));
763 _VideoRecorderImpl::GetFormat(CodecType& audioCodec, CodecType& videoCodec, MediaContainerType& container) const
765 audioCodec = __audioCodec;
766 videoCodec = __videoCodec;
767 container = __container;
770 Tizen::Base::Collection::ArrayListT <CodecType>*
771 _VideoRecorderImpl::GetSupportedAudioCodecListN(void) const
773 result r = E_SUCCESS;
774 _ResultType itemType = _RESULT_INTEGER_LIST;
776 std::unique_ptr<IList, _ListPtrUtil::Remover> pIntegerList (_RecorderCapability::GetListN(_VROP_AUDIO_ENCODER, itemType), _ListPtrUtil::remover);
777 SysTryReturn(NID_MEDIA, pIntegerList.get() != null, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Supported list was wrong.");
778 SysTryReturn(NID_MEDIA, pIntegerList->GetCount() > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. The list was empty.");
780 std::unique_ptr<ArrayListT<CodecType>, _ListPtrUtil::Remover> pAudioCodecList (new (std::nothrow) ArrayListT<CodecType>(), _ListPtrUtil::remover);
781 SysTryReturn(NID_MEDIA, pAudioCodecList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
783 r = pAudioCodecList->Construct();
784 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
786 for (int i = 0; i < pIntegerList->GetCount(); i++)
789 Integer* pInteger = null;
790 pObj = pIntegerList->GetAt(i);
791 SysTryCatch(NID_MEDIA, pObj != null, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object instance is not available. %d item is not found.", i);
793 pInteger = dynamic_cast<Integer*>(pObj);
794 SysTryCatch(NID_MEDIA, pInteger != null, r = E_INVALID_FORMAT, E_INVALID_FORMAT, "[E_INVALID_FORMAT] %d item's format is invalid.", i);
796 r = pAudioCodecList->Add((CodecType)pInteger->ToInt());
797 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
798 SysLog(NID_MEDIA, "Pixel format : %d was added.", pInteger->ToInt());
801 return pAudioCodecList.release();
807 Tizen::Base::Collection::ArrayListT<CodecType>*
808 _VideoRecorderImpl::GetSupportedVideoCodecListN(void) const
810 result r = E_SUCCESS;
811 _ResultType itemType = _RESULT_INTEGER_LIST;
813 std::unique_ptr<IList, _ListPtrUtil::Remover> pIntegerList (_RecorderCapability::GetListN(_VROP_VIDEO_ENCODER, itemType), _ListPtrUtil::remover);
814 SysTryReturn(NID_MEDIA, pIntegerList.get() != null, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Supported list was wrong.");
815 SysTryReturn(NID_MEDIA, pIntegerList->GetCount() > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. The list was empty.");
817 std::unique_ptr<ArrayListT<CodecType>, _ListPtrUtil::Remover> pVideoCodecList (new (std::nothrow) ArrayListT<CodecType>(), _ListPtrUtil::remover);
818 SysTryReturn(NID_MEDIA, pVideoCodecList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
820 r = pVideoCodecList->Construct();
821 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
823 for (int i = 0; i < pIntegerList->GetCount(); i++)
826 Integer* pInteger = null;
827 pObj = pIntegerList->GetAt(i);
828 SysTryCatch(NID_MEDIA, pObj != null, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object instance is not available. %d item is not found.", i);
830 pInteger = dynamic_cast<Integer*>(pObj);
831 SysTryCatch(NID_MEDIA, pInteger != null, r = E_INVALID_FORMAT, E_INVALID_FORMAT, "[E_INVALID_FORMAT] %d item's format is invalid.", i);
833 r = pVideoCodecList->Add((CodecType)pInteger->ToInt());
834 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
835 SysLog(NID_MEDIA, "Pixel format : %d was added.", pInteger->ToInt());
838 return pVideoCodecList.release();
845 Tizen::Base::Collection::ArrayListT<MediaContainerType>*
846 _VideoRecorderImpl::GetSupportedContainerListN(void) const
848 result r = E_SUCCESS;
849 _ResultType itemType = _RESULT_INTEGER_LIST;
851 std::unique_ptr<IList, _ListPtrUtil::Remover> pIntegerList (_RecorderCapability::GetListN(_VROP_FILE_FORMAT, itemType), _ListPtrUtil::remover);
852 SysTryReturn(NID_MEDIA, pIntegerList.get() != null, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Supported list was wrong.");
853 SysTryReturn(NID_MEDIA, pIntegerList->GetCount() > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. The list was empty.");
855 std::unique_ptr<ArrayListT<MediaContainerType>, _ListPtrUtil::Remover> pContainerList (new (std::nothrow) ArrayListT<MediaContainerType>(), _ListPtrUtil::remover);
856 SysTryReturn(NID_MEDIA, pContainerList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
858 r = pContainerList->Construct();
859 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
861 for (int i = 0; i < pIntegerList->GetCount(); i++)
864 Integer* pInteger = null;
865 pObj = pIntegerList->GetAt(i);
866 SysTryCatch(NID_MEDIA, pObj != null, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object instance is not available. %d item is not found.", i);
868 pInteger = dynamic_cast<Integer*>(pObj);
869 SysTryCatch(NID_MEDIA, pInteger != null, r = E_INVALID_FORMAT, E_INVALID_FORMAT, "[E_INVALID_FORMAT] %d item's format is invalid.", i);
871 r = pContainerList->Add((MediaContainerType)pInteger->ToInt());
872 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
873 SysLog(NID_MEDIA, "Pixel format : %d was added.", pInteger->ToInt());
876 return pContainerList.release();
884 _VideoRecorderImpl::SetMode(VideoRecorderMode mode)
886 result r = E_SUCCESS;
887 RecorderState state = RECORDER_STATE_ERROR;
889 SysLog(NID_MEDIA, "Enter. mode:%d", mode);
892 SysTryReturn(NID_MEDIA, state == RECORDER_STATE_INITIALIZED
893 || state == RECORDER_STATE_OPENED || state == RECORDER_STATE_ENDOF_FILE
894 || state == RECORDER_STATE_CLOSED
895 , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d.");
897 SysTryReturn(NID_MEDIA, mode >= VIDEORECORDER_MODE_VIDEO_WITH_AUDIO && mode <= VIDEORECORDER_MODE_VIDEO_ONLY
898 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(mode) is used. mode=%d.", mode);
900 r = SetMute(mode == VIDEORECORDER_MODE_VIDEO_ONLY ? true : false);
901 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. mode:%d", GetErrorMessage(r), mode);
909 _VideoRecorderImpl::GetMode(void) const
915 _VideoRecorderImpl::SetQuality(RecordingQuality quality)
917 result r = E_SUCCESS;
918 RecorderState state = RECORDER_STATE_ERROR;
919 CodecType audioCodec = CODEC_NONE;
920 CodecType videoCodec = CODEC_NONE;
921 MediaContainerType container = MEDIA_CONTAINER_NONE;
922 SysLog(NID_MEDIA, "Enter. quality:%d", quality);
925 SysTryReturn(NID_MEDIA, state == RECORDER_STATE_INITIALIZED
926 || state == RECORDER_STATE_OPENED || state == RECORDER_STATE_ENDOF_FILE || state == RECORDER_STATE_CLOSED
927 , E_INVALID_STATE, r, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d.", state);
929 SysTryReturn(NID_MEDIA, (quality >= RECORDING_QUALITY_LOW && quality <= RECORDING_QUALITY_HIGH)
930 , E_INVALID_ARG, r, "[E_INVALID_ARG] Invalid argument(quality) is used. The quality=%d.", quality);
932 GetFormat(audioCodec, videoCodec, container);
934 if (__handle != MM_INVALID_HANDLE)
936 r = SetQualityAttr(quality, audioCodec, videoCodec);
937 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] set quality failed. quality:%d", GetErrorMessage(r), quality);
947 _VideoRecorderImpl::GetQuality(void) const
953 _VideoRecorderImpl::SetRecordingResolution(const Tizen::Graphics::Dimension& resolution)
955 result r = E_SUCCESS;
956 RecorderState state = RECORDER_STATE_ERROR;
957 SysLog(NID_MEDIA, "Enter. resolution(%d,%d)", resolution.width, resolution.height);
960 SysTryReturn(NID_MEDIA, state == RECORDER_STATE_INITIALIZED
961 || state == RECORDER_STATE_OPENED || state == RECORDER_STATE_ENDOF_FILE
962 || state == RECORDER_STATE_CLOSED
963 , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d.", state);
965 SysTryReturn(NID_MEDIA, resolution.width >= 0 && resolution.height >= 0
966 , E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] resolution is out of range. The resolution(%d,%d) must be greater than (0,0).",
970 std::unique_ptr<IList, _ListPtrUtil::Remover> pList (GetSupportedRecordingResolutionListN(), _ListPtrUtil::remover);
971 SysTryReturn(NID_MEDIA, pList.get() != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Getting the supported list was failed.\n");
972 SysTryReturn(NID_MEDIA, pList->Contains(resolution), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE]. resolution is out of range. This resolution(%d,%d) is not supported in the device.\n", resolution.width, resolution.height);
974 if ( __pVideoSourceAdapter->HasRecordingResolutionRestriction())
976 Dimension sourceResolution = __pVideoSourceAdapter->GetSourceResolution();
977 SysTryReturn(NID_MEDIA, sourceResolution == resolution, E_SYSTEM, E_SYSTEM,
978 "[E_SYSTEM] A system error has been occurred. The source resolution(%d,%d) should be same as the recording resolution(%d,%d).", sourceResolution.width, sourceResolution.height, resolution.width, resolution.height);
982 SysLog(NID_MEDIA, "There is no recording attribute... ");
985 __recordingResolution = resolution;
990 Tizen::Graphics::Dimension
991 _VideoRecorderImpl::GetRecordingResolution(void) const
993 return __recordingResolution;
996 Tizen::Base::Collection::IList*
997 _VideoRecorderImpl::GetSupportedRecordingResolutionListN(void) const
999 SysTryReturn(NID_MEDIA, __pVideoSourceAdapter != null, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. The source is deleted.");
1001 return __pVideoSourceAdapter->GetSupportedRecordingResolutionListN();
1005 _VideoRecorderImpl::GetSupportedMaxFrameRate(const Tizen::Graphics::Dimension& dim) const
1007 result r = E_SUCCESS;
1008 int maxFrameRate = 0;
1010 SysTryReturn(NID_MEDIA, __pVideoSourceAdapter != null, 0, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. The source is deleted.");
1012 std::unique_ptr<IListT<int>, _ListPtrUtil::Remover> pListT (__pVideoSourceAdapter->GetSupportedFrameRateListN(dim), _ListPtrUtil::remover);
1013 SysTryCatch(NID_MEDIA, pListT.get() != null, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Supported list was wrong.");
1014 SysTryCatch(NID_MEDIA, pListT->GetCount() > 0, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. The list was empty.");
1016 r = pListT->GetAt(pListT->GetCount()-1, maxFrameRate);
1017 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] propogated", GetErrorMessage(r));
1019 return maxFrameRate;
1026 _VideoRecorderImpl::SetMute(bool mute)
1028 result r = E_SUCCESS;
1029 RecorderState state = RECORDER_STATE_ERROR;
1030 SysLog(NID_MEDIA, "Enter. mute:%d", mute);
1033 SysTryReturn(NID_MEDIA, state == RECORDER_STATE_INITIALIZED
1034 || state == RECORDER_STATE_OPENED || state == RECORDER_STATE_ENDOF_FILE || state == RECORDER_STATE_CLOSED
1035 || state == RECORDER_STATE_STOPPED || state == RECORDER_STATE_PAUSED || state == RECORDER_STATE_RECORDING
1036 , E_INVALID_STATE, r, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d.", state);
1038 if (__handle != MM_INVALID_HANDLE)
1040 r = SetMuteAttr(mute);
1041 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating. mute:%d", GetErrorMessage(r), mute);
1048 _VideoRecorderImpl::IsMuted(void) const
1054 _VideoRecorderImpl::SetRecordingRotation(RecordingRotation rotation)
1056 result r = E_SUCCESS;
1057 RecorderState state = RECORDER_STATE_ERROR;
1058 SysLog(NID_MEDIA, "Enter. rotation:%d", rotation);
1061 SysTryReturn(NID_MEDIA, state == RECORDER_STATE_INITIALIZED
1062 || state == RECORDER_STATE_OPENED || state == RECORDER_STATE_CLOSED
1063 , E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] VideoRecorder is in an invalid state:%d.", state);
1065 SysTryReturn(NID_MEDIA, (rotation >= RECORDING_ROTATION_NONE&& rotation <= RECORDING_ROTATION_270)
1066 , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(rotation) is used. The rotation=%d.", rotation);
1068 if (__handle != MM_INVALID_HANDLE)
1070 __pCoordinator->SetRecordingOrientation(rotation);
1072 __rotation = rotation;
1078 _VideoRecorderImpl::GetRecordingRotation(void) const
1084 _VideoRecorderImpl::SetFormatAttr(CodecType audioCodec, CodecType videoCodec, MediaContainerType container)
1086 result r = E_SUCCESS;
1087 int err = ::RECORDER_ERROR_NONE;
1089 recorder_audio_codec_e attrAudioCodec = ::RECORDER_AUDIO_CODEC_AAC;
1090 recorder_video_codec_e attrVideoCodec = ::RECORDER_VIDEO_CODEC_MPEG4;
1091 recorder_file_format_e attrFormat = ::RECORDER_FILE_FORMAT_MP4;
1093 r = _RecorderUtil::GetMmAudioCodec(audioCodec, attrAudioCodec);
1094 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. audio codec:0x%x", GetErrorMessage(r), audioCodec);
1096 err = recorder_set_audio_encoder(__handle, attrAudioCodec);
1097 r = ConvertResult(err);
1098 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Audio codec set failed. codec:0x%x", GetErrorMessage(r), audioCodec);
1100 r = _RecorderUtil::GetMmVideoCodec(videoCodec, attrVideoCodec);
1101 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. video codec:0x%x", GetErrorMessage(r), videoCodec);
1103 err = recorder_set_video_encoder(__handle, attrVideoCodec);
1104 r = ConvertResult(err);
1105 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Video codec set failed. codec:0x%x", GetErrorMessage(r), videoCodec);
1107 r = _RecorderUtil::GetMmFileFormat(container, attrFormat);
1108 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. container:0x%x", GetErrorMessage(r), container);
1110 err = recorder_set_file_format(__handle, attrFormat);
1111 r = ConvertResult(err);
1112 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] File format set failed. container:0x%x", GetErrorMessage(r), container);
1120 _VideoRecorderImpl::SetQualityAttr(RecordingQuality quality, CodecType audioCodec, CodecType videoCodec)
1122 result r = E_SUCCESS;
1123 int err = ::RECORDER_ERROR_NONE;
1124 int attrVideoBitrate = 0;
1125 if (audioCodec != CODEC_NONE)
1127 int attrAudioSampleate = 0;
1128 int attrAudioChannel = 0;
1129 int attrAudioBitrate = 0;
1131 r = _RecorderUtil::GetMmAudioQuality(audioCodec, quality, attrAudioSampleate, attrAudioChannel, attrAudioBitrate);
1132 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. audioCodec:%d, quality:%d", GetErrorMessage(r), audioCodec, quality);
1134 err = recorder_attr_set_audio_samplerate(__handle, attrAudioSampleate);
1135 r = ConvertResult(err);
1136 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Sampling-rate set failed. attr:%d", GetErrorMessage(r), attrAudioSampleate);
1138 err = recorder_attr_set_audio_channel(__handle, attrAudioChannel);
1139 r = ConvertResult(err);
1140 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Channel set failed. attr:%d", GetErrorMessage(r), attrAudioChannel);
1142 err = recorder_attr_set_audio_encoder_bitrate(__handle, attrAudioBitrate);
1143 r = ConvertResult(err);
1144 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Bitrate set failed. attr:%d", GetErrorMessage(r), attrAudioBitrate);
1146 r = _RecorderUtil::GetMmVideoQuality(_CameraUtil::ConvertResolutionType(__recordingResolution), quality, attrVideoBitrate);
1147 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. videoCodec:%d, quality:%d", GetErrorMessage(r), videoCodec, quality);
1149 err = recorder_attr_set_video_encoder_bitrate(__handle, attrVideoBitrate);
1150 r = ConvertResult(err);
1151 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Bitrate set failed. attr:%d", GetErrorMessage(r), attrVideoBitrate);
1159 _VideoRecorderImpl::SetMuteAttr(bool mute)
1161 result r = E_SUCCESS;
1162 int err = ::RECORDER_ERROR_NONE;
1164 err = recorder_attr_set_mute(__handle, mute);
1165 r = ConvertResult(err);
1166 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set mute failed", GetErrorMessage(r));
1173 _VideoRecorderImpl::SetMaxRecordingTimeAttr(long msTime)
1175 result r = E_SUCCESS;
1176 int err = ::RECORDER_ERROR_NONE;
1177 int secTime = MEDIA_INVALID_VALUE;
1178 // msec max time is not possible to set
1179 secTime = msTime > 1000 ? ((msTime + 500) / 1000) : 1;
1180 err = recorder_attr_set_time_limit(__handle, secTime);
1181 r = ConvertResult(err);
1182 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder set attribute failed. msTime:%ls", GetErrorMessage(r), msTime);
1189 _VideoRecorderImpl::SetCallback(void)
1191 result r = E_SUCCESS;
1192 int err = ::RECORDER_ERROR_NONE;
1194 err = recorder_set_state_changed_cb(__handle, StateChangedCb, this);
1195 r = ConvertResult(err);
1196 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set message callback failed.", GetErrorMessage(r));
1198 err = recorder_set_recording_limit_reached_cb(__handle, LimitReachedCb, this);
1199 r = ConvertResult(err);
1200 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set limit reached callback failed.", GetErrorMessage(r));
1202 err = recorder_set_recording_status_cb(__handle, RecordingStatusCb, this);
1203 r = ConvertResult(err);
1204 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set recording status callback failed.", GetErrorMessage(r));
1206 err = recorder_set_error_cb(__handle, ErrorCb, this);
1207 r = ConvertResult(err);
1208 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set limit reached callback failed.", GetErrorMessage(r));
1210 err = recorder_set_interrupted_cb(__handle, InterruptedCb, this);
1211 r = ConvertResult(err);
1212 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set limit reached callback failed.", GetErrorMessage(r));
1220 _VideoRecorderImpl::OnCameraCoordinatorModeChangePrepared(_CameraMode mode)
1222 result r = E_SUCCESS;
1223 SysLog(NID_MEDIA, "Mode:%d", mode);
1224 __handle = __pCoordinator->GetRecorderHandle(); // update to the new handle. All configuration shuld be updated with this handle after mode changing.
1226 if ( mode == _CAMERA_MODE_VIDEO )
1228 r = __pCoordinator->SetCameraSourceFormat(__mmSourceFormat);
1229 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1231 r = ReloadConfiguration(_RELOAD_FORMAT | _RELOAD_QUALITY);
1232 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
1241 _VideoRecorderImpl::OnCameraCoordinatorModeChanged(_CameraMode mode)
1243 result r = E_SUCCESS;
1244 SysLog(NID_MEDIA, "Mode:%d", mode);
1246 if ( mode == _CAMERA_MODE_VIDEO )
1248 r = ReloadConfiguration(_RELOAD_MAX_TIME | _RELOAD_FILE_PATH | _RELOAD_CALLBACK | _RELOAD_MUTE | _RELOAD_ROTATION);
1249 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
1258 _VideoRecorderImpl::StateChangedCb(recorder_state_e previous, recorder_state_e current, bool byPolicy, void* pUserData)
1260 result r = E_SUCCESS;
1261 _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>( pUserData);
1262 int tableTotalCount = 0;
1264 SysTryReturn(NID_MEDIA, _VideoRecorderImpl::IsAlive(), , E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
1265 SysTryReturn(NID_MEDIA, pImpl != null, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. pImpl is null.");
1266 SysLog(NID_MEDIA, "State previous:%d, current:%d, byPolicy:%d", previous, current, byPolicy);
1268 tableTotalCount = sizeof(_VIDEO_CALLBACK_EVENT) / sizeof(_VIDEO_CALLBACK_EVENT[0]);
1270 for (i = 0; i < tableTotalCount; i++)
1272 if (previous == _VIDEO_CALLBACK_EVENT[i].prevState && current == _VIDEO_CALLBACK_EVENT[i].postState && pImpl->GetStateChangeReason() == _VIDEO_CALLBACK_EVENT[i].reason) //for cancel
1274 r = pImpl->GetEvent()->SendEvent(_VIDEO_CALLBACK_EVENT[i].event, _VIDEO_CALLBACK_EVENT[i].error, E_SUCCESS);
1275 SysLog(NID_MEDIA, "VIDEO_CALLBACK_EVENT(%d) is sent by StateChangedCb", _VIDEO_CALLBACK_EVENT[i].event);
1276 SysTryReturn(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. i:%d", GetErrorMessage(r), i);
1283 _VideoRecorderImpl::RecordingStatusCb(unsigned long long elapsedTime, unsigned long long fileSize, void *pUserData)
1285 _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>(pUserData);
1286 SysTryReturn(NID_MEDIA, _VideoRecorderImpl::IsAlive(), , E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
1287 SysTryReturn(NID_MEDIA, pImpl != null, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. pImpl is null.");
1289 SysLog(NID_MEDIA, "FileSize:%llu,elapsedTime:%llu",fileSize,elapsedTime);
1291 pImpl->SetRecordingTime((long)elapsedTime);
1292 pImpl->SetRecordingSize((long)fileSize);
1296 _VideoRecorderImpl::AudioStreamCb(void* pStream, int size, audio_sample_type_e format, int channel, unsigned int timeStamp, void *pUserData)
1298 _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>(pUserData);
1299 SysTryReturn(NID_MEDIA, _VideoRecorderImpl::IsAlive(), , E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
1300 SysTryReturn(NID_MEDIA, pImpl != null, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. Impl is null.");
1301 SysTryReturn(NID_MEDIA, pStream != null, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] void instance is not available. pStream is null.");
1303 // SysLog(NID_MEDIA, "Size:%d, format:%d, channel:%d, timeStamp:%u", size, format, channel, timeStamp);
1307 _VideoRecorderImpl::LimitReachedCb(recorder_recording_limit_type_e type, void *pUserData)
1309 result r = E_SUCCESS;
1310 _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>(pUserData);
1311 SysTryReturn(NID_MEDIA, _VideoRecorderImpl::IsAlive(), , E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
1312 SysTryReturn(NID_MEDIA, pImpl != null, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. pImpl is null.");
1314 SysLog(NID_MEDIA, "Type:%d", type);
1318 case ::RECORDER_RECORDING_LIMIT_TIME:
1319 r = pImpl->ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_TIME_REACHED);
1320 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1323 case ::RECORDER_RECORDING_LIMIT_SIZE:
1324 r = pImpl->ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_END_SIZE_REACHED);
1325 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1328 case ::RECORDER_RECORDING_LIMIT_FREE_SPACE:
1329 r = pImpl->ChangeStateTo(::RECORDER_STATE_READY, _RECORDER_STATE_REASON_OUT_OF_STORAGE);
1330 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1342 _VideoRecorderImpl::ErrorCb(recorder_error_e error, recorder_state_e state, void *pUserData)
1344 result r = E_SUCCESS;
1345 _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>(pUserData);
1346 SysTryReturn(NID_MEDIA, _VideoRecorderImpl::IsAlive(), , E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
1347 SysTryReturn(NID_MEDIA, pImpl != null, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. pImpl is null.");
1348 SysLog(NID_MEDIA, "Error:%d, state:%d", error, state);
1350 _CameraCoordinator* __pCoordinator = null;
1351 __pCoordinator = _CameraCoordinator::AddInstance(pImpl->GetDeviceType());
1352 SysTryCatch(NID_MEDIA, __pCoordinator != null, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _CameraCoordinator instance is not available. Coordinator is not found");
1354 r = __pCoordinator->ChangeMode(_CAMERA_MODE_IMAGE, true);
1355 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1357 _CameraCoordinator::Release(pImpl->GetDeviceType());
1359 r = pImpl->GetEvent()->SendEvent(_RECORDER_EVENT_ERROR, RECORDER_ERROR_DEVICE_FAILED, E_SUCCESS);
1360 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1368 _VideoRecorderImpl::InterruptedCb(recorder_policy_e policy, recorder_state_e previous, recorder_state_e current, void *pUserData)
1370 _VideoRecorderImpl* pImpl = static_cast<_VideoRecorderImpl*>(pUserData);
1371 SysTryReturn(NID_MEDIA, _VideoRecorderImpl::IsAlive(), , E_INVALID_OPERATION, "[E_INVALID_OPERATION] The object was already destroyed.");
1372 SysTryReturn(NID_MEDIA, pImpl != null, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] _VideoRecorderImpl instance is not available. pImpl is null.");
1374 SysLog(NID_MEDIA, "Policy:%d, previous:%d, current:%d", policy, previous, current);
1377 _VideoRecorderEvent*
1378 _VideoRecorderImpl::GetEvent(void) const
1380 return __pVideoRecorderEvent;
1384 _VideoRecorderImpl::SetState(RecorderState state)
1390 _VideoRecorderImpl::SetRecordingTime(long recTime)
1392 __recTime = recTime;
1396 _VideoRecorderImpl::SetRecordingSize(long recSize)
1398 __recSize = recSize;
1402 _VideoRecorderImpl::GetDeviceType(void) const
1404 return __deviceType;
1408 _VideoRecorderImpl::ConvertResult(int err) const
1410 result r = E_SYSTEM;
1411 if (err != ::RECORDER_ERROR_NONE)
1413 SysLog(NID_MEDIA, "MM Err:0x%x", err);
1417 if (err == ::RECORDER_ERROR_NONE)
1421 else if (err == ::RECORDER_ERROR_INVALID_PARAMETER)
1425 else if (err == ::RECORDER_ERROR_INVALID_STATE)
1427 r = E_INVALID_STATE;
1429 else if (err == ::RECORDER_ERROR_OUT_OF_MEMORY)
1431 r = E_OUT_OF_MEMORY;
1433 else if (err == ::RECORDER_ERROR_DEVICE)
1435 r = E_DEVICE_FAILED;
1437 else if (err == ::RECORDER_ERROR_INVALID_OPERATION
1438 || err == ::RECORDER_ERROR_SECURITY_RESTRICTED)
1442 else if (err == ::RECORDER_ERROR_SOUND_POLICY)
1455 _VideoRecorderImpl::GetCodecString(const CodecType videoCodec, Tizen::Base::String& codec) const
1459 while (_CODEC_VAL_TABLE[i].pCodecName != null)
1461 if (videoCodec == _CODEC_VAL_TABLE[i].videoCodec)
1464 codec.Append(_CODEC_VAL_TABLE[i].pCodecName);
1472 _VideoRecorderImpl::ChangeStateTo(recorder_state_e mmDestState, _RecorderStateChangeReason reason)
1474 result r = E_SUCCESS;
1475 int tableTotalCount = 0;
1477 int err = MM_SUCCESS;
1478 recorder_state_e preState = ::RECORDER_STATE_NONE;
1479 recorder_state_e postState = ::RECORDER_STATE_NONE;
1481 SysLog(NID_MEDIA, "Enter. mmDestState:%d", mmDestState);
1482 SysTryReturn(NID_MEDIA, __isConstructed == true, E_INVALID_STATE, E_INVALID_STATE,
1483 "[E_INVALID_STATE] VideoRecorder is in an invalid state. VideoRecorder is not constructed.");
1485 preState = GetMmState();
1486 tableTotalCount = sizeof(_VIDEO_COMMAND_STATE) / sizeof(_VIDEO_COMMAND_STATE[0]);
1487 SysLog(NID_MEDIA, " preState:%d, mmDestState:%d, tableTotalCount:%d", preState, mmDestState, tableTotalCount);
1489 for (i = 0; i < tableTotalCount; i++)
1491 if (preState == _VIDEO_COMMAND_STATE[i].preState && mmDestState == _VIDEO_COMMAND_STATE[i].postState && reason ==
1492 _VIDEO_COMMAND_STATE[i].reason)
1494 if (_VIDEO_COMMAND_STATE[i].pFunc != null)
1496 SysLog(NID_MEDIA, "Exist the matching state field. current state:%d, mmState:%d, reason:%d",
1497 preState, mmDestState, reason);
1498 err = _VIDEO_COMMAND_STATE[i].pFunc(__handle);
1499 r = ConvertResult(err);
1500 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating. i:%d", GetErrorMessage(r), i);
1502 // Check whether the retuned states are destinationed states.
1503 postState = GetMmState();
1504 SysTryCatch(NID_MEDIA, mmDestState == postState, r = E_INVALID_STATE, E_INVALID_STATE,
1505 "[E_INVALID_STATE] VideoRecorder state of CAPI is in an invalid state. result mmState:%d, is different from the desired state:%", postState, mmDestState);
1506 SysLog(NID_MEDIA, "[E_SUCCESS] Found. result mmState:%d, param mmDestState:%d", postState,
1509 __stateChangeReason = reason; //for distinguish between stop and cancel
1512 if (_VIDEO_COMMAND_STATE[i].state >= RECORDER_STATE_INITIALIZED && _VIDEO_COMMAND_STATE[i].state <= RECORDER_STATE_ERROR)
1514 SysLog(NID_MEDIA, "State set to %d", _VIDEO_COMMAND_STATE[i].state);
1515 SetState(_VIDEO_COMMAND_STATE[i].state);
1520 SysTryCatch(NID_MEDIA, i != tableTotalCount, r = E_INVALID_STATE, E_INVALID_STATE, "[E_INVALID_STATE] Not found. ");
1524 SysLog(NID_MEDIA, "[%s] Real mmState:%d, param mmState:%d", GetErrorMessage(r), preState, mmDestState);
1528 _RecorderStateChangeReason
1529 _VideoRecorderImpl::GetStateChangeReason(void) const
1531 return __stateChangeReason;
1535 _VideoRecorderImpl::GetMmState(void) const
1537 result r = E_SUCCESS;
1538 int err = ::RECORDER_ERROR_NONE;
1539 recorder_state_e mmState = ::RECORDER_STATE_NONE;
1541 err = recorder_get_state(__handle, &mmState);
1542 r = ConvertResult(err);
1543 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1548 return ::RECORDER_STATE_NONE;
1552 _VideoRecorderImpl::GetMediaType(const Base::String& codec, CodecType& audioCodec, CodecType& videoCodec, MediaContainerType& container) const
1555 std::unique_ptr<char[]> pCodecChars (Tizen::Base::_StringConverter::CopyToCharArrayN(codec));
1557 while (_CODEC_VAL_TABLE[i].pCodecName != null)
1559 if (strcmp(_CODEC_VAL_TABLE[i].pCodecName, pCodecChars.get()) == 0)
1561 videoCodec = _CODEC_VAL_TABLE[i].videoCodec;
1562 audioCodec = _CODEC_VAL_TABLE[i].audioCodec;
1563 container = _CODEC_VAL_TABLE[i].container;
1571 _VideoRecorderImpl::GetMediaType(VideoRecordingFormat format, CodecType& audioCodec, CodecType& videoCodec,
1572 MediaContainerType& container) const
1576 case VIDEORECORDING_FORMAT_3GP:
1577 audioCodec = CODEC_AMR_NB;
1578 videoCodec = CODEC_MPEG4;
1579 container = MEDIA_CONTAINER_3GP;
1582 case VIDEORECORDING_FORMAT_DEFAULT:
1583 case VIDEORECORDING_FORMAT_MP4:
1584 audioCodec = CODEC_AAC;
1585 videoCodec = CODEC_MPEG4;
1586 container = MEDIA_CONTAINER_MP4;
1590 audioCodec = CODEC_NONE;
1591 videoCodec = CODEC_NONE;
1592 container = MEDIA_CONTAINER_NONE;
1598 _VideoRecorderImpl::ReloadConfiguration(int reload)
1600 result r = E_SUCCESS;
1601 int err = MM_SUCCESS;
1602 SysLog(NID_MEDIA, "Enter. reload:0x%x", reload);
1604 if (reload & _RELOAD_FORMAT)
1606 r = SetFormatAttr(__audioCodec, __videoCodec, __container);
1607 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] File format set failed. audioCodec:0x%x videoCodec:0x%x container:0x%x",
1608 GetErrorMessage(r), __audioCodec, __videoCodec, __videoCodec);
1610 if (reload & _RELOAD_QUALITY)
1612 r = SetQualityAttr(__quality, __audioCodec, __videoCodec);
1613 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] set quality failed. quality:%d", GetErrorMessage(r), __quality);
1615 if (reload & _RELOAD_MAX_TIME)
1617 r = SetMaxRecordingTimeAttr(__maxTime);
1618 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] camcorder set attribute failed. maxTime:%ls", GetErrorMessage(r), __maxTime);
1620 if (reload & _RELOAD_FILE_PATH)
1622 result r = E_SUCCESS;
1623 int err = MM_SUCCESS;
1624 std::unique_ptr<char[]> pFileName (Tizen::Base::_StringConverter::CopyToCharArrayN(__filePath));
1625 SysTryCatch(NID_MEDIA, pFileName.get() != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(__filePath) is used. File name is null.");
1626 SysLog(NID_MEDIA, "File Path : %s\n", pFileName.get());
1628 err = recorder_set_filename(__handle, pFileName.get());
1629 r = ConvertResult(err);
1630 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1632 if (reload & _RELOAD_INIT)
1637 if (reload & _RELOAD_CALLBACK)
1640 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set callback failed.", GetErrorMessage(r));
1642 if (reload & _RELOAD_MUTE)
1644 r = SetMuteAttr(__mute);
1645 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] video recorder set mute failed", GetErrorMessage(r));
1647 if (reload & _RELOAD_ROTATION)
1649 __pCoordinator->SetRecordingOrientation(__rotation);
1657 err = recorder_unset_state_changed_cb(__handle);
1658 err = recorder_unset_recording_limit_reached_cb(__handle);
1659 err = recorder_unset_error_cb(__handle);
1660 err = recorder_unset_interrupted_cb(__handle);
1661 __handle = MM_INVALID_HANDLE;
1668 _VideoRecorderImpl::LoadDefaultConfiguration(int reload)
1670 result r = E_SUCCESS;
1671 SysLog(NID_MEDIA, "Enter.");
1673 // Preview resolution
1674 if (reload & _RELOAD_RECORD_RESOLUTION)
1676 __recordingResolution = __pVideoSourceAdapter->GetSourceResolution();
1683 _VideoRecorderImpl::IsAlive(void)
1689 _VideoRecorderImpl::GetInstance(VideoRecorder *pVideoRecorder)
1691 if ( pVideoRecorder != null )
1693 return pVideoRecorder->__pImpl;
1698 const _VideoRecorderImpl*
1699 _VideoRecorderImpl::GetInstance(const VideoRecorder *pVideoRecorder)
1701 if ( pVideoRecorder != null )
1703 return pVideoRecorder->__pImpl;