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 FMediaVideoRecorder.cpp
20 * @brief This is the implementation file for the %VideoRecorder class.
23 #include <FMediaVideoRecorder.h>
24 #include <FBaseSysLog.h>
25 #include <FSec_AccessController.h>
26 #include "FMedia_VideoRecorderImpl.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Security;
32 namespace Tizen { namespace Media
35 VideoRecorder::VideoRecorder(void)
41 VideoRecorder::~VideoRecorder(void)
51 VideoRecorder::Construct(IVideoRecorderEventListener& listener, const Camera& camera)
53 SysAssertf(__pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
56 _VideoRecorderImpl* pImpl = new (std::nothrow) _VideoRecorderImpl();
57 SysTryCatch(NID_MEDIA, pImpl != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
58 r = pImpl->Construct(listener, camera);
59 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
75 VideoRecorder::CreateVideoFile(const Tizen::Base::String& mediaLocalPath, bool overwrite)
77 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
80 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
81 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
83 r = __pImpl->CreateVideoFile(mediaLocalPath, overwrite);
84 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
90 VideoRecorder::Close(void)
92 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
95 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
96 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
99 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
105 VideoRecorder::Record(void)
107 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
108 result r = E_SUCCESS;
110 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
111 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
113 r = __pImpl->Record();
114 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
120 VideoRecorder::Stop(void)
122 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
123 result r = E_SUCCESS;
125 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
126 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
129 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
135 VideoRecorder::Pause(void)
137 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
138 result r = E_SUCCESS;
140 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
141 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
143 r = __pImpl->Pause();
144 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
150 VideoRecorder::Cancel(void)
152 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
153 result r = E_SUCCESS;
155 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
156 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
158 r = __pImpl->Cancel();
159 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
165 VideoRecorder::GetState(void) const
167 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
168 result r = E_SUCCESS;
169 RecorderState state = RECORDER_STATE_ERROR;
172 state = __pImpl->GetState();
174 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
179 return (RecorderState) MEDIA_INVALID_VALUE;
183 VideoRecorder::GetRecordingTime(void) const
185 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
186 result r = E_SUCCESS;
187 long time = MEDIA_INVALID_VALUE;
190 time = __pImpl->GetRecordingTime();
192 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
197 return MEDIA_INVALID_VALUE;
201 VideoRecorder::GetRecordingSize(void) const
203 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
204 result r = E_SUCCESS;
205 long size = MEDIA_INVALID_VALUE;
208 size = __pImpl->GetRecordingSize();
210 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
215 return MEDIA_INVALID_VALUE;
219 VideoRecorder::SetMaxRecordingTime(long msTime)
221 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
222 result r = E_SUCCESS;
224 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
225 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
227 r = __pImpl->SetMaxRecordingTime(msTime);
228 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
234 VideoRecorder::GetMaxRecordingTime(void) const
236 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
237 result r = E_SUCCESS;
238 long time = MEDIA_INVALID_VALUE;
241 time = __pImpl->GetMaxRecordingTime();
243 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
248 return MEDIA_INVALID_VALUE;
252 VideoRecorder::SetCodec(const Tizen::Base::String& codec)
254 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
255 result r = E_SUCCESS;
258 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
259 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
261 r = __pImpl->SetCodec(codec);
262 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
268 VideoRecorder::GetCodec(void) const
270 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
271 result r = E_SUCCESS;
275 codec = __pImpl->GetCodec();
277 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
286 Tizen::Base::Collection::IList*
287 VideoRecorder::GetSupportedCodecListN(void) const
289 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
290 result r = E_SUCCESS;
291 Tizen::Base::Collection::IList* pCodecList = null;
294 pCodecList = __pImpl->GetSupportedCodecListN();
296 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
302 if (pCodecList != null)
304 pCodecList->RemoveAll(true);
312 VideoRecorder::SetFormat(VideoRecordingFormat format)
314 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
315 result r = E_SUCCESS;
317 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
318 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
320 r = __pImpl->SetFormat(format);
321 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
327 VideoRecorder::GetFormat(void) const
329 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
330 result r = E_SUCCESS;
331 VideoRecordingFormat format = VIDEORECORDING_FORMAT_MP4;
334 format = __pImpl->GetFormat();
336 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
341 return (VideoRecordingFormat) MEDIA_INVALID_VALUE;
347 VideoRecorder::SetFormat(CodecType audioCodec, CodecType videoCodec, MediaContainerType container)
349 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
350 result r = E_SUCCESS;
352 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
353 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
355 r = __pImpl->SetFormat(audioCodec, videoCodec, container);
356 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
362 VideoRecorder::GetFormat(CodecType& audioCodec, CodecType& videoCodec, MediaContainerType& container) const
364 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
365 result r = E_SUCCESS;
367 __pImpl->GetFormat(audioCodec, videoCodec, container);
372 Tizen::Base::Collection::IListT <CodecType>*
373 VideoRecorder::GetSupportedAudioCodecListN(void) const
375 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
376 result r = E_SUCCESS;
377 ArrayListT <CodecType>* pDestList = null;
380 pDestList = __pImpl->GetSupportedAudioCodecListN();
382 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
387 if (pDestList != null)
389 pDestList->RemoveAll();
395 Tizen::Base::Collection::IListT <CodecType>*
396 VideoRecorder::GetSupportedVideoCodecListN(void) const
398 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
399 result r = E_SUCCESS;
400 ArrayListT <CodecType>* pDestList = null;
403 pDestList = __pImpl->GetSupportedVideoCodecListN();
405 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
410 if (pDestList != null)
412 pDestList->RemoveAll();
418 Tizen::Base::Collection::IListT <MediaContainerType>*
419 VideoRecorder::GetSupportedContainerListN(void) const
421 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
422 result r = E_SUCCESS;
423 ArrayListT <MediaContainerType>* pDestList = null;
426 pDestList = __pImpl->GetSupportedContainerListN();
428 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
434 if (pDestList != null)
436 pDestList->RemoveAll();
443 VideoRecorder::SetMode(VideoRecorderMode mode)
445 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
446 result r = E_SUCCESS;
448 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
449 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
451 r = __pImpl->SetMode(mode);
452 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
458 VideoRecorder::GetMode(void) const
460 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
461 result r = E_SUCCESS;
462 VideoRecorderMode mode = VIDEORECORDER_MODE_VIDEO_WITH_AUDIO;
465 mode = __pImpl->GetMode();
467 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
472 return (VideoRecorderMode) MEDIA_INVALID_VALUE;
476 VideoRecorder::SetQuality(RecordingQuality quality)
478 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
479 result r = E_SUCCESS;
481 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
482 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
484 r = __pImpl->SetQuality(quality);
485 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
491 VideoRecorder::GetQuality(void) const
493 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
494 result r = E_SUCCESS;
495 RecordingQuality quality = RECORDING_QUALITY_LOW;
498 quality = __pImpl->GetQuality();
500 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
505 return (RecordingQuality) MEDIA_INVALID_VALUE;
509 VideoRecorder::SetRecordingResolution(const Tizen::Graphics::Dimension& resolution)
511 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
512 result r = E_SUCCESS;
514 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
515 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
517 r = __pImpl->SetRecordingResolution(resolution);
518 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
523 Tizen::Graphics::Dimension
524 VideoRecorder::GetRecordingResolution(void) const
526 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
527 result r = E_SUCCESS;
528 Tizen::Graphics::Dimension dimension;
531 dimension = __pImpl->GetRecordingResolution();
533 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
538 return Tizen::Graphics::Dimension(0, 0);
541 Tizen::Base::Collection::IList*
542 VideoRecorder::GetSupportedRecordingResolutionListN(void) const
544 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
545 result r = E_SUCCESS;
546 Tizen::Base::Collection::IList* pResolutionList = null;
549 pResolutionList = __pImpl->GetSupportedRecordingResolutionListN();
551 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
553 return pResolutionList;
556 if (pResolutionList != null)
558 pResolutionList->RemoveAll(true);
559 delete pResolutionList;
565 VideoRecorder::GetSupportedMaxFrameRate(const Tizen::Graphics::Dimension& dim) const
567 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
568 result r = E_SUCCESS;
569 int maxFrameRate = MEDIA_INVALID_VALUE;
572 maxFrameRate = __pImpl->GetSupportedMaxFrameRate(dim);
574 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
580 return MEDIA_INVALID_VALUE;
584 VideoRecorder::SetMute(bool mute)
586 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
587 result r = E_SUCCESS;
589 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
590 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
592 r = __pImpl->SetMute(mute);
593 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
599 VideoRecorder::IsMuted(void) const
601 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
602 result r = E_SUCCESS;
606 mute = __pImpl->IsMuted();
608 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
617 VideoRecorder::SetRecordingRotation(RecordingRotation rotation)
619 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
620 result r = E_SUCCESS;
622 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
623 SysTryReturn(NID_MEDIA, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED]. This application does not have the privilege to call this method.");
625 r = __pImpl->SetRecordingRotation(rotation);
626 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
633 VideoRecorder::GetRecordingRotation(void) const
635 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
636 RecordingRotation roation = RECORDING_ROTATION_NONE;
638 roation = __pImpl->GetRecordingRotation();