diff --git a/libvoice/libvoice.h b/libvoice/libvoice.h index 5ac21db8289c4ed7d8660802360a64f0b162f092..77f92f625e11708c7b77d9869f3434bda6650537 100644 --- a/libvoice/libvoice.h +++ b/libvoice/libvoice.h @@ -223,6 +223,16 @@ enum VOICE_CODEC { VOICE_CODEC_G729, }; +#define UBUS_DATA_CODEC_BIT 1 +#define UBUS_DATA_PTIME_BIT (1<<1) +struct config_update_struct { + uint8_t mask; // 8 bit mask + enum VOICE_CODEC codec; + int ptime; + // add more if needed +}; + + #define ENABLE_VOICE_DEBUG 0 // Enable/disable voice debug #if ENABLE_VOICE_DEBUG // log to file @@ -267,7 +277,7 @@ int voice_connection_close_all(void); int voice_connection_conference_start(int line, int connection); int voice_connection_conference_stop(int line, int connection); int voice_connection_find(int line, int connection); -int voice_connection_set_codec(int line, int connection, enum VOICE_CODEC codec); +int voice_connection_parm_update(int line, int connection, struct config_update_struct *data); // Line API int voice_line_preinit(void); int voice_line_init(int has_dect); diff --git a/line.c b/line.c index e6845e175bb70c4bbb90f3ae3f46801aef00f551..ed46172c9431d7402278f26bc9ce11bf4247aee0 100644 --- a/line.c +++ b/line.c @@ -353,17 +353,16 @@ int line_new_connection_by_asterisk(int line, int connection, struct voice_ubus_ } //--------------------------------------------------------------------------------------------------- -// Reception of a modify connection request from Asterisk. -int line_connection_modify_codec_by_asterisk(int line, int connection, enum VOICE_CODEC codec) { +// Reception of a connection parameter update request from Asterisk. +int line_connection_parm_update_by_asterisk(int line, int connection, struct config_update_struct *data) { int res = 0; if (!voice_line_is_ready(line)) return -1; - - ENDPT_DBG("%s line: %d, connection: %d, codec: %d\n", __func__, line, connection, codec); + ENDPT_DBG("parm_update request for %s line: %d, connection: %d, mask: %d, codec: %d, ptime: %d \n", __func__, line, connection, data->mask, data->codec, data->ptime); pcm_states_dump(__func__, line); - res = voice_connection_set_codec(line, line, codec); + res = voice_connection_parm_update(line, line, data); return res; } diff --git a/line.h b/line.h index a616218e7a714daf08b756b916f2dd1565441d4c..17c1253653aa1abf0db766099ee3c5d034cf40b8 100644 --- a/line.h +++ b/line.h @@ -56,7 +56,7 @@ int line_close_connection_by_asterisk(int line, int connection, struct voice_ubu int line_release_connection_by_asterisk(int line, int connection, struct voice_ubus_req_t *ubus_req); int line_update_connection_by_pbx(int line, int pcm_callid); int line_new_connection_by_dect(int line, const char *cid, int pcm, struct voice_ubus_req_t *ubus_req); -int line_connection_modify_codec_by_asterisk(int line, int connection, enum VOICE_CODEC codec); +int line_connection_parm_update_by_asterisk(int line, int connection, struct config_update_struct *data); int line_close_connection_by_dect(int line, int pcm, struct voice_ubus_req_t *ubus_req); int line_signal(int line, const char *signame, const char *data, struct voice_ubus_req_t *ubus_req); void pcm_states_dump(const char* func, int line); diff --git a/ubus.c b/ubus.c index e15d03d7c3d86a4e3f264570d68b5ebc2586bf0a..e971880933d65f988a28a56ccb1f34473adb9518 100644 --- a/ubus.c +++ b/ubus.c @@ -39,7 +39,8 @@ enum { CONNECTION_LINE, CONNECTION_ID, CONNECTION_ACTION, - CONNECTION_DATA, + CONNECTION_DATA_CODEC, + CONNECTION_DATA_PTIME, __CONNECTION_MAX, }; @@ -140,7 +141,8 @@ static const struct blobmsg_policy request_connection_policy[] = { [CONNECTION_LINE] = { .name = "line", .type = BLOBMSG_TYPE_INT32 }, [CONNECTION_ID] = { .name = "id", .type = BLOBMSG_TYPE_INT32 }, // rtp stream connection identifier (unique number generated by asterisk) [CONNECTION_ACTION] = { .name = "action", .type = BLOBMSG_TYPE_STRING }, - [CONNECTION_DATA] = { .name = "data", .type = BLOBMSG_TYPE_STRING }, + [CONNECTION_DATA_CODEC] = { .name = "codec", .type = BLOBMSG_TYPE_INT32 }, + [CONNECTION_DATA_PTIME] = { .name = "ptime", .type = BLOBMSG_TYPE_INT32 }, }; static const struct blobmsg_policy request_count_policy[] = { @@ -552,25 +554,6 @@ static int ubus_request_signal(struct ubus_context *uctx, struct ubus_object *ob return UBUS_STATUS_OK; } -// codec data string to codec enum -static enum VOICE_CODEC codec_string_to_enum(char *data){ - if (strcmp(data, "ulaw") == 0) { - return VOICE_CODEC_G711U; - } else if (strcmp(data, "alaw") == 0) { - return VOICE_CODEC_G711A; - } else if (strcmp(data, "g722") == 0) { - return VOICE_CODEC_G722; - } else if (strcmp(data, "g723") == 0) { - return VOICE_CODEC_G723; - } else if (strcmp(data, "g726") == 0) { - return VOICE_CODEC_G726; - } else if (strcmp(data, "g729") == 0) { - return VOICE_CODEC_G729; - } else { - return VOICE_CODEC_G711A; - } -} - // Reception of ubus call endpt connection '{ "line" : 1 , "id" : 0, "action" : "create" }' static int ubus_request_connection(struct ubus_context *uctx, struct ubus_object *obj __attribute__((unused)), struct ubus_request_data *req, const char *method __attribute__((unused)), @@ -579,7 +562,7 @@ static int ubus_request_connection(struct ubus_context *uctx, struct ubus_object struct blob_attr *keys[__CONNECTION_MAX]; struct voice_ubus_req_t ubusReq; int line, id; - char *action_str, *data; + char *action_str; if(blobmsg_parse(request_connection_policy, __CONNECTION_MAX, keys, blob_data(msg), blob_len(msg))) { @@ -612,10 +595,21 @@ static int ubus_request_connection(struct ubus_context *uctx, struct ubus_object ubusReq.reqIn = req; action_str = blobmsg_get_string(keys[CONNECTION_ACTION]); - data = NULL; - if (keys[CONNECTION_DATA]){ - data = blobmsg_get_string(keys[CONNECTION_DATA]); + struct config_update_struct data = { + .mask = 0, + .codec = VOICE_CODEC_G711A, + .ptime = 0, + }; + + if (keys[CONNECTION_DATA_CODEC]){ + data.codec = blobmsg_get_u32(keys[CONNECTION_DATA_CODEC]); + data.mask = data.mask|UBUS_DATA_CODEC_BIT; } + if (keys[CONNECTION_DATA_PTIME]){ + data.ptime = blobmsg_get_u32(keys[CONNECTION_DATA_PTIME]); + data.mask = data.mask|UBUS_DATA_PTIME_BIT; + } + ENDPT_DBG("%s() line: %d connection_id: %d action: %s\n", __func__, line, id, action_str); if (strcmp("create", action_str) == 0) { if(line_new_connection_by_asterisk(line, id, &ubusReq)) @@ -635,8 +629,9 @@ static int ubus_request_connection(struct ubus_context *uctx, struct ubus_object } else if (strcmp("update", action_str) == 0) { if(line_update_connection_by_pbx(line, id)) return UBUS_STATUS_UNKNOWN_ERROR; - } else if (strcmp("set_codec", action_str) == 0) { - if(line_connection_modify_codec_by_asterisk(line, id, codec_string_to_enum(data))) + } else if (strcmp("parm_update", action_str) == 0) { + ENDPT_DBG("parm_update request for %s line: %d, id: %d, mask: %d, codec: %d, ptime: %d \n", __func__, line, id, data.mask, data.codec, data.ptime); + if(line_connection_parm_update_by_asterisk(line, id, &data)) return UBUS_STATUS_UNKNOWN_ERROR; } else { ENDPT_DBG("Error! No such action: %s\n", action_str);