From d01c253f01eb8c0d0ca2f480275de40550d0a747 Mon Sep 17 00:00:00 2001 From: lioux Date: Thu, 9 Jan 2003 02:39:10 +0000 Subject: o Improve video grabbing quality via bktr(4) driver: less frame drops o Bump PORTREVISION Submitted by: Steve O'Hara-Smith --- multimedia/ffmpeg-devel/Makefile | 2 +- multimedia/ffmpeg-devel/files/grab_bsdbktr.c | 79 ++++++++++------------------ multimedia/ffmpeg/Makefile | 2 +- multimedia/ffmpeg/files/grab_bsdbktr.c | 79 ++++++++++------------------ multimedia/ffmpeg045/Makefile | 2 +- multimedia/ffmpeg045/files/grab_bsdbktr.c | 79 ++++++++++------------------ 6 files changed, 87 insertions(+), 156 deletions(-) (limited to 'multimedia') diff --git a/multimedia/ffmpeg-devel/Makefile b/multimedia/ffmpeg-devel/Makefile index e0100a4d8b41..0de5e6a4f254 100644 --- a/multimedia/ffmpeg-devel/Makefile +++ b/multimedia/ffmpeg-devel/Makefile @@ -7,7 +7,7 @@ PORTNAME= ffmpeg PORTVERSION= 0.4.5 -PORTREVISION= 4 +PORTREVISION= 5 CATEGORIES= multimedia audio net MASTER_SITES= ${MASTER_SITE_LOCAL} MASTER_SITE_SUBDIR= lioux diff --git a/multimedia/ffmpeg-devel/files/grab_bsdbktr.c b/multimedia/ffmpeg-devel/files/grab_bsdbktr.c index 06499141ea6d..f071b2da00f1 100644 --- a/multimedia/ffmpeg-devel/files/grab_bsdbktr.c +++ b/multimedia/ffmpeg-devel/files/grab_bsdbktr.c @@ -38,7 +38,8 @@ typedef struct { int frame_format; /* see VIDEO_PALETTE_xxx */ int width, height; int frame_rate; - int frame_size; + INT64 per_frame; + INT64 last_frame_time; } VideoData; const char *video_device = "/dev/bktr0"; @@ -59,14 +60,10 @@ const char *video_device = "/dev/bktr0"; #endif static UINT8 *video_buf; - -static int signal_expected = 0; -static int unexpected_signals = 0; - +static int nsignals = 0; static void catchsignal(int signal) { - if (!signal_expected) unexpected_signals++; - signal_expected = 0; + nsignals++; return; } @@ -88,6 +85,7 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) width = s->width; height = s->height; + s->last_frame_time = 0; s->tuner_fd = open ("/dev/tuner0", O_RDWR); if (s->tuner_fd < 0) { @@ -103,7 +101,7 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) geo.rows = height; geo.columns = width; geo.frames = 1; - geo.oformat = METEOR_GEO_YUV_PACKED; + geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12; if ((format == PAL) && (height <= (PAL_HEIGHT/2))) geo.oformat |= METEOR_GEO_EVEN_ONLY; @@ -131,7 +129,7 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) perror ("METEORSINPUT"); return -EIO; } - video_buf = mmap((caddr_t)0, width*height*2, PROT_READ, MAP_SHARED, + video_buf = mmap((caddr_t)0, width*height*3, PROT_READ, MAP_SHARED, video_fd, (off_t) 0); if (video_buf == MAP_FAILED) { perror ("mmap"); @@ -140,66 +138,45 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) c = METEOR_CAP_CONTINOUS; ioctl(s->fd, METEORCAPTUR, &c); c = SIGUSR1; - signal_expected = 1; ioctl (s->fd, METEORSSIGNAL, &c); return 0; } -static void bf_yuv422_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr, - UINT8 *src, int width, int height) -{ - int x, y; - UINT8 *p = src; - for(y=0;ypriv_data; int size, halfsize; sigset_t msig; - UINT8 *lum, *cb, *cr; + UINT64 curtime; size = s->width * s->height; halfsize = size << 1; if (av_new_packet(pkt, size + halfsize) < 0) return -EIO; - if (unexpected_signals > 0) { - unexpected_signals--; - } else { - signal_expected = 1; - sigemptyset (&msig); - sigsuspend (&msig); + curtime = av_gettime(); + if (!s->last_frame_time + || ((s->last_frame_time + s->per_frame) > curtime)) { + if (!usleep (s->last_frame_time + s->per_frame + s->per_frame/8 - curtime)) { + if (!nsignals) + printf ("\nSLEPT NO signals - %d microseconds late\n", + av_gettime() - s->last_frame_time - s->per_frame); + } + } else if ((s->last_frame_time + s->per_frame*5 < curtime)) { + bzero (pkt->data, size + halfsize); + printf ("\nBlank %d signals - %d microseconds\n", + nsignals, curtime - s->last_frame_time - s->per_frame); + s->last_frame_time += s->per_frame; + return size + halfsize; } + nsignals = 0; - if (unexpected_signals & 1) { - bzero (pkt->data, size + halfsize); - } else { - lum = pkt->data; - cb = lum + size; - cr = cb + size/4; + s->last_frame_time = s->last_frame_time + ? s->last_frame_time + s->per_frame + : av_gettime(); - bf_yuv422_to_yuv420p (lum, cb, cr, video_buf, s->width, s->height); - } + memcpy (pkt->data, video_buf, size + halfsize); return size + halfsize; } @@ -226,7 +203,7 @@ static int grab_read_header (AVFormatContext *s1, AVFormatParameters *ap) s->width = width; s->height = height; s->frame_rate = frame_rate; - s->frame_size = width*height*2; + s->per_frame = (INT64_C(1000000) * FRAME_RATE_BASE) / s->frame_rate; st->codec.pix_fmt = PIX_FMT_YUV420P; st->codec.codec_id = CODEC_ID_RAWVIDEO; st->codec.width = width; diff --git a/multimedia/ffmpeg/Makefile b/multimedia/ffmpeg/Makefile index e0100a4d8b41..0de5e6a4f254 100644 --- a/multimedia/ffmpeg/Makefile +++ b/multimedia/ffmpeg/Makefile @@ -7,7 +7,7 @@ PORTNAME= ffmpeg PORTVERSION= 0.4.5 -PORTREVISION= 4 +PORTREVISION= 5 CATEGORIES= multimedia audio net MASTER_SITES= ${MASTER_SITE_LOCAL} MASTER_SITE_SUBDIR= lioux diff --git a/multimedia/ffmpeg/files/grab_bsdbktr.c b/multimedia/ffmpeg/files/grab_bsdbktr.c index 06499141ea6d..f071b2da00f1 100644 --- a/multimedia/ffmpeg/files/grab_bsdbktr.c +++ b/multimedia/ffmpeg/files/grab_bsdbktr.c @@ -38,7 +38,8 @@ typedef struct { int frame_format; /* see VIDEO_PALETTE_xxx */ int width, height; int frame_rate; - int frame_size; + INT64 per_frame; + INT64 last_frame_time; } VideoData; const char *video_device = "/dev/bktr0"; @@ -59,14 +60,10 @@ const char *video_device = "/dev/bktr0"; #endif static UINT8 *video_buf; - -static int signal_expected = 0; -static int unexpected_signals = 0; - +static int nsignals = 0; static void catchsignal(int signal) { - if (!signal_expected) unexpected_signals++; - signal_expected = 0; + nsignals++; return; } @@ -88,6 +85,7 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) width = s->width; height = s->height; + s->last_frame_time = 0; s->tuner_fd = open ("/dev/tuner0", O_RDWR); if (s->tuner_fd < 0) { @@ -103,7 +101,7 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) geo.rows = height; geo.columns = width; geo.frames = 1; - geo.oformat = METEOR_GEO_YUV_PACKED; + geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12; if ((format == PAL) && (height <= (PAL_HEIGHT/2))) geo.oformat |= METEOR_GEO_EVEN_ONLY; @@ -131,7 +129,7 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) perror ("METEORSINPUT"); return -EIO; } - video_buf = mmap((caddr_t)0, width*height*2, PROT_READ, MAP_SHARED, + video_buf = mmap((caddr_t)0, width*height*3, PROT_READ, MAP_SHARED, video_fd, (off_t) 0); if (video_buf == MAP_FAILED) { perror ("mmap"); @@ -140,66 +138,45 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) c = METEOR_CAP_CONTINOUS; ioctl(s->fd, METEORCAPTUR, &c); c = SIGUSR1; - signal_expected = 1; ioctl (s->fd, METEORSSIGNAL, &c); return 0; } -static void bf_yuv422_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr, - UINT8 *src, int width, int height) -{ - int x, y; - UINT8 *p = src; - for(y=0;ypriv_data; int size, halfsize; sigset_t msig; - UINT8 *lum, *cb, *cr; + UINT64 curtime; size = s->width * s->height; halfsize = size << 1; if (av_new_packet(pkt, size + halfsize) < 0) return -EIO; - if (unexpected_signals > 0) { - unexpected_signals--; - } else { - signal_expected = 1; - sigemptyset (&msig); - sigsuspend (&msig); + curtime = av_gettime(); + if (!s->last_frame_time + || ((s->last_frame_time + s->per_frame) > curtime)) { + if (!usleep (s->last_frame_time + s->per_frame + s->per_frame/8 - curtime)) { + if (!nsignals) + printf ("\nSLEPT NO signals - %d microseconds late\n", + av_gettime() - s->last_frame_time - s->per_frame); + } + } else if ((s->last_frame_time + s->per_frame*5 < curtime)) { + bzero (pkt->data, size + halfsize); + printf ("\nBlank %d signals - %d microseconds\n", + nsignals, curtime - s->last_frame_time - s->per_frame); + s->last_frame_time += s->per_frame; + return size + halfsize; } + nsignals = 0; - if (unexpected_signals & 1) { - bzero (pkt->data, size + halfsize); - } else { - lum = pkt->data; - cb = lum + size; - cr = cb + size/4; + s->last_frame_time = s->last_frame_time + ? s->last_frame_time + s->per_frame + : av_gettime(); - bf_yuv422_to_yuv420p (lum, cb, cr, video_buf, s->width, s->height); - } + memcpy (pkt->data, video_buf, size + halfsize); return size + halfsize; } @@ -226,7 +203,7 @@ static int grab_read_header (AVFormatContext *s1, AVFormatParameters *ap) s->width = width; s->height = height; s->frame_rate = frame_rate; - s->frame_size = width*height*2; + s->per_frame = (INT64_C(1000000) * FRAME_RATE_BASE) / s->frame_rate; st->codec.pix_fmt = PIX_FMT_YUV420P; st->codec.codec_id = CODEC_ID_RAWVIDEO; st->codec.width = width; diff --git a/multimedia/ffmpeg045/Makefile b/multimedia/ffmpeg045/Makefile index e0100a4d8b41..0de5e6a4f254 100644 --- a/multimedia/ffmpeg045/Makefile +++ b/multimedia/ffmpeg045/Makefile @@ -7,7 +7,7 @@ PORTNAME= ffmpeg PORTVERSION= 0.4.5 -PORTREVISION= 4 +PORTREVISION= 5 CATEGORIES= multimedia audio net MASTER_SITES= ${MASTER_SITE_LOCAL} MASTER_SITE_SUBDIR= lioux diff --git a/multimedia/ffmpeg045/files/grab_bsdbktr.c b/multimedia/ffmpeg045/files/grab_bsdbktr.c index 06499141ea6d..f071b2da00f1 100644 --- a/multimedia/ffmpeg045/files/grab_bsdbktr.c +++ b/multimedia/ffmpeg045/files/grab_bsdbktr.c @@ -38,7 +38,8 @@ typedef struct { int frame_format; /* see VIDEO_PALETTE_xxx */ int width, height; int frame_rate; - int frame_size; + INT64 per_frame; + INT64 last_frame_time; } VideoData; const char *video_device = "/dev/bktr0"; @@ -59,14 +60,10 @@ const char *video_device = "/dev/bktr0"; #endif static UINT8 *video_buf; - -static int signal_expected = 0; -static int unexpected_signals = 0; - +static int nsignals = 0; static void catchsignal(int signal) { - if (!signal_expected) unexpected_signals++; - signal_expected = 0; + nsignals++; return; } @@ -88,6 +85,7 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) width = s->width; height = s->height; + s->last_frame_time = 0; s->tuner_fd = open ("/dev/tuner0", O_RDWR); if (s->tuner_fd < 0) { @@ -103,7 +101,7 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) geo.rows = height; geo.columns = width; geo.frames = 1; - geo.oformat = METEOR_GEO_YUV_PACKED; + geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12; if ((format == PAL) && (height <= (PAL_HEIGHT/2))) geo.oformat |= METEOR_GEO_EVEN_ONLY; @@ -131,7 +129,7 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) perror ("METEORSINPUT"); return -EIO; } - video_buf = mmap((caddr_t)0, width*height*2, PROT_READ, MAP_SHARED, + video_buf = mmap((caddr_t)0, width*height*3, PROT_READ, MAP_SHARED, video_fd, (off_t) 0); if (video_buf == MAP_FAILED) { perror ("mmap"); @@ -140,66 +138,45 @@ static int bktr_init(AVFormatContext *s1, AVFormatParameters *ap) c = METEOR_CAP_CONTINOUS; ioctl(s->fd, METEORCAPTUR, &c); c = SIGUSR1; - signal_expected = 1; ioctl (s->fd, METEORSSIGNAL, &c); return 0; } -static void bf_yuv422_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr, - UINT8 *src, int width, int height) -{ - int x, y; - UINT8 *p = src; - for(y=0;ypriv_data; int size, halfsize; sigset_t msig; - UINT8 *lum, *cb, *cr; + UINT64 curtime; size = s->width * s->height; halfsize = size << 1; if (av_new_packet(pkt, size + halfsize) < 0) return -EIO; - if (unexpected_signals > 0) { - unexpected_signals--; - } else { - signal_expected = 1; - sigemptyset (&msig); - sigsuspend (&msig); + curtime = av_gettime(); + if (!s->last_frame_time + || ((s->last_frame_time + s->per_frame) > curtime)) { + if (!usleep (s->last_frame_time + s->per_frame + s->per_frame/8 - curtime)) { + if (!nsignals) + printf ("\nSLEPT NO signals - %d microseconds late\n", + av_gettime() - s->last_frame_time - s->per_frame); + } + } else if ((s->last_frame_time + s->per_frame*5 < curtime)) { + bzero (pkt->data, size + halfsize); + printf ("\nBlank %d signals - %d microseconds\n", + nsignals, curtime - s->last_frame_time - s->per_frame); + s->last_frame_time += s->per_frame; + return size + halfsize; } + nsignals = 0; - if (unexpected_signals & 1) { - bzero (pkt->data, size + halfsize); - } else { - lum = pkt->data; - cb = lum + size; - cr = cb + size/4; + s->last_frame_time = s->last_frame_time + ? s->last_frame_time + s->per_frame + : av_gettime(); - bf_yuv422_to_yuv420p (lum, cb, cr, video_buf, s->width, s->height); - } + memcpy (pkt->data, video_buf, size + halfsize); return size + halfsize; } @@ -226,7 +203,7 @@ static int grab_read_header (AVFormatContext *s1, AVFormatParameters *ap) s->width = width; s->height = height; s->frame_rate = frame_rate; - s->frame_size = width*height*2; + s->per_frame = (INT64_C(1000000) * FRAME_RATE_BASE) / s->frame_rate; st->codec.pix_fmt = PIX_FMT_YUV420P; st->codec.codec_id = CODEC_ID_RAWVIDEO; st->codec.width = width; -- cgit