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;

    int r;



    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");

        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;

        PIN_INFO info = {0};

        AM_MEDIA_TYPE *type;

        GUID category;

        DWORD r2;



        IPin_QueryPinInfo(pin, &info);

        IBaseFilter_Release(info.pFilter);



        if (info.dir != PINDIR_OUTPUT)

            goto next;

        if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **) &p) != S_OK)

            goto next;

        if (IKsPropertySet_Get(p, &AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,

                               NULL, 0, &category, sizeof(GUID), &r2) != S_OK)

            goto next;

        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) {

                goto next;

            }

        }



        if (IPin_EnumMediaTypes(pin, &types) != S_OK)

            goto next;



        IEnumMediaTypes_Reset(types);

        while (IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK && !device_pin) {

            if (IsEqualGUID(&type->majortype, mediatype[devtype])) {

                device_pin = pin;

                goto next;

            }

            CoTaskMemFree(type);

        }



next:

        if (types)

            IEnumMediaTypes_Release(types);

        if (p)

            IKsPropertySet_Release(p);

        if (device_pin != pin)

            IPin_Release(pin);

    }



    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;

    }



    return 0;

}

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;

    int r;



    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");

        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;

        PIN_INFO info = {0};

        AM_MEDIA_TYPE *type;

        GUID category;

        DWORD r2;



        IPin_QueryPinInfo(pin, &info);

        IBaseFilter_Release(info.pFilter);



        if (info.dir != PINDIR_OUTPUT)

            goto next;

        if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **) &p) != S_OK)

            goto next;

        if (IKsPropertySet_Get(p, &AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,

                               NULL, 0, &category, sizeof(GUID), &r2) != S_OK)

            goto next;

        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) {

                goto next;

            }

        }



        if (IPin_EnumMediaTypes(pin, &types) != S_OK)

            goto next;



        IEnumMediaTypes_Reset(types);

        while (IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK && !device_pin) {

            if (IsEqualGUID(&type->majortype, mediatype[devtype])) {

                device_pin = pin;

                goto next;

            }

            CoTaskMemFree(type);

        }



next:

        if (types)

            IEnumMediaTypes_Release(types);

        if (p)

            IKsPropertySet_Release(p);

        if (device_pin != pin)

            IPin_Release(pin);

    }



    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;

    }



    return 0;

}

    while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK && !device_pin) {         while (IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK && !device_pin) {
FUNC_0(AVFormatContext *VAR_0, enum dshowDeviceType VAR_1,

                 IBaseFilter *VAR_2, IPin **VAR_3)

{

    struct dshow_ctx *VAR_4 = VAR_0->priv_data;

    IEnumPins *pins = 0;

    IPin *device_pin = NULL;

    IPin *pin;

    int VAR_5;



    const GUID *VAR_6[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio };

    const char *VAR_7 = (VAR_1 == VideoDevice) ? "video" : "audio";



    int VAR_8 = (VAR_1 == VideoDevice && (VAR_4->video_size || VAR_4->framerate))

                  || (VAR_1 == AudioDevice && (VAR_4->channels || VAR_4->sample_rate));

    int VAR_9 = 0;



    VAR_5 = IBaseFilter_EnumPins(VAR_2, &pins);

    if (VAR_5 != S_OK) {

        av_log(VAR_0, AV_LOG_ERROR, "Could not enumerate pins.\n");

        return AVERROR(EIO);

    }



    if (!VAR_3) {

        av_log(VAR_0, AV_LOG_INFO, "DirectShow %s device options\n",

               VAR_7);

    }

    while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK && !device_pin) {

        IKsPropertySet *p = NULL;

        IEnumMediaTypes *types = NULL;

        PIN_INFO info = {0};

        AM_MEDIA_TYPE *type;

        GUID category;

        DWORD r2;



        IPin_QueryPinInfo(pin, &info);

        IBaseFilter_Release(info.pFilter);



        if (info.dir != PINDIR_OUTPUT)

            goto next;

        if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **) &p) != S_OK)

            goto next;

        if (IKsPropertySet_Get(p, &AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,

                               NULL, 0, &category, sizeof(GUID), &r2) != S_OK)

            goto next;

        if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))

            goto next;



        if (!VAR_3) {

            char *VAR_10 = dup_wchar_to_utf8(info.achName);

            av_log(VAR_0, AV_LOG_INFO, " Pin \"%s\"\n", VAR_10);

            av_free(VAR_10);

            dshow_cycle_formats(VAR_0, VAR_1, pin, NULL);

            goto next;

        }

        if (VAR_8) {

            dshow_cycle_formats(VAR_0, VAR_1, pin, &VAR_9);

            if (!VAR_9) {

                goto next;

            }

        }



        if (IPin_EnumMediaTypes(pin, &types) != S_OK)

            goto next;



        IEnumMediaTypes_Reset(types);

        while (IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK && !device_pin) {

            if (IsEqualGUID(&type->majortype, VAR_6[VAR_1])) {

                device_pin = pin;

                goto next;

            }

            CoTaskMemFree(type);

        }



