2008-03-08 23:10:28 +01:00
|
|
|
/*
|
|
|
|
* VFW capture interface
|
2009-01-19 16:46:40 +01:00
|
|
|
* Copyright (c) 2006-2008 Ramiro Polla
|
2008-03-08 23:10:28 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2008-05-09 13:56:36 +02:00
|
|
|
#include "libavformat/avformat.h"
|
2008-03-08 23:10:28 +01:00
|
|
|
#include <windows.h>
|
2010-01-23 21:58:29 +01:00
|
|
|
#include <vfw.h>
|
2008-03-08 23:10:28 +01:00
|
|
|
|
|
|
|
//#define DEBUG_VFW
|
|
|
|
|
|
|
|
/* Defines for VFW missing from MinGW.
|
|
|
|
* Remove this when MinGW incorporates them. */
|
|
|
|
#define HWND_MESSAGE ((HWND)-3)
|
|
|
|
|
|
|
|
#define BI_RGB 0
|
|
|
|
|
|
|
|
/* End of missing MinGW defines */
|
|
|
|
|
|
|
|
struct vfw_ctx {
|
|
|
|
HWND hwnd;
|
|
|
|
HANDLE mutex;
|
|
|
|
HANDLE event;
|
|
|
|
AVPacketList *pktl;
|
|
|
|
AVFormatContext *s;
|
|
|
|
unsigned int curbufsize;
|
|
|
|
unsigned int frame_num;
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum PixelFormat vfw_pixfmt(DWORD biCompression, WORD biBitCount)
|
|
|
|
{
|
|
|
|
switch(biCompression) {
|
2010-03-10 06:25:06 +01:00
|
|
|
case MKTAG('U', 'Y', 'V', 'Y'):
|
|
|
|
return PIX_FMT_UYVY422;
|
2008-03-08 23:10:28 +01:00
|
|
|
case MKTAG('Y', 'U', 'Y', '2'):
|
|
|
|
return PIX_FMT_YUYV422;
|
2008-04-14 17:41:10 +02:00
|
|
|
case MKTAG('I', '4', '2', '0'):
|
|
|
|
return PIX_FMT_YUV420P;
|
2008-03-08 23:10:28 +01:00
|
|
|
case BI_RGB:
|
|
|
|
switch(biBitCount) { /* 1-8 are untested */
|
|
|
|
case 1:
|
|
|
|
return PIX_FMT_MONOWHITE;
|
|
|
|
case 4:
|
|
|
|
return PIX_FMT_RGB4;
|
|
|
|
case 8:
|
|
|
|
return PIX_FMT_RGB8;
|
|
|
|
case 16:
|
|
|
|
return PIX_FMT_RGB555;
|
|
|
|
case 24:
|
|
|
|
return PIX_FMT_BGR24;
|
|
|
|
case 32:
|
|
|
|
return PIX_FMT_RGB32;
|
|
|
|
}
|
|
|
|
}
|
2009-07-30 18:18:33 +02:00
|
|
|
return PIX_FMT_NONE;
|
2008-03-08 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
2009-07-30 19:29:24 +02:00
|
|
|
static enum CodecID vfw_codecid(DWORD biCompression)
|
|
|
|
{
|
|
|
|
switch(biCompression) {
|
|
|
|
case MKTAG('d', 'v', 's', 'd'):
|
|
|
|
return CODEC_ID_DVVIDEO;
|
2010-02-23 17:49:16 +01:00
|
|
|
case MKTAG('M', 'J', 'P', 'G'):
|
|
|
|
case MKTAG('m', 'j', 'p', 'g'):
|
|
|
|
return CODEC_ID_MJPEG;
|
2009-07-30 19:29:24 +02:00
|
|
|
}
|
|
|
|
return CODEC_ID_NONE;
|
|
|
|
}
|
|
|
|
|
2008-03-08 23:10:28 +01:00
|
|
|
#define dstruct(pctx, sname, var, type) \
|
|
|
|
av_log(pctx, AV_LOG_DEBUG, #var":\t%"type"\n", sname->var)
|
|
|
|
|
|
|
|
static void dump_captureparms(AVFormatContext *s, CAPTUREPARMS *cparms)
|
|
|
|
{
|
|
|
|
av_log(s, AV_LOG_DEBUG, "CAPTUREPARMS\n");
|
|
|
|
dstruct(s, cparms, dwRequestMicroSecPerFrame, "lu");
|
|
|
|
dstruct(s, cparms, fMakeUserHitOKToCapture, "d");
|
|
|
|
dstruct(s, cparms, wPercentDropForError, "u");
|
|
|
|
dstruct(s, cparms, fYield, "d");
|
|
|
|
dstruct(s, cparms, dwIndexSize, "lu");
|
|
|
|
dstruct(s, cparms, wChunkGranularity, "u");
|
|
|
|
dstruct(s, cparms, fUsingDOSMemory, "d");
|
|
|
|
dstruct(s, cparms, wNumVideoRequested, "u");
|
|
|
|
dstruct(s, cparms, fCaptureAudio, "d");
|
|
|
|
dstruct(s, cparms, wNumAudioRequested, "u");
|
|
|
|
dstruct(s, cparms, vKeyAbort, "u");
|
|
|
|
dstruct(s, cparms, fAbortLeftMouse, "d");
|
|
|
|
dstruct(s, cparms, fAbortRightMouse, "d");
|
|
|
|
dstruct(s, cparms, fLimitEnabled, "d");
|
|
|
|
dstruct(s, cparms, wTimeLimit, "u");
|
|
|
|
dstruct(s, cparms, fMCIControl, "d");
|
|
|
|
dstruct(s, cparms, fStepMCIDevice, "d");
|
|
|
|
dstruct(s, cparms, dwMCIStartTime, "lu");
|
|
|
|
dstruct(s, cparms, dwMCIStopTime, "lu");
|
|
|
|
dstruct(s, cparms, fStepCaptureAt2x, "d");
|
|
|
|
dstruct(s, cparms, wStepCaptureAverageFrames, "u");
|
|
|
|
dstruct(s, cparms, dwAudioBufferSize, "lu");
|
|
|
|
dstruct(s, cparms, fDisableWriteCache, "d");
|
|
|
|
dstruct(s, cparms, AVStreamMaster, "u");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_videohdr(AVFormatContext *s, VIDEOHDR *vhdr)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_VFW
|
|
|
|
av_log(s, AV_LOG_DEBUG, "VIDEOHDR\n");
|
|
|
|
dstruct(s, vhdr, lpData, "p");
|
|
|
|
dstruct(s, vhdr, dwBufferLength, "lu");
|
|
|
|
dstruct(s, vhdr, dwBytesUsed, "lu");
|
|
|
|
dstruct(s, vhdr, dwTimeCaptured, "lu");
|
|
|
|
dstruct(s, vhdr, dwUser, "lu");
|
|
|
|
dstruct(s, vhdr, dwFlags, "lu");
|
|
|
|
dstruct(s, vhdr, dwReserved[0], "lu");
|
|
|
|
dstruct(s, vhdr, dwReserved[1], "lu");
|
|
|
|
dstruct(s, vhdr, dwReserved[2], "lu");
|
|
|
|
dstruct(s, vhdr, dwReserved[3], "lu");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_bih(AVFormatContext *s, BITMAPINFOHEADER *bih)
|
|
|
|
{
|
|
|
|
av_log(s, AV_LOG_DEBUG, "BITMAPINFOHEADER\n");
|
|
|
|
dstruct(s, bih, biSize, "lu");
|
|
|
|
dstruct(s, bih, biWidth, "ld");
|
|
|
|
dstruct(s, bih, biHeight, "ld");
|
|
|
|
dstruct(s, bih, biPlanes, "d");
|
|
|
|
dstruct(s, bih, biBitCount, "d");
|
|
|
|
dstruct(s, bih, biCompression, "lu");
|
|
|
|
av_log(s, AV_LOG_DEBUG, " biCompression:\t\"%.4s\"\n",
|
|
|
|
(char*) &bih->biCompression);
|
|
|
|
dstruct(s, bih, biSizeImage, "lu");
|
|
|
|
dstruct(s, bih, biXPelsPerMeter, "lu");
|
|
|
|
dstruct(s, bih, biYPelsPerMeter, "lu");
|
|
|
|
dstruct(s, bih, biClrUsed, "lu");
|
|
|
|
dstruct(s, bih, biClrImportant, "lu");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int shall_we_drop(struct vfw_ctx *ctx)
|
|
|
|
{
|
|
|
|
AVFormatContext *s = ctx->s;
|
|
|
|
const uint8_t dropscore[] = {62, 75, 87, 100};
|
2008-10-21 23:40:24 +02:00
|
|
|
const int ndropscores = FF_ARRAY_ELEMS(dropscore);
|
2008-03-08 23:10:28 +01:00
|
|
|
unsigned int buffer_fullness = (ctx->curbufsize*100)/s->max_picture_buffer;
|
|
|
|
|
2008-03-09 00:06:33 +01:00
|
|
|
if(dropscore[++ctx->frame_num%ndropscores] <= buffer_fullness) {
|
2008-03-08 23:10:28 +01:00
|
|
|
av_log(ctx->s, AV_LOG_ERROR,
|
|
|
|
"real-time buffer %d%% full! frame dropped!\n", buffer_fullness);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK videostream_cb(HWND hwnd, LPVIDEOHDR vdhdr)
|
|
|
|
{
|
|
|
|
struct vfw_ctx *ctx;
|
|
|
|
AVPacketList **ppktl, *pktl_next;
|
|
|
|
|
|
|
|
ctx = (struct vfw_ctx *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
|
|
|
|
|
|
|
dump_videohdr(ctx->s, vdhdr);
|
|
|
|
|
|
|
|
if(shall_we_drop(ctx))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
WaitForSingleObject(ctx->mutex, INFINITE);
|
|
|
|
|
|
|
|
pktl_next = av_mallocz(sizeof(AVPacketList));
|
|
|
|
if(!pktl_next)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if(av_new_packet(&pktl_next->pkt, vdhdr->dwBytesUsed) < 0) {
|
|
|
|
av_free(pktl_next);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
pktl_next->pkt.pts = vdhdr->dwTimeCaptured;
|
|
|
|
memcpy(pktl_next->pkt.data, vdhdr->lpData, vdhdr->dwBytesUsed);
|
|
|
|
|
|
|
|
for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next);
|
|
|
|
*ppktl = pktl_next;
|
|
|
|
|
|
|
|
ctx->curbufsize += vdhdr->dwBytesUsed;
|
|
|
|
|
|
|
|
SetEvent(ctx->event);
|
|
|
|
ReleaseMutex(ctx->mutex);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
fail:
|
|
|
|
ReleaseMutex(ctx->mutex);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-02 19:39:10 +02:00
|
|
|
static int vfw_read_close(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
struct vfw_ctx *ctx = s->priv_data;
|
|
|
|
|
|
|
|
if(ctx->hwnd) {
|
|
|
|
SendMessage(ctx->hwnd, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
|
|
|
|
SendMessage(ctx->hwnd, WM_CAP_DRIVER_DISCONNECT, 0, 0);
|
|
|
|
DestroyWindow(ctx->hwnd);
|
|
|
|
}
|
|
|
|
if(ctx->mutex)
|
|
|
|
CloseHandle(ctx->mutex);
|
|
|
|
if(ctx->event)
|
|
|
|
CloseHandle(ctx->event);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-03-08 23:10:28 +01:00
|
|
|
|
|
|
|
static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
|
|
|
|
{
|
|
|
|
struct vfw_ctx *ctx = s->priv_data;
|
|
|
|
AVCodecContext *codec;
|
|
|
|
AVStream *st;
|
|
|
|
int devnum;
|
|
|
|
int bisize;
|
|
|
|
BITMAPINFO *bi;
|
|
|
|
CAPTUREPARMS cparms;
|
|
|
|
DWORD biCompression;
|
|
|
|
WORD biBitCount;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!ap->time_base.den) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "A time base must be specified.\n");
|
2010-03-13 20:19:44 +01:00
|
|
|
return AVERROR(EIO);
|
2008-03-08 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx->s = s;
|
|
|
|
|
|
|
|
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");
|
2010-03-13 20:19:44 +01:00
|
|
|
return AVERROR(EIO);
|
2008-03-08 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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");
|
|
|
|
DestroyWindow(ctx->hwnd);
|
|
|
|
return AVERROR(ENODEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
SendMessage(ctx->hwnd, WM_CAP_SET_OVERLAY, 0, 0);
|
|
|
|
SendMessage(ctx->hwnd, WM_CAP_SET_PREVIEW, 0, 0);
|
|
|
|
|
|
|
|
ret = SendMessage(ctx->hwnd, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0,
|
|
|
|
(LPARAM) videostream_cb);
|
|
|
|
if(!ret) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Could not set video stream callback.\n");
|
2008-04-14 16:59:51 +02:00
|
|
|
goto fail_io;
|
2008-03-08 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SetWindowLongPtr(ctx->hwnd, GWLP_USERDATA, (LONG_PTR) ctx);
|
|
|
|
|
|
|
|
st = av_new_stream(s, 0);
|
|
|
|
if(!st) {
|
|
|
|
vfw_read_close(s);
|
|
|
|
return AVERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set video format */
|
|
|
|
bisize = SendMessage(ctx->hwnd, WM_CAP_GET_VIDEOFORMAT, 0, 0);
|
2008-04-14 17:13:06 +02:00
|
|
|
if(!bisize)
|
2008-04-14 16:59:51 +02:00
|
|
|
goto fail_io;
|
2008-03-08 23:10:28 +01:00
|
|
|
bi = av_malloc(bisize);
|
|
|
|
if(!bi) {
|
|
|
|
vfw_read_close(s);
|
|
|
|
return AVERROR_NOMEM;
|
|
|
|
}
|
|
|
|
ret = SendMessage(ctx->hwnd, WM_CAP_GET_VIDEOFORMAT, bisize, (LPARAM) bi);
|
2008-04-14 17:13:06 +02:00
|
|
|
if(!ret)
|
2008-04-14 17:07:12 +02:00
|
|
|
goto fail_bi;
|
2008-03-08 23:10:28 +01:00
|
|
|
|
|
|
|
dump_bih(s, &bi->bmiHeader);
|
|
|
|
|
|
|
|
width = ap->width ? ap->width : bi->bmiHeader.biWidth ;
|
|
|
|
height = ap->height ? ap->height : bi->bmiHeader.biHeight;
|
|
|
|
bi->bmiHeader.biWidth = width ;
|
|
|
|
bi->bmiHeader.biHeight = height;
|
|
|
|
|
2009-09-04 18:31:21 +02:00
|
|
|
if (0) {
|
2009-09-04 18:32:06 +02:00
|
|
|
/* For testing yet unsupported compressions
|
|
|
|
* Copy these values from user-supplied verbose information */
|
|
|
|
bi->bmiHeader.biWidth = 320;
|
|
|
|
bi->bmiHeader.biHeight = 240;
|
|
|
|
bi->bmiHeader.biPlanes = 1;
|
|
|
|
bi->bmiHeader.biBitCount = 12;
|
|
|
|
bi->bmiHeader.biCompression = MKTAG('I','4','2','0');
|
|
|
|
bi->bmiHeader.biSizeImage = 115200;
|
|
|
|
dump_bih(s, &bi->bmiHeader);
|
2009-09-04 18:31:21 +02:00
|
|
|
}
|
2008-04-14 17:44:33 +02:00
|
|
|
|
2008-03-08 23:10:28 +01:00
|
|
|
ret = SendMessage(ctx->hwnd, WM_CAP_SET_VIDEOFORMAT, bisize, (LPARAM) bi);
|
|
|
|
if(!ret) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Could not set Video Format.\n");
|
2008-04-14 17:07:12 +02:00
|
|
|
goto fail_bi;
|
2008-03-08 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
biCompression = bi->bmiHeader.biCompression;
|
|
|
|
biBitCount = bi->bmiHeader.biBitCount;
|
|
|
|
|
|
|
|
av_free(bi);
|
|
|
|
|
|
|
|
/* Set sequence setup */
|
|
|
|
ret = SendMessage(ctx->hwnd, WM_CAP_GET_SEQUENCE_SETUP, sizeof(cparms),
|
|
|
|
(LPARAM) &cparms);
|
2008-04-14 17:13:06 +02:00
|
|
|
if(!ret)
|
2008-04-14 16:59:51 +02:00
|
|
|
goto fail_io;
|
2008-03-08 23:10:28 +01:00
|
|
|
|
|
|
|
dump_captureparms(s, &cparms);
|
|
|
|
|
|
|
|
cparms.fYield = 1; // Spawn a background thread
|
|
|
|
cparms.dwRequestMicroSecPerFrame =
|
|
|
|
(ap->time_base.num*1000000) / ap->time_base.den;
|
|
|
|
cparms.fAbortLeftMouse = 0;
|
|
|
|
cparms.fAbortRightMouse = 0;
|
|
|
|
cparms.fCaptureAudio = 0;
|
|
|
|
cparms.vKeyAbort = 0;
|
|
|
|
|
|
|
|
ret = SendMessage(ctx->hwnd, WM_CAP_SET_SEQUENCE_SETUP, sizeof(cparms),
|
|
|
|
(LPARAM) &cparms);
|
2008-04-14 17:13:06 +02:00
|
|
|
if(!ret)
|
2008-04-14 16:59:51 +02:00
|
|
|
goto fail_io;
|
2008-03-08 23:10:28 +01:00
|
|
|
|
|
|
|
codec = st->codec;
|
|
|
|
codec->time_base = ap->time_base;
|
|
|
|
codec->codec_type = CODEC_TYPE_VIDEO;
|
|
|
|
codec->width = width;
|
|
|
|
codec->height = height;
|
|
|
|
codec->pix_fmt = vfw_pixfmt(biCompression, biBitCount);
|
2009-07-30 18:18:33 +02:00
|
|
|
if(codec->pix_fmt == PIX_FMT_NONE) {
|
2009-07-30 19:29:24 +02:00
|
|
|
codec->codec_id = vfw_codecid(biCompression);
|
|
|
|
if(codec->codec_id == CODEC_ID_NONE) {
|
2009-07-30 19:31:28 +02:00
|
|
|
av_log(s, AV_LOG_ERROR, "Unknown compression type. "
|
|
|
|
"Please report verbose (-v 9) debug information.\n");
|
|
|
|
vfw_read_close(s);
|
|
|
|
return AVERROR_PATCHWELCOME;
|
2009-07-30 19:29:24 +02:00
|
|
|
}
|
|
|
|
codec->bits_per_coded_sample = biBitCount;
|
2009-07-30 19:31:28 +02:00
|
|
|
} else {
|
|
|
|
codec->codec_id = CODEC_ID_RAWVIDEO;
|
|
|
|
if(biCompression == BI_RGB)
|
|
|
|
codec->bits_per_coded_sample = biBitCount;
|
2009-07-30 19:29:24 +02:00
|
|
|
}
|
2009-07-30 19:25:15 +02:00
|
|
|
|
|
|
|
av_set_pts_info(st, 32, 1, 1000);
|
2008-03-08 23:10:28 +01:00
|
|
|
|
|
|
|
ctx->mutex = CreateMutex(NULL, 0, NULL);
|
|
|
|
if(!ctx->mutex) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Could not create Mutex.\n" );
|
2008-04-14 16:59:51 +02:00
|
|
|
goto fail_io;
|
2008-03-08 23:10:28 +01:00
|
|
|
}
|
|
|
|
ctx->event = CreateEvent(NULL, 1, 0, NULL);
|
|
|
|
if(!ctx->event) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Could not create Event.\n" );
|
2008-04-14 16:59:51 +02:00
|
|
|
goto fail_io;
|
2008-03-08 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = SendMessage(ctx->hwnd, WM_CAP_SEQUENCE_NOFILE, 0, 0);
|
|
|
|
if(!ret) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Could not start capture sequence.\n" );
|
2008-04-14 16:59:51 +02:00
|
|
|
goto fail_io;
|
2008-03-08 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-04-14 16:59:51 +02:00
|
|
|
|
2008-04-14 17:07:12 +02:00
|
|
|
fail_bi:
|
|
|
|
av_free(bi);
|
|
|
|
|
2008-04-14 16:59:51 +02:00
|
|
|
fail_io:
|
|
|
|
vfw_read_close(s);
|
2010-03-13 20:19:44 +01:00
|
|
|
return AVERROR(EIO);
|
2008-03-08 23:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vfw_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
struct vfw_ctx *ctx = s->priv_data;
|
|
|
|
AVPacketList *pktl = NULL;
|
|
|
|
|
|
|
|
while(!pktl) {
|
|
|
|
WaitForSingleObject(ctx->mutex, INFINITE);
|
|
|
|
pktl = ctx->pktl;
|
|
|
|
if(ctx->pktl) {
|
|
|
|
*pkt = ctx->pktl->pkt;
|
|
|
|
ctx->pktl = ctx->pktl->next;
|
|
|
|
av_free(pktl);
|
|
|
|
}
|
|
|
|
ResetEvent(ctx->event);
|
|
|
|
ReleaseMutex(ctx->mutex);
|
|
|
|
if(!pktl) {
|
|
|
|
if(s->flags & AVFMT_FLAG_NONBLOCK) {
|
|
|
|
return AVERROR(EAGAIN);
|
|
|
|
} else {
|
|
|
|
WaitForSingleObject(ctx->event, INFINITE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->curbufsize -= pkt->size;
|
|
|
|
|
|
|
|
return pkt->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
AVInputFormat vfwcap_demuxer = {
|
|
|
|
"vfwcap",
|
2008-06-03 18:20:54 +02:00
|
|
|
NULL_IF_CONFIG_SMALL("VFW video capture"),
|
2008-03-08 23:10:28 +01:00
|
|
|
sizeof(struct vfw_ctx),
|
|
|
|
NULL,
|
|
|
|
vfw_read_header,
|
|
|
|
vfw_read_packet,
|
|
|
|
vfw_read_close,
|
|
|
|
.flags = AVFMT_NOFILE,
|
|
|
|
};
|