2 * Linux video grab interface
3 * Copyright (c) 2000,2001 Fabrice Bellard.
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/ioctl.h>
27 #define _LINUX_TIME_H 1
28 #include <linux/videodev.h>
33 int frame_format; /* see VIDEO_PALETTE_xxx */
40 struct video_capability video_cap;
41 struct video_audio audio_saved;
43 struct video_mbuf gb_buffers;
44 struct video_mmap gb_buf;
47 /* ATI All In Wonder specific stuff */
48 /* XXX: remove and merge in libavcodec/imgconvert.c */
56 static int aiw_init(VideoData *s);
57 static int aiw_read_picture(VideoData *s, uint8_t *data);
58 static int aiw_close(VideoData *s);
60 static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
62 VideoData *s = s1->priv_data;
65 int video_fd, frame_size;
66 int ret, frame_rate, frame_rate_base;
67 int desired_palette, desired_depth;
68 struct video_tuner tuner;
69 struct video_audio audio;
70 struct video_picture pict;
71 const char *video_device;
74 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);
83 frame_rate = ap->time_base.den;
84 frame_rate_base = ap->time_base.num;
86 if((unsigned)width > 32767 || (unsigned)height > 32767) {
87 av_log(s1, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n",
93 st = av_new_stream(s1, 0);
96 av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
100 s->frame_rate = frame_rate;
101 s->frame_rate_base = frame_rate_base;
103 video_device = ap->device;
105 video_device = "/dev/video";
106 video_fd = open(video_device, O_RDWR);
108 perror(video_device);
112 if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) {
113 perror("VIDIOCGCAP");
117 if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {
118 av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n");
122 desired_palette = -1;
124 if (ap->pix_fmt == PIX_FMT_YUV420P) {
125 desired_palette = VIDEO_PALETTE_YUV420P;
127 } else if (ap->pix_fmt == PIX_FMT_YUV422) {
128 desired_palette = VIDEO_PALETTE_YUV422;
130 } else if (ap->pix_fmt == PIX_FMT_BGR24) {
131 desired_palette = VIDEO_PALETTE_RGB24;
135 /* set tv standard */
136 if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
137 if (!strcasecmp(ap->standard, "pal"))
138 tuner.mode = VIDEO_MODE_PAL;
139 else if (!strcasecmp(ap->standard, "secam"))
140 tuner.mode = VIDEO_MODE_SECAM;
142 tuner.mode = VIDEO_MODE_NTSC;
143 ioctl(video_fd, VIDIOCSTUNER, &tuner);
148 ioctl(video_fd, VIDIOCGAUDIO, &audio);
149 memcpy(&s->audio_saved, &audio, sizeof(audio));
150 audio.flags &= ~VIDEO_AUDIO_MUTE;
151 ioctl(video_fd, VIDIOCSAUDIO, &audio);
153 ioctl(video_fd, VIDIOCGPICT, &pict);
155 printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
162 /* try to choose a suitable video format */
163 pict.palette = desired_palette;
164 pict.depth= desired_depth;
165 if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
166 pict.palette=VIDEO_PALETTE_YUV420P;
168 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
170 pict.palette=VIDEO_PALETTE_YUV422;
172 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
174 pict.palette=VIDEO_PALETTE_RGB24;
176 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
178 pict.palette=VIDEO_PALETTE_GREY;
180 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
187 ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
189 /* try to use read based access */
190 struct video_window win;
200 ioctl(video_fd, VIDIOCSWIN, &win);
202 s->frame_format = pict.palette;
205 ioctl(video_fd, VIDIOCCAPTURE, &val);
207 s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
210 /* ATI All In Wonder automatic activation */
211 if (!strcmp(s->video_cap.name, "Km")) {
215 /* force 420P format because convertion from YUV422 to YUV420P
216 is done in this driver (ugly) */
217 s->frame_format = VIDEO_PALETTE_YUV420P;
220 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 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) {
229 s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
231 /* start to grab the first frame */
232 s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
233 s->gb_buf.height = height;
234 s->gb_buf.width = width;
235 s->gb_buf.format = pict.palette;
237 ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
239 if (errno != EAGAIN) {
241 av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n");
243 av_log(s1, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n");
247 for (j = 1; j < s->gb_buffers.frames; j++) {
249 ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
251 s->frame_format = s->gb_buf.format;
255 switch(s->frame_format) {
256 case VIDEO_PALETTE_YUV420P:
257 frame_size = (width * height * 3) / 2;
258 st->codec->pix_fmt = PIX_FMT_YUV420P;
260 case VIDEO_PALETTE_YUV422:
261 frame_size = width * height * 2;
262 st->codec->pix_fmt = PIX_FMT_YUV422;
264 case VIDEO_PALETTE_RGB24:
265 frame_size = width * height * 3;
266 st->codec->pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
268 case VIDEO_PALETTE_GREY:
269 frame_size = width * height * 1;
270 st->codec->pix_fmt = PIX_FMT_GRAY8;
276 s->frame_size = frame_size;
278 st->codec->codec_type = CODEC_TYPE_VIDEO;
279 st->codec->codec_id = CODEC_ID_RAWVIDEO;
280 st->codec->width = width;
281 st->codec->height = height;
282 st->codec->time_base.den = frame_rate;
283 st->codec->time_base.num = frame_rate_base;
284 st->codec->bit_rate = frame_size * 1/av_q2d(st->codec->time_base) * 8;
294 static int v4l_mm_read_picture(VideoData *s, uint8_t *buf)
298 while (ioctl(s->fd, VIDIOCSYNC, &s->gb_frame) < 0 &&
299 (errno == EAGAIN || errno == EINTR));
301 ptr = s->video_buf + s->gb_buffers.offsets[s->gb_frame];
302 memcpy(buf, ptr, s->frame_size);
304 /* Setup to capture the next frame */
305 s->gb_buf.frame = s->gb_frame;
306 if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) {
308 av_log(NULL, AV_LOG_ERROR, "Cannot Sync\n");
310 perror("VIDIOCMCAPTURE");
314 /* This is now the grabbing frame */
315 s->gb_frame = (s->gb_frame + 1) % s->gb_buffers.frames;
317 return s->frame_size;
320 static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
322 VideoData *s = s1->priv_data;
323 int64_t curtime, delay;
326 /* Calculate the time of the next frame */
327 s->time_frame += INT64_C(1000000);
329 /* wait based on the frame rate */
331 curtime = av_gettime();
332 delay = s->time_frame * s->frame_rate_base / s->frame_rate - curtime;
334 if (delay < INT64_C(-1000000) * s->frame_rate_base / s->frame_rate) {
335 /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */
336 s->time_frame += INT64_C(1000000);
340 ts.tv_sec = delay / 1000000;
341 ts.tv_nsec = (delay % 1000000) * 1000;
342 nanosleep(&ts, NULL);
345 if (av_new_packet(pkt, s->frame_size) < 0)
351 if (s->aiw_enabled) {
352 return aiw_read_picture(s, pkt->data);
353 } else if (s->use_mmap) {
354 return v4l_mm_read_picture(s, pkt->data);
356 if (read(s->fd, pkt->data, pkt->size) != pkt->size)
358 return s->frame_size;
362 static int grab_read_close(AVFormatContext *s1)
364 VideoData *s = s1->priv_data;
370 munmap(s->video_buf, s->gb_buffers.size);
372 /* mute audio. we must force it because the BTTV driver does not
373 return its state correctly */
374 s->audio_saved.flags |= VIDEO_AUDIO_MUTE;
375 ioctl(s->fd, VIDIOCSAUDIO, &s->audio_saved);
381 AVInputFormat video_grab_device_demuxer = {
389 .flags = AVFMT_NOFILE,
392 /* All in Wonder specific stuff */
393 /* XXX: remove and merge in libavcodec/imgconvert.c */
395 static int aiw_init(VideoData *s)
402 if ((width == s->video_cap.maxwidth && height == s->video_cap.maxheight) ||
403 (width == s->video_cap.maxwidth && height == s->video_cap.maxheight*2) ||
404 (width == s->video_cap.maxwidth/2 && height == s->video_cap.maxheight)) {
408 if (height == s->video_cap.maxheight*2) s->deint=1;
409 if (width == s->video_cap.maxwidth/2) s->halfw=1;
411 av_log(NULL, AV_LOG_ERROR, "\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
412 av_log(NULL, AV_LOG_ERROR, " %dx%d %dx%d %dx%d\n\n",
413 s->video_cap.maxwidth,s->video_cap.maxheight,
414 s->video_cap.maxwidth,s->video_cap.maxheight*2,
415 s->video_cap.maxwidth/2,s->video_cap.maxheight);
420 s->src_mem = av_malloc(s->width*2);
422 s->src_mem = av_malloc(s->width*4);
424 if (!s->src_mem) goto fail;
426 s->lum_m4_mem = av_malloc(s->width);
431 av_freep(&s->src_mem);
432 av_freep(&s->lum_m4_mem);
437 #include "libavcodec/i386/mmx.h"
439 #define LINE_WITH_UV \
440 movq_m2r(ptr[0],mm0); \
441 movq_m2r(ptr[8],mm1); \
442 movq_r2r(mm0, mm4); \
443 punpcklbw_r2r(mm1,mm0); \
444 punpckhbw_r2r(mm1,mm4); \
446 punpcklbw_r2r(mm4,mm0); \
447 punpckhbw_r2r(mm4,mm5); \
449 punpcklbw_r2r(mm5,mm1); \
450 movq_r2m(mm1,lum[0]); \
451 movq_m2r(ptr[16],mm2); \
452 movq_m2r(ptr[24],mm1); \
454 punpcklbw_r2r(mm1,mm2); \
455 punpckhbw_r2r(mm1,mm4); \
457 punpcklbw_r2r(mm4,mm2); \
458 punpckhbw_r2r(mm4,mm3); \
460 punpcklbw_r2r(mm3,mm1); \
461 movq_r2m(mm1,lum[8]); \
462 punpckhdq_r2r(mm2,mm0); \
463 punpckhdq_r2r(mm3,mm5); \
464 movq_r2m(mm0,cb[0]); \
468 movq_m2r(ptr[0],mm0);\
469 movq_m2r(ptr[8],mm1);\
471 punpcklbw_r2r(mm1,mm0); \
472 punpckhbw_r2r(mm1,mm4);\
474 punpcklbw_r2r(mm4,mm0);\
475 punpckhbw_r2r(mm4,mm5);\
477 punpcklbw_r2r(mm5,mm1);\
478 movq_r2m(mm1,lum[0]);\
479 movq_m2r(ptr[16],mm2);\
480 movq_m2r(ptr[24],mm1);\
482 punpcklbw_r2r(mm1,mm2);\
483 punpckhbw_r2r(mm1,mm4);\
485 punpcklbw_r2r(mm4,mm2);\
486 punpckhbw_r2r(mm4,mm3);\
488 punpcklbw_r2r(mm3,mm1);\
489 movq_r2m(mm1,lum[8]);
491 #define LINE_WITHUV_AVG \
492 movq_m2r(ptr[0], mm0);\
493 movq_m2r(ptr[8], mm1);\
495 punpcklbw_r2r(mm1,mm0);\
496 punpckhbw_r2r(mm1,mm4);\
498 punpcklbw_r2r(mm4,mm0);\
499 punpckhbw_r2r(mm4,mm5);\
502 punpcklbw_r2r(mm7,mm1);\
503 punpcklbw_r2r(mm7,mm2);\
507 packuswb_r2r(mm7,mm1);\
508 movd_r2m(mm1,lum[0]);\
509 movq_m2r(ptr[16],mm2);\
510 movq_m2r(ptr[24],mm1);\
512 punpcklbw_r2r(mm1,mm2);\
513 punpckhbw_r2r(mm1,mm4);\
515 punpcklbw_r2r(mm4,mm2);\
516 punpckhbw_r2r(mm4,mm3);\
519 punpcklbw_r2r(mm7,mm1);\
520 punpcklbw_r2r(mm7,mm4);\
524 packuswb_r2r(mm7,mm1);\
525 movd_r2m(mm1,lum[4]);\
526 punpckhbw_r2r(mm7,mm0);\
527 punpckhbw_r2r(mm7,mm2);\
531 packuswb_r2r(mm7,mm0);\
532 punpckhbw_r2r(mm7,mm5);\
533 punpckhbw_r2r(mm7,mm3);\
537 packuswb_r2r(mm7,mm5);\
538 movd_r2m(mm0,cb[0]);\
541 #define LINE_NOUV_AVG \
542 movq_m2r(ptr[0],mm0);\
543 movq_m2r(ptr[8],mm1);\
546 pmaddwd_r2r(mm6,mm0);\
547 pmaddwd_r2r(mm6,mm1);\
548 packssdw_r2r(mm1,mm0);\
551 movq_m2r(ptr[16],mm2);\
552 movq_m2r(ptr[24],mm3);\
555 pmaddwd_r2r(mm6,mm2);\
556 pmaddwd_r2r(mm6,mm3);\
557 packssdw_r2r(mm3,mm2);\
560 packuswb_r2r(mm2,mm0);\
561 movq_r2m(mm0,lum[0]);
563 #define DEINT_LINE_LUM(ptroff) \
564 movd_m2r(lum_m4[(ptroff)],mm0);\
565 movd_m2r(lum_m3[(ptroff)],mm1);\
566 movd_m2r(lum_m2[(ptroff)],mm2);\
567 movd_m2r(lum_m1[(ptroff)],mm3);\
568 movd_m2r(lum[(ptroff)],mm4);\
569 punpcklbw_r2r(mm7,mm0);\
570 movd_r2m(mm2,lum_m4[(ptroff)]);\
571 punpcklbw_r2r(mm7,mm1);\
572 punpcklbw_r2r(mm7,mm2);\
573 punpcklbw_r2r(mm7,mm3);\
574 punpcklbw_r2r(mm7,mm4);\
582 psubusw_r2r(mm0,mm1);\
584 packuswb_r2r(mm7,mm1);\
585 movd_r2m(mm1,lum_m2[(ptroff)]);
588 #include "libavcodec/dsputil.h"
590 #define LINE_WITH_UV \
591 lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
592 cb[0]=ptr[1];cb[1]=ptr[5];\
593 cr[0]=ptr[3];cr[1]=ptr[7];\
594 lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
595 cb[2]=ptr[9];cb[3]=ptr[13];\
596 cr[2]=ptr[11];cr[3]=ptr[15];\
597 lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
598 cb[4]=ptr[17];cb[5]=ptr[21];\
599 cr[4]=ptr[19];cr[5]=ptr[23];\
600 lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];\
601 cb[6]=ptr[25];cb[7]=ptr[29];\
602 cr[6]=ptr[27];cr[7]=ptr[31];
605 lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
606 lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
607 lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
608 lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];
610 #define LINE_WITHUV_AVG \
611 sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
612 sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
613 sum=(ptr[1]+ptr[5]+1) >> 1;cb[0]=sum; \
614 sum=(ptr[3]+ptr[7]+1) >> 1;cr[0]=sum; \
615 sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
616 sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
617 sum=(ptr[9]+ptr[13]+1) >> 1;cb[1]=sum; \
618 sum=(ptr[11]+ptr[15]+1) >> 1;cr[1]=sum; \
619 sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
620 sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
621 sum=(ptr[17]+ptr[21]+1) >> 1;cb[2]=sum; \
622 sum=(ptr[19]+ptr[23]+1) >> 1;cr[2]=sum; \
623 sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
624 sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum; \
625 sum=(ptr[25]+ptr[29]+1) >> 1;cb[3]=sum; \
626 sum=(ptr[27]+ptr[31]+1) >> 1;cr[3]=sum;
628 #define LINE_NOUV_AVG \
629 sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
630 sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
631 sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
632 sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
633 sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
634 sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
635 sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
636 sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum;
638 #define DEINT_LINE_LUM(ptroff) \
639 sum=(-lum_m4[(ptroff)]+(lum_m3[(ptroff)]<<2)+(lum_m2[(ptroff)]<<1)+(lum_m1[(ptroff)]<<2)-lum[(ptroff)]); \
640 lum_m4[(ptroff)]=lum_m2[(ptroff)];\
641 lum_m2[(ptroff)]=cm[(sum+4)>>3];\
642 sum=(-lum_m4[(ptroff)+1]+(lum_m3[(ptroff)+1]<<2)+(lum_m2[(ptroff)+1]<<1)+(lum_m1[(ptroff)+1]<<2)-lum[(ptroff)+1]); \
643 lum_m4[(ptroff)+1]=lum_m2[(ptroff)+1];\
644 lum_m2[(ptroff)+1]=cm[(sum+4)>>3];\
645 sum=(-lum_m4[(ptroff)+2]+(lum_m3[(ptroff)+2]<<2)+(lum_m2[(ptroff)+2]<<1)+(lum_m1[(ptroff)+2]<<2)-lum[(ptroff)+2]); \
646 lum_m4[(ptroff)+2]=lum_m2[(ptroff)+2];\
647 lum_m2[(ptroff)+2]=cm[(sum+4)>>3];\
648 sum=(-lum_m4[(ptroff)+3]+(lum_m3[(ptroff)+3]<<2)+(lum_m2[(ptroff)+3]<<1)+(lum_m1[(ptroff)+3]<<2)-lum[(ptroff)+3]); \
649 lum_m4[(ptroff)+3]=lum_m2[(ptroff)+3];\
650 lum_m2[(ptroff)+3]=cm[(sum+4)>>3];
655 /* Read two fields separately. */
656 static int aiw_read_picture(VideoData *s, uint8_t *data)
658 uint8_t *ptr, *lum, *cb, *cr;
663 uint8_t* src = s->src_mem;
664 uint8_t *ptrend = &src[s->width*2];
666 cb=&lum[s->width*s->height];
667 cr=&cb[(s->width*s->height)/4];
668 if (s->deint == 0 && s->halfw == 0) {
669 while (read(s->fd,src,s->width*2) < 0) {
672 for (h = 0; h < s->height-2; h+=2) {
673 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
676 read(s->fd,src,s->width*2);
677 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
680 read(s->fd,src,s->width*2);
685 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
688 read(s->fd,src,s->width*2);
689 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
692 /* drop second field */
693 while (read(s->fd,src,s->width*2) < 0) {
696 for (h = 0; h < s->height - 1; h++) {
697 read(s->fd,src,s->width*2);
699 } else if (s->halfw == 1) {
716 movq_m2r(rounder,mm6);
718 while (read(s->fd,src,s->width*4) < 0) {
721 ptrend = &src[s->width*4];
722 for (h = 0; h < s->height-2; h+=2) {
723 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
726 read(s->fd,src,s->width*4);
728 movq_m2r(masker,mm5);
730 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
733 read(s->fd,src,s->width*4);
738 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
741 read(s->fd,src,s->width*4);
743 movq_m2r(masker,mm5);
745 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
748 /* drop second field */
749 while (read(s->fd,src,s->width*4) < 0) {
752 for (h = 0; h < s->height - 1; h++) {
753 read(s->fd,src,s->width*4);
756 uint8_t *lum_m1, *lum_m2, *lum_m3, *lum_m4;
763 movq_m2r(rounder,mm6);
766 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
769 /* read two fields and deinterlace them */
770 while (read(s->fd,src,s->width*2) < 0) {
773 for (h = 0; h < (s->height/2)-2; h+=2) {
774 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
777 read(s->fd,src,s->width*2);
778 /* skip a luminance line - will be filled in later */
780 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
783 /* skip a luminance line - will be filled in later */
785 read(s->fd,src,s->width*2);
790 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
793 /* skip a luminance line - will be filled in later */
795 read(s->fd,src,s->width*2);
796 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
805 while (read(s->fd,src,s->width*2) < 0) {
808 /* First (and last) two lines not interlaced */
809 for (h = 0; h < 2; h++) {
810 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
813 read(s->fd,src,s->width*2);
814 /* skip a luminance line */
817 lum_m1=&lum[-s->width];
818 lum_m2=&lum_m1[-s->width];
819 lum_m3=&lum_m2[-s->width];
820 memmove(s->lum_m4_mem,&lum_m3[-s->width],s->width);
821 for (; h < (s->height/2)-1; h++) {
822 lum_m4=s->lum_m4_mem;
823 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16,lum_m1+=16,lum_m2+=16,lum_m3+=16,lum_m4+=16) {
831 read(s->fd,src,s->width*2);
832 /* skip a luminance line */
837 // lum_m4 += s->width;
842 lum_m4=s->lum_m4_mem;
843 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, lum_m1+=16, lum_m2+=16, lum_m3+=16, lum_m4+=16) {
855 return s->frame_size;
858 static int aiw_close(VideoData *s)
860 av_freep(&s->lum_m4_mem);
861 av_freep(&s->src_mem);