Example #1
0
bool BaseV4L2VideoCapture::UnInitMmap() {

  if(_deviceFD < 0 ) return false;

  if(_isInit == false) return true;

  if(_pV4L2Buffers == NULL) return true;

  for (uint32_t bi = 0; bi < _reqBufferCount; ++bi) { // bi: buffer index
    if(munmap(_pV4L2Buffers[bi].start, _pV4L2Buffers[bi].length) < 0){
      FATAL("unmap failed");
      delete (_pV4L2Buffers+bi);
      return false;
    }
    //FINEST("unmap buffer %d", bi);
  }
  _pV4L2Buffers = NULL;
  _reqBufferCount = 0;

  if (!v4l2_reqbufs(_reqBufferCount)) {
    FATAL("clean buffer failed");
    return false;
  }

  //FATAL("Number of buffer after releasing : %d", _reqBufferCount);
  _isInit = false;
  //INFO("UnInit mmap done");

  return true;
}
Example #2
0
bool BaseV4L2VideoCapture::InitMmap() {

  if(_deviceFD < 0 ) return false;

  if(_isInit ) return true;

  _reqBufferCount = _numOfV4L2Buffers;
  //FATAL("_numOfV4L2Buffers : %d ", _numOfV4L2Buffers);
  // 1. try to request default buffer number
  if(!v4l2_reqbufs(_reqBufferCount)) {
    return false;
  }

  if (_reqBufferCount < 2) {
    //FATAL("Insufficient buffer memory on fd %d buf # %d", _deviceFD, _reqBufferCount);
    return false;
  }

  // 2.  allocate buffer pointers for mmap
  if(_pV4L2Buffers == NULL){
    _pV4L2Buffers = new V4L2Buffer[_reqBufferCount];
  }else{
    FATAL("Memory is already mapped, cannot map again");
    return false;
  }

  if (_pV4L2Buffers == NULL){
    FATAL("Allocate memory failed");
    return false;
  }

  // 3. query buf and perform memory maping
  for (uint32_t bi = 0; bi < _reqBufferCount; ++bi) { // bi: buffer index
    if(v4l2_querybuf(_pV4L2Buffers[bi], bi) < 0){
      FATAL("Query buffer failed");
      return -1;
    }
  }

  _isInit  = true;
  //FATAL("Init mmap done. Buf #:%d", _reqBufferCount);
  return true;
}
Example #3
0
void *
capture_loop(void *arg)
{
	struct thr_data *data = (struct thr_data *)arg;
	struct display *disp = data->disp;
	struct v4l2 *v4l2 = data->v4l2;
	uint32_t fourcc = data->fourcc;
	uint32_t width = data->width, height = data->height;

	struct buffer **buffers, *capt, *alg, **alg_bufs;
	int ret, i;
	int *src, *dst;
	int w, h;

	buffers = disp_get_vid_buffers(disp, NBUF, fourcc, width, height);
	if (!buffers) {
		return NULL;
	}

	alg_bufs = disp_get_vid_buffers(disp, 1, fourcc, width, height);
	alg = alg_bufs[0];

	ret = v4l2_reqbufs(v4l2, buffers, NBUF);
	if (ret) {
		return NULL;
	}

	for (i = 0; i < NBUF; i++) {
		v4l2_qbuf(v4l2, buffers[i]);
	}

	ret = v4l2_streamon(v4l2);
	if (ret) {
		return NULL;
	}

	for (i = 1; i < CNT; i++) {

		capt = v4l2_dqbuf(v4l2);

src = omap_bo_map(capt->bo[0]);
dst = omap_bo_map(alg->bo[0]);

//printf("debug: %p %p\n", src, dst);
omap_bo_cpu_prep(capt->bo[0], OMAP_GEM_READ);
omap_bo_cpu_prep(alg->bo[0], OMAP_GEM_WRITE);
//printf("bufers prepared\n");

/*
for (h=0; h<720; h++)
	for(w=0;w<1280 / 2;w++)
		dst[h * 1280 / 2 + w] = src[h * 1280 / 2 + 1280 / 2 - w];


*/

printf("Calling get Image");
//getImage(dst);




//printf("Mirrrored\n");
omap_bo_cpu_fini(capt->bo[0], OMAP_GEM_READ);
omap_bo_cpu_fini(alg->bo[0], OMAP_GEM_WRITE);

ret = disp_post_vid_buffer(disp, alg,
		0, 0, width, height);

//printf("Alg buffer posted\n");
		ret = disp_post_vid_buffer(disp, capt,
			0, 0, width, height);
		if (ret) {
			ERROR("Post buffer failed");
			return NULL;
		}
		v4l2_qbuf(v4l2, capt);
	}
	v4l2_streamoff(v4l2);

	MSG("Ok!");
	return disp;
}