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 <FMediaAudioOut.h>
19 #include <FMediaAudioTypes.h>
20 #include <FBaseSysLog.h>
21 #include "FMedia_AudioOutImpl.h"
24 namespace Tizen { namespace Media
27 AudioOut::AudioOut(void)
28 : __pAudioOutImpl(null)
32 AudioOut::~AudioOut(void)
36 delete __pAudioOutImpl;
42 AudioOut::Construct(IAudioOutEventListener& listener)
47 SysAssertf(__pAudioOutImpl == null, "This instance is already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
49 _AudioOutImpl* pAudioOutImpl = new (std::nothrow) _AudioOutImpl;
50 SysTryCatch(NID_MEDIA, pAudioOutImpl != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
52 r = pAudioOutImpl->Construct(this, listener);
53 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
55 __pAudioOutImpl = pAudioOutImpl;
69 AudioOut::Prepare(AudioSampleType audioSampleType, AudioChannelType audioChannelType, int audioSampleRate)
74 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
76 r = __pAudioOutImpl->Prepare(audioSampleType, audioChannelType, audioSampleRate);
77 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
83 AudioOut::Prepare(AudioStreamType audioStreamType, AudioSampleType audioSampleType, AudioChannelType audioChannelType, int audioSampleRate)
88 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
90 r = __pAudioOutImpl->Prepare(audioStreamType, audioSampleType, audioChannelType, audioSampleRate);
91 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
97 AudioOut::Unprepare(void)
100 result r = E_SUCCESS;
102 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
104 r = __pAudioOutImpl->UnPrepare();
105 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
111 AudioOut::WriteBuffer(const Tizen::Base::ByteBuffer& userData)
114 result r = E_SUCCESS;
116 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
118 r = __pAudioOutImpl->WriteBuffer(userData);
119 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
125 AudioOut::Start(void)
129 result r = E_SUCCESS;
131 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
133 r = __pAudioOutImpl->Start();
134 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
143 result r = E_SUCCESS;
145 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
147 r = __pAudioOutImpl->Stop();
148 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
154 AudioOut::Reset(void)
157 result r = E_SUCCESS;
159 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
161 r = __pAudioOutImpl->Reset();
162 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
168 AudioOut::GetState(void) const
171 AudioOutState audioState = AUDIOOUT_STATE_ERROR;
173 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
175 audioState = __pAudioOutImpl->GetState();
176 SysTryReturn(NID_MEDIA, audioState != AUDIOOUT_STATE_ERROR, AUDIOOUT_STATE_ERROR, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
182 AudioOut::GetMaxBufferSize(void) const
187 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
189 bufferSize = __pAudioOutImpl->GetMaxBufferSize();
190 SysTryReturn(NID_MEDIA, bufferSize != -1, bufferSize, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
196 AudioOut::GetMinBufferSize(void) const
201 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
203 bufferSize = __pAudioOutImpl->GetMinBufferSize();
204 SysTryReturn(NID_MEDIA, bufferSize != -1, bufferSize, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
209 AudioOut::GetOptimizedSampleType(void) const
212 AudioSampleType audioSampleType = AUDIO_TYPE_NONE;
214 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
216 audioSampleType = __pAudioOutImpl->GetOptimizedSampleType();
217 SysTryReturn(NID_MEDIA, audioSampleType != AUDIO_TYPE_NONE, AUDIO_TYPE_NONE, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
218 return audioSampleType;
222 AudioOut::GetOptimizedChannelType(void) const
225 AudioChannelType audioChannelType = AUDIO_CHANNEL_TYPE_NONE;
227 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
229 audioChannelType = __pAudioOutImpl->GetOptimizedChannelType();
230 SysTryReturn(NID_MEDIA, audioChannelType != AUDIO_CHANNEL_TYPE_NONE, AUDIO_CHANNEL_TYPE_NONE, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
231 return audioChannelType;
235 AudioOut::GetOptimizedSampleRate(void) const
240 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
242 sampleRate = __pAudioOutImpl->GetOptimizedSampleRate();
243 SysTryReturn(NID_MEDIA, sampleRate != 0, 0, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
249 AudioOut::SetVolume(int volume)
252 result r = E_SUCCESS;
254 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
255 SysTryReturn(NID_MEDIA, (volume <= 100) && (volume >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
256 "[E_OUT_OF_RANGE] volume is out of range. The value of volume should be between 0 and 100");
258 r = __pAudioOutImpl->SetVolume(volume);
259 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
266 AudioOut::GetVolume(void) const
271 SysAssertf(__pAudioOutImpl != null, "Not yet constructed! Construct() should be called before use");
273 volume = __pAudioOutImpl->GetVolume();
274 SysTryReturn(NID_MEDIA, volume != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));