1 /* |
|
2 * Copyright (c) 2007 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 the License "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: Implementation of RTP file recognizer class.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CRtpClipRecognizer.h" |
|
22 #include <ecom/ImplementationProxy.h> |
|
23 #include <mmtsy_names.h> |
|
24 |
|
25 // CONSTANTS |
|
26 const TInt KIntegerBytes( 4 ); |
|
27 const TInt KStringLengthBytes( 1 ); |
|
28 const TInt KMaxMetaHeaderLength( 2048 ); |
|
29 const TInt KMetaLengthPoint( 0 ); |
|
30 const TInt KVersionFieldShift( 4 ); |
|
31 const TInt KPostRuleFieldShift( 16 ); |
|
32 const TInt KAttributesPoint( KMetaLengthPoint + KIntegerBytes ); // 4 |
|
33 const TInt KPlayCountPoint( KAttributesPoint + KIntegerBytes ); // 8 |
|
34 const TInt KPlaySpotPoint( KPlayCountPoint + KIntegerBytes ); // 12 |
|
35 const TInt KReservedPoint1( KPlaySpotPoint + KIntegerBytes ); // 16 |
|
36 const TInt KReservedPoint2( KReservedPoint1 + KIntegerBytes ); // 20 |
|
37 const TInt KReservedPoint3( KReservedPoint2 + KIntegerBytes ); // 24 |
|
38 const TInt KReservedPoint4( KReservedPoint3 + KIntegerBytes ); // 28 |
|
39 const TInt KStartTimePoint( KReservedPoint4 + KIntegerBytes ); // 32 |
|
40 const TInt KEndTimePoint( KStartTimePoint + 2 * KIntegerBytes ); // 40 |
|
41 const TInt KDurationPoint( KEndTimePoint + 2 * KIntegerBytes ); // 48 |
|
42 const TInt KSeekArrayPoint( KDurationPoint + KIntegerBytes ); // 52 |
|
43 const TInt KUserIdPoint( KSeekArrayPoint + KIntegerBytes ); // 56 |
|
44 const TInt KDeviceInfoPoint( KUserIdPoint + KStringLengthBytes + // 72 |
|
45 KUserIdLength ); |
|
46 |
|
47 const TInt KMaxRtpPostRule( 3 ); |
|
48 const TInt KMinRtpVersion( 2 ); |
|
49 const TInt KMaxRtpVersion( 8 ); |
|
50 const TInt KMaxDuration( 24 * 60 * 60 * 1000 ); |
|
51 const TInt KMaxDurationError( 60 * 1000 ); |
|
52 const TInt EContentRightsLockToDevice( 2 ); |
|
53 const TInt KSupportedMimeTypes( 1 ); |
|
54 const TInt KRtpClipRecogImplUIDValue( 0x10208446 ); |
|
55 const TUid KUidMimeRtpClipRecognizer = { 0x10208445 }; |
|
56 const TUint KNeededMetaBytes( KDeviceInfoPoint + KDeviceIdLength ); |
|
57 // Result of: TInt64( 1000 * 60 * 60 * 24 ) * TInt64( 365 * 2000 ) |
|
58 const TInt64 KSecondInMillenium( 63072000000000 ); |
|
59 _LIT8( KRtpClipMimetype, "application/x-nokia-teh-rtp" ); |
|
60 |
|
61 // ============================ MEMBER FUNCTIONS =============================== |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CRtpClipRecognizer::CreateRecognizerL |
|
65 // Static method to create instance of CRtpClipRecognizer |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CApaDataRecognizerType* CRtpClipRecognizer::CreateRecognizerL() |
|
69 { |
|
70 CApaDataRecognizerType* rtpRecogType = NULL; |
|
71 rtpRecogType = new( ELeave ) CRtpClipRecognizer(); |
|
72 return rtpRecogType; // NULL if new failed |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CRtpClipRecognizer::CRtpClipRecognizer |
|
77 // C++ default constructor can NOT contain any code, that might leave. |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CRtpClipRecognizer::CRtpClipRecognizer() |
|
81 : CApaDataRecognizerType( KUidMimeRtpClipRecognizer, |
|
82 CApaDataRecognizerType::EHigh ) |
|
83 { |
|
84 iImei.Zero(); |
|
85 iCountDataTypes = KSupportedMimeTypes; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CRtpClipRecognizer::PreferredBufSize |
|
90 // Overwritten method from CApaDataRecognizerType |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 TUint CRtpClipRecognizer::PreferredBufSize() |
|
94 { |
|
95 return KNeededMetaBytes; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CRtpClipRecognizer::SupportedDataTypeL |
|
100 // Overwritten method from CApaDataRecognizerType |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 TDataType CRtpClipRecognizer::SupportedDataTypeL( TInt aIndex ) const |
|
104 { |
|
105 __ASSERT_DEBUG( aIndex >= 0 && |
|
106 aIndex < KSupportedMimeTypes, User::Invariant() ); |
|
107 |
|
108 switch ( aIndex ) |
|
109 { |
|
110 case 0: |
|
111 { |
|
112 TDataType type( KRtpClipMimetype ); |
|
113 return type; |
|
114 } |
|
115 |
|
116 default: |
|
117 break; |
|
118 } |
|
119 |
|
120 return TDataType(); |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CRtpClipRecognizer::DoRecognizeL |
|
125 // Overwritten method from CApaDataRecognizerType |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void CRtpClipRecognizer::DoRecognizeL( |
|
129 const TDesC& /*aName*/, |
|
130 const TDesC8& aBuffer ) |
|
131 { |
|
132 iConfidence = ENotRecognized; |
|
133 iDataType = TDataType(); |
|
134 |
|
135 // Verify invest buffer length |
|
136 if ( aBuffer.Length() < KNeededMetaBytes ) |
|
137 { |
|
138 return; // Nothing to recognize |
|
139 } |
|
140 |
|
141 // Meta length |
|
142 const TInt metaLength( GetValueL( |
|
143 aBuffer.Mid( KMetaLengthPoint, KIntegerBytes ) ) ); |
|
144 if ( metaLength > KErrNotFound && metaLength < KMaxMetaHeaderLength ) |
|
145 { |
|
146 // Attributes |
|
147 TUint attr( GetValueL( |
|
148 aBuffer.Mid( KAttributesPoint, KIntegerBytes ) ) ); |
|
149 TUint8 ver( ( TUint8 )( ( attr >> KVersionFieldShift ) & 0xF ) ); |
|
150 TUint8 post( ( TUint8 )( ( attr >> KPostRuleFieldShift ) & KMaxTUint8 ) ); |
|
151 |
|
152 // Atributes valid? |
|
153 if ( post <= KMaxRtpPostRule && |
|
154 ver >= KMinRtpVersion && ver <= KMaxRtpVersion ) |
|
155 { |
|
156 // Verify mime |
|
157 TBool certain( EFalse ); |
|
158 TBuf8<KUserIdLength> info( KNullDesC8 ); |
|
159 GetMimeInfo( info ); |
|
160 const TInt len( aBuffer[KUserIdPoint] ); |
|
161 if ( len == KUserIdLength ) |
|
162 { |
|
163 TPtrC8 mime( aBuffer.Mid( KUserIdPoint + KStringLengthBytes, len ) ); |
|
164 if ( !mime.Compare( info ) ) |
|
165 { |
|
166 certain = ETrue; |
|
167 } |
|
168 else // old clip without mime in meta header |
|
169 { |
|
170 // Star time, end time, duration |
|
171 TInt64 start( GetTInt64L( |
|
172 aBuffer.Mid( KStartTimePoint, KIntegerBytes * 2 ) ) ); |
|
173 TInt64 end( GetTInt64L( |
|
174 aBuffer.Mid( KEndTimePoint, KIntegerBytes * 2 ) ) ); |
|
175 TUint dur( GetValueL( |
|
176 aBuffer.Mid( KDurationPoint, KIntegerBytes ) ) ); |
|
177 const TInt delta( TInt( ( end - start ) / 1000 ) ); |
|
178 |
|
179 if ( start > KSecondInMillenium && |
|
180 end > KSecondInMillenium && |
|
181 delta > 0 && dur < KMaxDuration && |
|
182 delta > ( ( dur > KMaxDurationError )? |
|
183 dur - KMaxDurationError: 0 ) ) |
|
184 { |
|
185 certain = ETrue; |
|
186 } |
|
187 } |
|
188 } |
|
189 |
|
190 // Verify content rights |
|
191 if ( certain && post == EContentRightsLockToDevice ) |
|
192 { |
|
193 // IMSI from the phone |
|
194 if ( !iImei.Length() ) |
|
195 { |
|
196 TBuf<KDeviceIdLength> buf; |
|
197 GetImeiL( buf ); |
|
198 iImei.Copy( buf ); |
|
199 } |
|
200 |
|
201 // Verify IMEI |
|
202 const TInt len( aBuffer[KDeviceInfoPoint] ); |
|
203 TPtrC8 imei( NULL, 0 ); |
|
204 if ( len == KDeviceIdLength ) |
|
205 { |
|
206 imei.Set( aBuffer.Mid( KDeviceInfoPoint + |
|
207 KStringLengthBytes, len ) ); |
|
208 } |
|
209 if ( len != KDeviceIdLength || imei.Compare( iImei ) ) |
|
210 { |
|
211 certain = EFalse; |
|
212 } |
|
213 } |
|
214 |
|
215 // Set confidence and mime |
|
216 if ( certain ) |
|
217 { |
|
218 iConfidence = ECertain; |
|
219 iDataType = TDataType( KRtpClipMimetype ); |
|
220 } |
|
221 } |
|
222 } |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CRtpClipRecognizer::GetValueL |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 TInt CRtpClipRecognizer::GetValueL( const TDesC8& aBytes ) |
|
230 { |
|
231 TInt value( KErrNotFound ); |
|
232 GetValueL( aBytes, value ); |
|
233 return value; |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CRtpClipRecognizer::GetValueL |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CRtpClipRecognizer::GetValueL( const TDesC8& aBytes, TInt& aValue ) |
|
241 { |
|
242 User::LeaveIfError( GetValue( aBytes, aValue ) ); |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CRtpClipRecognizer::GetValue |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 TInt CRtpClipRecognizer::GetValue( const TDesC8& aBytes, TInt& aValue ) |
|
250 { |
|
251 TUint value( 0 ); |
|
252 TInt err( GetValue( aBytes, value ) ); |
|
253 aValue = ( TInt )( value ); |
|
254 return err; |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CRtpClipRecognizer::GetValue |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 TInt CRtpClipRecognizer::GetValue( const TDesC8& aBytes, TUint& aValue ) |
|
262 { |
|
263 if ( aBytes.Length() >= KIntegerBytes ) |
|
264 { |
|
265 aValue = ( TUint )( aBytes[0] ); |
|
266 aValue <<= 8; |
|
267 aValue |= ( TUint )( aBytes[1] ); |
|
268 aValue <<= 8; |
|
269 aValue |= ( TUint )( aBytes[2] ); |
|
270 aValue <<= 8; |
|
271 aValue |= ( TUint )( aBytes[3] ); |
|
272 return KErrNone; |
|
273 } |
|
274 |
|
275 return KErrUnderflow; |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CRtpClipRecognizer::GetTInt64L |
|
280 // Reads 64 bits integer from descriptor. |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 TInt64 CRtpClipRecognizer::GetTInt64L( const TDesC8& aBytes ) |
|
284 { |
|
285 TUint low( GetValueL( aBytes.Mid( 0, KIntegerBytes ) ) ); |
|
286 TUint high( GetValueL( aBytes.Mid( KIntegerBytes, |
|
287 KIntegerBytes ) ) ); |
|
288 return TInt64( MAKE_TINT64( high, low ) ); |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CRtpClipRecognizer::GetMimeInfo |
|
293 // Mime type info of propriatary RTP clip. |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 void CRtpClipRecognizer::GetMimeInfo( TDes8& aMime ) |
|
297 { |
|
298 // Meta header has constant room as user info (IMSI) in old clips |
|
299 aMime.Copy( KRtpClipMimetype().Right( KUserIdLength ) ); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CRtpClipRecognizer::GetImeiL |
|
304 // Read IMEI on phone HW, use dummy under WINS |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 void CRtpClipRecognizer::GetImeiL( TDes& aImei ) |
|
308 { |
|
309 aImei.Zero(); |
|
310 |
|
311 #if defined( __WINS__ ) || defined( __WINSCW__ ) |
|
312 _LIT( KEmulatorImei, "147407051877780445" ); |
|
313 aImei.Copy( KEmulatorImei); |
|
314 #else // __WINS__ || __WINSCW__ |
|
315 |
|
316 RTelServer server; |
|
317 CleanupClosePushL( server ); |
|
318 RMobilePhone phone; |
|
319 CleanupClosePushL( phone ); |
|
320 GetMobilePhoneInfoL( server, phone ); |
|
321 |
|
322 // Get IMEI code |
|
323 TRequestStatus status; |
|
324 RMobilePhone::TMobilePhoneIdentityV1 phoneIdentity; |
|
325 phone.GetPhoneId( status, phoneIdentity ); |
|
326 User::WaitForRequest( status ); |
|
327 if ( !status.Int() ) |
|
328 { |
|
329 TPtrC imei( phoneIdentity.iSerialNumber ); |
|
330 for ( TInt i( 0 ); i < imei.Length() && i < aImei.MaxLength(); i++ ) |
|
331 { |
|
332 if ( TChar( imei[i] ).IsDigit() ) |
|
333 { |
|
334 aImei.Append( TChar( imei[i] ) ); |
|
335 } |
|
336 } |
|
337 } |
|
338 |
|
339 CleanupStack::PopAndDestroy( &phone ); |
|
340 CleanupStack::PopAndDestroy( &server ); |
|
341 |
|
342 #endif // __WINS__ || __WINSCW__ |
|
343 } |
|
344 |
|
345 //----------------------------------------------------------------------------- |
|
346 // CRtpClipRecognizer::GetMobilePhoneInfo |
|
347 //----------------------------------------------------------------------------- |
|
348 // |
|
349 void CRtpClipRecognizer::GetMobilePhoneInfoL( |
|
350 RTelServer& aServer, |
|
351 RMobilePhone& aPhone ) |
|
352 { |
|
353 TInt numPhone( 0 ); |
|
354 RTelServer::TPhoneInfo phoneInfo; |
|
355 User::LeaveIfError( aServer.Connect() ); |
|
356 User::LeaveIfError( aServer.LoadPhoneModule( KMmTsyModuleName ) ); |
|
357 User::LeaveIfError( aServer.EnumeratePhones( numPhone ) ); |
|
358 |
|
359 TInt found( KErrNotFound ); |
|
360 TName tsyName( KNullDesC ); |
|
361 for ( TInt i( 0 ); i < numPhone && found == KErrNotFound; i++ ) |
|
362 { |
|
363 User::LeaveIfError( aServer.GetPhoneInfo( i, phoneInfo ) ); |
|
364 User::LeaveIfError( aServer.GetTsyName( i, tsyName ) ); |
|
365 if ( tsyName.CompareF( KMmTsyModuleName ) == 0 ) |
|
366 { |
|
367 found = KErrNone; |
|
368 } |
|
369 } |
|
370 |
|
371 User::LeaveIfError( found ); |
|
372 User::LeaveIfError( aPhone.Open( aServer, phoneInfo.iName ) ); |
|
373 } |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // CRtpClipRecognizer::ImplementationTable |
|
377 // Table containing the data concerning CRtpClipRecognizer |
|
378 // ----------------------------------------------------------------------------- |
|
379 // |
|
380 const TImplementationProxy ImplementationTable[] = |
|
381 { |
|
382 IMPLEMENTATION_PROXY_ENTRY( KRtpClipRecogImplUIDValue, |
|
383 CRtpClipRecognizer::CreateRecognizerL ) |
|
384 }; |
|
385 |
|
386 // ----------------------------------------------------------------------------- |
|
387 // CRtpClipRecognizer::ImplementationGroupProxy |
|
388 // Function called by framework to return data about this recognizer |
|
389 // ----------------------------------------------------------------------------- |
|
390 // |
|
391 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount ) |
|
392 { |
|
393 aTableCount = sizeof( ImplementationTable ) / |
|
394 sizeof( TImplementationProxy ); |
|
395 |
|
396 return ImplementationTable; |
|
397 } |
|
398 |
|
399 // End of File |
|