[FFmpeg-devel] [PATCH] VFW capture support

Måns Rullgård mans
Tue Mar 4 22:17:12 CET 2008


Ramiro Polla <ramiro at lisha.ufsc.br> writes:

>>>>> struct vfw_ctx {
>>>>>     HWND hwnd;
>>>>>     int grabbed;
>>>>>     AVPacket *pkt;
>>>>> };
>>>>>
>>>>> static int vfw_pixfmt( DWORD biCompression )
>>>> Do we really have to use those dreadful windows typedefs and naming
>>>> conventions?
>>> I find it best when writing an interface to an API that has
>>> documentation, the same way you follow variable names from specs.
>> This function isn't part of any API.
>
> DWORD biCompression is part of the documentation.

As part of the BITMAPINFOHEADER struct, yes.  That function of yours
is certainly not in any MS API.

>>>     ctx->hwnd = capCreateCaptureWindow( NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0 );
>>>     if( !ctx->hwnd ) {
>>>         av_log( s, AV_LOG_ERROR, "Could not create capture window.\n" );
>>>         return AVERROR_IO;
>>>     }
>
> I don't know how this can fail. Left as is.

I can imagine it might run out of memory or whatever other limited
resources it needs.  I'm sure there's some upper limit for the number
of windows.

>>>     /* If atoi fails, devnum==0 and the default device is used */
>>>     devnum = atoi( s->filename );
>>>
>>>     ret = SendMessage( ctx->hwnd, WM_CAP_DRIVER_CONNECT, devnum, 0 );
>>>     if( !ret ) {
>>>         av_log( s, AV_LOG_ERROR, "Could not connect to device.\n" );
>>>         return AVERROR_IO;
>>>     }
>> I'm not sure AVERROR_IO is the proper error code for those failures.
>
> Other grab devices mostly return EIO.

EIO is appropriate when an attempt to perform I/O failed.  IMHO,
device setup doesn't quite fit that label.

> /*
>  * VFW capture interface
>  * Copyright (c) 2006-2008 Ramiro Polla.
>  *
>  * This file is part of FFmpeg.
>  *
>  * FFmpeg is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU Lesser General Public
>  * License as published by the Free Software Foundation; either
>  * version 2.1 of the License, or (at your option) any later version.
>  *
>  * FFmpeg is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>  * Lesser General Public License for more details.
>  *
>  * You should have received a copy of the GNU Lesser General Public
>  * License along with FFmpeg; if not, write to the Free Software
>  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>  */
>
> #include "avformat.h"
> #include <vfw.h>
> #include <windows.h>
>
> /* Defines for VFW missing from MinGW.
>  * Remove this when MinGW incorporates them. */
> #define WM_CAP_START                (0x0400)
> #define WM_CAP_SET_CALLBACK_FRAME   (WM_CAP_START + 5)
> #define WM_CAP_GET_USER_DATA        (WM_CAP_START + 8)
> #define WM_CAP_SET_USER_DATA        (WM_CAP_START + 9)
> #define WM_CAP_DRIVER_CONNECT       (WM_CAP_START + 10)
> #define WM_CAP_DRIVER_DISCONNECT    (WM_CAP_START + 11)
> #define WM_CAP_GRAB_FRAME           (WM_CAP_START + 60)
> #define WM_CAP_GET_VIDEOFORMAT      (WM_CAP_START + 44)
> #define WM_CAP_SET_PREVIEW          (WM_CAP_START + 50)
> #define WM_CAP_SET_OVERLAY          (WM_CAP_START + 51)
>
> #define HWND_MESSAGE                ((HWND)-3)
>
> #define BI_RGB                      0
>
> typedef struct videohdr_tag {
>     LPBYTE      lpData;
>     DWORD       dwBufferLength;
>     DWORD       dwBytesUsed;
>     DWORD       dwTimeCaptured;
>     DWORD       dwUser;
>     DWORD       dwFlags;
>     DWORD_PTR   dwReserved[4];
> } VIDEOHDR, NEAR *PVIDEOHDR, FAR * LPVIDEOHDR;
> /* End of missing MinGW defines */
>
> struct vfw_ctx {
>     HWND hwnd;
>     int grabbed;
>     AVPacket *pkt;
> };
>
> static int vfw_pixfmt( AVFormatContext *s, DWORD biCompression )

This function could return enum PixelFormat.

> {
>     switch( biCompression ) {
>     case MKTAG( 'Y', 'U', 'Y', '2' ):
>         return PIX_FMT_YUYV422;
>     case BI_RGB:
>         return PIX_FMT_BGR24;
>     }
>     av_log( s, AV_LOG_ERROR, "Unknown compression type."
>                              "Please report debug information.\n" );

Printing the value of the unknown format could be useful.

>     return -1;
> }

I have no further comments.

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list