sipcall.cpp 17.5 KB
Newer Older
yanmorin's avatar
   
yanmorin committed
1
/*
yanmorin's avatar
yanmorin committed
2
 *  Copyright (C) 2004-2006 Savoir-Faire Linux inc.
jpbl's avatar
jpbl committed
3
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
yanmorin's avatar
yanmorin committed
4
 *  Author : Laurielle Lea <laurielle.lea@savoirfairelinux.com>
jpbl's avatar
jpbl committed
5
 *
yanmorin's avatar
   
yanmorin committed
6
7
8
9
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
jpbl's avatar
jpbl committed
10
 *
yanmorin's avatar
   
yanmorin committed
11
12
13
14
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
jpbl's avatar
jpbl committed
15
 *
yanmorin's avatar
   
yanmorin committed
16
17
18
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
jpbl's avatar
jpbl committed
19
20
 */

yanmorin's avatar
yanmorin committed
21
#include "sipcall.h"
yanmorin's avatar
   
yanmorin committed
22
#include "global.h" // for _debug
yanmorin's avatar
yanmorin committed
23
#include <sstream> // for media buffer
jpbl's avatar
jpbl committed
24

yanmorin's avatar
yanmorin committed
25
26
27
28
#define _SENDRECV 0
#define _SENDONLY 1
#define _RECVONLY 2

29
SIPCall::SIPCall(const CallID& id, Call::CallType type) : Call(id, type)
yanmorin's avatar
yanmorin committed
30
31
32
33
34
35
36
{
  _cid = 0;
  _did = 0;
  _tid = 0;
}

SIPCall::~SIPCall() 
jpbl's avatar
jpbl committed
37
38
39
{
}

Alexandre Bourget's avatar
Alexandre Bourget committed
40

yanmorin's avatar
yanmorin committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
bool 
SIPCall::SIPCallInvite(eXosip_event_t *event)
{
  if (event->cid < 1 && event->did < 1) {
    _debug("SIP Failure: Invalid cid and did\n");
    return false;
  }

  if (event->request == NULL) {
    _debug("SIP Failure: No request into the event\n");
    return false;
  }

  setCid(event->cid);
  setDid(event->did);
  setTid(event->tid);

  setPeerInfoFromRequest(event);
  
  sdp_message_t* remote_sdp = getRemoteSDPFromRequest(event);
  if (remote_sdp == 0) {
    return false;
  }

  sdp_media_t* remote_med = getRemoteMedia(event->tid, remote_sdp);
  if (remote_med == 0) {
    sdp_message_free (remote_sdp);
    return false;
  }

  if (!setRemoteAudioFromSDP(remote_med, remote_sdp)) {
    _debug("SIP Failure: unable to set IP address and port from SDP\n");
    sdp_message_free (remote_sdp);
    return false;
  }

  if (!setAudioCodecFromSDP(remote_med, event->tid)) {
    sdp_message_free (remote_sdp);
    return false;
  }

  osip_message_t *answer = 0;
  eXosip_lock();
  _debug("< Building Answer 183\n");
  if (0 == eXosip_call_build_answer (event->tid, 183, &answer)) {
    if ( 0 != sdp_complete_message(remote_sdp, answer)) {
      osip_message_free(answer);
      // Send 415 Unsupported media type
      _debug("< Sending Answer 415 : unsupported media type\n");
      eXosip_call_send_answer (event->tid, 415, NULL);
    } else {

      sdp_message_t *local_sdp = eXosip_get_sdp_info(answer);
      sdp_media_t *local_med = NULL;
      if (local_sdp != NULL) {
         local_med = eXosip_get_audio_media(local_sdp);
      }
      if (local_sdp != NULL && local_med != NULL) {
        /* search if stream is sendonly or recvonly */
        int _remote_sendrecv = sdp_analyse_attribute (remote_sdp, remote_med);
        int _local_sendrecv =  sdp_analyse_attribute (local_sdp, local_med);
        _debug("            Remote SendRecv: %d\n", _remote_sendrecv);
        _debug("            Local  SendRecv: %d\n", _local_sendrecv);
        if (_local_sendrecv == _SENDRECV) {
          if (_remote_sendrecv == _SENDONLY)      { _local_sendrecv = _RECVONLY; }
          else if (_remote_sendrecv == _RECVONLY) { _local_sendrecv = _SENDONLY; }
        }
        _debug("            Final Local SendRecv: %d\n", _local_sendrecv);
        sdp_message_free (local_sdp);
      }
      _debug("< Sending answer 183\n");
      if (0 != eXosip_call_send_answer (event->tid, 183, answer)) {
        _debug("SipCall::newIncomingCall: cannot send 183 progress?\n");
      }
    }
  }
  eXosip_unlock ();

  sdp_message_free (remote_sdp);
  return true;
}

