Statistics
| Branch: | Revision:

ffmpeg / libavformat / grab.c @ 1d7d9935

History | View | Annotate | Download (28.5 KB)

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