[FFmpeg-devel] dshow: patches for adding some debug output, using more standardized codec table for lookup

Roger Pack rogerdpack2 at gmail.com
Tue Sep 25 01:10:38 CEST 2012


>> Here some dshow patches.  The third patch allows for debug messages
>> when enumerating the pins while actually using them, like
>>
>> $ ffmpeg -f dshow -i video=XXX
>>
>> with -loglevel debug, will show you which pins it actually uses, etc.
>> which could be helpful for debugging connection problems with
>> different devices.
>>
>> Thanks.
>> -roger-
>
>> From 704d4cd207d51f04792f7fe8e5f4692d11141c6c Mon Sep 17 00:00:00 2001
>> From: rogerdpack <rogerpack2005 at gmail.com>
>> Date: Fri, 7 Sep 2012 15:52:32 -0600
>> Subject: [PATCH 1/3] dshow: enhance error message
>>
>>
>> Signed-off-by: rogerdpack <rogerpack2005 at gmail.com>
>> ---
>>  libavdevice/dshow.c |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
>> index 120ddd9..1e86732 100644
>> --- a/libavdevice/dshow.c
>> +++ b/libavdevice/dshow.c
>> @@ -378,7 +378,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
>>                      enum AVCodecID codec_id = dshow_codecid(bih->biCompression);
>>                      AVCodec *codec = avcodec_find_decoder(codec_id);
>>                      if (codec_id == AV_CODEC_ID_NONE || !codec) {
>> -                        av_log(avctx, AV_LOG_INFO, "  unknown compression type");
>> +                        av_log(avctx, AV_LOG_INFO, "  unknown compression type 0x%X", (int) bih->biCompression);
>>                      } else {
>>                          av_log(avctx, AV_LOG_INFO, "  vcodec=%s", codec->name);
>>                      }
>> --
>> 1.7.9.5
>
> LGTM
>
>> From 7279c01613c0345ce85f18e3814350d438a5e397 Mon Sep 17 00:00:00 2001
>> From: rogerdpack <rogerpack2005 at gmail.com>
>> Date: Fri, 7 Sep 2012 15:55:07 -0600
>> Subject: [PATCH 2/3] dshow: attempt to use more standard codec lookup
>>
>>
>> Signed-off-by: rogerdpack <rogerpack2005 at gmail.com>
>> ---
>>  libavdevice/dshow.c |   19 ++++---------------
>>  1 file changed, 4 insertions(+), 15 deletions(-)
>>
>> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
>> index 1e86732..562368d 100644
>> --- a/libavdevice/dshow.c
>> +++ b/libavdevice/dshow.c
>> @@ -23,6 +23,7 @@
>>  #include "libavutil/pixdesc.h"
>>  #include "libavutil/opt.h"
>>  #include "libavformat/internal.h"
>> +#include "libavformat/riff.h"
>>  #include "avdevice.h"
>>  #include "dshow_capture.h"
>>
>> @@ -95,18 +96,6 @@ static enum PixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount)
>>      return PIX_FMT_NONE;
>>  }
>>
>> -static enum AVCodecID dshow_codecid(DWORD biCompression)
>> -{
>> -    switch(biCompression) {
>> -    case MKTAG('d', 'v', 's', 'd'):
>> -        return AV_CODEC_ID_DVVIDEO;
>> -    case MKTAG('M', 'J', 'P', 'G'):
>> -    case MKTAG('m', 'j', 'p', 'g'):
>> -        return AV_CODEC_ID_MJPEG;
>> -    }
>> -    return AV_CODEC_ID_NONE;
>> -}
>> -
>>  static int
>>  dshow_read_close(AVFormatContext *s)
>>  {
>> @@ -375,7 +364,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
>>              if (!pformat_set) {
>>                  enum PixelFormat pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount);
>>                  if (pix_fmt == PIX_FMT_NONE) {
>> -                    enum AVCodecID codec_id = dshow_codecid(bih->biCompression);
>> +                    enum AVCodecID codec_id = ff_codec_get_id(ff_codec_bmp_tags, bih->biCompression);
>>                      AVCodec *codec = avcodec_find_decoder(codec_id);
>>                      if (codec_id == AV_CODEC_ID_NONE || !codec) {
>>                          av_log(avctx, AV_LOG_INFO, "  unknown compression type 0x%X", (int) bih->biCompression);
>> @@ -393,7 +382,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
>>                  continue;
>>              }
>>              if (ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO) {
>> -                if (ctx->video_codec_id != dshow_codecid(bih->biCompression))
>> +                if (ctx->video_codec_id != ff_codec_get_id(ff_codec_bmp_tags, bih->biCompression))
>>                      goto next;
>>              }
>>              if (ctx->pixel_format != PIX_FMT_NONE &&
>> @@ -780,7 +769,7 @@ dshow_add_device(AVFormatContext *avctx,
>>          codec->height     = bih->biHeight;
>>          codec->pix_fmt    = dshow_pixfmt(bih->biCompression, bih->biBitCount);
>>          if (codec->pix_fmt == PIX_FMT_NONE) {
>> -            codec->codec_id = dshow_codecid(bih->biCompression);
>> +            codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, bih->biCompression);
>>              if (codec->codec_id == AV_CODEC_ID_NONE) {
>>                  av_log(avctx, AV_LOG_ERROR, "Unknown compression type. "
>>                                   "Please report verbose (-v 9) debug information.\n");
>> --
>> 1.7.9.5
>
> LGTM assuming this is the expected behavior.

It appears to work fine in my tests.

>> From 6d743136a1c0e36416f598b43e68e2486ff4f214 Mon Sep 17 00:00:00 2001
>> From: rogerdpack <rogerpack2005 at gmail.com>
>> Date: Fri, 7 Sep 2012 17:32:26 -0600
>> Subject: [PATCH 3/3] dshow: allow for pin enumeration logs when capturing
>>
>>
>> Signed-off-by: rogerdpack <rogerpack2005 at gmail.com>
>> ---
>>  libavdevice/dshow.c |   61 ++++++++++++++++++++++++++++-----------------------
>>  1 file changed, 33 insertions(+), 28 deletions(-)
>>
>> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
>> index 562368d..2d1df5a 100644
>> --- a/libavdevice/dshow.c
>> +++ b/libavdevice/dshow.c
>> @@ -278,14 +278,13 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,
>>
>>          buf = dup_wchar_to_utf8(var.bstrVal);
>>
>> +        av_log(avctx, pfilter ? AV_LOG_DEBUG : AV_LOG_INFO, " \"%s\"\n", buf);
>>          if (pfilter) {
>>              if (strcmp(device_name, buf))
>>                  goto fail1;
>>
>>              if (!skip--)
>>                  IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter);
>> -        } else {
>> -            av_log(avctx, AV_LOG_INFO, " \"%s\"\n", buf);
>>          }
>>
>>  fail1:
>> @@ -325,7 +324,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
>>      AM_MEDIA_TYPE *type = NULL;
>>      int format_set = 0;
>>      void *caps = NULL;
>> -    int i, n, size;
>> +    int i, n, size, log_level;
>>
>>      if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (void **) &config) != S_OK)
>>          return;
>> @@ -347,6 +346,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
>>              VIDEO_STREAM_CONFIG_CAPS *vcaps = caps;
>>              BITMAPINFOHEADER *bih;
>>              int64_t *fr;
>> +            enum PixelFormat pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount);
>>  #if DSHOWDEBUG
>>              ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps);
>>  #endif
>> @@ -362,25 +362,30 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
>>                  goto next;
>>              }
>>              if (!pformat_set) {
>> -                enum PixelFormat pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount);
>> -                if (pix_fmt == PIX_FMT_NONE) {
>> -                    enum AVCodecID codec_id = ff_codec_get_id(ff_codec_bmp_tags, bih->biCompression);
>> -                    AVCodec *codec = avcodec_find_decoder(codec_id);
>> -                    if (codec_id == AV_CODEC_ID_NONE || !codec) {
>> -                        av_log(avctx, AV_LOG_INFO, "  unknown compression type 0x%X", (int) bih->biCompression);
>> -                    } else {
>> -                        av_log(avctx, AV_LOG_INFO, "  vcodec=%s", codec->name);
>> -                    }
>> +                log_level = AV_LOG_INFO;
>> +            } else {
>> +                log_level = AV_LOG_DEBUG;
>> +            }
>> +            pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount);
>> +            if (pix_fmt == PIX_FMT_NONE) {
>> +                enum AVCodecID codec_id = ff_codec_get_id(ff_codec_bmp_tags, bih->biCompression);
>> +                AVCodec *codec = avcodec_find_decoder(codec_id);
>> +                if (codec_id == AV_CODEC_ID_NONE || !codec) {
>> +                    av_log(avctx, log_level, "  unknown compression type 0x%X", (int) bih->biCompression);
>>                  } else {
>> -                    av_log(avctx, AV_LOG_INFO, "  pixel_format=%s", av_get_pix_fmt_name(pix_fmt));
>> +                    av_log(avctx, log_level, "  vcodec=%s", codec->name);
>>                  }
>> -                av_log(avctx, AV_LOG_INFO, "  min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g\n",
>> -                       vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy,
>> -                       1e7 / vcaps->MaxFrameInterval,
>> -                       vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy,
>> -                       1e7 / vcaps->MinFrameInterval);
>> -                continue;
>> +            } else {
>> +                av_log(avctx, log_level, "  pixel_format=%s", av_get_pix_fmt_name(pix_fmt));
>>              }
>> +            av_log(avctx, log_level, "  min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g\n",
>> +                   vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy,
>> +                   1e7 / vcaps->MaxFrameInterval,
>> +                   vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy,
>> +                   1e7 / vcaps->MinFrameInterval);
>> +            if (!pformat_set)
>> +                continue;
>> +
>>              if (ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO) {
>>                  if (ctx->video_codec_id != ff_codec_get_id(ff_codec_bmp_tags, bih->biCompression))
>>                      goto next;
>> @@ -417,12 +422,11 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
>>              } else {
>>                  goto next;
>>              }
>> -            if (!pformat_set) {
>> -                av_log(avctx, AV_LOG_INFO, "  min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n",
>> -                       acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency,
>> -                       acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency);
>> -                continue;
>> -            }
>> +            av_log(avctx, pformat_set ? AV_LOG_DEBUG : AV_LOG_INFO, "  min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n",
>> +                   acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency,
>> +                   acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency);
>> +            if (!pformat_set)
>> +              continue;
>>              if (ctx->sample_rate) {
>>                  if (ctx->sample_rate > acaps->MaximumSampleFrequency ||
>>                      ctx->sample_rate < acaps->MinimumSampleFrequency)
>> @@ -546,6 +550,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
>>          AM_MEDIA_TYPE *type;
>>          GUID category;
>>          DWORD r2;
>> +        char *buf;
>>
>>          IPin_QueryPinInfo(pin, &info);
>>          IBaseFilter_Release(info.pFilter);
>> @@ -560,10 +565,10 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
>>          if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))
>>              goto next;
>>
>> +        buf = dup_wchar_to_utf8(info.achName);
>> +        av_log(avctx, ppin ? AV_LOG_DEBUG : AV_LOG_INFO, " Pin \"%s\"\n", buf);
>> +        av_free(buf);
>>          if (!ppin) {
>> -            char *buf = dup_wchar_to_utf8(info.achName);
>> -            av_log(avctx, AV_LOG_INFO, " Pin \"%s\"\n", buf);
>> -            av_free(buf);
>>              dshow_cycle_formats(avctx, devtype, pin, NULL);
>>              goto next;
>>          }
>> --
>> 1.7.9.5
>
> Why don't you print it inconditionally with AV_LOG_INFO? That would be
> much simpler (and the patch more readable).

I guess my impetus was so that users could do:

$ ffmpeg -f dshow -list_options true -i video=XXX

and it would display options available, but by default, when they
*use* the device, it wouldn't show options unless loglevel debug is
turned on.

In retrospect, however, I suppose we can hold off on this patch until
a user actually needs/requests it, so safely ignore for now.

> no comment from me on dshow changes, iam not maintainer of that
>
> thanks
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Yes there is no official maintainer, though perhaps Ramiro could chime in.

I'd be happy to serve as the maintainer.

-roger-


More information about the ffmpeg-devel mailing list