|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: S60 Audio Stream Source implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "S60AudioClientStreamSource.h" |
|
20 #include "S60SourceEventDispatcher.h" |
|
21 #include "WriteRequest.h" |
|
22 |
|
23 // CONSTANTS |
|
24 const TInt KMinBufferSize = 5120; |
|
25 _LIT8(KAMRMimetype,"audio/amr"); |
|
26 _LIT8(KAMRWBMimetype,"audio/amr-wb"); |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CS60AudioStreamSource::~CS60AudioStreamSource |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CS60AudioStreamSource::~CS60AudioStreamSource() |
|
33 { |
|
34 #ifdef _DEBUG |
|
35 RDebug::Print(_L("CS60AudioStreamSource::~CS60AudioStreamSource [%x]"),iDispatcher); |
|
36 #endif |
|
37 |
|
38 delete iDispatcher; |
|
39 iDispatcher = NULL; |
|
40 delete iMimeType; |
|
41 iMimeType = NULL; |
|
42 iControllers.Close(); |
|
43 iWriteRequests.ResetAndDestroy(); |
|
44 |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CS60AudioStreamSource::CS60AudioStreamSource |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CS60AudioStreamSource::CS60AudioStreamSource() |
|
52 { |
|
53 #ifdef _DEBUG |
|
54 RDebug::Print(_L("CS60AudioStreamSource::CS60AudioStreamSource")); |
|
55 #endif |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CS60AudioStreamSource::NewL |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 EXPORT_C CS60AudioStreamSource* CS60AudioStreamSource::NewL( |
|
63 MS60AudioStreamSourceObserver& aObserver, |
|
64 const TDesC8& aMimeType ) |
|
65 { |
|
66 |
|
67 #ifdef _DEBUG |
|
68 RDebug::Print(_L("CS60AudioStreamSource::NewL")); |
|
69 #endif |
|
70 |
|
71 CS60AudioStreamSource* self = new(ELeave) CS60AudioStreamSource(); |
|
72 CleanupStack::PushL(self); |
|
73 self->ConstructL(aObserver, aMimeType); |
|
74 CleanupStack::Pop(self); |
|
75 return self; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CS60AudioStreamSource::ConstructL |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void CS60AudioStreamSource::ConstructL( |
|
83 MS60AudioStreamSourceObserver& aObserver, |
|
84 const TDesC8& aMimeType ) |
|
85 { |
|
86 #ifdef _DEBUG |
|
87 RDebug::Print(_L("CS60AudioStreamSource::ConstructL ")); |
|
88 #endif |
|
89 TInt err = KErrNone; |
|
90 |
|
91 iDispatcher = CS60SourceEventDispatcher::NewL(aObserver); |
|
92 |
|
93 |
|
94 if(!aMimeType.Compare(KAMRMimetype) || !aMimeType.Compare(KAMRWBMimetype)) |
|
95 iMimeType = aMimeType.Alloc(); |
|
96 else |
|
97 User::Leave(KErrNotSupported); |
|
98 //TRAP(err, FindControllersL()); |
|
99 User::LeaveIfError(err); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CS60AudioStreamSource::FindControllersL |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CS60AudioStreamSource::FindControllersL() |
|
107 { |
|
108 #if _DEBUG |
|
109 RDebug::Print(_L("CS60AudioStreamSource::FindControllersL")); |
|
110 #endif |
|
111 // Retrieve a list of possible controllers from ECOM |
|
112 // If we don't have a match, leave with unsupported |
|
113 |
|
114 iControllers.ResetAndDestroy(); |
|
115 |
|
116 CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewLC(); |
|
117 CMMFFormatSelectionParameters* fSelect = CMMFFormatSelectionParameters::NewLC(); |
|
118 |
|
119 RArray<TUid> mediaIds; |
|
120 CleanupClosePushL(mediaIds); |
|
121 |
|
122 |
|
123 User::LeaveIfError(mediaIds.Append(KUidMediaTypeAudio)); |
|
124 |
|
125 cSelect->SetMediaIdsL(mediaIds, CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds); |
|
126 |
|
127 |
|
128 if (*iMimeType != KNullDesC8) |
|
129 { |
|
130 fSelect->SetMatchToMimeTypeL(*iMimeType);//We match to mime type |
|
131 } |
|
132 else |
|
133 { |
|
134 User::Leave(KErrNotSupported); |
|
135 } |
|
136 |
|
137 cSelect->SetRequiredPlayFormatSupportL(*fSelect); |
|
138 |
|
139 __UHEAP_MARK; |
|
140 RMMFControllerImplInfoArray siControllers; |
|
141 CleanupClosePushL(siControllers); |
|
142 |
|
143 cSelect->ListImplementationsL(siControllers); |
|
144 |
|
145 if ( siControllers.Count() == 0 ) |
|
146 { |
|
147 User::Leave(KErrNotSupported); |
|
148 } |
|
149 siControllers.ResetAndDestroy(); |
|
150 CleanupStack::PopAndDestroy(); |
|
151 __UHEAP_MARKEND; |
|
152 |
|
153 CleanupStack::PopAndDestroy(); |
|
154 CleanupStack::PopAndDestroy(fSelect); |
|
155 CleanupStack::PopAndDestroy(cSelect); |
|
156 } |
|
157 |
|
158 |
|
159 EXPORT_C TInt CS60AudioStreamSource::WriteAudioData( |
|
160 CClientAudioBuffer& aBuffer ) |
|
161 { |
|
162 #ifdef _DEBUG |
|
163 RDebug::Print(_L("CS60AudioStreamSource::WriteAudioData")); |
|
164 #endif |
|
165 |
|
166 TInt index; |
|
167 |
|
168 if ( GetFreeRequestSlot(index) ) |
|
169 { |
|
170 iWriteRequests[index]->WriteAudioData(aBuffer); |
|
171 } |
|
172 else |
|
173 { |
|
174 CWriteRequest* request = CWriteRequest::NewL(iSourceHandle, iController, *iDispatcher); |
|
175 iWriteRequests.Append(request); |
|
176 request->WriteAudioData(aBuffer); |
|
177 } |
|
178 |
|
179 return KErrNone; |
|
180 } |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CS60AudioStreamSource::NextAudioBuffer |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 TBool CS60AudioStreamSource::GetFreeRequestSlot(TInt& index) |
|
186 { |
|
187 #ifdef _DEBUG |
|
188 RDebug::Print(_L("CS60AudioStreamSource::NextAudioBuffer")); |
|
189 #endif |
|
190 |
|
191 for ( TInt i=0; i < iWriteRequests.Count(); i++) |
|
192 { |
|
193 if ( iWriteRequests[i]->IsFree() ) |
|
194 { |
|
195 index = i; |
|
196 return ETrue; |
|
197 } |
|
198 } |
|
199 |
|
200 return EFalse; |
|
201 } |
|
202 |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CS60AudioStreamSource::SetSize |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 EXPORT_C TInt CS60AudioStreamSource::SetSize( |
|
209 TUint aSize) |
|
210 { |
|
211 #ifdef _DEBUG |
|
212 RDebug::Print(_L("CS60AudioStreamSource::SetSize")); |
|
213 #endif |
|
214 iSize = aSize; |
|
215 return KErrNone; |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CS60AudioStreamSource::MinimumBufferSize |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 EXPORT_C TInt CS60AudioStreamSource::GetMinimumBufferSize() |
|
223 { |
|
224 #ifdef _DEBUG |
|
225 RDebug::Print(_L("CS60AudioStreamSource::MinimumBufferSize")); |
|
226 #endif |
|
227 return KMinBufferSize; |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CS60AudioStreamSource::GetMimeTypeL |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 EXPORT_C void CS60AudioStreamSource::GetMimeType(TDes8& aMimeType) |
|
235 { |
|
236 #ifdef _DEBUG |
|
237 RDebug::Print(_L("CS60AudioStreamSource::GetMimeType")); |
|
238 #endif |
|
239 aMimeType.Copy(*iMimeType); |
|
240 } |
|
241 |
|
242 EXPORT_C TUint CS60AudioStreamSource::GetSize() |
|
243 { |
|
244 #ifdef _DEBUG |
|
245 RDebug::Print(_L("CS60AudioStreamSource::GetSize")); |
|
246 #endif |
|
247 return iSize; |
|
248 } |
|
249 |
|
250 EXPORT_C TInt64 CS60AudioStreamSource::GetPosition() |
|
251 { |
|
252 #ifdef _DEBUG |
|
253 RDebug::Print(_L("CS60AudioStreamSource::GetPosition")); |
|
254 #endif |
|
255 return iPosition; |
|
256 } |
|
257 |
|
258 EXPORT_C TInt CS60AudioStreamSource::SetPosition( |
|
259 TInt64 aPosition) |
|
260 { |
|
261 #ifdef _DEBUG |
|
262 RDebug::Print(_L("CS60AudioStreamSource::SetPosition")); |
|
263 #endif |
|
264 iPosition = aPosition; |
|
265 return KErrNone; |
|
266 } |
|
267 |
|
268 TBool CS60AudioStreamSource::IsSeekingSupported() |
|
269 { |
|
270 #ifdef _DEBUG |
|
271 RDebug::Print(_L("CS60AudioStreamSource::IsSeekingSupported")); |
|
272 #endif |
|
273 return EFalse; |
|
274 } |
|
275 |
|
276 TBool CS60AudioStreamSource::IsRandomSeekingSupported() |
|
277 { |
|
278 #ifdef _DEBUG |
|
279 RDebug::Print(_L("CS60AudioStreamSource::IsRandomSeekingSupported")); |
|
280 #endif |
|
281 return EFalse; |
|
282 } |