2 * DirectShow capture services (QCAP.DLL)
4 * Copyright 2005 Maarten Lankhorst
6 * This file contains the part of the vfw capture interface that
7 * does the actual Video4Linux(1/2) stuff required for capturing
8 * and setting/getting media format..
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
35 #ifdef HAVE_SYS_IOCTL_H
36 #include <sys/ioctl.h>
38 #ifdef HAVE_SYS_MMAN_H
42 #ifdef HAVE_SYS_TIME_H
45 #ifdef HAVE_ASM_TYPES_H
46 #include <asm/types.h>
51 #ifdef HAVE_LINUX_VIDEODEV_H
52 #include <linux/videodev.h>
66 #include "wine/debug.h"
67 #include "wine/library.h"
70 #include "qcap_main.h"
72 WINE_DEFAULT_DEBUG_CHANNEL(qcap_v4l);
74 #if defined(HAVE_LINUX_VIDEODEV_H) || defined(HAVE_LIBV4L1_H)
76 static typeof(open) *video_open = open;
77 static typeof(close) *video_close = close;
78 static typeof(ioctl) *video_ioctl = ioctl;
79 static typeof(read) *video_read = read;
80 static typeof(mmap) *video_mmap = mmap;
81 static typeof(munmap) *video_munmap = munmap;
83 static void video_init(void)
86 static void *video_lib;
90 video_lib = wine_dlopen(SONAME_LIBV4L1, RTLD_NOW, NULL, 0);
93 video_open = wine_dlsym(video_lib, "v4l1_open", NULL, 0);
94 video_close = wine_dlsym(video_lib, "v4l1_close", NULL, 0);
95 video_ioctl = wine_dlsym(video_lib, "v4l1_ioctl", NULL, 0);
96 video_read = wine_dlsym(video_lib, "v4l1_read", NULL, 0);
97 video_mmap = wine_dlsym(video_lib, "v4l1_mmap", NULL, 0);
98 video_munmap = wine_dlsym(video_lib, "v4l1_munmap", NULL, 0);
102 typedef void (* Renderer)(const Capture *, LPBYTE bufferin, const BYTE *stream);
106 UINT width, height, bitDepth, fps, outputwidth, outputheight;
109 CRITICAL_SECTION CritSect;
113 int iscommitted, stopped;
114 struct video_picture pict;
115 int dbrightness, dhue, dcolour, dcontrast;
118 struct video_mmap *grab_buf;
119 struct video_mbuf gb_buffers;
140 static void renderer_RGB(const Capture *capBox, LPBYTE bufferin, const BYTE *stream);
141 static void renderer_YUV(const Capture *capBox, LPBYTE bufferin, const BYTE *stream);
143 static const struct renderlist renderlist_V4l[] = {
144 { 0, "NULL renderer", NULL },
145 { 8, "Gray scales", NULL }, /* 1, Don't support */
146 { 0, "High 240 cube (BT848)", NULL }, /* 2, Don't support */
147 { 16, "16 bit RGB (565)", NULL }, /* 3, Don't support */
148 { 24, "24 bit RGB values", renderer_RGB }, /* 4, Supported, */
149 { 32, "32 bit RGB values", renderer_RGB }, /* 5, Supported */
150 { 16, "15 bit RGB (555)", NULL }, /* 6, Don't support */
151 { 16, "YUV 422 (Not P)", renderer_YUV }, /* 7, Supported */
152 { 16, "YUYV (Not P)", renderer_YUV }, /* 8, Supported */
153 { 16, "UYVY (Not P)", renderer_YUV }, /* 9, Supported */
154 { 16, "YUV 420 (Not P)", NULL }, /* 10, Not supported, if I had to guess it's YYUYYV */
155 { 12, "YUV 411 (Not P)", renderer_YUV }, /* 11, Supported */
156 { 0, "Raw capturing (BT848)", NULL }, /* 12, Don't support */
157 { 16, "YUV 422 (Planar)", renderer_YUV }, /* 13, Supported */
158 { 12, "YUV 411 (Planar)", renderer_YUV }, /* 14, Supported */
159 { 12, "YUV 420 (Planar)", renderer_YUV }, /* 15, Supported */
160 { 10, "YUV 410 (Planar)", renderer_YUV }, /* 16, Supported */
161 /* FIXME: add YUV420 support */
165 static const int fallback_V4l[] = { 4, 5, 7, 8, 9, 13, 15, 14, 16, 11, -1 };
166 /* Fallback: First try raw formats (Should try yuv first perhaps?), then yuv */
168 /* static const Capture defbox; */
170 static int xioctl(int fd, int request, void * arg)
175 r = video_ioctl (fd, request, arg);
176 } while (-1 == r && EINTR == errno);
181 /* Prepare the capture buffers */
182 static HRESULT V4l_Prepare(Capture *capBox)
184 TRACE("%p: Preparing for %dx%d resolution\n", capBox, capBox->width, capBox->height);
188 if (xioctl(capBox->fd, VIDIOCGMBUF, &capBox->gb_buffers) != -1 &&
189 capBox->gb_buffers.frames)
191 capBox->buffers = capBox->gb_buffers.frames;
192 if (capBox->gb_buffers.frames > 1)
194 TRACE("%p: Using %d/%d buffers\n", capBox,
195 capBox->buffers, capBox->gb_buffers.frames);
197 capBox->pmap = video_mmap( 0, capBox->gb_buffers.size, PROT_READ|PROT_WRITE,
198 MAP_SHARED, capBox->fd, 0 );
199 if (capBox->pmap != MAP_FAILED)
203 capBox->grab_buf = CoTaskMemAlloc(sizeof(struct video_mmap) * capBox->buffers);
204 if (!capBox->grab_buf)
206 video_munmap(capBox->pmap, capBox->gb_buffers.size);
207 return E_OUTOFMEMORY;
210 /* Setup mmap capture buffers. */
211 for (i = 0; i < capBox->buffers; i++)
213 capBox->grab_buf[i].format = capBox->pict.palette;
214 capBox->grab_buf[i].frame = i;
215 capBox->grab_buf[i].width = capBox->width;
216 capBox->grab_buf[i].height = capBox->height;
224 capBox->imagesize = renderlist_V4l[capBox->pict.palette].depth *
225 capBox->height * capBox->width / 8;
226 capBox->grab_data = CoTaskMemAlloc(capBox->imagesize);
227 if (!capBox->grab_data)
228 return E_OUTOFMEMORY;
230 TRACE("Using mmap: %d\n", capBox->mmap);
234 static void V4l_Unprepare(Capture *capBox)
238 for (capBox->curframe = 0; capBox->curframe < capBox->buffers; capBox->curframe++)
239 xioctl(capBox->fd, VIDIOCSYNC, &capBox->grab_buf[capBox->curframe]);
240 video_munmap(capBox->pmap, capBox->gb_buffers.size);
241 CoTaskMemFree(capBox->grab_buf);
244 CoTaskMemFree(capBox->grab_data);
247 HRESULT qcap_driver_destroy(Capture *capBox)
249 TRACE("%p\n", capBox);
251 if( capBox->fd != -1 )
252 video_close(capBox->fd);
253 capBox->CritSect.DebugInfo->Spare[0] = 0;
254 DeleteCriticalSection(&capBox->CritSect);
255 CoTaskMemFree(capBox);
259 HRESULT qcap_driver_set_format(Capture *capBox, AM_MEDIA_TYPE * mT)
261 int newheight, newwidth;
262 struct video_window window;
263 VIDEOINFOHEADER *format;
265 TRACE("%p\n", capBox);
267 format = (VIDEOINFOHEADER *) mT->pbFormat;
268 if (format->bmiHeader.biBitCount != 24 ||
269 format->bmiHeader.biCompression != BI_RGB)
271 FIXME("unsupported media type %d %d\n", format->bmiHeader.biBitCount,
272 format->bmiHeader.biCompression );
273 return VFW_E_INVALIDMEDIATYPE;
276 newwidth = format->bmiHeader.biWidth;
277 newheight = format->bmiHeader.biHeight;
279 TRACE("%p -> (%p) - %d %d\n", capBox, mT, newwidth, newheight);
281 if (capBox->height == newheight && capBox->width == newwidth)
284 if(-1 == xioctl(capBox->fd, VIDIOCGWIN, &window))
286 ERR("ioctl(VIDIOCGWIN) failed (%d)\n", errno);
289 window.width = newwidth;
290 window.height = newheight;
291 if (xioctl(capBox->fd, VIDIOCSWIN, &window) == -1)
293 TRACE("using software resize: %dx%d -> %dx%d\n",
294 window.width, window.height, capBox->width, capBox->height);
295 capBox->swresize = TRUE;
299 capBox->height = window.height;
300 capBox->width = window.width;
301 capBox->swresize = FALSE;
303 capBox->outputwidth = window.width;
304 capBox->outputheight = window.height;
308 HRESULT qcap_driver_get_format(const Capture *capBox, AM_MEDIA_TYPE ** mT)
312 mT[0] = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
314 return E_OUTOFMEMORY;
315 vi = CoTaskMemAlloc(sizeof(VIDEOINFOHEADER));
316 mT[0]->cbFormat = sizeof(VIDEOINFOHEADER);
319 CoTaskMemFree(mT[0]);
321 return E_OUTOFMEMORY;
323 mT[0]->majortype = MEDIATYPE_Video;
324 mT[0]->subtype = MEDIASUBTYPE_RGB24;
325 mT[0]->formattype = FORMAT_VideoInfo;
326 mT[0]->bFixedSizeSamples = TRUE;
327 mT[0]->bTemporalCompression = FALSE;
329 mT[0]->lSampleSize = capBox->outputwidth * capBox->outputheight * capBox->bitDepth / 8;
330 TRACE("Output format: %dx%d - %d bits = %u KB\n", capBox->outputwidth,
331 capBox->outputheight, capBox->bitDepth, mT[0]->lSampleSize/1024);
332 vi->rcSource.left = 0; vi->rcSource.top = 0;
333 vi->rcTarget.left = 0; vi->rcTarget.top = 0;
334 vi->rcSource.right = capBox->width; vi->rcSource.bottom = capBox->height;
335 vi->rcTarget.right = capBox->outputwidth; vi->rcTarget.bottom = capBox->outputheight;
336 vi->dwBitRate = capBox->fps * mT[0]->lSampleSize;
337 vi->dwBitErrorRate = 0;
338 vi->AvgTimePerFrame = (LONGLONG)10000000.0 / (LONGLONG)capBox->fps;
339 vi->bmiHeader.biSize = 40;
340 vi->bmiHeader.biWidth = capBox->outputwidth;
341 vi->bmiHeader.biHeight = capBox->outputheight;
342 vi->bmiHeader.biPlanes = 1;
343 vi->bmiHeader.biBitCount = 24;
344 vi->bmiHeader.biCompression = BI_RGB;
345 vi->bmiHeader.biSizeImage = mT[0]->lSampleSize;
346 vi->bmiHeader.biClrUsed = vi->bmiHeader.biClrImportant = 0;
347 vi->bmiHeader.biXPelsPerMeter = 100;
348 vi->bmiHeader.biYPelsPerMeter = 100;
349 mT[0]->pbFormat = (void *)vi;
350 dump_AM_MEDIA_TYPE(mT[0]);
354 HRESULT qcap_driver_get_prop_range( Capture *capBox,
355 VideoProcAmpProperty Property, LONG *pMin, LONG *pMax,
356 LONG *pSteppingDelta, LONG *pDefault, LONG *pCapsFlags )
358 TRACE("%p -> %d %p %p %p %p %p\n", capBox, Property,
359 pMin, pMax, pSteppingDelta, pDefault, pCapsFlags);
363 case VideoProcAmp_Brightness:
364 *pDefault = capBox->dbrightness;
366 case VideoProcAmp_Contrast:
367 *pDefault = capBox->dcontrast;
369 case VideoProcAmp_Hue:
370 *pDefault = capBox->dhue;
372 case VideoProcAmp_Saturation:
373 *pDefault = capBox->dcolour;
376 FIXME("Not implemented %d\n", Property);
381 *pSteppingDelta = 65536/256;
382 *pCapsFlags = VideoProcAmp_Flags_Manual;
386 HRESULT qcap_driver_get_prop( Capture *capBox,
387 VideoProcAmpProperty Property, LONG *lValue, LONG *Flags )
389 TRACE("%p -> %d %p %p\n", capBox, Property, lValue, Flags);
393 case VideoProcAmp_Brightness:
394 *lValue = capBox->pict.brightness;
396 case VideoProcAmp_Contrast:
397 *lValue = capBox->pict.contrast;
399 case VideoProcAmp_Hue:
400 *lValue = capBox->pict.hue;
402 case VideoProcAmp_Saturation:
403 *lValue = capBox->pict.colour;
406 FIXME("Not implemented %d\n", Property);
409 *Flags = VideoProcAmp_Flags_Manual;
413 HRESULT qcap_driver_set_prop(Capture *capBox, VideoProcAmpProperty Property,
414 LONG lValue, LONG Flags)
416 TRACE("%p -> %d %d %d\n", capBox, Property, lValue, Flags);
420 case VideoProcAmp_Brightness:
421 capBox->pict.brightness = lValue;
423 case VideoProcAmp_Contrast:
424 capBox->pict.contrast = lValue;
426 case VideoProcAmp_Hue:
427 capBox->pict.hue = lValue;
429 case VideoProcAmp_Saturation:
430 capBox->pict.colour = lValue;
433 FIXME("Not implemented %d\n", Property);
437 if (xioctl(capBox->fd, VIDIOCSPICT, &capBox->pict) == -1)
439 ERR("ioctl(VIDIOCSPICT) failed (%d)\n",errno);
445 static void renderer_RGB(const Capture *capBox, LPBYTE bufferin, const BYTE *stream)
447 int depth = renderlist_V4l[capBox->pict.palette].depth;
448 int size = capBox->height * capBox->width * depth / 8;
454 memcpy(bufferin, stream, size);
459 while (pointer + offset <= size)
461 bufferin[pointer] = stream[pointer + offset];
463 bufferin[pointer] = stream[pointer + offset];
465 bufferin[pointer] = stream[pointer + offset];
471 ERR("Unknown bit depth %d\n", depth);
476 static void renderer_YUV(const Capture *capBox, LPBYTE bufferin, const BYTE *stream)
478 enum YUV_Format format;
480 switch (capBox->pict.palette)
482 case 7: /* YUV422 - same as YUYV */
489 case 11: /* YUV411 */
492 case 13: /* YUV422P */
495 case 14: /* YUV411P */
498 case 15: /* YUV420P */
501 case 16: /* YUV410P */
505 ERR("Unknown palette %d\n", capBox->pict.palette);
508 YUV_To_RGB24(format, bufferin, stream, capBox->width, capBox->height);
511 static void Resize(const Capture * capBox, LPBYTE output, const BYTE *input)
513 /* the whole image needs to be reversed,
514 because the dibs are messed up in windows */
515 if (!capBox->swresize)
517 int depth = capBox->bitDepth / 8;
518 int inoffset = 0, outoffset = capBox->height * capBox->width * depth;
519 int ow = capBox->width * depth;
520 while (outoffset > 0)
524 for (x = 0; x < ow; x++)
525 output[outoffset + x] = input[inoffset + x];
532 HBITMAP bmp_s, bmp_d;
533 int depth = capBox->bitDepth / 8;
534 int inoffset = 0, outoffset = (capBox->outputheight) * capBox->outputwidth * depth;
535 int ow = capBox->outputwidth * depth;
538 /* FIXME: Improve software resizing: add error checks and optimize */
540 myarray = CoTaskMemAlloc(capBox->outputwidth * capBox->outputheight * depth);
541 dc_s = CreateCompatibleDC(NULL);
542 dc_d = CreateCompatibleDC(NULL);
543 bmp_s = CreateBitmap(capBox->width, capBox->height, 1, capBox->bitDepth, input);
544 bmp_d = CreateBitmap(capBox->outputwidth, capBox->outputheight, 1, capBox->bitDepth, NULL);
545 SelectObject(dc_s, bmp_s);
546 SelectObject(dc_d, bmp_d);
547 StretchBlt(dc_d, 0, 0, capBox->outputwidth, capBox->outputheight,
548 dc_s, 0, 0, capBox->width, capBox->height, SRCCOPY);
549 GetBitmapBits(bmp_d, capBox->outputwidth * capBox->outputheight * depth, myarray);
550 while (outoffset > 0)
555 for (i = 0; i < ow; i++)
556 output[outoffset + i] = myarray[inoffset + i];
559 CoTaskMemFree(myarray);
567 static void V4l_GetFrame(Capture * capBox, unsigned char ** pInput)
571 if (xioctl(capBox->fd, VIDIOCSYNC, &capBox->grab_buf[capBox->curframe]) == -1)
572 WARN("Syncing ioctl failed: %d\n", errno);
574 *pInput = capBox->pmap + capBox->gb_buffers.offsets[capBox->curframe];
579 while ((retval = video_read(capBox->fd, capBox->grab_data, capBox->imagesize)) == -1)
580 if (errno != EAGAIN) break;
582 WARN("Error occurred while reading from device: %s\n", strerror(errno));
583 *pInput = (unsigned char*) capBox->grab_data;
587 static void V4l_FreeFrame(Capture * capBox)
592 if (xioctl(capBox->fd, VIDIOCMCAPTURE, &capBox->grab_buf[capBox->curframe]) == -1)
593 ERR("Freeing frame for capture failed: %s\n", strerror(errno));
595 if (++capBox->curframe == capBox->buffers)
596 capBox->curframe = 0;
599 static DWORD WINAPI ReadThread(LPVOID lParam)
601 Capture * capBox = lParam;
603 IMediaSample *pSample = NULL;
604 ULONG framecount = 0;
605 unsigned char *pTarget, *pInput, *pOutput;
607 hr = V4l_Prepare(capBox);
611 pOutput = CoTaskMemAlloc(capBox->width * capBox->height * capBox->bitDepth / 8);
612 capBox->curframe = 0;
614 V4l_FreeFrame(capBox);
615 } while (capBox->curframe != 0);
619 EnterCriticalSection(&capBox->CritSect);
622 hr = BaseOutputPinImpl_GetDeliveryBuffer((BaseOutputPin *)capBox->pOut, &pSample, NULL, NULL, 0);
627 if (!capBox->swresize)
628 len = capBox->height * capBox->width * capBox->bitDepth / 8;
630 len = capBox->outputheight * capBox->outputwidth * capBox->bitDepth / 8;
631 IMediaSample_SetActualDataLength(pSample, len);
633 len = IMediaSample_GetActualDataLength(pSample);
634 TRACE("Data length: %d KB\n", len / 1024);
636 IMediaSample_GetPointer(pSample, &pTarget);
637 /* FIXME: Check return values.. */
638 V4l_GetFrame(capBox, &pInput);
639 capBox->renderer(capBox, pOutput, pInput);
640 Resize(capBox, pTarget, pOutput);
641 hr = BaseOutputPinImpl_Deliver((BaseOutputPin *)capBox->pOut, pSample);
642 TRACE("%p -> Frame %u: %x\n", capBox, ++framecount, hr);
643 IMediaSample_Release(pSample);
644 V4l_FreeFrame(capBox);
646 LeaveCriticalSection(&capBox->CritSect);
647 if (FAILED(hr) && hr != VFW_E_NOT_CONNECTED)
649 ERR("Received error: %x\n", hr);
653 LeaveCriticalSection(&capBox->CritSect);
654 CoTaskMemFree(pOutput);
659 CoTaskMemFree(pOutput);
660 V4l_Unprepare(capBox);
661 LeaveCriticalSection(&capBox->CritSect);
664 capBox->thread = 0; capBox->stopped = 1;
665 FIXME("Stop IFilterGraph\n");
669 HRESULT qcap_driver_run(Capture *capBox, FILTER_STATE *state)
674 TRACE("%p -> (%p)\n", capBox, state);
676 if (*state == State_Running) return S_OK;
678 EnterCriticalSection(&capBox->CritSect);
682 if (*state == State_Stopped)
684 *state = State_Running;
685 if (!capBox->iscommitted++)
687 ALLOCATOR_PROPERTIES ap, actual;
691 if (!capBox->swresize)
692 ap.cbBuffer = capBox->width * capBox->height;
694 ap.cbBuffer = capBox->outputwidth * capBox->outputheight;
695 ap.cbBuffer = (ap.cbBuffer * capBox->bitDepth) / 8;
699 out = (BaseOutputPin *)capBox->pOut;
701 hr = IMemAllocator_SetProperties(out->pAllocator, &ap, &actual);
704 hr = IMemAllocator_Commit(out->pAllocator);
706 TRACE("Committing allocator: %x\n", hr);
709 thread = CreateThread(NULL, 0, ReadThread, capBox, 0, NULL);
712 capBox->thread = thread;
713 SetThreadPriority(thread, THREAD_PRIORITY_LOWEST);
714 LeaveCriticalSection(&capBox->CritSect);
717 ERR("Creating thread failed.. %u\n", GetLastError());
718 LeaveCriticalSection(&capBox->CritSect);
722 ResumeThread(capBox->thread);
723 *state = State_Running;
724 LeaveCriticalSection(&capBox->CritSect);
728 HRESULT qcap_driver_pause(Capture *capBox, FILTER_STATE *state)
730 TRACE("%p -> (%p)\n", capBox, state);
732 if (*state == State_Paused)
734 if (*state == State_Stopped)
735 qcap_driver_run(capBox, state);
737 EnterCriticalSection(&capBox->CritSect);
738 *state = State_Paused;
739 SuspendThread(capBox->thread);
740 LeaveCriticalSection(&capBox->CritSect);
745 HRESULT qcap_driver_stop(Capture *capBox, FILTER_STATE *state)
747 TRACE("%p -> (%p)\n", capBox, state);
749 if (*state == State_Stopped)
752 EnterCriticalSection(&capBox->CritSect);
756 if (*state == State_Paused)
757 ResumeThread(capBox->thread);
760 if (capBox->iscommitted)
765 capBox->iscommitted = 0;
767 out = (BaseOutputPin*)capBox->pOut;
769 hr = IMemAllocator_Decommit(out->pAllocator);
771 if (hr != S_OK && hr != VFW_E_NOT_COMMITTED)
772 WARN("Decommitting allocator: %x\n", hr);
774 V4l_Unprepare(capBox);
777 *state = State_Stopped;
778 LeaveCriticalSection(&capBox->CritSect);
782 Capture * qcap_driver_init( IPin *pOut, USHORT card )
784 Capture * capBox = NULL;
786 struct video_capability capa;
787 struct video_picture pict;
788 struct video_window window;
793 capBox = CoTaskMemAlloc(sizeof(Capture));
797 /* capBox->vtbl = &defboxVtbl; */
799 InitializeCriticalSection( &capBox->CritSect );
800 capBox->CritSect.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": Capture.CritSect");
802 sprintf(device, "/dev/video%i", card);
803 TRACE("opening %s\n", device);
804 capBox->fd = video_open(device, O_RDWR | O_NONBLOCK);
805 if (capBox->fd == -1)
807 WARN("open failed (%d)\n", errno);
811 memset(&capa, 0, sizeof(capa));
813 if (xioctl(capBox->fd, VIDIOCGCAP, &capa) == -1)
815 WARN("ioctl(VIDIOCGCAP) failed (%d)\n", errno);
819 if (!(capa.type & VID_TYPE_CAPTURE))
821 WARN("not a video capture device\n");
825 TRACE("%d inputs on %s\n", capa.channels, capa.name );
827 if (xioctl(capBox->fd, VIDIOCGPICT, &pict) == -1)
829 ERR("ioctl(VIDIOCGPICT) failed (%d)\n", errno );
833 TRACE("depth %d palette %d (%s) hue %d color %d contrast %d\n",
834 pict.depth, pict.palette, renderlist_V4l[pict.palette].name,
835 pict.hue, pict.colour, pict.contrast );
837 capBox->dbrightness = pict.brightness;
838 capBox->dcolour = pict.colour;
839 capBox->dhue = pict.hue;
840 capBox->dcontrast = pict.contrast;
842 if (!renderlist_V4l[pict.palette].renderer)
844 int palet = pict.palette, i;
846 TRACE("No renderer available for %s, falling back to defaults\n",
847 renderlist_V4l[pict.palette].name);
848 capBox->renderer = NULL;
849 for (i = 0; fallback_V4l[i] >=0 ; i++)
851 int n = fallback_V4l[i];
853 if (renderlist_V4l[n].renderer == NULL)
856 pict.depth = renderlist_V4l[n].depth;
858 if (xioctl(capBox->fd, VIDIOCSPICT, &pict) == -1)
860 TRACE("Could not render with %s (%d)\n",
861 renderlist_V4l[n].name, n);
864 TRACE("using renderer %s (%d)\n",
865 renderlist_V4l[n].name, n);
866 capBox->renderer = renderlist_V4l[n].renderer;
870 if (!capBox->renderer)
872 ERR("video format %s isn't available\n",
873 renderlist_V4l[palet].name);
879 TRACE("Using the suggested format\n");
880 capBox->renderer = renderlist_V4l[pict.palette].renderer;
882 memcpy(&capBox->pict, &pict, sizeof(struct video_picture));
884 memset(&window, 0, sizeof(window));
885 if (xioctl(capBox->fd, VIDIOCGWIN, &window) == -1)
887 WARN("VIDIOCGWIN failed (%d)\n", errno);
891 capBox->height = capBox->outputheight = window.height;
892 capBox->width = capBox->outputwidth = window.width;
893 capBox->swresize = FALSE;
894 capBox->bitDepth = 24;
898 capBox->curframe = 0;
899 capBox->iscommitted = 0;
901 TRACE("format: %d bits - %d x %d\n", capBox->bitDepth, capBox->width, capBox->height);
907 qcap_driver_destroy( capBox );
914 Capture * qcap_driver_init( IPin *pOut, USHORT card )
917 "The v4l headers were not available at compile time,\n"
918 "so video capture support is not available.\n";
923 #define FAIL_WITH_ERR \
924 ERR("v4l absent: shouldn't be called\n"); \
927 HRESULT qcap_driver_destroy(Capture *capBox)
932 HRESULT qcap_driver_set_format(Capture *capBox, AM_MEDIA_TYPE * mT)
937 HRESULT qcap_driver_get_format(const Capture *capBox, AM_MEDIA_TYPE ** mT)
942 HRESULT qcap_driver_get_prop_range( Capture *capBox,
943 VideoProcAmpProperty Property, LONG *pMin, LONG *pMax,
944 LONG *pSteppingDelta, LONG *pDefault, LONG *pCapsFlags )
949 HRESULT qcap_driver_get_prop(Capture *capBox,
950 VideoProcAmpProperty Property, LONG *lValue, LONG *Flags)
955 HRESULT qcap_driver_set_prop(Capture *capBox, VideoProcAmpProperty Property,
956 LONG lValue, LONG Flags)
961 HRESULT qcap_driver_run(Capture *capBox, FILTER_STATE *state)
966 HRESULT qcap_driver_pause(Capture *capBox, FILTER_STATE *state)
971 HRESULT qcap_driver_stop(Capture *capBox, FILTER_STATE *state)
976 #endif /* HAVE_LINUX_VIDEODEV_H || HAVE_LINUX_LIBV4L1_H */