diff --git a/audio_capture/launch/capture_udp.launch b/audio_capture/launch/capture_udp.launch new file mode 100644 index 00000000..8fbc0d56 --- /dev/null +++ b/audio_capture/launch/capture_udp.launch @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/audio_capture/src/audio_capture.cpp b/audio_capture/src/audio_capture.cpp index e5d6ee5f..21970099 100644 --- a/audio_capture/src/audio_capture.cpp +++ b/audio_capture/src/audio_capture.cpp @@ -14,9 +14,7 @@ namespace audio_transport public: RosGstCapture() { - _bitrate = 192; - - std::string dst_type; + std::string dst_type, source_type; // Need to encoding or publish raw wave data ros::param::param("~format", _format, "mp3"); @@ -33,7 +31,7 @@ namespace audio_transport ros::param::param("~dst", dst_type, "appsink"); // The source of the audio - //ros::param::param("~src", source_type, "alsasrc"); + ros::param::param("~src", source_type, "alsasrc"); std::string device; ros::param::param("~device", device, ""); @@ -63,29 +61,65 @@ namespace audio_transport g_object_set( G_OBJECT(_sink), "location", dst_type.c_str(), NULL); } - _source = gst_element_factory_make("alsasrc", "source"); - // if device isn't specified, it will use the default which is - // the alsa default source. - // A valid device will be of the foram hw:0,0 with other numbers - // than 0 and 0 as are available. - if (device != "") - { - // ghcar *gst_device = device.c_str(); - g_object_set(G_OBJECT(_source), "device", device.c_str(), NULL); - } + _source = gst_element_factory_make(source_type.c_str(), "source"); _filter = gst_element_factory_make("capsfilter", "filter"); + + GstCaps *caps; + if (source_type == "udpsrc") { - GstCaps *caps; + int port; + ros::param::param("~port", port, 5603); + g_object_set (G_OBJECT (_source), "port", port, NULL); + + std::string depay; + ros::param::param("~depay", depay, "L16"); + + caps = gst_caps_new_simple("application/x-rtp", + "media", G_TYPE_STRING, "audio", + "clock-rate", G_TYPE_INT, _sample_rate, + "encoding-name", G_TYPE_STRING, depay.c_str(), + "channels", G_TYPE_INT, _channels, + NULL); + + if (depay == "L16") + { + _depay = gst_element_factory_make ("rtpL16depay", "rtpdepay"); + } + else + { + ROS_ERROR_STREAM("Depay currently not supported, it must be \"L16\""); + exitOnMainThread(1); + } + } + else if (source_type == "alsasrc") + { + // if device isn't specified, it will use the default which is + // the alsa default source. + // A valid device will be of the foram hw:0,0 with other numbers + // than 0 and 0 as are available. + if (device != "") + { + // ghcar *gst_device = device.c_str(); + g_object_set(G_OBJECT(_source), "device", device.c_str(), NULL); + } + caps = gst_caps_new_simple("audio/x-raw", // "channels", G_TYPE_INT, _channels, // "depth", G_TYPE_INT, _depth, "rate", G_TYPE_INT, _sample_rate, // "signed", G_TYPE_BOOLEAN, TRUE, NULL); - g_object_set( G_OBJECT(_filter), "caps", caps, NULL); - gst_caps_unref(caps); + + _depay = NULL; + } + else + { + ROS_ERROR_STREAM("Source currently not supported"); + exitOnMainThread(1); } + g_object_set( G_OBJECT(_filter), "caps", caps, NULL); + gst_caps_unref(caps); _convert = gst_element_factory_make("audioconvert", "convert"); if (!_convert) { @@ -104,8 +138,16 @@ namespace audio_transport g_object_set( G_OBJECT(_encode), "quality", 2.0, NULL); g_object_set( G_OBJECT(_encode), "bitrate", _bitrate, NULL); - gst_bin_add_many( GST_BIN(_pipeline), _source, _filter, _convert, _encode, _sink, NULL); - link_ok = gst_element_link_many(_source, _filter, _convert, _encode, _sink, NULL); + if (_depay== NULL) + { + gst_bin_add_many( GST_BIN(_pipeline), _source, _filter, _convert, _encode, _sink, NULL); + link_ok = gst_element_link_many(_source, _filter, _convert, _encode, _sink, NULL); + } + else + { + gst_bin_add_many( GST_BIN(_pipeline), _source, _filter, _depay, _convert, _encode, _sink, NULL); + link_ok = gst_element_link_many(_source, _filter, _depay, _convert, _encode, _sink, NULL); + } } else if (_format == "wave") { GstCaps *caps; caps = gst_caps_new_simple("audio/x-raw", @@ -209,7 +251,7 @@ namespace audio_transport boost::thread _gst_thread; - GstElement *_pipeline, *_source, *_filter, *_sink, *_convert, *_encode; + GstElement *_pipeline, *_source, *_filter, *_sink, *_convert, *_encode, *_depay; GstBus *_bus; int _bitrate, _channels, _depth, _sample_rate; GMainLoop *_loop;