|
1 /* |
|
2 * Copyright (c) 2006 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #ifndef CMCEMEDIASDPCODEC_H |
|
23 #define CMCEMEDIASDPCODEC_H |
|
24 |
|
25 // INCLUDES |
|
26 #include "mcesdpcodec.h" |
|
27 #include "mcecomcodec.h" |
|
28 |
|
29 const TInt KMceMaxPTValue = 127; |
|
30 const TInt KMceMaxPayloadTypes = 20; |
|
31 |
|
32 const TBool KMceMediaCodecUpdate = ETrue; |
|
33 const TBool KMceMediaCodecNoUpdate = EFalse; |
|
34 |
|
35 /** |
|
36 * Class for encoding and decoding media lines and creating server streams |
|
37 * |
|
38 */ |
|
39 class CMceMediaSdpCodec : public CMceSdpCodec |
|
40 { |
|
41 |
|
42 public: |
|
43 |
|
44 /** |
|
45 * destructor |
|
46 */ |
|
47 ~CMceMediaSdpCodec(); |
|
48 |
|
49 public: //from CMceSdpCodec |
|
50 |
|
51 |
|
52 /** |
|
53 * Encodes a media line. |
|
54 * @param aStream media stream |
|
55 * @param aMediaLine media line |
|
56 * @param aSdpDocument sdp document |
|
57 * @leave system wide error |
|
58 */ |
|
59 void EncodeMediaOfferL( CMceComMediaStream& aStream, |
|
60 CSdpMediaField& aMediaLine, |
|
61 CSdpDocument& aSdpDocument ); |
|
62 |
|
63 /** |
|
64 * Decodes the media answer. |
|
65 * @param aStream media stream |
|
66 * @param aSdpDocument sdp document |
|
67 * @return warning if any |
|
68 * @leave system wide error |
|
69 */ |
|
70 TMceSipWarningCode DecodeMediaAnswerL( CSdpMediaField& aMediaLine, |
|
71 CMceComMediaStream& aStream, |
|
72 CSdpDocument& aSdpDocument ); |
|
73 |
|
74 /** |
|
75 * Decodes media offer and creates media stream. The stream is appended |
|
76 * into the media session, if aStream is NULL |
|
77 * @param aMediaLine media line |
|
78 * @param aStream stream added to session |
|
79 * @param aSession media session |
|
80 * @param aSdpDocument sdp document |
|
81 * @param aStream stream to updated, if any |
|
82 * @return warning if any |
|
83 * @leave system wide error |
|
84 */ |
|
85 TMceSipWarningCode DecodeMediaOfferL( CSdpMediaField& aMediaLine, |
|
86 CMceComMediaStream*& aStream, |
|
87 CMceComSession& aSession, |
|
88 CSdpDocument& aSdpDocument ); |
|
89 |
|
90 /** |
|
91 * Decodes media update by updating media stream |
|
92 * @param aMediaLine media line |
|
93 * @param aStream stream to be updated |
|
94 * @param aSdpDocument sdp document |
|
95 * @return warning if any |
|
96 * @leave system wide error |
|
97 */ |
|
98 TMceSipWarningCode DecodeMediaUpdateL( CSdpMediaField& aMediaLine, |
|
99 CMceComMediaStream& aStream, |
|
100 CSdpDocument& aSdpDocument ); |
|
101 |
|
102 |
|
103 /** |
|
104 * Creates a encoded media line based on the offer received earlier. |
|
105 * @param aStream media stream |
|
106 * @param aMediaLine media line |
|
107 * @param aSdpDocument sdp document |
|
108 * @leave system wide error |
|
109 */ |
|
110 void EncodeMediaAnswerL( CMceComMediaStream& aStream, |
|
111 CSdpMediaField& aMediaLine, |
|
112 CSdpDocument& aSdpDocument ); |
|
113 |
|
114 /** |
|
115 * Clean attributes |
|
116 * @param aMediaLine media line |
|
117 */ |
|
118 void CleanAttributes( CSdpMediaField& aMediaLine ); |
|
119 |
|
120 |
|
121 /** |
|
122 * Prepares media line before offer/answer will be decoded |
|
123 * @param aMediaLine media line |
|
124 * @param aStream media stream |
|
125 * @leave system wide error |
|
126 */ |
|
127 void PrepareForDecodeL( CSdpMediaField& aMediaLine, |
|
128 CMceComMediaStream* aStream ); |
|
129 |
|
130 |
|
131 |
|
132 protected://abstract interface |
|
133 |
|
134 |
|
135 /** |
|
136 * Returns codecs |
|
137 * @param aStream media stream |
|
138 * @param return codecs |
|
139 * @leave if stream type does not macth codecs |
|
140 */ |
|
141 virtual const RPointerArray<CMceComCodec>& CodecsL( |
|
142 CMceComMediaStream& aStream ) const = 0; |
|
143 /** |
|
144 * Encodes rtpmap -attribute |
|
145 * @param aCodec codec encoded to rtpmap |
|
146 * @leave system wide error |
|
147 */ |
|
148 virtual CSdpFmtAttributeField* EncodeRtpmapAttributeLC( |
|
149 CMceComCodec& aCodec ) const = 0; |
|
150 |
|
151 /** |
|
152 * Encodes media related attributes |
|
153 * @param aCodec the codec |
|
154 * @param aMediaLine media line |
|
155 * @param aRtpmap rtpmap attribute |
|
156 * @leave system wide error |
|
157 */ |
|
158 virtual void EncodeMediaAttributesL( CMceComCodec& aCodec, |
|
159 CSdpMediaField& aMediaLine, |
|
160 CSdpFmtAttributeField& aRtpmap ) const = 0; |
|
161 |
|
162 /** |
|
163 * Decodes media related attributes |
|
164 * @param aMediaLine media line |
|
165 * @param aCodec the codec |
|
166 * @leave system wide error |
|
167 */ |
|
168 virtual void DecodeMediaAttributesL( CSdpMediaField& aMediaLine, |
|
169 CMceComCodec& aCodec, |
|
170 CSdpFmtAttributeField& aRtpmap ) const = 0; |
|
171 |
|
172 |
|
173 /** |
|
174 * Creates media stream based on sdp type |
|
175 * @param aType the sdp type sendrecv, sendonly or receive only |
|
176 * @return media stream |
|
177 * @leave system wide error |
|
178 */ |
|
179 virtual CMceComMediaStream* CreateStreamLC( TInt aType ) const = 0; |
|
180 |
|
181 /** |
|
182 * Updates media based on received offer |
|
183 * @param aStream media stream |
|
184 * @param aDirection the direction |
|
185 * @leave system wide error |
|
186 */ |
|
187 virtual void UpdateStreamL( CMceComMediaStream& aStream, TInt aDirection ) const = 0; |
|
188 |
|
189 /** |
|
190 * Creates codec based on rtpmap line |
|
191 * @param aRtpmap rtpmap line |
|
192 * @return codec or NULL, if not supported |
|
193 * @leave system wide error |
|
194 */ |
|
195 virtual CMceComCodec* CreateCodecLC( CSdpFmtAttributeField& aRtpmap ) const = 0; |
|
196 |
|
197 /** |
|
198 * Creates codec based on payload type |
|
199 * @param aPayload payload |
|
200 * @param aMediaLine media line |
|
201 * @return codec or NULL, if not supported |
|
202 * @leave system wide error |
|
203 */ |
|
204 virtual CMceComCodec* CreateCodecLC( TUint aPayload, CSdpMediaField& aMediaLine ) const = 0; |
|
205 |
|
206 /** |
|
207 * Decodes session level media attributes |
|
208 * @param aStream media stream |
|
209 * @param aSdpDocument sdp document |
|
210 * @return codec or NULL, if not supported |
|
211 * @leave system wide error |
|
212 */ |
|
213 virtual void DecodeSessionMediaAttributesL( CMceComMediaStream& aStream, |
|
214 CSdpDocument& aSdpDocument ) const = 0; |
|
215 |
|
216 protected: |
|
217 |
|
218 |
|
219 /** |
|
220 * validates sdp offer. Called before offer will be decoded |
|
221 * @param aMediaLine media line |
|
222 * @param aSdpDocument sdp document |
|
223 * @return warning |
|
224 */ |
|
225 virtual TMceSipWarningCode ValidateSdpL( CSdpMediaField& aMediaLine, |
|
226 CSdpDocument& aSdpDocument ); |
|
227 |
|
228 /** |
|
229 * Gets the type of session ( sendrecv, sendonly or receiveonly ) |
|
230 * @param aMediaLine media line |
|
231 * @param aSessionAttributes all session attributes |
|
232 * @return type |
|
233 */ |
|
234 TInt Type( CSdpMediaField& aMediaLine, |
|
235 RPointerArray<CSdpAttributeField>& aSessionAttributes ) const; |
|
236 |
|
237 |
|
238 /** |
|
239 * Encodes direction attribute |
|
240 * @param aStream media stream |
|
241 * @param aMediaLine media line |
|
242 * @param aSdpDocument sdp document |
|
243 * @param aRole negotiation role |
|
244 */ |
|
245 void EncodeDirectionL( CMceComMediaStream& aStream, |
|
246 CSdpMediaField& aMediaLine, |
|
247 CSdpDocument& aSdpDocument, |
|
248 TMceNegotiationRole aRole ) const; |
|
249 |
|
250 |
|
251 /** |
|
252 * Encodes preconditions |
|
253 * @param aStream media stream |
|
254 * @param aMedia media line |
|
255 * @param aRole negotiation role |
|
256 * @leave system wide error |
|
257 */ |
|
258 void EncodePreconditionsL( CMceComMediaStream& aStream, |
|
259 CSdpMediaField& aMediaLine, |
|
260 TMceNegotiationRole aRole ) const; |
|
261 |
|
262 /** |
|
263 * Decodes preconditions |
|
264 * @param aMedia media line |
|
265 * @param aStream media stream |
|
266 * @param aRole negotiation role |
|
267 * @return warning if any |
|
268 * @leave system wide error |
|
269 */ |
|
270 TMceSipWarningCode DecodePreconditionsL( CSdpMediaField& aMediaLine, |
|
271 CMceComMediaStream& aStream, |
|
272 TMceNegotiationRole aRole ) const; |
|
273 |
|
274 |
|
275 /** |
|
276 * Decodes rmtpmap lines in answer |
|
277 * @param aMediaLine Media line |
|
278 * @param aStream stream |
|
279 * @param aRole role of negotiation |
|
280 * @return number of lines decoded |
|
281 */ |
|
282 TInt DecodeRtpmapLinesL( CSdpMediaField& aMediaLine, |
|
283 CMceComMediaStream& aStream, |
|
284 TMceNegotiationRole aRole ) const; |
|
285 |
|
286 |
|
287 /** |
|
288 * Decodes rmtpmap lines in offer, and adds codes to stream. |
|
289 * @param aMediaLine Media line |
|
290 * @param aStream stream |
|
291 * @return number of lines decoded |
|
292 */ |
|
293 TInt DecodeRtpmapLinesL( CSdpMediaField& aMediaLine, |
|
294 CMceComMediaStream& aStream ) const; |
|
295 |
|
296 /** |
|
297 * Decodes static payloads if payload wasn't defined as rtpmap |
|
298 * @param aMediaLine Media line |
|
299 * @param aStream stream |
|
300 * @param aPayloadTypes payload types as an array |
|
301 * @param aRole role of negotiation |
|
302 * @return number of lines decoded |
|
303 */ |
|
304 TInt DecodeStaticPayloadsL( CSdpMediaField& aMediaLine, |
|
305 CMceComMediaStream& aStream, |
|
306 RArray<TUint>& aPayloadTypes, |
|
307 TMceNegotiationRole aRole ) const; |
|
308 |
|
309 /** |
|
310 * Decodes rtpmap line. |
|
311 * @param aRtpMaptLine rtpmap line |
|
312 * @param aMediaLine media line |
|
313 * @param aStream stream |
|
314 * @param aFmtpValue |
|
315 * @return decoded codec if codec was supported |
|
316 */ |
|
317 CMceComCodec* DecodeRtpmapLineL( CSdpFmtAttributeField& aRtpMaptLine, |
|
318 CSdpMediaField& aMediaLine, |
|
319 CMceComMediaStream& aStream, |
|
320 const TDesC8& aFmtpValue = KNullDesC8 ) const; |
|
321 |
|
322 /** |
|
323 * Decodes fmtp lines. |
|
324 * @pre codecs and rtpmaps are in sync |
|
325 * @param aMediaLine Media line |
|
326 * @param aCodecs codecs |
|
327 * @param aRole the role |
|
328 */ |
|
329 void DecodeFmtpLinesL( CSdpMediaField& aMediaLine, |
|
330 CMceComCodec::TIterator& aCodecs, |
|
331 TMceNegotiationRole aRole ) const; |
|
332 |
|
333 |
|
334 /** |
|
335 * Creates fmtp attribute and appends it into media line |
|
336 * @param aCodec the codec |
|
337 * @param aMediaLine Media line |
|
338 * @return None. |
|
339 */ |
|
340 void EncodeFmtpAttributeL( CMceComCodec& aCodec, |
|
341 CSdpMediaField& aMediaLine ) const; |
|
342 |
|
343 |
|
344 /** |
|
345 * Encodes secure session |
|
346 * @param aStream media stream |
|
347 * @param aMediaLine Media line |
|
348 * @param aRole the role |
|
349 */ |
|
350 void EncodeSecureSessionL( CMceComMediaStream& aStream, |
|
351 CSdpMediaField& aMediaLine, |
|
352 TMceNegotiationRole aRole ); |
|
353 |
|
354 |
|
355 /** |
|
356 * Decodes secure session |
|
357 * @param aMediaLine Media line |
|
358 * @param aStream media stream |
|
359 * @param aRole the role |
|
360 * @param aUpdate is it update (role EMceRoleAnswerer ) |
|
361 */ |
|
362 void DecodeSecureSessionL( CSdpMediaField& aMediaLine, |
|
363 CMceComMediaStream& aStream, |
|
364 TMceNegotiationRole aRole, |
|
365 TBool aUpdate = KMceMediaCodecNoUpdate ); |
|
366 |
|
367 |
|
368 |
|
369 /** |
|
370 * Decodes direction and 'old school' hold |
|
371 * @param aMediaLine Media line |
|
372 * @param aStream media stream |
|
373 * @param aSdpDocument sdp document |
|
374 * @param aRole the role |
|
375 * @param aUpdate is it update |
|
376 */ |
|
377 void DecodeDirectionL( CSdpMediaField& aMediaLine, |
|
378 CMceComMediaStream& aStream, |
|
379 CSdpDocument& aSdpDocument, |
|
380 TMceNegotiationRole aRole ) const; |
|
381 |
|
382 |
|
383 /** |
|
384 * Update direction and 'old school' hold |
|
385 * @param aMediaLine Media line |
|
386 * @param aStream media stream |
|
387 * @param aSdpDocument sdp document |
|
388 */ |
|
389 |
|
390 void UpdateDirectionL( CSdpMediaField& aMediaLine, |
|
391 CMceComMediaStream& aStream, |
|
392 CSdpDocument& aSdpDocument) const; |
|
393 |
|
394 /** |
|
395 * Creates fmtlist that can be used as media field fmt list -attribute |
|
396 * @param aCodecs codecs |
|
397 * @return fmtp list |
|
398 */ |
|
399 HBufC8* CreateFormatListL( CMceComCodec::TIterator& aCodecs ) const; |
|
400 |
|
401 |
|
402 /** |
|
403 * decodes the remote RTCP port according to RFC 3605 |
|
404 * @param aMediaLine Media line |
|
405 * @param aStream media stream |
|
406 */ |
|
407 void DecodeRemoteRtcpFieldL( CSdpMediaField& aMediaLine, |
|
408 CMceComMediaStream& aStream ) const; |
|
409 |
|
410 /** |
|
411 * encodes the remote RTCP port according to RFC 3605 |
|
412 * @param aMediaLine Media line |
|
413 * @param aStream media stream |
|
414 */ |
|
415 void EncodelocalRtcpAttrL( CSdpMediaField& aMediaLine, |
|
416 CMceComMediaStream& aStream ) const; |
|
417 |
|
418 /** |
|
419 * Encodes media attributes client is willing to insert |
|
420 * @param aStream media stream |
|
421 * @param aMediaLine media line |
|
422 */ |
|
423 void EncodeClientAttributesL( CMceComMediaStream& aStream, |
|
424 CSdpMediaField& aMediaLine ) const; |
|
425 |
|
426 /** |
|
427 * Decodes media attributes to be sent to client |
|
428 * @param aMediaLine Media line |
|
429 * @param aStream media stream |
|
430 */ |
|
431 void DecodeClientAttributesL( CSdpMediaField& aMediaLine, |
|
432 CMceComMediaStream& aStream ) const; |
|
433 |
|
434 |
|
435 /** |
|
436 * Decodes media line's format list to payload type array |
|
437 * @param aMediaLine Media line |
|
438 * @param aPayloadTypes payload types as an array |
|
439 */ |
|
440 void DecodeFormatListL( CSdpMediaField& aMedia, |
|
441 RArray<TUint>& aPayloadTypes ) const; |
|
442 |
|
443 /** |
|
444 * Decodes media line's format list to payload type array |
|
445 * @param aMediaLine Media line |
|
446 * @param aPayloadTypes payload types as an array |
|
447 * @return system wide error |
|
448 */ |
|
449 TInt DecodeFormatList( CSdpMediaField& aMedia, |
|
450 RArray<TUint>& aPayloadTypes ) const; |
|
451 |
|
452 /** |
|
453 * Finds codec based on payload type |
|
454 * @param aPayloadType payload |
|
455 * @param aStream stream containig codecs |
|
456 * @return codec |
|
457 */ |
|
458 CMceComCodec* FindCodec( TInt aPayloadType, |
|
459 CMceComMediaStream& aStream ) const; |
|
460 |
|
461 |
|
462 /** |
|
463 * Decodes payloads and static payloads if payload wasn't defined |
|
464 * as rtpmap. Additionally, codec sdp indexes are updated. |
|
465 * @param aMediaLine Media line |
|
466 * @param aStream stream |
|
467 * @param aRole role of negotiation |
|
468 * @return number of lines decoded |
|
469 */ |
|
470 TInt DecodePayloadsL( CSdpMediaField& aMediaLine, |
|
471 CMceComMediaStream& aStream, |
|
472 TMceNegotiationRole aRole ) const; |
|
473 |
|
474 /** |
|
475 * Updates streams codec sdp index values. Can be called after |
|
476 * dynamic payload types have been updated. |
|
477 * @param aStream stream containig codecs |
|
478 * @param aPayloadTypes list of payload types |
|
479 */ |
|
480 void UpdateSdpCodecIndexesL( CMceComMediaStream& aStream, |
|
481 RArray<TUint>& aPayloadTypes ) const; |
|
482 |
|
483 |
|
484 /** |
|
485 * Tries to find matching fmtp line for certain rtpmap line |
|
486 * @param aMediaLine Media line |
|
487 * @param aRtpMapFormatLine rtpmap format line |
|
488 * @return KNullDesC8 if fmtp line is not found |
|
489 */ |
|
490 TPtrC8 GetCorrespondingFmtpLineL( CSdpMediaField& aMediaLine, |
|
491 CSdpFmtAttributeField& aRtpMapFormatLine ) const; |
|
492 |
|
493 protected: |
|
494 |
|
495 |
|
496 /** |
|
497 * C++ Constructor |
|
498 * @param aMedia media |
|
499 */ |
|
500 CMceMediaSdpCodec( RStringF aMedia ); |
|
501 |
|
502 |
|
503 |
|
504 friend class UT_CMceMediaSdpCodec; |
|
505 friend class UT_CMceMediaManager; |
|
506 friend class UT_CMceSdpSession; |
|
507 |
|
508 |
|
509 }; |
|
510 |
|
511 #endif // CMCEMEDIASDPCODEC_H |
|
512 |
|
513 // End of File |