update to liblinphone 3.12
Stefan Schuermans

Stefan Schuermans commited on 2019-08-13 18:30:31
Showing 1 changed files, with 59 additions and 18 deletions.

... ...
@@ -107,11 +107,13 @@ unsigned int glLogLineCnt; ///< number of lines already logged
107 107
 
108 108
 /**
109 109
  * @brief log information from linphone library
110
+ * @param[in] domain log domain - ignored
110 111
  * @param[in] lev log level
111 112
  * @param[in] fmt format string
112 113
  * @param[in] args arguments to insert into format string
113 114
  */
114
-void log_handler(OrtpLogLevel lev, const char *fmt, va_list args)
115
+void log_handler(const char *domain, OrtpLogLevel lev, const char *fmt,
116
+                 va_list args)
115 117
 {
116 118
   // (re-)open logfile on first line
117 119
   if (glLogLineCnt == 0) {
... ...
@@ -139,6 +141,7 @@ void log_handler(OrtpLogLevel lev, const char *fmt, va_list args)
139 141
     // reset line count, so new file is opened on next line
140 142
     glLogLineCnt = 0;
141 143
   }
144
+  (void)domain;
142 145
 }
143 146
 
144 147
 /// global init
... ...
@@ -153,7 +156,7 @@ void init(std::string const &logFileName)
153 156
 struct Data {
154 157
   SipPhone::ConfigData const *configData; ///< config data for worker thread
155 158
   SipPhone::SharedData *sharedData; ///< data shared with main Blinker thread
156
-  LinphoneCoreVTable callbacks; ///< callback table
159
+  LinphoneCoreCbs *callbacks; ///< callbacks object, if active
157 160
   LinphoneCore *lc; ///< linphone core object, if active
158 161
   LinphoneCall *call; ///< current call, if available
159 162
   std::string playback; ///< name of playback file
... ...
@@ -222,6 +225,9 @@ void global_state_changed(struct _LinphoneCore *lc,
222 225
                           const char *message)
223 226
 {
224 227
   Data *data = (Data*)linphone_core_get_user_data(lc);
228
+  if (data == nullptr) {
229
+    return; // still initializing -> ignore
230
+  }
225 231
 
226 232
   std::stringstream line;
227 233
   line << "global state changed to " << gstate2str(gstate) << ": " << message;
... ...
@@ -241,6 +247,9 @@ void registration_state_changed(struct _LinphoneCore *lc,
241 247
                                 const char *message)
242 248
 {
243 249
   Data *data = (Data*)linphone_core_get_user_data(lc);
250
+  if (data == nullptr) {
251
+    return; // still initializing -> ignore
252
+  }
244 253
   (void)cfg;
245 254
 
246 255
   std::stringstream line;
... ...
@@ -260,6 +269,9 @@ void call_state_changed(struct _LinphoneCore *lc, LinphoneCall *call,
260 269
                         LinphoneCallState cstate, const char *message)
261 270
 {
262 271
   Data *data = (Data*)linphone_core_get_user_data(lc);
272
+  if (data == nullptr) {
273
+    return; // still initializing -> ignore
274
+  }
263 275
 
264 276
   std::stringstream line;
265 277
   line << "call state changed to " << cstate2str(cstate) << ": "
... ...
@@ -291,7 +303,7 @@ void call_state_changed(struct _LinphoneCore *lc, LinphoneCall *call,
291 303
     switch (cstate) {
292 304
     case LinphoneCallIncomingReceived:
293 305
       log(*data, "rejecting call (busy)");
294
-      linphone_core_decline_call(lc, call, LinphoneReasonBusy);
306
+      linphone_call_decline(call, LinphoneReasonBusy);
295 307
       break;
296 308
     default:
297 309
       break;
... ...
@@ -308,7 +320,7 @@ void call_state_changed(struct _LinphoneCore *lc, LinphoneCall *call,
308 320
       }
309 321
       data->playback.clear();
310 322
       log(*data, "accepting call");
311
-      linphone_core_accept_call(lc, call);
323
+      linphone_call_accept(call);
312 324
       break;
313 325
     default:
314 326
       break;
... ...
@@ -325,6 +337,9 @@ void call_state_changed(struct _LinphoneCore *lc, LinphoneCall *call,
325 337
 void dtmf_received(struct _LinphoneCore* lc, LinphoneCall *call, int dtmf)
326 338
 {
327 339
   Data *data = (Data*)linphone_core_get_user_data(lc);
340
+  if (data == nullptr) {
341
+    return; // still initializing -> ignore
342
+  }
328 343
 
329 344
   // check if current call
330 345
   bool current = data->call == call;
... ...
@@ -375,23 +390,45 @@ void do_register(Data &data, std::string const &server,
375 390
     return;
376 391
   }
377 392
 
393
+  LinphoneFactory *factory = linphone_factory_get();
394
+
395
+  // create linphone callback object
396
+  data.callbacks = linphone_factory_create_core_cbs(factory);
397
+  if (! data.callbacks) {
398
+    log(data, "failed to create linphone callback object");
399
+    return;
400
+  }
401
+
402
+  // set callbacks
403
+  linphone_core_cbs_set_global_state_changed(data.callbacks,
404
+                                             global_state_changed);
405
+  linphone_core_cbs_set_registration_state_changed(data.callbacks,
406
+                                                   registration_state_changed);
407
+  linphone_core_cbs_set_call_state_changed(data.callbacks, call_state_changed);
408
+  linphone_core_cbs_set_dtmf_received(data.callbacks, dtmf_received);
409
+
378 410
   // create linphone core object
379
-  data.lc = linphone_core_new(&data.callbacks, NULL, NULL, &data);
411
+  data.lc = linphone_factory_create_core(factory, data.callbacks, NULL, NULL);
380 412
   if (! data.lc) {
381 413
     log(data, "failed to create linphone core");
414
+    linphone_core_cbs_unref(data.callbacks);
415
+    data.callbacks = nullptr;
382 416
     return;
383 417
   }
418
+  linphone_core_set_user_data(data.lc, &data);
384 419
   log(data, "linphone core created");
385 420
 
386 421
   // set auth data
387 422
   if (! username.empty() && ! password.empty()) {
388 423
     LinphoneAuthInfo *auth_info =
389 424
         linphone_auth_info_new(username.c_str(), username.c_str(),
390
-                               password.c_str(), "", "");
425
+                               password.c_str(), nullptr, "", "");
391 426
     if (! auth_info) {
392 427
       log(data, "failed to create auth info");
393
-      linphone_core_destroy(data.lc);
428
+      linphone_core_unref(data.lc);
394 429
       data.lc = nullptr;
430
+      linphone_core_cbs_unref(data.callbacks);
431
+      data.callbacks = nullptr;
395 432
       return;
396 433
     }
397 434
     linphone_core_add_auth_info(data.lc, auth_info);
... ...
@@ -406,12 +443,18 @@ void do_register(Data &data, std::string const &server,
406 443
   LinphoneProxyConfig *proxy = linphone_core_create_proxy_config(data.lc);
407 444
   if (! proxy) {
408 445
     log(data, "failed to create proxy config");
409
-    linphone_core_destroy(data.lc);
446
+    linphone_core_unref(data.lc);
410 447
     data.lc = nullptr;
448
+    linphone_core_cbs_unref(data.callbacks);
449
+    data.callbacks = nullptr;
411 450
     return;
412 451
   }
413 452
   linphone_proxy_config_set_server_addr(proxy, sipserver.c_str());
414
-  linphone_proxy_config_set_identity(proxy, identity.c_str());
453
+  LinphoneAddress *addr =
454
+      linphone_proxy_config_normalize_sip_uri(proxy, identity.c_str());
455
+  if (addr != NULL) {
456
+    linphone_proxy_config_set_identity_address(proxy, addr);
457
+  }
415 458
   linphone_proxy_config_enable_register(proxy, TRUE);
416 459
   linphone_core_add_proxy_config(data.lc, proxy);
417 460
   log(data, "proxy config set");
... ...
@@ -432,11 +475,13 @@ void do_deregister(Data &data)
432 475
     return;
433 476
   }
434 477
 
435
-  log(data, "destroying...");
436
-  linphone_core_destroy(data.lc);
478
+  log(data, "unreferencing...");
479
+  linphone_core_unref(data.lc);
437 480
   data.lc = nullptr;
481
+  linphone_core_cbs_unref(data.callbacks);
482
+  data.callbacks = nullptr;
438 483
   data.call = nullptr;
439
-  log(data, "destroyed");
484
+  log(data, "unreferenced");
440 485
 }
441 486
 
442 487
 /**
... ...
@@ -474,7 +519,7 @@ void do_hangup(Data &data)
474 519
   }
475 520
 
476 521
   log(data, "terminating call...");
477
-  linphone_core_terminate_call(data.lc, data.call);
522
+  linphone_call_terminate(data.call);
478 523
   data.call = nullptr;
479 524
   log(data, "call terminated");
480 525
 }
... ...
@@ -491,11 +536,7 @@ void worker(SipPhone::ConfigData const &configData,
491 536
   Data data;
492 537
   data.configData = &configData;
493 538
   data.sharedData = &sharedData;
494
-  memset(&data.callbacks, 0, sizeof(data.callbacks));
495
-  data.callbacks.global_state_changed = global_state_changed;
496
-  data.callbacks.registration_state_changed = registration_state_changed;
497
-  data.callbacks.call_state_changed = call_state_changed;
498
-  data.callbacks.dtmf_received = dtmf_received;
539
+  data.callbacks = nullptr;
499 540
   data.lc = nullptr;
500 541
   data.call = nullptr;
501 542
   data.logLineCnt = 0;
502 543