Commit 1b0dfa52 authored by Ghislain MARY's avatar Ghislain MARY

Split payloadtype and rtpprofile in two separate files.

parent afced210
......@@ -3,7 +3,7 @@
ortp_includedir=$(includedir)/ortp
ortp_include_HEADERS=str_utils.h rtpsession.h rtp.h port.h logging.h \
ortp.h telephonyevents.h sessionset.h payloadtype.h rtpsignaltable.h \
ortp.h telephonyevents.h sessionset.h payloadtype.h rtpprofile.h rtpsignaltable.h \
rtcp.h \
event.h stun.h stun_udp.h ortp_srtp.h zrtp.h \
b64.h
......
......@@ -19,7 +19,7 @@
/**
* \file payloadtype.h
* \brief Using and creating standart and custom RTP profiles
* \brief Definition of payload types
*
**/
......@@ -76,21 +76,6 @@ typedef struct _PayloadType PayloadType;
#define payload_type_unset_flag(pt,flag) (pt)->flags&=(~(int)flag)
#define payload_type_get_flags(pt) (pt)->flags
#define RTP_PROFILE_MAX_PAYLOADS 128
/**
* The RTP profile is a table RTP_PROFILE_MAX_PAYLOADS entries to make the matching
* between RTP payload type number and the PayloadType that defines the type of
* media.
**/
struct _RtpProfile
{
char *name;
PayloadType *payload[RTP_PROFILE_MAX_PAYLOADS];
};
typedef struct _RtpProfile RtpProfile;
PayloadType *payload_type_new(void);
PayloadType *payload_type_clone(PayloadType *payload);
......@@ -107,59 +92,9 @@ void payload_type_append_send_fmtp(PayloadType *pt, const char *fmtp);
bool_t fmtp_get_value(const char *fmtp, const char *param_name, char *result, size_t result_len);
VAR_DECLSPEC RtpProfile av_profile;
#define payload_type_set_user_data(pt,p) (pt)->user_data=(p)
#define payload_type_get_user_data(pt) ((pt)->user_data)
#define rtp_profile_get_name(profile) (const char*)((profile)->name)
void rtp_profile_set_payload(RtpProfile *prof, int idx, PayloadType *pt);
/**
* Set payload type number @index unassigned in the profile.
*
*@param profile an RTP profile
*@param index the payload type number
**/
#define rtp_profile_clear_payload(profile,index) \
rtp_profile_set_payload(profile,index,NULL)
/* I prefer have this function inlined because it is very often called in the code */
/**
*
* Gets the payload description of the payload type @index in the profile.
*
*@param profile an RTP profile (a #RtpProfile object)
*@param index the payload type number
*@return the payload description (a PayloadType object)
**/
static inline PayloadType * rtp_profile_get_payload(RtpProfile *prof, int idx){
if (idx<0 || idx>=RTP_PROFILE_MAX_PAYLOADS) {
return NULL;
}
return prof->payload[idx];
}
void rtp_profile_clear_all(RtpProfile *prof);
void rtp_profile_set_name(RtpProfile *prof, const char *name);
PayloadType * rtp_profile_get_payload_from_mime(RtpProfile *profile,const char *mime);
PayloadType * rtp_profile_get_payload_from_rtpmap(RtpProfile *profile, const char *rtpmap);
int rtp_profile_get_payload_number_from_mime(RtpProfile *profile,const char *mime);
int rtp_profile_get_payload_number_from_rtpmap(RtpProfile *profile, const char *rtpmap);
int rtp_profile_find_payload_number(RtpProfile *prof,const char *mime,int rate, int channels);
PayloadType * rtp_profile_find_payload(RtpProfile *prof,const char *mime,int rate, int channels);
int rtp_profile_move_payload(RtpProfile *prof,int oldpos,int newpos);
RtpProfile * rtp_profile_new(const char *name);
/* clone a profile, payload are not cloned */
RtpProfile * rtp_profile_clone(RtpProfile *prof);
/*clone a profile and its payloads (ie payload type are newly allocated, not reusing payload types of the reference profile) */
RtpProfile * rtp_profile_clone_full(RtpProfile *prof);
/* frees the profile and all its PayloadTypes*/
void rtp_profile_destroy(RtpProfile *prof);
/* some payload types */
/* audio */
......
/*
The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* \file rtpprofile.h
* \brief Using and creating standart and custom RTP profiles
*
**/
#ifndef RTPPROFILE_H
#define RTPPROFILE_H
#include <ortp/port.h>
#ifdef __cplusplus
extern "C"{
#endif
#define RTP_PROFILE_MAX_PAYLOADS 128
/**
* The RTP profile is a table RTP_PROFILE_MAX_PAYLOADS entries to make the matching
* between RTP payload type number and the PayloadType that defines the type of
* media.
**/
struct _RtpProfile
{
char *name;
PayloadType *payload[RTP_PROFILE_MAX_PAYLOADS];
};
typedef struct _RtpProfile RtpProfile;
VAR_DECLSPEC RtpProfile av_profile;
#define rtp_profile_get_name(profile) (const char*)((profile)->name)
void rtp_profile_set_payload(RtpProfile *prof, int idx, PayloadType *pt);
/**
* Set payload type number @index unassigned in the profile.
*
*@param profile an RTP profile
*@param index the payload type number
**/
#define rtp_profile_clear_payload(profile,index) \
rtp_profile_set_payload(profile,index,NULL)
/* I prefer have this function inlined because it is very often called in the code */
/**
*
* Gets the payload description of the payload type @index in the profile.
*
*@param profile an RTP profile (a #RtpProfile object)
*@param index the payload type number
*@return the payload description (a PayloadType object)
**/
static inline PayloadType * rtp_profile_get_payload(RtpProfile *prof, int idx){
if (idx<0 || idx>=RTP_PROFILE_MAX_PAYLOADS) {
return NULL;
}
return prof->payload[idx];
}
void rtp_profile_clear_all(RtpProfile *prof);
void rtp_profile_set_name(RtpProfile *prof, const char *name);
PayloadType * rtp_profile_get_payload_from_mime(RtpProfile *profile,const char *mime);
PayloadType * rtp_profile_get_payload_from_rtpmap(RtpProfile *profile, const char *rtpmap);
int rtp_profile_get_payload_number_from_mime(RtpProfile *profile,const char *mime);
int rtp_profile_get_payload_number_from_rtpmap(RtpProfile *profile, const char *rtpmap);
int rtp_profile_find_payload_number(RtpProfile *prof,const char *mime,int rate, int channels);
PayloadType * rtp_profile_find_payload(RtpProfile *prof,const char *mime,int rate, int channels);
int rtp_profile_move_payload(RtpProfile *prof,int oldpos,int newpos);
RtpProfile * rtp_profile_new(const char *name);
/* clone a profile, payload are not cloned */
RtpProfile * rtp_profile_clone(RtpProfile *prof);
/*clone a profile and its payloads (ie payload type are newly allocated, not reusing payload types of the reference profile) */
RtpProfile * rtp_profile_clone_full(RtpProfile *prof);
/* frees the profile and all its PayloadTypes*/
void rtp_profile_destroy(RtpProfile *prof);
#ifdef __cplusplus
}
#endif
#endif
......@@ -34,6 +34,7 @@
#include <ortp/port.h>
#include <ortp/rtp.h>
#include <ortp/payloadtype.h>
#include <ortp/rtpprofile.h>
#include <ortp/sessionset.h>
#include <ortp/rtcp.h>
#include <ortp/str_utils.h>
......
......@@ -25,6 +25,7 @@ libortp_la_SOURCES= str_utils.c \
sessionset.c \
telephonyevents.c \
payloadtype.c \
rtpprofile.c \
rtcp.c \
utils.c utils.h \
rtcpparse.c \
......
......@@ -19,6 +19,7 @@
#include <ortp/payloadtype.h>
#include <ortp/rtpprofile.h>
char offset127=127;
char offset0xD5=(char)0xD5;
......
......@@ -18,8 +18,7 @@
*/
#include "ortp/ortp.h"
#include "ortp/payloadtype.h"
#include "utils.h"
char *payload_type_get_rtpmap(PayloadType *pt)
{
......@@ -28,7 +27,7 @@ char *payload_type_get_rtpmap(PayloadType *pt)
if (pt->channels>0)
snprintf(rtpmap,len,"%s/%i/%i",pt->mime_type,pt->clock_rate,pt->channels);
else
snprintf(rtpmap,len,"%s/%i",pt->mime_type,pt->clock_rate);
snprintf(rtpmap,len,"%s/%i",pt->mime_type,pt->clock_rate);
return rtpmap;
}
......@@ -156,208 +155,3 @@ bool_t fmtp_get_value(const char *fmtp, const char *param_name, char *result, si
}
return FALSE;
}
int rtp_profile_get_payload_number_from_mime(RtpProfile *profile,const char *mime)
{
PayloadType *pt;
int i;
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++)
{
pt=rtp_profile_get_payload(profile,i);
if (pt!=NULL)
{
if (strcasecmp(pt->mime_type,mime)==0){
return i;
}
}
}
return -1;
}
int rtp_profile_find_payload_number(RtpProfile*profile,const char *mime,int rate,int channels)
{
int i;
PayloadType *pt;
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++)
{
pt=rtp_profile_get_payload(profile,i);
if (pt!=NULL)
{
if (strcasecmp(pt->mime_type,mime)==0 &&
pt->clock_rate==rate &&
(pt->channels==channels || channels<=0 || pt->channels<=0)) {
/*we don't look at channels if it is undefined
ie a negative or zero value*/
return i;
}
}
}
return -1;
}
int rtp_profile_get_payload_number_from_rtpmap(RtpProfile *profile,const char *rtpmap)
{
int clock_rate, channels, ret;
char* subtype = ortp_strdup( rtpmap );
char* rate_str = NULL;
char* chan_str = NULL;
/* find the slash after the subtype */
rate_str = strchr(subtype, '/');
if (rate_str && strlen(rate_str)>1) {
*rate_str = 0;
rate_str++;
/* Look for another slash */
chan_str = strchr(rate_str, '/');
if (chan_str && strlen(chan_str)>1) {
*chan_str = 0;
chan_str++;
} else {
chan_str = NULL;
}
} else {
rate_str = NULL;
}
// Use default clock rate if none given
if (rate_str) clock_rate = atoi(rate_str);
else clock_rate = 8000;
// Use default number of channels if none given
if (chan_str) channels = atoi(chan_str);
else channels = -1;
//printf("Searching for payload %s at freq %i with %i channels\n",subtype,clock_rate,ch1annels);
ret=rtp_profile_find_payload_number(profile,subtype,clock_rate,channels);
ortp_free(subtype);
return ret;
}
PayloadType * rtp_profile_find_payload(RtpProfile *prof,const char *mime,int rate,int channels)
{
int i;
i=rtp_profile_find_payload_number(prof,mime,rate,channels);
if (i>=0) return rtp_profile_get_payload(prof,i);
return NULL;
}
PayloadType * rtp_profile_get_payload_from_mime(RtpProfile *profile,const char *mime)
{
int pt;
pt=rtp_profile_get_payload_number_from_mime(profile,mime);
if (pt==-1) return NULL;
else return rtp_profile_get_payload(profile,pt);
}
PayloadType * rtp_profile_get_payload_from_rtpmap(RtpProfile *profile, const char *rtpmap)
{
int pt = rtp_profile_get_payload_number_from_rtpmap(profile,rtpmap);
if (pt==-1) return NULL;
else return rtp_profile_get_payload(profile,pt);
}
int rtp_profile_move_payload(RtpProfile *prof,int oldpos,int newpos){
prof->payload[newpos]=prof->payload[oldpos];
prof->payload[oldpos]=NULL;
return 0;
}
RtpProfile * rtp_profile_new(const char *name)
{
RtpProfile *prof=(RtpProfile*)ortp_new0(RtpProfile,1);
rtp_profile_set_name(prof,name);
return prof;
}
/**
* Assign payload type number index to payload type desribed in pt for the RTP profile profile.
* @param profile a RTP profile
* @param idx the payload type number
* @param pt the payload type description
*
**/
void rtp_profile_set_payload(RtpProfile *prof, int idx, PayloadType *pt){
if (idx<0 || idx>=RTP_PROFILE_MAX_PAYLOADS) {
ortp_error("Bad index %i",idx);
return;
}
prof->payload[idx]=pt;
}
/**
* Initialize the profile to the empty profile (all payload type are unassigned).
*@param profile a RTP profile
*
**/
void rtp_profile_clear_all(RtpProfile *obj){
int i;
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++){
obj->payload[i]=0;
}
}
/**
* Set a name to the rtp profile. (This is not required)
* @param profile a rtp profile object
* @param nm a string
*
**/
void rtp_profile_set_name(RtpProfile *obj, const char *name){
if (obj->name!=NULL) ortp_free(obj->name);
obj->name=ortp_strdup(name);
}
/* ! payload are not cloned*/
RtpProfile * rtp_profile_clone(RtpProfile *prof)
{
int i;
PayloadType *pt;
RtpProfile *newprof=rtp_profile_new(prof->name);
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++){
pt=rtp_profile_get_payload(prof,i);
if (pt!=NULL){
rtp_profile_set_payload(newprof,i,pt);
}
}
return newprof;
}
/*clone a profile and its payloads */
RtpProfile * rtp_profile_clone_full(RtpProfile *prof)
{
int i;
PayloadType *pt;
RtpProfile *newprof=rtp_profile_new(prof->name);
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++){
pt=rtp_profile_get_payload(prof,i);
if (pt!=NULL){
rtp_profile_set_payload(newprof,i,payload_type_clone(pt));
}
}
return newprof;
}
void rtp_profile_destroy(RtpProfile *prof)
{
int i;
PayloadType *payload;
if (prof->name) {
ortp_free(prof->name);
prof->name = NULL;
}
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++)
{
payload=rtp_profile_get_payload(prof,i);
if (payload!=NULL && (payload->flags & PAYLOAD_TYPE_ALLOCATED))
payload_type_destroy(payload);
}
ortp_free(prof);
}
/*
The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ortp/ortp.h"
int rtp_profile_get_payload_number_from_mime(RtpProfile *profile,const char *mime)
{
PayloadType *pt;
int i;
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++)
{
pt=rtp_profile_get_payload(profile,i);
if (pt!=NULL)
{
if (strcasecmp(pt->mime_type,mime)==0){
return i;
}
}
}
return -1;
}
int rtp_profile_find_payload_number(RtpProfile*profile,const char *mime,int rate,int channels)
{
int i;
PayloadType *pt;
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++)
{
pt=rtp_profile_get_payload(profile,i);
if (pt!=NULL)
{
if (strcasecmp(pt->mime_type,mime)==0 &&
pt->clock_rate==rate &&
(pt->channels==channels || channels<=0 || pt->channels<=0)) {
/*we don't look at channels if it is undefined
ie a negative or zero value*/
return i;
}
}
}
return -1;
}
int rtp_profile_get_payload_number_from_rtpmap(RtpProfile *profile,const char *rtpmap)
{
int clock_rate, channels, ret;
char* subtype = ortp_strdup( rtpmap );
char* rate_str = NULL;
char* chan_str = NULL;
/* find the slash after the subtype */
rate_str = strchr(subtype, '/');
if (rate_str && strlen(rate_str)>1) {
*rate_str = 0;
rate_str++;
/* Look for another slash */
chan_str = strchr(rate_str, '/');
if (chan_str && strlen(chan_str)>1) {
*chan_str = 0;
chan_str++;
} else {
chan_str = NULL;
}
} else {
rate_str = NULL;
}
// Use default clock rate if none given
if (rate_str) clock_rate = atoi(rate_str);
else clock_rate = 8000;
// Use default number of channels if none given
if (chan_str) channels = atoi(chan_str);
else channels = -1;
//printf("Searching for payload %s at freq %i with %i channels\n",subtype,clock_rate,ch1annels);
ret=rtp_profile_find_payload_number(profile,subtype,clock_rate,channels);
ortp_free(subtype);
return ret;
}
PayloadType * rtp_profile_find_payload(RtpProfile *prof,const char *mime,int rate,int channels)
{
int i;
i=rtp_profile_find_payload_number(prof,mime,rate,channels);
if (i>=0) return rtp_profile_get_payload(prof,i);
return NULL;
}
PayloadType * rtp_profile_get_payload_from_mime(RtpProfile *profile,const char *mime)
{
int pt;
pt=rtp_profile_get_payload_number_from_mime(profile,mime);
if (pt==-1) return NULL;
else return rtp_profile_get_payload(profile,pt);
}
PayloadType * rtp_profile_get_payload_from_rtpmap(RtpProfile *profile, const char *rtpmap)
{
int pt = rtp_profile_get_payload_number_from_rtpmap(profile,rtpmap);
if (pt==-1) return NULL;
else return rtp_profile_get_payload(profile,pt);
}
int rtp_profile_move_payload(RtpProfile *prof,int oldpos,int newpos){
prof->payload[newpos]=prof->payload[oldpos];
prof->payload[oldpos]=NULL;
return 0;
}
RtpProfile * rtp_profile_new(const char *name)
{
RtpProfile *prof=(RtpProfile*)ortp_new0(RtpProfile,1);
rtp_profile_set_name(prof,name);
return prof;
}
/**
* Assign payload type number index to payload type desribed in pt for the RTP profile profile.
* @param profile a RTP profile
* @param idx the payload type number
* @param pt the payload type description
*
**/
void rtp_profile_set_payload(RtpProfile *prof, int idx, PayloadType *pt){
if (idx<0 || idx>=RTP_PROFILE_MAX_PAYLOADS) {
ortp_error("Bad index %i",idx);
return;
}
prof->payload[idx]=pt;
}
/**
* Initialize the profile to the empty profile (all payload type are unassigned).
*@param profile a RTP profile
*
**/
void rtp_profile_clear_all(RtpProfile *obj){
int i;
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++){
obj->payload[i]=0;
}
}
/**
* Set a name to the rtp profile. (This is not required)
* @param profile a rtp profile object
* @param nm a string
*
**/
void rtp_profile_set_name(RtpProfile *obj, const char *name){
if (obj->name!=NULL) ortp_free(obj->name);
obj->name=ortp_strdup(name);
}
/* ! payload are not cloned*/
RtpProfile * rtp_profile_clone(RtpProfile *prof)
{
int i;
PayloadType *pt;
RtpProfile *newprof=rtp_profile_new(prof->name);
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++){
pt=rtp_profile_get_payload(prof,i);
if (pt!=NULL){
rtp_profile_set_payload(newprof,i,pt);
}
}
return newprof;
}
/*clone a profile and its payloads */
RtpProfile * rtp_profile_clone_full(RtpProfile *prof)
{
int i;
PayloadType *pt;
RtpProfile *newprof=rtp_profile_new(prof->name);
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++){
pt=rtp_profile_get_payload(prof,i);
if (pt!=NULL){
rtp_profile_set_payload(newprof,i,payload_type_clone(pt));
}
}
return newprof;
}
void rtp_profile_destroy(RtpProfile *prof)
{
int i;
PayloadType *payload;
if (prof->name) {
ortp_free(prof->name);
prof->name = NULL;
}
for (i=0;i<RTP_PROFILE_MAX_PAYLOADS;i++)
{
payload=rtp_profile_get_payload(prof,i);
if (payload!=NULL && (payload->flags & PAYLOAD_TYPE_ALLOCATED))
payload_type_destroy(payload);
}
ortp_free(prof);
}
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