1 /*
2  * The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) implementation with additional features.
3  * Copyright (C) 2017 Belledonne Communications SARL
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19 
20 /**
21  * \file rtpprofile.h
22  * \brief Using and creating standart and custom RTP profiles
23  *
24 **/
25 
26 #ifndef RTPPROFILE_H
27 #define RTPPROFILE_H
28 #include <ortp/port.h>
29 
30 #ifdef __cplusplus
31 extern "C"{
32 #endif
33 
34 #define RTP_PROFILE_MAX_PAYLOADS 128
35 
36 /**
37  * The RTP profile is a table RTP_PROFILE_MAX_PAYLOADS entries to make the matching
38  * between RTP payload type number and the PayloadType that defines the type of
39  * media.
40 **/
41 struct _RtpProfile
42 {
43 	char *name;
44 	PayloadType *payload[RTP_PROFILE_MAX_PAYLOADS];
45 };
46 
47 
48 typedef struct _RtpProfile RtpProfile;
49 
50 ORTP_VAR_PUBLIC RtpProfile av_profile;
51 
52 #define rtp_profile_get_name(profile) 	(const char*)((profile)->name)
53 
54 ORTP_PUBLIC void rtp_profile_set_payload(RtpProfile *prof, int idx, PayloadType *pt);
55 
56 /**
57  *	Set payload type number \a index unassigned in the profile.
58  *
59  *@param profile an RTP profile
60  *@param index	the payload type number
61 **/
62 #define rtp_profile_clear_payload(profile,index) \
63 	rtp_profile_set_payload(profile,index,NULL)
64 
65 /* I prefer have this function inlined because it is very often called in the code */
66 /**
67  *
68  *	Gets the payload description of the payload type \a index in the profile.
69  *
70  *@param prof an RTP profile (a #_RtpProfile object)
71  *@param idx	the payload type number
72  *@return the payload description (a PayloadType object)
73 **/
rtp_profile_get_payload(const RtpProfile * prof,int idx)74 static ORTP_INLINE PayloadType * rtp_profile_get_payload(const RtpProfile *prof, int idx){
75 	if (idx<0 || idx>=RTP_PROFILE_MAX_PAYLOADS) {
76 		return NULL;
77 	}
78 	return prof->payload[idx];
79 }
80 ORTP_PUBLIC void rtp_profile_clear_all(RtpProfile *prof);
81 ORTP_PUBLIC void rtp_profile_set_name(RtpProfile *prof, const char *name);
82 ORTP_PUBLIC PayloadType * rtp_profile_get_payload_from_mime(RtpProfile *profile,const char *mime);
83 ORTP_PUBLIC PayloadType * rtp_profile_get_payload_from_rtpmap(RtpProfile *profile, const char *rtpmap);
84 ORTP_PUBLIC int rtp_profile_get_payload_number_from_mime(RtpProfile *profile, const char *mime);
85 ORTP_PUBLIC int rtp_profile_get_payload_number_from_mime_and_flag(RtpProfile *profile, const char *mime, int flag);
86 ORTP_PUBLIC int rtp_profile_get_payload_number_from_rtpmap(RtpProfile *profile, const char *rtpmap);
87 ORTP_PUBLIC int rtp_profile_find_payload_number(RtpProfile *prof,const char *mime,int rate, int channels);
88 ORTP_PUBLIC PayloadType * rtp_profile_find_payload(RtpProfile *prof,const char *mime,int rate, int channels);
89 ORTP_PUBLIC int rtp_profile_move_payload(RtpProfile *prof,int oldpos,int newpos);
90 
91 ORTP_PUBLIC RtpProfile * rtp_profile_new(const char *name);
92 /* clone a profile, payload are not cloned */
93 ORTP_PUBLIC RtpProfile * rtp_profile_clone(RtpProfile *prof);
94 
95 
96 /*clone a profile and its payloads (ie payload type are newly allocated, not reusing payload types of the reference profile) */
97 ORTP_PUBLIC RtpProfile * rtp_profile_clone_full(RtpProfile *prof);
98 /* frees the profile and all its PayloadTypes*/
99 ORTP_PUBLIC void rtp_profile_destroy(RtpProfile *prof);
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif
106