bool 
SIPCall::SIPCallReinvite(eXosip_event_t *event)
{
  if (event->cid < 1 && event->did < 1) {
    _debug("SIP Failure: Invalid cid and did\n");
    return false;
  }

  if (event->request == NULL) {
    _debug("SIP Failure: No request into the event\n");
    return false;
  }

  setCid(event->cid);
  setDid(event->did);
  setTid(event->tid);

  setPeerInfoFromRequest(event);

  sdp_message_t* remote_sdp = getRemoteSDPFromRequest(event);
  if (remote_sdp == 0) {
    return false;
  }

  sdp_media_t* remote_med = getRemoteMedia(event->tid, remote_sdp);
  if (remote_med == 0) {
    sdp_message_free (remote_sdp);
    return false;
  }

  if (!setRemoteAudioFromSDP(remote_med, remote_sdp)) {
    _debug("SIP Failure: unable to set IP address and port from SDP\n");
    sdp_message_free (remote_sdp);
    return false;
  }

  if (!setAudioCodecFromSDP(remote_med, event->tid)) {
    sdp_message_free (remote_sdp);
    return false;
  }

  osip_message_t *answer = 0;
  eXosip_lock();
  _debug("< Building Answer 200\n");
  if (0 == eXosip_call_build_answer (event->tid, 200, &answer)) {
    if ( 0 != sdp_complete_message(remote_sdp, answer)) {
      osip_message_free(answer);
      // Send 415 Unsupported media type
      eXosip_call_send_answer (event->tid, 415, NULL);
      _debug("< Sending Answer 415\n");
    } else {

      sdp_message_t *local_sdp = eXosip_get_sdp_info(answer);
      sdp_media_t *local_med = NULL;
      if (local_sdp != NULL) {
         local_med = eXosip_get_audio_media(local_sdp);
      }
      if (local_sdp != NULL && local_med != NULL) {
        /* search if stream is sendonly or recvonly */
        int _remote_sendrecv = sdp_analyse_attribute (remote_sdp, remote_med);
        int _local_sendrecv =  sdp_analyse_attribute (local_sdp, local_med);
        _debug("            Remote SendRecv: %d\n", _remote_sendrecv);
        _debug("            Local  SendRecv: %d\n", _local_sendrecv);
        if (_local_sendrecv == _SENDRECV) {
          if (_remote_sendrecv == _SENDONLY)      { _local_sendrecv = _RECVONLY; }
          else if (_remote_sendrecv == _RECVONLY) { _local_sendrecv = _SENDONLY; }
        }
        _debug("            Final Local SendRecv: %d\n", _local_sendrecv);
        sdp_message_free (local_sdp);
      }
      _debug("< Sending answer 200\n");
      if (0 != eXosip_call_send_answer (event->tid, 200, answer)) {
        _debug("SipCall::newIncomingCall: cannot send 200 OK?\n");
      }
    }
  }
  eXosip_unlock ();
  sdp_message_free (remote_sdp);
  return true;
}

