Skip to content

Commit a1f7ef4

Browse files
authored
Merge pull request #28 from fengqikai1414/master
add image_common, audio_common and vision_opencv, refer to ros-indigo
2 parents 17897b4 + 437dd3c commit a1f7ef4

File tree

222 files changed

+20554
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

222 files changed

+20554
-0
lines changed

ros/audio_common/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pyc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2+
Changelog for package audio_capture
3+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
5+
0.2.12 (2016-02-29)
6+
-------------------
7+
8+
0.2.11 (2016-02-16)
9+
-------------------
10+
11+
0.2.10 (2016-01-21)
12+
-------------------
13+
14+
0.2.9 (2015-12-02)
15+
------------------
16+
* [audio_capture] add error handler
17+
* [audio_capture] add option to publish captured audio data as wav format
18+
* Fixed memory leak (see `#18 <https://github.com/ros-drivers/audio_common/issues/18>`_).
19+
* Removed trailing whitespace.
20+
* Contributors: Felix Duvallet, Furushchev
21+
22+
0.2.8 (2015-10-02)
23+
------------------
24+
* Update maintainer email
25+
* Contributors: trainman419
26+
27+
0.2.7 (2014-07-25)
28+
------------------
29+
* audio_capture.cpp has to wait for generated AudioData headers
30+
* Contributors: v4hn
31+
32+
0.2.6 (2014-02-26)
33+
------------------
34+
* audio_capture and play _require\_ gstreamer, it's not optional
35+
* Contributors: v4hn
36+
37+
0.2.5 (2014-01-23)
38+
------------------
39+
* "0.2.5"
40+
* Contributors: trainman419
41+
42+
0.2.4 (2013-09-10)
43+
------------------
44+
* Update CMakeLists.txt
45+
* audio_capture: install launchfiles
46+
* Contributors: David Gossow
47+
48+
0.2.3 (2013-07-15)
49+
------------------
50+
* Fix install rule for audio_capture.
51+
* Contributors: Austin Hendrix
52+
53+
0.2.2 (2013-04-10)
54+
------------------
55+
56+
0.2.1 (2013-04-08 13:59)
57+
------------------------
58+
59+
0.2.0 (2013-04-08 13:49)
60+
------------------------
61+
* Finish catkinizing audio_common.
62+
* Catkinize audio_play.
63+
* Catkinize audio_capture.
64+
* Fix typo in package.xml
65+
* Versions and more URLs.
66+
* Convert manifests to package.xml
67+
* Convert audio_capture manifest to package.xml
68+
* Ditch old makefiles.
69+
* Updates manifest
70+
* Updated manifests for rodep2
71+
* oneiric build fixes, bump version to 0.1.6
72+
* Removed redundant thread::thread
73+
* Added a rosdep.yaml file
74+
* Fixed to use audio_common_msgs
75+
* Added ability to use different festival voices
76+
* Updated documentation
77+
* Added ability to capture to file
78+
* Fixed ignore files
79+
* Added hgignore files
80+
* Audio_capture and audio_play working
81+
* Making separate audio_capture and audio_play packages
82+
* Moved audio_transport to audio_capture
83+
* Contributors: Austin Hendrix, Brian Gerkey, Nate Koenig, nkoenig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cmake_minimum_required(VERSION 2.8.3)
2+
3+
project(audio_capture)
4+
5+
find_package(catkin REQUIRED COMPONENTS roscpp audio_common_msgs)
6+
7+
find_package(PkgConfig)
8+
pkg_check_modules(GST gstreamer-0.10 REQUIRED)
9+
10+
find_package(Boost REQUIRED COMPONENTS thread)
11+
12+
include_directories(${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${GST_INCLUDE_DIRS})
13+
14+
catkin_package()
15+
16+
add_executable(audio_capture src/audio_capture.cpp)
17+
target_link_libraries(audio_capture ${catkin_LIBRARIES} ${GST_LIBRARIES} ${Boost_LIBRARIES})
18+
add_dependencies(audio_capture ${catkin_EXPORTED_TARGETS})
19+
20+
install(TARGETS audio_capture
21+
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
22+
23+
install(DIRECTORY launch
24+
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<launch>
2+
3+
<node name="audio_capture" pkg="audio_capture" type="audio_capture" output="screen">
4+
<param name="bitrate" value="128"/>
5+
</node>
6+
7+
</launch>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<launch>
2+
3+
<node name="audio_capture" pkg="audio_capture" type="audio_capture" output="screen">
4+
<param name="bitrate" value="128"/>
5+
<param name="dst" value="output.mp3"/>
6+
</node>
7+
8+
</launch>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<launch>
2+
<!-- publish audio data as wav format -->
3+
<node name="audio_capture" pkg="audio_capture" type="audio_capture" output="screen">
4+
<param name="format" value="wave" />
5+
<param name="channels" value="1" />
6+
<param name="depth" value="16" />
7+
<param name="sample_rate" value="16000" />
8+
</node>
9+
</launch>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
\mainpage
3+
\htmlinclude manifest.html
4+
5+
\b audio_capture is a package that records audio from a microphone and makes it available to other ROS nodes.
6+
7+
\section codeapi Code API
8+
9+
<!--
10+
Provide links to specific auto-generated API documentation within your
11+
package that is of particular interest to a reader. Doxygen will
12+
document pretty much every part of your code, so do your best here to
13+
point the reader to the actual API.
14+
15+
If your codebase is fairly large or has different sets of APIs, you
16+
should use the doxygen 'group' tag to keep these APIs together. For
17+
example, the roscpp documentation has 'libros' group.
18+
-->
19+
20+
21+
*/
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<package>
2+
<name>audio_capture</name>
3+
<version>0.2.12</version>
4+
<description>
5+
Transports audio from a source to a destination. Audio sources can come
6+
from a microphone or file. The destination can play the audio or save it
7+
to an mp3 file.
8+
</description>
9+
<maintainer email="namniart@gmail.com">Austin Hendrix</maintainer>
10+
<author>Nate Koenig</author>
11+
<license>BSD</license>
12+
<url type="website">http://ros.org/wiki/audio_capture</url>
13+
<url type="repository">https://github.com/ros-drivers/audio_common</url>
14+
<url type="bugtracker">https://github.com/ros-drivers/audio_common/issues</url>
15+
16+
<buildtool_depend>catkin</buildtool_depend>
17+
18+
<build_depend>roscpp</build_depend>
19+
<build_depend>audio_common_msgs</build_depend>
20+
<build_depend>libgstreamer0.10-dev</build_depend>
21+
<build_depend>libgstreamer-plugins-base0.10-dev</build_depend>
22+
23+
<run_depend>roscpp</run_depend>
24+
<run_depend>audio_common_msgs</run_depend>
25+
<run_depend>libgstreamer0.10-0</run_depend>
26+
<run_depend>libgstreamer-plugins-base0.10-0</run_depend>
27+
<run_depend>gstreamer0.10-plugins-ugly</run_depend>
28+
<run_depend>gstreamer0.10-plugins-good</run_depend>
29+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#include <stdio.h>
2+
#include <gst/gst.h>
3+
#include <gst/app/gstappsink.h>
4+
#include <boost/thread.hpp>
5+
6+
#include <ros/ros.h>
7+
8+
#include "audio_common_msgs/AudioData.h"
9+
10+
namespace audio_transport
11+
{
12+
class RosGstCapture
13+
{
14+
public:
15+
RosGstCapture()
16+
{
17+
_bitrate = 192;
18+
19+
std::string dst_type;
20+
21+
// Need to encoding or publish raw wave data
22+
ros::param::param<std::string>("~format", _format, "mp3");
23+
24+
// The bitrate at which to encode the audio
25+
ros::param::param<int>("~bitrate", _bitrate, 192);
26+
27+
// only available for raw data
28+
ros::param::param<int>("~channels", _channels, 1);
29+
ros::param::param<int>("~depth", _depth, 16);
30+
ros::param::param<int>("~sample_rate", _sample_rate, 16000);
31+
32+
// The destination of the audio
33+
ros::param::param<std::string>("~dst", dst_type, "appsink");
34+
35+
// The source of the audio
36+
//ros::param::param<std::string>("~src", source_type, "alsasrc");
37+
38+
_pub = _nh.advertise<audio_common_msgs::AudioData>("audio", 10, true);
39+
40+
_loop = g_main_loop_new(NULL, false);
41+
_pipeline = gst_pipeline_new("ros_pipeline");
42+
_bus = gst_pipeline_get_bus(GST_PIPELINE(_pipeline));
43+
gst_bus_add_signal_watch(_bus);
44+
g_signal_connect(_bus, "message::error",
45+
G_CALLBACK(onMessage), this);
46+
g_object_unref(_bus);
47+
48+
// We create the sink first, just for convenience
49+
if (dst_type == "appsink")
50+
{
51+
_sink = gst_element_factory_make("appsink", "sink");
52+
g_object_set(G_OBJECT(_sink), "emit-signals", true, NULL);
53+
g_object_set(G_OBJECT(_sink), "max-buffers", 100, NULL);
54+
g_signal_connect( G_OBJECT(_sink), "new-buffer",
55+
G_CALLBACK(onNewBuffer), this);
56+
}
57+
else
58+
{
59+
printf("file sink\n");
60+
_sink = gst_element_factory_make("filesink", "sink");
61+
g_object_set( G_OBJECT(_sink), "location", dst_type.c_str(), NULL);
62+
}
63+
64+
_source = gst_element_factory_make("alsasrc", "source");
65+
_convert = gst_element_factory_make("audioconvert", "convert");
66+
67+
gboolean link_ok;
68+
69+
if (_format == "mp3"){
70+
_encode = gst_element_factory_make("lame", "encoder");
71+
g_object_set( G_OBJECT(_encode), "preset", 1001, NULL);
72+
g_object_set( G_OBJECT(_encode), "bitrate", _bitrate, NULL);
73+
74+
gst_bin_add_many( GST_BIN(_pipeline), _source, _convert, _encode, _sink, NULL);
75+
link_ok = gst_element_link_many(_source, _convert, _encode, _sink, NULL);
76+
} else if (_format == "wave") {
77+
GstCaps *caps;
78+
caps = gst_caps_new_simple("audio/x-raw-int",
79+
"channels", G_TYPE_INT, _channels,
80+
"width", G_TYPE_INT, _depth,
81+
"depth", G_TYPE_INT, _depth,
82+
"rate", G_TYPE_INT, _sample_rate,
83+
"signed", G_TYPE_BOOLEAN, TRUE,
84+
NULL);
85+
86+
g_object_set( G_OBJECT(_sink), "caps", caps, NULL);
87+
gst_caps_unref(caps);
88+
gst_bin_add_many( GST_BIN(_pipeline), _source, _sink, NULL);
89+
link_ok = gst_element_link_many( _source, _sink, NULL);
90+
} else {
91+
ROS_ERROR_STREAM("format must be \"wave\" or \"mp3\"");
92+
exitOnMainThread(1);
93+
}
94+
/*}
95+
else
96+
{
97+
_sleep_time = 10000;
98+
_source = gst_element_factory_make("filesrc", "source");
99+
g_object_set(G_OBJECT(_source), "location", source_type.c_str(), NULL);
100+
101+
gst_bin_add_many( GST_BIN(_pipeline), _source, _sink, NULL);
102+
gst_element_link_many(_source, _sink, NULL);
103+
}
104+
*/
105+
106+
if (!link_ok) {
107+
ROS_ERROR_STREAM("Unsupported media type.");
108+
exitOnMainThread(1);
109+
}
110+
111+
gst_element_set_state(GST_ELEMENT(_pipeline), GST_STATE_PLAYING);
112+
113+
_gst_thread = boost::thread( boost::bind(g_main_loop_run, _loop) );
114+
}
115+
116+
~RosGstCapture()
117+
{
118+
g_main_loop_quit(_loop);
119+
gst_element_set_state(_pipeline, GST_STATE_NULL);
120+
gst_object_unref(_pipeline);
121+
g_main_loop_unref(_loop);
122+
}
123+
124+
void exitOnMainThread(int code)
125+
{
126+
exit(code);
127+
}
128+
129+
void publish( const audio_common_msgs::AudioData &msg )
130+
{
131+
_pub.publish(msg);
132+
}
133+
134+
static GstFlowReturn onNewBuffer (GstAppSink *appsink, gpointer userData)
135+
{
136+
RosGstCapture *server = reinterpret_cast<RosGstCapture*>(userData);
137+
138+
GstBuffer *buffer;
139+
g_signal_emit_by_name(appsink, "pull-buffer", &buffer);
140+
141+
audio_common_msgs::AudioData msg;
142+
msg.data.resize( buffer->size );
143+
memcpy( &msg.data[0], buffer->data, buffer->size);
144+
145+
server->publish(msg);
146+
147+
return GST_FLOW_OK;
148+
}
149+
150+
static gboolean onMessage (GstBus *bus, GstMessage *message, gpointer userData)
151+
{
152+
RosGstCapture *server = reinterpret_cast<RosGstCapture*>(userData);
153+
GError *err;
154+
gchar *debug;
155+
156+
gst_message_parse_error(message, &err, &debug);
157+
ROS_ERROR_STREAM("gstreamer: " << err->message);
158+
g_error_free(err);
159+
g_free(debug);
160+
g_main_loop_quit(server->_loop);
161+
server->exitOnMainThread(1);
162+
return FALSE;
163+
}
164+
165+
private:
166+
ros::NodeHandle _nh;
167+
ros::Publisher _pub;
168+
169+
boost::thread _gst_thread;
170+
171+
GstElement *_pipeline, *_source, *_sink, *_convert, *_encode;
172+
GstBus *_bus;
173+
int _bitrate, _channels, _depth, _sample_rate;
174+
GMainLoop *_loop;
175+
std::string _format;
176+
};
177+
}
178+
179+
int main (int argc, char **argv)
180+
{
181+
ros::init(argc, argv, "audio_capture");
182+
gst_init(&argc, &argv);
183+
184+
audio_transport::RosGstCapture server;
185+
ros::spin();
186+
}

0 commit comments

Comments
 (0)