Statistics
| Branch: | Revision:

ffmpeg / libavformat / grab.c @ 7e33d3fe

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