bool 
SIPCall::SIPCallAnswered(eXosip_event_t *event)
{
  if (event->cid < 1 && event->did < 1) {
    _debug("SIP Failure: Invalid cid and did\n");
    return false;
  }

  if (event->request == NULL) {
    _debug("SIP Failure: No request into the event\n");
    return false;
  }

  setCid(event->cid);
  setDid(event->did);

  //setPeerInfoFromResponse()

  eXosip_lock ();
  {
    osip_message_t *ack = NULL;
    int i;
    i = eXosip_call_build_ack (event->did, &ack);
    if (i != 0) {
      _debug("SipCall::answeredCall: Cannot build ACK for call!\n");
    } else {
      sdp_message_t *local_sdp = NULL;
      sdp_message_t *remote_sdp = NULL;

      if (event->request != NULL && event->response != NULL) {
        local_sdp = eXosip_get_sdp_info (event->request);
        remote_sdp = eXosip_get_sdp_info (event->response);
      }
      if (local_sdp == NULL && remote_sdp != NULL) {
        /* sdp in ACK */
        i = sdp_complete_message (remote_sdp, ack);
        if (i != 0) {
            _debug("SipCall::answeredCall: Cannot complete ACK with sdp body?!\n");
        }
      }
      sdp_message_free (local_sdp);
      sdp_message_free (remote_sdp);

      _debug("< Send ACK\n");
      eXosip_call_send_ack (event->did, ack);
    }
  }
  eXosip_unlock ();
  return true;  
}
Alexandre Bourget's avatar
Alexandre Bourget committed
254
255


yanmorin's avatar
yanmorin committed
256
bool 
yanmorin's avatar
yanmorin committed
257
SIPCall::SIPCallAnsweredWithoutHold(eXosip_event_t* event)
yanmorin's avatar
yanmorin committed
258
259
260
261
{
  if (event->response == NULL || event->request  == NULL) { return false; }
  
  eXosip_lock();
yanmorin's avatar
yanmorin committed
262
  sdp_message_t* remote_sdp = eXosip_get_sdp_info (event->response);
yanmorin's avatar
yanmorin committed
263
264
265
266
267
268
269
  eXosip_unlock();
  if (remote_sdp == NULL) {
    _debug("SIP Failure: no remote sdp\n");
    sdp_message_free(remote_sdp);
    return false;
  }

yanmorin's avatar
yanmorin committed
270
  sdp_media_t* remote_med = getRemoteMedia(event->tid, remote_sdp);
yanmorin's avatar
yanmorin committed
271
272
273
274
275
276
277
278
279
  if (remote_med==NULL) {
    sdp_message_free(remote_sdp);
    return false;
  }
  if ( ! setRemoteAudioFromSDP(remote_med, remote_sdp) ) {
    sdp_message_free(remote_sdp);
    return false;
  }

yanmorin's avatar
yanmorin committed
280
281
282
283
284
#ifdef LIBOSIP2_WITHPOINTER
  char *tmp = (char*) osip_list_get (remote_med->m_payloads, 0);
#else
  char *tmp = (char*) osip_list_get (&(remote_med->m_payloads), 0);
#endif
yanmorin's avatar
yanmorin committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
  setAudioCodec(0);
  if (tmp != NULL) {
    int payload = atoi (tmp);
    _debug("            Remote Payload: %d\n", payload);
    setAudioCodec(_codecMap.getCodec((CodecType)payload)); // codec builder for the mic
  }

/*
    // search if stream is sendonly or recvonly
    _remote_sendrecv = sdp_analyse_attribute (remote_sdp, remote_med);
    _local_sendrecv = sdp_analyse_attribute (local_sdp, local_med);
    if (_local_sendrecv == _SENDRECV) {
      if (_remote_sendrecv == _SENDONLY)
          _local_sendrecv = _RECVONLY;
      else if (_remote_sendrecv == _RECVONLY)
          _local_sendrecv = _SENDONLY;
    }
  _debug("            Remote Sendrecv: %d\n", _remote_sendrecv);
  _debug("            Local Sendrecv: %d\n", _local_sendrecv);
*/
  sdp_message_free (remote_sdp);
  return true;
}

