summaryrefslogtreecommitdiffstats
path: root/src/telephone/telephone.h
blob: 4c7dfa08c0993b2906fce84a330b56b48e825c97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
#include "../libtimer/timer.h"
#include "../libosmocc/endpoint.h"
#include "../libsample/sample.h"
#include "../libsamplerate/samplerate.h"
#include "../libjitter/jitter.h"

enum call_state {
	CALL_STATE_IDLE = 0,    /* no call */
	CALL_STATE_IN_SETUP,    /* incoming connection */
	CALL_STATE_OUT_SETUP,   /* outgoing connection */
	CALL_STATE_IN_OVERLAP,  /* more informatiopn needed */
	CALL_STATE_OUT_OVERLAP, /* more informatiopn needed */
	CALL_STATE_IN_PROCEEDING,/* call is proceeding */
	CALL_STATE_OUT_PROCEEDING,/* call is proceeding */
	CALL_STATE_IN_ALERTING, /* call is ringing */
	CALL_STATE_OUT_ALERTING,/* call is ringing */
	CALL_STATE_CONNECT,     /* call is connected and transmission is enabled */
	CALL_STATE_IN_DISCONNECT,/* incoming disconnected */
	CALL_STATE_OUT_DISCONNECT,/* outgoing disconnected */
};

struct telephone;

struct call_list;

typedef struct telephone {
	osmo_cc_endpoint_t cc_ep;
	struct call_list *call_list;
	const char *name;

	/* settings */
	int serving_location; /* who we serve when sending causes towards interface */
	int early_audio;

	/* sound */
	int loopback;
	int samplerate;		/* sample rate of headphone interface */
	int latspl;
	void *sound;		/* headphone interface */

} telephone_t;

typedef struct call_list {
	struct call_list *next;
        telephone_t *telephone_ep;

	/* alsa states */

	/* osmo-cc states */
	uint32_t cc_callref;
	const char *sdp;
	osmo_cc_session_t *cc_session;
	osmo_cc_session_codec_t *codec;
	int codec_negotiated;

	/* call states */
	enum call_state state;

	/* audio states */
	jitter_t dejitter;
	samplerate_t srstate;
	sample_t tx_buffer[160]; /* transmit audio buffer */
        int tx_buffer_pos; /* current position in transmit audio buffer */
} call_t;

void telephone_destroy(telephone_t *telephone_ep);
telephone_t *telephone_create(void);
int telephone_init(telephone_t *telephone_ep, const char *name, const char *callerid, uint8_t serving_location, int early_audio, const char *audiodev, int samplerate, int __attribute__((unused)) latspl);
void cc_message(osmo_cc_endpoint_t *ep, uint32_t callref, osmo_cc_msg_t *msg);
int ui_init(const char *remote_id, int autoalert, int autoanswer);
int ui_work(telephone_t *telephone_ep, int c);
void alsa_work(telephone_t *telephone_ep);
void rtp_work(telephone_t *telephone_ep);