[FFmpeg-devel] Fw: [PATCH] DirectShow patches
Stefano Sabatini
stefasab at gmail.com
Wed Sep 14 22:48:27 CEST 2011
On date Tuesday 2011-09-13 15:14:04 -0300, Ramiro Polla encoded:
> On Fri, Sep 9, 2011 at 7:08 PM, Stefano Sabatini
[...]
> From cb8f67c4422397e3df9d09c3bad396602c7a7f82 Mon Sep 17 00:00:00 2001
> From: Ramiro Polla <ramiro.polla at gmail.com>
> Date: Fri, 9 Sep 2011 00:10:07 -0300
> Subject: [PATCH 01/11] dshow: factorise cycling through pins
>
> ---
> libavdevice/dshow.c | 73 ++++++++++++++++++++++++++++++++------------------
> 1 files changed, 47 insertions(+), 26 deletions(-)
>
> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
> index 7035337..2ef313f 100644
> --- a/libavdevice/dshow.c
> +++ b/libavdevice/dshow.c
> @@ -295,42 +295,27 @@ fail1:
> return 0;
> }
>
> +/**
> + * Cycle through available pins using the device_filter device, of type
> + * devtype, retrieve the first output pin and return the pointer to the
> + * object found in *ppin.
> + */
> static int
> -dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
> - enum dshowDeviceType devtype)
> +dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
> + IBaseFilter *device_filter, IPin **ppin)
> {
> - struct dshow_ctx *ctx = avctx->priv_data;
> - IBaseFilter *device_filter = NULL;
> - IGraphBuilder *graph = ctx->graph;
> IEnumPins *pins = 0;
> IPin *device_pin = NULL;
> - libAVPin *capture_pin = NULL;
> - libAVFilter *capture_filter = NULL;
> - int ret = AVERROR(EIO);
> IPin *pin;
> int r;
>
> const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio };
> const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
> - const wchar_t *filter_name[2] = { L"Audio capture filter", L"Video capture filter" };
> -
> - if ((r = dshow_cycle_devices(avctx, devenum, devtype, &device_filter)) < 0) {
> - ret = r;
> - goto error;
> - }
> -
> - ctx->device_filter [devtype] = device_filter;
> -
> - r = IGraphBuilder_AddFilter(graph, device_filter, NULL);
> - if (r != S_OK) {
> - av_log(avctx, AV_LOG_ERROR, "Could not add device filter to graph.\n");
> - goto error;
> - }
>
> r = IBaseFilter_EnumPins(device_filter, &pins);
> if (r != S_OK) {
> av_log(avctx, AV_LOG_ERROR, "Could not enumerate pins.\n");
> - goto error;
> + return AVERROR(EIO);
> }
>
> while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK && !device_pin) {
> @@ -375,9 +360,48 @@ next:
> IPin_Release(pin);
> }
>
> + IEnumPins_Release(pins);
> +
> if (!device_pin) {
> av_log(avctx, AV_LOG_ERROR,
> "Could not find output pin from %s capture device.\n", devtypename);
> + return AVERROR(EIO);
> + }
> + *ppin = device_pin;
> +
> + return 0;
> +}
> +
> +static int
> +dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
> + enum dshowDeviceType devtype)
> +{
> + struct dshow_ctx *ctx = avctx->priv_data;
> + IBaseFilter *device_filter = NULL;
> + IGraphBuilder *graph = ctx->graph;
> + IPin *device_pin = NULL;
> + libAVPin *capture_pin = NULL;
> + libAVFilter *capture_filter = NULL;
> + int ret = AVERROR(EIO);
> + int r;
> +
> + const wchar_t *filter_name[2] = { L"Audio capture filter", L"Video capture filter" };
> +
> + if ((r = dshow_cycle_devices(avctx, devenum, devtype, &device_filter)) < 0) {
> + ret = r;
> + goto error;
> + }
> +
> + ctx->device_filter [devtype] = device_filter;
> +
> + r = IGraphBuilder_AddFilter(graph, device_filter, NULL);
> + if (r != S_OK) {
> + av_log(avctx, AV_LOG_ERROR, "Could not add device filter to graph.\n");
> + goto error;
> + }
> +
> + if ((r = dshow_cycle_pins(avctx, devtype, device_filter, &device_pin)) < 0) {
> + ret = r;
> goto error;
> }
> ctx->device_pin[devtype] = device_pin;
> @@ -409,9 +433,6 @@ next:
> ret = 0;
>
> error:
> - if (pins)
> - IEnumPins_Release(pins);
> -
> return ret;
> }
>
> --
> 1.7.4.1
Looks fine.
> From 912fbebf3b3ee7837dec4f6fe449b4151379881e Mon Sep 17 00:00:00 2001
> From: Ramiro Polla <ramiro.polla at gmail.com>
> Date: Fri, 9 Sep 2011 00:10:22 -0300
> Subject: [PATCH 02/11] dshow: initialize variable to prevent releasing random data
>
> ---
> libavdevice/dshow.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
> index 2ef313f..fe60b9f 100644
> --- a/libavdevice/dshow.c
> +++ b/libavdevice/dshow.c
> @@ -320,7 +320,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
>
> while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK && !device_pin) {
> IKsPropertySet *p = NULL;
> - IEnumMediaTypes *types;
> + IEnumMediaTypes *types = NULL;
> PIN_INFO info = {0};
> AM_MEDIA_TYPE *type;
> GUID category;
> --
> 1.7.4.1
Sounds good.
> From 688c2f45399008623a05e76b713fcb2c12aa061f Mon Sep 17 00:00:00 2001
> From: Ramiro Polla <ramiro.polla at gmail.com>
> Date: Fri, 9 Sep 2011 00:12:42 -0300
> Subject: [PATCH 03/11] dshow: add audio/video options
>
> ---
> libavdevice/dshow.c | 160 ++++++++++++++++++++++++++++++++++++++++++++
> libavdevice/dshow.h | 2 +
> libavdevice/dshow_common.c | 49 +++++++++++++
> 3 files changed, 211 insertions(+), 0 deletions(-)
>
> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
> index fe60b9f..379689f 100644
> --- a/libavdevice/dshow.c
> +++ b/libavdevice/dshow.c
> @@ -19,6 +19,7 @@
> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> */
>
> +#include "libavutil/parseutils.h"
> #include "libavutil/opt.h"
>
> #include "avdevice.h"
> @@ -46,6 +47,17 @@ struct dshow_ctx {
> unsigned int video_frame_num;
>
> IMediaControl *control;
> +
> + char *video_size;
> + char *framerate;
> +
> + int requested_width;
> + int requested_height;
> + AVRational requested_framerate;
> +
> + int sample_rate;
> + int sample_size;
> + int channels;
> };
>
> static enum PixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount)
> @@ -296,6 +308,118 @@ fail1:
> }
>
> /**
> + * Cycle through available formats using the specified pin,
> + * try to set parameters specified through AVOptions and if successful
> + * return 1 in *pformat_set.
> + */
> +static void
> +dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
> + IPin *pin, int *pformat_set)
> +{
> + struct dshow_ctx *ctx = avctx->priv_data;
> + IAMStreamConfig *config = NULL;
> + AM_MEDIA_TYPE *type = NULL;
> + int format_set = 0;
> + void *caps = NULL;
> + int i, n, size;
> +
> + if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (void **) &config) != S_OK)
> + return;
> + if (IAMStreamConfig_GetNumberOfCapabilities(config, &n, &size) != S_OK)
> + goto end;
> +
> + caps = av_malloc(size);
> + if (!caps)
> + goto end;
> +
> + for (i = 0; i < n && !format_set; i++) {
> + IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps);
> +
> +#if DSHOWDEBUG
> + ff_print_AM_MEDIA_TYPE(type);
> +#endif
> +
> + if (devtype == VideoDevice) {
> + VIDEO_STREAM_CONFIG_CAPS *vcaps = caps;
> + BITMAPINFOHEADER *bih;
> + int64_t *fr;
> +#if DSHOWDEBUG
> + ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps);
> +#endif
> + if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) {
> + VIDEOINFOHEADER *v = (void *) type->pbFormat;
> + fr = &v->AvgTimePerFrame;
> + bih = &v->bmiHeader;
> + } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) {
> + VIDEOINFOHEADER2 *v = (void *) type->pbFormat;
> + fr = &v->AvgTimePerFrame;
> + bih = &v->bmiHeader;
> + } else {
> + goto next;
> + }
> + if (ctx->framerate) {
> + int64_t framerate = ((int64_t) ctx->requested_framerate.den*10000000)
> + / ctx->requested_framerate.num;
> + if (framerate > vcaps->MaxFrameInterval ||
> + framerate < vcaps->MinFrameInterval)
> + goto next;
> + *fr = framerate;
> + }
> + if (ctx->video_size) {
> + if (ctx->requested_width > vcaps->MaxOutputSize.cx ||
> + ctx->requested_width < vcaps->MinOutputSize.cx ||
> + ctx->requested_height > vcaps->MaxOutputSize.cy ||
> + ctx->requested_height < vcaps->MinOutputSize.cy)
> + goto next;
> + bih->biWidth = ctx->requested_width;
> + bih->biHeight = ctx->requested_height;
> + }
> + } else {
> + AUDIO_STREAM_CONFIG_CAPS *acaps = caps;
> + WAVEFORMATEX *fx;
> +#if DSHOWDEBUG
> + ff_print_AUDIO_STREAM_CONFIG_CAPS(acaps);
> +#endif
> + if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) {
> + fx = (void *) type->pbFormat;
> + } else {
> + goto next;
> + }
> + if (ctx->sample_rate) {
> + if (ctx->sample_rate > acaps->MaximumSampleFrequency ||
> + ctx->sample_rate < acaps->MinimumSampleFrequency)
> + goto next;
> + fx->nSamplesPerSec = ctx->sample_rate;
> + }
> + if (ctx->sample_size) {
> + if (ctx->sample_size > acaps->MaximumBitsPerSample ||
> + ctx->sample_size < acaps->MinimumBitsPerSample)
> + goto next;
> + fx->wBitsPerSample = ctx->sample_size;
> + }
> + if (ctx->channels) {
> + if (ctx->channels > acaps->MaximumChannels ||
> + ctx->channels < acaps->MinimumChannels)
> + goto next;
> + fx->nChannels = ctx->channels;
> + }
> + }
> + if (IAMStreamConfig_SetFormat(config, type) != S_OK)
> + goto next;
> + format_set = 1;
> +next:
> + if (type->pbFormat)
> + CoTaskMemFree(type->pbFormat);
> + CoTaskMemFree(type);
> + }
> +end:
> + IAMStreamConfig_Release(config);
> + if (caps)
> + av_free(caps);
> + *pformat_set = format_set;
> +}
> +
> +/**
> * Cycle through available pins using the device_filter device, of type
> * devtype, retrieve the first output pin and return the pointer to the
> * object found in *ppin.
> @@ -304,6 +428,7 @@ static int
> dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
> IBaseFilter *device_filter, IPin **ppin)
> {
> + struct dshow_ctx *ctx = avctx->priv_data;
> IEnumPins *pins = 0;
> IPin *device_pin = NULL;
> IPin *pin;
> @@ -312,6 +437,10 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
> const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio };
> const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
>
> + int set_format = (devtype == VideoDevice && (ctx->video_size || ctx->framerate))
> + || (devtype == AudioDevice && (ctx->channels || ctx->sample_rate));
> + int format_set = 0;
> +
> r = IBaseFilter_EnumPins(device_filter, &pins);
> if (r != S_OK) {
> av_log(avctx, AV_LOG_ERROR, "Could not enumerate pins.\n");
> @@ -339,6 +468,13 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
> if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))
> goto next;
>
> + if (set_format) {
> + dshow_cycle_formats(avctx, devtype, pin, &format_set);
> + if (!format_set) {
> + goto next;
> + }
> + }
> +
> if (IPin_EnumMediaTypes(pin, &types) != S_OK)
> goto next;
>
> @@ -362,6 +498,10 @@ next:
>
> IEnumPins_Release(pins);
>
> + if (set_format && !format_set) {
> + av_log(avctx, AV_LOG_ERROR, "Could not set %s options\n", devtypename);
> + return AVERROR(EIO);
> + }
> if (!device_pin) {
> av_log(avctx, AV_LOG_ERROR,
> "Could not find output pin from %s capture device.\n", devtypename);
> @@ -594,6 +734,21 @@ static int dshow_read_header(AVFormatContext *avctx, AVFormatParameters *ap)
> goto error;
> }
>
> + if (ctx->video_size) {
> + r = av_parse_video_size(&ctx->requested_width, &ctx->requested_height, ctx->video_size);
> + if (r < 0) {
> + av_log(avctx, AV_LOG_ERROR, "Could not parse video size.\n");
Nit: av_log(avctx, AV_LOG_ERROR, "Could not parse video size '%s'.\n", ctx->video_size);
> + goto error;
> + }
> + }
> + if (ctx->framerate) {
> + r = av_parse_video_rate(&ctx->requested_framerate, ctx->framerate);
> + if (r < 0) {
> + av_log(avctx, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", ctx->framerate);
> + goto error;
> + }
> + }
> +
> CoInitialize(0);
>
> r = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
> @@ -710,6 +865,11 @@ static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt)
> #define OFFSET(x) offsetof(struct dshow_ctx, x)
> #define DEC AV_OPT_FLAG_DECODING_PARAM
> static const AVOption options[] = {
> + { "video_size", "set video size given a string such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
> + { "framerate", "set video frame rate", OFFSET(framerate), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
> + { "sample_rate", "set audio sample rate, such as 8000 or 44100", OFFSET(sample_rate), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, DEC },
> + { "sample_size", "set audio sample size, such as 8 or 16", OFFSET(sample_size), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 16, DEC },
> + { "channels", "set number of audio channels, such as 1 or 2", OFFSET(channels), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, DEC },
nit++: the examples shown here are a bit overkill imo, since no
special syntax is used
> { "list_devices", "list available devices", OFFSET(list_devices), FF_OPT_TYPE_INT, {.dbl=0}, 0, 1, DEC, "list_devices" },
> { "true", "", 0, FF_OPT_TYPE_CONST, {.dbl=1}, 0, 0, DEC, "list_devices" },
> { "false", "", 0, FF_OPT_TYPE_CONST, {.dbl=0}, 0, 0, DEC, "list_devices" },
> diff --git a/libavdevice/dshow.h b/libavdevice/dshow.h
> index 4e79680..83c71c4 100644
> --- a/libavdevice/dshow.h
> +++ b/libavdevice/dshow.h
> @@ -29,6 +29,8 @@
> #include <dvdmedia.h>
>
> long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src);
> +void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps);
> +void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps);
> void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type);
> void ff_printGUID(const GUID *g);
>
> diff --git a/libavdevice/dshow_common.c b/libavdevice/dshow_common.c
> index c813dc1..8fe2f77 100644
> --- a/libavdevice/dshow_common.c
> +++ b/libavdevice/dshow_common.c
> @@ -82,6 +82,55 @@ static void dump_bih(void *s, BITMAPINFOHEADER *bih)
> }
> #endif
>
> +void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps)
> +{
> +#if DSHOWDEBUG
> + dshowdebug(" VIDEO_STREAM_CONFIG_CAPS\n");
> + dshowdebug(" guid\t");
> + ff_printGUID(&caps->guid);
> + dshowdebug("\n");
> + dshowdebug(" VideoStandard\t%lu\n", caps->VideoStandard);
> + dshowdebug(" InputSize %ld\t%ld\n", caps->InputSize.cx, caps->InputSize.cy);
> + dshowdebug(" MinCroppingSize %ld\t%ld\n", caps->MinCroppingSize.cx, caps->MinCroppingSize.cy);
> + dshowdebug(" MaxCroppingSize %ld\t%ld\n", caps->MaxCroppingSize.cx, caps->MaxCroppingSize.cy);
> + dshowdebug(" CropGranularityX\t%d\n", caps->CropGranularityX);
> + dshowdebug(" CropGranularityY\t%d\n", caps->CropGranularityY);
> + dshowdebug(" CropAlignX\t%d\n", caps->CropAlignX);
> + dshowdebug(" CropAlignY\t%d\n", caps->CropAlignY);
> + dshowdebug(" MinOutputSize %ld\t%ld\n", caps->MinOutputSize.cx, caps->MinOutputSize.cy);
> + dshowdebug(" MaxOutputSize %ld\t%ld\n", caps->MaxOutputSize.cx, caps->MaxOutputSize.cy);
> + dshowdebug(" OutputGranularityX\t%d\n", caps->OutputGranularityX);
> + dshowdebug(" OutputGranularityY\t%d\n", caps->OutputGranularityY);
> + dshowdebug(" StretchTapsX\t%d\n", caps->StretchTapsX);
> + dshowdebug(" StretchTapsY\t%d\n", caps->StretchTapsY);
> + dshowdebug(" ShrinkTapsX\t%d\n", caps->ShrinkTapsX);
> + dshowdebug(" ShrinkTapsY\t%d\n", caps->ShrinkTapsY);
> + dshowdebug(" MinFrameInterval\t%"PRId64"\n", caps->MinFrameInterval);
> + dshowdebug(" MaxFrameInterval\t%"PRId64"\n", caps->MaxFrameInterval);
> + dshowdebug(" MinBitsPerSecond\t%ld\n", caps->MinBitsPerSecond);
> + dshowdebug(" MaxBitsPerSecond\t%ld\n", caps->MaxBitsPerSecond);
> +#endif
> +}
> +
> +void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps)
> +{
> +#if DSHOWDEBUG
> + dshowdebug(" AUDIO_STREAM_CONFIG_CAPS\n");
> + dshowdebug(" guid\t");
> + ff_printGUID(&caps->guid);
> + dshowdebug("\n");
> + dshowdebug(" MinimumChannels\t%lu\n", caps->MinimumChannels);
> + dshowdebug(" MaximumChannels\t%lu\n", caps->MaximumChannels);
> + dshowdebug(" ChannelsGranularity\t%lu\n", caps->ChannelsGranularity);
> + dshowdebug(" MinimumBitsPerSample\t%lu\n", caps->MinimumBitsPerSample);
> + dshowdebug(" MaximumBitsPerSample\t%lu\n", caps->MaximumBitsPerSample);
> + dshowdebug(" BitsPerSampleGranularity\t%lu\n", caps->BitsPerSampleGranularity);
> + dshowdebug(" MinimumSampleFrequency\t%lu\n", caps->MinimumSampleFrequency);
> + dshowdebug(" MaximumSampleFrequency\t%lu\n", caps->MaximumSampleFrequency);
> + dshowdebug(" SampleFrequencyGranularity\t%lu\n", caps->SampleFrequencyGranularity);
> +#endif
> +}
> +
> void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type)
> {
> #if DSHOWDEBUG
> --
> 1.7.4.1
Reads fine otherwise, I can fix the patch myself before committing if
you don't care/don't have time for it.
> From 00cb1e6f9ffe89ece3293f1a78edbdb118d653a0 Mon Sep 17 00:00:00 2001
> From: Ramiro Polla <ramiro.polla at gmail.com>
> Date: Fri, 9 Sep 2011 00:15:14 -0300
> Subject: [PATCH 04/11] dshow: add option to list audio/video options
>
> ---
> libavdevice/dshow.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 57 insertions(+), 0 deletions(-)
>
> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
> index 379689f..0ef7a5d 100644
> --- a/libavdevice/dshow.c
> +++ b/libavdevice/dshow.c
> @@ -32,6 +32,7 @@ struct dshow_ctx {
>
> char *device_name[2];
>
> + int list_options;
> int list_devices;
>
> IBaseFilter *device_filter[2];
> @@ -311,6 +312,7 @@ fail1:
> * Cycle through available formats using the specified pin,
> * try to set parameters specified through AVOptions and if successful
> * return 1 in *pformat_set.
> + * If pformat_set is NULL, list all pin capabilities.
> */
> static void
> dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
> @@ -357,6 +359,14 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
> } else {
> goto next;
> }
> + if (!pformat_set) {
> + 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->MinFrameInterval,
> + vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy,
> + 1e7 / vcaps->MaxFrameInterval);
> + continue;
> + }
> if (ctx->framerate) {
> int64_t framerate = ((int64_t) ctx->requested_framerate.den*10000000)
> / ctx->requested_framerate.num;
> @@ -385,6 +395,12 @@ 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;
> + }
> if (ctx->sample_rate) {
> if (ctx->sample_rate > acaps->MaximumSampleFrequency ||
> ctx->sample_rate < acaps->MinimumSampleFrequency)
> @@ -416,6 +432,7 @@ end:
> IAMStreamConfig_Release(config);
> if (caps)
> av_free(caps);
> + if (pformat_set)
> *pformat_set = format_set;
> }
>
> @@ -423,6 +440,7 @@ end:
> * Cycle through available pins using the device_filter device, of type
> * devtype, retrieve the first output pin and return the pointer to the
> * object found in *ppin.
> + * If ppin is NULL, cycle through all pins listing audio/video capabilities.
> */
> static int
> dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
> @@ -447,6 +465,10 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
> return AVERROR(EIO);
> }
>
> + if (!ppin) {
> + av_log(avctx, AV_LOG_INFO, "DirectShow %s device options\n",
> + devtypename);
> + }
> while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK && !device_pin) {
> IKsPropertySet *p = NULL;
> IEnumMediaTypes *types = NULL;
> @@ -468,6 +490,13 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
> if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))
> goto next;
>
> + 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;
> + }
> if (set_format) {
> dshow_cycle_formats(avctx, devtype, pin, &format_set);
> if (!format_set) {
> @@ -498,6 +527,7 @@ next:
>
> IEnumPins_Release(pins);
>
> + if (ppin) {
> if (set_format && !format_set) {
> av_log(avctx, AV_LOG_ERROR, "Could not set %s options\n", devtypename);
> return AVERROR(EIO);
> @@ -508,6 +538,22 @@ next:
> return AVERROR(EIO);
> }
> *ppin = device_pin;
> + }
> +
> + return 0;
> +}
> +
> +static int
> +dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum,
> + enum dshowDeviceType devtype)
A doxy here may be useful as well, something along the lines of:
|List options for device with type devtype retrieved by using the
|device enumerator in devenum.
> +{
> + IBaseFilter *device_filter = NULL;
> + int r;
> +
> + if ((r = dshow_cycle_devices(avctx, devenum, devtype, &device_filter)) < 0)
> + return r;
> + if ((r = dshow_cycle_pins(avctx, devtype, device_filter, NULL)) < 0)
> + return r;
>
> return 0;
> }
> @@ -774,6 +820,14 @@ static int dshow_read_header(AVFormatContext *avctx, AVFormatParameters *ap)
> ret = AVERROR_EXIT;
> goto error;
> }
> + if (ctx->list_options) {
> + if (ctx->device_name[VideoDevice])
> + dshow_list_device_options(avctx, devenum, VideoDevice);
> + if (ctx->device_name[AudioDevice])
> + dshow_list_device_options(avctx, devenum, AudioDevice);
> + ret = AVERROR_EXIT;
> + goto error;
> + }
Note: would be possible to find more than one audio/video "subdevices"
in a single dshow device?
> if (ctx->device_name[VideoDevice]) {
> ret = dshow_open_device(avctx, devenum, VideoDevice);
> @@ -873,6 +927,9 @@ static const AVOption options[] = {
> { "list_devices", "list available devices", OFFSET(list_devices), FF_OPT_TYPE_INT, {.dbl=0}, 0, 1, DEC, "list_devices" },
> { "true", "", 0, FF_OPT_TYPE_CONST, {.dbl=1}, 0, 0, DEC, "list_devices" },
> { "false", "", 0, FF_OPT_TYPE_CONST, {.dbl=0}, 0, 0, DEC, "list_devices" },
> + { "list_options", "list available options for specified device", OFFSET(list_options), FF_OPT_TYPE_INT, {.dbl=0}, 0, 1, DEC, "list_options" },
> + { "true", "", 0, FF_OPT_TYPE_CONST, {.dbl=1}, 0, 0, DEC, "list_options" },
> + { "false", "", 0, FF_OPT_TYPE_CONST, {.dbl=0}, 0, 0, DEC, "list_options" },
Note: we may introduce a new type FF_OPT_TYPE_BOOL for dealing with
these options.
> { NULL },
> };
>
> --
> 1.7.4.1
Looks fine otherwise.
> From 49c97934c24ee12530f69444f7066716c99472bb Mon Sep 17 00:00:00 2001
> From: Ramiro Polla <ramiro.polla at gmail.com>
> Date: Fri, 9 Sep 2011 00:15:22 -0300
> Subject: [PATCH 05/11] dshow: indent
>
> ---
> libavdevice/dshow.c | 22 +++++++++++-----------
> 1 files changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
> index 0ef7a5d..c5122eb 100644
> --- a/libavdevice/dshow.c
> +++ b/libavdevice/dshow.c
> @@ -433,7 +433,7 @@ end:
> if (caps)
> av_free(caps);
> if (pformat_set)
> - *pformat_set = format_set;
> + *pformat_set = format_set;
> }
>
> /**
> @@ -528,16 +528,16 @@ next:
> IEnumPins_Release(pins);
>
> if (ppin) {
> - if (set_format && !format_set) {
> - av_log(avctx, AV_LOG_ERROR, "Could not set %s options\n", devtypename);
> - return AVERROR(EIO);
> - }
> - if (!device_pin) {
> - av_log(avctx, AV_LOG_ERROR,
> - "Could not find output pin from %s capture device.\n", devtypename);
> - return AVERROR(EIO);
> - }
> - *ppin = device_pin;
> + if (set_format && !format_set) {
> + av_log(avctx, AV_LOG_ERROR, "Could not set %s options\n", devtypename);
> + return AVERROR(EIO);
> + }
> + if (!device_pin) {
> + av_log(avctx, AV_LOG_ERROR,
> + "Could not find output pin from %s capture device.\n", devtypename);
> + return AVERROR(EIO);
> + }
> + *ppin = device_pin;
> }
>
> return 0;
> --
> 1.7.4.1
Should be fine if I'm not blind.
> From 358b1a30bae6d497e34120362c07e594fd6042e2 Mon Sep 17 00:00:00 2001
> From: Ramiro Polla <ramiro.polla at gmail.com>
> Date: Fri, 9 Sep 2011 00:15:41 -0300
> Subject: [PATCH 06/11] doc: add documentation for dshow indev
>
> ---
> doc/indevs.texi | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 77 insertions(+), 0 deletions(-)
[...]
I suppose it is the same already posted, so it should be still OK
(assuming I didn't change my state ;-)).
> From 90bd28a77200aeebbe99ad66f79574f7407ed87f Mon Sep 17 00:00:00 2001
> From: Ramiro Polla <ramiro.polla at gmail.com>
> Date: Fri, 9 Sep 2011 00:15:54 -0300
> Subject: [PATCH 07/11] dshow: release pin on disconnect
>
> ---
> libavdevice/dshow_pin.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c
> index f31ecc6..5e14108 100644
> --- a/libavdevice/dshow_pin.c
> +++ b/libavdevice/dshow_pin.c
> @@ -73,6 +73,7 @@ libAVPin_Disconnect(libAVPin *this)
> return VFW_E_NOT_STOPPED;
> if (!this->connectedto)
> return S_FALSE;
> + IPin_Release(this->connectedto);
> this->connectedto = NULL;
>
> return S_OK;
> --
> 1.7.4.1
Should be still fine.
> From 4367929e083dfc75e5b8efbcd523c2f770be4a25 Mon Sep 17 00:00:00 2001
> From: Ramiro Polla <ramiro.polla at gmail.com>
> Date: Fri, 9 Sep 2011 00:16:06 -0300
> Subject: [PATCH 08/11] dshow: cleanup internal references on capture interface
>
> ---
> libavdevice/dshow_enumpins.c | 8 +++++++-
> libavdevice/dshow_filter.c | 8 +++++++-
> 2 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/libavdevice/dshow_enumpins.c b/libavdevice/dshow_enumpins.c
> index 97890fb..02e967a 100644
> --- a/libavdevice/dshow_enumpins.c
> +++ b/libavdevice/dshow_enumpins.c
> @@ -94,6 +94,12 @@ libAVEnumPins_Setup(libAVEnumPins *this, libAVPin *pin, libAVFilter *filter)
>
> return 1;
> }
> +static int
> +libAVEnumPins_Cleanup(libAVEnumPins *this)
> +{
> + libAVFilter_Release(this->filter);
> + return 1;
> +}
> DECLARE_CREATE(libAVEnumPins, libAVEnumPins_Setup(this, pin, filter),
> libAVPin *pin, libAVFilter *filter)
> -DECLARE_DESTROY(libAVEnumPins, nothing)
> +DECLARE_DESTROY(libAVEnumPins, libAVEnumPins_Cleanup)
> diff --git a/libavdevice/dshow_filter.c b/libavdevice/dshow_filter.c
> index e5a3be8..64e8306 100644
> --- a/libavdevice/dshow_filter.c
> +++ b/libavdevice/dshow_filter.c
> @@ -191,6 +191,12 @@ libAVFilter_Setup(libAVFilter *this, void *priv_data, void *callback,
>
> return 1;
> }
> +static int
> +libAVFilter_Cleanup(libAVFilter *this)
> +{
> + libAVPin_Release(this->pin);
> + return 1;
> +}
> DECLARE_CREATE(libAVFilter, libAVFilter_Setup(this, priv_data, callback, type),
> void *priv_data, void *callback, enum dshowDeviceType type)
> -DECLARE_DESTROY(libAVFilter, nothing)
> +DECLARE_DESTROY(libAVFilter, libAVFilter_Cleanup)
> --
> 1.7.4.1
I assume this is correct (without checking the fine msdev.com).
> From 8d5ce3d7000cb7a985d3b2bf469b4165f94a6cc0 Mon Sep 17 00:00:00 2001
> From: Ramiro Polla <ramiro.polla at gmail.com>
> Date: Fri, 9 Sep 2011 00:16:17 -0300
> Subject: [PATCH 09/11] dshow: invert condition to avoid leaking objects
>
> ---
> libavdevice/dshow.c | 6 +++---
> 1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
> index c5122eb..a5b011d 100644
> --- a/libavdevice/dshow.c
> +++ b/libavdevice/dshow.c
> @@ -261,7 +261,7 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,
> return AVERROR(EIO);
> }
>
> - while (IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK && !device_filter) {
> + while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) {
> IPropertyBag *bag = NULL;
> char *buf = NULL;
> VARIANT var;
> @@ -469,7 +469,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
> av_log(avctx, AV_LOG_INFO, "DirectShow %s device options\n",
> devtypename);
> }
> - while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK && !device_pin) {
> + while (!device_pin && IEnumPins_Next(pins, 1, &pin, NULL) == S_OK) {
> IKsPropertySet *p = NULL;
> IEnumMediaTypes *types = NULL;
> PIN_INFO info = {0};
> @@ -508,7 +508,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
> goto next;
>
> IEnumMediaTypes_Reset(types);
> - while (IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK && !device_pin) {
> + while (!device_pin && IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK) {
> if (IsEqualGUID(&type->majortype, mediatype[devtype])) {
> device_pin = pin;
> goto next;
> --
> 1.7.4.1
>
> From abea756be47729d52fe825d89204752a1a9ef341 Mon Sep 17 00:00:00 2001
> From: Ramiro Polla <ramiro.polla at gmail.com>
> Date: Tue, 13 Sep 2011 14:55:08 -0300
> Subject: [PATCH 10/11] dshow: reset list for each filter removed
>
> ---
> libavdevice/dshow.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
> index a5b011d..b04f13e 100644
> --- a/libavdevice/dshow.c
> +++ b/libavdevice/dshow.c
> @@ -138,7 +138,9 @@ dshow_read_close(AVFormatContext *s)
> IBaseFilter *f;
> IEnumFilters_Reset(fenum);
> while (IEnumFilters_Next(fenum, 1, &f, NULL) == S_OK)
> - IGraphBuilder_RemoveFilter(ctx->graph, f);
> + if (IGraphBuilder_RemoveFilter(ctx->graph, f) == S_OK)
> + IEnumFilters_Reset(fenum); /* When a filter is removed,
> + * the list must be reset. */
> IEnumFilters_Release(fenum);
> }
> IGraphBuilder_Release(ctx->graph);
> --
> 1.7.4.1
Seems correct.
> From 1bd8db2716816a984161550887a7a035740a296e Mon Sep 17 00:00:00 2001
> From: Ramiro Polla <ramiro.polla at gmail.com>
> Date: Tue, 13 Sep 2011 14:56:28 -0300
> Subject: [PATCH 11/11] dshow: remove filters from graph before releasing them
>
> ---
> libavdevice/dshow.c | 32 ++++++++++++++++----------------
> 1 files changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
> index b04f13e..d505610 100644
> --- a/libavdevice/dshow.c
> +++ b/libavdevice/dshow.c
> @@ -112,6 +112,22 @@ dshow_read_close(AVFormatContext *s)
> IMediaControl_Release(ctx->control);
> }
>
> + if (ctx->graph) {
> + IEnumFilters *fenum;
> + int r;
> + r = IGraphBuilder_EnumFilters(ctx->graph, &fenum);
> + if (r == S_OK) {
> + IBaseFilter *f;
> + IEnumFilters_Reset(fenum);
> + while (IEnumFilters_Next(fenum, 1, &f, NULL) == S_OK)
> + if (IGraphBuilder_RemoveFilter(ctx->graph, f) == S_OK)
> + IEnumFilters_Reset(fenum); /* When a filter is removed,
> + * the list must be reset. */
> + IEnumFilters_Release(fenum);
> + }
> + IGraphBuilder_Release(ctx->graph);
> + }
> +
> if (ctx->capture_pin[VideoDevice])
> libAVPin_Release(ctx->capture_pin[VideoDevice]);
> if (ctx->capture_pin[AudioDevice])
> @@ -130,22 +146,6 @@ dshow_read_close(AVFormatContext *s)
> if (ctx->device_filter[AudioDevice])
> IBaseFilter_Release(ctx->device_filter[AudioDevice]);
>
> - if (ctx->graph) {
> - IEnumFilters *fenum;
> - int r;
> - r = IGraphBuilder_EnumFilters(ctx->graph, &fenum);
> - if (r == S_OK) {
> - IBaseFilter *f;
> - IEnumFilters_Reset(fenum);
> - while (IEnumFilters_Next(fenum, 1, &f, NULL) == S_OK)
> - if (IGraphBuilder_RemoveFilter(ctx->graph, f) == S_OK)
> - IEnumFilters_Reset(fenum); /* When a filter is removed,
> - * the list must be reset. */
> - IEnumFilters_Release(fenum);
> - }
> - IGraphBuilder_Release(ctx->graph);
> - }
> -
It seems correct to me.
Of course I assume all your patches have been tested. I'll push them
in a few days if no one wants to comment on the patches, I can
eventually fix the few remaining nits myself before committing in case
you don't reply to this one.
Thanks for the patches!
--
FFmpeg = Funny Fostering Mean Programmable Extreme Glue
More information about the ffmpeg-devel
mailing list