27 #include <sbIGStreamerService.h>
30 #include <nsServiceManagerUtils.h>
31 #include <nsThreadUtils.h>
32 #include <nsStringAPI.h>
37 #include "gst/sdp/gstsdp.h"
38 #include "gst/sdp/gstsdpmessage.h"
45 static PRLogModuleInfo* gGStreamerRTPStreamer = PR_NewLogModule(
"sbGStreamerRTPStreamer");
46 #define LOG(args) PR_LOG(gGStreamerRTPStreamer, PR_LOG_WARNING, args)
47 #define TRACE(args) PR_LOG(gGStreamerRTPStreamer, PR_LOG_DEBUG, args)
67 sbGStreamerRTPStreamer::sbGStreamerRTPStreamer() :
75 sbGStreamerRTPStreamer::~sbGStreamerRTPStreamer()
82 sbGStreamerRTPStreamer::SetSourceURI(
const nsAString& aSourceURI)
84 mSourceURI = aSourceURI;
89 sbGStreamerRTPStreamer::GetSourceURI(nsAString& aSourceURI)
91 aSourceURI = mSourceURI;
96 sbGStreamerRTPStreamer::SetDestHost(
const nsAString& aDestHost)
98 mDestHost = aDestHost;
103 sbGStreamerRTPStreamer::GetDestHost(nsAString& aDestHost)
105 aDestHost = mDestHost;
110 sbGStreamerRTPStreamer::SetDestPort(PRInt32 aDestPort)
112 mDestPort = aDestPort;
117 sbGStreamerRTPStreamer::GetDestPort(PRInt32 *aDestPort)
119 *aDestPort = mDestPort;
126 nsCString pipelineString = NS_ConvertUTF16toUTF8(mSourceURI);
129 pipelineString += NS_LITERAL_CSTRING(
130 " ! decodebin ! audioconvert ! audioresample ! vorbisenc ! "
131 "rtpvorbispay name=payloader ! multiudpsink name=udpsink");
133 pipelineString += NS_LITERAL_CSTRING(
134 " ! decodebin ! audioconvert ! audioresample ! lame ! mp3parse ! "
135 "rtpmpapay name=payloader ! multiudpsink name=udpsink");
138 GError *error = NULL;
140 GstElement *sink, *payloader;
144 mPipeline = gst_parse_launch (pipelineString.BeginReading(), &error);
148 rv = NS_ERROR_FAILURE;
152 sink = gst_bin_get_by_name (GST_BIN (
mPipeline),
"udpsink");
154 host = NS_ConvertUTF16toUTF8(mDestHost);
155 g_signal_emit_by_name (sink,
"add", host.BeginReading(), mDestPort);
156 gst_object_unref (sink);
158 payloader = gst_bin_get_by_name (GST_BIN (
mPipeline),
"payloader");
159 srcpad = gst_element_get_pad (payloader,
"src");
160 g_signal_connect (srcpad,
"notify::caps", (GCallback) capsNotifyHelper,
this);
161 gst_object_unref (srcpad);
162 gst_object_unref (payloader);
170 sbGStreamerRTPStreamer::capsNotifyHelper(GObject* obj, GParamSpec* pspec,
173 GstPad *pad = GST_PAD(obj);
174 GstCaps *caps = gst_pad_get_negotiated_caps(pad);
178 gst_caps_unref (caps);
188 const gchar *capsstr, *encoding_name, *encoding_params;
191 const char *stdproperties[] = {
"media",
"payload",
"clock-rate",
192 "encoding-name",
"encoding-params",
"ssrc",
"clock-base",
197 gst_sdp_message_new (&sdp);
199 gst_sdp_message_set_version (sdp,
"0");
200 gst_sdp_message_set_origin (sdp,
207 gst_sdp_message_set_session_name (sdp,
"Songbird RTP Stream");
208 gst_sdp_message_set_information (sdp,
"Streaming from Songbird");
209 gst_sdp_message_add_time (sdp,
"0",
"0", NULL);
210 gst_sdp_message_add_attribute (sdp,
"tool",
"songbird");
217 gst_sdp_media_new (&media);
218 s = gst_caps_get_structure (caps, 0);
220 capsstr = gst_structure_get_string (s,
"media");
221 gst_sdp_media_set_media (media, capsstr);
223 gst_structure_get_int (s,
"payload", &pt);
224 tmp = g_strdup_printf(
"%d", pt);
225 gst_sdp_media_add_format (media, tmp);
228 gst_sdp_media_set_port_info (media, mDestPort, 1);
229 gst_sdp_media_set_proto (media,
"RTP/AVP");
234 gst_sdp_media_add_connection (media,
"IN",
"IP4",
"0.0.0.0", 0, 0);
236 gst_structure_get_int (s,
"clock-rate", &rate);
237 encoding_name = gst_structure_get_string (s,
"encoding-name");
238 encoding_params = gst_structure_get_string (s,
"encoding-params");
240 tmp = g_strdup_printf (
"%d %s/%d/%s", pt, encoding_name, rate,
243 tmp = g_strdup_printf (
"%d %s/%d", pt, encoding_name, rate);
244 gst_sdp_media_add_attribute (media,
"rtpmap", tmp);
248 int fields = gst_structure_n_fields (s);
249 GString *fmtp = g_string_new (
"");
250 g_string_append_printf (fmtp,
"%d ", pt);
252 for (
int i = 0;
i < fields;
i++)
255 const gchar *fieldname = gst_structure_nth_field_name (s,
i);
256 const gchar *fieldval;
257 for (
unsigned int j = 0;
258 j <
sizeof (stdproperties)/
sizeof(*stdproperties); j++)
260 if (!strcmp (fieldname, stdproperties[
i]))
263 if (!skip && (fieldval = gst_structure_get_string (s, fieldname)))
266 g_string_append_printf (fmtp,
";");
269 g_string_append_printf (fmtp,
"%s=%s", fieldname, fieldval);
275 gst_sdp_media_add_attribute (media,
"fmtp", fmtp->str);
277 g_string_free (fmtp, TRUE);
279 gst_sdp_message_add_media (sdp, media);
280 gst_sdp_media_free (media);
282 gchar *text = gst_sdp_message_as_text (sdp);
283 nsCString sdptext(text);
286 gst_sdp_message_free (sdp);
void OnCapsSet(GstCaps *caps)
Songbird Variant Utility Definitions.
NS_IMPL_THREADSAFE_CI(sbGStreamerRTPStreamer)
void DispatchMediacoreEvent(unsigned long type, nsIVariant *aData=NULL, sbIMediacoreError *aError=NULL)
virtual nsresult BuildPipeline()
NS_IMPL_THREADSAFE_ISUPPORTS4(sbGStreamerRTPStreamer, sbIGStreamerPipeline, sbIGStreamerRTPStreamer, sbIMediacoreEventTarget, nsIClassInfo) NS_IMPL_CI_INTERFACE_GETTER3(sbGStreamerRTPStreamer
void SetPipelineOp(GStreamer::pipelineOp_t aPipelineOp)
NS_DECL_CLASSINFO(sbGstreamerRTPStreamer)
const unsigned long EVENT_SDP_AVAILABLE
_getSelectedPageStyle s i