Merge "seek expection handling bug" into tizen_2.2
[platform/framework/native/media.git] / src / FMediaAudioIn.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include <FMediaAudioIn.h>
19 #include <FMediaAudioTypes.h>
20 #include <FBaseSysLog.h>
21 #include "FMedia_AudioInImpl.h"
22
23
24 namespace Tizen { namespace Media
25 {
26
27
28 AudioIn::AudioIn(void)
29         : __pAudioInImpl(null)
30 {
31 }
32
33 AudioIn::~AudioIn(void)
34 {
35         if (__pAudioInImpl)
36         {
37                 delete __pAudioInImpl;
38         }
39 }
40
41 result
42 AudioIn::Construct(IAudioInEventListener& listener)
43 {
44         ClearLastResult();
45         result r = E_SUCCESS;
46
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");
48
49         _AudioInImpl* pAudioInImpl = new (std::nothrow) _AudioInImpl;
50
51         SysTryCatch(NID_MEDIA, pAudioInImpl, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY , "[E_OUT_OF_MEMORY] Memory allocation failed.");
52
53         r = pAudioInImpl->Construct(listener);
54         SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
55
56         __pAudioInImpl = pAudioInImpl;
57
58         return r;
59
60 CATCH:
61         if (pAudioInImpl)
62         {
63                 delete pAudioInImpl;
64                 pAudioInImpl = null;
65         }
66         return r;
67 }
68
69 result
70 AudioIn::Prepare(AudioInputDevice audioInputDevice, AudioSampleType audioSampleType, AudioChannelType audioChannelType,
71                                  int audioSampleRate)
72 {
73         ClearLastResult();
74         result r = E_SUCCESS;
75
76         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
77
78         r = __pAudioInImpl->Prepare(audioSampleType, audioChannelType, audioSampleRate);
79         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
80         return r;
81 }
82
83 result
84 AudioIn::Prepare(AudioSampleType audioSampleType, AudioChannelType audioChannelType, int audioSampleRate)
85 {
86         ClearLastResult();
87         result r = E_SUCCESS;
88
89         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
90
91         r = __pAudioInImpl->Prepare(audioSampleType, audioChannelType, audioSampleRate);
92         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
93         return r;
94 }
95
96 result
97 AudioIn::Unprepare(void)
98 {
99         ClearLastResult();
100         result r = E_SUCCESS;
101
102         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
103
104         r = __pAudioInImpl->Unprepare();
105         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
106         return r;
107 }
108
109 result
110 AudioIn::AddBuffer(const Tizen::Base::ByteBuffer* pByteBuffer)
111 {
112         ClearLastResult();
113         result r = E_SUCCESS;
114
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.");
117
118         r = __pAudioInImpl->AddBuffer(pByteBuffer);
119         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
120         return r;
121 }
122
123 result
124 AudioIn::Start(void)
125 {
126         ClearLastResult();
127         result r = E_SUCCESS;
128
129         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
130
131         r = __pAudioInImpl->Start();
132         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
133
134         return r;
135 }
136
137 result
138 AudioIn::Stop(void)
139 {
140         ClearLastResult();
141         result r = E_SUCCESS;
142
143         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
144
145         r = __pAudioInImpl->Stop();
146         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
147         return r;
148 }
149
150 result
151 AudioIn::Reset(void)
152 {
153         ClearLastResult();
154         result r = E_SUCCESS;
155
156         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
157
158         r = __pAudioInImpl->Reset();
159         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
160         return r;
161 }
162
163 AudioInState
164 AudioIn::GetState(void) const
165 {
166         ClearLastResult();
167         AudioInState audioState = AUDIOIN_STATE_ERROR;
168
169         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
170
171         audioState = __pAudioInImpl->GetState();
172         SysTryReturn(NID_MEDIA, audioState != AUDIOIN_STATE_ERROR , audioState, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
173         return audioState;
174
175 }
176
177 int
178 AudioIn::GetMaxBufferSize(void) const
179 {
180         ClearLastResult();
181         int bufferSize = -1;
182
183         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
184
185         bufferSize = __pAudioInImpl->GetMaxBufferSize();
186         SysTryReturn(NID_MEDIA, bufferSize != -1, bufferSize, GetLastResult(), "[%s] Progogated", GetErrorMessage(GetLastResult()));
187         return bufferSize;
188 }
189
190 int
191 AudioIn::GetMinBufferSize(void) const
192 {
193         ClearLastResult();
194         int bufferSize = -1;
195
196         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
197
198         bufferSize = __pAudioInImpl->GetMinBufferSize();
199         SysTryReturn(NID_MEDIA,  bufferSize != -1, bufferSize, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
200         return bufferSize;
201 }
202
203 AudioSampleType
204 AudioIn::GetOptimizedSampleType(void) const
205 {
206         ClearLastResult();
207         AudioSampleType audioSampleType = AUDIO_TYPE_NONE;
208
209         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
210
211         audioSampleType = __pAudioInImpl->GetOptimizedSampleType();
212         SysTryReturn(NID_MEDIA, audioSampleType != AUDIO_TYPE_NONE , audioSampleType, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
213         return audioSampleType;
214 }
215
216 AudioChannelType
217 AudioIn::GetOptimizedChannelType(void) const
218 {
219         ClearLastResult();
220         AudioChannelType audioChannelType = AUDIO_CHANNEL_TYPE_NONE;
221
222         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
223
224         audioChannelType = __pAudioInImpl->GetOptimizedChannelType();
225         SysTryReturn(NID_MEDIA, audioChannelType != AUDIO_CHANNEL_TYPE_NONE , audioChannelType, GetLastResult(), " [%s] Progpogated", GetErrorMessage(GetLastResult()));
226         return audioChannelType;
227 }
228
229 int
230 AudioIn::GetOptimizedSampleRate(void) const
231 {
232         ClearLastResult();
233         int sampleRate = 0;
234
235         SysAssertf(__pAudioInImpl !=  null, "Not yet constructed! Construct() should be called before use");
236
237         sampleRate = __pAudioInImpl->GetOptimizedSampleRate();
238         SysTryReturn(NID_MEDIA, sampleRate != 0, sampleRate, GetLastResult(), "[%s] Propogeated", GetErrorMessage(GetLastResult()));
239         return sampleRate;
240 }
241
242
243 }} // Tizen::Media