]> git.sesse.net Git - ffmpeg/blobdiff - libavdevice/vfwcap.c
Use the correct type for the V4L2 format.
[ffmpeg] / libavdevice / vfwcap.c
index 34beac4e90ebb4b2755b866d6449992ffb6479f8..60ab169e7663341f5745892031f82ae96d3f750f 100644 (file)
@@ -66,7 +66,16 @@ static enum PixelFormat vfw_pixfmt(DWORD biCompression, WORD biBitCount)
                 return PIX_FMT_RGB32;
         }
     }
-    return -1;
+    return PIX_FMT_NONE;
+}
+
+static enum CodecID vfw_codecid(DWORD biCompression)
+{
+    switch(biCompression) {
+    case MKTAG('d', 'v', 's', 'd'):
+        return CODEC_ID_DVVIDEO;
+    }
+    return CODEC_ID_NONE;
 }
 
 #define dstruct(pctx, sname, var, type) \
@@ -192,7 +201,22 @@ fail:
     return FALSE;
 }
 
-static int vfw_read_close(AVFormatContext *s);
+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;
+}
 
 static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
 {
@@ -270,17 +294,17 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
     bi->bmiHeader.biWidth  = width ;
     bi->bmiHeader.biHeight = height;
 
-#if 0
-    /* 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);
-#endif
+    if (0) {
+        /* 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);
+    }
 
     ret = SendMessage(ctx->hwnd, WM_CAP_SET_VIDEOFORMAT, bisize, (LPARAM) bi);
     if(!ret) {
@@ -319,20 +343,24 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap)
     codec->codec_type = CODEC_TYPE_VIDEO;
     codec->width = width;
     codec->height = height;
-    codec->codec_id = CODEC_ID_RAWVIDEO;
     codec->pix_fmt = vfw_pixfmt(biCompression, biBitCount);
-    if(biCompression == BI_RGB)
+    if(codec->pix_fmt == PIX_FMT_NONE) {
+        codec->codec_id = vfw_codecid(biCompression);
+        if(codec->codec_id == CODEC_ID_NONE) {
+            av_log(s, AV_LOG_ERROR, "Unknown compression type. "
+                             "Please report verbose (-v 9) debug information.\n");
+            vfw_read_close(s);
+            return AVERROR_PATCHWELCOME;
+        }
         codec->bits_per_coded_sample = biBitCount;
+    } else {
+        codec->codec_id = CODEC_ID_RAWVIDEO;
+        if(biCompression == BI_RGB)
+            codec->bits_per_coded_sample = biBitCount;
+    }
 
     av_set_pts_info(st, 32, 1, 1000);
 
-    if(codec->pix_fmt == -1) {
-        av_log(s, AV_LOG_ERROR, "Unknown compression type. "
-                         "Please report verbose (-v 9) debug information.\n");
-        vfw_read_close(s);
-        return AVERROR_PATCHWELCOME;
-    }
-
     ctx->mutex = CreateMutex(NULL, 0, NULL);
     if(!ctx->mutex) {
         av_log(s, AV_LOG_ERROR, "Could not create Mutex.\n" );
@@ -389,23 +417,6 @@ static int vfw_read_packet(AVFormatContext *s, AVPacket *pkt)
     return pkt->size;
 }
 
-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;
-}
-
 AVInputFormat vfwcap_demuxer = {
     "vfwcap",
     NULL_IF_CONFIG_SMALL("VFW video capture"),