1 /* GStreamer
2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
3 *
4 * gstrtppayloads.h: various helper functions to deal with RTP payload
5 * types.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 /**
24 * SECTION:gstrtppayloads
25 * @title: GstRTPPayloadInfo
26 * @short_description: Helper methods for dealing with RTP payloads
27 * @see_also: gstrtpbuffer
28 *
29 * The GstRTPPayloads helper functions makes it easy to deal with static and dynamic
30 * payloads. Its main purpose is to retrieve properties such as the default clock-rate
31 * and get session bandwidth information.
32 *
33 */
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
37
38 #include <string.h>
39
40 #include "gstrtppayloads.h"
41
42 /* pt, encoding_name, media, rate, params, bitrate */
43 static const GstRTPPayloadInfo info[] = {
44 /* static audio */
45 {0, "audio", "PCMU", 8000, "1", 64000},
46 /* { 1, "audio", "reserved", 0, NULL, 0 }, */
47 /* { 2, "audio", "reserved", 0, NULL, 0 }, */
48 {3, "audio", "GSM", 8000, "1", 0},
49 {4, "audio", "G723", 8000, "1", 0},
50 {5, "audio", "DVI4", 8000, "1", 32000},
51 {6, "audio", "DVI4", 16000, "1", 64000},
52 {7, "audio", "LPC", 8000, "1", 0},
53 {8, "audio", "PCMA", 8000, "1", 64000},
54 {9, "audio", "G722", 8000, "1", 64000},
55 {10, "audio", "L16", 44100, "2", 1411200},
56 {11, "audio", "L16", 44100, "1", 705600},
57 {12, "audio", "QCELP", 8000, "1", 0},
58 {13, "audio", "CN", 8000, "1", 0},
59 {14, "audio", "MPA", 90000, NULL, 0},
60 {15, "audio", "G728", 8000, "1", 0},
61 {16, "audio", "DVI4", 11025, "1", 44100},
62 {17, "audio", "DVI4", 22050, "1", 88200},
63 {18, "audio", "G729", 8000, "1", 0},
64 /* { 19, "audio", "reserved", 0, NULL, 0 }, */
65 /* { 20, "audio", "unassigned", 0, NULL, 0 }, */
66 /* { 21, "audio", "unassigned", 0, NULL, 0 }, */
67 /* { 22, "audio", "unassigned", 0, NULL, 0 }, */
68 /* { 23, "audio", "unassigned", 0, NULL, 0 }, */
69
70 /* video and video/audio */
71 /* { 24, "video", "unassigned", 0, NULL, 0 }, */
72 {25, "video", "CelB", 90000, NULL, 0},
73 {26, "video", "JPEG", 90000, NULL, 0},
74 /* { 27, "video", "unassigned", 0, NULL, 0 }, */
75 {28, "video", "nv", 90000, NULL, 0},
76 /* { 29, "video", "unassigned", 0, NULL, 0 }, */
77 /* { 30, "video", "unassigned", 0, NULL, 0 }, */
78 {31, "video", "H261", 90000, NULL, 0},
79 {32, "video", "MPV", 90000, NULL, 0},
80 {33, "video", "MP2T", 90000, NULL, 0},
81 {34, "video", "H263", 90000, NULL, 0},
82 /* { 35-71, "unassigned", 0, 0, NULL, 0 }, */
83 /* { 72-76, "reserved", 0, 0, NULL, 0 }, */
84 /* { 77-95, "unassigned", 0, 0, NULL, 0 }, */
85 /* { 96-127, "dynamic", 0, 0, NULL, 0 }, */
86
87 /* dynamic stuff */
88 {G_MAXUINT8, "application", "parityfec", 0, NULL, 0}, /* [RFC3009] */
89 {G_MAXUINT8, "application", "rtx", 0, NULL, 0}, /* [RFC4588] */
90 {G_MAXUINT8, "audio", "AMR", 8000, NULL, 0}, /* [RFC4867][RFC3267] */
91 {G_MAXUINT8, "audio", "AMR-WB", 16000, NULL, 0}, /* [RFC4867][RFC3267] */
92 {G_MAXUINT8, "audio", "DAT12", 0, NULL, 0}, /* [RFC3190] */
93 {G_MAXUINT8, "audio", "dsr-es201108", 0, NULL, 0}, /* [RFC3557] */
94 {G_MAXUINT8, "audio", "EVRC", 8000, "1", 0}, /* [RFC4788] */
95 {G_MAXUINT8, "audio", "EVRC0", 8000, "1", 0}, /* [RFC4788] */
96 {G_MAXUINT8, "audio", "EVRC1", 8000, "1", 0}, /* [RFC4788] */
97 {G_MAXUINT8, "audio", "EVRCB", 8000, "1", 0}, /* [RFC4788] */
98 {G_MAXUINT8, "audio", "EVRCB0", 8000, "1", 0}, /* [RFC4788] */
99 {G_MAXUINT8, "audio", "EVRCB1", 8000, "1", 0}, /* [RFC4788] */
100 {G_MAXUINT8, "audio", "G7221", 16000, "1", 0}, /* [RFC3047] */
101 {G_MAXUINT8, "audio", "G726-16", 8000, "1", 0}, /* [RFC3551][RFC4856] */
102 {G_MAXUINT8, "audio", "G726-24", 8000, "1", 0}, /* [RFC3551][RFC4856] */
103 {G_MAXUINT8, "audio", "G726-32", 8000, "1", 0}, /* [RFC3551][RFC4856] */
104 {G_MAXUINT8, "audio", "G726-40", 8000, "1", 0}, /* [RFC3551][RFC4856] */
105 {G_MAXUINT8, "audio", "G729D", 8000, "1", 0}, /* [RFC3551][RFC4856] */
106 {G_MAXUINT8, "audio", "G729E", 8000, "1", 0}, /* [RFC3551][RFC4856] */
107 {G_MAXUINT8, "audio", "GSM-EFR", 8000, "1", 0}, /* [RFC3551][RFC4856] */
108 {G_MAXUINT8, "audio", "L8", 0, NULL, 0}, /* [RFC3551][RFC4856] */
109 {G_MAXUINT8, "audio", "RED", 0, NULL, 0}, /* [RFC2198][RFC3555] */
110 {G_MAXUINT8, "audio", "rtx", 0, NULL, 0}, /* [RFC4588] */
111 {G_MAXUINT8, "audio", "VDVI", 0, "1", 0}, /* [RFC3551][RFC4856] */
112 {G_MAXUINT8, "audio", "L20", 0, NULL, 0}, /* [RFC3190] */
113 {G_MAXUINT8, "audio", "L24", 0, NULL, 0}, /* [RFC3190] */
114 {G_MAXUINT8, "audio", "MP4A-LATM", 0, NULL, 0}, /* [RFC3016] */
115 {G_MAXUINT8, "audio", "mpa-robust", 90000, NULL, 0}, /* [RFC3119] */
116 {G_MAXUINT8, "audio", "parityfec", 0, NULL, 0}, /* [RFC3009] */
117 {G_MAXUINT8, "audio", "SMV", 8000, "1", 0}, /* [RFC3558] */
118 {G_MAXUINT8, "audio", "SMV0", 8000, "1", 0}, /* [RFC3558] */
119 {G_MAXUINT8, "audio", "t140c", 0, NULL, 0}, /* [RFC4351] */
120 {G_MAXUINT8, "audio", "t38", 0, NULL, 0}, /* [RFC4612] */
121 {G_MAXUINT8, "audio", "telephone-event", 0, NULL, 0}, /* [RFC4733] */
122 {G_MAXUINT8, "audio", "tone", 0, NULL, 0}, /* [RFC4733] */
123 {G_MAXUINT8, "audio", "DVI4", 0, NULL, 0}, /* [RFC4856] */
124 {G_MAXUINT8, "audio", "G722", 0, NULL, 0}, /* [RFC4856] */
125 {G_MAXUINT8, "audio", "G723", 0, NULL, 0}, /* [RFC4856] */
126 {G_MAXUINT8, "audio", "G728", 0, NULL, 0}, /* [RFC4856] */
127 {G_MAXUINT8, "audio", "G729", 0, NULL, 0}, /* [RFC4856] */
128 {G_MAXUINT8, "audio", "GSM", 0, NULL, 0}, /* [RFC4856] */
129 {G_MAXUINT8, "audio", "L16", 0, NULL, 0}, /* [RFC4856] */
130 {G_MAXUINT8, "audio", "LPC", 0, NULL, 0}, /* [RFC4856] */
131 {G_MAXUINT8, "audio", "PCMA", 0, NULL, 0}, /* [RFC4856] */
132 {G_MAXUINT8, "audio", "PCMU", 0, NULL, 0}, /* [RFC4856] */
133 {G_MAXUINT8, "text", "parityfec", 0, NULL, 0}, /* [RFC3009] */
134 {G_MAXUINT8, "text", "red", 1000, NULL, 0}, /* [RFC4102] */
135 {G_MAXUINT8, "text", "rtx", 0, NULL, 0}, /* [RFC4588] */
136 {G_MAXUINT8, "text", "t140", 1000, NULL, 0}, /* [RFC4103] */
137 {G_MAXUINT8, "video", "BMPEG", 90000, NULL, 0}, /* [RFC2343][RFC3555] */
138 {G_MAXUINT8, "video", "BT656", 90000, NULL, 0}, /* [RFC2431][RFC3555] */
139 {G_MAXUINT8, "video", "DV", 90000, NULL, 0}, /* [RFC3189] */
140 {G_MAXUINT8, "video", "H263-1998", 90000, NULL, 0}, /* [RFC2429][RFC3555] */
141 {G_MAXUINT8, "video", "H263-2000", 90000, NULL, 0}, /* [RFC2429][RFC3555] */
142 {G_MAXUINT8, "video", "MP1S", 90000, NULL, 0}, /* [RFC2250][RFC3555] */
143 {G_MAXUINT8, "video", "MP2P", 90000, NULL, 0}, /* [RFC2250][RFC3555] */
144 {G_MAXUINT8, "video", "MP4V-ES", 90000, NULL, 0}, /* [RFC3016] */
145 {G_MAXUINT8, "video", "parityfec", 0, NULL, 0}, /* [RFC3009] */
146 {G_MAXUINT8, "video", "pointer", 90000, NULL, 0}, /* [RFC2862] */
147 {G_MAXUINT8, "video", "raw", 90000, NULL, 0}, /* [RFC4175] */
148 {G_MAXUINT8, "video", "rtx", 0, NULL, 0}, /* [RFC4588] */
149 {G_MAXUINT8, "video", "SMPTE292M", 0, NULL, 0}, /* [RFC3497] */
150 {G_MAXUINT8, "video", "vc1", 90000, NULL, 0}, /* [RFC4425] */
151
152 /* not in http://www.iana.org/assignments/rtp-parameters */
153 {G_MAXUINT8, "audio", "AC3", 0, NULL, 0},
154 {G_MAXUINT8, "audio", "ILBC", 8000, NULL, 0},
155 {G_MAXUINT8, "audio", "MPEG4-GENERIC", 0, NULL, 0},
156 {G_MAXUINT8, "audio", "SPEEX", 0, NULL, 0},
157 {G_MAXUINT8, "audio", "OPUS", 48000, NULL, 0},
158
159 {G_MAXUINT8, "application", "MPEG4-GENERIC", 0, NULL, 0},
160
161 {G_MAXUINT8, "video", "H264", 90000, NULL, 0},
162 {G_MAXUINT8, "video", "H265", 90000, NULL, 0},
163 {G_MAXUINT8, "video", "MPEG4-GENERIC", 90000, NULL, 0},
164 {G_MAXUINT8, "video", "THEORA", 0, NULL, 0},
165 {G_MAXUINT8, "video", "VORBIS", 0, NULL, 0},
166 {G_MAXUINT8, "video", "X-SV3V-ES", 90000, NULL, 0},
167 {G_MAXUINT8, "video", "X-SORENSON-VIDEO", 90000, NULL, 0},
168 {G_MAXUINT8, "video", "VP8", 90000, NULL, 0},
169 {G_MAXUINT8, "video", "VP9", 90000, NULL, 0},
170
171 /* real stuff */
172 {G_MAXUINT8, "video", "x-pn-realvideo", 1000, NULL, 0},
173 {G_MAXUINT8, "audio", "x-pn-realaudio", 1000, NULL, 0},
174 {G_MAXUINT8, "application", "x-pn-realmedia", 1000, NULL, 0},
175
176 /* terminator */
177 {G_MAXUINT8, NULL, NULL, 0, NULL, 0}
178 };
179
180 /**
181 * gst_rtp_payload_info_for_pt:
182 * @payload_type: the payload_type to find
183 *
184 * Get the #GstRTPPayloadInfo for @payload_type. This function is
185 * mostly used to get the default clock-rate and bandwidth for static payload
186 * types specified with @payload_type.
187 *
188 * Returns: a #GstRTPPayloadInfo or NULL when no info could be found.
189 */
190 const GstRTPPayloadInfo *
gst_rtp_payload_info_for_pt(guint8 payload_type)191 gst_rtp_payload_info_for_pt (guint8 payload_type)
192 {
193 const GstRTPPayloadInfo *result = NULL;
194 gint i;
195
196 for (i = 0; info[i].media; i++) {
197 if (info[i].payload_type == payload_type) {
198 result = &info[i];
199 break;
200 }
201 }
202 return result;
203 }
204
205 /**
206 * gst_rtp_payload_info_for_name:
207 * @media: the media to find
208 * @encoding_name: the encoding name to find
209 *
210 * Get the #GstRTPPayloadInfo for @media and @encoding_name. This function is
211 * mostly used to get the default clock-rate and bandwidth for dynamic payload
212 * types specified with @media and @encoding name.
213 *
214 * The search for @encoding_name will be performed in a case insensitive way.
215 *
216 * Returns: a #GstRTPPayloadInfo or NULL when no info could be found.
217 */
218 const GstRTPPayloadInfo *
gst_rtp_payload_info_for_name(const gchar * media,const gchar * encoding_name)219 gst_rtp_payload_info_for_name (const gchar * media, const gchar * encoding_name)
220 {
221 const GstRTPPayloadInfo *result = NULL;
222 gint i;
223
224 for (i = 0; info[i].media; i++) {
225 if (strcmp (media, info[i].media) == 0
226 && g_ascii_strcasecmp (encoding_name, info[i].encoding_name) == 0) {
227 result = &info[i];
228 break;
229 }
230 }
231 return result;
232 }
233