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 FMediaAudioRecorder.cpp
20 * @brief This file contains the implementation of the %AudioRecorder class.
23 #include <unique_ptr.h>
24 #include <FMediaAudioRecorder.h>
25 #include <FBaseSysLog.h>
26 #include <FSec_AccessController.h>
27 #include "FMedia_RecorderTypes.h"
28 #include "FMedia_AudioRecorderImpl.h"
29 #include "FMedia_CamPtrUtil.h"
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Security;
35 namespace Tizen { namespace Media
38 AudioRecorder::AudioRecorder(void)
44 AudioRecorder::~AudioRecorder(void)
53 AudioRecorder::Construct(IAudioRecorderEventListener& listener)
55 SysAssertf(__pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
58 std::unique_ptr <_AudioRecorderImpl> pImpl (new (std::nothrow) _AudioRecorderImpl());
59 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.");
61 r = pImpl->Construct(listener);
62 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
64 __pImpl = pImpl.release();
69 AudioRecorder::CreateAudioFile(const Tizen::Base::String& mediaLocalPath, bool overwrite)
71 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
74 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
75 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.");
77 r = __pImpl->CreateAudioFile(mediaLocalPath, overwrite);
78 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
84 AudioRecorder::AddAudioStreamFilter(IAudioStreamFilter& filter)
86 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
89 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
90 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.");
92 r = __pImpl->AddAudioStreamFilter(filter);
93 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
99 AudioRecorder::RemoveAudioStreamFilter(IAudioStreamFilter& filter)
101 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
102 result r = E_SUCCESS;
104 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
105 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.");
107 r = __pImpl->RemoveAudioStreamFilter(filter);
108 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
115 AudioRecorder::Close(void)
117 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
118 result r = E_SUCCESS;
120 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
121 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.");
123 r = __pImpl->Close();
124 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
130 AudioRecorder::Record(void)
132 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
133 result r = E_SUCCESS;
135 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
136 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.");
138 r = __pImpl->Record();
139 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
145 AudioRecorder::Stop(void)
147 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
148 result r = E_SUCCESS;
150 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
151 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.");
154 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
160 AudioRecorder::Pause(void)
162 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
163 result r = E_SUCCESS;
165 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
166 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.");
168 r = __pImpl->Pause();
169 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
175 AudioRecorder::Cancel(void)
177 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
178 result r = E_SUCCESS;
180 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
181 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.");
183 r = __pImpl->Cancel();
184 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
190 AudioRecorder::GetState(void) const
192 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
193 result r = E_SUCCESS;
194 RecorderState state = RECORDER_STATE_ERROR;
197 state = __pImpl->GetState();
199 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
204 return static_cast<RecorderState>( MEDIA_INVALID_VALUE);
209 AudioRecorder::GetRecordingTime(void) const
211 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
212 result r = E_SUCCESS;
213 long time = MEDIA_INVALID_VALUE;
216 time = __pImpl->GetRecordingTime();
218 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
223 return MEDIA_INVALID_VALUE;
227 AudioRecorder::GetRecordingSize(void) const
229 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
230 result r = E_SUCCESS;
231 long size = MEDIA_INVALID_VALUE;
234 size = __pImpl->GetRecordingSize();
236 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
241 return MEDIA_INVALID_VALUE;
245 AudioRecorder::SetMaxRecordingTime(long msTime)
247 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
248 result r = E_SUCCESS;
250 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
251 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.");
253 r = __pImpl->SetMaxRecordingTime(msTime);
254 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
260 AudioRecorder::GetMaxRecordingTime(void) const
262 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
263 result r = E_SUCCESS;
264 long time = MEDIA_INVALID_VALUE;
267 time = __pImpl->GetMaxRecordingTime();
269 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
274 return MEDIA_INVALID_VALUE;
280 AudioRecorder::SetFormat(AudioRecordingFormat format)
282 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
283 result r = E_SUCCESS;
285 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
286 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.");
288 r = __pImpl->SetFormat(format);
289 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
295 AudioRecorder::GetFormat(void) const
297 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
298 result r = E_SUCCESS;
299 AudioRecordingFormat format = AUDIORECORDING_FORMAT_AMR;
302 format = __pImpl->GetFormat();
304 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
309 return static_cast<AudioRecordingFormat>( MEDIA_INVALID_VALUE);
314 AudioRecorder::SetFormat(CodecType audioCodec, MediaContainerType container)
316 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
317 result r = E_SUCCESS;
319 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
320 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.");
322 r = __pImpl->SetFormat(audioCodec, container);
323 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
329 AudioRecorder::GetFormat(CodecType& audioCodec, MediaContainerType& container) const
331 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
332 result r = E_SUCCESS;
334 __pImpl->GetFormat(audioCodec, container);
338 Tizen::Base::Collection::IListT <CodecType>*
339 AudioRecorder::GetSupportedCodecListN(void) const
341 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
342 result r = E_SUCCESS;
345 std::unique_ptr <IListT<CodecType>, _ListPtrUtil::Remover> pDestListT (__pImpl->GetSupportedCodecListN(), _ListPtrUtil::remover);
347 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
348 return pDestListT.release();
351 Tizen::Base::Collection::IListT <MediaContainerType>*
352 AudioRecorder::GetSupportedContainerListN(void) const
354 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
355 result r = E_SUCCESS;
358 std::unique_ptr <IListT<MediaContainerType>, _ListPtrUtil::Remover> pDestListT (__pImpl->GetSupportedContainerListN(), _ListPtrUtil::remover);
360 SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
361 return pDestListT.release();
365 AudioRecorder::SetQuality(RecordingQuality quality)
367 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
368 result r = E_SUCCESS;
370 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
371 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.");
373 r = __pImpl->SetQuality(quality);
374 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
380 AudioRecorder::GetQuality(void) const
382 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
383 result r = E_SUCCESS;
384 RecordingQuality quality = RECORDING_QUALITY_LOW;
387 quality = __pImpl->GetQuality();
389 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
394 return static_cast<RecordingQuality>( MEDIA_INVALID_VALUE);
399 AudioRecorder::SetMute(bool mute)
401 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
402 result r = E_SUCCESS;
404 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
405 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.");
407 r = __pImpl->SetMute(mute);
408 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
414 AudioRecorder::IsMuted(void) const
416 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
417 result r = E_SUCCESS;
421 mute = __pImpl->IsMuted();
423 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));