diff options
| -rw-r--r-- | PICA_client.c | 79 | ||||
| -rw-r--r-- | PICA_client.h | 34 | ||||
| -rw-r--r-- | PICA_proto.h | 5 | ||||
| -rw-r--r-- | doc/proto-doc-audiovideo.txt | 8 |
4 files changed, 124 insertions, 2 deletions
diff --git a/PICA_client.c b/PICA_client.c index 14d2082..4f814db 100644 --- a/PICA_client.c +++ b/PICA_client.c @@ -3403,6 +3403,85 @@ int PICA_send_file_fragment(struct PICA_c2c *chn) return PICA_OK; } + +int PICA_start_call(struct PICA_c2c *chn) +{ + struct PICA_proto_msg *mp; + + if (chn->call_state != PICA_CALL_STATE_IDLE) + return PICA_ERRCALLINPROGRESS; + + if ((mp = c2c_writebuf_push(chn, PICA_PROTO_CALLREQ, PICA_PROTO_CALLREQ_SIZE))) + { + RAND_pseudo_bytes(mp->tail, 2); + } + else + { + return PICA_ERRNOMEM; + } + + return PICA_OK; +} + +int PICA_pickup_call(struct PICA_c2c *chn) +{ + struct PICA_proto_msg *mp; + + if (chn->call_state != PICA_CALL_STATE_INCOMINGCALL) + return PICA_ERRCALLNOTINPROGRESS; + + if ((mp = c2c_writebuf_push(chn, PICA_PROTO_CALLANS, PICA_PROTO_CALLANS_SIZE))) + { + RAND_pseudo_bytes(mp->tail, 2); + } + else + { + return PICA_ERRNOMEM; + } + + return PICA_OK; +} + +int PICA_reject_call(struct PICA_c2c *chn) +{ + struct PICA_proto_msg *mp; + + if (chn->call_state != PICA_CALL_STATE_INCOMINGCALL) + return PICA_ERRCALLNOTINPROGRESS; + + if ((mp = c2c_writebuf_push(chn, PICA_PROTO_CALLREJ, PICA_PROTO_CALLREJ_SIZE))) + { + RAND_pseudo_bytes(mp->tail, 2); + } + else + { + return PICA_ERRNOMEM; + } + + return PICA_OK; +} + +int PICA_hangup_call(struct PICA_c2c *chn) +{ + struct PICA_proto_msg *mp; + + if (chn->call_state != PICA_CALL_STATE_ACTIVE) + return PICA_ERRCALLNOTINPROGRESS; + + if ((mp = c2c_writebuf_push(chn, PICA_PROTO_CALLFIN, PICA_PROTO_CALLFIN_SIZE))) + { + RAND_pseudo_bytes(mp->tail, 2); + } + else + { + return PICA_ERRNOMEM; + } + + // release call resources?? + // handle incoming last stream packets? + return PICA_OK; +} + void PICA_close_directc2c(struct PICA_directc2c *d) { PICA_TRACEFUNC diff --git a/PICA_client.h b/PICA_client.h index eca7178..98df947 100644 --- a/PICA_client.h +++ b/PICA_client.h @@ -118,6 +118,9 @@ typedef u_short in_port_t; #define PICA_ERRINVPKEYFILE -23 #define PICA_ERRTIMEDOUT -24 +#define PICA_ERRCALLINPROGRESS -25 +#define PICA_ERRCALLNOTINPROGRESS -26 + //#define PICA_CHNMSGBUFLEN 104 #define PICA_CHANREADBUFSIZE 65536 @@ -239,6 +242,14 @@ enum PICA_directc2c_connection_state PICA_DIRECTC2C_CONNSTATE_FAILED }; +enum PICA_call_state +{ + PICA_CALL_STATE_IDLE = 0, + PICA_CALL_STATE_CALLING, + PICA_CALL_STATE_INCOMINGCALL, + PICA_CALL_STATE_ACTIVE +}; + struct PICA_directc2c { int is_outgoing; @@ -301,6 +312,8 @@ struct PICA_c2c int want_write; unsigned int directc2c_write_barrier_pos; unsigned int directc2c_write_before_barrier_pos; + + enum PICA_call_state call_state; }; struct PICA_listener @@ -396,6 +409,22 @@ struct PICA_client_callbacks void (*multilogin_cb)(uint64_t timestamp, void *addr_bin, const char *addr_str, uint16_t port); void (*direct_c2c_established_cb)(const unsigned char *peer_id, const char *ciphersuitename); + + void (*incoming_call_cb)(const unsigned char *peer_id); + + void (*call_picked_up_cb)(const unsigned char *peer_id); + + void (*call_rejected_cb)(const unsigned char *peer_id); + + void (*call_hangup_cb)(const unsigned char *peer_id); + + void (*call_audio_params_cb)(const unsigned char *peer_id, const char *codec, uint16_t sample_rate); + + void (*call_video_params_cb)(const unsigned char *peer_id, const char *codec, uint16_t width, uint16_t height); + + void (*call_audio_packet_cb)(const unsigned char *peer_id, uint16_t size, const char *pkt_data); + + void (*call_video_packet_cb)(const unsigned char *peer_id, uint16_t size, const char *pkt_data); }; @@ -455,6 +484,11 @@ int PICA_pause_file(struct PICA_c2c *chan, int sending); int PICA_resume_file(struct PICA_c2c *chan, int sending); int PICA_cancel_file(struct PICA_c2c *chan, int sending); +int PICA_start_call(struct PICA_c2c *chn); +int PICA_pickup_call(struct PICA_c2c *chn); +int PICA_reject_call(struct PICA_c2c *chn); +int PICA_hangup_call(struct PICA_c2c *chn); + void PICA_close_c2c(struct PICA_c2c *chn); void PICA_close_c2n(struct PICA_c2n *cid); void PICA_close_directc2c(struct PICA_directc2c *d); diff --git a/PICA_proto.h b/PICA_proto.h index 3691c0e..3efe5e0 100644 --- a/PICA_proto.h +++ b/PICA_proto.h @@ -147,6 +147,11 @@ #define PICA_PROTO_N2NALLOW_SIZE 58 #define PICA_PROTO_N2NNOTFOUND_SIZE 58 +#define PICA_PROTO_CALLREQ_SIZE 4 +#define PICA_PROTO_CALLANS_SIZE 4 +#define PICA_PROTO_CALLREJ_SIZE 4 +#define PICA_PROTO_CALLFIN_SIZE 4 + #define PICA_PROTO_N2NMSG_MAXDATASIZE 65476 #define PICA_PROTO_C2CMSG_MAXDATASIZE 65532 #define PICA_PROTO_C2CMSG_MAXFILENAMESIZE 255 diff --git a/doc/proto-doc-audiovideo.txt b/doc/proto-doc-audiovideo.txt index 11e65b7..4ccc667 100644 --- a/doc/proto-doc-audiovideo.txt +++ b/doc/proto-doc-audiovideo.txt @@ -2,15 +2,19 @@ Audio and Video Calls. Call request (ring) [0x70 0x70] +[2 pseudo-random octets] Call answer (pick up) [0x71 0x71] +[2 pseudo-random octets] Call reject [0x72 0x72] +[2 pseudo-random octets] Call hang up (finished) [0x73 0x73] +[2 pseudo-random octets] Audio stream parameters [0x74 0x74] @@ -26,9 +30,9 @@ Video stream parameters [height, uint16_t, little-endian] Voice (audio) packet -[0x76 0x76][length 2 octets][PTS][data] +[0x76 0x76][length 2 octets][data] Video packet -[0x77 0x77][length 2 octets][PTS][data] +[0x77 0x77][length 2 octets][data] |
