Commit e5470e27 authored by Simon Morlat's avatar Simon Morlat

allow support for multiple telephone-event payload types, which is required...

allow support for multiple telephone-event payload types, which is required when having multiple sampling rate in a SDP offer.
Fix big memory leak.
parent 0ad89f5e
......@@ -44,6 +44,7 @@ extern "C"{
#define PAYLOAD_TYPE_USER_FLAG_1 (1<<5)
#define PAYLOAD_TYPE_USER_FLAG_2 (1<<6)
#define PAYLOAD_TYPE_USER_FLAG_3 (1<<7)
#define PAYLOAD_TYPE_USER_FLAG_4 (1<<8)
/* ask for more if you need*/
#define PAYLOAD_AUDIO_CONTINUOUS 0
......@@ -93,7 +94,7 @@ typedef struct _PayloadTypeAvpfParams PayloadTypeAvpfParams;
ORTP_PUBLIC PayloadType *payload_type_new(void);
ORTP_PUBLIC PayloadType *payload_type_clone(PayloadType *payload);
ORTP_PUBLIC PayloadType *payload_type_clone(const PayloadType *payload);
ORTP_PUBLIC char *payload_type_get_rtpmap(PayloadType *pt);
ORTP_PUBLIC void payload_type_destroy(PayloadType *pt);
ORTP_PUBLIC void payload_type_set_recv_fmtp(PayloadType *pt, const char *fmtp);
......
......@@ -71,7 +71,7 @@ ORTP_PUBLIC void rtp_profile_set_payload(RtpProfile *prof, int idx, PayloadType
*@param index the payload type number
*@return the payload description (a PayloadType object)
**/
static ORTP_INLINE PayloadType * rtp_profile_get_payload(RtpProfile *prof, int idx){
static ORTP_INLINE PayloadType * rtp_profile_get_payload(const RtpProfile *prof, int idx){
if (idx<0 || idx>=RTP_PROFILE_MAX_PAYLOADS) {
return NULL;
}
......
......@@ -325,7 +325,6 @@ struct _RtpSession
int pt;
unsigned int ssrc;
WaitPoint wp;
int telephone_events_pt; /* the payload type used for telephony events */
} snd,rcv;
unsigned int inc_ssrc_candidate;
int inc_same_ssrc_count;
......
......@@ -60,7 +60,6 @@ extern "C" {
ORTP_PUBLIC int rtp_session_telephone_events_supported(RtpSession *session);
ORTP_PUBLIC int rtp_session_send_telephone_events_supported(RtpSession *session);
ORTP_PUBLIC int rtp_session_recv_telephone_events_supported(RtpSession *session);
ORTP_PUBLIC mblk_t *rtp_session_create_telephone_event_packet(RtpSession *session, int start);
ORTP_PUBLIC int rtp_session_add_telephone_event(RtpSession *session,
......
......@@ -45,7 +45,7 @@ PayloadType *payload_type_new()
}
PayloadType *payload_type_clone(PayloadType *payload)
PayloadType *payload_type_clone(const PayloadType *payload)
{
PayloadType *newpayload=(PayloadType *)ortp_new0(PayloadType,1);
memcpy(newpayload,payload,sizeof(PayloadType));
......
......@@ -270,7 +270,7 @@ void rtp_session_rtp_parse(RtpSession *session, mblk_t *mp, uint32_t local_str_t
}
/* check for possible telephone events */
if (rtp->paytype==session->rcv.telephone_events_pt){
if (rtp_profile_is_telephone_event(session->snd.profile, rtp->paytype)){
queue_packet(&session->rtp.tev_rq,session->rtp.max_rq_size,mp,rtp,&discarded,&duplicate);
stats->discarded+=discarded;
ortp_global_stats.discarded+=discarded;
......@@ -288,7 +288,10 @@ void rtp_session_rtp_parse(RtpSession *session, mblk_t *mp, uint32_t local_str_t
}
/* Drop the packets while the RTP_SESSION_FLUSH flag is set. */
if (session->flags & RTP_SESSION_FLUSH) return;
if (session->flags & RTP_SESSION_FLUSH) {
freemsg(mp);
return;
}
jitter_control_new_packet(&session->rtp.jittctl,rtp->timestamp,local_str_ts);
......
......@@ -234,8 +234,6 @@ rtp_session_init (RtpSession * session, int mode)
rtp_session_set_source_description(session,"unknown@unknown",NULL,NULL,
NULL,NULL,"oRTP-" ORTP_VERSION,NULL);
}
session->snd.telephone_events_pt=-1; /* not defined a priori */
session->rcv.telephone_events_pt=-1; /* not defined a priori */
rtp_session_set_profile (session, &av_profile); /*the default profile to work with */
session->rtp.gs.socket=-1;
session->rtcp.gs.socket=-1;
......@@ -919,8 +917,7 @@ __rtp_session_sendm_with_ts (RtpSession * session, mblk_t *mp, uint32_t packet_t
/* We are probably trying to send a STUN packet so don't change its content. */
} else {
rtp->timestamp=packet_ts;
if (session->snd.telephone_events_pt==rtp->paytype)
{
if (rtp_profile_is_telephone_event(session->snd.profile, rtp->paytype)){
rtp->seq_number = session->rtp.snd_seq;
session->rtp.snd_seq++;
}
......
......@@ -78,4 +78,7 @@ void rtp_session_send_regular_rtcp_packet_and_reschedule(RtpSession *session, ui
void rtp_session_send_fb_rtcp_packet_and_reschedule(RtpSession *session);
void ortp_stream_clear_aux_addresses(OrtpStream *os);
ORTP_PUBLIC bool_t rtp_profile_is_telephone_event(const RtpProfile *prof, int pt);
#endif
......@@ -44,10 +44,12 @@ PayloadType payload_type_telephone_event={
int rtp_session_telephone_events_supported(RtpSession *session)
{
/* search for a telephony event payload in the current profile */
session->snd.telephone_events_pt=rtp_profile_get_payload_number_from_mime(session->snd.profile,"telephone-event");
session->rcv.telephone_events_pt=rtp_profile_get_payload_number_from_mime(session->rcv.profile,"telephone-event");
/*printf("Telephone event pt is %i\n",session->telephone_events_pt);*/
return session->snd.telephone_events_pt;
return rtp_profile_get_payload_number_from_mime(session->snd.profile,"telephone-event");
}
bool_t rtp_profile_is_telephone_event(const RtpProfile *prof, int pt_num){
PayloadType *pt=rtp_profile_get_payload(prof, pt_num);
return pt && strcasecmp(pt->mime_type,"telephone-event")==0;
}
......@@ -61,9 +63,7 @@ int rtp_session_telephone_events_supported(RtpSession *session)
int rtp_session_send_telephone_events_supported(RtpSession *session)
{
/* search for a telephony event payload in the current profile */
session->snd.telephone_events_pt=rtp_profile_get_payload_number_from_mime(session->snd.profile,"telephone-event");
/*printf("Telephone event pt is %i\n",session->telephone_events_pt);*/
return session->snd.telephone_events_pt;
return rtp_profile_get_payload_number_from_mime(session->snd.profile,"telephone-event");
}
/**
......@@ -75,9 +75,7 @@ int rtp_session_send_telephone_events_supported(RtpSession *session)
**/int rtp_session_recv_telephone_events_supported(RtpSession *session)
{
/* search for a telephony event payload in the current profile */
session->rcv.telephone_events_pt=rtp_profile_get_payload_number_from_mime(session->rcv.profile,"telephone-event");
/*printf("Telephone event pt is %i\n",session->telephone_events_pt);*/
return session->snd.telephone_events_pt;
return rtp_profile_get_payload_number_from_mime(session->rcv.profile,"telephone-event");
}
......@@ -97,8 +95,9 @@ mblk_t *rtp_session_create_telephone_event_packet(RtpSession *session, int start
{
mblk_t *mp;
rtp_header_t *rtp;
return_val_if_fail(session->snd.telephone_events_pt!=-1,NULL);
PayloadType *cur_pt=rtp_profile_get_payload(session->snd.profile, rtp_session_get_send_payload_type(session));
int tev_pt=rtp_profile_find_payload_number(session->snd.profile, "telephone-event", cur_pt ? cur_pt->clock_rate : 8000, 1);
return_val_if_fail(tev_pt!=-1,NULL);
mp=allocb(RTP_FIXED_HEADER_SIZE+TELEPHONY_EVENTS_ALLOCATED_SIZE,BPRI_MED);
if (mp==NULL) return NULL;
......@@ -113,7 +112,7 @@ mblk_t *rtp_session_create_telephone_event_packet(RtpSession *session, int start
/*seq number set later, when packet is sended */
/*set the payload type */
rtp->paytype=session->snd.telephone_events_pt;
rtp->paytype=tev_pt;
/*copy the payload */
mp->b_wptr+=RTP_FIXED_HEADER_SIZE;
......@@ -310,7 +309,7 @@ int rtp_session_read_telephone_event(RtpSession *session,
telephone_event_t *tev;
rtp_header_t *hdr=(rtp_header_t*)packet->b_rptr;
unsigned char *payload;
if (hdr->paytype!=session->rcv.telephone_events_pt) return 0; /* this is not tel ev.*/
if (rtp_profile_is_telephone_event(session->rcv.profile, hdr->paytype)) return 0; /* this is not tel ev.*/
datasize=rtp_get_payload(packet,&payload);
tev=*tab=(telephone_event_t*)payload;
/* convert from network to host order what should be */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment