2 * Linux video grab interface
3 * Copyright (c) 2000,2001 Fabrice Bellard.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sys/ioctl.h>
25 #define _LINUX_TIME_H 1
26 #include <linux/videodev.h>
31 int frame_format; /* see VIDEO_PALETTE_xxx */
38 struct video_capability video_cap;
39 struct video_audio audio_saved;
41 struct video_mbuf gb_buffers;
42 struct video_mmap gb_buf;
45 /* ATI All In Wonder specific stuff */
46 /* XXX: remove and merge in libavcodec/imgconvert.c */
54 static int aiw_init(VideoData *s);
55 static int aiw_read_picture(VideoData *s, uint8_t *data);
56 static int aiw_close(VideoData *s);
58 static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
60 VideoData *s = s1->priv_data;
63 int video_fd, frame_size;
64 int ret, frame_rate, frame_rate_base;
66 struct video_tuner tuner;
67 struct video_audio audio;
68 const char *video_device;
71 if (!ap || ap->width <= 0 || ap->height <= 0 || ap->frame_rate <= 0)
76 frame_rate = ap->frame_rate;
77 frame_rate_base = ap->frame_rate_base;
79 st = av_new_stream(s1, 0);
85 s->frame_rate = frame_rate;
86 s->frame_rate_base = frame_rate_base;
88 video_device = ap->device;
90 video_device = "/dev/video";
91 video_fd = open(video_device, O_RDWR);
97 if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) {
102 if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {
103 av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n");
107 desired_palette = -1;
108 if (st->codec.pix_fmt == PIX_FMT_YUV420P) {
109 desired_palette = VIDEO_PALETTE_YUV420P;
110 } else if (st->codec.pix_fmt == PIX_FMT_YUV422) {
111 desired_palette = VIDEO_PALETTE_YUV422;
112 } else if (st->codec.pix_fmt == PIX_FMT_BGR24) {
113 desired_palette = VIDEO_PALETTE_RGB24;
116 /* set tv standard */
117 if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
118 if (!strcasecmp(ap->standard, "pal"))
119 tuner.mode = VIDEO_MODE_PAL;
120 else if (!strcasecmp(ap->standard, "secam"))
121 tuner.mode = VIDEO_MODE_SECAM;
123 tuner.mode = VIDEO_MODE_NTSC;
124 ioctl(video_fd, VIDIOCSTUNER, &tuner);
129 ioctl(video_fd, VIDIOCGAUDIO, &audio);
130 memcpy(&s->audio_saved, &audio, sizeof(audio));
131 audio.flags &= ~VIDEO_AUDIO_MUTE;
132 ioctl(video_fd, VIDIOCSAUDIO, &audio);
134 ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
136 /* try to use read based access */
137 struct video_window win;
138 struct video_picture pict;
148 ioctl(video_fd, VIDIOCSWIN, &win);
150 ioctl(video_fd, VIDIOCGPICT, &pict);
152 printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
159 /* try to choose a suitable video format */
160 pict.palette = desired_palette;
161 if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
162 pict.palette=VIDEO_PALETTE_YUV420P;
163 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
165 pict.palette=VIDEO_PALETTE_YUV422;
166 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
168 pict.palette=VIDEO_PALETTE_RGB24;
169 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
176 s->frame_format = pict.palette;
179 ioctl(video_fd, VIDIOCCAPTURE, &val);
181 s->time_frame = av_gettime();
184 /* ATI All In Wonder automatic activation */
185 if (!strcmp(s->video_cap.name, "Km")) {
189 /* force 420P format because convertion from YUV422 to YUV420P
190 is done in this driver (ugly) */
191 s->frame_format = VIDEO_PALETTE_YUV420P;
194 s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0);
195 if ((unsigned char*)-1 == s->video_buf) {
200 s->time_frame = av_gettime();
202 /* start to grab the first frame */
203 s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
204 s->gb_buf.height = height;
205 s->gb_buf.width = width;
206 s->gb_buf.format = desired_palette;
208 if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf)) < 0) {
209 s->gb_buf.format = VIDEO_PALETTE_YUV420P;
211 ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
212 if (ret < 0 && errno != EAGAIN) {
214 s->gb_buf.format = VIDEO_PALETTE_YUV422;
216 ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
217 if (ret < 0 && errno != EAGAIN) {
219 s->gb_buf.format = VIDEO_PALETTE_RGB24;
220 ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
225 if (errno != EAGAIN) {
227 av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n");
229 av_log(s1, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n");
233 for (j = 1; j < s->gb_buffers.frames; j++) {
235 ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
237 s->frame_format = s->gb_buf.format;
241 switch(s->frame_format) {
242 case VIDEO_PALETTE_YUV420P:
243 frame_size = (width * height * 3) / 2;
244 st->codec.pix_fmt = PIX_FMT_YUV420P;
246 case VIDEO_PALETTE_YUV422:
247 frame_size = width * height * 2;
248 st->codec.pix_fmt = PIX_FMT_YUV422;
250 case VIDEO_PALETTE_RGB24:
251 frame_size = width * height * 3;
252 st->codec.pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
258 s->frame_size = frame_size;
260 st->codec.codec_type = CODEC_TYPE_VIDEO;
261 st->codec.codec_id = CODEC_ID_RAWVIDEO;
262 st->codec.width = width;
263 st->codec.height = height;
264 st->codec.frame_rate = frame_rate;
265 st->codec.frame_rate_base = frame_rate_base;
267 av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
277 static int v4l_mm_read_picture(VideoData *s, uint8_t *buf)
281 while (ioctl(s->fd, VIDIOCSYNC, &s->gb_frame) < 0 &&
282 (errno == EAGAIN || errno == EINTR));
284 ptr = s->video_buf + s->gb_buffers.offsets[s->gb_frame];
285 memcpy(buf, ptr, s->frame_size);
287 /* Setup to capture the next frame */
288 s->gb_buf.frame = s->gb_frame;
289 if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) {
291 av_log(NULL, AV_LOG_ERROR, "Cannot Sync\n");
293 perror("VIDIOCMCAPTURE");
297 /* This is now the grabbing frame */
298 s->gb_frame = (s->gb_frame + 1) % s->gb_buffers.frames;
300 return s->frame_size;
303 static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
305 VideoData *s = s1->priv_data;
306 int64_t curtime, delay;
308 int64_t per_frame = (int64_t_C(1000000) * s->frame_rate_base) / s->frame_rate;
310 /* Calculate the time of the next frame */
311 s->time_frame += per_frame;
313 /* wait based on the frame rate */
315 curtime = av_gettime();
316 delay = s->time_frame - curtime;
318 if (delay < -per_frame) {
319 /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */
320 s->time_frame += per_frame;
324 ts.tv_sec = delay / 1000000;
325 ts.tv_nsec = (delay % 1000000) * 1000;
326 nanosleep(&ts, NULL);
329 if (av_new_packet(pkt, s->frame_size) < 0)
332 pkt->pts = curtime & ((1LL << 48) - 1);
335 if (s->aiw_enabled) {
336 return aiw_read_picture(s, pkt->data);
337 } else if (s->use_mmap) {
338 return v4l_mm_read_picture(s, pkt->data);
340 if (read(s->fd, pkt->data, pkt->size) != pkt->size)
342 return s->frame_size;
346 static int grab_read_close(AVFormatContext *s1)
348 VideoData *s = s1->priv_data;
354 munmap(s->video_buf, s->gb_buffers.size);
356 /* mute audio. we must force it because the BTTV driver does not
357 return its state correctly */
358 s->audio_saved.flags |= VIDEO_AUDIO_MUTE;
359 ioctl(s->fd, VIDIOCSAUDIO, &s->audio_saved);
365 static AVInputFormat video_grab_device_format = {
373 .flags = AVFMT_NOFILE,
376 /* All in Wonder specific stuff */
377 /* XXX: remove and merge in libavcodec/imgconvert.c */
379 static int aiw_init(VideoData *s)
386 if ((width == s->video_cap.maxwidth && height == s->video_cap.maxheight) ||
387 (width == s->video_cap.maxwidth && height == s->video_cap.maxheight*2) ||
388 (width == s->video_cap.maxwidth/2 && height == s->video_cap.maxheight)) {
392 if (height == s->video_cap.maxheight*2) s->deint=1;
393 if (width == s->video_cap.maxwidth/2) s->halfw=1;
395 av_log(NULL, AV_LOG_ERROR, "\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
396 av_log(NULL, AV_LOG_ERROR, " %dx%d %dx%d %dx%d\n\n",
397 s->video_cap.maxwidth,s->video_cap.maxheight,
398 s->video_cap.maxwidth,s->video_cap.maxheight*2,
399 s->video_cap.maxwidth/2,s->video_cap.maxheight);
404 s->src_mem = av_malloc(s->width*2);
406 s->src_mem = av_malloc(s->width*4);
408 if (!s->src_mem) goto fail;
410 s->lum_m4_mem = av_malloc(s->width);
415 av_freep(&s->src_mem);
416 av_freep(&s->lum_m4_mem);
421 #include "../libavcodec/i386/mmx.h"
423 #define LINE_WITH_UV \
424 movq_m2r(ptr[0],mm0); \
425 movq_m2r(ptr[8],mm1); \
426 movq_r2r(mm0, mm4); \
427 punpcklbw_r2r(mm1,mm0); \
428 punpckhbw_r2r(mm1,mm4); \
430 punpcklbw_r2r(mm4,mm0); \
431 punpckhbw_r2r(mm4,mm5); \
433 punpcklbw_r2r(mm5,mm1); \
434 movq_r2m(mm1,lum[0]); \
435 movq_m2r(ptr[16],mm2); \
436 movq_m2r(ptr[24],mm1); \
438 punpcklbw_r2r(mm1,mm2); \
439 punpckhbw_r2r(mm1,mm4); \
441 punpcklbw_r2r(mm4,mm2); \
442 punpckhbw_r2r(mm4,mm3); \
444 punpcklbw_r2r(mm3,mm1); \
445 movq_r2m(mm1,lum[8]); \
446 punpckhdq_r2r(mm2,mm0); \
447 punpckhdq_r2r(mm3,mm5); \
448 movq_r2m(mm0,cb[0]); \
452 movq_m2r(ptr[0],mm0);\
453 movq_m2r(ptr[8],mm1);\
455 punpcklbw_r2r(mm1,mm0); \
456 punpckhbw_r2r(mm1,mm4);\
458 punpcklbw_r2r(mm4,mm0);\
459 punpckhbw_r2r(mm4,mm5);\
461 punpcklbw_r2r(mm5,mm1);\
462 movq_r2m(mm1,lum[0]);\
463 movq_m2r(ptr[16],mm2);\
464 movq_m2r(ptr[24],mm1);\
466 punpcklbw_r2r(mm1,mm2);\
467 punpckhbw_r2r(mm1,mm4);\
469 punpcklbw_r2r(mm4,mm2);\
470 punpckhbw_r2r(mm4,mm3);\
472 punpcklbw_r2r(mm3,mm1);\
473 movq_r2m(mm1,lum[8]);
475 #define LINE_WITHUV_AVG \
476 movq_m2r(ptr[0], mm0);\
477 movq_m2r(ptr[8], mm1);\
479 punpcklbw_r2r(mm1,mm0);\
480 punpckhbw_r2r(mm1,mm4);\
482 punpcklbw_r2r(mm4,mm0);\
483 punpckhbw_r2r(mm4,mm5);\
486 punpcklbw_r2r(mm7,mm1);\
487 punpcklbw_r2r(mm7,mm2);\
491 packuswb_r2r(mm7,mm1);\
492 movd_r2m(mm1,lum[0]);\
493 movq_m2r(ptr[16],mm2);\
494 movq_m2r(ptr[24],mm1);\
496 punpcklbw_r2r(mm1,mm2);\
497 punpckhbw_r2r(mm1,mm4);\
499 punpcklbw_r2r(mm4,mm2);\
500 punpckhbw_r2r(mm4,mm3);\
503 punpcklbw_r2r(mm7,mm1);\
504 punpcklbw_r2r(mm7,mm4);\
508 packuswb_r2r(mm7,mm1);\
509 movd_r2m(mm1,lum[4]);\
510 punpckhbw_r2r(mm7,mm0);\
511 punpckhbw_r2r(mm7,mm2);\
515 packuswb_r2r(mm7,mm0);\
516 punpckhbw_r2r(mm7,mm5);\
517 punpckhbw_r2r(mm7,mm3);\
521 packuswb_r2r(mm7,mm5);\
522 movd_r2m(mm0,cb[0]);\
525 #define LINE_NOUV_AVG \
526 movq_m2r(ptr[0],mm0);\
527 movq_m2r(ptr[8],mm1);\
530 pmaddwd_r2r(mm6,mm0);\
531 pmaddwd_r2r(mm6,mm1);\
532 packssdw_r2r(mm1,mm0);\
535 movq_m2r(ptr[16],mm2);\
536 movq_m2r(ptr[24],mm3);\
539 pmaddwd_r2r(mm6,mm2);\
540 pmaddwd_r2r(mm6,mm3);\
541 packssdw_r2r(mm3,mm2);\
544 packuswb_r2r(mm2,mm0);\
545 movq_r2m(mm0,lum[0]);
547 #define DEINT_LINE_LUM(ptroff) \
548 movd_m2r(lum_m4[(ptroff)],mm0);\
549 movd_m2r(lum_m3[(ptroff)],mm1);\
550 movd_m2r(lum_m2[(ptroff)],mm2);\
551 movd_m2r(lum_m1[(ptroff)],mm3);\
552 movd_m2r(lum[(ptroff)],mm4);\
553 punpcklbw_r2r(mm7,mm0);\
554 movd_r2m(mm2,lum_m4[(ptroff)]);\
555 punpcklbw_r2r(mm7,mm1);\
556 punpcklbw_r2r(mm7,mm2);\
557 punpcklbw_r2r(mm7,mm3);\
558 punpcklbw_r2r(mm7,mm4);\
566 psubusw_r2r(mm0,mm1);\
568 packuswb_r2r(mm7,mm1);\
569 movd_r2m(mm1,lum_m2[(ptroff)]);
572 #include "../libavcodec/dsputil.h"
574 #define LINE_WITH_UV \
575 lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
576 cb[0]=ptr[1];cb[1]=ptr[5];\
577 cr[0]=ptr[3];cr[1]=ptr[7];\
578 lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
579 cb[2]=ptr[9];cb[3]=ptr[13];\
580 cr[2]=ptr[11];cr[3]=ptr[15];\
581 lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
582 cb[4]=ptr[17];cb[5]=ptr[21];\
583 cr[4]=ptr[19];cr[5]=ptr[23];\
584 lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];\
585 cb[6]=ptr[25];cb[7]=ptr[29];\
586 cr[6]=ptr[27];cr[7]=ptr[31];
589 lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
590 lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
591 lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
592 lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];
594 #define LINE_WITHUV_AVG \
595 sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
596 sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
597 sum=(ptr[1]+ptr[5]+1) >> 1;cb[0]=sum; \
598 sum=(ptr[3]+ptr[7]+1) >> 1;cr[0]=sum; \
599 sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
600 sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
601 sum=(ptr[9]+ptr[13]+1) >> 1;cb[1]=sum; \
602 sum=(ptr[11]+ptr[15]+1) >> 1;cr[1]=sum; \
603 sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
604 sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
605 sum=(ptr[17]+ptr[21]+1) >> 1;cb[2]=sum; \
606 sum=(ptr[19]+ptr[23]+1) >> 1;cr[2]=sum; \
607 sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
608 sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum; \
609 sum=(ptr[25]+ptr[29]+1) >> 1;cb[3]=sum; \
610 sum=(ptr[27]+ptr[31]+1) >> 1;cr[3]=sum;
612 #define LINE_NOUV_AVG \
613 sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
614 sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=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[16]+ptr[18]+1) >> 1;lum[4]=sum; \
618 sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
619 sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
620 sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum;
622 #define DEINT_LINE_LUM(ptroff) \
623 sum=(-lum_m4[(ptroff)]+(lum_m3[(ptroff)]<<2)+(lum_m2[(ptroff)]<<1)+(lum_m1[(ptroff)]<<2)-lum[(ptroff)]); \
624 lum_m4[(ptroff)]=lum_m2[(ptroff)];\
625 lum_m2[(ptroff)]=cm[(sum+4)>>3];\
626 sum=(-lum_m4[(ptroff)+1]+(lum_m3[(ptroff)+1]<<2)+(lum_m2[(ptroff)+1]<<1)+(lum_m1[(ptroff)+1]<<2)-lum[(ptroff)+1]); \
627 lum_m4[(ptroff)+1]=lum_m2[(ptroff)+1];\
628 lum_m2[(ptroff)+1]=cm[(sum+4)>>3];\
629 sum=(-lum_m4[(ptroff)+2]+(lum_m3[(ptroff)+2]<<2)+(lum_m2[(ptroff)+2]<<1)+(lum_m1[(ptroff)+2]<<2)-lum[(ptroff)+2]); \
630 lum_m4[(ptroff)+2]=lum_m2[(ptroff)+2];\
631 lum_m2[(ptroff)+2]=cm[(sum+4)>>3];\
632 sum=(-lum_m4[(ptroff)+3]+(lum_m3[(ptroff)+3]<<2)+(lum_m2[(ptroff)+3]<<1)+(lum_m1[(ptroff)+3]<<2)-lum[(ptroff)+3]); \
633 lum_m4[(ptroff)+3]=lum_m2[(ptroff)+3];\
634 lum_m2[(ptroff)+3]=cm[(sum+4)>>3];
639 /* Read two fields separately. */
640 static int aiw_read_picture(VideoData *s, uint8_t *data)
642 uint8_t *ptr, *lum, *cb, *cr;
647 uint8_t* src = s->src_mem;
648 uint8_t *ptrend = &src[s->width*2];
650 cb=&lum[s->width*s->height];
651 cr=&cb[(s->width*s->height)/4];
652 if (s->deint == 0 && s->halfw == 0) {
653 while (read(s->fd,src,s->width*2) < 0) {
656 for (h = 0; h < s->height-2; h+=2) {
657 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
660 read(s->fd,src,s->width*2);
661 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
664 read(s->fd,src,s->width*2);
669 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
672 read(s->fd,src,s->width*2);
673 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
676 /* drop second field */
677 while (read(s->fd,src,s->width*2) < 0) {
680 for (h = 0; h < s->height - 1; h++) {
681 read(s->fd,src,s->width*2);
683 } else if (s->halfw == 1) {
700 movq_m2r(rounder,mm6);
702 while (read(s->fd,src,s->width*4) < 0) {
705 ptrend = &src[s->width*4];
706 for (h = 0; h < s->height-2; h+=2) {
707 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
710 read(s->fd,src,s->width*4);
712 movq_m2r(masker,mm5);
714 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
717 read(s->fd,src,s->width*4);
722 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
725 read(s->fd,src,s->width*4);
727 movq_m2r(masker,mm5);
729 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
732 /* drop second field */
733 while (read(s->fd,src,s->width*4) < 0) {
736 for (h = 0; h < s->height - 1; h++) {
737 read(s->fd,src,s->width*4);
740 uint8_t *lum_m1, *lum_m2, *lum_m3, *lum_m4;
747 movq_m2r(rounder,mm6);
750 uint8_t *cm = cropTbl + MAX_NEG_CROP;
753 /* read two fields and deinterlace them */
754 while (read(s->fd,src,s->width*2) < 0) {
757 for (h = 0; h < (s->height/2)-2; h+=2) {
758 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
761 read(s->fd,src,s->width*2);
762 /* skip a luminance line - will be filled in later */
764 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
767 /* skip a luminance line - will be filled in later */
769 read(s->fd,src,s->width*2);
774 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
777 /* skip a luminance line - will be filled in later */
779 read(s->fd,src,s->width*2);
780 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
789 while (read(s->fd,src,s->width*2) < 0) {
792 /* First (and last) two lines not interlaced */
793 for (h = 0; h < 2; h++) {
794 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
797 read(s->fd,src,s->width*2);
798 /* skip a luminance line */
801 lum_m1=&lum[-s->width];
802 lum_m2=&lum_m1[-s->width];
803 lum_m3=&lum_m2[-s->width];
804 memmove(s->lum_m4_mem,&lum_m3[-s->width],s->width);
805 for (; h < (s->height/2)-1; h++) {
806 lum_m4=s->lum_m4_mem;
807 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16,lum_m1+=16,lum_m2+=16,lum_m3+=16,lum_m4+=16) {
815 read(s->fd,src,s->width*2);
816 /* skip a luminance line */
821 // lum_m4 += s->width;
826 lum_m4=s->lum_m4_mem;
827 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, lum_m1+=16, lum_m2+=16, lum_m3+=16, lum_m4+=16) {
839 return s->frame_size;
842 static int aiw_close(VideoData *s)
844 av_freep(&s->lum_m4_mem);
845 av_freep(&s->src_mem);
849 int video_grab_init(void)
851 av_register_input_format(&video_grab_device_format);