aboutsummaryrefslogtreecommitdiffstats
path: root/multimedia
diff options
context:
space:
mode:
authorlioux <lioux@FreeBSD.org>2003-01-09 10:39:10 +0800
committerlioux <lioux@FreeBSD.org>2003-01-09 10:39:10 +0800
commitd01c253f01eb8c0d0ca2f480275de40550d0a747 (patch)
tree2672a6ea8ea87ff6e0f6d953128674a6beb12ad3 /multimedia
parent7a7da5fa12f200ab331fa56976a01d5748ad6c7e (diff)
downloadfreebsd-ports-graphics-d01c253f01eb8c0d0ca2f480275de40550d0a747.tar.gz
freebsd-ports-graphics-d01c253f01eb8c0d0ca2f480275de40550d0a747.tar.zst
freebsd-ports-graphics-d01c253f01eb8c0d0ca2f480275de40550d0a747.zip
o Improve video grabbing quality via bktr(4) driver: less frame
drops o Bump PORTREVISION Submitted by: Steve O'Hara-Smith <steve@sohara.org>
Diffstat (limited to 'multimedia')
-rw-r--r--multimedia/ffmpeg-devel/Makefile2
-rw-r--r--multimedia/ffmpeg-devel/files/grab_bsdbktr.c79
-rw-r--r--multimedia/ffmpeg/Makefile2
-rw-r--r--multimedia/ffmpeg/files/grab_bsdbktr.c79
-rw-r--r--multimedia/ffmpeg045/Makefile2
-rw-r--r--multimedia/ffmpeg045/files/grab_bsdbktr.c79
6 files changed, 87 insertions, 156 deletions
diff --git a/multimedia/ffmpeg-devel/Makefile b/multimedia/ffmpeg-devel/Makefile
index e0100a4d8b4..0de5e6a4f25 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 06499141ea6..f071b2da00f 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;y<height;y+=2) {
- for(x=0;x<width;x+=2) {
- lum[0] = p[1];
- cb[0] = p[0];
- lum[1] = p[3];
- cr[0] = p[2];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- for(x=0;x<width;x+=2) {
- lum[0] = p[1];
- lum[1] = p[3];
- p += 4;
- lum += 2;
- }
- }
-}
-
/* note: we support only one picture read at a time */
static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
{
VideoData *s = s1->priv_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 e0100a4d8b4..0de5e6a4f25 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 06499141ea6..f071b2da00f 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;y<height;y+=2) {
- for(x=0;x<width;x+=2) {
- lum[0] = p[1];
- cb[0] = p[0];
- lum[1] = p[3];
- cr[0] = p[2];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- for(x=0;x<width;x+=2) {
- lum[0] = p[1];
- lum[1] = p[3];
- p += 4;
- lum += 2;
- }
- }
-}
-
/* note: we support only one picture read at a time */
static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
{
VideoData *s = s1->priv_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 e0100a4d8b4..0de5e6a4f25 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 06499141ea6..f071b2da00f 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;y<height;y+=2) {
- for(x=0;x<width;x+=2) {
- lum[0] = p[1];
- cb[0] = p[0];
- lum[1] = p[3];
- cr[0] = p[2];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- for(x=0;x<width;x+=2) {
- lum[0] = p[1];
- lum[1] = p[3];
- p += 4;
- lum += 2;
- }
- }
-}
-
/* note: we support only one picture read at a time */
static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
{
VideoData *s = s1->priv_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;