Alexandre Bourget's avatar
Alexandre Bourget committed
309

yanmorin's avatar
yanmorin committed
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
int 
SIPCall::sdp_complete_message(sdp_message_t * remote_sdp, osip_message_t * msg)
{
  // Format port to a char*
  if (remote_sdp == NULL) {
    _debug("SipCall::sdp_complete_message: No remote SDP body found for call\n");
    return -1;
  }
  if (msg == NULL) {
    _debug("SipCall::sdp_complete_message: No message to complete\n");
    return -1;
  }

  std::ostringstream media;

  // for each medias
  int iMedia = 0;
  char *tmp = NULL;
yanmorin's avatar
yanmorin committed
328
329
330
331
332
333
334
335
336
  #ifdef LIBOSIP2_WITHPOINTER 
  const osip_list_t* remote_sdp_m_medias = remote_sdp->m_medias; // old abi
  #else
  const osip_list_t* remote_sdp_m_medias = &(remote_sdp->m_medias);
  #endif
  osip_list_t* remote_med_m_payloads = 0;

  while (!osip_list_eol(remote_sdp_m_medias, iMedia)) {
    sdp_media_t *remote_med = (sdp_media_t *)osip_list_get(remote_sdp_m_medias, iMedia);
yanmorin's avatar
yanmorin committed
337
338
339
340
341
342
343
344
345
346
347
    if (remote_med == 0) { continue; }

    if (0 != osip_strcasecmp (remote_med->m_media, "audio")) {
      // if this is not an "audio" media, we set it to 0
      media << "m=" << remote_med->m_media << " 0 " << remote_med->m_proto << " \r\n";
    } else {
      std::ostringstream listCodec;
      std::ostringstream listRtpMap;

      // search for compatible codec: foreach payload
      int iPayload = 0;
yanmorin's avatar
yanmorin committed
348
349
350
351
352
353
354
355
      #ifdef LIBOSIP2_WITHPOINTER 
      remote_med_m_payloads = remote_med->m_payloads; // old abi
      #else
      remote_med_m_payloads = &(remote_med->m_payloads);
      #endif

      while (!osip_list_eol(remote_med_m_payloads, iPayload)) {
        tmp = (char *)osip_list_get(remote_med_m_payloads, iPayload);
yanmorin's avatar
yanmorin committed
356
357
358
        if (tmp!=NULL) {
          int payload = atoi(tmp);
          AudioCodec* audiocodec = _codecMap.getCodec((CodecType)payload);
359
          if (audiocodec != NULL && audiocodec->isActive()) {
yanmorin's avatar
yanmorin committed
360
            listCodec << payload << " ";
361
            listRtpMap << "a=rtpmap:" << payload << " " << audiocodec->getCodecName() << "/" << audiocodec->getClockRate();
yanmorin's avatar
yanmorin committed
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
            if ( audiocodec->getChannel() != 1) {
              listRtpMap << "/" << audiocodec->getChannel();
            }
            listRtpMap << "\r\n";
          }
        }
        iPayload++;
      }
      if (listCodec.str().empty()) {
        media << "m=" << remote_med->m_media << " 0 " << remote_med->m_proto << " \r\n";
      } else {
        // we add the media line + a=rtpmap list
        media << "m=" << remote_med->m_media << " " << getLocalExternAudioPort() << " RTP/AVP " << listCodec.str() << "\r\n";
        media << listRtpMap.str();
      }
    }
    iMedia++;
  }
  char buf[4096];
  snprintf (buf, 4096,
    "v=0\r\n"
    "o=user 0 0 IN IP4 %s\r\n"
    "s=session\r\n"
    "c=IN IP4 %s\r\n"
    "t=0 0\r\n"
    "%s\n", getLocalIp().c_str(), getLocalIp().c_str(), media.str().c_str());

  osip_message_set_body (msg, buf, strlen (buf));
  osip_message_set_content_type (msg, "application/sdp");
  _debug("          sdp: %s", buf);
  return 0;
}


