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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, 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 if (media->status != GST_RTSP_MEDIA_STATUS_PREPARED)
44 n_streams = gst_rtsp_media_n_streams (media);
46 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 GstRTSPMediaStream *stream;
54 const gchar *caps_str, *caps_enc, *caps_params;
56 gint caps_pt, caps_rate;
61 stream = gst_rtsp_media_get_stream (media, i);
63 if (stream->caps == NULL) {
64 g_warning ("ignoring stream %d without media type", i);
68 s = gst_caps_get_structure (stream->caps, 0);
70 g_warning ("ignoring stream %d without media type", i);
74 gst_sdp_media_new (&smedia);
76 /* get media type and payload for the m= line */
77 caps_str = gst_structure_get_string (s, "media");
78 gst_sdp_media_set_media (smedia, caps_str);
80 gst_structure_get_int (s, "payload", &caps_pt);
81 tmp = g_strdup_printf ("%d", caps_pt);
82 gst_sdp_media_add_format (smedia, tmp);
85 gst_sdp_media_set_port_info (smedia, 0, 1);
86 gst_sdp_media_set_proto (smedia, "RTP/AVP");
89 gst_sdp_media_add_connection (smedia, "IN", info->server_proto,
90 info->server_ip, 16, 0);
92 /* get clock-rate, media type and params for the rtpmap attribute */
93 gst_structure_get_int (s, "clock-rate", &caps_rate);
94 caps_enc = gst_structure_get_string (s, "encoding-name");
95 caps_params = gst_structure_get_string (s, "encoding-params");
99 tmp = g_strdup_printf ("%d %s/%d/%s", caps_pt, caps_enc, caps_rate,
102 tmp = g_strdup_printf ("%d %s/%d", caps_pt, caps_enc, caps_rate);
104 gst_sdp_media_add_attribute (smedia, "rtpmap", tmp);
109 tmp = g_strdup_printf ("stream=%d", i);
110 gst_sdp_media_add_attribute (smedia, "control", tmp);
113 /* collect all other properties and add them to fmtp */
114 fmtp = g_string_new ("");
115 g_string_append_printf (fmtp, "%d ", caps_pt);
117 n_fields = gst_structure_n_fields (s);
118 for (j = 0; j < n_fields; j++) {
119 const gchar *fname, *fval;
121 fname = gst_structure_nth_field_name (s, j);
123 /* filter out standard properties */
124 if (!strcmp (fname, "media"))
126 if (!strcmp (fname, "payload"))
128 if (!strcmp (fname, "clock-rate"))
130 if (!strcmp (fname, "encoding-name"))
132 if (!strcmp (fname, "encoding-params"))
134 if (!strcmp (fname, "ssrc"))
136 if (!strcmp (fname, "clock-base"))
138 if (!strcmp (fname, "seqnum-base"))
141 if ((fval = gst_structure_get_string (s, fname))) {
142 g_string_append_printf (fmtp, "%s%s=%s", first ? "" : ";", fname, fval);
147 tmp = g_string_free (fmtp, FALSE);
148 gst_sdp_media_add_attribute (smedia, "fmtp", tmp);
151 g_string_free (fmtp, TRUE);
153 gst_sdp_message_add_media (sdp, smedia);
154 gst_sdp_media_free (smedia);
162 GST_ERROR ("media %p is not prepared", media);