30 stream_(stream), payload_size_bytes_(payload_size_bytes), n_buffers_(0),
31 self_(this, [](CameraBufferPool *p) {})
33 allocateBuffers(n_preallocated_buffers);
42 std::lock_guard<std::mutex> lock(
mutex_);
44 return sensor_msgs::ImagePtr(
new sensor_msgs::Image, boost::bind(&
CameraBufferPool::reclaim, this->weak_from_this(), boost::placeholders::_1));
55 std::lock_guard<std::mutex> lock(
mutex_);
56 sensor_msgs::ImagePtr img_ptr;
60 const uint8_t *buffer_data = (
const uint8_t*)arv_buffer_get_data(buffer, &buffer_size);
66 img_ptr = iter->second;
72 ROS_WARN(
"Could not find available image in pool corresponding to buffer.");
73 img_ptr.reset(
new sensor_msgs::Image);
74 img_ptr->data.resize(buffer_size);
75 memcpy(img_ptr->data.data(), buffer_data, buffer_size);
84 std::lock_guard<std::mutex> lock(
mutex_);
88 for (
size_t i = 0; i < n; ++i)
90 sensor_msgs::Image *p_img =
new sensor_msgs::Image;
93 sensor_msgs::ImagePtr img_ptr(
96 arv_stream_push_buffer(
stream_, buffer);
103 ROS_ERROR(
"Error: Stream not valid. Failed to allocate buffers.");
122 std::lock_guard<std::mutex> lock(
mutex_);
124 std::map<sensor_msgs::Image*, ArvBuffer*>::iterator iter =
used_buffers_.find(p_img);
130 sensor_msgs::ImagePtr img_ptr(
133 arv_stream_push_buffer(
stream_, iter->second);