Alexandre Bourget's avatar
Alexandre Bourget committed
396

yanmorin's avatar
yanmorin committed
397
398
399
400
401
402
403
404
int 
SIPCall::sdp_analyse_attribute (sdp_message_t * sdp, sdp_media_t * med)
{
  int pos;
  int pos_media;

  /* test media attributes */
  pos = 0;
yanmorin's avatar
yanmorin committed
405
406
407
408
409
410
  #ifdef LIBOSIP2_WITHPOINTER 
  const osip_list_t* med_a_attributes = med->a_attributes; // old abi
  #else
  const osip_list_t* med_a_attributes = &(med->a_attributes);
  #endif
  while (!osip_list_eol (med_a_attributes, pos)) {
yanmorin's avatar
yanmorin committed
411
412
      sdp_attribute_t *at;

yanmorin's avatar
yanmorin committed
413
      at = (sdp_attribute_t *) osip_list_get (med_a_attributes, pos);
yanmorin's avatar
yanmorin committed
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
      if (at->a_att_field != NULL && 
      0 == strcmp (at->a_att_field, "sendonly")) {
      return _SENDONLY;
      } else if (at->a_att_field != NULL &&
                0 == strcmp (at->a_att_field, "recvonly")) {
          return _RECVONLY;
      } else if (at->a_att_field != NULL &&
                0 == strcmp (at->a_att_field, "sendrecv")) {
          return _SENDRECV;
      }
      pos++;
  }

  /* test global attributes */
  pos_media = -1;
  pos = 0;
yanmorin's avatar
yanmorin committed
430
431
432
433
434
435
  #ifdef LIBOSIP2_WITHPOINTER 
  const osip_list_t* sdp_a_attributes = sdp->a_attributes; // old abi
  #else
  const osip_list_t* sdp_a_attributes = &(sdp->a_attributes);
  #endif
  while (!osip_list_eol (sdp_a_attributes, pos)) {
yanmorin's avatar
yanmorin committed
436
437
      sdp_attribute_t *at;

yanmorin's avatar
yanmorin committed
438
      at = (sdp_attribute_t *) osip_list_get (sdp_a_attributes, pos);
yanmorin's avatar
yanmorin committed
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
      if (at->a_att_field != NULL && 
      0 == strcmp (at->a_att_field, "sendonly")) {
          return _SENDONLY;
      } else if (at->a_att_field != NULL &&
                0 == strcmp (at->a_att_field, "recvonly")) {
          return _RECVONLY;
      } else if (at->a_att_field != NULL &&
                0 == strcmp (at->a_att_field, "sendrecv")) {
          return _SENDRECV;
      }
      pos++;
  }

  return _SENDRECV;
}

bool 
SIPCall::setPeerInfoFromRequest(eXosip_event_t *event)
{
  // event->request should not be NULL!
  char remote_uri[256] = "";
  std::string name("");
  std::string number("");

  char *tmp = NULL;
  osip_from_to_str(event->request->from, &tmp);
  if (tmp != NULL) {
    snprintf (remote_uri, 255, "%s", tmp);
    remote_uri[255] = '\0';
    osip_free (tmp);

    // Get the name/number
    osip_from_t *from;
    osip_from_init(&from);
    osip_from_parse(from, remote_uri);
    char *tmpname = osip_from_get_displayname(from);
    if ( tmpname != NULL ) {
      name = tmpname;
    }
    osip_uri_t* url = osip_from_get_url(from); 
    if ( url != NULL && url->username != NULL) {
      number = url->username;
    }
    osip_from_free(from);
  }

  _debug("            Name: %s\n", name.c_str());
  _debug("            Number: %s\n", number.c_str());
  _debug("            Remote URI: %s\n", remote_uri);

  setPeerName(name);
  setPeerNumber(number);  
  return true;
}

