Skip to content

Commit

Permalink
Added parsing of custom a= attributes related to a payload
Browse files Browse the repository at this point in the history
Fixed codec_delete() to also delete the custom attributes related to the codec to be deleted

ie.
For
      m=video 38453 UDP/TLS/RTP/SAVPF 96 97 98 99
      a=rtpmap:96 VP8/90000
      a=fmtp:96 annexb=yes
      a=rtcp-fb:96 goog-remb
      a=rtcp-fb:96 transport-cc
      a=rtcp-fb:96 ccm fir
      a=rtcp-fb:96 nack
      a=rtcp-fb:96 nack pli

OpenSIPS will save all the rtcp-fb: lines as custom attributes for the VP8 codec
and when doing codec_delete("VP8") it will delete all the corresponding attributes
  • Loading branch information
vladpaiu committed May 15, 2023
1 parent 6725409 commit 7743524
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 30 deletions.
63 changes: 36 additions & 27 deletions modules/sipmsgops/codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,32 +386,32 @@ static int stream_process(struct sip_msg * msg, struct sdp_stream_cell *cell,
{
static sdp_payload_attr_t static_payloads[] = {
/* as per http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml */
{ NULL,0,{ "0",1},{"PCMU",4},{ "8000",4},{NULL,0},{NULL,0} }, /* 0 - PCMU/8000 */
{ NULL,0,{ "3",1},{ "GSM",3},{ "8000",4},{NULL,0},{NULL,0} }, /* 3 - GSM/8000 */
{ NULL,0,{ "4",1},{"G723",4},{ "8000",4},{NULL,0},{NULL,0} }, /* 4 - G723/8000 */
{ NULL,0,{ "5",1},{"DVI4",4},{ "8000",4},{NULL,0},{NULL,0} }, /* 5 - DVI4/8000 */
{ NULL,0,{ "6",1},{"DVI4",4},{"16000",5},{NULL,0},{NULL,0} }, /* 6 - DVI4/16000 */
{ NULL,0,{ "7",1},{ "LPC",3},{ "8000",4},{NULL,0},{NULL,0} }, /* 7 - LPC/8000 */
{ NULL,0,{ "8",1},{"PCMA",4},{ "8000",4},{NULL,0},{NULL,0} }, /* 8 - PCMA/8000 */
{ NULL,0,{ "9",1},{"G722",4},{ "8000",4},{NULL,0},{NULL,0} }, /* 9 - G722/8000 */
{ NULL,0,{"10",2},{ "L16",3},{"44100",5},{NULL,0},{NULL,0} }, /*10 - L16/44100 */
{ NULL,0,{"11",2},{ "L16",3},{"44100",5},{NULL,0},{NULL,0} }, /*11 - L16/44100 */
{ NULL,0,{"12",2},{"QCELP",5},{"8000",4},{NULL,0},{NULL,0} }, /*12 -QCELP/8000 */
{ NULL,0,{"13",2},{ "CN",2},{ "8000",4},{NULL,0},{NULL,0} }, /*13 - CN/8000 */
{ NULL,0,{"14",2},{ "MPA",3},{"90000",5},{NULL,0},{NULL,0} }, /*14 - MPA/90000 */
{ NULL,0,{"15",2},{"G728",4},{ "8000",4},{NULL,0},{NULL,0} }, /*15 - G728/8000 */
{ NULL,0,{"16",2},{"DVI4",4},{"11025",5},{NULL,0},{NULL,0} }, /*16 - DVI4/11025 */
{ NULL,0,{"17",2},{"DVI4",4},{"22050",5},{NULL,0},{NULL,0} }, /*17 - DVI4/22050 */
{ NULL,0,{"18",2},{"G729",4},{ "8000",4},{NULL,0},{NULL,0} }, /*18 - G729/8000 */
{ NULL,0,{"25",2},{"CelB",4},{ "8000",4},{NULL,0},{NULL,0} }, /*25 - CelB/8000 */
{ NULL,0,{"26",2},{"JPEG",4},{"90000",5},{NULL,0},{NULL,0} }, /*26 - JPEG/90000 */
{ NULL,0,{"28",2},{ "nv",2},{"90000",5},{NULL,0},{NULL,0} }, /*28 - nv/90000 */
{ NULL,0,{"31",2},{"H261",4},{"90000",5},{NULL,0},{NULL,0} }, /*31 - H261/90000 */
{ NULL,0,{"32",2},{ "MPV",3},{"90000",5},{NULL,0},{NULL,0} }, /*32 - MPV/90000 */
{ NULL,0,{"33",2},{"MP2T",4},{"90000",5},{NULL,0},{NULL,0} }, /*33 - MP2T/90000 */
{ NULL,0,{"34",2},{"H263",4},{"90000",5},{NULL,0},{NULL,0} }, /*34 - H263/90000 */
{ NULL,0,{"t38",3},{"t38",3},{ "",0},{NULL,0},{NULL,0} }, /*T38- fax */
{ NULL,0,{NULL,0},{ NULL,0},{ NULL,0},{NULL,0},{NULL,0} }
{ NULL,0,{ "0",1},{"PCMU",4},{ "8000",4},{NULL,0},{NULL,0},{},0 }, /* 0 - PCMU/8000 */
{ NULL,0,{ "3",1},{ "GSM",3},{ "8000",4},{NULL,0},{NULL,0},{},0 }, /* 3 - GSM/8000 */
{ NULL,0,{ "4",1},{"G723",4},{ "8000",4},{NULL,0},{NULL,0},{},0 }, /* 4 - G723/8000 */
{ NULL,0,{ "5",1},{"DVI4",4},{ "8000",4},{NULL,0},{NULL,0},{},0 }, /* 5 - DVI4/8000 */
{ NULL,0,{ "6",1},{"DVI4",4},{"16000",5},{NULL,0},{NULL,0},{},0 }, /* 6 - DVI4/16000 */
{ NULL,0,{ "7",1},{ "LPC",3},{ "8000",4},{NULL,0},{NULL,0},{},0 }, /* 7 - LPC/8000 */
{ NULL,0,{ "8",1},{"PCMA",4},{ "8000",4},{NULL,0},{NULL,0},{},0 }, /* 8 - PCMA/8000 */
{ NULL,0,{ "9",1},{"G722",4},{ "8000",4},{NULL,0},{NULL,0},{},0 }, /* 9 - G722/8000 */
{ NULL,0,{"10",2},{ "L16",3},{"44100",5},{NULL,0},{NULL,0},{},0 }, /*10 - L16/44100 */
{ NULL,0,{"11",2},{ "L16",3},{"44100",5},{NULL,0},{NULL,0},{},0 }, /*11 - L16/44100 */
{ NULL,0,{"12",2},{"QCELP",5},{"8000",4},{NULL,0},{NULL,0},{},0 }, /*12 -QCELP/8000 */
{ NULL,0,{"13",2},{ "CN",2},{ "8000",4},{NULL,0},{NULL,0},{},0 }, /*13 - CN/8000 */
{ NULL,0,{"14",2},{ "MPA",3},{"90000",5},{NULL,0},{NULL,0},{},0 }, /*14 - MPA/90000 */
{ NULL,0,{"15",2},{"G728",4},{ "8000",4},{NULL,0},{NULL,0},{},0 }, /*15 - G728/8000 */
{ NULL,0,{"16",2},{"DVI4",4},{"11025",5},{NULL,0},{NULL,0},{},0 }, /*16 - DVI4/11025 */
{ NULL,0,{"17",2},{"DVI4",4},{"22050",5},{NULL,0},{NULL,0},{},0 }, /*17 - DVI4/22050 */
{ NULL,0,{"18",2},{"G729",4},{ "8000",4},{NULL,0},{NULL,0},{},0 }, /*18 - G729/8000 */
{ NULL,0,{"25",2},{"CelB",4},{ "8000",4},{NULL,0},{NULL,0},{},0 }, /*25 - CelB/8000 */
{ NULL,0,{"26",2},{"JPEG",4},{"90000",5},{NULL,0},{NULL,0},{},0 }, /*26 - JPEG/90000 */
{ NULL,0,{"28",2},{ "nv",2},{"90000",5},{NULL,0},{NULL,0},{},0 }, /*28 - nv/90000 */
{ NULL,0,{"31",2},{"H261",4},{"90000",5},{NULL,0},{NULL,0},{},0 }, /*31 - H261/90000 */
{ NULL,0,{"32",2},{ "MPV",3},{"90000",5},{NULL,0},{NULL,0},{},0 }, /*32 - MPV/90000 */
{ NULL,0,{"33",2},{"MP2T",4},{"90000",5},{NULL,0},{NULL,0},{},0 }, /*33 - MP2T/90000 */
{ NULL,0,{"34",2},{"H263",4},{"90000",5},{NULL,0},{NULL,0},{},0 }, /*34 - H263/90000 */
{ NULL,0,{"t38",3},{"t38",3},{ "",0},{NULL,0},{NULL,0},{},0 }, /*T38- fax */
{ NULL,0,{NULL,0},{ NULL,0},{ NULL,0},{NULL,0},{NULL,0},{},0 }
};
sdp_payload_attr_t *payload;
char *cur, *tmp, *buff, temp;
Expand Down Expand Up @@ -533,7 +533,6 @@ static int stream_process(struct sip_msg * msg, struct sdp_stream_cell *cell,
if( op == DELETE && !is_static )
{
/* find the full 'a=...' entry */

if( delete_sdp_line( msg, payload->rtp_enc.s, cell) < 0 )
{
LM_ERR("Unable to add delete lump for a=\n");
Expand All @@ -547,6 +546,16 @@ static int stream_process(struct sip_msg * msg, struct sdp_stream_cell *cell,
ret = -1;
goto end;
}

for (i=0;i<payload->custom_attrs_size;i++) {
LM_DBG("also deleting attribute [%.*s] belonging to codec to be deleted\n",payload->custom_attrs[i].len,payload->custom_attrs[i].s);
if( delete_sdp_line( msg, payload->custom_attrs[i].s, cell) < 0 )
{
LM_ERR("Unable to add delete lump for a=\n");
ret = -1;
goto end;
}
}
}

{
Expand Down
24 changes: 21 additions & 3 deletions parser/sdp/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ void set_sdp_payload_fmtp(sdp_payload_attr_t *payload_attr, str *fmtp_string )
return;
}

int set_sdp_payload_custom_attr(sdp_payload_attr_t *payload_attr, str *attr )
{
if (payload_attr->custom_attrs_size == MAX_CUSTOM_ATTRS-1) {
LM_DBG("Max custom a= attrs reached \n");
return -1;
}

payload_attr->custom_attrs[payload_attr->custom_attrs_size++] = *attr;
return 1;
}

/*
* Getters ....
*/
Expand Down Expand Up @@ -372,7 +383,7 @@ int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_info_t*
int is_rtp;
char *bodylimit;
char *v1p, *o1p, *m1p, *m2p, *c1p, *c2p, *a1p, *a2p, *b1p;
str tmpstr1;
str tmpstr1,custom_attr;
int stream_num, payloadnum, pf;
sdp_session_cell_t *session;
sdp_stream_cell_t *stream;
Expand Down Expand Up @@ -594,8 +605,15 @@ int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_info_t*
a1p = stream->max_size.s + stream->max_size.len;
} else if (extract_path(&tmpstr1, &stream->path) == 0) {
a1p = stream->path.s + stream->path.len;
/*} else { */
/* LM_DBG("else: `%.*s'\n", tmpstr1.len, tmpstr1.s); */
} else {
if (parse_payload_attr && extract_custom_a_attr(&tmpstr1,&rtp_payload,&custom_attr) == 0) {
LM_DBG("extracted attr [%.*s] for payload [%.*s]\n",custom_attr.len,custom_attr.s,rtp_payload.len,rtp_payload.s);
a1p = custom_attr.s + custom_attr.len;
payload_attr = (sdp_payload_attr_t*)get_sdp_payload4payload(stream, &rtp_payload);
set_sdp_payload_custom_attr(payload_attr, &custom_attr);
} else {
LM_DBG("else: parse_payload_attr ? %d `%.*s'\n",parse_payload_attr, tmpstr1.len, tmpstr1.s);
}
}

tmpstr1.s = a2p;
Expand Down
3 changes: 3 additions & 0 deletions parser/sdp/sdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef struct sdp_attr {
str value;
} sdp_attr_t;

#define MAX_CUSTOM_ATTRS 16
typedef struct sdp_payload_attr {
struct sdp_payload_attr *next;
/**< payload index inside stream */
Expand All @@ -53,6 +54,8 @@ typedef struct sdp_payload_attr {
str rtp_clock;
str rtp_params;
str fmtp_string;
str custom_attrs[MAX_CUSTOM_ATTRS];
int custom_attrs_size;
} sdp_payload_attr_t;

typedef struct sdp_stream_cell {
Expand Down
65 changes: 65 additions & 0 deletions parser/sdp/sdp_helpr_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,71 @@ int extract_rtpmap(str *body,
return 0;
}

int extract_custom_a_attr(str *body, str *payload, str *value)
{
char *cp, *p;
int len,i;

/* a=<format> <format specific parameters> */
/* 10 for good luck ? */
if (body->len < 10) {
LM_DBG("Too small body \n");
return -1;
}

if (body->s[0] != 'a' && body->s[1] != '=') {
LM_DBG("We are not pointing to an a= attribute =>`%.*s'\n", body->len, body->s);
return -1;
}

i=0;
p=body->s;
while (i<body->len) {
if (*p == ':')
break;
p++;
i++;
}

if (i==body->len) {
/* no payload found */
LM_DBG("no payload ID\n");
return -1;
}

/* payload ID starts after : */
payload->s = p+1;
payload->len = eat_line(payload->s, body->s + body->len -
payload->s) - payload->s;
trim_len(payload->len, payload->s, *payload);
len = payload->len;

/* */
cp = eat_token_end(payload->s, payload->s + payload->len);
payload->len = cp - payload->s;
if (payload->len <= 0 || cp == payload->s) {
LM_ERR("no encoding \n");
return -1;
}

len -= payload->len;
value->s = cp;
cp = eat_space_end(value->s, value->s + len);
len -= cp - value->s;
if (len <= 0 || cp == value->s) {
LM_ERR("no value in a= line \n");
return -1;
}

value->s = cp;

value->len = eat_line(value->s, body->s + body->len -
value->s) - value->s;
trim_len(value->len, value->s, *value);

return 0;
}

int extract_fmtp( str *body, str *fmtp_payload, str *fmtp_string )
{
char *cp, *cp1;
Expand Down
1 change: 1 addition & 0 deletions parser/sdp/sdp_helpr_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

int extract_field(str *body, str *value, str field);
int extract_rtpmap(str *body, str *rtpmap_payload, str *rtpmap_encoding, str *rtpmap_clockrate, str *rtpmap_parmas);
int extract_custom_a_attr(str *body, str *payload, str *value);
int extract_fmtp( str *body, str *fmtp_payload, str *fmtp_string );
int extract_ptime(str *body, str *ptime);
int extract_sendrecv_mode(str *body, str *sendrecv_mode, int *is_on_hold);
Expand Down

0 comments on commit 7743524

Please sign in to comment.