sip-lab 1.8.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/sip.cpp CHANGED
@@ -26,6 +26,7 @@
26
26
  #include "chainlink_dtmfdet.h"
27
27
  #include "chainlink_tonegen.h"
28
28
  #include "chainlink_wav_port.h"
29
+ #include "chainlink_fax.h"
29
30
 
30
31
  #include <ctime>
31
32
 
@@ -166,6 +167,7 @@ struct Call {
166
167
  chainlink *wav_player;
167
168
  chainlink *tonegen;
168
169
  chainlink *dtmfdet;
170
+ chainlink *fax;
169
171
 
170
172
  Transport *transport;
171
173
 
@@ -361,6 +363,8 @@ bool prepare_tonegen(Call *c);
361
363
  bool prepare_wav_player(Call *c, const char *file);
362
364
  bool prepare_wav_writer(Call *c, const char *file);
363
365
 
366
+ bool prepare_fax(Call *c, bool is_sender, const char *file);
367
+
364
368
  void prepare_error_event(ostringstream *oss, char *scope, char *details);
365
369
  //void prepare_pjsipcall_error_event(ostringstream *oss, char *scope, char *function, pj_status_t s);
366
370
  void append_status(ostringstream *oss, pj_status_t s);
@@ -461,6 +465,21 @@ static void on_inband_dtmf(pjmedia_port *port, void *user_data, char digit){
461
465
  }
462
466
  }
463
467
 
468
+ static void on_fax_result(pjmedia_port *port, void *user_data, int result){
469
+ if(g_shutting_down) return;
470
+
471
+ long call_id;
472
+ if( !g_call_ids.get_id((long)user_data, call_id) ){
473
+ printf("on_fax_result: Failed to get call_id. Event will not be notified.\n");
474
+ return;
475
+ }
476
+
477
+ char evt[256];
478
+ make_evt_fax_result(evt, sizeof(evt), call_id, result);
479
+ dispatch_event(evt);
480
+ }
481
+
482
+
464
483
  void dispatch_event(const char * evt)
465
484
  {
466
485
  //addon_log(LOG_LEVEL_DEBUG, "dispach_event called\n");
@@ -2215,6 +2234,87 @@ int pjw_call_stop_record_wav(long call_id)
2215
2234
  return 0;
2216
2235
  }
2217
2236
 
2237
+ int pjw_call_start_fax(long call_id, bool is_sender, const char *file)
2238
+ {
2239
+ PJW_LOCK();
2240
+
2241
+ long val;
2242
+
2243
+ if(!g_call_ids.get(call_id, val)){
2244
+ PJW_UNLOCK();
2245
+ set_error("Invalid call_id");
2246
+ return -1;
2247
+ }
2248
+
2249
+ Call *call = (Call*)val;
2250
+
2251
+ if(!call->med_stream)
2252
+ {
2253
+ PJW_UNLOCK();
2254
+ set_error("Media not ready");
2255
+ return -1;
2256
+ }
2257
+
2258
+ pj_status_t status;
2259
+
2260
+ pjmedia_port *stream_port;
2261
+ status = pjmedia_stream_get_port(call->med_stream,
2262
+ &stream_port);
2263
+ if(status != PJ_SUCCESS)
2264
+ {
2265
+ PJW_UNLOCK();
2266
+ set_error("pjmedia_stream_get_port failed");
2267
+ return -1;
2268
+ }
2269
+
2270
+ if(!prepare_fax(call, is_sender, file)){
2271
+ PJW_UNLOCK();
2272
+ set_error("pjmedia_wav_player_port_create failed");
2273
+ return -1;
2274
+ }
2275
+
2276
+ PJW_UNLOCK();
2277
+ return 0;
2278
+ }
2279
+
2280
+
2281
+ int pjw_call_stop_fax(long call_id)
2282
+ {
2283
+ PJW_LOCK();
2284
+
2285
+ long val;
2286
+
2287
+ if(!g_call_ids.get(call_id, val)){
2288
+ PJW_UNLOCK();
2289
+ set_error("Invalid call_id");
2290
+ return -1;
2291
+ }
2292
+
2293
+ Call *call = (Call*)val;
2294
+
2295
+ pjmedia_port *stream_port;
2296
+ pj_status_t status;
2297
+ status = pjmedia_stream_get_port(call->med_stream,
2298
+ &stream_port);
2299
+ if(status != PJ_SUCCESS) {
2300
+ PJW_UNLOCK();
2301
+ set_error("pjmedia_stream_get_port failed.");
2302
+ return -1;
2303
+ }
2304
+
2305
+ if(!prepare_wire(call->inv->pool, &call->fax, PJMEDIA_PIA_SRATE(&stream_port->info), PJMEDIA_PIA_CCNT(&stream_port->info), PJMEDIA_PIA_SPF(&stream_port->info), PJMEDIA_PIA_BITS(&stream_port->info))) {
2306
+ PJW_UNLOCK();
2307
+ set_error("prepare_wire failed.");
2308
+ return -1;
2309
+ }
2310
+
2311
+ connect_media_ports(call);
2312
+
2313
+ PJW_UNLOCK();
2314
+ return 0;
2315
+ }
2316
+
2317
+
2218
2318
  int pjw_call_get_stream_stat(long call_id, char *out_stats){
2219
2319
  PJW_LOCK();
2220
2320
 
@@ -3350,6 +3450,9 @@ int __pjw_shutdown()
3350
3450
 
3351
3451
  g_shutting_down = true;
3352
3452
 
3453
+ //disable auto cleanup
3454
+
3455
+ /*
3353
3456
  map<long, long>::iterator iter;
3354
3457
  iter = g_call_ids.id_map.begin();
3355
3458
  while(iter != g_call_ids.id_map.end()){
@@ -3427,11 +3530,6 @@ int __pjw_shutdown()
3427
3530
  //uint32_t wait = 100000 * (g_call_ids.id_map.size() + g_account_ids.id_map.size()));
3428
3531
  //wait += 1000000; //Wait one whole second to permit packet capture to get any final packets
3429
3532
 
3430
- /*
3431
- time_t end,start;
3432
- time(&start);
3433
- end = start;
3434
- */
3435
3533
  timeval tv_start;
3436
3534
  timeval tv_end;
3437
3535
  gettimeofday(&tv_start, NULL);
@@ -3451,6 +3549,8 @@ int __pjw_shutdown()
3451
3549
  //time(&end);
3452
3550
  }
