2001-07-22 17:18:56 +03:00
|
|
|
/*
|
|
|
|
* Linux video grab interface
|
2002-05-26 01:34:32 +03:00
|
|
|
* Copyright (c) 2000,2001 Fabrice Bellard.
|
2001-07-22 17:18:56 +03:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-05-26 01:34:32 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 18:30:46 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2001-07-22 17:18:56 +03:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2001-07-22 17:18:56 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2002-05-26 01:34:32 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2001-07-22 17:18:56 +03:00
|
|
|
*
|
2002-05-26 01:34:32 +03:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 18:30:46 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-13 00:43:26 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-07-22 17:18:56 +03:00
|
|
|
*/
|
2001-08-14 00:37:10 +03:00
|
|
|
#include "avformat.h"
|
2001-07-22 17:18:56 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/time.h>
|
2003-09-09 22:14:05 +03:00
|
|
|
#define _LINUX_TIME_H 1
|
|
|
|
#include <linux/videodev.h>
|
2002-02-18 12:20:03 +02:00
|
|
|
#include <time.h>
|
2001-07-22 17:18:56 +03:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int fd;
|
|
|
|
int frame_format; /* see VIDEO_PALETTE_xxx */
|
|
|
|
int use_mmap;
|
|
|
|
int width, height;
|
2001-09-25 02:27:06 +03:00
|
|
|
int frame_rate;
|
2003-03-12 17:16:19 +02:00
|
|
|
int frame_rate_base;
|
2003-02-11 18:35:48 +02:00
|
|
|
int64_t time_frame;
|
2001-09-25 02:27:06 +03:00
|
|
|
int frame_size;
|
2002-11-19 16:57:42 +02:00
|
|
|
struct video_capability video_cap;
|
|
|
|
struct video_audio audio_saved;
|
2003-02-11 18:35:48 +02:00
|
|
|
uint8_t *video_buf;
|
2002-11-19 16:57:42 +02:00
|
|
|
struct video_mbuf gb_buffers;
|
|
|
|
struct video_mmap gb_buf;
|
|
|
|
int gb_frame;
|
|
|
|
|
|
|
|
/* ATI All In Wonder specific stuff */
|
|
|
|
/* XXX: remove and merge in libavcodec/imgconvert.c */
|
|
|
|
int aiw_enabled;
|
|
|
|
int deint;
|
|
|
|
int halfw;
|
2003-02-11 18:35:48 +02:00
|
|
|
uint8_t *src_mem;
|
|
|
|
uint8_t *lum_m4_mem;
|
2001-07-22 17:18:56 +03:00
|
|
|
} VideoData;
|
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
static int aiw_init(VideoData *s);
|
|
|
|
static int aiw_read_picture(VideoData *s, uint8_t *data);
|
|
|
|
static int aiw_close(VideoData *s);
|
2001-07-22 17:18:56 +03:00
|
|
|
|
2001-09-25 02:27:06 +03:00
|
|
|
static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
|
2001-07-22 17:18:56 +03:00
|
|
|
{
|
2002-05-20 19:31:13 +03:00
|
|
|
VideoData *s = s1->priv_data;
|
2001-09-25 02:27:06 +03:00
|
|
|
AVStream *st;
|
2001-07-22 17:18:56 +03:00
|
|
|
int width, height;
|
|
|
|
int video_fd, frame_size;
|
2003-03-12 17:16:19 +02:00
|
|
|
int ret, frame_rate, frame_rate_base;
|
2006-06-28 15:18:22 +03:00
|
|
|
int desired_palette, desired_depth;
|
2003-06-25 13:21:45 +03:00
|
|
|
struct video_tuner tuner;
|
2002-11-19 16:57:42 +02:00
|
|
|
struct video_audio audio;
|
2006-05-04 15:23:12 +03:00
|
|
|
struct video_picture pict;
|
2003-01-23 12:33:16 +02:00
|
|
|
const char *video_device;
|
2004-04-25 16:30:21 +03:00
|
|
|
int j;
|
2001-09-25 02:27:06 +03:00
|
|
|
|
2006-03-13 11:47:37 +02:00
|
|
|
if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
|
|
|
|
av_log(s1, AV_LOG_ERROR, "Bad capture size (%dx%d) or wrong time base (%d)\n",
|
|
|
|
ap->width, ap->height, ap->time_base.den);
|
|
|
|
|
2001-09-25 02:27:06 +03:00
|
|
|
return -1;
|
2006-03-13 11:47:37 +02:00
|
|
|
}
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2001-09-25 02:27:06 +03:00
|
|
|
width = ap->width;
|
|
|
|
height = ap->height;
|
2005-05-01 00:43:59 +03:00
|
|
|
frame_rate = ap->time_base.den;
|
|
|
|
frame_rate_base = ap->time_base.num;
|
2001-09-25 02:27:06 +03:00
|
|
|
|
2006-03-13 11:47:37 +02:00
|
|
|
if((unsigned)width > 32767 || (unsigned)height > 32767) {
|
|
|
|
av_log(s1, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n",
|
|
|
|
width, height);
|
|
|
|
|
2005-01-08 16:21:33 +02:00
|
|
|
return -1;
|
2006-03-13 11:47:37 +02:00
|
|
|
}
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2002-05-20 19:31:13 +03:00
|
|
|
st = av_new_stream(s1, 0);
|
|
|
|
if (!st)
|
2001-09-25 02:27:06 +03:00
|
|
|
return -ENOMEM;
|
2006-02-01 13:31:33 +02:00
|
|
|
av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
|
2001-09-25 02:27:06 +03:00
|
|
|
|
|
|
|
s->width = width;
|
|
|
|
s->height = height;
|
2003-03-12 17:16:19 +02:00
|
|
|
s->frame_rate = frame_rate;
|
|
|
|
s->frame_rate_base = frame_rate_base;
|
2001-07-22 17:18:56 +03:00
|
|
|
|
2003-01-23 12:33:16 +02:00
|
|
|
video_device = ap->device;
|
|
|
|
if (!video_device)
|
|
|
|
video_device = "/dev/video";
|
2003-01-23 00:40:52 +02:00
|
|
|
video_fd = open(video_device, O_RDWR);
|
2001-07-22 17:18:56 +03:00
|
|
|
if (video_fd < 0) {
|
2003-01-23 00:40:52 +02:00
|
|
|
perror(video_device);
|
2001-09-25 02:27:06 +03:00
|
|
|
goto fail;
|
2001-07-22 17:18:56 +03:00
|
|
|
}
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) {
|
2001-07-22 17:18:56 +03:00
|
|
|
perror("VIDIOCGCAP");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {
|
2005-12-22 03:10:11 +02:00
|
|
|
av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n");
|
2001-07-22 17:18:56 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
2002-04-08 23:58:56 +03:00
|
|
|
|
|
|
|
desired_palette = -1;
|
2006-06-28 15:18:22 +03:00
|
|
|
desired_depth = -1;
|
|
|
|
if (ap->pix_fmt == PIX_FMT_YUV420P) {
|
2002-04-08 23:58:56 +03:00
|
|
|
desired_palette = VIDEO_PALETTE_YUV420P;
|
2006-06-28 15:18:22 +03:00
|
|
|
desired_depth = 12;
|
|
|
|
} else if (ap->pix_fmt == PIX_FMT_YUV422) {
|
2002-04-08 23:58:56 +03:00
|
|
|
desired_palette = VIDEO_PALETTE_YUV422;
|
2006-06-28 15:18:22 +03:00
|
|
|
desired_depth = 16;
|
|
|
|
} else if (ap->pix_fmt == PIX_FMT_BGR24) {
|
2002-04-08 23:58:56 +03:00
|
|
|
desired_palette = VIDEO_PALETTE_RGB24;
|
2006-06-28 15:18:22 +03:00
|
|
|
desired_depth = 24;
|
2005-12-17 20:14:38 +02:00
|
|
|
}
|
2003-06-25 13:21:45 +03:00
|
|
|
|
|
|
|
/* set tv standard */
|
|
|
|
if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
|
2005-12-22 03:10:11 +02:00
|
|
|
if (!strcasecmp(ap->standard, "pal"))
|
|
|
|
tuner.mode = VIDEO_MODE_PAL;
|
|
|
|
else if (!strcasecmp(ap->standard, "secam"))
|
|
|
|
tuner.mode = VIDEO_MODE_SECAM;
|
|
|
|
else
|
|
|
|
tuner.mode = VIDEO_MODE_NTSC;
|
|
|
|
ioctl(video_fd, VIDIOCSTUNER, &tuner);
|
2003-06-25 13:21:45 +03:00
|
|
|
}
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
/* unmute audio */
|
2002-11-19 16:57:42 +02:00
|
|
|
audio.audio = 0;
|
2001-07-22 17:18:56 +03:00
|
|
|
ioctl(video_fd, VIDIOCGAUDIO, &audio);
|
2002-11-19 16:57:42 +02:00
|
|
|
memcpy(&s->audio_saved, &audio, sizeof(audio));
|
2001-07-22 17:18:56 +03:00
|
|
|
audio.flags &= ~VIDEO_AUDIO_MUTE;
|
|
|
|
ioctl(video_fd, VIDIOCSAUDIO, &audio);
|
|
|
|
|
2006-05-04 15:23:12 +03:00
|
|
|
ioctl(video_fd, VIDIOCGPICT, &pict);
|
|
|
|
#if 0
|
|
|
|
printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
|
|
|
|
pict.colour,
|
|
|
|
pict.hue,
|
|
|
|
pict.brightness,
|
|
|
|
pict.contrast,
|
|
|
|
pict.whiteness);
|
|
|
|
#endif
|
|
|
|
/* try to choose a suitable video format */
|
|
|
|
pict.palette = desired_palette;
|
2006-06-28 15:18:22 +03:00
|
|
|
pict.depth= desired_depth;
|
2006-05-04 15:23:12 +03:00
|
|
|
if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
|
|
|
|
pict.palette=VIDEO_PALETTE_YUV420P;
|
2006-06-28 15:18:22 +03:00
|
|
|
pict.depth=12;
|
2006-05-04 15:23:12 +03:00
|
|
|
ret = ioctl(video_fd, VIDIOCSPICT, &pict);
|
|
|
|
if (ret < 0) {
|
|
|
|
pict.palette=VIDEO_PALETTE_YUV422;
|
2006-06-28 15:18:22 +03:00
|
|
|
pict.depth=16;
|
2006-05-04 15:23:12 +03:00
|
|
|
ret = ioctl(video_fd, VIDIOCSPICT, &pict);
|
|
|
|
if (ret < 0) {
|
|
|
|
pict.palette=VIDEO_PALETTE_RGB24;
|
2006-06-28 15:18:22 +03:00
|
|
|
pict.depth=24;
|
2006-05-04 15:23:12 +03:00
|
|
|
ret = ioctl(video_fd, VIDIOCSPICT, &pict);
|
|
|
|
if (ret < 0)
|
2006-09-15 14:17:41 +03:00
|
|
|
pict.palette=VIDEO_PALETTE_GREY;
|
|
|
|
pict.depth=8;
|
|
|
|
ret = ioctl(video_fd, VIDIOCSPICT, &pict);
|
|
|
|
if (ret < 0)
|
|
|
|
goto fail1;
|
2006-05-04 15:23:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
|
2001-07-22 17:18:56 +03:00
|
|
|
if (ret < 0) {
|
|
|
|
/* try to use read based access */
|
|
|
|
struct video_window win;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
win.x = 0;
|
|
|
|
win.y = 0;
|
|
|
|
win.width = width;
|
|
|
|
win.height = height;
|
|
|
|
win.chromakey = -1;
|
|
|
|
win.flags = 0;
|
|
|
|
|
|
|
|
ioctl(video_fd, VIDIOCSWIN, &win);
|
|
|
|
|
|
|
|
s->frame_format = pict.palette;
|
|
|
|
|
|
|
|
val = 1;
|
|
|
|
ioctl(video_fd, VIDIOCCAPTURE, &val);
|
|
|
|
|
2004-04-27 16:28:16 +03:00
|
|
|
s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
|
2001-07-22 17:18:56 +03:00
|
|
|
s->use_mmap = 0;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
/* ATI All In Wonder automatic activation */
|
|
|
|
if (!strcmp(s->video_cap.name, "Km")) {
|
|
|
|
if (aiw_init(s) < 0)
|
|
|
|
goto fail;
|
|
|
|
s->aiw_enabled = 1;
|
|
|
|
/* force 420P format because convertion from YUV422 to YUV420P
|
|
|
|
is done in this driver (ugly) */
|
|
|
|
s->frame_format = VIDEO_PALETTE_YUV420P;
|
|
|
|
}
|
2001-07-22 17:18:56 +03:00
|
|
|
} else {
|
2002-11-19 16:57:42 +02:00
|
|
|
s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0);
|
|
|
|
if ((unsigned char*)-1 == s->video_buf) {
|
2006-12-28 02:32:06 +02:00
|
|
|
s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_PRIVATE,video_fd,0);
|
|
|
|
if ((unsigned char*)-1 == s->video_buf) {
|
|
|
|
perror("mmap");
|
|
|
|
goto fail;
|
|
|
|
}
|
2001-07-22 17:18:56 +03:00
|
|
|
}
|
2002-11-19 16:57:42 +02:00
|
|
|
s->gb_frame = 0;
|
2004-04-27 16:28:16 +03:00
|
|
|
s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
/* start to grab the first frame */
|
2002-11-19 16:57:42 +02:00
|
|
|
s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
|
|
|
|
s->gb_buf.height = height;
|
|
|
|
s->gb_buf.width = width;
|
2006-05-04 15:23:12 +03:00
|
|
|
s->gb_buf.format = pict.palette;
|
|
|
|
|
|
|
|
ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
|
2001-07-22 17:18:56 +03:00
|
|
|
if (ret < 0) {
|
|
|
|
if (errno != EAGAIN) {
|
|
|
|
fail1:
|
2004-03-03 17:41:21 +02:00
|
|
|
av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n");
|
2001-07-22 17:18:56 +03:00
|
|
|
} else {
|
2004-03-03 17:41:21 +02:00
|
|
|
av_log(s1, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n");
|
2001-07-22 17:18:56 +03:00
|
|
|
}
|
|
|
|
goto fail;
|
|
|
|
}
|
2005-12-22 03:10:11 +02:00
|
|
|
for (j = 1; j < s->gb_buffers.frames; j++) {
|
|
|
|
s->gb_buf.frame = j;
|
|
|
|
ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
|
|
|
|
}
|
2002-11-19 16:57:42 +02:00
|
|
|
s->frame_format = s->gb_buf.format;
|
2001-07-22 17:18:56 +03:00
|
|
|
s->use_mmap = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(s->frame_format) {
|
|
|
|
case VIDEO_PALETTE_YUV420P:
|
|
|
|
frame_size = (width * height * 3) / 2;
|
2005-07-18 01:24:36 +03:00
|
|
|
st->codec->pix_fmt = PIX_FMT_YUV420P;
|
2001-07-22 17:18:56 +03:00
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_YUV422:
|
|
|
|
frame_size = width * height * 2;
|
2005-07-18 01:24:36 +03:00
|
|
|
st->codec->pix_fmt = PIX_FMT_YUV422;
|
2001-07-22 17:18:56 +03:00
|
|
|
break;
|
|
|
|
case VIDEO_PALETTE_RGB24:
|
|
|
|
frame_size = width * height * 3;
|
2005-07-18 01:24:36 +03:00
|
|
|
st->codec->pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
|
2001-07-22 17:18:56 +03:00
|
|
|
break;
|
2006-09-15 14:17:41 +03:00
|
|
|
case VIDEO_PALETTE_GREY:
|
|
|
|
frame_size = width * height * 1;
|
|
|
|
st->codec->pix_fmt = PIX_FMT_GRAY8;
|
|
|
|
break;
|
2001-07-22 17:18:56 +03:00
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
s->fd = video_fd;
|
2001-09-25 02:27:06 +03:00
|
|
|
s->frame_size = frame_size;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2005-07-18 01:24:36 +03:00
|
|
|
st->codec->codec_type = CODEC_TYPE_VIDEO;
|
|
|
|
st->codec->codec_id = CODEC_ID_RAWVIDEO;
|
|
|
|
st->codec->width = width;
|
|
|
|
st->codec->height = height;
|
|
|
|
st->codec->time_base.den = frame_rate;
|
|
|
|
st->codec->time_base.num = frame_rate_base;
|
2005-10-13 01:35:06 +03:00
|
|
|
st->codec->bit_rate = frame_size * 1/av_q2d(st->codec->time_base) * 8;
|
2002-11-19 17:52:29 +02:00
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
return 0;
|
|
|
|
fail:
|
2001-09-25 02:27:06 +03:00
|
|
|
if (video_fd >= 0)
|
|
|
|
close(video_fd);
|
2002-05-19 02:11:09 +03:00
|
|
|
av_free(st);
|
2004-06-19 06:59:34 +03:00
|
|
|
return AVERROR_IO;
|
2001-07-22 17:18:56 +03:00
|
|
|
}
|
|
|
|
|
2003-02-11 18:35:48 +02:00
|
|
|
static int v4l_mm_read_picture(VideoData *s, uint8_t *buf)
|
2001-07-22 17:18:56 +03:00
|
|
|
{
|
2003-02-11 18:35:48 +02:00
|
|
|
uint8_t *ptr;
|
2001-07-22 17:18:56 +03:00
|
|
|
|
2004-04-25 16:30:21 +03:00
|
|
|
while (ioctl(s->fd, VIDIOCSYNC, &s->gb_frame) < 0 &&
|
|
|
|
(errno == EAGAIN || errno == EINTR));
|
|
|
|
|
|
|
|
ptr = s->video_buf + s->gb_buffers.offsets[s->gb_frame];
|
|
|
|
memcpy(buf, ptr, s->frame_size);
|
|
|
|
|
2002-04-08 23:58:56 +03:00
|
|
|
/* Setup to capture the next frame */
|
2004-04-25 16:30:21 +03:00
|
|
|
s->gb_buf.frame = s->gb_frame;
|
2002-11-19 16:57:42 +02:00
|
|
|
if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) {
|
2002-05-09 04:18:42 +03:00
|
|
|
if (errno == EAGAIN)
|
2004-03-03 17:41:21 +02:00
|
|
|
av_log(NULL, AV_LOG_ERROR, "Cannot Sync\n");
|
2002-05-09 04:18:42 +03:00
|
|
|
else
|
2001-07-22 17:18:56 +03:00
|
|
|
perror("VIDIOCMCAPTURE");
|
2004-06-19 06:59:34 +03:00
|
|
|
return AVERROR_IO;
|
2001-07-22 17:18:56 +03:00
|
|
|
}
|
2002-04-08 23:58:56 +03:00
|
|
|
|
|
|
|
/* This is now the grabbing frame */
|
2004-04-25 16:30:21 +03:00
|
|
|
s->gb_frame = (s->gb_frame + 1) % s->gb_buffers.frames;
|
2002-04-08 23:58:56 +03:00
|
|
|
|
2001-09-25 02:27:06 +03:00
|
|
|
return s->frame_size;
|
2001-07-22 17:18:56 +03:00
|
|
|
}
|
|
|
|
|
2001-09-25 02:27:06 +03:00
|
|
|
static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
|
2001-07-22 17:18:56 +03:00
|
|
|
{
|
2001-09-25 02:27:06 +03:00
|
|
|
VideoData *s = s1->priv_data;
|
2003-02-11 18:35:48 +02:00
|
|
|
int64_t curtime, delay;
|
2001-09-25 02:27:06 +03:00
|
|
|
struct timespec ts;
|
2002-04-08 23:58:56 +03:00
|
|
|
|
|
|
|
/* Calculate the time of the next frame */
|
2006-12-07 01:46:11 +02:00
|
|
|
s->time_frame += INT64_C(1000000);
|
2001-07-22 17:18:56 +03:00
|
|
|
|
|
|
|
/* wait based on the frame rate */
|
2002-11-19 17:52:29 +02:00
|
|
|
for(;;) {
|
2002-07-25 19:05:25 +03:00
|
|
|
curtime = av_gettime();
|
2004-04-27 16:28:16 +03:00
|
|
|
delay = s->time_frame * s->frame_rate_base / s->frame_rate - curtime;
|
2002-04-08 23:58:56 +03:00
|
|
|
if (delay <= 0) {
|
2006-12-07 01:46:11 +02:00
|
|
|
if (delay < INT64_C(-1000000) * s->frame_rate_base / s->frame_rate) {
|
2002-04-08 23:58:56 +03:00
|
|
|
/* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */
|
2006-12-07 01:46:11 +02:00
|
|
|
s->time_frame += INT64_C(1000000);
|
2002-04-08 23:58:56 +03:00
|
|
|
}
|
2001-09-25 02:27:06 +03:00
|
|
|
break;
|
2005-12-17 20:14:38 +02:00
|
|
|
}
|
2001-09-25 02:27:06 +03:00
|
|
|
ts.tv_sec = delay / 1000000;
|
|
|
|
ts.tv_nsec = (delay % 1000000) * 1000;
|
|
|
|
nanosleep(&ts, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (av_new_packet(pkt, s->frame_size) < 0)
|
2004-06-19 06:59:34 +03:00
|
|
|
return AVERROR_IO;
|
2001-07-22 17:18:56 +03:00
|
|
|
|
2006-02-01 13:31:33 +02:00
|
|
|
pkt->pts = curtime;
|
2002-11-19 17:52:29 +02:00
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
/* read one frame */
|
2002-11-19 16:57:42 +02:00
|
|
|
if (s->aiw_enabled) {
|
|
|
|
return aiw_read_picture(s, pkt->data);
|
|
|
|
} else if (s->use_mmap) {
|
2001-09-25 02:27:06 +03:00
|
|
|
return v4l_mm_read_picture(s, pkt->data);
|
2001-07-22 17:18:56 +03:00
|
|
|
} else {
|
2001-09-25 02:27:06 +03:00
|
|
|
if (read(s->fd, pkt->data, pkt->size) != pkt->size)
|
2004-06-19 06:59:34 +03:00
|
|
|
return AVERROR_IO;
|
2001-09-25 02:27:06 +03:00
|
|
|
return s->frame_size;
|
2001-07-22 17:18:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-25 02:27:06 +03:00
|
|
|
static int grab_read_close(AVFormatContext *s1)
|
2001-07-22 17:18:56 +03:00
|
|
|
{
|
2001-09-25 02:27:06 +03:00
|
|
|
VideoData *s = s1->priv_data;
|
2002-09-01 11:54:22 +03:00
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
if (s->aiw_enabled)
|
|
|
|
aiw_close(s);
|
|
|
|
|
2002-09-01 11:54:22 +03:00
|
|
|
if (s->use_mmap)
|
2002-11-19 16:57:42 +02:00
|
|
|
munmap(s->video_buf, s->gb_buffers.size);
|
2002-09-01 11:54:22 +03:00
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
/* mute audio. we must force it because the BTTV driver does not
|
|
|
|
return its state correctly */
|
|
|
|
s->audio_saved.flags |= VIDEO_AUDIO_MUTE;
|
|
|
|
ioctl(s->fd, VIDIOCSAUDIO, &s->audio_saved);
|
2001-09-17 00:49:48 +03:00
|
|
|
|
2001-07-22 17:18:56 +03:00
|
|
|
close(s->fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-11 00:14:37 +03:00
|
|
|
AVInputFormat video_grab_device_demuxer = {
|
2003-01-23 00:40:52 +02:00
|
|
|
"video4linux",
|
2001-09-25 02:27:06 +03:00
|
|
|
"video grab",
|
2002-05-20 19:31:13 +03:00
|
|
|
sizeof(VideoData),
|
2001-09-25 02:27:06 +03:00
|
|
|
NULL,
|
|
|
|
grab_read_header,
|
|
|
|
grab_read_packet,
|
|
|
|
grab_read_close,
|
2002-10-07 02:06:06 +03:00
|
|
|
.flags = AVFMT_NOFILE,
|
2001-07-22 17:18:56 +03:00
|
|
|
};
|
2002-05-20 19:31:13 +03:00
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
/* All in Wonder specific stuff */
|
|
|
|
/* XXX: remove and merge in libavcodec/imgconvert.c */
|
2002-10-21 00:45:38 +03:00
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
static int aiw_init(VideoData *s)
|
2002-10-21 00:45:38 +03:00
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
width = s->width;
|
|
|
|
height = s->height;
|
2002-10-21 00:45:38 +03:00
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
if ((width == s->video_cap.maxwidth && height == s->video_cap.maxheight) ||
|
|
|
|
(width == s->video_cap.maxwidth && height == s->video_cap.maxheight*2) ||
|
|
|
|
(width == s->video_cap.maxwidth/2 && height == s->video_cap.maxheight)) {
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
s->deint=0;
|
|
|
|
s->halfw=0;
|
|
|
|
if (height == s->video_cap.maxheight*2) s->deint=1;
|
|
|
|
if (width == s->video_cap.maxwidth/2) s->halfw=1;
|
2002-10-21 00:45:38 +03:00
|
|
|
} else {
|
2004-03-03 17:41:21 +02:00
|
|
|
av_log(NULL, AV_LOG_ERROR, "\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
|
|
|
|
av_log(NULL, AV_LOG_ERROR, " %dx%d %dx%d %dx%d\n\n",
|
2002-11-19 16:57:42 +02:00
|
|
|
s->video_cap.maxwidth,s->video_cap.maxheight,
|
|
|
|
s->video_cap.maxwidth,s->video_cap.maxheight*2,
|
|
|
|
s->video_cap.maxwidth/2,s->video_cap.maxheight);
|
2002-10-21 00:45:38 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->halfw == 0) {
|
|
|
|
s->src_mem = av_malloc(s->width*2);
|
|
|
|
} else {
|
|
|
|
s->src_mem = av_malloc(s->width*4);
|
|
|
|
}
|
|
|
|
if (!s->src_mem) goto fail;
|
|
|
|
|
|
|
|
s->lum_m4_mem = av_malloc(s->width);
|
2002-11-19 16:57:42 +02:00
|
|
|
if (!s->lum_m4_mem)
|
2002-10-21 00:45:38 +03:00
|
|
|
goto fail;
|
|
|
|
return 0;
|
|
|
|
fail:
|
2002-11-19 16:57:42 +02:00
|
|
|
av_freep(&s->src_mem);
|
|
|
|
av_freep(&s->lum_m4_mem);
|
|
|
|
return -1;
|
2002-10-21 00:45:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_MMX
|
2005-12-05 22:44:56 +02:00
|
|
|
#include "libavcodec/i386/mmx.h"
|
2002-10-21 00:45:38 +03:00
|
|
|
|
|
|
|
#define LINE_WITH_UV \
|
|
|
|
movq_m2r(ptr[0],mm0); \
|
|
|
|
movq_m2r(ptr[8],mm1); \
|
|
|
|
movq_r2r(mm0, mm4); \
|
|
|
|
punpcklbw_r2r(mm1,mm0); \
|
|
|
|
punpckhbw_r2r(mm1,mm4); \
|
|
|
|
movq_r2r(mm0,mm5); \
|
|
|
|
punpcklbw_r2r(mm4,mm0); \
|
|
|
|
punpckhbw_r2r(mm4,mm5); \
|
|
|
|
movq_r2r(mm0,mm1); \
|
|
|
|
punpcklbw_r2r(mm5,mm1); \
|
|
|
|
movq_r2m(mm1,lum[0]); \
|
|
|
|
movq_m2r(ptr[16],mm2); \
|
|
|
|
movq_m2r(ptr[24],mm1); \
|
|
|
|
movq_r2r(mm2,mm4); \
|
|
|
|
punpcklbw_r2r(mm1,mm2); \
|
|
|
|
punpckhbw_r2r(mm1,mm4); \
|
|
|
|
movq_r2r(mm2,mm3); \
|
|
|
|
punpcklbw_r2r(mm4,mm2); \
|
|
|
|
punpckhbw_r2r(mm4,mm3); \
|
|
|
|
movq_r2r(mm2,mm1); \
|
|
|
|
punpcklbw_r2r(mm3,mm1); \
|
|
|
|
movq_r2m(mm1,lum[8]); \
|
|
|
|
punpckhdq_r2r(mm2,mm0); \
|
|
|
|
punpckhdq_r2r(mm3,mm5); \
|
|
|
|
movq_r2m(mm0,cb[0]); \
|
|
|
|
movq_r2m(mm5,cr[0]);
|
|
|
|
|
|
|
|
#define LINE_NO_UV \
|
|
|
|
movq_m2r(ptr[0],mm0);\
|
|
|
|
movq_m2r(ptr[8],mm1);\
|
|
|
|
movq_r2r(mm0, mm4);\
|
|
|
|
punpcklbw_r2r(mm1,mm0); \
|
|
|
|
punpckhbw_r2r(mm1,mm4);\
|
|
|
|
movq_r2r(mm0,mm5);\
|
|
|
|
punpcklbw_r2r(mm4,mm0);\
|
|
|
|
punpckhbw_r2r(mm4,mm5);\
|
|
|
|
movq_r2r(mm0,mm1);\
|
|
|
|
punpcklbw_r2r(mm5,mm1);\
|
|
|
|
movq_r2m(mm1,lum[0]);\
|
|
|
|
movq_m2r(ptr[16],mm2);\
|
|
|
|
movq_m2r(ptr[24],mm1);\
|
|
|
|
movq_r2r(mm2,mm4);\
|
|
|
|
punpcklbw_r2r(mm1,mm2);\
|
|
|
|
punpckhbw_r2r(mm1,mm4);\
|
|
|
|
movq_r2r(mm2,mm3);\
|
|
|
|
punpcklbw_r2r(mm4,mm2);\
|
|
|
|
punpckhbw_r2r(mm4,mm3);\
|
|
|
|
movq_r2r(mm2,mm1);\
|
|
|
|
punpcklbw_r2r(mm3,mm1);\
|
|
|
|
movq_r2m(mm1,lum[8]);
|
|
|
|
|
|
|
|
#define LINE_WITHUV_AVG \
|
|
|
|
movq_m2r(ptr[0], mm0);\
|
|
|
|
movq_m2r(ptr[8], mm1);\
|
|
|
|
movq_r2r(mm0, mm4);\
|
|
|
|
punpcklbw_r2r(mm1,mm0);\
|
|
|
|
punpckhbw_r2r(mm1,mm4);\
|
|
|
|
movq_r2r(mm0,mm5);\
|
|
|
|
punpcklbw_r2r(mm4,mm0);\
|
|
|
|
punpckhbw_r2r(mm4,mm5);\
|
|
|
|
movq_r2r(mm0,mm1);\
|
|
|
|
movq_r2r(mm5,mm2);\
|
|
|
|
punpcklbw_r2r(mm7,mm1);\
|
|
|
|
punpcklbw_r2r(mm7,mm2);\
|
|
|
|
paddw_r2r(mm6,mm1);\
|
|
|
|
paddw_r2r(mm2,mm1);\
|
|
|
|
psraw_i2r(1,mm1);\
|
|
|
|
packuswb_r2r(mm7,mm1);\
|
|
|
|
movd_r2m(mm1,lum[0]);\
|
|
|
|
movq_m2r(ptr[16],mm2);\
|
|
|
|
movq_m2r(ptr[24],mm1);\
|
|
|
|
movq_r2r(mm2,mm4);\
|
|
|
|
punpcklbw_r2r(mm1,mm2);\
|
|
|
|
punpckhbw_r2r(mm1,mm4);\
|
|
|
|
movq_r2r(mm2,mm3);\
|
|
|
|
punpcklbw_r2r(mm4,mm2);\
|
|
|
|
punpckhbw_r2r(mm4,mm3);\
|
|
|
|
movq_r2r(mm2,mm1);\
|
|
|
|
movq_r2r(mm3,mm4);\
|
|
|
|
punpcklbw_r2r(mm7,mm1);\
|
|
|
|
punpcklbw_r2r(mm7,mm4);\
|
|
|
|
paddw_r2r(mm6,mm1);\
|
|
|
|
paddw_r2r(mm4,mm1);\
|
|
|
|
psraw_i2r(1,mm1);\
|
|
|
|
packuswb_r2r(mm7,mm1);\
|
|
|
|
movd_r2m(mm1,lum[4]);\
|
|
|
|
punpckhbw_r2r(mm7,mm0);\
|
|
|
|
punpckhbw_r2r(mm7,mm2);\
|
|
|
|
paddw_r2r(mm6,mm0);\
|
|
|
|
paddw_r2r(mm2,mm0);\
|
|
|
|
psraw_i2r(1,mm0);\
|
|
|
|
packuswb_r2r(mm7,mm0);\
|
|
|
|
punpckhbw_r2r(mm7,mm5);\
|
|
|
|
punpckhbw_r2r(mm7,mm3);\
|
|
|
|
paddw_r2r(mm6,mm5);\
|
|
|
|
paddw_r2r(mm3,mm5);\
|
|
|
|
psraw_i2r(1,mm5);\
|
|
|
|
packuswb_r2r(mm7,mm5);\
|
|
|
|
movd_r2m(mm0,cb[0]);\
|
|
|
|
movd_r2m(mm5,cr[0]);
|
|
|
|
|
|
|
|
#define LINE_NOUV_AVG \
|
|
|
|
movq_m2r(ptr[0],mm0);\
|
|
|
|
movq_m2r(ptr[8],mm1);\
|
|
|
|
pand_r2r(mm5,mm0);\
|
|
|
|
pand_r2r(mm5,mm1);\
|
|
|
|
pmaddwd_r2r(mm6,mm0);\
|
|
|
|
pmaddwd_r2r(mm6,mm1);\
|
|
|
|
packssdw_r2r(mm1,mm0);\
|
|
|
|
paddw_r2r(mm6,mm0);\
|
|
|
|
psraw_i2r(1,mm0);\
|
|
|
|
movq_m2r(ptr[16],mm2);\
|
|
|
|
movq_m2r(ptr[24],mm3);\
|
|
|
|
pand_r2r(mm5,mm2);\
|
|
|
|
pand_r2r(mm5,mm3);\
|
|
|
|
pmaddwd_r2r(mm6,mm2);\
|
|
|
|
pmaddwd_r2r(mm6,mm3);\
|
|
|
|
packssdw_r2r(mm3,mm2);\
|
|
|
|
paddw_r2r(mm6,mm2);\
|
|
|
|
psraw_i2r(1,mm2);\
|
|
|
|
packuswb_r2r(mm2,mm0);\
|
|
|
|
movq_r2m(mm0,lum[0]);
|
|
|
|
|
|
|
|
#define DEINT_LINE_LUM(ptroff) \
|
|
|
|
movd_m2r(lum_m4[(ptroff)],mm0);\
|
|
|
|
movd_m2r(lum_m3[(ptroff)],mm1);\
|
|
|
|
movd_m2r(lum_m2[(ptroff)],mm2);\
|
|
|
|
movd_m2r(lum_m1[(ptroff)],mm3);\
|
|
|
|
movd_m2r(lum[(ptroff)],mm4);\
|
|
|
|
punpcklbw_r2r(mm7,mm0);\
|
|
|
|
movd_r2m(mm2,lum_m4[(ptroff)]);\
|
|
|
|
punpcklbw_r2r(mm7,mm1);\
|
|
|
|
punpcklbw_r2r(mm7,mm2);\
|
|
|
|
punpcklbw_r2r(mm7,mm3);\
|
|
|
|
punpcklbw_r2r(mm7,mm4);\
|
|
|
|
psllw_i2r(2,mm1);\
|
|
|
|
psllw_i2r(1,mm2);\
|
|
|
|
paddw_r2r(mm6,mm1);\
|
|
|
|
psllw_i2r(2,mm3);\
|
|
|
|
paddw_r2r(mm2,mm1);\
|
|
|
|
paddw_r2r(mm4,mm0);\
|
|
|
|
paddw_r2r(mm3,mm1);\
|
|
|
|
psubusw_r2r(mm0,mm1);\
|
|
|
|
psrlw_i2r(3,mm1);\
|
|
|
|
packuswb_r2r(mm7,mm1);\
|
|
|
|
movd_r2m(mm1,lum_m2[(ptroff)]);
|
|
|
|
|
|
|
|
#else
|
2005-12-05 22:44:56 +02:00
|
|
|
#include "libavcodec/dsputil.h"
|
2002-10-21 00:45:38 +03:00
|
|
|
|
|
|
|
#define LINE_WITH_UV \
|
|
|
|
lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
|
|
|
|
cb[0]=ptr[1];cb[1]=ptr[5];\
|
|
|
|
cr[0]=ptr[3];cr[1]=ptr[7];\
|
|
|
|
lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
|
|
|
|
cb[2]=ptr[9];cb[3]=ptr[13];\
|
|
|
|
cr[2]=ptr[11];cr[3]=ptr[15];\
|
|
|
|
lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
|
|
|
|
cb[4]=ptr[17];cb[5]=ptr[21];\
|
|
|
|
cr[4]=ptr[19];cr[5]=ptr[23];\
|
|
|
|
lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];\
|
|
|
|
cb[6]=ptr[25];cb[7]=ptr[29];\
|
|
|
|
cr[6]=ptr[27];cr[7]=ptr[31];
|
|
|
|
|
|
|
|
#define LINE_NO_UV \
|
|
|
|
lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
|
|
|
|
lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
|
|
|
|
lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
|
|
|
|
lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];
|
|
|
|
|
|
|
|
#define LINE_WITHUV_AVG \
|
|
|
|
sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
|
|
|
|
sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
|
|
|
|
sum=(ptr[1]+ptr[5]+1) >> 1;cb[0]=sum; \
|
|
|
|
sum=(ptr[3]+ptr[7]+1) >> 1;cr[0]=sum; \
|
|
|
|
sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
|
|
|
|
sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
|
|
|
|
sum=(ptr[9]+ptr[13]+1) >> 1;cb[1]=sum; \
|
|
|
|
sum=(ptr[11]+ptr[15]+1) >> 1;cr[1]=sum; \
|
|
|
|
sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
|
|
|
|
sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
|
|
|
|
sum=(ptr[17]+ptr[21]+1) >> 1;cb[2]=sum; \
|
|
|
|
sum=(ptr[19]+ptr[23]+1) >> 1;cr[2]=sum; \
|
|
|
|
sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
|
|
|
|
sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum; \
|
|
|
|
sum=(ptr[25]+ptr[29]+1) >> 1;cb[3]=sum; \
|
2005-12-17 20:14:38 +02:00
|
|
|
sum=(ptr[27]+ptr[31]+1) >> 1;cr[3]=sum;
|
2002-10-21 00:45:38 +03:00
|
|
|
|
|
|
|
#define LINE_NOUV_AVG \
|
|
|
|
sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
|
|
|
|
sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
|
|
|
|
sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
|
|
|
|
sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
|
|
|
|
sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
|
|
|
|
sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
|
|
|
|
sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
|
2005-12-17 20:14:38 +02:00
|
|
|
sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum;
|
2002-10-21 00:45:38 +03:00
|
|
|
|
|
|
|
#define DEINT_LINE_LUM(ptroff) \
|
|
|
|
sum=(-lum_m4[(ptroff)]+(lum_m3[(ptroff)]<<2)+(lum_m2[(ptroff)]<<1)+(lum_m1[(ptroff)]<<2)-lum[(ptroff)]); \
|
|
|
|
lum_m4[(ptroff)]=lum_m2[(ptroff)];\
|
|
|
|
lum_m2[(ptroff)]=cm[(sum+4)>>3];\
|
|
|
|
sum=(-lum_m4[(ptroff)+1]+(lum_m3[(ptroff)+1]<<2)+(lum_m2[(ptroff)+1]<<1)+(lum_m1[(ptroff)+1]<<2)-lum[(ptroff)+1]); \
|
|
|
|
lum_m4[(ptroff)+1]=lum_m2[(ptroff)+1];\
|
|
|
|
lum_m2[(ptroff)+1]=cm[(sum+4)>>3];\
|
|
|
|
sum=(-lum_m4[(ptroff)+2]+(lum_m3[(ptroff)+2]<<2)+(lum_m2[(ptroff)+2]<<1)+(lum_m1[(ptroff)+2]<<2)-lum[(ptroff)+2]); \
|
|
|
|
lum_m4[(ptroff)+2]=lum_m2[(ptroff)+2];\
|
|
|
|
lum_m2[(ptroff)+2]=cm[(sum+4)>>3];\
|
|
|
|
sum=(-lum_m4[(ptroff)+3]+(lum_m3[(ptroff)+3]<<2)+(lum_m2[(ptroff)+3]<<1)+(lum_m1[(ptroff)+3]<<2)-lum[(ptroff)+3]); \
|
|
|
|
lum_m4[(ptroff)+3]=lum_m2[(ptroff)+3];\
|
|
|
|
lum_m2[(ptroff)+3]=cm[(sum+4)>>3];
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
/* Read two fields separately. */
|
|
|
|
static int aiw_read_picture(VideoData *s, uint8_t *data)
|
2002-10-21 00:45:38 +03:00
|
|
|
{
|
2003-02-11 18:35:48 +02:00
|
|
|
uint8_t *ptr, *lum, *cb, *cr;
|
2002-11-19 16:57:42 +02:00
|
|
|
int h;
|
2002-10-21 00:45:38 +03:00
|
|
|
#ifndef HAVE_MMX
|
2002-11-19 16:57:42 +02:00
|
|
|
int sum;
|
2002-10-21 00:45:38 +03:00
|
|
|
#endif
|
2003-02-11 18:35:48 +02:00
|
|
|
uint8_t* src = s->src_mem;
|
|
|
|
uint8_t *ptrend = &src[s->width*2];
|
2002-11-19 16:57:42 +02:00
|
|
|
lum=data;
|
|
|
|
cb=&lum[s->width*s->height];
|
|
|
|
cr=&cb[(s->width*s->height)/4];
|
|
|
|
if (s->deint == 0 && s->halfw == 0) {
|
|
|
|
while (read(s->fd,src,s->width*2) < 0) {
|
|
|
|
usleep(100);
|
|
|
|
}
|
|
|
|
for (h = 0; h < s->height-2; h+=2) {
|
2002-10-21 00:45:38 +03:00
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
|
|
|
|
LINE_WITH_UV
|
2002-11-19 16:57:42 +02:00
|
|
|
}
|
2002-10-21 00:45:38 +03:00
|
|
|
read(s->fd,src,s->width*2);
|
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
|
|
|
|
LINE_NO_UV
|
2002-11-19 16:57:42 +02:00
|
|
|
}
|
|
|
|
read(s->fd,src,s->width*2);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Do last two lines
|
|
|
|
*/
|
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
|
|
|
|
LINE_WITH_UV
|
2002-10-21 00:45:38 +03:00
|
|
|
}
|
2002-11-19 16:57:42 +02:00
|
|
|
read(s->fd,src,s->width*2);
|
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
|
|
|
|
LINE_NO_UV
|
|
|
|
}
|
|
|
|
/* drop second field */
|
|
|
|
while (read(s->fd,src,s->width*2) < 0) {
|
|
|
|
usleep(100);
|
|
|
|
}
|
|
|
|
for (h = 0; h < s->height - 1; h++) {
|
|
|
|
read(s->fd,src,s->width*2);
|
|
|
|
}
|
|
|
|
} else if (s->halfw == 1) {
|
2002-10-21 00:45:38 +03:00
|
|
|
#ifdef HAVE_MMX
|
2002-11-19 16:57:42 +02:00
|
|
|
mmx_t rounder;
|
|
|
|
mmx_t masker;
|
|
|
|
rounder.uw[0]=1;
|
|
|
|
rounder.uw[1]=1;
|
|
|
|
rounder.uw[2]=1;
|
|
|
|
rounder.uw[3]=1;
|
|
|
|
masker.ub[0]=0xff;
|
|
|
|
masker.ub[1]=0;
|
|
|
|
masker.ub[2]=0xff;
|
|
|
|
masker.ub[3]=0;
|
|
|
|
masker.ub[4]=0xff;
|
|
|
|
masker.ub[5]=0;
|
|
|
|
masker.ub[6]=0xff;
|
|
|
|
masker.ub[7]=0;
|
|
|
|
pxor_r2r(mm7,mm7);
|
|
|
|
movq_m2r(rounder,mm6);
|
2002-10-21 00:45:38 +03:00
|
|
|
#endif
|
2002-11-19 16:57:42 +02:00
|
|
|
while (read(s->fd,src,s->width*4) < 0) {
|
|
|
|
usleep(100);
|
|
|
|
}
|
|
|
|
ptrend = &src[s->width*4];
|
|
|
|
for (h = 0; h < s->height-2; h+=2) {
|
2002-10-21 00:45:38 +03:00
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
|
|
|
|
LINE_WITHUV_AVG
|
2002-11-19 16:57:42 +02:00
|
|
|
}
|
2002-10-21 00:45:38 +03:00
|
|
|
read(s->fd,src,s->width*4);
|
|
|
|
#ifdef HAVE_MMX
|
|
|
|
movq_m2r(masker,mm5);
|
|
|
|
#endif
|
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
|
|
|
|
LINE_NOUV_AVG
|
2002-11-19 16:57:42 +02:00
|
|
|
}
|
|
|
|
read(s->fd,src,s->width*4);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Do last two lines
|
|
|
|
*/
|
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
|
|
|
|
LINE_WITHUV_AVG
|
|
|
|
}
|
|
|
|
read(s->fd,src,s->width*4);
|
|
|
|
#ifdef HAVE_MMX
|
|
|
|
movq_m2r(masker,mm5);
|
|
|
|
#endif
|
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
|
|
|
|
LINE_NOUV_AVG
|
|
|
|
}
|
|
|
|
/* drop second field */
|
|
|
|
while (read(s->fd,src,s->width*4) < 0) {
|
|
|
|
usleep(100);
|
|
|
|
}
|
|
|
|
for (h = 0; h < s->height - 1; h++) {
|
|
|
|
read(s->fd,src,s->width*4);
|
|
|
|
}
|
|
|
|
} else {
|
2003-02-11 18:35:48 +02:00
|
|
|
uint8_t *lum_m1, *lum_m2, *lum_m3, *lum_m4;
|
2002-10-21 00:45:38 +03:00
|
|
|
#ifdef HAVE_MMX
|
2002-11-19 16:57:42 +02:00
|
|
|
mmx_t rounder;
|
|
|
|
rounder.uw[0]=4;
|
|
|
|
rounder.uw[1]=4;
|
|
|
|
rounder.uw[2]=4;
|
|
|
|
rounder.uw[3]=4;
|
|
|
|
movq_m2r(rounder,mm6);
|
|
|
|
pxor_r2r(mm7,mm7);
|
2002-10-21 00:45:38 +03:00
|
|
|
#else
|
2006-11-12 22:08:09 +02:00
|
|
|
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
|
2002-10-21 00:45:38 +03:00
|
|
|
#endif
|
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
/* read two fields and deinterlace them */
|
|
|
|
while (read(s->fd,src,s->width*2) < 0) {
|
|
|
|
usleep(100);
|
|
|
|
}
|
|
|
|
for (h = 0; h < (s->height/2)-2; h+=2) {
|
2002-10-21 00:45:38 +03:00
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
|
|
|
|
LINE_WITH_UV
|
2002-11-19 16:57:42 +02:00
|
|
|
}
|
2002-10-21 00:45:38 +03:00
|
|
|
read(s->fd,src,s->width*2);
|
2002-11-19 16:57:42 +02:00
|
|
|
/* skip a luminance line - will be filled in later */
|
|
|
|
lum += s->width;
|
2002-10-21 00:45:38 +03:00
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
|
|
|
|
LINE_WITH_UV
|
2002-11-19 16:57:42 +02:00
|
|
|
}
|
|
|
|
/* skip a luminance line - will be filled in later */
|
|
|
|
lum += s->width;
|
|
|
|
read(s->fd,src,s->width*2);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Do last two lines
|
|
|
|
*/
|
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
|
|
|
|
LINE_WITH_UV
|
|
|
|
}
|
|
|
|
/* skip a luminance line - will be filled in later */
|
|
|
|
lum += s->width;
|
|
|
|
read(s->fd,src,s->width*2);
|
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
|
|
|
|
LINE_WITH_UV
|
|
|
|
}
|
|
|
|
/*
|
2002-10-21 00:45:38 +03:00
|
|
|
*
|
|
|
|
* SECOND FIELD
|
|
|
|
*
|
|
|
|
*/
|
2002-11-19 16:57:42 +02:00
|
|
|
lum=&data[s->width];
|
|
|
|
while (read(s->fd,src,s->width*2) < 0) {
|
|
|
|
usleep(10);
|
|
|
|
}
|
|
|
|
/* First (and last) two lines not interlaced */
|
|
|
|
for (h = 0; h < 2; h++) {
|
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
|
|
|
|
LINE_NO_UV
|
|
|
|
}
|
|
|
|
read(s->fd,src,s->width*2);
|
|
|
|
/* skip a luminance line */
|
|
|
|
lum += s->width;
|
|
|
|
}
|
|
|
|
lum_m1=&lum[-s->width];
|
|
|
|
lum_m2=&lum_m1[-s->width];
|
|
|
|
lum_m3=&lum_m2[-s->width];
|
|
|
|
memmove(s->lum_m4_mem,&lum_m3[-s->width],s->width);
|
|
|
|
for (; h < (s->height/2)-1; h++) {
|
|
|
|
lum_m4=s->lum_m4_mem;
|
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16,lum_m1+=16,lum_m2+=16,lum_m3+=16,lum_m4+=16) {
|
|
|
|
LINE_NO_UV
|
2002-10-21 00:45:38 +03:00
|
|
|
|
|
|
|
DEINT_LINE_LUM(0)
|
|
|
|
DEINT_LINE_LUM(4)
|
|
|
|
DEINT_LINE_LUM(8)
|
|
|
|
DEINT_LINE_LUM(12)
|
2002-11-19 16:57:42 +02:00
|
|
|
}
|
|
|
|
read(s->fd,src,s->width*2);
|
|
|
|
/* skip a luminance line */
|
|
|
|
lum += s->width;
|
|
|
|
lum_m1 += s->width;
|
|
|
|
lum_m2 += s->width;
|
|
|
|
lum_m3 += s->width;
|
|
|
|
// lum_m4 += s->width;
|
|
|
|
}
|
|
|
|
/*
|
2002-10-21 00:45:38 +03:00
|
|
|
* Do last line
|
|
|
|
*/
|
2002-11-19 16:57:42 +02:00
|
|
|
lum_m4=s->lum_m4_mem;
|
|
|
|
for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, lum_m1+=16, lum_m2+=16, lum_m3+=16, lum_m4+=16) {
|
|
|
|
LINE_NO_UV
|
2002-10-21 00:45:38 +03:00
|
|
|
|
|
|
|
DEINT_LINE_LUM(0)
|
|
|
|
DEINT_LINE_LUM(4)
|
|
|
|
DEINT_LINE_LUM(8)
|
|
|
|
DEINT_LINE_LUM(12)
|
2002-11-19 16:57:42 +02:00
|
|
|
}
|
|
|
|
}
|
2002-10-21 00:45:38 +03:00
|
|
|
#ifdef HAVE_MMX
|
2002-11-19 16:57:42 +02:00
|
|
|
emms();
|
2002-10-21 00:45:38 +03:00
|
|
|
#endif
|
|
|
|
return s->frame_size;
|
|
|
|
}
|
|
|
|
|
2002-11-19 16:57:42 +02:00
|
|
|
static int aiw_close(VideoData *s)
|
2002-10-21 00:45:38 +03:00
|
|
|
{
|
2002-11-19 16:57:42 +02:00
|
|
|
av_freep(&s->lum_m4_mem);
|
|
|
|
av_freep(&s->src_mem);
|
2002-10-21 00:45:38 +03:00
|
|
|
return 0;
|
|
|
|
}
|