Exemplo n.º 1
0
		bool Source::stream_buffers (IStreamable * stream) {
			ALint processed = processed_buffer_count();
			bool complete = true;

			// std::cerr << "Processed buffers = " << processed << std::endl;

			AudioError::reset();

			while (processed--) {
				ALuint buffer;
				unqueue_buffers(&buffer, 1);

				bool result = stream->load_next_buffer(this, buffer);

				if (result) {
					queue_buffers(&buffer, 1);
				} else {
					complete = false;
				}
			}

			AudioError::check("Streaming Buffers");

			return complete;
		}
Exemplo n.º 2
0
static int init_device (int w, int h) {
	struct v4l2_capability cap;
	struct v4l2_cropcap cropcap;
	struct v4l2_crop crop;
	struct v4l2_format fmt;
	unsigned int min;

	if (-1 == xioctl (fd, VIDIOC_QUERYCAP, &cap)) {
		if (EINVAL == errno) {
			return -1;
		} else {
			return -1;
		}
	}

	if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
		return -1;
	}

	if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
		return -1;
	}


	/* Select video input, video standard and tune here. */

	CLEAR (cropcap);

	cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

	if (0 == xioctl (fd, VIDIOC_CROPCAP, &cropcap)) {
		crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		crop.c = cropcap.defrect; /* reset to default */

		if (-1 == xioctl (fd, VIDIOC_S_CROP, &crop)) {
			if (EINVAL == errno) {
				/* Cropping not supported (ignored) */
			} else {
				/* Errors ignored. */
			}
		}
	} else {
		/* Errors ignored. */
	}

/*
	fmt.fmt.pix.field	= V4L2_FIELD_INTERLACED;
	fmt.fmt.pix.field	= V4L2_FIELD_TOP;
*/

	CLEAR (fmt);

	fmt.type		= V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt.fmt.pix.width	= w;
	fmt.fmt.pix.height	= h;
	fmt.fmt.pix.pixelformat	= V4L2_PIX_FMT_YUYV; //V4L2_PIX_FMT_RGB32;
	fmt.fmt.pix.field	= V4L2_FIELD_NONE; //V4L2_FIELD_INTERLACED;

	if (-1 == xioctl (fd, VIDIOC_S_FMT, &fmt)) {
		return -1;
	}

	/* Note VIDIOC_S_FMT may change width and height. */

	//if ((w != fmt.fmt.pix.width) | (h != fmt.fmt.pix.height) | (V4L2_PIX_FMT_RGB32 != fmt.fmt.pix.pixelformat)) {
	if ((w != fmt.fmt.pix.width) | (h != fmt.fmt.pix.height) | (V4L2_PIX_FMT_YUYV != fmt.fmt.pix.pixelformat)) {
		return -1;
	}

	/* Buggy driver paranoia. */
	min = fmt.fmt.pix.width * 4;
	if (fmt.fmt.pix.bytesperline < min)
		fmt.fmt.pix.bytesperline = min;
	min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
	if (fmt.fmt.pix.sizeimage < min)
		fmt.fmt.pix.sizeimage = min;

	if (0 > init_mmap())
		return -1;

	if (0 > queue_buffers())
		return -1;

	/* cache returned dims (make fmt a global?) */
	bmWidth = fmt.fmt.pix.width;
	bmHeight = fmt.fmt.pix.height;

	/* How many bytes to transfer? */
	/* NB: Scratch dictates equal or *larger* sized frame than requested */
	/* >>> For initial test assuming got frame size requested and "min" above is correct */
	sqBufferBytes = min;
	sqPixels = bmWidth * bmHeight;

	return 0;
}