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 */
36 struct video_capability video_cap
;
37 struct video_audio audio_saved
;
39 struct video_mbuf gb_buffers
;
40 struct video_mmap gb_buf
;
43 /* ATI All In Wonder specific stuff */
44 /* XXX: remove and merge in libavcodec/imgconvert.c */
52 static int aiw_init(VideoData
*s
);
53 static int aiw_read_picture(VideoData
*s
, uint8_t *data
);
54 static int aiw_close(VideoData
*s
);
56 const char *v4l_device
= "/dev/video";
58 static int grab_read_header(AVFormatContext
*s1
, AVFormatParameters
*ap
)
60 VideoData
*s
= s1
->priv_data
;
63 int video_fd
, frame_size
;
66 struct video_audio audio
;
68 if (!ap
|| ap
->width
<= 0 || ap
->height
<= 0 || ap
->frame_rate
<= 0)
73 frame_rate
= ap
->frame_rate
;
75 st
= av_new_stream(s1
, 0);
81 s
->frame_rate
= frame_rate
;
83 video_fd
= open(v4l_device
, O_RDWR
);
89 if (ioctl(video_fd
,VIDIOCGCAP
, &s
->video_cap
) < 0) {
94 if (!(s
->video_cap
.type
& VID_TYPE_CAPTURE
)) {
95 fprintf(stderr
, "Fatal: grab device does not handle capture\n");
100 if (st
->codec
.pix_fmt
== PIX_FMT_YUV420P
) {
101 desired_palette
= VIDEO_PALETTE_YUV420P
;
102 } else if (st
->codec
.pix_fmt
== PIX_FMT_YUV422
) {
103 desired_palette
= VIDEO_PALETTE_YUV422
;
104 } else if (st
->codec
.pix_fmt
== PIX_FMT_BGR24
) {
105 desired_palette
= VIDEO_PALETTE_RGB24
;
110 ioctl(video_fd
, VIDIOCGAUDIO
, &audio
);
111 memcpy(&s
->audio_saved
, &audio
, sizeof(audio
));
112 audio
.flags
&= ~VIDEO_AUDIO_MUTE
;
113 ioctl(video_fd
, VIDIOCSAUDIO
, &audio
);
115 ret
= ioctl(video_fd
,VIDIOCGMBUF
,&s
->gb_buffers
);
117 /* try to use read based access */
118 struct video_window win
;
119 struct video_picture pict
;
129 ioctl(video_fd
, VIDIOCSWIN
, &win
);
131 ioctl(video_fd
, VIDIOCGPICT
, &pict
);
133 printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
140 /* try to choose a suitable video format */
141 pict
.palette
= desired_palette
;
142 if (desired_palette
== -1 || (ret
= ioctl(video_fd
, VIDIOCSPICT
, &pict
)) < 0) {
143 pict
.palette
=VIDEO_PALETTE_YUV420P
;
144 ret
= ioctl(video_fd
, VIDIOCSPICT
, &pict
);
146 pict
.palette
=VIDEO_PALETTE_YUV422
;
147 ret
= ioctl(video_fd
, VIDIOCSPICT
, &pict
);
149 pict
.palette
=VIDEO_PALETTE_RGB24
;
150 ret
= ioctl(video_fd
, VIDIOCSPICT
, &pict
);
157 s
->frame_format
= pict
.palette
;
160 ioctl(video_fd
, VIDIOCCAPTURE
, &val
);
162 s
->time_frame
= av_gettime();
165 /* ATI All In Wonder automatic activation */
166 if (!strcmp(s
->video_cap
.name
, "Km")) {
170 /* force 420P format because convertion from YUV422 to YUV420P
171 is done in this driver (ugly) */
172 s
->frame_format
= VIDEO_PALETTE_YUV420P
;
175 s
->video_buf
= mmap(0,s
->gb_buffers
.size
,PROT_READ
|PROT_WRITE
,MAP_SHARED
,video_fd
,0);
176 if ((unsigned char*)-1 == s
->video_buf
) {
181 s
->time_frame
= av_gettime();
183 /* start to grab the first frame */
184 s
->gb_buf
.frame
= s
->gb_frame
% s
->gb_buffers
.frames
;
185 s
->gb_buf
.height
= height
;
186 s
->gb_buf
.width
= width
;
187 s
->gb_buf
.format
= desired_palette
;
189 if (desired_palette
== -1 || (ret
= ioctl(video_fd
, VIDIOCMCAPTURE
, &s
->gb_buf
)) < 0) {
190 s
->gb_buf
.format
= VIDEO_PALETTE_YUV420P
;
192 ret
= ioctl(video_fd
, VIDIOCMCAPTURE
, &s
->gb_buf
);
193 if (ret
< 0 && errno
!= EAGAIN
) {
195 s
->gb_buf
.format
= VIDEO_PALETTE_YUV422
;
197 ret
= ioctl(video_fd
, VIDIOCMCAPTURE
, &s
->gb_buf
);
198 if (ret
< 0 && errno
!= EAGAIN
) {
200 s
->gb_buf
.format
= VIDEO_PALETTE_RGB24
;
201 ret
= ioctl(video_fd
, VIDIOCMCAPTURE
, &s
->gb_buf
);
206 if (errno
!= EAGAIN
) {
208 fprintf(stderr
, "Fatal: grab device does not support suitable format\n");
210 fprintf(stderr
,"Fatal: grab device does not receive any video signal\n");
214 s
->frame_format
= s
->gb_buf
.format
;
218 switch(s
->frame_format
) {
219 case VIDEO_PALETTE_YUV420P
:
220 frame_size
= (width
* height
* 3) / 2;
221 st
->codec
.pix_fmt
= PIX_FMT_YUV420P
;
223 case VIDEO_PALETTE_YUV422
:
224 frame_size
= width
* height
* 2;
225 st
->codec
.pix_fmt
= PIX_FMT_YUV422
;
227 case VIDEO_PALETTE_RGB24
:
228 frame_size
= width
* height
* 3;
229 st
->codec
.pix_fmt
= PIX_FMT_BGR24
; /* NOTE: v4l uses BGR24, not RGB24 ! */
235 s
->frame_size
= frame_size
;
237 st
->codec
.codec_type
= CODEC_TYPE_VIDEO
;
238 st
->codec
.codec_id
= CODEC_ID_RAWVIDEO
;
239 st
->codec
.width
= width
;
240 st
->codec
.height
= height
;
241 st
->codec
.frame_rate
= frame_rate
;
243 av_set_pts_info(s1
, 48, 1, 1000000); /* 48 bits pts in us */
253 static int v4l_mm_read_picture(VideoData
*s
, UINT8
*buf
)
257 /* Setup to capture the next frame */
258 s
->gb_buf
.frame
= (s
->gb_frame
+ 1) % s
->gb_buffers
.frames
;
259 if (ioctl(s
->fd
, VIDIOCMCAPTURE
, &s
->gb_buf
) < 0) {
261 fprintf(stderr
,"Cannot Sync\n");
263 perror("VIDIOCMCAPTURE");
267 while (ioctl(s
->fd
, VIDIOCSYNC
, &s
->gb_frame
) < 0 &&
268 (errno
== EAGAIN
|| errno
== EINTR
));
270 ptr
= s
->video_buf
+ s
->gb_buffers
.offsets
[s
->gb_frame
];
271 memcpy(buf
, ptr
, s
->frame_size
);
273 /* This is now the grabbing frame */
274 s
->gb_frame
= s
->gb_buf
.frame
;
276 return s
->frame_size
;
279 static int grab_read_packet(AVFormatContext
*s1
, AVPacket
*pkt
)
281 VideoData
*s
= s1
->priv_data
;
282 INT64 curtime
, delay
;
284 INT64 per_frame
= (INT64_C(1000000) * FRAME_RATE_BASE
) / s
->frame_rate
;
286 /* Calculate the time of the next frame */
287 s
->time_frame
+= per_frame
;
289 /* wait based on the frame rate */
291 curtime
= av_gettime();
292 delay
= s
->time_frame
- curtime
;
294 if (delay
< -per_frame
) {
295 /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */
296 s
->time_frame
+= per_frame
;
300 ts
.tv_sec
= delay
/ 1000000;
301 ts
.tv_nsec
= (delay
% 1000000) * 1000;
302 nanosleep(&ts
, NULL
);
305 if (av_new_packet(pkt
, s
->frame_size
) < 0)
308 pkt
->pts
= curtime
& ((1LL << 48) - 1);
311 if (s
->aiw_enabled
) {
312 return aiw_read_picture(s
, pkt
->data
);
313 } else if (s
->use_mmap
) {
314 return v4l_mm_read_picture(s
, pkt
->data
);
316 if (read(s
->fd
, pkt
->data
, pkt
->size
) != pkt
->size
)
318 return s
->frame_size
;
322 static int grab_read_close(AVFormatContext
*s1
)
324 VideoData
*s
= s1
->priv_data
;
330 munmap(s
->video_buf
, s
->gb_buffers
.size
);
332 /* mute audio. we must force it because the BTTV driver does not
333 return its state correctly */
334 s
->audio_saved
.flags
|= VIDEO_AUDIO_MUTE
;
335 ioctl(s
->fd
, VIDIOCSAUDIO
, &s
->audio_saved
);
341 static AVInputFormat video_grab_device_format
= {
349 .flags
= AVFMT_NOFILE
,
352 /* All in Wonder specific stuff */
353 /* XXX: remove and merge in libavcodec/imgconvert.c */
355 static int aiw_init(VideoData
*s
)
362 if ((width
== s
->video_cap
.maxwidth
&& height
== s
->video_cap
.maxheight
) ||
363 (width
== s
->video_cap
.maxwidth
&& height
== s
->video_cap
.maxheight
*2) ||
364 (width
== s
->video_cap
.maxwidth
/2 && height
== s
->video_cap
.maxheight
)) {
368 if (height
== s
->video_cap
.maxheight
*2) s
->deint
=1;
369 if (width
== s
->video_cap
.maxwidth
/2) s
->halfw
=1;
371 fprintf(stderr
,"\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
372 fprintf(stderr
," %dx%d %dx%d %dx%d\n\n",
373 s
->video_cap
.maxwidth
,s
->video_cap
.maxheight
,
374 s
->video_cap
.maxwidth
,s
->video_cap
.maxheight
*2,
375 s
->video_cap
.maxwidth
/2,s
->video_cap
.maxheight
);
380 s
->src_mem
= av_malloc(s
->width
*2);
382 s
->src_mem
= av_malloc(s
->width
*4);
384 if (!s
->src_mem
) goto fail
;
386 s
->lum_m4_mem
= av_malloc(s
->width
);
391 av_freep(&s
->src_mem
);
392 av_freep(&s
->lum_m4_mem
);
397 #include "../libavcodec/i386/mmx.h"
399 #define LINE_WITH_UV \
400 movq_m2r(ptr[0],mm0); \
401 movq_m2r(ptr[8],mm1); \
402 movq_r2r(mm0, mm4); \
403 punpcklbw_r2r(mm1,mm0); \
404 punpckhbw_r2r(mm1,mm4); \
406 punpcklbw_r2r(mm4,mm0); \
407 punpckhbw_r2r(mm4,mm5); \
409 punpcklbw_r2r(mm5,mm1); \
410 movq_r2m(mm1,lum[0]); \
411 movq_m2r(ptr[16],mm2); \
412 movq_m2r(ptr[24],mm1); \
414 punpcklbw_r2r(mm1,mm2); \
415 punpckhbw_r2r(mm1,mm4); \
417 punpcklbw_r2r(mm4,mm2); \
418 punpckhbw_r2r(mm4,mm3); \
420 punpcklbw_r2r(mm3,mm1); \
421 movq_r2m(mm1,lum[8]); \
422 punpckhdq_r2r(mm2,mm0); \
423 punpckhdq_r2r(mm3,mm5); \
424 movq_r2m(mm0,cb[0]); \
428 movq_m2r(ptr[0],mm0);\
429 movq_m2r(ptr[8],mm1);\
431 punpcklbw_r2r(mm1,mm0); \
432 punpckhbw_r2r(mm1,mm4);\
434 punpcklbw_r2r(mm4,mm0);\
435 punpckhbw_r2r(mm4,mm5);\
437 punpcklbw_r2r(mm5,mm1);\
438 movq_r2m(mm1,lum[0]);\
439 movq_m2r(ptr[16],mm2);\
440 movq_m2r(ptr[24],mm1);\
442 punpcklbw_r2r(mm1,mm2);\
443 punpckhbw_r2r(mm1,mm4);\
445 punpcklbw_r2r(mm4,mm2);\
446 punpckhbw_r2r(mm4,mm3);\
448 punpcklbw_r2r(mm3,mm1);\
449 movq_r2m(mm1,lum[8]);
451 #define LINE_WITHUV_AVG \
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);\
462 punpcklbw_r2r(mm7,mm1);\
463 punpcklbw_r2r(mm7,mm2);\
467 packuswb_r2r(mm7,mm1);\
468 movd_r2m(mm1,lum[0]);\
469 movq_m2r(ptr[16],mm2);\
470 movq_m2r(ptr[24],mm1);\
472 punpcklbw_r2r(mm1,mm2);\
473 punpckhbw_r2r(mm1,mm4);\
475 punpcklbw_r2r(mm4,mm2);\
476 punpckhbw_r2r(mm4,mm3);\
479 punpcklbw_r2r(mm7,mm1);\
480 punpcklbw_r2r(mm7,mm4);\
484 packuswb_r2r(mm7,mm1);\
485 movd_r2m(mm1,lum[4]);\
486 punpckhbw_r2r(mm7,mm0);\
487 punpckhbw_r2r(mm7,mm2);\
491 packuswb_r2r(mm7,mm0);\
492 punpckhbw_r2r(mm7,mm5);\
493 punpckhbw_r2r(mm7,mm3);\
497 packuswb_r2r(mm7,mm5);\
498 movd_r2m(mm0,cb[0]);\
501 #define LINE_NOUV_AVG \
502 movq_m2r(ptr[0],mm0);\
503 movq_m2r(ptr[8],mm1);\
506 pmaddwd_r2r(mm6,mm0);\
507 pmaddwd_r2r(mm6,mm1);\
508 packssdw_r2r(mm1,mm0);\
511 movq_m2r(ptr[16],mm2);\
512 movq_m2r(ptr[24],mm3);\
515 pmaddwd_r2r(mm6,mm2);\
516 pmaddwd_r2r(mm6,mm3);\
517 packssdw_r2r(mm3,mm2);\
520 packuswb_r2r(mm2,mm0);\
521 movq_r2m(mm0,lum[0]);
523 #define DEINT_LINE_LUM(ptroff) \
524 movd_m2r(lum_m4[(ptroff)],mm0);\
525 movd_m2r(lum_m3[(ptroff)],mm1);\
526 movd_m2r(lum_m2[(ptroff)],mm2);\
527 movd_m2r(lum_m1[(ptroff)],mm3);\
528 movd_m2r(lum[(ptroff)],mm4);\
529 punpcklbw_r2r(mm7,mm0);\
530 movd_r2m(mm2,lum_m4[(ptroff)]);\
531 punpcklbw_r2r(mm7,mm1);\
532 punpcklbw_r2r(mm7,mm2);\
533 punpcklbw_r2r(mm7,mm3);\
534 punpcklbw_r2r(mm7,mm4);\
542 psubusw_r2r(mm0,mm1);\
544 packuswb_r2r(mm7,mm1);\
545 movd_r2m(mm1,lum_m2[(ptroff)]);
548 #include "../libavcodec/dsputil.h"
550 #define LINE_WITH_UV \
551 lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
552 cb[0]=ptr[1];cb[1]=ptr[5];\
553 cr[0]=ptr[3];cr[1]=ptr[7];\
554 lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
555 cb[2]=ptr[9];cb[3]=ptr[13];\
556 cr[2]=ptr[11];cr[3]=ptr[15];\
557 lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
558 cb[4]=ptr[17];cb[5]=ptr[21];\
559 cr[4]=ptr[19];cr[5]=ptr[23];\
560 lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];\
561 cb[6]=ptr[25];cb[7]=ptr[29];\
562 cr[6]=ptr[27];cr[7]=ptr[31];
565 lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
566 lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
567 lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
568 lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];
570 #define LINE_WITHUV_AVG \
571 sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
572 sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
573 sum=(ptr[1]+ptr[5]+1) >> 1;cb[0]=sum; \
574 sum=(ptr[3]+ptr[7]+1) >> 1;cr[0]=sum; \
575 sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
576 sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
577 sum=(ptr[9]+ptr[13]+1) >> 1;cb[1]=sum; \
578 sum=(ptr[11]+ptr[15]+1) >> 1;cr[1]=sum; \
579 sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
580 sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
581 sum=(ptr[17]+ptr[21]+1) >> 1;cb[2]=sum; \
582 sum=(ptr[19]+ptr[23]+1) >> 1;cr[2]=sum; \
583 sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
584 sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum; \
585 sum=(ptr[25]+ptr[29]+1) >> 1;cb[3]=sum; \
586 sum=(ptr[27]+ptr[31]+1) >> 1;cr[3]=sum;
588 #define LINE_NOUV_AVG \
589 sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
590 sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
591 sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
592 sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
593 sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
594 sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
595 sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
596 sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum;
598 #define DEINT_LINE_LUM(ptroff) \
599 sum=(-lum_m4[(ptroff)]+(lum_m3[(ptroff)]<<2)+(lum_m2[(ptroff)]<<1)+(lum_m1[(ptroff)]<<2)-lum[(ptroff)]); \
600 lum_m4[(ptroff)]=lum_m2[(ptroff)];\
601 lum_m2[(ptroff)]=cm[(sum+4)>>3];\
602 sum=(-lum_m4[(ptroff)+1]+(lum_m3[(ptroff)+1]<<2)+(lum_m2[(ptroff)+1]<<1)+(lum_m1[(ptroff)+1]<<2)-lum[(ptroff)+1]); \
603 lum_m4[(ptroff)+1]=lum_m2[(ptroff)+1];\
604 lum_m2[(ptroff)+1]=cm[(sum+4)>>3];\
605 sum=(-lum_m4[(ptroff)+2]+(lum_m3[(ptroff)+2]<<2)+(lum_m2[(ptroff)+2]<<1)+(lum_m1[(ptroff)+2]<<2)-lum[(ptroff)+2]); \
606 lum_m4[(ptroff)+2]=lum_m2[(ptroff)+2];\
607 lum_m2[(ptroff)+2]=cm[(sum+4)>>3];\
608 sum=(-lum_m4[(ptroff)+3]+(lum_m3[(ptroff)+3]<<2)+(lum_m2[(ptroff)+3]<<1)+(lum_m1[(ptroff)+3]<<2)-lum[(ptroff)+3]); \
609 lum_m4[(ptroff)+3]=lum_m2[(ptroff)+3];\
610 lum_m2[(ptroff)+3]=cm[(sum+4)>>3];
615 /* Read two fields separately. */
616 static int aiw_read_picture(VideoData
*s
, uint8_t *data
)
618 UINT8
*ptr
, *lum
, *cb
, *cr
;
623 UINT8
* src
= s
->src_mem
;
624 UINT8
*ptrend
= &src
[s
->width
*2];
626 cb
=&lum
[s
->width
*s
->height
];
627 cr
=&cb
[(s
->width
*s
->height
)/4];
628 if (s
->deint
== 0 && s
->halfw
== 0) {
629 while (read(s
->fd
,src
,s
->width
*2) < 0) {
632 for (h
= 0; h
< s
->height
-2; h
+=2) {
633 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=16, cb
+=8, cr
+=8) {
636 read(s
->fd
,src
,s
->width
*2);
637 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=16) {
640 read(s
->fd
,src
,s
->width
*2);
645 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=16, cb
+=8, cr
+=8) {
648 read(s
->fd
,src
,s
->width
*2);
649 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=16) {
652 /* drop second field */
653 while (read(s
->fd
,src
,s
->width
*2) < 0) {
656 for (h
= 0; h
< s
->height
- 1; h
++) {
657 read(s
->fd
,src
,s
->width
*2);
659 } else if (s
->halfw
== 1) {
676 movq_m2r(rounder
,mm6
);
678 while (read(s
->fd
,src
,s
->width
*4) < 0) {
681 ptrend
= &src
[s
->width
*4];
682 for (h
= 0; h
< s
->height
-2; h
+=2) {
683 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=8, cb
+=4, cr
+=4) {
686 read(s
->fd
,src
,s
->width
*4);
688 movq_m2r(masker
,mm5
);
690 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=8) {
693 read(s
->fd
,src
,s
->width
*4);
698 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=8, cb
+=4, cr
+=4) {
701 read(s
->fd
,src
,s
->width
*4);
703 movq_m2r(masker
,mm5
);
705 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=8) {
708 /* drop second field */
709 while (read(s
->fd
,src
,s
->width
*4) < 0) {
712 for (h
= 0; h
< s
->height
- 1; h
++) {
713 read(s
->fd
,src
,s
->width
*4);
716 UINT8
*lum_m1
, *lum_m2
, *lum_m3
, *lum_m4
;
723 movq_m2r(rounder
,mm6
);
726 UINT8
*cm
= cropTbl
+ MAX_NEG_CROP
;
729 /* read two fields and deinterlace them */
730 while (read(s
->fd
,src
,s
->width
*2) < 0) {
733 for (h
= 0; h
< (s
->height
/2)-2; h
+=2) {
734 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=16, cb
+=8, cr
+=8) {
737 read(s
->fd
,src
,s
->width
*2);
738 /* skip a luminance line - will be filled in later */
740 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=16, cb
+=8, cr
+=8) {
743 /* skip a luminance line - will be filled in later */
745 read(s
->fd
,src
,s
->width
*2);
750 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=16, cb
+=8, cr
+=8) {
753 /* skip a luminance line - will be filled in later */
755 read(s
->fd
,src
,s
->width
*2);
756 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=16, cb
+=8, cr
+=8) {
765 while (read(s
->fd
,src
,s
->width
*2) < 0) {
768 /* First (and last) two lines not interlaced */
769 for (h
= 0; h
< 2; h
++) {
770 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=16) {
773 read(s
->fd
,src
,s
->width
*2);
774 /* skip a luminance line */
777 lum_m1
=&lum
[-s
->width
];
778 lum_m2
=&lum_m1
[-s
->width
];
779 lum_m3
=&lum_m2
[-s
->width
];
780 memmove(s
->lum_m4_mem
,&lum_m3
[-s
->width
],s
->width
);
781 for (; h
< (s
->height
/2)-1; h
++) {
782 lum_m4
=s
->lum_m4_mem
;
783 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=16,lum_m1
+=16,lum_m2
+=16,lum_m3
+=16,lum_m4
+=16) {
791 read(s
->fd
,src
,s
->width
*2);
792 /* skip a luminance line */
797 // lum_m4 += s->width;
802 lum_m4
=s
->lum_m4_mem
;
803 for (ptr
= &src
[0]; ptr
< ptrend
; ptr
+=32, lum
+=16, lum_m1
+=16, lum_m2
+=16, lum_m3
+=16, lum_m4
+=16) {
815 return s
->frame_size
;
818 static int aiw_close(VideoData
*s
)
820 av_freep(&s
->lum_m4_mem
);
821 av_freep(&s
->src_mem
);
825 int video_grab_init(void)
827 av_register_input_format(&video_grab_device_format
);