Ejemplo n.º 1
0
/*---------------------------------------------------------------------*/
H_STREAM ArchiveOpenStream(H_ARCHIVE harchive, STREAM * criteria, UINT32 options)
{
    H_STREAM hstream;

    ASSERT(criteria != NULL);

    if (!ValidateHandle(harchive))
        return (VOID_H_STREAM);

    _archive[harchive].last_error = ARC_NO_ERROR;

    /* Must specify unit and stream */
    if (criteria->unit == VOID_UNIT || criteria->stream == VOID_STREAM) {
        ArchiveLog(ARC_LOG_ERRORS, "%s", "ArchiveOpenStream: criteria must specify unit and stream!");
        _archive[harchive].last_error = ARC_BAD_CRITERIA;
        return (VOID_H_STREAM);
    }

    /* Get next available stream handle */
    if ((hstream = GetNextStreamHandle(harchive)) == VOID_H_STREAM)
        return (VOID_H_STREAM);

    /* Start clean */
    InitRead(hstream);

    /* Copy criteria and options */
    _reads[hstream].harchive = harchive;
    _reads[hstream].criteria.unit = criteria->unit;
    _reads[hstream].criteria.stream = criteria->stream;
    _reads[hstream].criteria.chn_mask = criteria->chn_mask;
    _reads[hstream].criteria.time.earliest = criteria->time.earliest;
    _reads[hstream].criteria.time.latest = criteria->time.latest;
    _reads[hstream].options = options;

    /* Find the first event file */
    if (!ArchiveFindFirstEvent(_reads[hstream].harchive, &_reads[hstream].criteria,
            &_reads[hstream].event))
        return (VOID_H_STREAM);

    /* If strict continuous is on, file must contain the criteria earliest time */
    if (_reads[hstream].options & OPT_NO_DISCONTINUOUS) {
        if (_reads[hstream].event.time.latest > _reads[hstream].criteria.time.earliest) {
            _archive[harchive].last_error = ARC_NOT_FOUND;
            return (VOID_H_STREAM);
        }
    }

    return (hstream);
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------*/
BOOL ArchiveCloseStream(H_STREAM hstream)
{

    if (!ValidateStreamHandle(hstream))
        return (FALSE);

    _archive[_reads[hstream].harchive].last_error = ARC_NO_ERROR;

    /* Close any open file */
    if (_reads[hstream].file != VOID_H_FILE) {
        if (!FileClose(_reads[hstream].file)) {
            _archive[_reads[hstream].harchive].last_error = ARC_FILE_IO_ERROR;
            return (FALSE);
        }
    }

    /* Clear any state */
    InitRead(hstream);

    return (TRUE);
}
Ejemplo n.º 3
0
void VideoInput::InitDevice(void)
{
	struct v4l2_capability cap;
	struct v4l2_cropcap cropcap;
	struct v4l2_crop crop;
	struct v4l2_format fmt;
	unsigned int min;

	if (-1 == Xioctl(VIDIOC_QUERYCAP, &cap))
	{
		if (EINVAL == errno)
		{
			cout << "VideoInput: " << dev_name;
			cout << " is not a V4L2 device\n";
			errored = true;
		} else {
			ErrnoError("VIDIOC_QUERYCAP");
		}
	}

	if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
	{
		cout << "VideoInput: " << dev_name;
		cout << " is not a capture device\n";
		errored = true;
	}

	switch (io)
	{
		case IO_METHOD_READ:
			if (!(cap.capabilities & V4L2_CAP_READWRITE))
			{
				cout << "VideoInput: " << dev_name;
				cout << " does not support read i/o\n";
				errored = true;
			}

			break;

		case IO_METHOD_MMAP:
			if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
				cout << "VideoInput: " << dev_name;
				cout << " does not support streaming i/o\n";
				errored = true;
			}

			break;
	}

	int input = 1;
	if (-1 == Xioctl(VIDIOC_S_INPUT, &input))
		cout << "VideoInput: Input select error\n";

	cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

	if (-1 == Xioctl(VIDIOC_CROPCAP, &cropcap))
		cout << "VideoInput: Cropcap failure\n";

	crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	crop.c = cropcap.defrect; // reset to default

	if (-1 == Xioctl(VIDIOC_S_CROP, &crop))
		cout << "VideoInput: Cropping not supported\n";

	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_GREY;
	fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;

	if (-1 == Xioctl(VIDIOC_S_FMT, &fmt))
		ErrnoError("VIDIOC_S_FMT");

	// Note VIDIOC_S_FMT may change width and height

	// Buggy driver paranoia
	min = fmt.fmt.pix.width * 2;
	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;

	w = fmt.fmt.pix.width;
	h = fmt.fmt.pix.height;
	cout << "VideoInput: New image size: ";
	cout << w << "x" << h << endl;

	videobuffer = new vidbuffertype;
	videobuffer->buffer = new uint8_t [w*h];
	videobuffer->w = w;
	videobuffer->h = h;
	videobuffer->bufferlen = w*h;

	switch (io)
	{
		case IO_METHOD_READ:
			InitRead(fmt.fmt.pix.sizeimage);
			break;

		case IO_METHOD_MMAP:
			InitMmap();
			break;
	}
}
Ejemplo n.º 4
0
void EchoSession::OnConnect()
{
    LOG << "current thread:" << boost::this_thread::get_id() << std::endl;
    InitRead();
}
Ejemplo n.º 5
0
int GentConnect::TryRunning(string &outstr2) {
    char *new_rbuf;
    int rbytes = 0;
    int readNum;
    int stop=0;
	while(true) {
	  if(stop==1) break;
        switch(curstatus) {
            case Status::CONN_READ:
                outstr = "";
                readNum = InitRead(rbytes);
                LOG(GentLog::INFO, "init read the number of byte is %d.", readNum);
                if(readNum < 0) {
                    LOG(GentLog::WARN, "init read the number of byte less than zero");
                    outstr2 = "read error\r\n";
                    Reset();
                    return readNum;
                }else if(readNum == 0) {                                
                    return readNum;
                }
                remainsize = comm->Process(rbuf, rbytes, outstr);
                LOG(GentLog::INFO, "curstatus: %d",curstatus);
                 if(!remainsize && outstr != "") {
                     curstatus = Status::CONN_WRITE;
                     gevent->UpdateEvent(fd, this, eventWrite);
                }
                break;
            case Status::CONN_NREAD:
                //OutString("ok\r\n"); 
                //LOG(GentLog::INFO, "start conn_nread remainsize:%d",remainsize);
				if(!content) {
                    new_rbuf = (char *)malloc(remainsize);
                    memset(new_rbuf,0,remainsize);
                    rcont = content = new_rbuf;
                }
                if(NextRead() == -1) {
                    stop = 1;
                    break;		
                }
                break;
            case Status::CONN_DATA:
                outstr = "";
                comm->Complete(outstr,content, actualsize);
                curstatus = Status::CONN_WRITE;
                gevent->UpdateEvent(fd, this, eventWrite);
                
                return 0;
            case Status::CONN_WRITE:
                OutString(outstr);
                break;
            case Status::CONN_WAIT:
				LOG(GentLog::INFO, "the status of %d is connect wait", fd);
                remainsize = 0;
                Reset();
                curstatus = Status::CONN_READ;
                //GentEvent::Instance()->UpdateEvent(fd, this);
                gevent->UpdateEvent(fd, this, eventRead);
                
                return 0;
            case Status::CONN_CLOSE:
                return -1;		
            default:
                return -1;
        }
        
	}
	return 1;
}