示例#1
0
static gboolean show_camera(gpointer data)
{
	read_frame();

	if(pixmap) {
		g_object_unref(pixmap); // ref count minus one
	}

	pixmap = gdk_pixmap_new (image_face->window, preview_width, preview_height, -1);

	unsigned char *buf2 = (unsigned char *) malloc (sizeof(unsigned char) * width * height * 3);

	Pyuv422torgb24((unsigned char*)framebuffer, buf2, width, height);
	GdkPixbuf *rgbBuf = gdk_pixbuf_new_from_data(buf2,
												GDK_COLORSPACE_RGB,
												FALSE, 8,
												width, height,
												width * 3,
												NULL, NULL);

	if(rgbBuf != NULL) {
		GdkPixbuf* buf = gdk_pixbuf_scale_simple(rgbBuf,
												preview_width,
												preview_height,
												GDK_INTERP_BILINEAR);

		gdk_draw_pixbuf(pixmap,
						image_face->style->white_gc,
						buf,
						0, 0, 0, 0,
						preview_width, preview_height,
						GDK_RGB_DITHER_NONE, 0, 0);

		gdk_draw_drawable(image_face->window,
						image_face->style->white_gc,
						pixmap,
						0, 0, 0, 0,
						preview_width, preview_height);

		g_object_unref(buf);
		g_object_unref(rgbBuf);
	}

	gtk_widget_show(image_face);

	free(buf2);
	return TRUE;
}
示例#2
0
static int control(sh_audio_t *sh,int cmd,void* arg, ...){
  mad_decoder_t *this = sh->context;
    // various optional functions you MAY implement:
    switch(cmd){
      case ADCTRL_RESYNC_STREAM:
	this->have_frame=0;
	mad_synth_init  (&this->synth);
	mad_stream_init (&this->stream);
	mad_frame_init  (&this->frame);
	return CONTROL_TRUE;
      case ADCTRL_SKIP_FRAME:
        this->have_frame=read_frame(sh);
	return CONTROL_TRUE;
    }
  return CONTROL_UNKNOWN;
}
示例#3
0
文件: v4l2.c 项目: jonnor/gegl
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *output,
         const GeglRectangle *result,
         gint                 level)
{
  GeglProperties *o = GEGL_PROPERTIES (operation);
  Priv       *p = (Priv*)o->user_data;

  static gboolean inited = FALSE;

    if (!inited && o->fps != 0)
      {
        inited= TRUE;
        g_timeout_add (1000/o->fps, update, operation);
      }


  {
    fd_set fds;
    struct timeval tv;
    FD_ZERO (&fds);
    FD_SET (p->fd, &fds);

    tv.tv_sec = 2;
    tv.tv_usec = 0;

    switch (select (p->fd + 1, &fds, NULL, NULL, &tv))
    {
      case -1:
        if (errno == EINTR)
        {
          g_warning ("select");
          return FALSE;
        }
        break;
      case 0:
        g_warning ("select timeout");
        return FALSE;
        break;
      default:
        read_frame (operation, output);
    }
  }

  return  TRUE;
}
示例#4
0
static void mainloop(void)
{
    SDL_Event event;
    for (;;)
    {

        while (SDL_PollEvent(&event))
            if (event.type == SDL_QUIT)
                return;


        for (;;)
        {
            fd_set fds;
            struct timeval tv;
            int r;

            FD_ZERO(&fds);
            FD_SET(fd, &fds);

            /* Timeout. */
            tv.tv_sec = 2;
            tv.tv_usec = 0;

            r = select(fd + 1, &fds, NULL, NULL, &tv);

            if (-1 == r)
            {
                if (EINTR == errno)
                    continue;

                errno_exit("select");
            }

            if (0 == r)
            {
                fprintf(stderr, "select timeout\n");
                exit(EXIT_FAILURE);
            }

            if (read_frame())
                break;

            /* EAGAIN - continue select loop. */
        }
    }
}
BC_Bitmap::BC_Bitmap(BC_WindowBase *parent_window, unsigned char *png_data)
{
// Decompress data into a temporary vframe
    VFrame frame;

    frame.read_png(png_data);

// Initialize the bitmap
    initialize(parent_window,
               frame.get_w(),
               frame.get_h(),
               parent_window->get_color_model(),
               0);

// Copy the vframe to the bitmap
    read_frame(&frame, 0, 0, w, h);
}
示例#6
0
static gboolean id3v24_read_image (VFSFile * handle, void * * image_data, gint *
 image_size)
{
    gint version, header_size, data_size, footer_size, parsed;
    gboolean syncsafe;
    gint64 offset;
    gboolean found = FALSE;

    if (! read_header (handle, & version, & syncsafe, & offset, & header_size,
     & data_size, & footer_size))
        return FALSE;

    for (parsed = 0; parsed < data_size && ! found; )
    {
        gint frame_size, size, type;
        gchar key[5];
        guchar * data;
        gchar * mime, * desc;

        if (! read_frame (handle, data_size - parsed, version, syncsafe,
         & frame_size, key, & data, & size))
            break;

        if (! strcmp (key, "APIC") && parse_apic (data, size, & mime, & type,
         & desc, image_data, image_size))
        {
            g_free (mime);
            g_free (desc);

            if (type == 3) /* album cover */
                found = TRUE;
            else if (type == 0) /* iTunes */
                found = TRUE;
            else if (*image_data != NULL)
            {
                g_free(*image_data);
                *image_data = NULL;
            }
        }

        g_free (data);
        parsed += frame_size;
    }

    return found;
}
示例#7
0
void CQTByteStreamBase::check_for_end_of_frame (void)
{
  if (m_byte_on >= m_this_frame_size) {
    uint32_t next_frame;
    next_frame = m_frame_in_buffer + 1;
#if 0
    player_debug_message("%s - next frame %d", 
			 m_name, 
			 next_frame);
#endif
    if (next_frame >= m_frames_max) {
      m_eof = 1;
    } else {
      read_frame(next_frame);
    }
  }
}
示例#8
0
文件: play.c 项目: amyphan/firefly-mv
static int 
renderframe(int i, playback_t *play) 
{
    if( i < 0 )
        return 0;

    if (fseek(play->fp, i * play->total_frame_size, SEEK_SET) == 0) {
        if (play->frame.image) {
            free(play->frame.image);
            play->frame.image = NULL;
        }
        read_frame( &(play->frame), play->fp );
        return 1;
    } else {
        return 0;
    }
}
示例#9
0
static void mainloop (void) {
	unsigned int count;


	count = G_frames;

	while (G_frames == 0 || count-- > 0) {
		for (;;) {
			fd_set fds;
			struct timeval tv;
			int r;

			FD_ZERO (&fds);
			FD_SET (fd, &fds);

			/* Timeout. */
			tv.tv_sec = 2;
			tv.tv_usec = 0;

			r = select (fd + 1, &fds, NULL, NULL, &tv);

			if (-1 == r) {
				if (EINTR == errno)
					continue;

				errno_exit ("select");
			}

			if (0 == r) {
				//char msg[256];
				if (G_paused)
					continue;
				fprintf (stderr, "select timeout\n");
				//ioctl (fd, S2253_VIDIOC_DEBUG, msg);
				//fprintf (stderr, "debug: %s\n", msg);
				exit (EXIT_FAILURE);
			}

			if (read_frame ())
				break;

			/* EAGAIN - continue select loop. */
		}
	}
}
示例#10
0
int main(int argc,char **argv)
{
	rfbScreenInfoPtr s;
	double t1, t2;
	double timeout;
	int nread;

	if (argc == 2)
		v4l2str = argv[1];
	printf("Using dev %s\n", v4l2str);
	if (argc == 3)
		v4l2fps = atoi(argv[2]);
	printf("Using fps %d\n", v4l2fps);

	if (open_v4l2() != 0)
		exit(EXIT_FAILURE);
	if (init_v4l2() != 0)
		exit(EXIT_FAILURE);
	if (alloc_mem() != 0)
		exit(EXIT_FAILURE);

	s = rfbGetScreen(&argc, argv, v4l2width, v4l2height, 8, 3, v4l2Bpp);
	s->desktopName = "v4l2tovnc";
	s->frameBuffer = (char *) v4l2buf;
	s->serverFormat.blueShift = 0;
	s->serverFormat.greenShift = 8;
	s->serverFormat.redShift = 16;

	timeout = 1.0 / v4l2fps;
	rfbInitServer(s);
	t1 = timestamp();
	while (rfbIsActive(s)) {
		t2 = timestamp();
		if ((t2 - t1) >= timeout) {
			nread = read_frame();
			if (nread < 0)
				break;
			rfbMarkRectAsModified(s, 0, 0, v4l2width, v4l2height);
			t1 = timestamp();
		}
		rfbProcessEvents(s, -1);
	}
	close_v4l2();
	return 0;
}
示例#11
0
void capture(int *fd, camera_buffer *cam_bufs, void **img, int camera_count, int isSelect)
{
	int i;
	void *ptr;

	for (i=0;i<camera_count;i++){
		for (;;) {
			fd_set fds;
			struct timeval tv;
			int r;

			FD_ZERO (&fds);
			FD_SET (fd[i], &fds);

			/* Timeout. */
			tv.tv_sec = 0;
			tv.tv_usec = 1000000;

			if (isSelect==1)
			{
				r = select (fd[i] + 1, &fds, NULL, NULL, &tv);

				if (-1 == r) 
				{
     					if (EINTR == errno)
					continue;
					errno_exit (__FILE__,__LINE__,"select");
				}

				if (0 == r) 
				{
					fprintf (stderr, "select timeout\n");
					exit (EXIT_FAILURE);
				}
			}
			
			ptr=read_frame(fd[i],&cam_bufs[i]);
			if (ptr){
				img[i]=ptr;
				break;
			}
			/* EAGAIN - continue select loop. */
		}
	}
}
示例#12
0
/*
 * Reading raw socket.
 */
