2009-01-29 12:31:27 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:14:25 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-01-29 12:31:27 +00:00
|
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "rtsp-sdp.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_sdp_from_media:
|
2010-12-11 09:48:25 +00:00
|
|
|
* @sdp: a #GstSDPMessage
|
2010-03-16 17:37:18 +00:00
|
|
|
* @info: info
|
2009-01-29 12:31:27 +00:00
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
2010-03-16 17:37:18 +00:00
|
|
|
* Add @media specific info to @sdp. @info is used to configure the connection
|
|
|
|
* information in the SDP.
|
2009-01-29 12:31:27 +00:00
|
|
|
*
|
2010-03-16 17:37:18 +00:00
|
|
|
* Returns: TRUE on success.
|
2009-01-29 12:31:27 +00:00
|
|
|
*/
|
2010-03-16 17:37:18 +00:00
|
|
|
gboolean
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_sdp_from_media (GstSDPMessage * sdp, GstSDPInfo * info,
|
|
|
|
GstRTSPMedia * media)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
|
|
|
guint i, n_streams;
|
2009-02-04 16:00:42 +00:00
|
|
|
gchar *rangestr;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2010-03-05 16:57:08 +00:00
|
|
|
if (media->status != GST_RTSP_MEDIA_STATUS_PREPARED)
|
|
|
|
goto not_prepared;
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
n_streams = gst_rtsp_media_n_streams (media);
|
|
|
|
|
2010-12-28 17:35:01 +00:00
|
|
|
rangestr = gst_rtsp_media_get_range_string (media, FALSE);
|
2009-02-04 16:00:42 +00:00
|
|
|
gst_sdp_message_add_attribute (sdp, "range", rangestr);
|
|
|
|
g_free (rangestr);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n_streams; i++) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStream *stream;
|
2009-01-29 12:31:27 +00:00
|
|
|
GstSDPMedia *smedia;
|
|
|
|
GstStructure *s;
|
|
|
|
const gchar *caps_str, *caps_enc, *caps_params;
|
|
|
|
gchar *tmp;
|
|
|
|
gint caps_pt, caps_rate;
|
|
|
|
guint n_fields, j;
|
|
|
|
gboolean first;
|
|
|
|
GString *fmtp;
|
|
|
|
|
|
|
|
stream = gst_rtsp_media_get_stream (media, i);
|
2009-06-03 10:13:21 +00:00
|
|
|
|
|
|
|
if (stream->caps == NULL) {
|
|
|
|
g_warning ("ignoring stream %d without media type", i);
|
|
|
|
continue;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
s = gst_caps_get_structure (stream->caps, 0);
|
2009-06-03 10:13:21 +00:00
|
|
|
if (s == NULL) {
|
|
|
|
g_warning ("ignoring stream %d without media type", i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_sdp_media_new (&smedia);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
/* get media type and payload for the m= line */
|
|
|
|
caps_str = gst_structure_get_string (s, "media");
|
|
|
|
gst_sdp_media_set_media (smedia, caps_str);
|
|
|
|
|
|
|
|
gst_structure_get_int (s, "payload", &caps_pt);
|
|
|
|
tmp = g_strdup_printf ("%d", caps_pt);
|
|
|
|
gst_sdp_media_add_format (smedia, tmp);
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
gst_sdp_media_set_port_info (smedia, 0, 1);
|
|
|
|
gst_sdp_media_set_proto (smedia, "RTP/AVP");
|
|
|
|
|
|
|
|
/* for the c= line */
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_sdp_media_add_connection (smedia, "IN", info->server_proto,
|
|
|
|
info->server_ip, 16, 0);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
/* get clock-rate, media type and params for the rtpmap attribute */
|
|
|
|
gst_structure_get_int (s, "clock-rate", &caps_rate);
|
|
|
|
caps_enc = gst_structure_get_string (s, "encoding-name");
|
|
|
|
caps_params = gst_structure_get_string (s, "encoding-params");
|
|
|
|
|
2009-05-24 17:33:22 +00:00
|
|
|
if (caps_enc) {
|
|
|
|
if (caps_params)
|
|
|
|
tmp = g_strdup_printf ("%d %s/%d/%s", caps_pt, caps_enc, caps_rate,
|
2010-03-05 16:57:08 +00:00
|
|
|
caps_params);
|
2009-05-24 17:33:22 +00:00
|
|
|
else
|
|
|
|
tmp = g_strdup_printf ("%d %s/%d", caps_pt, caps_enc, caps_rate);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-05-24 17:33:22 +00:00
|
|
|
gst_sdp_media_add_attribute (smedia, "rtpmap", tmp);
|
|
|
|
g_free (tmp);
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
/* the config uri */
|
|
|
|
tmp = g_strdup_printf ("stream=%d", i);
|
|
|
|
gst_sdp_media_add_attribute (smedia, "control", tmp);
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
/* collect all other properties and add them to fmtp */
|
|
|
|
fmtp = g_string_new ("");
|
|
|
|
g_string_append_printf (fmtp, "%d ", caps_pt);
|
|
|
|
first = TRUE;
|
|
|
|
n_fields = gst_structure_n_fields (s);
|
|
|
|
for (j = 0; j < n_fields; j++) {
|
|
|
|
const gchar *fname, *fval;
|
|
|
|
|
|
|
|
fname = gst_structure_nth_field_name (s, j);
|
|
|
|
|
|
|
|
/* filter out standard properties */
|
2010-03-05 16:57:08 +00:00
|
|
|
if (!strcmp (fname, "media"))
|
2009-01-29 12:31:27 +00:00
|
|
|
continue;
|
2010-03-05 16:57:08 +00:00
|
|
|
if (!strcmp (fname, "payload"))
|
2009-01-29 12:31:27 +00:00
|
|
|
continue;
|
2010-03-05 16:57:08 +00:00
|
|
|
if (!strcmp (fname, "clock-rate"))
|
2009-01-29 12:31:27 +00:00
|
|
|
continue;
|
2010-03-05 16:57:08 +00:00
|
|
|
if (!strcmp (fname, "encoding-name"))
|
2009-01-29 12:31:27 +00:00
|
|
|
continue;
|
2010-03-05 16:57:08 +00:00
|
|
|
if (!strcmp (fname, "encoding-params"))
|
2009-01-29 12:31:27 +00:00
|
|
|
continue;
|
2010-03-05 16:57:08 +00:00
|
|
|
if (!strcmp (fname, "ssrc"))
|
2009-01-29 12:31:27 +00:00
|
|
|
continue;
|
2010-03-05 16:57:08 +00:00
|
|
|
if (!strcmp (fname, "clock-base"))
|
2009-01-29 12:31:27 +00:00
|
|
|
continue;
|
2010-03-05 16:57:08 +00:00
|
|
|
if (!strcmp (fname, "seqnum-base"))
|
2009-01-29 12:31:27 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((fval = gst_structure_get_string (s, fname))) {
|
2010-03-05 16:57:08 +00:00
|
|
|
g_string_append_printf (fmtp, "%s%s=%s", first ? "" : ";", fname, fval);
|
2009-01-29 12:31:27 +00:00
|
|
|
first = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!first) {
|
|
|
|
tmp = g_string_free (fmtp, FALSE);
|
|
|
|
gst_sdp_media_add_attribute (smedia, "fmtp", tmp);
|
|
|
|
g_free (tmp);
|
2010-03-05 16:57:08 +00:00
|
|
|
} else {
|
2009-01-29 12:31:27 +00:00
|
|
|
g_string_free (fmtp, TRUE);
|
|
|
|
}
|
|
|
|
gst_sdp_message_add_media (sdp, smedia);
|
2009-01-30 16:06:26 +00:00
|
|
|
gst_sdp_media_free (smedia);
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 17:37:18 +00:00
|
|
|
return TRUE;
|
2010-03-05 16:57:08 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
not_prepared:
|
|
|
|
{
|
|
|
|
GST_ERROR ("media %p is not prepared", media);
|
2010-03-16 17:37:18 +00:00
|
|
|
return FALSE;
|
2010-03-05 16:57:08 +00:00
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|