sdp_message_t* 
SIPCall::getRemoteSDPFromRequest(eXosip_event_t *event)
{
  // event->request should not be null!
  /* negotiate payloads */
  sdp_message_t *remote_sdp = NULL;
  if (event->request != NULL) {
    eXosip_lock();
    remote_sdp = eXosip_get_sdp_info (event->request);
    eXosip_unlock();
  }
  if (remote_sdp == NULL) {
    _debug("SIP Failure: No SDP into the request\n");
    _debug("< Sending 400 Bad Request (no SDP)\n");
    eXosip_lock();
    eXosip_call_send_answer (event->tid, 400, NULL);
    eXosip_unlock();
    return 0;
  }
  return remote_sdp;
}

sdp_media_t* 
SIPCall::getRemoteMedia(int tid, sdp_message_t* remote_sdp)
{
  // Remote Media Port
  eXosip_lock();
  sdp_media_t *remote_med = eXosip_get_audio_media(remote_sdp);
  eXosip_unlock();

  if (remote_med == NULL || remote_med->m_port == NULL) {
    // no audio media proposed
    _debug("SIP Failure: unsupported media\n");
    _debug("< Sending 415 Unsupported media type\n");
    eXosip_lock();
    eXosip_call_send_answer (tid, 415, NULL);
    eXosip_unlock();
    sdp_message_free (remote_sdp);
    return 0;
  }
  return remote_med;
}

bool 
SIPCall::setRemoteAudioFromSDP(sdp_media_t* remote_med, sdp_message_t* remote_sdp)
{
  // Remote Media IP
  eXosip_lock();
  sdp_connection_t *conn = eXosip_get_audio_connection(remote_sdp);
  eXosip_unlock();
  if (conn != NULL && conn->c_addr != NULL) {
    char _remote_sdp_audio_ip[50] = "";
    snprintf (_remote_sdp_audio_ip, 49, "%s", conn->c_addr);
    _remote_sdp_audio_ip[49] = '\0';
    _debug("            Remote Audio IP: %s\n", _remote_sdp_audio_ip);
    setRemoteIP(_remote_sdp_audio_ip);
    if (_remote_sdp_audio_ip[0] == '\0') {
      setRemoteAudioPort(0);
      return false;
    }
  }

  // Remote port
  int _remote_sdp_audio_port = atoi(remote_med->m_port);
  _debug("            Remote Audio Port: %d\n", _remote_sdp_audio_port);
  setRemoteAudioPort(_remote_sdp_audio_port);

  if (_remote_sdp_audio_port == 0) {
    return false;
  }
  return true;
}

bool 
SIPCall::setAudioCodecFromSDP(sdp_media_t* remote_med, int tid)
{
  // Remote Payload
  char *tmp = NULL;
  int pos = 0;
yanmorin's avatar
yanmorin committed
573
574
575
576
577
578
579
  #ifdef LIBOSIP2_WITHPOINTER 
  const osip_list_t* remote_med_m_payloads = remote_med->m_payloads; // old abi
  #else
  const osip_list_t* remote_med_m_payloads = &(remote_med->m_payloads);
  #endif
  while (!osip_list_eol (remote_med_m_payloads, pos)) {
    tmp = (char *) osip_list_get (remote_med_m_payloads, pos);
yanmorin's avatar
yanmorin committed
580
581
582
    if (tmp != NULL ) {
      int payload = atoi(tmp);
      // stop if we find a correct codec
583
      if (_codecMap.getCodec((CodecType)payload) != NULL){
yanmorin's avatar
yanmorin committed
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
          break;
      }
    }
    tmp = NULL;
    pos++;
  }

  setAudioCodec(0);
  if (tmp != NULL) {
    int payload = atoi (tmp);
    _debug("            Payload: %d\n", payload);
    setAudioCodec(_codecMap.getCodec((CodecType)payload)); // codec builder for the mic
  }
  if (getAudioCodec() == 0) {
    _debug("SIPCall Failure: Unable to set codec\n");
    _debug("< Sending 415 Unsupported media type\n");
    eXosip_lock();
    eXosip_call_send_answer(tid, 415, NULL);
    eXosip_unlock();
    return false;
  }
  return true;
}