static int read_raw_socket(void)
{
	char buffer[BUFSIZE + 1] = { };
	int len;
	len = read(rawfd, buffer, BUFSIZE);
	if (len < 0) {
		perror("read()");
		return -1;
	}

	char output[BUFSIZE + 1] = { };
	// getting data from raw socket, creating readable string
	// and sending it to all clients
	if (read_frame(buffer, output, strtoul(port.c_str(), NULL, 10)) > 0)
		send_data(output);

	return 1;
}
示例#13
0
文件: readers.c 项目: Moteesh/reactos
static int stream_seek_frame(mpg123_handle *fr, off_t newframe)
{
	debug2("seek_frame to %"OFF_P" (from %"OFF_P")", (off_p)newframe, (off_p)fr->num);
	/* Seekable streams can go backwards and jump forwards.
	   Non-seekable streams still can go forward, just not jump. */
	if((fr->rdat.flags & READER_SEEKABLE) || (newframe >= fr->num))
	{
		off_t preframe; /* a leading frame we jump to */
		off_t seek_to;  /* the byte offset we want to reach */
		off_t to_skip;  /* bytes to skip to get there (can be negative) */
		/*
			now seek to nearest leading index position and read from there until newframe is reached.
			We use skip_bytes, which handles seekable and non-seekable streams
			(the latter only for positive offset, which we ensured before entering here).
		*/
		seek_to = frame_index_find(fr, newframe, &preframe);
		/* No need to seek to index position if we are closer already.
		   But I am picky about fr->num == newframe, play safe by reading the frame again.
		   If you think that's stupid, don't call a seek to the current frame. */
		if(fr->num >= newframe || fr->num < preframe)
		{
			to_skip = seek_to - fr->rd->tell(fr);
			if(fr->rd->skip_bytes(fr, to_skip) != seek_to)
			return READER_ERROR;

			debug2("going to %lu; just got %lu", (long unsigned)newframe, (long unsigned)preframe);
			fr->num = preframe-1; /* Watch out! I am going to read preframe... fr->num should indicate the frame before! */
		}
		while(fr->num < newframe)
		{
			/* try to be non-fatal now... frameNum only gets advanced on success anyway */
			if(!read_frame(fr)) break;
		}
		/* Now the wanted frame should be ready for decoding. */
		debug1("arrived at %lu", (long unsigned)fr->num);

		return MPG123_OK;
	}
	else
	{
		fr->err = MPG123_NO_SEEK;
		return READER_ERROR; /* invalid, no seek happened */
	}
}
示例#14
0
bool Camera::GetBuffer(unsigned char *image){
    fd_set fds;
    struct timeval tv;
    int r;
    FD_ZERO(&fds);
    FD_SET(fd, &fds);
    /* Timeout. */
    tv.tv_sec = 2;
    tv.tv_usec = 0;
    r = select(fd + 1, &fds, NULL, NULL, &tv);
    if (-1 == r) {
        errno_exit("select");
    }
    if (0 == r) {
        fprintf(stderr, "select timeout\n");
        exit(EXIT_FAILURE);
    }
    read_frame(image);
}
示例#15
0
//return a captured image - from wait_and_read_devices
void ImgCap_V4L2::grabImageToFile() {
  /* 
     1. wait on both devices
     2. read the device that was ready first
     3. wait on the second device
     4. read the second device

  */
  fd_set fds;
  while(true) {
      struct timeval tv;
      int r;

    FD_ZERO(&fds);
//cn/im: adds a file descriptor to a file descriptor set
    FD_SET(r_fd, &fds);
 
    tv.tv_sec = 1;
    tv.tv_usec = 0;

    r = select(r_fd+1, &fds, NULL, NULL, &tv);
    //cn/im: select() is a socket function which monitors a list of file descriptors for readability,so here we have (point to array of file descriptors, number of file descriptors checked, don't check for writeable, no files are checked for exceptions thrown, and a timeout value)

    //these check to see if a camera is connected, if one isn't after one second it throws a connection timeout
  if (-1 == r) {
      if (EINTR == errno)
        continue;
      std::cerr << "select" << std::endl;
      //errno_exit ("select");
    }

    if (0 == r) {
      std::cerr<< "Master select timeout" << std::endl;
      exit (EXIT_FAILURE);
    }

    break;

  }  
    wait_for_device(&r_fd, "right");
    read_frame(&r_fd, &r_buf);
    save_frames();
}
void CMp4ByteStream::check_for_end_of_frame (void)
{
  if (m_byte_on >= m_this_frame_size) {
    uint32_t next_frame;
    next_frame = m_frame_in_buffer + 1;
#if 0
    mp4f_message(LOG_DEBUG, "%s - next frame %d", 
		 m_name, 
		 next_frame); 
#endif
    if (next_frame >= m_frames_max + 1) {
	m_eof = true;
	mp4f_message(LOG_DEBUG, "%s last frame %u %u", 
		     m_name, next_frame, m_frames_max);
    } else {
      read_frame(next_frame, NULL);
    }
  }
}
示例#17
0
int ImgCap_V4L2::grabImageToPPM(const char * fileName) {
  /* 
     1. wait on device
     2. read the device 
  */

 
  fd_set fds;
  while(true) {
    struct timeval tv;
    int r;
    
    FD_ZERO(&fds);
    //cn/im: adds a file descriptor to a file descriptor set
    FD_SET(r_fd, &fds);
    
    tv.tv_sec = 1;
    tv.tv_usec = 0;
   
    //check for readability 
    r = select(r_fd+1, &fds, NULL, NULL, &tv);
    
    //these check to see if a camera is connected, if one isn't after one second it throws a connection timeout
    if (-1 == r) {
      if (EINTR == errno)
        continue;
      if(ImgCap_V4L2::verboseErrorPrinting) std::cerr  << "select" <<std::endl;
      return 1;
    }
    
    if (0 == r) {
      if(ImgCap_V4L2::verboseErrorPrinting) std::cerr  << "Master select timeout" << std::endl;
      return 2;
    }
    
    break;
    
  }  
  wait_for_device(&r_fd, "right");
  read_frame(&r_fd, &r_buf);
  save_frames(fileName);
  return 0;
}
示例#18
0
bool CAviVideoByteStream::start_next_frame (uint8_t **buffer, 
					    uint32_t *buflen,
					    frame_timestamp_t *ts,
					    void **ud)
{
  double ftime;
  
  read_frame(m_frame_on);
  ftime = (double)m_frame_on;
  ftime *= 1000.0;
  ftime /= m_frame_rate;
  ts->msec_timestamp = (uint64_t)ftime;
  ts->timestamp_is_pts = false;
  *buffer = m_buffer;
  *buflen = m_this_frame_size;
  m_frame_on++;
  if (m_frame_on > m_frames_max) m_eof = 1;
  return (true);
}
示例#19
0
static void mainloop(void)
{
	unsigned int count;

	if (frame_count == 0) {
		infinit_count = 1;
	}
	count = frame_count;

	while (infinit_count || count-- > 0) {
		// printf("%u\n", count);
		for (;; ) {
			fd_set fds;
			struct timeval tv;
			int r;

			FD_ZERO(&fds);
			FD_SET(fd, &fds);

			/* Timeout. */
			tv.tv_sec = 2;
			tv.tv_usec = 0;

			r = select(fd + 1, &fds, NULL, NULL, &tv);

			if (-1 == r) {
				if (EINTR == errno)
					continue;
				errno_exit("select");
			}

			if (0 == r) {
				fprintf(stderr, "select timeout\n");
				exit(EXIT_FAILURE);
			}

			if (read_frame())
				break;
			/* EAGAIN - continue select loop. */
		}
	}
}
示例#20
0
文件: reader.c 项目: jeefo/xash3d
static int stream_seek_frame( mpg123_handle_t *fr, mpg_off_t newframe )
{
	// seekable streams can go backwards and jump forwards.
	// non-seekable streams still can go forward, just not jump.
	if(( fr->rdat.flags & READER_SEEKABLE ) || ( newframe >= fr->num ))
	{
		mpg_off_t	preframe;	// a leading frame we jump to
		mpg_off_t	seek_to;	// the byte offset we want to reach
		mpg_off_t	to_skip;	// bytes to skip to get there (can be negative)

		// now seek to nearest leading index position and read from there until newframe is reached.
		// we use skip_bytes, which handles seekable and non-seekable streams
		// (the latter only for positive offset, which we ensured before entering here).
		seek_to = frame_index_find( fr, newframe, &preframe );

		// no need to seek to index position if we are closer already.
		// but I am picky about fr->num == newframe, play safe by reading the frame again.
		// if you think that's stupid, don't call a seek to the current frame.
		if( fr->num >= newframe || fr->num < preframe )
		{
			to_skip = seek_to - fr->rd->tell( fr );
			if( fr->rd->skip_bytes( fr, to_skip ) != seek_to )
				return MPG123_ERR;

			fr->num = preframe - 1; // watch out! I am going to read preframe... fr->num should indicate the frame before!
		}

		while( fr->num < newframe )
		{
			// try to be non-fatal now... frameNum only gets advanced on success anyway
			if( !read_frame( fr )) break;
		}

		// now the wanted frame should be ready for decoding.
		return MPG123_OK;
	}
	else
	{
		fr->err = MPG123_NO_SEEK;
		return MPG123_ERR; // invalid, no seek happened
	}
}
示例#21
0
/////////////////////////////////LLOPEN
int llopen(char *port, int status){
    
    
    struct termios newtio;
    
    
    
    
    link_layer.fd = open(port, O_RDWR | O_NOCTTY );
    
    
    bzero(&newtio, sizeof(newtio));
    newtio.c_cflag = program.baudrate | CS8 | CLOCAL | CREAD;
    newtio.c_iflag = IGNPAR;
    newtio.c_oflag = 0;
    
    
    newtio.c_lflag = 0;
    
    newtio.c_cc[VTIME]    = 0;
    newtio.c_cc[VMIN]     = 0;
    
    
    tcflush(link_layer.fd, TCIOFLUSH);
    
    if ( tcsetattr(link_layer.fd,TCSANOW,&newtio) == -1) {
        perror("tcsetattr");
        exit(-1);
    }
    sleep(2);
    
    
    if(read_frame(link_layer.fd,status) == -1)
    return -1;
    
    sleep(2);
    
    
    tcflush(link_layer.fd, TCIOFLUSH);
    return 0;
    
}
示例#22
0
static bool_t id3v24_read_image (VFSFile * handle, void * * image_data,
 int64_t * image_size)
{
    int version, header_size, data_size, footer_size, parsed;
    bool_t syncsafe;
    int64_t offset;
    bool_t found = FALSE;

    if (! read_header (handle, & version, & syncsafe, & offset, & header_size,
     & data_size, & footer_size))
        return FALSE;

    for (parsed = 0; parsed < data_size && ! found; )
    {
        int frame_size, size, type;
        char key[5];
        char * data;

        if (! read_frame (handle, data_size - parsed, version, syncsafe,
         & frame_size, key, & data, & size))
            break;

        if (! strcmp (key, "APIC") && id3_decode_picture (data, size, & type,
         image_data, image_size))
        {
            if (type == 3) /* album cover */
                found = TRUE;
            else if (type == 0) /* iTunes */
                found = TRUE;
            else if (*image_data != NULL)
            {
                g_free(*image_data);
                *image_data = NULL;
            }
        }

        g_free (data);
        parsed += frame_size;
    }

    return found;
}
示例#23
0
unsigned char* snapFrame()
{
      //printf("Start snapFrame\n");
      for (;;)
      {
	  fd_set fds;
	  struct timeval tv;
	  int r;

	  FD_ZERO(&fds);
	  FD_SET(fd, &fds);

	  /* Timeout. */
	  tv.tv_sec = 2;
	  tv.tv_usec = 0;

	  r = select(fd + 1, &fds, NULL, NULL, &tv);

	  if (-1 == r)
	  {
	      if (EINTR == errno)
		  continue;
	      errno_exit("select");
	  }

	  if (0 == r)
	  {
	      fprintf(stderr, "select timeout\n");
	      exit(EXIT_FAILURE);
	  }

	  if (read_frame())
	      break;
	  /* EAGAIN - continue select loop. */
      }
      //printf("End snapFrame\n");
      
     // v4l2_buffer* pI = ((v4l2_buffer*)buffers[buf.index].start);
      //return pI;
      return (unsigned char*)buffers[buf.index].start;
 
}
/**************************************************************************
 * Quicktime stream base class functions
 **************************************************************************/
