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 the Common Recording Engine RTP convertions.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <ipvideo/CRtpUtil.h> |
|
22 #include <mmtsy_names.h> |
|
23 #include <bsp.h> |
|
24 #include "videoserviceutilsLogger.h" |
|
25 |
|
26 // CONSTANTS |
|
27 // None |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CRtpUtil::NewL() |
|
33 // |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 EXPORT_C CRtpUtil* CRtpUtil::NewL() |
|
37 { |
|
38 CRtpUtil* self = CRtpUtil::NewLC(); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CRtpUtil::NewLC() |
|
45 // |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C CRtpUtil* CRtpUtil::NewLC() |
|
49 { |
|
50 CRtpUtil* self = new ( ELeave ) CRtpUtil; |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CRtpUtil::CRtpUtil |
|
58 // C++ default constructor can NOT contain any code, that might leave. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CRtpUtil::CRtpUtil() |
|
62 { |
|
63 // None |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CRtpUtil::ConstructL |
|
68 // Symbian 2nd phase constructor can leave. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CRtpUtil::ConstructL() |
|
72 { |
|
73 // None |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // Destructor |
|
78 // |
|
79 EXPORT_C CRtpUtil::~CRtpUtil() |
|
80 // ----------------------------------------------------------------------------- |
|
81 { |
|
82 // None |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CRtpUtil::MakeBytesLC |
|
87 // Returns: Buffer of four bytes where integer is stored |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C HBufC8* CRtpUtil::MakeBytesLC( const TInt& aValue ) |
|
91 { |
|
92 HBufC8* bytes = HBufC8::NewLC( KIntegerBytes ); |
|
93 TPtr8 ptr( bytes->Des() ); |
|
94 MakeBytesL( aValue, ptr ); |
|
95 return bytes; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CRtpUtil::MakeBytes |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 EXPORT_C void CRtpUtil::MakeBytesL( const TInt& aValue, TDes8& aBuf ) |
|
103 { |
|
104 User::LeaveIfError( MakeBytes( aValue, aBuf ) ); |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CRtpUtil::MakeBytes |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 EXPORT_C TInt CRtpUtil::MakeBytes( const TInt& aValue, TDes8& aBuf ) |
|
112 { |
|
113 if ( aBuf.MaxLength() >= KIntegerBytes ) |
|
114 { |
|
115 aBuf.SetLength( KIntegerBytes ); |
|
116 aBuf[0] = ( TUint8 )( aValue >> 24 ); |
|
117 aBuf[1] = ( TUint8 )( aValue >> 16 ); |
|
118 aBuf[2] = ( TUint8 )( aValue >> 8 ); |
|
119 aBuf[3] = ( TUint8 )( aValue ); |
|
120 return KErrNone; |
|
121 } |
|
122 |
|
123 return KErrUnderflow; |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CRtpUtil::GetValueL |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 EXPORT_C TInt CRtpUtil::GetValueL( const TDesC8& aBytes ) |
|
131 { |
|
132 TInt value( KErrNotFound ); |
|
133 GetValueL( aBytes, value ); |
|
134 return value; |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CRtpUtil::GetValueL |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 EXPORT_C void CRtpUtil::GetValueL( const TDesC8& aBytes, TInt& aValue ) |
|
142 { |
|
143 User::LeaveIfError( GetValue( aBytes, aValue ) ); |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CRtpUtil::GetValue |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 EXPORT_C TInt CRtpUtil::GetValue( const TDesC8& aBytes, TInt& aValue ) |
|
151 { |
|
152 TUint value( 0 ); |
|
153 TInt err( GetValue( aBytes, value ) ); |
|
154 aValue = ( TInt )( value ); |
|
155 return err; |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CRtpUtil::GetValue |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 EXPORT_C TInt CRtpUtil::GetValue( const TDesC8& aBytes, TUint& aValue ) |
|
163 { |
|
164 if ( aBytes.Length() >= KIntegerBytes ) |
|
165 { |
|
166 aValue = ( TUint )( aBytes[0] ); |
|
167 aValue <<= 8; |
|
168 aValue |= ( TUint )( aBytes[1] ); |
|
169 aValue <<= 8; |
|
170 aValue |= ( TUint )( aBytes[2] ); |
|
171 aValue <<= 8; |
|
172 aValue |= ( TUint )( aBytes[3] ); |
|
173 return KErrNone; |
|
174 } |
|
175 |
|
176 return KErrUnderflow; |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CRtpUtil::SpecialPacketL |
|
181 // Generates new special packet. |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 EXPORT_C HBufC8* CRtpUtil::SpecialPacketL( const TInt aType ) |
|
185 { |
|
186 // Create buffer |
|
187 HBufC8* packet = HBufC8::NewLC( KSpecialPacketLength ); |
|
188 TPtr8 ptr( packet->Des() ); |
|
189 |
|
190 // Packet length (PTL) |
|
191 HBufC8* bytes = MakeBytesLC( KSpecialPacketLength ); |
|
192 ptr.Copy( bytes->Des() ); |
|
193 CleanupStack::PopAndDestroy( bytes ); |
|
194 |
|
195 // Packet type |
|
196 ptr.Append( KCharSpace ); |
|
197 ptr[KPacketTypeBytePoint] = ( TUint8 )( aType ); |
|
198 |
|
199 // Dummy payload |
|
200 bytes = MakeBytesLC( KMaxTUint ); |
|
201 ptr.Append( bytes->Des() ); |
|
202 CleanupStack::PopAndDestroy( bytes ); |
|
203 |
|
204 CleanupStack::Pop( packet ); |
|
205 return packet; |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CRtpUtil::GetMimeInfo |
|
210 // Mime type info of propriatary RTP clip. |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 EXPORT_C void CRtpUtil::GetMimeInfo( TDes& aMime ) |
|
214 { |
|
215 // Meta header has constant room as user info (IMSI) in old clips |
|
216 aMime.Copy( KRtpClipMimetype().Right( KUserIdLength ) ); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CRtpUtil::GetMimeInfo |
|
221 // Mime type info of propriatary RTP clip. |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 EXPORT_C void CRtpUtil::GetMimeInfo( TDes8& aMime ) |
|
225 { |
|
226 // Meta header has constant room as user info (IMSI) in old clips |
|
227 aMime.Copy( KRtpClipMimetype().Right( KUserIdLength ) ); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CRtpUtil::GetImeiL |
|
232 // Read IMEI on phone HW, use dummy under WINS |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 EXPORT_C void CRtpUtil::GetImeiL( TDes& aImei ) |
|
236 { |
|
237 aImei.Zero(); |
|
238 |
|
239 #if defined( __WINS__ ) || defined( __WINSCW__ ) |
|
240 _LIT( KEmulatorImei, "147407051877780445" ); |
|
241 aImei.Copy( KEmulatorImei); |
|
242 #else // __WINS__ || __WINSCW__ |
|
243 |
|
244 RTelServer server; |
|
245 CleanupClosePushL( server ); |
|
246 RMobilePhone phone; |
|
247 CleanupClosePushL( phone ); |
|
248 GetMobilePhoneInfoL( server, phone ); |
|
249 |
|
250 // Get IMEI code |
|
251 TRequestStatus status; |
|
252 RMobilePhone::TMobilePhoneIdentityV1 phoneIdentity; |
|
253 phone.GetPhoneId( status, phoneIdentity ); |
|
254 User::WaitForRequest( status ); |
|
255 if ( !status.Int() ) |
|
256 { |
|
257 TPtrC imei( phoneIdentity.iSerialNumber ); |
|
258 for ( TInt i( 0 ); i < imei.Length() && i < aImei.MaxLength(); i++ ) |
|
259 { |
|
260 if ( TChar( imei[i] ).IsDigit() ) |
|
261 { |
|
262 aImei.Append( TChar( imei[i] ) ); |
|
263 } |
|
264 } |
|
265 } |
|
266 |
|
267 CleanupStack::PopAndDestroy( &phone ); |
|
268 CleanupStack::PopAndDestroy( &server ); |
|
269 |
|
270 #endif // __WINS__ || __WINSCW__ |
|
271 } |
|
272 |
|
273 //----------------------------------------------------------------------------- |
|
274 // CRtpUtil::GetMobilePhoneInfo |
|
275 //----------------------------------------------------------------------------- |
|
276 // |
|
277 void CRtpUtil::GetMobilePhoneInfoL( |
|
278 RTelServer& aServer, |
|
279 RMobilePhone& aPhone ) |
|
280 { |
|
281 TInt numPhone( 0 ); |
|
282 RTelServer::TPhoneInfo phoneInfo; |
|
283 User::LeaveIfError( aServer.Connect() ); |
|
284 User::LeaveIfError( aServer.LoadPhoneModule( KMmTsyModuleName ) ); |
|
285 User::LeaveIfError( aServer.EnumeratePhones( numPhone ) ); |
|
286 |
|
287 TInt found( KErrNotFound ); |
|
288 TName tsyName( KNullDesC ); |
|
289 for ( TInt i( 0 ); i < numPhone && found == KErrNotFound; i++ ) |
|
290 { |
|
291 User::LeaveIfError( aServer.GetPhoneInfo( i, phoneInfo ) ); |
|
292 User::LeaveIfError( aServer.GetTsyName( i, tsyName ) ); |
|
293 if ( tsyName.CompareF( KMmTsyModuleName ) == 0 ) |
|
294 { |
|
295 found = KErrNone; |
|
296 } |
|
297 } |
|
298 |
|
299 User::LeaveIfError( found ); |
|
300 User::LeaveIfError( aPhone.Open( aServer, phoneInfo.iName ) ); |
|
301 } |
|
302 |
|
303 // End of File |
|