2 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 * @short_description: Make SDP messages
22 * @see_also: #GstRTSPMedia
24 * Last reviewed on 2013-07-11 (1.0.0)
32 get_info_from_tags (GstPad * pad, GstEvent ** event, gpointer user_data)
34 GstSDPMedia *media = (GstSDPMedia *) user_data;
36 if (GST_EVENT_TYPE (*event) == GST_EVENT_TAG) {
40 gst_event_parse_tag (*event, &tags);
42 if (gst_tag_list_get_scope (tags) != GST_TAG_SCOPE_STREAM)
45 if (!gst_tag_list_get_uint (tags, GST_TAG_MAXIMUM_BITRATE,
46 &bitrate) || bitrate == 0)
47 if (!gst_tag_list_get_uint (tags, GST_TAG_BITRATE, &bitrate) ||
51 /* set bandwidth (kbits/s) */
52 gst_sdp_media_add_bandwidth (media, GST_SDP_BWTYPE_AS, bitrate / 1000);
62 update_sdp_from_tags (GstRTSPStream * stream, GstSDPMedia * stream_media)
66 src_pad = gst_rtsp_stream_get_srcpad (stream);
68 gst_pad_sticky_events_foreach (src_pad, get_info_from_tags, stream_media);
70 gst_object_unref (src_pad);
74 * gst_rtsp_sdp_from_media:
75 * @sdp: a #GstSDPMessage
77 * @media: a #GstRTSPMedia
79 * Add @media specific info to @sdp. @info is used to configure the connection
80 * information in the SDP.
82 * Returns: TRUE on success.
85 gst_rtsp_sdp_from_media (GstSDPMessage * sdp, GstSDPInfo * info,
91 n_streams = gst_rtsp_media_n_streams (media);
93 rangestr = gst_rtsp_media_get_range_string (media, FALSE, GST_RTSP_RANGE_NPT);
97 gst_sdp_message_add_attribute (sdp, "range", rangestr);
100 for (i = 0; i < n_streams; i++) {
101 GstRTSPStream *stream;
104 const gchar *caps_str, *caps_enc, *caps_params;
106 gint caps_pt, caps_rate;
112 stream = gst_rtsp_media_get_stream (media, i);
113 caps = gst_rtsp_stream_get_caps (stream);
116 g_warning ("ignoring stream %d without media type", i);
120 s = gst_caps_get_structure (caps, 0);
122 gst_caps_unref (caps);
123 g_warning ("ignoring stream %d without media type", i);
127 gst_sdp_media_new (&smedia);
129 /* get media type and payload for the m= line */
130 caps_str = gst_structure_get_string (s, "media");
131 gst_sdp_media_set_media (smedia, caps_str);
133 gst_structure_get_int (s, "payload", &caps_pt);
134 tmp = g_strdup_printf ("%d", caps_pt);
135 gst_sdp_media_add_format (smedia, tmp);
138 gst_sdp_media_set_port_info (smedia, 0, 1);
139 gst_sdp_media_set_proto (smedia, "RTP/AVP");
141 /* for the c= line */
143 gst_sdp_media_add_connection (smedia, "IN", "IP6", "::", 16, 0);
145 gst_sdp_media_add_connection (smedia, "IN", "IP4", "0.0.0.0", 16, 0);
148 /* get clock-rate, media type and params for the rtpmap attribute */
149 gst_structure_get_int (s, "clock-rate", &caps_rate);
150 caps_enc = gst_structure_get_string (s, "encoding-name");
151 caps_params = gst_structure_get_string (s, "encoding-params");
155 tmp = g_strdup_printf ("%d %s/%d/%s", caps_pt, caps_enc, caps_rate,
158 tmp = g_strdup_printf ("%d %s/%d", caps_pt, caps_enc, caps_rate);
160 gst_sdp_media_add_attribute (smedia, "rtpmap", tmp);
165 tmp = gst_rtsp_stream_get_control (stream);
166 gst_sdp_media_add_attribute (smedia, "control", tmp);
169 /* collect all other properties and add them to fmtp or attributes */
170 fmtp = g_string_new ("");
171 g_string_append_printf (fmtp, "%d ", caps_pt);
173 n_fields = gst_structure_n_fields (s);
174 for (j = 0; j < n_fields; j++) {
175 const gchar *fname, *fval;
177 fname = gst_structure_nth_field_name (s, j);
179 /* filter out standard properties */
180 if (!strcmp (fname, "media"))
182 if (!strcmp (fname, "payload"))
184 if (!strcmp (fname, "clock-rate"))
186 if (!strcmp (fname, "encoding-name"))
188 if (!strcmp (fname, "encoding-params"))
190 if (!strcmp (fname, "ssrc"))
192 if (!strcmp (fname, "clock-base"))
194 if (!strcmp (fname, "seqnum-base"))
197 if (g_str_has_prefix (fname, "a-")) {
199 if ((fval = gst_structure_get_string (s, fname)))
200 gst_sdp_media_add_attribute (smedia, fname + 2, fval);
203 if (g_str_has_prefix (fname, "x-")) {
205 if ((fval = gst_structure_get_string (s, fname)))
206 gst_sdp_media_add_attribute (smedia, fname, fval);
210 if ((fval = gst_structure_get_string (s, fname))) {
211 g_string_append_printf (fmtp, "%s%s=%s", first ? "" : ";", fname, fval);
216 tmp = g_string_free (fmtp, FALSE);
217 gst_sdp_media_add_attribute (smedia, "fmtp", tmp);
220 g_string_free (fmtp, TRUE);
223 update_sdp_from_tags (stream, smedia);
225 gst_sdp_message_add_media (sdp, smedia);
226 gst_sdp_media_free (smedia);
227 gst_caps_unref (caps);
231 GstNetTimeProvider *provider;
234 gst_rtsp_media_get_time_provider (media, info->server_ip, 0))) {
236 gchar *address, *str;
239 g_object_get (provider, "clock", &clock, "address", &address, "port",
242 str = g_strdup_printf ("GstNetTimeProvider %s %s:%d %" G_GUINT64_FORMAT,
243 g_type_name (G_TYPE_FROM_INSTANCE (clock)), address, port,
244 gst_clock_get_time (clock));
246 gst_sdp_message_add_attribute (sdp, "x-gst-clock", str);
248 gst_object_unref (clock);
250 gst_object_unref (provider);
259 GST_ERROR ("media %p is not prepared", media);