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.
24 * gst_rtsp_sdp_from_media:
25 * @sdp: a #GstSDPMessage
27 * @media: a #GstRTSPMedia
29 * Add @media specific info to @sdp. @info is used to configure the connection
30 * information in the SDP.
32 * Returns: TRUE on success.
35 gst_rtsp_sdp_from_media (GstSDPMessage * sdp, GstSDPInfo * info,
41 n_streams = gst_rtsp_media_n_streams (media);
43 rangestr = gst_rtsp_media_get_range_string (media, FALSE);
47 gst_sdp_message_add_attribute (sdp, "range", rangestr);
50 for (i = 0; i < n_streams; i++) {
51 GstRTSPStream *stream;
54 const gchar *caps_str, *caps_enc, *caps_params;
56 gint caps_pt, caps_rate;
62 stream = gst_rtsp_media_get_stream (media, i);
63 caps = gst_rtsp_stream_get_caps (stream);
66 g_warning ("ignoring stream %d without media type", i);
70 s = gst_caps_get_structure (caps, 0);
72 gst_caps_unref (caps);
73 g_warning ("ignoring stream %d without media type", i);
77 gst_sdp_media_new (&smedia);
79 /* get media type and payload for the m= line */
80 caps_str = gst_structure_get_string (s, "media");
81 gst_sdp_media_set_media (smedia, caps_str);
83 gst_structure_get_int (s, "payload", &caps_pt);
84 tmp = g_strdup_printf ("%d", caps_pt);
85 gst_sdp_media_add_format (smedia, tmp);
88 gst_sdp_media_set_port_info (smedia, 0, 1);
89 gst_sdp_media_set_proto (smedia, "RTP/AVP");
92 gst_sdp_media_add_connection (smedia, "IN", info->server_proto,
93 info->server_ip, 16, 0);
95 /* get clock-rate, media type and params for the rtpmap attribute */
96 gst_structure_get_int (s, "clock-rate", &caps_rate);
97 caps_enc = gst_structure_get_string (s, "encoding-name");
98 caps_params = gst_structure_get_string (s, "encoding-params");
102 tmp = g_strdup_printf ("%d %s/%d/%s", caps_pt, caps_enc, caps_rate,
105 tmp = g_strdup_printf ("%d %s/%d", caps_pt, caps_enc, caps_rate);
107 gst_sdp_media_add_attribute (smedia, "rtpmap", tmp);
112 tmp = g_strdup_printf ("stream=%d", i);
113 gst_sdp_media_add_attribute (smedia, "control", tmp);
116 /* collect all other properties and add them to fmtp */
117 fmtp = g_string_new ("");
118 g_string_append_printf (fmtp, "%d ", caps_pt);
120 n_fields = gst_structure_n_fields (s);
121 for (j = 0; j < n_fields; j++) {
122 const gchar *fname, *fval;
124 fname = gst_structure_nth_field_name (s, j);
126 /* filter out standard properties */
127 if (!strcmp (fname, "media"))
129 if (!strcmp (fname, "payload"))
131 if (!strcmp (fname, "clock-rate"))
133 if (!strcmp (fname, "encoding-name"))
135 if (!strcmp (fname, "encoding-params"))
137 if (!strcmp (fname, "ssrc"))
139 if (!strcmp (fname, "clock-base"))
141 if (!strcmp (fname, "seqnum-base"))
144 if ((fval = gst_structure_get_string (s, fname))) {
145 g_string_append_printf (fmtp, "%s%s=%s", first ? "" : ";", fname, fval);
150 tmp = g_string_free (fmtp, FALSE);
151 gst_sdp_media_add_attribute (smedia, "fmtp", tmp);
154 g_string_free (fmtp, TRUE);
156 gst_sdp_message_add_media (sdp, smedia);
157 gst_sdp_media_free (smedia);
158 gst_caps_unref (caps);
166 GST_ERROR ("media %p is not prepared", media);