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.
18 #include <FMediaAudioIn.h>
19 #include <FMediaAudioTypes.h>
20 #include <FBaseSysLog.h>
21 #include <FSec_AccessController.h>
22 #include "FMedia_AudioInImpl.h"
24 using namespace Tizen::Security;
26 namespace Tizen { namespace Media
30 AudioIn::AudioIn(void)
31 : __pAudioInImpl(null)
35 AudioIn::~AudioIn(void)
39 delete __pAudioInImpl;
44 AudioIn::Construct(IAudioInEventListener& listener)
49 SysAssertf(__pAudioInImpl == null, "Failed to construct an instance of AudioIn. Calling Construct() twice or more on a same instance is not allowed for this class");
51 _AudioInImpl* pAudioInImpl = new (std::nothrow) _AudioInImpl;
53 SysTryCatch(NID_MEDIA, pAudioInImpl, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY , "[E_OUT_OF_MEMORY] Memory allocation failed.");
55 r = pAudioInImpl->Construct(listener);
56 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
58 __pAudioInImpl = pAudioInImpl;
72 AudioIn::Prepare(AudioInputDevice audioInputDevice, AudioSampleType audioSampleType, AudioChannelType audioChannelType,
78 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
80 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
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 = __pAudioInImpl->Prepare(audioSampleType, audioChannelType, audioSampleRate);
84 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
89 AudioIn::Prepare(AudioSampleType audioSampleType, AudioChannelType audioChannelType, int audioSampleRate)
94 SysAssertf(__pAudioInImpl != 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.");
99 r = __pAudioInImpl->Prepare(audioSampleType, audioChannelType, audioSampleRate);
100 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
105 AudioIn::Unprepare(void)
108 result r = E_SUCCESS;
110 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
112 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
113 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.");
115 r = __pAudioInImpl->Unprepare();
116 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
121 AudioIn::AddBuffer(const Tizen::Base::ByteBuffer* pByteBuffer)
124 result r = E_SUCCESS;
126 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
127 SysTryReturn(NID_MEDIA, pByteBuffer, E_INVALID_ARG, E_INVALID_ARG, "The value of pByteBuffer is null.");
129 r = __pAudioInImpl->AddBuffer(pByteBuffer);
130 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
138 result r = E_SUCCESS;
140 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
142 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
143 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.");
145 r = __pAudioInImpl->Start();
146 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
155 result r = E_SUCCESS;
157 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
159 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
160 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.");
162 r = __pAudioInImpl->Stop();
163 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
171 result r = E_SUCCESS;
173 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
175 r = _AccessController::CheckUserPrivilege(_PRV_AUDIORECORDER);
176 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.");
178 r = __pAudioInImpl->Reset();
179 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
184 AudioIn::GetState(void) const
187 AudioInState audioState = AUDIOIN_STATE_ERROR;
189 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
191 audioState = __pAudioInImpl->GetState();
192 SysTryReturn(NID_MEDIA, audioState != AUDIOIN_STATE_ERROR , audioState, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
198 AudioIn::GetMaxBufferSize(void) const
203 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
205 bufferSize = __pAudioInImpl->GetMaxBufferSize();
206 SysTryReturn(NID_MEDIA, bufferSize != -1, bufferSize, GetLastResult(), "[%s] Progogated", GetErrorMessage(GetLastResult()));
211 AudioIn::GetMinBufferSize(void) const
216 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
218 bufferSize = __pAudioInImpl->GetMinBufferSize();
219 SysTryReturn(NID_MEDIA, bufferSize != -1, bufferSize, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
224 AudioIn::GetOptimizedSampleType(void) const
227 AudioSampleType audioSampleType = AUDIO_TYPE_NONE;
229 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
231 audioSampleType = __pAudioInImpl->GetOptimizedSampleType();
232 SysTryReturn(NID_MEDIA, audioSampleType != AUDIO_TYPE_NONE , audioSampleType, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
233 return audioSampleType;
237 AudioIn::GetOptimizedChannelType(void) const
240 AudioChannelType audioChannelType = AUDIO_CHANNEL_TYPE_NONE;
242 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
244 audioChannelType = __pAudioInImpl->GetOptimizedChannelType();
245 SysTryReturn(NID_MEDIA, audioChannelType != AUDIO_CHANNEL_TYPE_NONE , audioChannelType, GetLastResult(), " [%s] Progpogated", GetErrorMessage(GetLastResult()));
246 return audioChannelType;
250 AudioIn::GetOptimizedSampleRate(void) const
255 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
257 sampleRate = __pAudioInImpl->GetOptimizedSampleRate();
258 SysTryReturn(NID_MEDIA, sampleRate != 0, sampleRate, GetLastResult(), "[%s] Propogeated", GetErrorMessage(GetLastResult()));