annotate grab.c @ 2100:33a90cc1a5de libavformat

fix "incorrect frame size" errors with small.nuv
author michael
date Sun, 27 May 2007 08:06:45 +0000
parents fa4066708500
children 861cfbc6297a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * Linux video grab interface
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000,2001 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1316
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1316
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1316
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1316
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1316
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1316
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include <unistd.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include <fcntl.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include <sys/ioctl.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 #include <sys/mman.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 #include <sys/time.h>
236
ee98d63dbba7 kernel header bug workaround by (Ronald Bultje <rbultje at ronald dot bitfreak dot net>)
michaelni
parents: 159
diff changeset
27 #define _LINUX_TIME_H 1
ee98d63dbba7 kernel header bug workaround by (Ronald Bultje <rbultje at ronald dot bitfreak dot net>)
michaelni
parents: 159
diff changeset
28 #include <linux/videodev.h>
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 #include <time.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 int fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 int frame_format; /* see VIDEO_PALETTE_xxx */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 int use_mmap;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 int width, height;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 int frame_rate;
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
37 int frame_rate_base;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 30
diff changeset
38 int64_t time_frame;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 int frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 struct video_capability video_cap;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 struct video_audio audio_saved;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 30
diff changeset
42 uint8_t *video_buf;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 struct video_mbuf gb_buffers;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 struct video_mmap gb_buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 int gb_frame;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 /* ATI All In Wonder specific stuff */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 /* XXX: remove and merge in libavcodec/imgconvert.c */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 int aiw_enabled;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 int deint;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 int halfw;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 30
diff changeset
52 uint8_t *src_mem;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 30
diff changeset
53 uint8_t *lum_m4_mem;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 } VideoData;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 static int aiw_init(VideoData *s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 static int aiw_read_picture(VideoData *s, uint8_t *data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 static int aiw_close(VideoData *s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 VideoData *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 int width, height;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 int video_fd, frame_size;
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
66 int ret, frame_rate, frame_rate_base;
1137
246df8e6aab7 Properly set the image depth
lucabe
parents: 1068
diff changeset
67 int desired_palette, desired_depth;
159
7d698c3213a0 tv standard selection support for dv1394 and grab (v4l)
al3x
parents: 85
diff changeset
68 struct video_tuner tuner;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 struct video_audio audio;
1068
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
70 struct video_picture pict;
451
31784bdb76ee ring buffer fix by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 370
diff changeset
71 int j;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72
1012
9a88a1f43ea9 Tell the user why video capture is failing
lucabe
parents: 1003
diff changeset
73 if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
9a88a1f43ea9 Tell the user why video capture is failing
lucabe
parents: 1003
diff changeset
74 av_log(s1, AV_LOG_ERROR, "Bad capture size (%dx%d) or wrong time base (%d)\n",
9a88a1f43ea9 Tell the user why video capture is failing
lucabe
parents: 1003
diff changeset
75 ap->width, ap->height, ap->time_base.den);
9a88a1f43ea9 Tell the user why video capture is failing
lucabe
parents: 1003
diff changeset
76
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 return -1;
1012
9a88a1f43ea9 Tell the user why video capture is failing
lucabe
parents: 1003
diff changeset
78 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
79
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 width = ap->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 height = ap->height;
743
af4e24d6310c switch to native time bases
michael
parents: 639
diff changeset
82 frame_rate = ap->time_base.den;
af4e24d6310c switch to native time bases
michael
parents: 639
diff changeset
83 frame_rate_base = ap->time_base.num;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84
1012
9a88a1f43ea9 Tell the user why video capture is failing
lucabe
parents: 1003
diff changeset
85 if((unsigned)width > 32767 || (unsigned)height > 32767) {
9a88a1f43ea9 Tell the user why video capture is failing
lucabe
parents: 1003
diff changeset
86 av_log(s1, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n",
9a88a1f43ea9 Tell the user why video capture is failing
lucabe
parents: 1003
diff changeset
87 width, height);
9a88a1f43ea9 Tell the user why video capture is failing
lucabe
parents: 1003
diff changeset
88
639
0b52743104ac integer overflows, heap corruption
michael
parents: 482
diff changeset
89 return -1;
1012
9a88a1f43ea9 Tell the user why video capture is failing
lucabe
parents: 1003
diff changeset
90 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
91
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 st = av_new_stream(s1, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 if (!st)
1787
eb16c64144ee This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents: 1760
diff changeset
94 return AVERROR(ENOMEM);
921
547675092e98 video4linux2 input support
diego
parents: 896
diff changeset
95 av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 s->width = width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 s->height = height;
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
99 s->frame_rate = frame_rate;
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
100 s->frame_rate_base = frame_rate_base;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101
1795
62792a60f740 implement new grabbing interface, as described here:
gpoirier
parents: 1787
diff changeset
102 video_fd = open(s1->filename, O_RDWR);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 if (video_fd < 0) {
1795
62792a60f740 implement new grabbing interface, as described here:
gpoirier
parents: 1787
diff changeset
104 perror(s1->filename);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
107
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 perror("VIDIOCGCAP");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
114 av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 desired_palette = -1;
1137
246df8e6aab7 Properly set the image depth
lucabe
parents: 1068
diff changeset
119 desired_depth = -1;
246df8e6aab7 Properly set the image depth
lucabe
parents: 1068
diff changeset
120 if (ap->pix_fmt == PIX_FMT_YUV420P) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 desired_palette = VIDEO_PALETTE_YUV420P;
1137
246df8e6aab7 Properly set the image depth
lucabe
parents: 1068
diff changeset
122 desired_depth = 12;
1760
8cba5672faa4 Replace deprecated PIX_FMT names by the newer variants.
diego
parents: 1669
diff changeset
123 } else if (ap->pix_fmt == PIX_FMT_YUYV422) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 desired_palette = VIDEO_PALETTE_YUV422;
1137
246df8e6aab7 Properly set the image depth
lucabe
parents: 1068
diff changeset
125 desired_depth = 16;
246df8e6aab7 Properly set the image depth
lucabe
parents: 1068
diff changeset
126 } else if (ap->pix_fmt == PIX_FMT_BGR24) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 desired_palette = VIDEO_PALETTE_RGB24;
1137
246df8e6aab7 Properly set the image depth
lucabe
parents: 1068
diff changeset
128 desired_depth = 24;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
129 }
159
7d698c3213a0 tv standard selection support for dv1394 and grab (v4l)
al3x
parents: 85
diff changeset
130
7d698c3213a0 tv standard selection support for dv1394 and grab (v4l)
al3x
parents: 85
diff changeset
131 /* set tv standard */
7d698c3213a0 tv standard selection support for dv1394 and grab (v4l)
al3x
parents: 85
diff changeset
132 if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
133 if (!strcasecmp(ap->standard, "pal"))
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
134 tuner.mode = VIDEO_MODE_PAL;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
135 else if (!strcasecmp(ap->standard, "secam"))
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
136 tuner.mode = VIDEO_MODE_SECAM;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
137 else
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
138 tuner.mode = VIDEO_MODE_NTSC;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
139 ioctl(video_fd, VIDIOCSTUNER, &tuner);
159
7d698c3213a0 tv standard selection support for dv1394 and grab (v4l)
al3x
parents: 85
diff changeset
140 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
141
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 /* unmute audio */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 audio.audio = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 ioctl(video_fd, VIDIOCGAUDIO, &audio);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 memcpy(&s->audio_saved, &audio, sizeof(audio));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 audio.flags &= ~VIDEO_AUDIO_MUTE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 ioctl(video_fd, VIDIOCSAUDIO, &audio);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148
1068
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
149 ioctl(video_fd, VIDIOCGPICT, &pict);
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
150 #if 0
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
151 printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
152 pict.colour,
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
153 pict.hue,
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
154 pict.brightness,
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
155 pict.contrast,
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
156 pict.whiteness);
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
157 #endif
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
158 /* try to choose a suitable video format */
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
159 pict.palette = desired_palette;
1137
246df8e6aab7 Properly set the image depth
lucabe
parents: 1068
diff changeset
160 pict.depth= desired_depth;
1068
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
161 if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
162 pict.palette=VIDEO_PALETTE_YUV420P;
1137
246df8e6aab7 Properly set the image depth
lucabe
parents: 1068
diff changeset
163 pict.depth=12;
1068
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
164 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
165 if (ret < 0) {
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
166 pict.palette=VIDEO_PALETTE_YUV422;
1137
246df8e6aab7 Properly set the image depth
lucabe
parents: 1068
diff changeset
167 pict.depth=16;
1068
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
168 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
169 if (ret < 0) {
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
170 pict.palette=VIDEO_PALETTE_RGB24;
1137
246df8e6aab7 Properly set the image depth
lucabe
parents: 1068
diff changeset
171 pict.depth=24;
1068
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
172 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
1669
30b51285b882 omg, major typo (fails if card supports rgb24)
alex
parents: 1604
diff changeset
173 if (ret < 0) {
1316
d584d375f928 Add support for 8-bit grayscale to V4L grabber
gpoirier
parents: 1169
diff changeset
174 pict.palette=VIDEO_PALETTE_GREY;
d584d375f928 Add support for 8-bit grayscale to V4L grabber
gpoirier
parents: 1169
diff changeset
175 pict.depth=8;
d584d375f928 Add support for 8-bit grayscale to V4L grabber
gpoirier
parents: 1169
diff changeset
176 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
d584d375f928 Add support for 8-bit grayscale to V4L grabber
gpoirier
parents: 1169
diff changeset
177 if (ret < 0)
d584d375f928 Add support for 8-bit grayscale to V4L grabber
gpoirier
parents: 1169
diff changeset
178 goto fail1;
1669
30b51285b882 omg, major typo (fails if card supports rgb24)
alex
parents: 1604
diff changeset
179 }
1068
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
180 }
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
181 }
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
182 }
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
183
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 if (ret < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 /* try to use read based access */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 struct video_window win;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 int val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 win.x = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 win.y = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 win.width = width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 win.height = height;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 win.chromakey = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 win.flags = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 ioctl(video_fd, VIDIOCSWIN, &win);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 s->frame_format = pict.palette;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 val = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 ioctl(video_fd, VIDIOCCAPTURE, &val);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203
455
e5174af0f52f fix rounding errors with NTSC patch by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 451
diff changeset
204 s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 s->use_mmap = 0;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
206
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 /* ATI All In Wonder automatic activation */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 if (!strcmp(s->video_cap.name, "Km")) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 if (aiw_init(s) < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 s->aiw_enabled = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 /* force 420P format because convertion from YUV422 to YUV420P
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 is done in this driver (ugly) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 s->frame_format = VIDEO_PALETTE_YUV420P;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 if ((unsigned char*)-1 == s->video_buf) {
1604
ec546897df3d fall back mmap() call using MAP_PRIVATE for working on no-mmu systems
aurel
parents: 1556
diff changeset
219 s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_PRIVATE,video_fd,0);
ec546897df3d fall back mmap() call using MAP_PRIVATE for working on no-mmu systems
aurel
parents: 1556
diff changeset
220 if ((unsigned char*)-1 == s->video_buf) {
ec546897df3d fall back mmap() call using MAP_PRIVATE for working on no-mmu systems
aurel
parents: 1556
diff changeset
221 perror("mmap");
ec546897df3d fall back mmap() call using MAP_PRIVATE for working on no-mmu systems
aurel
parents: 1556
diff changeset
222 goto fail;
ec546897df3d fall back mmap() call using MAP_PRIVATE for working on no-mmu systems
aurel
parents: 1556
diff changeset
223 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 s->gb_frame = 0;
455
e5174af0f52f fix rounding errors with NTSC patch by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 451
diff changeset
226 s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
227
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 /* start to grab the first frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 s->gb_buf.height = height;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 s->gb_buf.width = width;
1068
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
232 s->gb_buf.format = pict.palette;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
233
1068
b14b8b976bce Fix v4l grabbing with some webcams, and simplify the code.
lucabe
parents: 1012
diff changeset
234 ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 if (ret < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 if (errno != EAGAIN) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 fail1:
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 236
diff changeset
238 av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 } else {
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 236
diff changeset
240 av_log(s1, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 }
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
244 for (j = 1; j < s->gb_buffers.frames; j++) {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
245 s->gb_buf.frame = j;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
246 ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
247 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 s->frame_format = s->gb_buf.format;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 s->use_mmap = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 switch(s->frame_format) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 case VIDEO_PALETTE_YUV420P:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 frame_size = (width * height * 3) / 2;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
255 st->codec->pix_fmt = PIX_FMT_YUV420P;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 case VIDEO_PALETTE_YUV422:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 frame_size = width * height * 2;
1760
8cba5672faa4 Replace deprecated PIX_FMT names by the newer variants.
diego
parents: 1669
diff changeset
259 st->codec->pix_fmt = PIX_FMT_YUYV422;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 case VIDEO_PALETTE_RGB24:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 frame_size = width * height * 3;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
263 st->codec->pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 break;
1316
d584d375f928 Add support for 8-bit grayscale to V4L grabber
gpoirier
parents: 1169
diff changeset
265 case VIDEO_PALETTE_GREY:
d584d375f928 Add support for 8-bit grayscale to V4L grabber
gpoirier
parents: 1169
diff changeset
266 frame_size = width * height * 1;
d584d375f928 Add support for 8-bit grayscale to V4L grabber
gpoirier
parents: 1169
diff changeset
267 st->codec->pix_fmt = PIX_FMT_GRAY8;
d584d375f928 Add support for 8-bit grayscale to V4L grabber
gpoirier
parents: 1169
diff changeset
268 break;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 s->fd = video_fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 s->frame_size = frame_size;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
274
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
275 st->codec->codec_type = CODEC_TYPE_VIDEO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
276 st->codec->codec_id = CODEC_ID_RAWVIDEO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
277 st->codec->width = width;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
278 st->codec->height = height;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
279 st->codec->time_base.den = frame_rate;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
280 st->codec->time_base.num = frame_rate_base;
861
728a86721270 lame bit_rate calculation
alex
parents: 820
diff changeset
281 st->codec->bit_rate = frame_size * 1/av_q2d(st->codec->time_base) * 8;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 if (video_fd >= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 close(video_fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 av_free(st);
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
288 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 30
diff changeset
291 static int v4l_mm_read_picture(VideoData *s, uint8_t *buf)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 30
diff changeset
293 uint8_t *ptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294
451
31784bdb76ee ring buffer fix by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 370
diff changeset
295 while (ioctl(s->fd, VIDIOCSYNC, &s->gb_frame) < 0 &&
31784bdb76ee ring buffer fix by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 370
diff changeset
296 (errno == EAGAIN || errno == EINTR));
31784bdb76ee ring buffer fix by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 370
diff changeset
297
31784bdb76ee ring buffer fix by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 370
diff changeset
298 ptr = s->video_buf + s->gb_buffers.offsets[s->gb_frame];
31784bdb76ee ring buffer fix by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 370
diff changeset
299 memcpy(buf, ptr, s->frame_size);
31784bdb76ee ring buffer fix by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 370
diff changeset
300
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 /* Setup to capture the next frame */
451
31784bdb76ee ring buffer fix by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 370
diff changeset
302 s->gb_buf.frame = s->gb_frame;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 if (errno == EAGAIN)
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 236
diff changeset
305 av_log(NULL, AV_LOG_ERROR, "Cannot Sync\n");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 perror("VIDIOCMCAPTURE");
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
308 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 /* This is now the grabbing frame */
451
31784bdb76ee ring buffer fix by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 370
diff changeset
312 s->gb_frame = (s->gb_frame + 1) % s->gb_buffers.frames;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 return s->frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 VideoData *s = s1->priv_data;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 30
diff changeset
320 int64_t curtime, delay;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 struct timespec ts;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 /* Calculate the time of the next frame */
1556
65b7b3ff4ed7 use the standard INT64_C() macro for 64-bit constants
mru
parents: 1491
diff changeset
324 s->time_frame += INT64_C(1000000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 /* wait based on the frame rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 curtime = av_gettime();
455
e5174af0f52f fix rounding errors with NTSC patch by (Luca Abeni <lucabe72 at email dot it>)
michael
parents: 451
diff changeset
329 delay = s->time_frame * s->frame_rate_base / s->frame_rate - curtime;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 if (delay <= 0) {
1556
65b7b3ff4ed7 use the standard INT64_C() macro for 64-bit constants
mru
parents: 1491
diff changeset
331 if (delay < INT64_C(-1000000) * s->frame_rate_base / s->frame_rate) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */
1556
65b7b3ff4ed7 use the standard INT64_C() macro for 64-bit constants
mru
parents: 1491
diff changeset
333 s->time_frame += INT64_C(1000000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 break;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
336 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 ts.tv_sec = delay / 1000000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 ts.tv_nsec = (delay % 1000000) * 1000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 nanosleep(&ts, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 if (av_new_packet(pkt, s->frame_size) < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
343 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344
921
547675092e98 video4linux2 input support
diego
parents: 896
diff changeset
345 pkt->pts = curtime;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 /* read one frame */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 if (s->aiw_enabled) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 return aiw_read_picture(s, pkt->data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 } else if (s->use_mmap) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 return v4l_mm_read_picture(s, pkt->data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 if (read(s->fd, pkt->data, pkt->size) != pkt->size)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
354 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 return s->frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 static int grab_read_close(AVFormatContext *s1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 VideoData *s = s1->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 if (s->aiw_enabled)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 aiw_close(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 if (s->use_mmap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 munmap(s->video_buf, s->gb_buffers.size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 /* mute audio. we must force it because the BTTV driver does not
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 return its state correctly */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 s->audio_saved.flags |= VIDEO_AUDIO_MUTE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 ioctl(s->fd, VIDIOCSAUDIO, &s->audio_saved);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 close(s->fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377
1982
1805da944f22 There were two files, libavformat/grab.c and libavformat/grab_bktr.c declaring
diego
parents: 1795
diff changeset
378 AVInputFormat video_grab_v4l_demuxer = {
27
fcdea3df94fe dv patch by Max Krasnyansky (maxk at qualcomm dot com)
bellard
parents: 0
diff changeset
379 "video4linux",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 "video grab",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 sizeof(VideoData),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 grab_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 grab_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 grab_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 .flags = AVFMT_NOFILE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 /* All in Wonder specific stuff */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390 /* XXX: remove and merge in libavcodec/imgconvert.c */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 static int aiw_init(VideoData *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 int width, height;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 width = s->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 height = s->height;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 if ((width == s->video_cap.maxwidth && height == s->video_cap.maxheight) ||
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 (width == s->video_cap.maxwidth && height == s->video_cap.maxheight*2) ||
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 (width == s->video_cap.maxwidth/2 && height == s->video_cap.maxheight)) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
402
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 s->deint=0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 s->halfw=0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 if (height == s->video_cap.maxheight*2) s->deint=1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 if (width == s->video_cap.maxwidth/2) s->halfw=1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 } else {
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 236
diff changeset
408 av_log(NULL, AV_LOG_ERROR, "\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 236
diff changeset
409 av_log(NULL, AV_LOG_ERROR, " %dx%d %dx%d %dx%d\n\n",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 s->video_cap.maxwidth,s->video_cap.maxheight,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 s->video_cap.maxwidth,s->video_cap.maxheight*2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 s->video_cap.maxwidth/2,s->video_cap.maxheight);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 if (s->halfw == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 s->src_mem = av_malloc(s->width*2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 s->src_mem = av_malloc(s->width*4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 if (!s->src_mem) goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 s->lum_m4_mem = av_malloc(s->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 if (!s->lum_m4_mem)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 av_freep(&s->src_mem);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 av_freep(&s->lum_m4_mem);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 #ifdef HAVE_MMX
2087
fa4066708500 Drop unnecessary libavcodec/ prefix in #include path.
diego
parents: 1982
diff changeset
434 #include "i386/mmx.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 #define LINE_WITH_UV \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 movq_m2r(ptr[0],mm0); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 movq_m2r(ptr[8],mm1); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 movq_r2r(mm0, mm4); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 punpcklbw_r2r(mm1,mm0); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 punpckhbw_r2r(mm1,mm4); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 movq_r2r(mm0,mm5); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 punpcklbw_r2r(mm4,mm0); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 punpckhbw_r2r(mm4,mm5); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 movq_r2r(mm0,mm1); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 punpcklbw_r2r(mm5,mm1); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 movq_r2m(mm1,lum[0]); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 movq_m2r(ptr[16],mm2); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 movq_m2r(ptr[24],mm1); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 movq_r2r(mm2,mm4); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 punpcklbw_r2r(mm1,mm2); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 punpckhbw_r2r(mm1,mm4); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 movq_r2r(mm2,mm3); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 punpcklbw_r2r(mm4,mm2); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 punpckhbw_r2r(mm4,mm3); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 movq_r2r(mm2,mm1); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 punpcklbw_r2r(mm3,mm1); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 movq_r2m(mm1,lum[8]); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 punpckhdq_r2r(mm2,mm0); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 punpckhdq_r2r(mm3,mm5); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 movq_r2m(mm0,cb[0]); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 movq_r2m(mm5,cr[0]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 #define LINE_NO_UV \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 movq_m2r(ptr[0],mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 movq_m2r(ptr[8],mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 movq_r2r(mm0, mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 punpcklbw_r2r(mm1,mm0); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 punpckhbw_r2r(mm1,mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 movq_r2r(mm0,mm5);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 punpcklbw_r2r(mm4,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 punpckhbw_r2r(mm4,mm5);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 movq_r2r(mm0,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 punpcklbw_r2r(mm5,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 movq_r2m(mm1,lum[0]);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 movq_m2r(ptr[16],mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 movq_m2r(ptr[24],mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 movq_r2r(mm2,mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479 punpcklbw_r2r(mm1,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480 punpckhbw_r2r(mm1,mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 movq_r2r(mm2,mm3);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 punpcklbw_r2r(mm4,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 punpckhbw_r2r(mm4,mm3);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484 movq_r2r(mm2,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 punpcklbw_r2r(mm3,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486 movq_r2m(mm1,lum[8]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 #define LINE_WITHUV_AVG \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 movq_m2r(ptr[0], mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 movq_m2r(ptr[8], mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 movq_r2r(mm0, mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 punpcklbw_r2r(mm1,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 punpckhbw_r2r(mm1,mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 movq_r2r(mm0,mm5);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 punpcklbw_r2r(mm4,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 punpckhbw_r2r(mm4,mm5);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 movq_r2r(mm0,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 movq_r2r(mm5,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 punpcklbw_r2r(mm7,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 punpcklbw_r2r(mm7,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501 paddw_r2r(mm6,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502 paddw_r2r(mm2,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 psraw_i2r(1,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 packuswb_r2r(mm7,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505 movd_r2m(mm1,lum[0]);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506 movq_m2r(ptr[16],mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507 movq_m2r(ptr[24],mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508 movq_r2r(mm2,mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509 punpcklbw_r2r(mm1,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 punpckhbw_r2r(mm1,mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 movq_r2r(mm2,mm3);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 punpcklbw_r2r(mm4,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 punpckhbw_r2r(mm4,mm3);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 movq_r2r(mm2,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 movq_r2r(mm3,mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 punpcklbw_r2r(mm7,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 punpcklbw_r2r(mm7,mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 paddw_r2r(mm6,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 paddw_r2r(mm4,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 psraw_i2r(1,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 packuswb_r2r(mm7,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 movd_r2m(mm1,lum[4]);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523 punpckhbw_r2r(mm7,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524 punpckhbw_r2r(mm7,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525 paddw_r2r(mm6,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 paddw_r2r(mm2,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 psraw_i2r(1,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 packuswb_r2r(mm7,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 punpckhbw_r2r(mm7,mm5);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 punpckhbw_r2r(mm7,mm3);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 paddw_r2r(mm6,mm5);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 paddw_r2r(mm3,mm5);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 psraw_i2r(1,mm5);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 packuswb_r2r(mm7,mm5);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 movd_r2m(mm0,cb[0]);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 movd_r2m(mm5,cr[0]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 #define LINE_NOUV_AVG \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 movq_m2r(ptr[0],mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540 movq_m2r(ptr[8],mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 pand_r2r(mm5,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 pand_r2r(mm5,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
543 pmaddwd_r2r(mm6,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
544 pmaddwd_r2r(mm6,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545 packssdw_r2r(mm1,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546 paddw_r2r(mm6,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547 psraw_i2r(1,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
548 movq_m2r(ptr[16],mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549 movq_m2r(ptr[24],mm3);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550 pand_r2r(mm5,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551 pand_r2r(mm5,mm3);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552 pmaddwd_r2r(mm6,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 pmaddwd_r2r(mm6,mm3);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
554 packssdw_r2r(mm3,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555 paddw_r2r(mm6,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 psraw_i2r(1,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557 packuswb_r2r(mm2,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 movq_r2m(mm0,lum[0]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560 #define DEINT_LINE_LUM(ptroff) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 movd_m2r(lum_m4[(ptroff)],mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 movd_m2r(lum_m3[(ptroff)],mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563 movd_m2r(lum_m2[(ptroff)],mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564 movd_m2r(lum_m1[(ptroff)],mm3);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 movd_m2r(lum[(ptroff)],mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 punpcklbw_r2r(mm7,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 movd_r2m(mm2,lum_m4[(ptroff)]);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568 punpcklbw_r2r(mm7,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
569 punpcklbw_r2r(mm7,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
570 punpcklbw_r2r(mm7,mm3);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571 punpcklbw_r2r(mm7,mm4);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572 psllw_i2r(2,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 psllw_i2r(1,mm2);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 paddw_r2r(mm6,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 psllw_i2r(2,mm3);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576 paddw_r2r(mm2,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 paddw_r2r(mm4,mm0);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 paddw_r2r(mm3,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 psubusw_r2r(mm0,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580 psrlw_i2r(3,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 packuswb_r2r(mm7,mm1);\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582 movd_r2m(mm1,lum_m2[(ptroff)]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 #else
2087
fa4066708500 Drop unnecessary libavcodec/ prefix in #include path.
diego
parents: 1982
diff changeset
585 #include "dsputil.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 #define LINE_WITH_UV \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 cb[0]=ptr[1];cb[1]=ptr[5];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590 cr[0]=ptr[3];cr[1]=ptr[7];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591 lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 cb[2]=ptr[9];cb[3]=ptr[13];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 cr[2]=ptr[11];cr[3]=ptr[15];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 cb[4]=ptr[17];cb[5]=ptr[21];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 cr[4]=ptr[19];cr[5]=ptr[23];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 cb[6]=ptr[25];cb[7]=ptr[29];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 cr[6]=ptr[27];cr[7]=ptr[31];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 #define LINE_NO_UV \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
605 lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607 #define LINE_WITHUV_AVG \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608 sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
610 sum=(ptr[1]+ptr[5]+1) >> 1;cb[0]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 sum=(ptr[3]+ptr[7]+1) >> 1;cr[0]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 sum=(ptr[9]+ptr[13]+1) >> 1;cb[1]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 sum=(ptr[11]+ptr[15]+1) >> 1;cr[1]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616 sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617 sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618 sum=(ptr[17]+ptr[21]+1) >> 1;cb[2]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619 sum=(ptr[19]+ptr[23]+1) >> 1;cr[2]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
620 sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
621 sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 sum=(ptr[25]+ptr[29]+1) >> 1;cb[3]=sum; \
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
623 sum=(ptr[27]+ptr[31]+1) >> 1;cr[3]=sum;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
625 #define LINE_NOUV_AVG \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626 sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629 sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
631 sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632 sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 878
diff changeset
633 sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
634
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 #define DEINT_LINE_LUM(ptroff) \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 sum=(-lum_m4[(ptroff)]+(lum_m3[(ptroff)]<<2)+(lum_m2[(ptroff)]<<1)+(lum_m1[(ptroff)]<<2)-lum[(ptroff)]); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637 lum_m4[(ptroff)]=lum_m2[(ptroff)];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638 lum_m2[(ptroff)]=cm[(sum+4)>>3];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 sum=(-lum_m4[(ptroff)+1]+(lum_m3[(ptroff)+1]<<2)+(lum_m2[(ptroff)+1]<<1)+(lum_m1[(ptroff)+1]<<2)-lum[(ptroff)+1]); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640 lum_m4[(ptroff)+1]=lum_m2[(ptroff)+1];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 lum_m2[(ptroff)+1]=cm[(sum+4)>>3];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642 sum=(-lum_m4[(ptroff)+2]+(lum_m3[(ptroff)+2]<<2)+(lum_m2[(ptroff)+2]<<1)+(lum_m1[(ptroff)+2]<<2)-lum[(ptroff)+2]); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 lum_m4[(ptroff)+2]=lum_m2[(ptroff)+2];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644 lum_m2[(ptroff)+2]=cm[(sum+4)>>3];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
645 sum=(-lum_m4[(ptroff)+3]+(lum_m3[(ptroff)+3]<<2)+(lum_m2[(ptroff)+3]<<1)+(lum_m1[(ptroff)+3]<<2)-lum[(ptroff)+3]); \
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
646 lum_m4[(ptroff)+3]=lum_m2[(ptroff)+3];\
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647 lum_m2[(ptroff)+3]=cm[(sum+4)>>3];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
649 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
650
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
651
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
652 /* Read two fields separately. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
653 static int aiw_read_picture(VideoData *s, uint8_t *data)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 30
diff changeset
655 uint8_t *ptr, *lum, *cb, *cr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 int h;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657 #ifndef HAVE_MMX
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658 int sum;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659 #endif
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 30
diff changeset
660 uint8_t* src = s->src_mem;
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 30
diff changeset
661 uint8_t *ptrend = &src[s->width*2];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
662 lum=data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 cb=&lum[s->width*s->height];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664 cr=&cb[(s->width*s->height)/4];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
665 if (s->deint == 0 && s->halfw == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 while (read(s->fd,src,s->width*2) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667 usleep(100);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
668 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
669 for (h = 0; h < s->height-2; h+=2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
670 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
671 LINE_WITH_UV
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
672 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
673 read(s->fd,src,s->width*2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
675 LINE_NO_UV
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
677 read(s->fd,src,s->width*2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
678 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
679 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
680 * Do last two lines
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
681 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
682 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
683 LINE_WITH_UV
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
684 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
685 read(s->fd,src,s->width*2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
686 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
687 LINE_NO_UV
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
689 /* drop second field */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
690 while (read(s->fd,src,s->width*2) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
691 usleep(100);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
692 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
693 for (h = 0; h < s->height - 1; h++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
694 read(s->fd,src,s->width*2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
695 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
696 } else if (s->halfw == 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
697 #ifdef HAVE_MMX
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
698 mmx_t rounder;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
699 mmx_t masker;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
700 rounder.uw[0]=1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
701 rounder.uw[1]=1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702 rounder.uw[2]=1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
703 rounder.uw[3]=1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
704 masker.ub[0]=0xff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
705 masker.ub[1]=0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
706 masker.ub[2]=0xff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
707 masker.ub[3]=0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
708 masker.ub[4]=0xff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709 masker.ub[5]=0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710 masker.ub[6]=0xff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
711 masker.ub[7]=0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
712 pxor_r2r(mm7,mm7);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
713 movq_m2r(rounder,mm6);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715 while (read(s->fd,src,s->width*4) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716 usleep(100);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
718 ptrend = &src[s->width*4];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719 for (h = 0; h < s->height-2; h+=2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721 LINE_WITHUV_AVG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
723 read(s->fd,src,s->width*4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
724 #ifdef HAVE_MMX
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
725 movq_m2r(masker,mm5);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
726 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728 LINE_NOUV_AVG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
730 read(s->fd,src,s->width*4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
731 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
732 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
733 * Do last two lines
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
734 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
735 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
736 LINE_WITHUV_AVG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
737 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
738 read(s->fd,src,s->width*4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
739 #ifdef HAVE_MMX
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
740 movq_m2r(masker,mm5);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
741 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
742 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
743 LINE_NOUV_AVG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
744 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745 /* drop second field */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
746 while (read(s->fd,src,s->width*4) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
747 usleep(100);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
748 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
749 for (h = 0; h < s->height - 1; h++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
750 read(s->fd,src,s->width*4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
751 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
752 } else {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 30
diff changeset
753 uint8_t *lum_m1, *lum_m2, *lum_m3, *lum_m4;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
754 #ifdef HAVE_MMX
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
755 mmx_t rounder;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
756 rounder.uw[0]=4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
757 rounder.uw[1]=4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
758 rounder.uw[2]=4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
759 rounder.uw[3]=4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 movq_m2r(rounder,mm6);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
761 pxor_r2r(mm7,mm7);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762 #else
1491
89f88d324eea rename cropTbl -> ff_cropTbl
mru
parents: 1358
diff changeset
763 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
766 /* read two fields and deinterlace them */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 while (read(s->fd,src,s->width*2) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
768 usleep(100);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
770 for (h = 0; h < (s->height/2)-2; h+=2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
771 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772 LINE_WITH_UV
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
773 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774 read(s->fd,src,s->width*2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
775 /* skip a luminance line - will be filled in later */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
776 lum += s->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
777 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
778 LINE_WITH_UV
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
779 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
780 /* skip a luminance line - will be filled in later */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
781 lum += s->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
782 read(s->fd,src,s->width*2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
783 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
784 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
785 * Do last two lines
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
786 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
787 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
788 LINE_WITH_UV
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
789 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
790 /* skip a luminance line - will be filled in later */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
791 lum += s->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
792 read(s->fd,src,s->width*2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
793 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
794 LINE_WITH_UV
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
795 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
796 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
797 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
798 * SECOND FIELD
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
800 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
801 lum=&data[s->width];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
802 while (read(s->fd,src,s->width*2) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
803 usleep(10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
804 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
805 /* First (and last) two lines not interlaced */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
806 for (h = 0; h < 2; h++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
807 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
808 LINE_NO_UV
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
809 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
810 read(s->fd,src,s->width*2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
811 /* skip a luminance line */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
812 lum += s->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
813 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
814 lum_m1=&lum[-s->width];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
815 lum_m2=&lum_m1[-s->width];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
816 lum_m3=&lum_m2[-s->width];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
817 memmove(s->lum_m4_mem,&lum_m3[-s->width],s->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
818 for (; h < (s->height/2)-1; h++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
819 lum_m4=s->lum_m4_mem;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
820 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16,lum_m1+=16,lum_m2+=16,lum_m3+=16,lum_m4+=16) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
821 LINE_NO_UV
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
822
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
823 DEINT_LINE_LUM(0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
824 DEINT_LINE_LUM(4)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
825 DEINT_LINE_LUM(8)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
826 DEINT_LINE_LUM(12)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
827 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
828 read(s->fd,src,s->width*2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
829 /* skip a luminance line */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
830 lum += s->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
831 lum_m1 += s->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
832 lum_m2 += s->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
833 lum_m3 += s->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
834 // lum_m4 += s->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
835 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
836 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
837 * Do last line
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
838 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839 lum_m4=s->lum_m4_mem;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
840 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, lum_m1+=16, lum_m2+=16, lum_m3+=16, lum_m4+=16) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841 LINE_NO_UV
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
842
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
843 DEINT_LINE_LUM(0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
844 DEINT_LINE_LUM(4)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
845 DEINT_LINE_LUM(8)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
846 DEINT_LINE_LUM(12)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
847 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
848 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
849 #ifdef HAVE_MMX
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
850 emms();
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
851 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
852 return s->frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
853 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
854
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
855 static int aiw_close(VideoData *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
856 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
857 av_freep(&s->lum_m4_mem);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
858 av_freep(&s->src_mem);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
859 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
860 }