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 "FMedia_AudioInImpl.h"
24 namespace Tizen { namespace Media
28 AudioIn::AudioIn(void)
29 : __pAudioInImpl(null)
33 AudioIn::~AudioIn(void)
37 delete __pAudioInImpl;
42 AudioIn::Construct(IAudioInEventListener& listener)
47 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");
49 _AudioInImpl* pAudioInImpl = new (std::nothrow) _AudioInImpl;
51 SysTryCatch(NID_MEDIA, pAudioInImpl, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY , "[E_OUT_OF_MEMORY] Memory allocation failed.");
53 r = pAudioInImpl->Construct(listener);
54 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
56 __pAudioInImpl = pAudioInImpl;
70 AudioIn::Prepare(AudioInputDevice audioInputDevice, AudioSampleType audioSampleType, AudioChannelType audioChannelType,
76 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
78 r = __pAudioInImpl->Prepare(audioSampleType, audioChannelType, audioSampleRate);
79 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
84 AudioIn::Prepare(AudioSampleType audioSampleType, AudioChannelType audioChannelType, int audioSampleRate)
89 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
91 r = __pAudioInImpl->Prepare(audioSampleType, audioChannelType, audioSampleRate);
92 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
97 AudioIn::Unprepare(void)
100 result r = E_SUCCESS;
102 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
104 r = __pAudioInImpl->Unprepare();
105 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
110 AudioIn::AddBuffer(const Tizen::Base::ByteBuffer* pByteBuffer)
113 result r = E_SUCCESS;
115 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
116 SysTryReturn(NID_MEDIA, pByteBuffer, E_INVALID_ARG, E_INVALID_ARG, "The value of pByteBuffer is null.");
118 r = __pAudioInImpl->AddBuffer(pByteBuffer);
119 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
127 result r = E_SUCCESS;
129 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
131 r = __pAudioInImpl->Start();
132 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
141 result r = E_SUCCESS;
143 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
145 r = __pAudioInImpl->Stop();
146 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
154 result r = E_SUCCESS;
156 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
158 r = __pAudioInImpl->Reset();
159 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
164 AudioIn::GetState(void) const
167 AudioInState audioState = AUDIOIN_STATE_ERROR;
169 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
171 audioState = __pAudioInImpl->GetState();
172 SysTryReturn(NID_MEDIA, audioState != AUDIOIN_STATE_ERROR , audioState, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
178 AudioIn::GetMaxBufferSize(void) const
183 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
185 bufferSize = __pAudioInImpl->GetMaxBufferSize();
186 SysTryReturn(NID_MEDIA, bufferSize != -1, bufferSize, GetLastResult(), "[%s] Progogated", GetErrorMessage(GetLastResult()));
191 AudioIn::GetMinBufferSize(void) const
196 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
198 bufferSize = __pAudioInImpl->GetMinBufferSize();
199 SysTryReturn(NID_MEDIA, bufferSize != -1, bufferSize, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
204 AudioIn::GetOptimizedSampleType(void) const
207 AudioSampleType audioSampleType = AUDIO_TYPE_NONE;
209 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
211 audioSampleType = __pAudioInImpl->GetOptimizedSampleType();
212 SysTryReturn(NID_MEDIA, audioSampleType != AUDIO_TYPE_NONE , audioSampleType, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
213 return audioSampleType;
217 AudioIn::GetOptimizedChannelType(void) const
220 AudioChannelType audioChannelType = AUDIO_CHANNEL_TYPE_NONE;
222 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
224 audioChannelType = __pAudioInImpl->GetOptimizedChannelType();
225 SysTryReturn(NID_MEDIA, audioChannelType != AUDIO_CHANNEL_TYPE_NONE , audioChannelType, GetLastResult(), " [%s] Progpogated", GetErrorMessage(GetLastResult()));
226 return audioChannelType;
230 AudioIn::GetOptimizedSampleRate(void) const
235 SysAssertf(__pAudioInImpl != null, "Not yet constructed! Construct() should be called before use");
237 sampleRate = __pAudioInImpl->GetOptimizedSampleRate();
238 SysTryReturn(NID_MEDIA, sampleRate != 0, sampleRate, GetLastResult(), "[%s] Propogeated", GetErrorMessage(GetLastResult()));