Exemple #1
0
void network_stream_buffer::add_buffer(buffer_ptr b){
	if (client_error_code)
		return ;

	try{
		boost::system::error_code ec;
		boost::asio::write(tcptr->get_socket(),
			boost::asio::buffer(b->data(),b->size()),ec);
		if (ec){
			client_error_code = ec;
			//_stop_handler()
		}
	}
	catch(...){
		throw std::runtime_error("delivery error");
	}

	return;

	boost::unique_lock<boost::recursive_mutex> l1(buffers_mutex);




	/*
	boost::asio::async_write(tcptr->get_socket(),
		boost::asio::buffer(b->data(),b->size()),
		boost::bind(&network_stream_buffer::write_data_handler, 
		this,
		b,
		boost::asio::placeholders::error,
		boost::asio::placeholders::bytes_transferred));
	*/
	return ;



	while (total_size + b->size() >= _max_buffer_size){
		std::cout<<"add_buffer: need cleanup"<<std::endl;
		buffer_ptr b1 = buffers.front();
		if (b1){
			buffers.pop();
			total_size -= b1->size();
		} else
			break;
	}

	if (total_size + b->size() >= _max_buffer_size)
		throw std::runtime_error("NetworkStreamer: buffer overflow");

	buffers.push(b);
	total_size += b->size();
	// std::cout<<"B: total_size="<<total_size<<",count="<<buffers.size()<<std::endl;
	send_first_buffer();
}
Exemple #2
0
void network_stream_buffer::write_data_handler(buffer_ptr bptr, boost::system::error_code ec,unsigned int bytes_transferred){
	boost::unique_lock<boost::recursive_mutex> l1(buffers_mutex);
	sent_packets_count--;
	if (!ec){
		//std::cout<<"bytes_transferred:"<<bytes_transferred<<std::endl;
		if (bptr->size() != bytes_transferred)
			std::cout<<"------------TRANSFERED only "<<bytes_transferred<<" bytes from "<<bptr->size()<<std::endl;

		//send next data buffer

		if (current_buffer){
			total_size -= current_buffer->size();
			current_buffer = buffer_ptr();
		}


		boost::posix_time::ptime now_pt = boost::posix_time::microsec_clock::universal_time();
		boost::posix_time::time_duration td = now_pt - last_debug_output_pt;
		//std::cout<<td.total_seconds()<<std::endl;
		if ((td.total_seconds() > 5)||(last_debug_output_pt==boost::posix_time::min_date_time)){
			std::ostringstream oss;
			oss<<"NSB debug info: queue_size:"<<buffers.size()<<",cp_count:"<<sent_packets_count;
			if (deliveries_count>0){
				unsigned int avg_d_time = total_delivery_time_ms / deliveries_count;
				oss<<",avg delivery time:"<<avg_d_time<<" ms ("<<deliveries_count<<" packets)";
				total_delivery_time_ms = 0;
				deliveries_count = 0;
			}


			std::cout<<oss.str()<<std::endl;
			last_debug_output_pt = now_pt;
		}

		//delivery time
		td = now_pt - bptr->pt;
		total_delivery_time_ms += td.total_milliseconds();
		deliveries_count++;


		send_first_buffer();

	} else{
		//deleting client
		std::string e_mess = ec.message();
		//std::cout<<"delivery error (bt:"<<bytes_transferred<<")("<<e_mess<<")"<<std::endl;
		client_error_code = ec;


		//client disconnected
		_stop_handler(this,client_error_code);
	}

}
Exemple #3
0
    void print_depth(const astra::DepthFrame& depthFrame,
                     const astra::CoordinateMapper& mapper)
    {
        if (depthFrame.is_valid())
        {
            int width = depthFrame.width();
            int height = depthFrame.height();
            int frameIndex = depthFrame.frame_index();

            //determine if buffer needs to be reallocated
            if (width != lastWidth_ || height != lastHeight_)
            {
                buffer_ = buffer_ptr(new int16_t[depthFrame.length()]);
                lastWidth_ = width;
                lastHeight_ = height;
            }
            depthFrame.copy_to(buffer_.get());

            size_t index = ((width * (height / 2.0f)) + (width / 2.0f));
            short middle = buffer_[index];

            float worldX, worldY, worldZ;
            float depthX, depthY, depthZ;
            mapper.convert_depth_to_world(width / 2.0f, height / 2.0f, middle, &worldX, &worldY, &worldZ);
            mapper.convert_world_to_depth(worldX, worldY, worldZ, &depthX, &depthY, &depthZ);

            std::cout << "depth frameIndex: " << frameIndex
                      << " value: " << middle
                      << " wX: " << worldX
                      << " wY: " << worldY
                      << " wZ: " << worldZ
                      << " dX: " << depthX
                      << " dY: " << depthY
                      << " dZ: " << depthZ
                      << std::endl;
        }
    }
void indexed_buffer_target_t::bind_buffer( buffer_ptr buffer )
{
    set_current_buffer(buffer);
    glBindBufferBase(gl_target_type(type()), idx_, buffer->gl_id());
}
void buffer_target_t::bind_buffer( buffer_ptr buffer )
{
    set_current_buffer(buffer);
    glBindBuffer(gl_target_type(type_), buffer->gl_id());
}
void indexed_buffer_target_t::bind_buffer_range( buffer_ptr buffer, size_t offset, size_t length )
{
    set_current_buffer(buffer);
    glBindBufferRange(gl_target_type(type()), idx_, buffer->gl_id(), offset, length);
}
		write_operation(buffer_ptr const& buf, handler const& hdl)
		: m_header(static_cast<boost::uint32_t>(buf->size()))
		, m_buffer(buf)
		, m_handler(hdl)
		{}