next:

        if (types)

            IEnumMediaTypes_Release(types);

        if (p)

            IKsPropertySet_Release(p);

        if (device_pin != pin)

            IPin_Release(pin);

    }



    IEnumPins_Release(pins);



    if (VAR_3) {

        if (VAR_8 && !VAR_9) {

            av_log(VAR_0, AV_LOG_ERROR, "Could not set %s options\n", VAR_7);

            return AVERROR(EIO);

        }

        if (!device_pin) {

            av_log(VAR_0, AV_LOG_ERROR,

                "Could not find output pin from %s capture device.\n", VAR_7);

            return AVERROR(EIO);

        }

        *VAR_3 = device_pin;

    }



    return 0;

}

FUNC_0(AVFormatContext *VAR_0, enum dshowDeviceType VAR_1,
IBaseFilter *VAR_2, IPin **VAR_3)
{ struct dshow_ctx *VAR_4 = VAR_0->priv_data; IEnumPins *pins = 0; IPin *device_pin = NULL; IPin *pin; int VAR_5; const GUID *VAR_6[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio }; const char *VAR_7 = (VAR_1 == VideoDevice) ? "video" : "audio"; int VAR_8 = (VAR_1 == VideoDevice && (VAR_4->video_size || VAR_4->framerate))
|| (VAR_1 == AudioDevice && (VAR_4->channels || VAR_4->sample_rate)); int VAR_9 = 0; VAR_5 = IBaseFilter_EnumPins(VAR_2, &pins); if (VAR_5 != S_OK) { av_log(VAR_0, AV_LOG_ERROR, "Could not enumerate pins.\n"); return AVERROR(EIO); } if (!VAR_3) { av_log(VAR_0, AV_LOG_INFO, "DirectShow %s device options\n",
VAR_7); } while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK && !device_pin) { IKsPropertySet *p = NULL; IEnumMediaTypes *types = NULL; PIN_INFO info = {0}; AM_MEDIA_TYPE *type; GUID category; DWORD r2; IPin_QueryPinInfo(pin, &info); IBaseFilter_Release(info.pFilter); if (info.dir != PINDIR_OUTPUT)
goto next; if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **) &p) != S_OK)
goto next; if (IKsPropertySet_Get(p, &AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,
NULL, 0, &category, sizeof(GUID), &r2) != S_OK)
goto next; if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))
goto next; if (!VAR_3) { char *VAR_10 = dup_wchar_to_utf8(info.achName); av_log(VAR_0, AV_LOG_INFO, " Pin \"%s\"\n", VAR_10); av_free(VAR_10); dshow_cycle_formats(VAR_0, VAR_1, pin, NULL); goto next; } if (VAR_8) { dshow_cycle_formats(VAR_0, VAR_1, pin, &VAR_9); if (!VAR_9) { goto next; } } if (IPin_EnumMediaTypes(pin, &types) != S_OK)
goto next; IEnumMediaTypes_Reset(types); while (IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK && !device_pin) { if (IsEqualGUID(&type->majortype, VAR_6[VAR_1])) { device_pin = pin; goto next; } CoTaskMemFree(type); } next:
if (types)
IEnumMediaTypes_Release(types); if (p)
IKsPropertySet_Release(p); if (device_pin != pin)
IPin_Release(pin); } IEnumPins_Release(pins); if (VAR_3) { if (VAR_8 && !VAR_9) { av_log(VAR_0, AV_LOG_ERROR, "Could not set %s options\n", VAR_7); return AVERROR(EIO); } if (!device_pin) { av_log(VAR_0, AV_LOG_ERROR,
"Could not find output pin from %s capture device.\n", VAR_7); return AVERROR(EIO); } *VAR_3 = device_pin; } return 0; }