3453
3551
 
3552
+ */
3553
+
3454
3554
  return 0;
3455
3555
  }
3456
3556
 
@@ -3645,6 +3745,12 @@ bool init_media_ports(Call *c, unsigned sampling_rate, unsigned channel_count, u
3645
3745
  if(status != PJ_SUCCESS) return false;
3646
3746
  }
3647
3747
 
3748
+ if(!c->fax) {
3749
+ if(!prepare_wire(c->inv->pool, &c->fax, sampling_rate, channel_count, samples_per_frame, bits_per_sample)) {
3750
+ return false;
3751
+ }
3752
+ }
3753
+
3648
3754
  connect_media_ports(c);
3649
3755
  return true;
3650
3756
  }
@@ -3653,7 +3759,8 @@ void connect_media_ports(Call *c) {
3653
3759
  ((chainlink*)c->dtmfdet)->next = (pjmedia_port*)c->tonegen;
3654
3760
  ((chainlink*)c->tonegen)->next = (pjmedia_port*)c->wav_player;
3655
3761
  ((chainlink*)c->wav_player)->next = (pjmedia_port*)c->wav_writer;
3656
- ((chainlink*)c->wav_writer)->next = c->null_port;
3762
+ ((chainlink*)c->wav_writer)->next = (pjmedia_port*)c->fax;
3763
+ ((chainlink*)c->fax)->next = c->null_port;
3657
3764
  }
3658
3765
 
3659
3766
  bool prepare_tonegen(Call *c) {
@@ -3740,6 +3847,37 @@ bool prepare_wav_writer(Call *c, const char *file) {
3740
3847
  return true;
3741
3848
  }
3742
3849
 
3850
+
3851
+ bool prepare_fax(Call *c, bool is_sender, const char *file) {
3852
+ pj_status_t status;
3853
+
3854
+ chainlink *link = (chainlink*)c->fax;
3855
+
3856
+ pjmedia_port *stream_port;
3857
+ status = pjmedia_stream_get_port(c->med_stream,
3858
+ &stream_port);
3859
+ if(status != PJ_SUCCESS) return false;
3860
+
3861
+ status = pjmedia_port_destroy((pjmedia_port*)link);
3862
+ if(status != PJ_SUCCESS) return false;
3863
+
3864
+ status = chainlink_fax_port_create(c->inv->pool,
3865
+ PJMEDIA_PIA_SRATE(&stream_port->info),
3866
+ PJMEDIA_PIA_CCNT(&stream_port->info),
3867
+ PJMEDIA_PIA_SPF(&stream_port->info),
3868
+ PJMEDIA_PIA_BITS(&stream_port->info),
3869
+ on_fax_result,
3870
+ c,
3871
+ c->outgoing,
3872
+ is_sender,
3873
+ file,
3874
+ (pjmedia_port**)&c->fax);
3875
+ if(status != PJ_SUCCESS) return false;
3876
+
3877
+ connect_media_ports(c);
3878
+ return true;
3879
+ }
3880
+
3743
3881
  bool prepare_wire(pj_pool_t *pool, chainlink **link, unsigned sampling_rate, unsigned channel_count, unsigned samples_per_frame, unsigned bits_per_sample) {
3744
3882
  pj_status_t status;
3745
3883
 
package/src/sip.hpp CHANGED
@@ -33,6 +33,8 @@ int pjw_call_start_record_wav(long call_id, const char *file);
33
33
  int pjw_call_start_play_wav(long call_id, const char *file);
34
34
  int pjw_call_stop_play_wav(long call_id);
35
35
  int pjw_call_stop_record_wav(long call_id);
36
+ int pjw_call_start_fax(long call_id, bool is_sender, const char *file);
37
+ int pjw_call_stop_fax(long call_id);
36
38
  int pjw_call_get_stream_stat(long call_id, char *out_stats);
37
39
  int pjw_call_refer(long call_id, const char *dest_uri, const char *additional_headers, long *out_subscription_id);
38
40
  int pjw_call_get_info(long call_id, const char *required_info, char *out_info);