2 #include <gst/app/gstappsrc.h> 4 #include <boost/thread.hpp> 6 #include "audio_common_msgs/AudioData.h" 21 ros::param::param<std::string>(
"~dst", dst_type,
"alsasink");
22 ros::param::param<std::string>(
"~device", device, std::string());
26 _loop = g_main_loop_new(NULL,
false);
28 _pipeline = gst_pipeline_new(
"app_pipeline");
29 _source = gst_element_factory_make(
"appsrc",
"app_source");
30 g_object_set(G_OBJECT(
_source),
"do-timestamp", TRUE, NULL);
35 if (dst_type ==
"alsasink")
37 _decoder = gst_element_factory_make(
"decodebin",
"decoder");
42 _audio = gst_bin_new(
"audiobin");
43 _convert = gst_element_factory_make(
"audioconvert",
"convert");
44 audiopad = gst_element_get_static_pad(
_convert,
"sink");
45 _sink = gst_element_factory_make(
"autoaudiosink",
"sink");
46 if (!device.empty()) {
47 g_object_set(G_OBJECT(
_sink),
"device", device.c_str(), NULL);
51 gst_element_add_pad(
_audio, gst_ghost_pad_new(
"sink", audiopad));
52 gst_object_unref(audiopad);
58 _sink = gst_element_factory_make(
"filesink",
"sink");
59 g_object_set( G_OBJECT(
_sink),
"location", dst_type.c_str(), NULL);
64 gst_element_set_state(GST_ELEMENT(
_pipeline), GST_STATE_PLAYING);
72 void onAudio(
const audio_common_msgs::AudioDataConstPtr &msg)
74 GstBuffer *buffer = gst_buffer_new_and_alloc(msg->data.size());
75 gst_buffer_fill(buffer, 0, &msg->data[0], msg->data.size());
78 g_signal_emit_by_name(
_source,
"push-buffer", buffer, &ret);
81 static void cb_newpad (GstElement *decodebin, GstPad *pad,
91 audiopad = gst_element_get_static_pad (client->
_audio,
"sink");
92 if (GST_PAD_IS_LINKED (audiopad))
94 g_object_unref (audiopad);
99 caps = gst_pad_query_caps (pad, NULL);
100 str = gst_caps_get_structure (caps, 0);
101 if (!g_strrstr (gst_structure_get_name (str),
"audio")) {
102 gst_caps_unref (caps);
103 gst_object_unref (audiopad);
107 gst_caps_unref (caps);
110 gst_pad_link (pad, audiopad);
112 g_object_unref (audiopad);
126 int main (
int argc,
char **argv)
129 gst_init(&argc, &argv);
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
static void cb_newpad(GstElement *decodebin, GstPad *pad, gpointer data)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
boost::thread _gst_thread
void onAudio(const audio_common_msgs::AudioDataConstPtr &msg)