[FFmpeg-devel] PATCH grab.c, adding support for hardware based VIDIOSFPS

Benoit Fouet benoit.fouet
Mon Jun 4 16:36:34 CEST 2007


Hi,

mmh wrote:
> If the underlying video4linux driver supports frame rate control then
> use it instead of user space software support.
>
>   
> ------------------------------------------------------------------------
>
> Index: grab.c
> ===================================================================
> --- grab.c	(revision 9203)
> +++ grab.c	(working copy)
> @@ -28,6 +28,10 @@
>  #include <linux/videodev.h>
>  #include <time.h>
>  
> +#ifndef VIDIOSFPS
> +#define VIDIOSFPS		_IOW('v',BASE_VIDIOCPRIVATE+20, int)			/* Set fps */
> +#endif
> +
>   

i think this is "dangerous", as this ioctl id can be used for "private"
usage

>  typedef struct {
>      int fd;
>      int frame_format; /* see VIDEO_PALETTE_xxx */
> @@ -35,6 +39,7 @@
>      int width, height;
>      int frame_rate;
>      int frame_rate_base;
> +    int sw_fps_reduction;
>      int64_t time_frame;
>      int frame_size;
>      struct video_capability video_cap;
> @@ -78,6 +83,7 @@
>      VideoData *s = s1->priv_data;
>      AVStream *st;
>      int width, height;
> +    int fps;
>      int video_fd, frame_size;
>      int ret, frame_rate, frame_rate_base;
>      int desired_palette, desired_depth;
> @@ -183,6 +189,9 @@
>              goto fail1;
>      }
>  
> +    fps = s->frame_rate / s->frame_rate_base;
> +    s->sw_fps_reduction  = ioctl( video_fd, VIDIOSFPS, &fps ) < 0;
> +
>   

maybe something like:
#ifdef VIDIOSFPS
    fps = s->frame_rate / s->frame_rate_base;
    s->sw_fps_reduction = ioctl( video_fd, VIDIOSFPS, &fps ) < 0;
#else
    s->sw_fps_reduction = 1;
#endif

you may also need to flag fps variable definition...

>      ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
>      if (ret < 0) {
>          /* try to use read based access */
> @@ -327,9 +336,11 @@
>              }
>              break;
>          }
> -        ts.tv_sec = delay / 1000000;
> -        ts.tv_nsec = (delay % 1000000) * 1000;
> -        nanosleep(&ts, NULL);
> +        if (s->sw_fps_reduction) {
> +            ts.tv_sec = delay / 1000000;
> +            ts.tv_nsec = (delay % 1000000) * 1000;
> +            nanosleep(&ts, NULL);
> +	}
>   

and the cosmetics should come as a separate patch

>      }
>  
>      if (av_new_packet(pkt, s->frame_size) < 0)
>   

Ben
-- 
Purple Labs S.A.
www.purplelabs.com




More information about the ffmpeg-devel mailing list