42 #include <bta_ros/sensor2D.hpp> 48 std::string nodeName) :
50 nh_private_(nh_private),
54 address_(
"192.168.0.10")
73 GstElement* elem = ( GstElement* ) data;
75 GstPadLinkReturn lres;
77 sinkpad = gst_element_get_static_pad ( elem ,
"sink" );
79 lres == gst_pad_link ( pad, sinkpad );
80 g_assert (GST_PAD_LINK_SUCCESSFUL(lres));
81 gst_object_unref( sinkpad );
85 GstElement *souphttpsrc,
86 *sdpdemux, *videodepay,
87 *videodecoder, *videoconvert,
92 GstPadLinkReturn lres;
93 GstPad *srcpad, *sinkpad;
99 "No ip for download sdp file given. Trying with default: " <<
address_);
102 gst_init (NULL,NULL);
105 pipeline_ = gst_pipeline_new (
"pipeline");
108 souphttpsrc = gst_element_factory_make (
"souphttpsrc",
"sdphttpsrc");
109 g_assert (souphttpsrc);
110 g_object_set (souphttpsrc,
"location",
address_.c_str(), NULL);
112 sdpdemux = gst_element_factory_make (
"sdpdemux", NULL);
119 videodepay = gst_element_factory_make (
"rtph264depay", NULL);
120 g_assert (videodepay);
123 videodecoder = gst_element_factory_make (
"avdec_h264", NULL);
124 g_assert (videodecoder);
125 g_object_set (videodecoder,
"skip-frame", 5, NULL);
153 videoconvert =gst_element_factory_make(
"videoconvert", NULL);
154 g_assert (videoconvert);
156 filter = gst_element_factory_make (
"capsfilter",
"filter");
159 filtercaps = gst_caps_new_simple (
"video/x-raw",
160 "format", G_TYPE_STRING,
"BGR",
162 g_object_set (G_OBJECT (filter),
"caps", filtercaps, NULL);
163 gst_caps_unref (filtercaps);
165 appsink = gst_element_factory_make(
"appsink", NULL);
168 g_object_set (
appsink,
"drop", TRUE, NULL);
169 g_object_set (
appsink,
"max-buffers", 1, NULL);
182 res = gst_element_link (souphttpsrc, sdpdemux);
183 g_assert (res == TRUE);
186 g_signal_connect (sdpdemux,
"pad-added", G_CALLBACK (
cb_new_pad), videodepay);
188 res = gst_element_link_many (videodepay, videodecoder, videoconvert, filter,
appsink, NULL);
189 g_assert (res == TRUE);
205 ROS_INFO (
"starting receiver pipeline");
207 gst_element_set_state(
pipeline_, GST_STATE_PAUSED);
208 if (gst_element_get_state(
pipeline_, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) {
209 ROS_FATAL(
"Failed to PAUSE stream, check your configuration.");
215 gst_element_set_state (
pipeline_, GST_STATE_PLAYING);
216 if (gst_element_get_state(
pipeline_, NULL, NULL, -1) == GST_STATE_CHANGE_FAILURE) {
226 "package://bta_ros/calib.yml")) {
229 "package://bta_ros/calib.yml" );
232 "package://bta_ros/calib.yml" <<
233 " not found. Using an uncalibrated config.");
243 gst_element_get_state(
pipeline_, &state, NULL, -1);
244 if (state == GST_STATE_PLAYING)
247 ROS_INFO(
"Stream STOPPED. Reconnecting");
248 gst_element_set_state (
pipeline_, GST_STATE_NULL);
249 if (gst_element_set_state (
pipeline_, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
262 g_print (
"Returned, stopping playback\n");
263 gst_element_set_state (
pipeline_, GST_STATE_NULL);
265 g_print (
"Deleting pipeline_\n");
266 gst_object_unref (GST_OBJECT (
pipeline_));
274 sample = gst_app_sink_pull_sample((GstAppSink *)
appsink);
278 sensor_msgs::ImagePtr rgb (
new sensor_msgs::Image);
279 GstBuffer* sampleBuffer = NULL;
282 GstMapInfo bufferInfo;
286 caps = gst_sample_get_caps (sample);
287 s = gst_caps_get_structure (caps, 0);
288 res = gst_structure_get_int (s,
"width", &width);
289 res |= gst_structure_get_int (s,
"height", &height);
291 ROS_DEBUG (
"could not get snapshot dimension\n");
295 sampleBuffer = gst_sample_get_buffer(sample);
296 if(sampleBuffer != NULL)
298 gst_buffer_map(sampleBuffer, &bufferInfo, GST_MAP_READ);
301 rgb->height = height;
304 rgb->step = width*(
sizeof(
unsigned char)*3);
305 rgb->data.resize(bufferInfo.size);
306 memcpy ( &rgb->data[0], bufferInfo.data, bufferInfo.size );
308 sensor_msgs::CameraInfoPtr ci_rgb(
310 ci_rgb->header.frame_id =
nodeName_+
"/sensor2d";
311 rgb->header.frame_id =
nodeName_+
"/sensor2d";
315 gst_buffer_unmap (sampleBuffer, &bufferInfo);
316 gst_sample_unref(sample);
void publish(const sensor_msgs::Image &image, const sensor_msgs::CameraInfo &info) const
camera_info_manager::CameraInfoManager cim_rgb_
sensor_msgs::CameraInfo getCameraInfo(void)
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
bool loadCameraInfo(const std::string &url)
image_transport::ImageTransport it_
bool validateURL(const std::string &url)
static void cb_new_pad(GstElement *element, GstPad *pad, gpointer data)
CameraPublisher advertiseCamera(const std::string &base_topic, uint32_t queue_size, bool latch=false)
image_transport::CameraPublisher pub_rgb_
ROSCPP_DECL bool isShuttingDown()
#define ROS_WARN_STREAM(args)
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
ros::NodeHandle nh_private_
ROSCPP_DECL void shutdown()
ROSCONSOLE_DECL bool set_logger_level(const std::string &name, levels::Level level)
ROSCPP_DECL void spinOnce()
#define ROSCONSOLE_DEFAULT_NAME
bool setCameraName(const std::string &cname)