CMp4ByteStream::CMp4ByteStream (CMp4File *parent,
				MP4TrackId track,
				const char *type,
				bool has_video)
  : COurInByteStream(type)
{
#ifdef ISMACRYP_DEBUG
  my_enc_file = fopen("encbuffer.raw", "w");
  my_unenc_file = fopen("unencbuffer.raw", "w");
  my_unenc_file2 = fopen("unencbuffer2.raw", "w");
#endif
#ifdef OUTPUT_TO_FILE
  char buffer[80];
  strcpy(buffer, type);
  strcat(buffer, ".raw");
  m_output_file = fopen(buffer, "w");
#endif
  m_track = track;
  m_frame_on = 1;
  m_parent = parent;
  m_eof = false;
  MP4FileHandle fh = parent->get_file();
  m_frames_max = MP4GetTrackNumberOfSamples(fh, m_track);
  mp4f_message(LOG_DEBUG, "%s - %u samples", type, m_frames_max);
  m_max_frame_size = MP4GetTrackMaxSampleSize(fh, m_track) + 4; 
  m_sample_freq = MP4GetTrackTimeScale(fh, m_track);
  m_buffer = (u_int8_t *) malloc(m_max_frame_size * sizeof(u_int8_t));
  m_has_video = has_video;
  m_frame_in_buffer = 0xffffffff;
  MP4Duration trackDuration;
  trackDuration = MP4GetTrackDuration(fh, m_track);
  uint64_t max_ts;
  max_ts = MP4ConvertFromTrackDuration(fh, 
				       m_track, 
				       trackDuration,
				       MP4_MSECS_TIME_SCALE);
  m_max_time = UINT64_TO_DOUBLE(max_ts);
  m_max_time /= 1000.0;
  mp4f_message(LOG_DEBUG, 
	       "MP4 %s max time is "U64" %g", type, max_ts, m_max_time);
  read_frame(1, NULL);
}
示例#25
0
文件: qm_spi.c 项目: jeez/qmsi
/**
 * Service an RX FIFO Full interrupt
 *
 * @brief Interrupt based transfer on SPI.
 * @param [in] spi Which SPI to transfer from.
 */
