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 <FMediaAudioRecorder.h>
24 #include <FBaseSysLog.h>
25 #include <FSec_AccessController.h>
26 #include "FMedia_RecorderTypes.h"
27 #include "FMedia_AudioRecorderImpl.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Security;
33 namespace Tizen { namespace Media
36 AudioRecorder::AudioRecorder(void)
42 AudioRecorder::~AudioRecorder(void)
51 AudioRecorder::Construct(IAudioRecorderEventListener& listener)
53 SysAssertf(__pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
57 _AudioRecorderImpl* pImpl = new (std::nothrow) _AudioRecorderImpl();
58 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.");
60 r = pImpl->Construct(listener);
61 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
76 AudioRecorder::CreateAudioFile(const Tizen::Base::String& mediaLocalPath, bool overwrite)
78 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
81 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
82 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.");
84 r = __pImpl->CreateAudioFile(mediaLocalPath, overwrite);
85 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
91 AudioRecorder::Close(void)
93 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
96 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
97 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.");
100 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
106 AudioRecorder::Record(void)
108 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
109 result r = E_SUCCESS;
111 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
112 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.");
114 r = __pImpl->Record();
115 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
121 AudioRecorder::Stop(void)
123 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
124 result r = E_SUCCESS;
126 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
127 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.");
130 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
136 AudioRecorder::Pause(void)
138 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
139 result r = E_SUCCESS;
141 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
142 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.");
144 r = __pImpl->Pause();
145 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
151 AudioRecorder::Cancel(void)
153 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
154 result r = E_SUCCESS;
156 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
157 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.");
159 r = __pImpl->Cancel();
160 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
166 AudioRecorder::GetState(void) const
168 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
169 result r = E_SUCCESS;
170 RecorderState state = RECORDER_STATE_ERROR;
173 state = __pImpl->GetState();
175 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
180 return static_cast<RecorderState>( MEDIA_INVALID_VALUE);
185 AudioRecorder::GetRecordingTime(void) const
187 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
188 result r = E_SUCCESS;
189 long time = MEDIA_INVALID_VALUE;
192 time = __pImpl->GetRecordingTime();
194 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
199 return MEDIA_INVALID_VALUE;
203 AudioRecorder::GetRecordingSize(void) const
205 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
206 result r = E_SUCCESS;
207 long size = MEDIA_INVALID_VALUE;
210 size = __pImpl->GetRecordingSize();
212 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
217 return MEDIA_INVALID_VALUE;
221 AudioRecorder::SetMaxRecordingTime(long msTime)
223 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
224 result r = E_SUCCESS;
226 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
227 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.");
229 r = __pImpl->SetMaxRecordingTime(msTime);
230 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
236 AudioRecorder::GetMaxRecordingTime(void) const
238 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
239 result r = E_SUCCESS;
240 long time = MEDIA_INVALID_VALUE;
243 time = __pImpl->GetMaxRecordingTime();
245 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
250 return MEDIA_INVALID_VALUE;
256 AudioRecorder::SetFormat(AudioRecordingFormat format)
258 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
259 result r = E_SUCCESS;
261 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
262 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.");
264 r = __pImpl->SetFormat(format);
265 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
271 AudioRecorder::GetFormat(void) const
273 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
274 result r = E_SUCCESS;
275 AudioRecordingFormat format = AUDIORECORDING_FORMAT_AMR;
278 format = __pImpl->GetFormat();
280 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
285 return static_cast<AudioRecordingFormat>( MEDIA_INVALID_VALUE);
290 AudioRecorder::SetFormat(CodecType audioCodec, MediaContainerType container)
292 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
293 result r = E_SUCCESS;
295 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
296 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.");
298 r = __pImpl->SetFormat(audioCodec, container);
299 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
305 AudioRecorder::GetFormat(CodecType& audioCodec, MediaContainerType& container) const
307 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
308 result r = E_SUCCESS;
310 __pImpl->GetFormat(audioCodec, container);
314 Tizen::Base::Collection::IListT <CodecType>*
315 AudioRecorder::GetSupportedCodecListN(void) const
317 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
318 result r = E_SUCCESS;
319 ArrayListT <CodecType>* pDestListT = null;
322 pDestListT = __pImpl->GetSupportedCodecListN();
324 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
328 if (pDestListT != null)
330 pDestListT->RemoveAll();
337 Tizen::Base::Collection::IListT <MediaContainerType>*
338 AudioRecorder::GetSupportedContainerListN(void) const
340 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
341 result r = E_SUCCESS;
342 ArrayListT <MediaContainerType>* pDestListT = null;
345 pDestListT = __pImpl->GetSupportedContainerListN();
347 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
352 if (pDestListT != null)
354 pDestListT->RemoveAll();
362 AudioRecorder::SetQuality(RecordingQuality quality)
364 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
365 result r = E_SUCCESS;
367 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
368 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.");
370 r = __pImpl->SetQuality(quality);
371 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
377 AudioRecorder::GetQuality(void) const
379 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
380 result r = E_SUCCESS;
381 RecordingQuality quality = RECORDING_QUALITY_LOW;
384 quality = __pImpl->GetQuality();
386 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
391 return static_cast<RecordingQuality>( MEDIA_INVALID_VALUE);
396 AudioRecorder::SetMute(bool mute)
398 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
399 result r = E_SUCCESS;
401 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
402 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.");
404 r = __pImpl->SetMute(mute);
405 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
411 AudioRecorder::IsMuted(void) const
413 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
414 result r = E_SUCCESS;
418 mute = __pImpl->IsMuted();
420 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));