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"
27 #include "FMedia_CamPtrUtil.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Security;
33 namespace Tizen { namespace Media
36 VideoRecorder::VideoRecorder(void)
42 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 std::unique_ptr <_VideoRecorderImpl> pImpl (new (std::nothrow) _VideoRecorderImpl());
57 SysTryReturn(NID_MEDIA, pImpl.get() != null, 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 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
61 __pImpl = pImpl.release();
66 VideoRecorder::CreateVideoFile(const Tizen::Base::String& mediaLocalPath, bool overwrite)
68 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
71 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
72 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.");
74 r = __pImpl->CreateVideoFile(mediaLocalPath, overwrite);
75 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
81 VideoRecorder::AddAudioStreamFilter(IAudioStreamFilter& filter)
83 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
86 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
87 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.");
89 r = __pImpl->AddAudioStreamFilter(filter);
90 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
96 VideoRecorder::RemoveAudioStreamFilter(IAudioStreamFilter& filter)
98 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
101 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
102 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.");
104 r = __pImpl->RemoveAudioStreamFilter(filter);
105 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
111 VideoRecorder::Close(void)
113 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
114 result r = E_SUCCESS;
116 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
117 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.");
119 r = __pImpl->Close();
120 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
126 VideoRecorder::Record(void)
128 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
129 result r = E_SUCCESS;
131 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
132 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.");
134 r = __pImpl->Record();
135 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
141 VideoRecorder::Stop(void)
143 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
144 result r = E_SUCCESS;
146 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
147 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.");
150 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
156 VideoRecorder::Pause(void)
158 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
159 result r = E_SUCCESS;
161 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
162 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.");
164 r = __pImpl->Pause();
165 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
171 VideoRecorder::Cancel(void)
173 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
174 result r = E_SUCCESS;
176 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
177 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.");
179 r = __pImpl->Cancel();
180 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
186 VideoRecorder::GetState(void) const
188 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
189 result r = E_SUCCESS;
190 RecorderState state = RECORDER_STATE_ERROR;
193 state = __pImpl->GetState();
195 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
200 return (RecorderState) MEDIA_INVALID_VALUE;
204 VideoRecorder::GetRecordingTime(void) const
206 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
207 result r = E_SUCCESS;
208 long time = MEDIA_INVALID_VALUE;
211 time = __pImpl->GetRecordingTime();
213 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
218 return MEDIA_INVALID_VALUE;
222 VideoRecorder::GetRecordingSize(void) const
224 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
225 result r = E_SUCCESS;
226 long size = MEDIA_INVALID_VALUE;
229 size = __pImpl->GetRecordingSize();
231 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
236 return MEDIA_INVALID_VALUE;
240 VideoRecorder::SetMaxRecordingTime(long msTime)
242 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
243 result r = E_SUCCESS;
245 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
246 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.");
248 r = __pImpl->SetMaxRecordingTime(msTime);
249 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
255 VideoRecorder::GetMaxRecordingTime(void) const
257 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
258 result r = E_SUCCESS;
259 long time = MEDIA_INVALID_VALUE;
262 time = __pImpl->GetMaxRecordingTime();
264 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
269 return MEDIA_INVALID_VALUE;
273 VideoRecorder::SetCodec(const Tizen::Base::String& codec)
275 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
276 result r = E_SUCCESS;
279 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
280 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.");
282 r = __pImpl->SetCodec(codec);
283 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
289 VideoRecorder::GetCodec(void) const
291 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
292 result r = E_SUCCESS;
296 codec = __pImpl->GetCodec();
298 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
307 Tizen::Base::Collection::IList*
308 VideoRecorder::GetSupportedCodecListN(void) const
310 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
311 result r = E_SUCCESS;
314 std::unique_ptr <IList, _ListPtrUtil::Remover> pCodecList (__pImpl->GetSupportedCodecListN(), _ListPtrUtil::remover);
315 SysTryReturn(NID_MEDIA, pCodecList.get() != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
317 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
319 return pCodecList.release();
323 VideoRecorder::SetFormat(VideoRecordingFormat format)
325 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
326 result r = E_SUCCESS;
328 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
329 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.");
331 r = __pImpl->SetFormat(format);
332 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
338 VideoRecorder::GetFormat(void) const
340 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
341 result r = E_SUCCESS;
342 VideoRecordingFormat format = VIDEORECORDING_FORMAT_MP4;
345 format = __pImpl->GetFormat();
347 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
352 return (VideoRecordingFormat) MEDIA_INVALID_VALUE;
358 VideoRecorder::SetFormat(CodecType audioCodec, CodecType videoCodec, MediaContainerType container)
360 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
361 result r = E_SUCCESS;
363 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
364 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.");
366 r = __pImpl->SetFormat(audioCodec, videoCodec, container);
367 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
373 VideoRecorder::GetFormat(CodecType& audioCodec, CodecType& videoCodec, MediaContainerType& container) const
375 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
376 result r = E_SUCCESS;
378 __pImpl->GetFormat(audioCodec, videoCodec, container);
383 Tizen::Base::Collection::IListT <CodecType>*
384 VideoRecorder::GetSupportedAudioCodecListN(void) const
386 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
387 result r = E_SUCCESS;
390 std::unique_ptr <IListT<CodecType>, _ListPtrUtil::Remover> pDestList (__pImpl->GetSupportedAudioCodecListN());
392 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
394 return pDestList.release();
397 Tizen::Base::Collection::IListT <CodecType>*
398 VideoRecorder::GetSupportedVideoCodecListN(void) const
400 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
401 result r = E_SUCCESS;
404 std::unique_ptr <IListT<CodecType>, _ListPtrUtil::Remover> pDestList (__pImpl->GetSupportedVideoCodecListN());
406 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
408 return pDestList.release();
411 Tizen::Base::Collection::IListT <MediaContainerType>*
412 VideoRecorder::GetSupportedContainerListN(void) const
414 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
415 result r = E_SUCCESS;
418 std::unique_ptr <IListT<MediaContainerType>, _ListPtrUtil::Remover> pDestList (__pImpl->GetSupportedContainerListN());
420 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
422 return pDestList.release();
426 VideoRecorder::SetMode(VideoRecorderMode mode)
428 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
429 result r = E_SUCCESS;
431 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
432 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.");
434 r = __pImpl->SetMode(mode);
435 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
441 VideoRecorder::GetMode(void) const
443 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
444 result r = E_SUCCESS;
445 VideoRecorderMode mode = VIDEORECORDER_MODE_VIDEO_WITH_AUDIO;
448 mode = __pImpl->GetMode();
450 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
455 return (VideoRecorderMode) MEDIA_INVALID_VALUE;
459 VideoRecorder::SetQuality(RecordingQuality quality)
461 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
462 result r = E_SUCCESS;
464 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
465 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.");
467 r = __pImpl->SetQuality(quality);
468 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
474 VideoRecorder::GetQuality(void) const
476 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
477 result r = E_SUCCESS;
478 RecordingQuality quality = RECORDING_QUALITY_LOW;
481 quality = __pImpl->GetQuality();
483 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
488 return (RecordingQuality) MEDIA_INVALID_VALUE;
492 VideoRecorder::SetRecordingResolution(const Tizen::Graphics::Dimension& resolution)
494 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
495 result r = E_SUCCESS;
497 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
498 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.");
500 r = __pImpl->SetRecordingResolution(resolution);
501 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
506 Tizen::Graphics::Dimension
507 VideoRecorder::GetRecordingResolution(void) const
509 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
510 result r = E_SUCCESS;
511 Tizen::Graphics::Dimension dimension;
514 dimension = __pImpl->GetRecordingResolution();
516 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
521 return Tizen::Graphics::Dimension(0, 0);
524 Tizen::Base::Collection::IList*
525 VideoRecorder::GetSupportedRecordingResolutionListN(void) const
527 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
528 result r = E_SUCCESS;
531 std::unique_ptr <IList, _ListPtrUtil::Remover> pResolutionList (__pImpl->GetSupportedRecordingResolutionListN(), _ListPtrUtil::remover);
533 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
535 return pResolutionList.release();
539 VideoRecorder::GetSupportedMaxFrameRate(const Tizen::Graphics::Dimension& dim) const
541 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
542 result r = E_SUCCESS;
543 int maxFrameRate = MEDIA_INVALID_VALUE;
546 maxFrameRate = __pImpl->GetSupportedMaxFrameRate(dim);
548 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
554 return MEDIA_INVALID_VALUE;
558 VideoRecorder::SetMute(bool mute)
560 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
561 result r = E_SUCCESS;
563 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
564 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.");
566 r = __pImpl->SetMute(mute);
567 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
573 VideoRecorder::IsMuted(void) const
575 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
576 result r = E_SUCCESS;
580 mute = __pImpl->IsMuted();
582 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
591 VideoRecorder::SetRecordingRotation(RecordingRotation rotation)
593 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
594 result r = E_SUCCESS;
596 r = _AccessController::CheckUserPrivilege(_PRV_VIDEORECORDER);
597 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.");
599 r = __pImpl->SetRecordingRotation(rotation);
600 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
607 VideoRecorder::GetRecordingRotation(void) const
609 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
610 RecordingRotation roation = RECORDING_ROTATION_NONE;
612 roation = __pImpl->GetRecordingRotation();