Пример #1
0
void EXROStream::write(const char c[], int n)
{
	if(position + n > data->get_compressed_allocated())
		data->allocate_compressed_data(MAX(position + n, data->get_compressed_allocated() * 2));

	memcpy(data->get_data() + position, c, n);
	position += n;
	data->set_compressed_size(MAX(position, data->get_compressed_size()));
}
Пример #2
0
static void read_function(png_structp png_ptr, 
	png_bytep data, 
	png_uint_32 length)
{
	VFrame *input = (VFrame*)png_get_io_ptr(png_ptr);

	memcpy(data, input->get_data() + input->get_compressed_size(), length);
	input->set_compressed_size(input->get_compressed_size() + length);
}
Пример #3
0
static void write_function(png_structp png_ptr, png_bytep data, png_uint_32 length)
{
	VFrame *output = (VFrame*)png_get_io_ptr(png_ptr);

	if(output->get_compressed_allocated() < output->get_compressed_size() + length)
		output->allocate_compressed_data((output->get_compressed_allocated() + length) * 2);
	memcpy(output->get_data() + output->get_compressed_size(), data, length);
	output->set_compressed_size(output->get_compressed_size() + length);
}
Пример #4
0
void DeviceV4L2Base::run()
{
	Thread::disable_cancel();
	int min_buffers = total_buffers / 2;
	if( min_buffers > 3 ) min_buffers = 3;

// Read buffers continuously
	while( !done )
	{
		int retry = 0;
		int qbfrs = q_bfrs;
		while( !done && (!qbfrs || (!retry && qbfrs < min_buffers)) )
		{
			Thread::enable_cancel();
			Timer::delay(10);
			Thread::disable_cancel();
			++retry;  qbfrs = q_bfrs;
		}
		if( done ) break;
		struct v4l2_buffer buffer;
		memset(&buffer, 0, sizeof(buffer));
		buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		buffer.memory = V4L2_MEMORY_MMAP;

// The driver returns the first buffer not queued, so only one buffer
// can be unqueued at a time.
		Thread::enable_cancel();
		qbfrs_lock->lock("DeviceV4L2Base::run");
		int result = vioctl(VIDIOC_DQBUF, &buffer);
		if( !result ) --q_bfrs;
		qbfrs_lock->unlock();
		Thread::disable_cancel();
		if(result < 0)
		{
			perror("DeviceV4L2Base::run VIDIOC_DQBUF");
			Thread::enable_cancel();
			Timer::delay(10);
			Thread::disable_cancel();
			continue;
		}

// Get output frame
		int bfr = buffer.index;
// Set output frame data size/time, queue video
		VFrame *frame = device_buffers[bfr];
		if(color_model == BC_COMPRESSED)
			frame->set_compressed_size(buffer.bytesused);
		struct timeval *tv = &buffer.timestamp;
		double bfr_time = tv->tv_sec + tv->tv_usec / 1000000.;
		frame->set_timestamp(bfr_time);
		if( !getq->q(bfr) ) video_lock->unlock();
	}
}