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
20 #include <linux/videodev.h>
23 #include <sys/ioctl.h>
30 int frame_format; /* see VIDEO_PALETTE_xxx */
37 struct video_capability video_cap;
38 struct video_audio audio_saved;
40 struct video_mbuf gb_buffers;
41 struct video_mmap gb_buf;
44 /* ATI All In Wonder specific stuff */
45 /* XXX: remove and merge in libavcodec/imgconvert.c */
53 static int aiw_init(VideoData *s);
54 static int aiw_read_picture(VideoData *s, uint8_t *data);
55 static int aiw_close(VideoData *s);
57 static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
59 VideoData *s = s1->priv_data;
62 int video_fd, frame_size;
63 int ret, frame_rate, frame_rate_base;
65 struct video_audio audio;
66 const char *video_device;
68 if (!ap || ap->width <= 0 || ap->height <= 0 || ap->frame_rate <= 0)
73 frame_rate = ap->frame_rate;
74 frame_rate_base = ap->frame_rate_base;
76 st = av_new_stream(s1, 0);
82 s->frame_rate = frame_rate;
83 s->frame_rate_base = frame_rate_base;
85 video_device = ap->device;
87 video_device = "/dev/video";
88 video_fd = open(video_device, O_RDWR);
94 if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) {
99 if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {
100 fprintf(stderr, "Fatal: grab device does not handle capture\n");
104 desired_palette = -1;
105 if (st->codec.pix_fmt == PIX_FMT_YUV420P) {
106 desired_palette = VIDEO_PALETTE_YUV420P;
107 } else if (st->codec.pix_fmt == PIX_FMT_YUV422) {
108 desired_palette = VIDEO_PALETTE_YUV422;
109 } else if (st->codec.pix_fmt == PIX_FMT_BGR24) {
110 desired_palette = VIDEO_PALETTE_RGB24;
115 ioctl(video_fd, VIDIOCGAUDIO, &audio);
116 memcpy(&s->audio_saved, &audio, sizeof(audio));
117 audio.flags &= ~VIDEO_AUDIO_MUTE;
118 ioctl(video_fd, VIDIOCSAUDIO, &audio);
120 ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
122 /* try to use read based access */
123 struct video_window win;
124 struct video_picture pict;
134 ioctl(video_fd, VIDIOCSWIN, &win);
136 ioctl(video_fd, VIDIOCGPICT, &pict);
138 printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
145 /* try to choose a suitable video format */
146 pict.palette = desired_palette;
147 if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
148 pict.palette=VIDEO_PALETTE_YUV420P;
149 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
151 pict.palette=VIDEO_PALETTE_YUV422;
152 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
154 pict.palette=VIDEO_PALETTE_RGB24;
155 ret = ioctl(video_fd, VIDIOCSPICT, &pict);
162 s->frame_format = pict.palette;
165 ioctl(video_fd, VIDIOCCAPTURE, &val);
167 s->time_frame = av_gettime();
170 /* ATI All In Wonder automatic activation */
171 if (!strcmp(s->video_cap.name, "Km")) {
175 /* force 420P format because convertion from YUV422 to YUV420P
176 is done in this driver (ugly) */
177 s->frame_format = VIDEO_PALETTE_YUV420P;
180 s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0);
181 if ((unsigned char*)-1 == s->video_buf) {
186 s->time_frame = av_gettime();
188 /* start to grab the first frame */
189 s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
190 s->gb_buf.height = height;
191 s->gb_buf.width = width;
192 s->gb_buf.format = desired_palette;
194 if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf)) < 0) {
195 s->gb_buf.format = VIDEO_PALETTE_YUV420P;
197 ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
198 if (ret < 0 && errno != EAGAIN) {
200 s->gb_buf.format = VIDEO_PALETTE_YUV422;
202 ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
203 if (ret < 0 && errno != EAGAIN) {
205 s->gb_buf.format = VIDEO_PALETTE_RGB24;
206 ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
211 if (errno != EAGAIN) {
213 fprintf(stderr, "Fatal: grab device does not support suitable format\n");
215 fprintf(stderr,"Fatal: grab device does not receive any video signal\n");
219 s->frame_format = s->gb_buf.format;
223 switch(s->frame_format) {
224 case VIDEO_PALETTE_YUV420P:
225 frame_size = (width * height * 3) / 2;
226 st->codec.pix_fmt = PIX_FMT_YUV420P;
228 case VIDEO_PALETTE_YUV422:
229 frame_size = width * height * 2;
230 st->codec.pix_fmt = PIX_FMT_YUV422;
232 case VIDEO_PALETTE_RGB24:
233 frame_size = width * height * 3;
234 st->codec.pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
240 s->frame_size = frame_size;
242 st->codec.codec_type = CODEC_TYPE_VIDEO;
243 st->codec.codec_id = CODEC_ID_RAWVIDEO;
244 st->codec.width = width;
245 st->codec.height = height;
246 st->codec.frame_rate = frame_rate;
247 st->codec.frame_rate_base = frame_rate_base;
249 av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
259 static int v4l_mm_read_picture(VideoData *s, uint8_t *buf)
263 /* Setup to capture the next frame */
264 s->gb_buf.frame = (s->gb_frame + 1) % s->gb_buffers.frames;
265 if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) {
267 fprintf(stderr,"Cannot Sync\n");
269 perror("VIDIOCMCAPTURE");
273 while (ioctl(s->fd, VIDIOCSYNC, &s->gb_frame) < 0 &&
274 (errno == EAGAIN || errno == EINTR));
276 ptr = s->video_buf + s->gb_buffers.offsets[s->gb_frame];
277 memcpy(buf, ptr, s->frame_size);
279 /* This is now the grabbing frame */
280 s->gb_frame = s->gb_buf.frame;
282 return s->frame_size;
285 static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
287 VideoData *s = s1->priv_data;
288 int64_t curtime, delay;
290 int64_t per_frame = (int64_t_C(1000000) * s->frame_rate_base) / s->frame_rate;
292 /* Calculate the time of the next frame */
293 s->time_frame += per_frame;
295 /* wait based on the frame rate */
297 curtime = av_gettime();
298 delay = s->time_frame - curtime;
300 if (delay < -per_frame) {
301 /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */
302 s->time_frame += per_frame;
306 ts.tv_sec = delay / 1000000;
307 ts.tv_nsec = (delay % 1000000) * 1000;
308 nanosleep(&ts, NULL);
311 if (av_new_packet(pkt, s->frame_size) < 0)
314 pkt->pts = curtime & ((1LL << 48) - 1);
317 if (s->aiw_enabled) {
318 return aiw_read_picture(s, pkt->data);
319 } else if (s->use_mmap) {
320 return v4l_mm_read_picture(s, pkt->data);
322 if (read(s->fd, pkt->data, pkt->size) != pkt->size)
324 return s->frame_size;
328 static int grab_read_close(AVFormatContext *s1)
330 VideoData *s = s1->priv_data;
336 munmap(s->video_buf, s->gb_buffers.size);
338 /* mute audio. we must force it because the BTTV driver does not
339 return its state correctly */
340 s->audio_saved.flags |= VIDEO_AUDIO_MUTE;
341 ioctl(s->fd, VIDIOCSAUDIO, &s->audio_saved);
347 static AVInputFormat video_grab_device_format = {
355 .flags = AVFMT_NOFILE,
358 /* All in Wonder specific stuff */
359 /* XXX: remove and merge in libavcodec/imgconvert.c */
361 static int aiw_init(VideoData *s)
368 if ((width == s->video_cap.maxwidth && height == s->video_cap.maxheight) ||
369 (width == s->video_cap.maxwidth && height == s->video_cap.maxheight*2) ||
370 (width == s->video_cap.maxwidth/2 && height == s->video_cap.maxheight)) {
374 if (height == s->video_cap.maxheight*2) s->deint=1;
375 if (width == s->video_cap.maxwidth/2) s->halfw=1;
377 fprintf(stderr,"\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
378 fprintf(stderr," %dx%d %dx%d %dx%d\n\n",
379 s->video_cap.maxwidth,s->video_cap.maxheight,
380 s->video_cap.maxwidth,s->video_cap.maxheight*2,
381 s->video_cap.maxwidth/2,s->video_cap.maxheight);
386 s->src_mem = av_malloc(s->width*2);
388 s->src_mem = av_malloc(s->width*4);
390 if (!s->src_mem) goto fail;
392 s->lum_m4_mem = av_malloc(s->width);
397 av_freep(&s->src_mem);
398 av_freep(&s->lum_m4_mem);
403 #include "../libavcodec/i386/mmx.h"
405 #define LINE_WITH_UV \
406 movq_m2r(ptr[0],mm0); \
407 movq_m2r(ptr[8],mm1); \
408 movq_r2r(mm0, mm4); \
409 punpcklbw_r2r(mm1,mm0); \
410 punpckhbw_r2r(mm1,mm4); \
412 punpcklbw_r2r(mm4,mm0); \
413 punpckhbw_r2r(mm4,mm5); \
415 punpcklbw_r2r(mm5,mm1); \
416 movq_r2m(mm1,lum[0]); \
417 movq_m2r(ptr[16],mm2); \
418 movq_m2r(ptr[24],mm1); \
420 punpcklbw_r2r(mm1,mm2); \
421 punpckhbw_r2r(mm1,mm4); \
423 punpcklbw_r2r(mm4,mm2); \
424 punpckhbw_r2r(mm4,mm3); \
426 punpcklbw_r2r(mm3,mm1); \
427 movq_r2m(mm1,lum[8]); \
428 punpckhdq_r2r(mm2,mm0); \
429 punpckhdq_r2r(mm3,mm5); \
430 movq_r2m(mm0,cb[0]); \
434 movq_m2r(ptr[0],mm0);\
435 movq_m2r(ptr[8],mm1);\
437 punpcklbw_r2r(mm1,mm0); \
438 punpckhbw_r2r(mm1,mm4);\
440 punpcklbw_r2r(mm4,mm0);\
441 punpckhbw_r2r(mm4,mm5);\
443 punpcklbw_r2r(mm5,mm1);\
444 movq_r2m(mm1,lum[0]);\
445 movq_m2r(ptr[16],mm2);\
446 movq_m2r(ptr[24],mm1);\
448 punpcklbw_r2r(mm1,mm2);\
449 punpckhbw_r2r(mm1,mm4);\
451 punpcklbw_r2r(mm4,mm2);\
452 punpckhbw_r2r(mm4,mm3);\
454 punpcklbw_r2r(mm3,mm1);\
455 movq_r2m(mm1,lum[8]);
457 #define LINE_WITHUV_AVG \
458 movq_m2r(ptr[0], mm0);\
459 movq_m2r(ptr[8], mm1);\
461 punpcklbw_r2r(mm1,mm0);\
462 punpckhbw_r2r(mm1,mm4);\
464 punpcklbw_r2r(mm4,mm0);\
465 punpckhbw_r2r(mm4,mm5);\
468 punpcklbw_r2r(mm7,mm1);\
469 punpcklbw_r2r(mm7,mm2);\
473 packuswb_r2r(mm7,mm1);\
474 movd_r2m(mm1,lum[0]);\
475 movq_m2r(ptr[16],mm2);\
476 movq_m2r(ptr[24],mm1);\
478 punpcklbw_r2r(mm1,mm2);\
479 punpckhbw_r2r(mm1,mm4);\
481 punpcklbw_r2r(mm4,mm2);\
482 punpckhbw_r2r(mm4,mm3);\
485 punpcklbw_r2r(mm7,mm1);\
486 punpcklbw_r2r(mm7,mm4);\
490 packuswb_r2r(mm7,mm1);\
491 movd_r2m(mm1,lum[4]);\
492 punpckhbw_r2r(mm7,mm0);\
493 punpckhbw_r2r(mm7,mm2);\
497 packuswb_r2r(mm7,mm0);\
498 punpckhbw_r2r(mm7,mm5);\
499 punpckhbw_r2r(mm7,mm3);\
503 packuswb_r2r(mm7,mm5);\
504 movd_r2m(mm0,cb[0]);\
507 #define LINE_NOUV_AVG \
508 movq_m2r(ptr[0],mm0);\
509 movq_m2r(ptr[8],mm1);\
512 pmaddwd_r2r(mm6,mm0);\
513 pmaddwd_r2r(mm6,mm1);\
514 packssdw_r2r(mm1,mm0);\
517 movq_m2r(ptr[16],mm2);\
518 movq_m2r(ptr[24],mm3);\
521 pmaddwd_r2r(mm6,mm2);\
522 pmaddwd_r2r(mm6,mm3);\
523 packssdw_r2r(mm3,mm2);\
526 packuswb_r2r(mm2,mm0);\
527 movq_r2m(mm0,lum[0]);
529 #define DEINT_LINE_LUM(ptroff) \
530 movd_m2r(lum_m4[(ptroff)],mm0);\
531 movd_m2r(lum_m3[(ptroff)],mm1);\
532 movd_m2r(lum_m2[(ptroff)],mm2);\
533 movd_m2r(lum_m1[(ptroff)],mm3);\
534 movd_m2r(lum[(ptroff)],mm4);\
535 punpcklbw_r2r(mm7,mm0);\
536 movd_r2m(mm2,lum_m4[(ptroff)]);\
537 punpcklbw_r2r(mm7,mm1);\
538 punpcklbw_r2r(mm7,mm2);\
539 punpcklbw_r2r(mm7,mm3);\
540 punpcklbw_r2r(mm7,mm4);\
548 psubusw_r2r(mm0,mm1);\
550 packuswb_r2r(mm7,mm1);\
551 movd_r2m(mm1,lum_m2[(ptroff)]);
554 #include "../libavcodec/dsputil.h"
556 #define LINE_WITH_UV \
557 lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
558 cb[0]=ptr[1];cb[1]=ptr[5];\
559 cr[0]=ptr[3];cr[1]=ptr[7];\
560 lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
561 cb[2]=ptr[9];cb[3]=ptr[13];\
562 cr[2]=ptr[11];cr[3]=ptr[15];\
563 lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
564 cb[4]=ptr[17];cb[5]=ptr[21];\
565 cr[4]=ptr[19];cr[5]=ptr[23];\
566 lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];\
567 cb[6]=ptr[25];cb[7]=ptr[29];\
568 cr[6]=ptr[27];cr[7]=ptr[31];
571 lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
572 lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
573 lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
574 lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];
576 #define LINE_WITHUV_AVG \
577 sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
578 sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
579 sum=(ptr[1]+ptr[5]+1) >> 1;cb[0]=sum; \
580 sum=(ptr[3]+ptr[7]+1) >> 1;cr[0]=sum; \
581 sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
582 sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
583 sum=(ptr[9]+ptr[13]+1) >> 1;cb[1]=sum; \
584 sum=(ptr[11]+ptr[15]+1) >> 1;cr[1]=sum; \
585 sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
586 sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
587 sum=(ptr[17]+ptr[21]+1) >> 1;cb[2]=sum; \
588 sum=(ptr[19]+ptr[23]+1) >> 1;cr[2]=sum; \
589 sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
590 sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum; \
591 sum=(ptr[25]+ptr[29]+1) >> 1;cb[3]=sum; \
592 sum=(ptr[27]+ptr[31]+1) >> 1;cr[3]=sum;
594 #define LINE_NOUV_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[8]+ptr[10]+1) >> 1;lum[2]=sum; \
598 sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
599 sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
600 sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
601 sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
602 sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum;
604 #define DEINT_LINE_LUM(ptroff) \
605 sum=(-lum_m4[(ptroff)]+(lum_m3[(ptroff)]<<2)+(lum_m2[(ptroff)]<<1)+(lum_m1[(ptroff)]<<2)-lum[(ptroff)]); \
606 lum_m4[(ptroff)]=lum_m2[(ptroff)];\
607 lum_m2[(ptroff)]=cm[(sum+4)>>3];\
608 sum=(-lum_m4[(ptroff)+1]+(lum_m3[(ptroff)+1]<<2)+(lum_m2[(ptroff)+1]<<1)+(lum_m1[(ptroff)+1]<<2)-lum[(ptroff)+1]); \
609 lum_m4[(ptroff)+1]=lum_m2[(ptroff)+1];\
610 lum_m2[(ptroff)+1]=cm[(sum+4)>>3];\
611 sum=(-lum_m4[(ptroff)+2]+(lum_m3[(ptroff)+2]<<2)+(lum_m2[(ptroff)+2]<<1)+(lum_m1[(ptroff)+2]<<2)-lum[(ptroff)+2]); \
612 lum_m4[(ptroff)+2]=lum_m2[(ptroff)+2];\
613 lum_m2[(ptroff)+2]=cm[(sum+4)>>3];\
614 sum=(-lum_m4[(ptroff)+3]+(lum_m3[(ptroff)+3]<<2)+(lum_m2[(ptroff)+3]<<1)+(lum_m1[(ptroff)+3]<<2)-lum[(ptroff)+3]); \
615 lum_m4[(ptroff)+3]=lum_m2[(ptroff)+3];\
616 lum_m2[(ptroff)+3]=cm[(sum+4)>>3];
621 /* Read two fields separately. */
622 static int aiw_read_picture(VideoData *s, uint8_t *data)
624 uint8_t *ptr, *lum, *cb, *cr;
629 uint8_t* src = s->src_mem;
630 uint8_t *ptrend = &src[s->width*2];
632 cb=&lum[s->width*s->height];
633 cr=&cb[(s->width*s->height)/4];
634 if (s->deint == 0 && s->halfw == 0) {
635 while (read(s->fd,src,s->width*2) < 0) {
638 for (h = 0; h < s->height-2; h+=2) {
639 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
642 read(s->fd,src,s->width*2);
643 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
646 read(s->fd,src,s->width*2);
651 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
654 read(s->fd,src,s->width*2);
655 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
658 /* drop second field */
659 while (read(s->fd,src,s->width*2) < 0) {
662 for (h = 0; h < s->height - 1; h++) {
663 read(s->fd,src,s->width*2);
665 } else if (s->halfw == 1) {
682 movq_m2r(rounder,mm6);
684 while (read(s->fd,src,s->width*4) < 0) {
687 ptrend = &src[s->width*4];
688 for (h = 0; h < s->height-2; h+=2) {
689 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
692 read(s->fd,src,s->width*4);
694 movq_m2r(masker,mm5);
696 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
699 read(s->fd,src,s->width*4);
704 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
707 read(s->fd,src,s->width*4);
709 movq_m2r(masker,mm5);
711 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
714 /* drop second field */
715 while (read(s->fd,src,s->width*4) < 0) {
718 for (h = 0; h < s->height - 1; h++) {
719 read(s->fd,src,s->width*4);
722 uint8_t *lum_m1, *lum_m2, *lum_m3, *lum_m4;
729 movq_m2r(rounder,mm6);
732 uint8_t *cm = cropTbl + MAX_NEG_CROP;
735 /* read two fields and deinterlace them */
736 while (read(s->fd,src,s->width*2) < 0) {
739 for (h = 0; h < (s->height/2)-2; h+=2) {
740 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
743 read(s->fd,src,s->width*2);
744 /* skip a luminance line - will be filled in later */
746 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
749 /* skip a luminance line - will be filled in later */
751 read(s->fd,src,s->width*2);
756 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
759 /* skip a luminance line - will be filled in later */
761 read(s->fd,src,s->width*2);
762 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
771 while (read(s->fd,src,s->width*2) < 0) {
774 /* First (and last) two lines not interlaced */
775 for (h = 0; h < 2; h++) {
776 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
779 read(s->fd,src,s->width*2);
780 /* skip a luminance line */
783 lum_m1=&lum[-s->width];
784 lum_m2=&lum_m1[-s->width];
785 lum_m3=&lum_m2[-s->width];
786 memmove(s->lum_m4_mem,&lum_m3[-s->width],s->width);
787 for (; h < (s->height/2)-1; h++) {
788 lum_m4=s->lum_m4_mem;
789 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16,lum_m1+=16,lum_m2+=16,lum_m3+=16,lum_m4+=16) {
797 read(s->fd,src,s->width*2);
798 /* skip a luminance line */
803 // lum_m4 += s->width;
808 lum_m4=s->lum_m4_mem;
809 for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, lum_m1+=16, lum_m2+=16, lum_m3+=16, lum_m4+=16) {
821 return s->frame_size;
824 static int aiw_close(VideoData *s)
826 av_freep(&s->lum_m4_mem);
827 av_freep(&s->src_mem);
831 int video_grab_init(void)
833 av_register_input_format(&video_grab_device_format);