1 /**
2 * @file baresip.h Public Interface to Baresip
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6
7 #ifndef BARESIP_H__
8 #define BARESIP_H__
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14
15 /** Defines the Baresip version string */
16 #define BARESIP_VERSION "0.5.8"
17
18
19 #ifndef NET_MAX_NS
20 #define NET_MAX_NS (4)
21 #endif
22
23
24 /* forward declarations */
25 struct sa;
26 struct sdp_media;
27 struct sdp_session;
28 struct sip_msg;
29 struct stream;
30 struct ua;
31 struct vidframe;
32 struct vidrect;
33 struct vidsz;
34
35
36 /*
37 * Account
38 */
39
40 /** Defines the answermodes */
41 enum answermode {
42 ANSWERMODE_MANUAL = 0,
43 ANSWERMODE_EARLY,
44 ANSWERMODE_AUTO
45 };
46
47 struct account;
48
49 int account_alloc(struct account **accp, const char *sipaddr);
50 int account_debug(struct re_printf *pf, const struct account *acc);
51 int account_set_auth_pass(struct account *acc, const char *pass);
52 int account_set_display_name(struct account *acc, const char *dname);
53 int account_auth(const struct account *acc, char **username, char **password,
54 const char *realm);
55 struct list *account_aucodecl(const struct account *acc);
56 struct list *account_vidcodecl(const struct account *acc);
57 struct sip_addr *account_laddr(const struct account *acc);
58 uint32_t account_regint(const struct account *acc);
59 uint32_t account_pubint(const struct account *acc);
60 uint32_t account_ptime(const struct account *acc);
61 enum answermode account_answermode(const struct account *acc);
62 const char *account_aor(const struct account *acc);
63 const char *account_auth_user(const struct account *acc);
64 const char *account_auth_pass(const struct account *acc);
65 const char *account_outbound(const struct account *acc, unsigned ix);
66 const char *account_stun_user(const struct account *acc);
67 const char *account_stun_pass(const struct account *acc);
68 const char *account_stun_host(const struct account *acc);
69
70
71 /*
72 * Audio-level
73 */
74
75
76 #define AULEVEL_MIN (-96.0)
77 #define AULEVEL_MAX (0.0)
78
79
80 double aulevel_calc_dbov(const int16_t *sampv, size_t sampc);
81
82
83 /*
84 * Call
85 */
86
87 enum call_event {
88 CALL_EVENT_INCOMING,
89 CALL_EVENT_RINGING,
90 CALL_EVENT_PROGRESS,
91 CALL_EVENT_ESTABLISHED,
92 CALL_EVENT_CLOSED,
93 CALL_EVENT_TRANSFER,
94 CALL_EVENT_TRANSFER_FAILED,
95 };
96
97 struct call;
98
99 typedef void (call_event_h)(struct call *call, enum call_event ev,
100 const char *str, void *arg);
101 typedef void (call_dtmf_h)(struct call *call, char key, void *arg);
102
103 int call_modify(struct call *call);
104 int call_hold(struct call *call, bool hold);
105 int call_send_digit(struct call *call, char key);
106 bool call_has_audio(const struct call *call);
107 bool call_has_video(const struct call *call);
108 int call_transfer(struct call *call, const char *uri);
109 int call_status(struct re_printf *pf, const struct call *call);
110 int call_debug(struct re_printf *pf, const struct call *call);
111 void call_set_handlers(struct call *call, call_event_h *eh,
112 call_dtmf_h *dtmfh, void *arg);
113 uint16_t call_scode(const struct call *call);
114 uint32_t call_duration(const struct call *call);
115 uint32_t call_setup_duration(const struct call *call);
116 const char *call_id(const struct call *call);
117 const char *call_peeruri(const struct call *call);
118 const char *call_peername(const struct call *call);
119 const char *call_localuri(const struct call *call);
120 struct audio *call_audio(const struct call *call);
121 struct video *call_video(const struct call *call);
122 struct list *call_streaml(const struct call *call);
123 struct ua *call_get_ua(const struct call *call);
124 bool call_is_onhold(const struct call *call);
125 bool call_is_outgoing(const struct call *call);
126 void call_enable_rtp_timeout(struct call *call, uint32_t timeout_ms);
127 uint32_t call_linenum(const struct call *call);
128 struct call *call_find_linenum(const struct list *calls, uint32_t linenum);
129 void call_set_current(struct list *calls, struct call *call);
130
131
132 /*
133 * Conf (utils)
134 */
135
136
137 /** Defines the configuration line handler */
138 typedef int (confline_h)(const struct pl *addr, void *arg);
139
140 int conf_configure(void);
141 int conf_modules(void);
142 void conf_path_set(const char *path);
143 int conf_path_get(char *path, size_t sz);
144 int conf_parse(const char *filename, confline_h *ch, void *arg);
145 int conf_get_vidsz(const struct conf *conf, const char *name,
146 struct vidsz *sz);
147 int conf_get_sa(const struct conf *conf, const char *name, struct sa *sa);
148 bool conf_fileexist(const char *path);
149 void conf_close(void);
150 struct conf *conf_cur(void);
151
152
153 /*
154 * Config (core configuration)
155 */
156
157 /** A range of numbers */
158 struct range {
159 uint32_t min; /**< Minimum number */
160 uint32_t max; /**< Maximum number */
161 };
162
in_range(const struct range * rng,uint32_t val)163 static inline bool in_range(const struct range *rng, uint32_t val)
164 {
165 return rng ? (val >= rng->min && val <= rng->max) : false;
166 }
167
168 /** Audio transmit mode */
169 enum audio_mode {
170 AUDIO_MODE_POLL = 0, /**< Polling mode */
171 AUDIO_MODE_THREAD, /**< Use dedicated thread */
172 };
173
174
175 /** SIP User-Agent */
176 struct config_sip {
177 uint32_t trans_bsize; /**< SIP Transaction bucket size */
178 char uuid[64]; /**< Universally Unique Identifier */
179 char local[64]; /**< Local SIP Address */
180 char cert[256]; /**< SIP Certificate */
181 };
182
183 /** Call config */
184 struct config_call {
185 uint32_t local_timeout; /**< Incoming call timeout [sec] 0=off */
186 uint32_t max_calls; /**< Maximum number of calls, 0=unlimited */
187 };
188
189 /** Audio */
190 struct config_audio {
191 char audio_path[256]; /**< Audio file directory */
192 char src_mod[16]; /**< Audio source module */
193 char src_dev[128]; /**< Audio source device */
194 char play_mod[16]; /**< Audio playback module */
195 char play_dev[128]; /**< Audio playback device */
196 char alert_mod[16]; /**< Audio alert module */
197 char alert_dev[128]; /**< Audio alert device */
198 struct range srate; /**< Audio sampling rate in [Hz] */
199 struct range channels; /**< Nr. of audio channels (1=mono) */
200 uint32_t srate_play; /**< Opt. sampling rate for player */
201 uint32_t srate_src; /**< Opt. sampling rate for source */
202 uint32_t channels_play; /**< Opt. channels for player */
203 uint32_t channels_src; /**< Opt. channels for source */
204 bool src_first; /**< Audio source opened first */
205 enum audio_mode txmode; /**< Audio transmit mode */
206 bool level; /**< Enable audio level indication */
207 int src_fmt; /**< Audio source sample format */
208 int play_fmt; /**< Audio playback sample format */
209 int enc_fmt; /**< Audio encoder sample format */
210 int dec_fmt; /**< Audio decoder sample format */
211 };
212
213 #ifdef USE_VIDEO
214 /** Video */
215 struct config_video {
216 char src_mod[16]; /**< Video source module */
217 char src_dev[128]; /**< Video source device */
218 char disp_mod[16]; /**< Video display module */
219 char disp_dev[128]; /**< Video display device */
220 unsigned width, height; /**< Video resolution */
221 uint32_t bitrate; /**< Encoder bitrate in [bit/s] */
222 uint32_t fps; /**< Video framerate */
223 bool fullscreen; /**< Enable fullscreen display */
224 int enc_fmt; /**< Encoder pixelfmt (enum vidfmt) */
225 };
226 #endif
227
228 /** Audio/Video Transport */
229 struct config_avt {
230 uint8_t rtp_tos; /**< Type-of-Service for outg. RTP */
231 struct range rtp_ports; /**< RTP port range */
232 struct range rtp_bw; /**< RTP Bandwidth range [bit/s] */
233 bool rtcp_enable; /**< RTCP is enabled */
234 bool rtcp_mux; /**< RTP/RTCP multiplexing */
235 struct range jbuf_del; /**< Delay, number of frames */
236 bool rtp_stats; /**< Enable RTP statistics */
237 uint32_t rtp_timeout; /**< RTP Timeout in seconds (0=off) */
238 };
239
240 /* Network */
241 struct config_net {
242 char ifname[16]; /**< Bind to interface (optional) */
243 struct {
244 char addr[64];
245 } nsv[NET_MAX_NS]; /**< Configured DNS nameservers */
246 size_t nsc; /**< Number of DNS nameservers */
247 };
248
249 #ifdef USE_VIDEO
250 /* BFCP */
251 struct config_bfcp {
252 char proto[16]; /**< BFCP Transport (optional) */
253 };
254 #endif
255
256 /** SDP */
257 struct config_sdp {
258 bool ebuacip; /**< Enable EBU-ACIP parameters */
259 };
260
261
262 /** Core configuration */
263 struct config {
264
265 struct config_sip sip;
266
267 struct config_call call;
268
269 struct config_audio audio;
270
271 #ifdef USE_VIDEO
272 struct config_video video;
273 #endif
274 struct config_avt avt;
275
276 struct config_net net;
277
278 #ifdef USE_VIDEO
279 struct config_bfcp bfcp;
280 #endif
281
282 struct config_sdp sdp;
283 };
284
285 int config_parse_conf(struct config *cfg, const struct conf *conf);
286 int config_print(struct re_printf *pf, const struct config *cfg);
287 int config_write_template(const char *file, const struct config *cfg);
288 struct config *conf_config(void);
289
290
291 /*
292 * Contact
293 */
294
295 enum presence_status {
296 PRESENCE_UNKNOWN,
297 PRESENCE_OPEN,
298 PRESENCE_CLOSED,
299 PRESENCE_BUSY
300 };
301
302
303 struct contact;
304 typedef void (contact_update_h)(struct contact *c, bool removed, void *arg);
305
306 struct contacts {
307 struct list cl;
308 struct hash *cht;
309
310 contact_update_h *handler;
311 void* handler_arg;
312 };
313
314
315 int contact_init(struct contacts *contacts);
316 void contact_close(struct contacts *contacts);
317 int contact_add(struct contacts *contacts,
318 struct contact **contactp, const struct pl *addr);
319 void contact_remove(struct contacts *contacts, struct contact *c);
320 void contact_set_update_handler(struct contacts *contacs,
321 contact_update_h *updateh, void *arg);
322 int contacts_print(struct re_printf *pf, const struct contacts *contacts);
323 enum presence_status contact_presence(const struct contact *c);
324 void contact_set_presence(struct contact *c, enum presence_status status);
325 bool contact_block_access(const struct contacts *contacts, const char *uri);
326 struct contact *contact_find(const struct contacts *contacts,
327 const char *uri);
328 struct sip_addr *contact_addr(const struct contact *c);
329 struct list *contact_list(const struct contacts *contacts);
330 const char *contact_str(const struct contact *c);
331 const char *contact_presence_str(enum presence_status status);
332
333
334 /*
335 * Media Context
336 */
337
338 /** Media Context */
339 struct media_ctx {
340 const char *id; /**< Media Context identifier */
341 };
342
343
344 /*
345 * Message
346 */
347
348 typedef void (message_recv_h)(const struct pl *peer, const struct pl *ctype,
349 struct mbuf *body, void *arg);
350
351 struct message;
352 struct message_lsnr;
353
354 int message_init(struct message **messagep);
355 int message_listen(struct message_lsnr **lsnrp, struct message *message,
356 message_recv_h *h, void *arg);
357 int message_send(struct ua *ua, const char *peer, const char *msg,
358 sip_resp_h *resph, void *arg);
359
360
361 /*
362 * Audio Source
363 */
364
365 struct ausrc;
366 struct ausrc_st;
367
368 /** Audio Source parameters */
369 struct ausrc_prm {
370 uint32_t srate; /**< Sampling rate in [Hz] */
371 uint8_t ch; /**< Number of channels */
372 uint32_t ptime; /**< Wanted packet-time in [ms] */
373 int fmt; /**< Sample format (enum aufmt) */
374 };
375
376 typedef void (ausrc_read_h)(const void *sampv, size_t sampc, void *arg);
377 typedef void (ausrc_error_h)(int err, const char *str, void *arg);
378
379 typedef int (ausrc_alloc_h)(struct ausrc_st **stp, const struct ausrc *ausrc,
380 struct media_ctx **ctx,
381 struct ausrc_prm *prm, const char *device,
382 ausrc_read_h *rh, ausrc_error_h *errh, void *arg);
383
384 int ausrc_register(struct ausrc **asp, struct list *ausrcl, const char *name,
385 ausrc_alloc_h *alloch);
386 const struct ausrc *ausrc_find(const struct list *ausrcl, const char *name);
387 int ausrc_alloc(struct ausrc_st **stp, struct list *ausrcl,
388 struct media_ctx **ctx,
389 const char *name,
390 struct ausrc_prm *prm, const char *device,
391 ausrc_read_h *rh, ausrc_error_h *errh, void *arg);
392
393
394 /*
395 * Audio Player
396 */
397
398 struct auplay;
399 struct auplay_st;
400
401 /** Audio Player parameters */
402 struct auplay_prm {
403 uint32_t srate; /**< Sampling rate in [Hz] */
404 uint8_t ch; /**< Number of channels */
405 uint32_t ptime; /**< Wanted packet-time in [ms] */
406 int fmt; /**< Sample format (enum aufmt) */
407 };
408
409 typedef void (auplay_write_h)(void *sampv, size_t sampc, void *arg);
410
411 typedef int (auplay_alloc_h)(struct auplay_st **stp, const struct auplay *ap,
412 struct auplay_prm *prm, const char *device,
413 auplay_write_h *wh, void *arg);
414
415 int auplay_register(struct auplay **pp, struct list *auplayl,
416 const char *name, auplay_alloc_h *alloch);
417 const struct auplay *auplay_find(const struct list *auplayl, const char *name);
418 int auplay_alloc(struct auplay_st **stp, struct list *auplayl,
419 const char *name,
420 struct auplay_prm *prm, const char *device,
421 auplay_write_h *wh, void *arg);
422
423
424 /*
425 * Audio Filter
426 */
427
428 struct aufilt;
429
430 /* Base class */
431 struct aufilt_enc_st {
432 const struct aufilt *af;
433 struct le le;
434 };
435
436 struct aufilt_dec_st {
437 const struct aufilt *af;
438 struct le le;
439 };
440
441 /** Audio Filter Parameters */
442 struct aufilt_prm {
443 uint32_t srate; /**< Sampling rate in [Hz] */
444 uint8_t ch; /**< Number of channels */
445 uint32_t ptime; /**< Wanted packet-time in [ms] */
446 };
447
448 typedef int (aufilt_encupd_h)(struct aufilt_enc_st **stp, void **ctx,
449 const struct aufilt *af, struct aufilt_prm *prm);
450 typedef int (aufilt_encode_h)(struct aufilt_enc_st *st,
451 int16_t *sampv, size_t *sampc);
452
453 typedef int (aufilt_decupd_h)(struct aufilt_dec_st **stp, void **ctx,
454 const struct aufilt *af, struct aufilt_prm *prm);
455 typedef int (aufilt_decode_h)(struct aufilt_dec_st *st,
456 int16_t *sampv, size_t *sampc);
457
458 struct aufilt {
459 struct le le;
460 const char *name;
461 aufilt_encupd_h *encupdh;
462 aufilt_encode_h *ench;
463 aufilt_decupd_h *decupdh;
464 aufilt_decode_h *dech;
465 };
466
467 void aufilt_register(struct list *aufiltl, struct aufilt *af);
468 void aufilt_unregister(struct aufilt *af);
469
470
471 /*
472 * Log
473 */
474
475 enum log_level {
476 LEVEL_DEBUG = 0,
477 LEVEL_INFO,
478 LEVEL_WARN,
479 LEVEL_ERROR,
480 };
481
482 typedef void (log_h)(uint32_t level, const char *msg);
483
484 struct log {
485 struct le le;
486 log_h *h;
487 };
488
489 void log_register_handler(struct log *logh);
490 void log_unregister_handler(struct log *logh);
491 void log_enable_debug(bool enable);
492 void log_enable_info(bool enable);
493 void log_enable_stdout(bool enable);
494 void vlog(enum log_level level, const char *fmt, va_list ap);
495 void loglv(enum log_level level, const char *fmt, ...);
496 void debug(const char *fmt, ...);
497 void info(const char *fmt, ...);
498 void warning(const char *fmt, ...);
499 void error_msg(const char *fmt, ...);
500
501
502 /*
503 * Menc - Media encryption (for RTP)
504 */
505
506 struct menc;
507 struct menc_sess;
508 struct menc_media;
509
510
511 typedef void (menc_error_h)(int err, void *arg);
512
513 typedef int (menc_sess_h)(struct menc_sess **sessp, struct sdp_session *sdp,
514 bool offerer, menc_error_h *errorh, void *arg);
515
516 typedef int (menc_media_h)(struct menc_media **mp, struct menc_sess *sess,
517 struct rtp_sock *rtp, int proto,
518 void *rtpsock, void *rtcpsock,
519 struct sdp_media *sdpm);
520
521 struct menc {
522 struct le le;
523 const char *id;
524 const char *sdp_proto;
525 menc_sess_h *sessh;
526 menc_media_h *mediah;
527 };
528
529 void menc_register(struct list *mencl, struct menc *menc);
530 void menc_unregister(struct menc *menc);
531 const struct menc *menc_find(const struct list *mencl, const char *id);
532
533
534 /*
535 * Net - Networking
536 */
537
538 struct network;
539
540 typedef void (net_change_h)(void *arg);
541
542 int net_alloc(struct network **netp, const struct config_net *cfg, int af);
543 int net_use_nameserver(struct network *net, const struct sa *ns);
544 void net_change(struct network *net, uint32_t interval,
545 net_change_h *ch, void *arg);
546 void net_force_change(struct network *net);
547 bool net_check(struct network *net);
548 int net_af(const struct network *net);
549 int net_debug(struct re_printf *pf, const struct network *net);
550 const struct sa *net_laddr_af(const struct network *net, int af);
551 const char *net_domain(const struct network *net);
552 struct dnsc *net_dnsc(const struct network *net);
553
554
555 /*
556 * Play - audio file player
557 */
558
559 struct play;
560 struct player;
561
562 int play_file(struct play **playp, struct player *player,
563 const char *filename, int repeat);
564 int play_tone(struct play **playp, struct player *player,
565 struct mbuf *tone,
566 uint32_t srate, uint8_t ch, int repeat);
567 int play_init(struct player **playerp);
568 void play_set_path(struct player *player, const char *path);
569
570
571 /*
572 * User Agent
573 */
574
575 struct ua;
576
577 /** Events from User-Agent */
578 enum ua_event {
579 UA_EVENT_REGISTERING = 0,
580 UA_EVENT_REGISTER_OK,
581 UA_EVENT_REGISTER_FAIL,
582 UA_EVENT_UNREGISTERING,
583 UA_EVENT_SHUTDOWN,
584 UA_EVENT_EXIT,
585
586 UA_EVENT_CALL_INCOMING,
587 UA_EVENT_CALL_RINGING,
588 UA_EVENT_CALL_PROGRESS,
589 UA_EVENT_CALL_ESTABLISHED,
590 UA_EVENT_CALL_CLOSED,
591 UA_EVENT_CALL_TRANSFER_FAILED,
592 UA_EVENT_CALL_DTMF_START,
593 UA_EVENT_CALL_DTMF_END,
594 UA_EVENT_CALL_RTCP,
595
596 UA_EVENT_MAX,
597 };
598
599 /** Video mode */
600 enum vidmode {
601 VIDMODE_OFF = 0, /**< Video disabled */
602 VIDMODE_ON, /**< Video enabled */
603 };
604
605 /** Defines the User-Agent event handler */
606 typedef void (ua_event_h)(struct ua *ua, enum ua_event ev,
607 struct call *call, const char *prm, void *arg);
608 typedef void (options_resp_h)(int err, const struct sip_msg *msg, void *arg);
609
610 typedef void (ua_exit_h)(void *arg);
611
612 /* Multiple instances */
613 int ua_alloc(struct ua **uap, const char *aor);
614 int ua_connect(struct ua *ua, struct call **callp,
615 const char *from_uri, const char *uri,
616 const char *params, enum vidmode vmode);
617 void ua_hangup(struct ua *ua, struct call *call,
618 uint16_t scode, const char *reason);
619 int ua_answer(struct ua *ua, struct call *call);
620 int ua_progress(struct ua *ua, struct call *call);
621 int ua_hold_answer(struct ua *ua, struct call *call);
622 int ua_options_send(struct ua *ua, const char *uri,
623 options_resp_h *resph, void *arg);
624 int ua_debug(struct re_printf *pf, const struct ua *ua);
625 int ua_print_calls(struct re_printf *pf, const struct ua *ua);
626 int ua_print_status(struct re_printf *pf, const struct ua *ua);
627 int ua_print_supported(struct re_printf *pf, const struct ua *ua);
628 int ua_register(struct ua *ua);
629 void ua_unregister(struct ua *ua);
630 bool ua_isregistered(const struct ua *ua);
631 void ua_pub_gruu_set(struct ua *ua, const struct pl *pval);
632 const char *ua_aor(const struct ua *ua);
633 const char *ua_cuser(const struct ua *ua);
634 const char *ua_local_cuser(const struct ua *ua);
635 struct account *ua_account(const struct ua *ua);
636 const char *ua_outbound(const struct ua *ua);
637 struct call *ua_call(const struct ua *ua);
638 struct call *ua_prev_call(const struct ua *ua);
639 struct list *ua_calls(const struct ua *ua);
640 enum presence_status ua_presence_status(const struct ua *ua);
641 void ua_presence_status_set(struct ua *ua, const enum presence_status status);
642 void ua_set_media_af(struct ua *ua, int af_media);
643
644
645 /* One instance */
646 int ua_init(const char *software, bool udp, bool tcp, bool tls,
647 bool prefer_ipv6);
648 void ua_close(void);
649 void ua_stop_all(bool forced);
650 void uag_set_exit_handler(ua_exit_h *exith, void *arg);
651 int uag_reset_transp(bool reg, bool reinvite);
652 int uag_event_register(ua_event_h *eh, void *arg);
653 void uag_event_unregister(ua_event_h *eh);
654 void uag_set_sub_handler(sip_msg_h *subh);
655 int ua_print_sip_status(struct re_printf *pf, void *unused);
656 int uag_set_extra_params(const char *eprm);
657 struct ua *uag_find(const struct pl *cuser);
658 struct ua *uag_find_aor(const char *aor);
659 struct ua *uag_find_param(const char *name, const char *val);
660 struct sip *uag_sip(void);
661 const char *uag_event_str(enum ua_event ev);
662 struct list *uag_list(void);
663 void uag_current_set(struct ua *ua);
664 struct ua *uag_current(void);
665 struct sipsess_sock *uag_sipsess_sock(void);
666 struct sipevent_sock *uag_sipevent_sock(void);
667
668
669 /*
670 * User Interface
671 */
672
673 struct ui_sub {
674 struct list uil; /**< List of UIs (struct ui) */
675 struct cmd_ctx *uictx;
676 };
677
678 typedef int (ui_output_h)(const char *str);
679
680 /** Defines a User-Interface module */
681 struct ui {
682 struct le le; /**< Linked-list element */
683 const char *name; /**< Name of the UI-module */
684 ui_output_h *outputh; /**< Handler for output strings (optional) */
685 };
686
687 void ui_register(struct ui_sub *uis, struct ui *ui);
688 void ui_unregister(struct ui *ui);
689
690 void ui_reset(struct ui_sub *uis);
691 void ui_input_key(struct ui_sub *uis, char key, struct re_printf *pf);
692 void ui_input_str(const char *str);
693 int ui_input_pl(struct re_printf *pf, const struct pl *pl);
694 void ui_output(struct ui_sub *uis, const char *fmt, ...);
695 bool ui_isediting(const struct ui_sub *uis);
696 int ui_password_prompt(char **passwordp);
697
698
699 /*
700 * Command interface
701 */
702
703 /* special keys */
704 #define KEYCODE_NONE (0x00)
705 #define KEYCODE_REL (0x04) /* Key was released */
706 #define KEYCODE_ESC (0x1b)
707
708
709 /** Command flags */
710 enum {
711 CMD_PRM = (1<<0), /**< Command with parameter */
712 CMD_PROG = (1<<1), /**< Show progress */
713
714 CMD_IPRM = CMD_PRM | CMD_PROG, /**< Interactive parameter */
715 };
716
717 /** Command arguments */
718 struct cmd_arg {
719 char key; /**< Which key was pressed */
720 char *prm; /**< Optional parameter */
721 bool complete; /**< True if complete */
722 void *data; /**< Application data */
723 };
724
725 /** Defines a command */
726 struct cmd {
727 const char *name; /**< Long command */
728 char key; /**< Short command */
729 int flags; /**< Optional command flags */
730 const char *desc; /**< Description string */
731 re_printf_h *h; /**< Command handler */
732 };
733
734 struct cmd_ctx;
735 struct commands;
736
737
738 int cmd_init(struct commands **commandsp);
739 int cmd_register(struct commands *commands,
740 const struct cmd *cmdv, size_t cmdc);
741 void cmd_unregister(struct commands *commands, const struct cmd *cmdv);
742 int cmd_process(struct commands *commands, struct cmd_ctx **ctxp, char key,
743 struct re_printf *pf, void *data);
744 int cmd_process_long(struct commands *commands, const char *str, size_t len,
745 struct re_printf *pf_resp, void *data);
746 int cmd_print(struct re_printf *pf, const struct commands *commands);
747 const struct cmd *cmd_find_long(const struct commands *commands,
748 const char *name);
749 struct cmds *cmds_find(const struct commands *commands,
750 const struct cmd *cmdv);
751
752
753 /*
754 * Video Source
755 */
756
757 struct vidsrc;
758 struct vidsrc_st;
759
760 /** Video Source parameters */
761 struct vidsrc_prm {
762 int orient; /**< Wanted picture orientation (enum vidorient) */
763 int fps; /**< Wanted framerate */
764 };
765
766 typedef void (vidsrc_frame_h)(struct vidframe *frame, void *arg);
767 typedef void (vidsrc_error_h)(int err, void *arg);
768
769 typedef int (vidsrc_alloc_h)(struct vidsrc_st **vsp, const struct vidsrc *vs,
770 struct media_ctx **ctx, struct vidsrc_prm *prm,
771 const struct vidsz *size,
772 const char *fmt, const char *dev,
773 vidsrc_frame_h *frameh,
774 vidsrc_error_h *errorh, void *arg);
775
776 typedef void (vidsrc_update_h)(struct vidsrc_st *st, struct vidsrc_prm *prm,
777 const char *dev);
778
779 int vidsrc_register(struct vidsrc **vp, struct list *vidsrcl, const char *name,
780 vidsrc_alloc_h *alloch, vidsrc_update_h *updateh);
781 const struct vidsrc *vidsrc_find(const struct list *vidsrcl, const char *name);
782 int vidsrc_alloc(struct vidsrc_st **stp, struct list *vidsrcl,
783 const char *name,
784 struct media_ctx **ctx, struct vidsrc_prm *prm,
785 const struct vidsz *size, const char *fmt, const char *dev,
786 vidsrc_frame_h *frameh, vidsrc_error_h *errorh, void *arg);
787
788
789 /*
790 * Video Display
791 */
792
793 struct vidisp;
794 struct vidisp_st;
795
796 /** Video Display parameters */
797 struct vidisp_prm {
798 void *view; /**< Optional view (set by application or module) */
799 bool fullscreen; /**< Enable fullscreen display */
800 };
801
802 typedef void (vidisp_resize_h)(const struct vidsz *size, void *arg);
803
804 typedef int (vidisp_alloc_h)(struct vidisp_st **vp,
805 const struct vidisp *vd, struct vidisp_prm *prm,
806 const char *dev,
807 vidisp_resize_h *resizeh, void *arg);
808 typedef int (vidisp_update_h)(struct vidisp_st *st, bool fullscreen,
809 int orient, const struct vidrect *window);
810 typedef int (vidisp_disp_h)(struct vidisp_st *st, const char *title,
811 const struct vidframe *frame);
812 typedef void (vidisp_hide_h)(struct vidisp_st *st);
813
814 int vidisp_register(struct vidisp **vp, struct list *vidispl, const char *name,
815 vidisp_alloc_h *alloch, vidisp_update_h *updateh,
816 vidisp_disp_h *disph, vidisp_hide_h *hideh);
817 int vidisp_alloc(struct vidisp_st **stp, struct list *vidispl,
818 const char *name,
819 struct vidisp_prm *prm, const char *dev,
820 vidisp_resize_h *resizeh, void *arg);
821 int vidisp_display(struct vidisp_st *st, const char *title,
822 const struct vidframe *frame);
823 const struct vidisp *vidisp_find(const struct list *vidispl, const char *name);
824
825
826 /*
827 * Audio Codec
828 */
829
830 /** Audio Codec parameters */
831 struct auenc_param {
832 uint32_t ptime; /**< Packet time in [ms] */
833 uint32_t bitrate;/**< Wanted bitrate in [bit/s] */
834 };
835
836 struct auenc_state;
837 struct audec_state;
838 struct aucodec;
839
840 typedef int (auenc_update_h)(struct auenc_state **aesp,
841 const struct aucodec *ac,
842 struct auenc_param *prm, const char *fmtp);
843 typedef int (auenc_encode_h)(struct auenc_state *aes,
844 uint8_t *buf, size_t *len,
845 int fmt, const void *sampv, size_t sampc);
846
847 typedef int (audec_update_h)(struct audec_state **adsp,
848 const struct aucodec *ac, const char *fmtp);
849 typedef int (audec_decode_h)(struct audec_state *ads,
850 int fmt, void *sampv, size_t *sampc,
851 const uint8_t *buf, size_t len);
852 typedef int (audec_plc_h)(struct audec_state *ads,
853 int fmt, void *sampv, size_t *sampc);
854
855 struct aucodec {
856 struct le le;
857 const char *pt;
858 const char *name;
859 uint32_t srate; /* Audio samplerate */
860 uint32_t crate; /* RTP Clock rate */
861 uint8_t ch;
862 const char *fmtp;
863 auenc_update_h *encupdh;
864 auenc_encode_h *ench;
865 audec_update_h *decupdh;
866 audec_decode_h *dech;
867 audec_plc_h *plch;
868 sdp_fmtp_enc_h *fmtp_ench;
869 sdp_fmtp_cmp_h *fmtp_cmph;
870 };
871
872 void aucodec_register(struct list *aucodecl, struct aucodec *ac);
873 void aucodec_unregister(struct aucodec *ac);
874 const struct aucodec *aucodec_find(const struct list *aucodecl,
875 const char *name, uint32_t srate,
876 uint8_t ch);
877
878
879 /*
880 * Video Codec
881 */
882
883 /** Video Codec parameters */
884 struct videnc_param {
885 unsigned bitrate; /**< Encoder bitrate in [bit/s] */
886 unsigned pktsize; /**< RTP packetsize in [bytes] */
887 unsigned fps; /**< Video framerate */
888 uint32_t max_fs;
889 };
890
891 struct videnc_state;
892 struct viddec_state;
893 struct vidcodec;
894
895 typedef int (videnc_packet_h)(bool marker, uint32_t rtp_ts,
896 const uint8_t *hdr, size_t hdr_len,
897 const uint8_t *pld, size_t pld_len,
898 void *arg);
899
900 typedef int (videnc_update_h)(struct videnc_state **vesp,
901 const struct vidcodec *vc,
902 struct videnc_param *prm, const char *fmtp,
903 videnc_packet_h *pkth, void *arg);
904 typedef int (videnc_encode_h)(struct videnc_state *ves, bool update,
905 const struct vidframe *frame);
906
907 typedef int (viddec_update_h)(struct viddec_state **vdsp,
908 const struct vidcodec *vc, const char *fmtp);
909 typedef int (viddec_decode_h)(struct viddec_state *vds, struct vidframe *frame,
910 bool *intra, bool marker, uint16_t seq,
911 struct mbuf *mb);
912
913 struct vidcodec {
914 struct le le;
915 const char *pt;
916 const char *name;
917 const char *variant;
918 const char *fmtp;
919 videnc_update_h *encupdh;
920 videnc_encode_h *ench;
921 viddec_update_h *decupdh;
922 viddec_decode_h *dech;
923 sdp_fmtp_enc_h *fmtp_ench;
924 sdp_fmtp_cmp_h *fmtp_cmph;
925 };
926
927 void vidcodec_register(struct list *vidcodecl, struct vidcodec *vc);
928 void vidcodec_unregister(struct vidcodec *vc);
929 const struct vidcodec *vidcodec_find(const struct list *vidcodecl,
930 const char *name, const char *variant);
931 const struct vidcodec *vidcodec_find_encoder(const struct list *vidcodecl,
932 const char *name);
933 const struct vidcodec *vidcodec_find_decoder(const struct list *vidcodecl,
934 const char *name);
935
936
937 /*
938 * Video Filter
939 */
940
941 struct vidfilt;
942
943 /* Base class */
944 struct vidfilt_enc_st {
945 const struct vidfilt *vf;
946 struct le le;
947 };
948
949 struct vidfilt_dec_st {
950 const struct vidfilt *vf;
951 struct le le;
952 };
953
954 typedef int (vidfilt_encupd_h)(struct vidfilt_enc_st **stp, void **ctx,
955 const struct vidfilt *vf);
956 typedef int (vidfilt_encode_h)(struct vidfilt_enc_st *st,
957 struct vidframe *frame);
958
959 typedef int (vidfilt_decupd_h)(struct vidfilt_dec_st **stp, void **ctx,
960 const struct vidfilt *vf);
961 typedef int (vidfilt_decode_h)(struct vidfilt_dec_st *st,
962 struct vidframe *frame);
963
964 struct vidfilt {
965 struct le le;
966 const char *name;
967 vidfilt_encupd_h *encupdh;
968 vidfilt_encode_h *ench;
969 vidfilt_decupd_h *decupdh;
970 vidfilt_decode_h *dech;
971 };
972
973 void vidfilt_register(struct list *vidfiltl, struct vidfilt *vf);
974 void vidfilt_unregister(struct vidfilt *vf);
975 int vidfilt_enc_append(struct list *filtl, void **ctx,
976 const struct vidfilt *vf);
977 int vidfilt_dec_append(struct list *filtl, void **ctx,
978 const struct vidfilt *vf);
979
980
981 /*
982 * Audio stream
983 */
984
985 struct audio;
986
987 void audio_mute(struct audio *a, bool muted);
988 bool audio_ismuted(const struct audio *a);
989 void audio_set_devicename(struct audio *a, const char *src, const char *play);
990 int audio_set_source(struct audio *au, const char *mod, const char *device);
991 int audio_set_player(struct audio *au, const char *mod, const char *device);
992 void audio_encoder_cycle(struct audio *audio);
993 int audio_level_get(const struct audio *au, double *level);
994 int audio_debug(struct re_printf *pf, const struct audio *a);
995 struct stream *audio_strm(const struct audio *a);
996 int audio_set_bitrate(struct audio *au, uint32_t bitrate);
997
998
999 /*
1000 * Video stream
1001 */
1002
1003 struct video;
1004
1005 void video_mute(struct video *v, bool muted);
1006 void *video_view(const struct video *v);
1007 int video_set_fullscreen(struct video *v, bool fs);
1008 int video_set_orient(struct video *v, int orient);
1009 void video_vidsrc_set_device(struct video *v, const char *dev);
1010 int video_set_source(struct video *v, const char *name, const char *dev);
1011 void video_set_devicename(struct video *v, const char *src, const char *disp);
1012 void video_encoder_cycle(struct video *video);
1013 int video_debug(struct re_printf *pf, const struct video *v);
1014 uint32_t video_calc_rtp_timestamp(int64_t pts, unsigned fps);
1015 double video_calc_seconds(uint32_t rtp_ts);
1016 struct stream *video_strm(const struct video *v);
1017
1018
1019 /*
1020 * Generic stream
1021 */
1022
1023 const struct rtcp_stats *stream_rtcp_stats(const struct stream *strm);
1024
1025
1026 /*
1027 * Media NAT
1028 */
1029
1030 struct mnat;
1031 struct mnat_sess;
1032 struct mnat_media;
1033
1034 typedef void (mnat_estab_h)(int err, uint16_t scode, const char *reason,
1035 void *arg);
1036
1037 typedef int (mnat_sess_h)(struct mnat_sess **sessp, struct dnsc *dnsc,
1038 int af, const char *srv, uint16_t port,
1039 const char *user, const char *pass,
1040 struct sdp_session *sdp, bool offerer,
1041 mnat_estab_h *estabh, void *arg);
1042
1043 typedef int (mnat_media_h)(struct mnat_media **mp, struct mnat_sess *sess,
1044 int proto, void *sock1, void *sock2,
1045 struct sdp_media *sdpm);
1046
1047 typedef int (mnat_update_h)(struct mnat_sess *sess);
1048
1049 int mnat_register(struct mnat **mnatp, struct list *mnatl,
1050 const char *id, const char *ftag,
1051 mnat_sess_h *sessh, mnat_media_h *mediah,
1052 mnat_update_h *updateh);
1053
1054
1055 /*
1056 * Real-time
1057 */
1058 int realtime_enable(bool enable, int fps);
1059
1060
1061 /*
1062 * SDP
1063 */
1064
1065 bool sdp_media_has_media(const struct sdp_media *m);
1066 int sdp_media_find_unused_pt(const struct sdp_media *m);
1067 int sdp_fingerprint_decode(const char *attr, struct pl *hash,
1068 uint8_t *md, size_t *sz);
1069 uint32_t sdp_media_rattr_u32(const struct sdp_media *sdpm, const char *name);
1070 const char *sdp_rattr(const struct sdp_session *s, const struct sdp_media *m,
1071 const char *name);
1072
1073
1074 /*
1075 * SIP Request
1076 */
1077
1078 int sip_req_send(struct ua *ua, const char *method, const char *uri,
1079 sip_resp_h *resph, void *arg, const char *fmt, ...);
1080
1081
1082 /*
1083 * H.264
1084 */
1085
1086 /** NAL unit types (RFC 3984, Table 1) */
1087 enum {
1088 H264_NAL_UNKNOWN = 0,
1089 /* 1-23 NAL unit Single NAL unit packet per H.264 */
1090 H264_NAL_SLICE = 1,
1091 H264_NAL_DPA = 2,
1092 H264_NAL_DPB = 3,
1093 H264_NAL_DPC = 4,
1094 H264_NAL_IDR_SLICE = 5,
1095 H264_NAL_SEI = 6,
1096 H264_NAL_SPS = 7,
1097 H264_NAL_PPS = 8,
1098 H264_NAL_AUD = 9,
1099 H264_NAL_END_SEQUENCE = 10,
1100 H264_NAL_END_STREAM = 11,
1101 H264_NAL_FILLER_DATA = 12,
1102 H264_NAL_SPS_EXT = 13,
1103 H264_NAL_AUX_SLICE = 19,
1104
1105 H264_NAL_STAP_A = 24, /**< Single-time aggregation packet */
1106 H264_NAL_STAP_B = 25, /**< Single-time aggregation packet */
1107 H264_NAL_MTAP16 = 26, /**< Multi-time aggregation packet */
1108 H264_NAL_MTAP24 = 27, /**< Multi-time aggregation packet */
1109 H264_NAL_FU_A = 28, /**< Fragmentation unit */
1110 H264_NAL_FU_B = 29, /**< Fragmentation unit */
1111 };
1112
1113 /**
1114 * H.264 Header defined in RFC 3984
1115 *
1116 * <pre>
1117 +---------------+
1118 |0|1|2|3|4|5|6|7|
1119 +-+-+-+-+-+-+-+-+
1120 |F|NRI| Type |
1121 +---------------+
1122 * </pre>
1123 */
1124 struct h264_hdr {
1125 unsigned f:1; /**< 1 bit - Forbidden zero bit (must be 0) */
1126 unsigned nri:2; /**< 2 bits - nal_ref_idc */
1127 unsigned type:5; /**< 5 bits - nal_unit_type */
1128 };
1129
1130 int h264_hdr_encode(const struct h264_hdr *hdr, struct mbuf *mb);
1131 int h264_hdr_decode(struct h264_hdr *hdr, struct mbuf *mb);
1132
1133 /** Fragmentation Unit header */
1134 struct h264_fu {
1135 unsigned s:1; /**< Start bit */
1136 unsigned e:1; /**< End bit */
1137 unsigned r:1; /**< The Reserved bit MUST be equal to 0 */
1138 unsigned type:5; /**< The NAL unit payload type */
1139 };
1140
1141 int h264_fu_hdr_encode(const struct h264_fu *fu, struct mbuf *mb);
1142 int h264_fu_hdr_decode(struct h264_fu *fu, struct mbuf *mb);
1143
1144 const uint8_t *h264_find_startcode(const uint8_t *p, const uint8_t *end);
1145
1146 int h264_packetize(uint32_t rtp_ts, const uint8_t *buf, size_t len,
1147 size_t pktsize, videnc_packet_h *pkth, void *arg);
1148 int h264_nal_send(bool first, bool last,
1149 bool marker, uint32_t ihdr, uint32_t rtp_ts,
1150 const uint8_t *buf, size_t size, size_t maxsz,
1151 videnc_packet_h *pkth, void *arg);
h264_is_keyframe(int type)1152 static inline bool h264_is_keyframe(int type)
1153 {
1154 return type == H264_NAL_SPS;
1155 }
1156
1157
1158 /*
1159 * Modules
1160 */
1161
1162 #ifdef STATIC
1163 #define DECL_EXPORTS(name) exports_ ##name
1164 #else
1165 #define DECL_EXPORTS(name) exports
1166 #endif
1167
1168
1169 int module_preload(const char *module);
1170 int module_load(const char *name);
1171 void module_unload(const char *name);
1172
1173
1174 /*
1175 * MOS (Mean Opinion Score)
1176 */
1177
1178 double mos_calculate(double *r_factor, double rtt,
1179 double jitter, uint32_t num_packets_lost);
1180
1181
1182 /*
1183 * Generic event
1184 */
1185
1186 int event_encode_dict(struct odict *od, struct ua *ua, enum ua_event ev,
1187 struct call *call, const char *prm);
1188
1189
1190 /*
1191 * Baresip instance
1192 */
1193
1194 int baresip_init(struct config *cfg, bool prefer_ipv6);
1195 void baresip_close(void);
1196 struct network *baresip_network(void);
1197 struct contacts *baresip_contacts(void);
1198 struct commands *baresip_commands(void);
1199 struct player *baresip_player(void);
1200 struct message *baresip_message(void);
1201 struct list *baresip_mnatl(void);
1202 struct list *baresip_mencl(void);
1203 struct list *baresip_aucodecl(void);
1204 struct list *baresip_ausrcl(void);
1205 struct list *baresip_auplayl(void);
1206 struct list *baresip_aufiltl(void);
1207 struct list *baresip_vidcodecl(void);
1208 struct list *baresip_vidsrcl(void);
1209 struct list *baresip_vidispl(void);
1210 struct list *baresip_vidfiltl(void);
1211 struct ui_sub *baresip_uis(void);
1212
1213
1214 #ifdef __cplusplus
1215 }
1216 #endif
1217
1218
1219 #endif /* BARESIP_H__ */
1220