static __inline__ void handle_rx_interrupt(const qm_spi_t spi)
{
	qm_spi_reg_t *const controller = QM_SPI[spi];
	const qm_spi_async_transfer_t *const transfer = spi_async_transfer[spi];

	/* Jump to the right position of RX buffer.
	 * If no bytes were received before, we start from the beginning,
	 * otherwise we jump to the next available frame position.
	 */
	uint8_t *rx_buffer = transfer->rx + (rx_counter[spi] * dfs[spi]);

	while (controller->rxflr) {
		read_frame(spi, rx_buffer);
		rx_buffer += dfs[spi];
		rx_counter[spi]++;

		/* Check that there's not more data in the FIFO than we had
		 * requested.
		 */
		if (transfer->rx_len == rx_counter[spi]) {
			controller->imr &=
			    ~(QM_SPI_IMR_RXUIM | QM_SPI_IMR_RXOIM |
			      QM_SPI_IMR_RXFIM);
			if (transfer->callback &&
			    tmode[spi] == QM_SPI_TMOD_RX) {
				transfer->callback(transfer->callback_data, 0,
						   QM_SPI_IDLE,
						   transfer->rx_len);
			}
			break;
		}
	}

	/* Check if enough data will arrive to trigger an interrupt and adjust
	 * rxftlr accordingly.
	 */
	const uint32_t frames_left = transfer->rx_len - rx_counter[spi];
	if (frames_left <= controller->rxftlr) {
		controller->rxftlr = frames_left - 1;
	}
}
示例#26
0
static void mainloop(void)
{
	unsigned int count = capture_count;
	printf("Start capture %d frames\n", count);

	while (count-- > 0) {
		for (;;) {
#if 0
			fd_set fds;
			struct timeval tv;
			int r;

			FD_ZERO(&fds);
			FD_SET(fd, &fds);

			/* Timeout. */
			tv.tv_sec = 2;
			tv.tv_usec = 0;

			r = select(fd + 1, &fds, NULL, NULL, &tv);

			if (-1 == r) {
				if (EINTR == errno)
					continue;

				errno_exit("select");
			}

			if (0 == r) {
				fprintf(stderr, "select timeout\n");
				exit(EXIT_FAILURE);
			}
#endif

			if (read_frame())
				break;

			/* EAGAIN - continue select loop. */
		}
	}
}
示例#27
0
static void mainloop()
{
    unsigned long val,count;
    time_t elapsed = time(NULL);
    val = count = 100;

    while (count-- > 0)
    {
        for (;;)
        {
            fd_set fds;
            struct timeval tv;
            int r;
            FD_ZERO (&fds);
            FD_SET (fd, &fds);

            // * Timeout. *
            tv.tv_sec = 2;
            tv.tv_usec = 0;

            r = select (fd + 1, &fds, NULL, NULL, &tv);
            if (-1 == r)
            {
                if (EINTR == errno)
                    continue;
                errno_exit ("select");
            }
            if (0 == r)
            {
                fprintf (stderr, "select timeout\n");
                exit (EXIT_FAILURE);
            }
            if (read_frame ())
                break;
        }
    }

    elapsed = time(NULL) - elapsed;
    fprintf(stdout, "The frame rate (per second) = %lu\n", val/elapsed);

}
示例#28
0
int main(int argc,char **argv)
{
	int fd;
    int i=4;
    struct head_buffer *hbuffer;
 	if(argc>1)
		fd=open(argv[1],O_RDWR);
	else
		fd=open("/dev/video0",O_RDWR);

	hbuffer=(struct head_buffer*)malloc(sizeof(struct head_buffer));
    set_fmt(fd);
    hbuffer=init_mmap(fd,hbuffer);
    start_capturing(fd,IO_METHOD_MMAP,hbuffer);
    while(i--)
    {
        read_frame(fd,IO_METHOD_MMAP,hbuffer);
        sleep(1);
    }
    return 0;
}
示例#29
0
void
mpeg_es_reader_c::read_headers() {
  try {
    M2VParser parser;

    // Let's find the first frame. We need its information like
    // resolution, MPEG version etc.
    parser.SetProbeMode();
    if (!read_frame(parser, *m_in, 1024 * 1024))
      throw mtx::input::header_parsing_x();

    m_in->setFilePointer(0);

    MPEG2SequenceHeader seq_hdr = parser.GetSequenceHeader();
    version                     = parser.GetMPEGVersion();
    interlaced                  = !seq_hdr.progressiveSequence;
    width                       = seq_hdr.width;
    height                      = seq_hdr.height;
    frame_rate                  = seq_hdr.progressiveSequence ? seq_hdr.frameOrFieldRate : seq_hdr.frameOrFieldRate * 2.0f;
    aspect_ratio                = seq_hdr.aspectRatio;

    if ((0 >= aspect_ratio) || (1 == aspect_ratio))
      dwidth = width;
    else
      dwidth = (int)(height * aspect_ratio);
    dheight = height;

    MPEGChunk *raw_seq_hdr = parser.GetRealSequenceHeader();
    if (raw_seq_hdr) {
      m_ti.m_private_data = (unsigned char *)safememdup(raw_seq_hdr->GetPointer(), raw_seq_hdr->GetSize());
      m_ti.m_private_size = raw_seq_hdr->GetSize();
    }

    mxverb(2, boost::format("mpeg_es_reader: version %1% width %2% height %3% FPS %4% AR %5%\n") % version % width % height % frame_rate % aspect_ratio);

  } catch (mtx::mm_io::exception &) {
    throw mtx::input::open_x();
  }
  show_demuxer_info();
}
示例#30
0
int ChromaKeyHSV::process_buffer(VFrame *frame,
		int64_t start_position,
		double frame_rate)
{
	load_configuration();
	this->input = frame;
	this->output = frame;


	read_frame(frame, 
		0, 
		start_position, 
		frame_rate,
		get_use_opengl());
	if(get_use_opengl()) return run_opengl();


	if(!engine) engine = new ChromaKeyServer(this);
	engine->process_packages();

	return 0;
}