dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,

                    enum dshowDeviceType devtype, IBaseFilter **pfilter)

{

    struct dshow_ctx *ctx = avctx->priv_data;

    IBaseFilter *device_filter = NULL;

    IEnumMoniker *classenum = NULL;

    IMoniker *m = NULL;

    const char *device_name = ctx->device_name[devtype];

    int skip = (devtype == VideoDevice) ? ctx->video_device_number

                                        : ctx->audio_device_number;

    int r;



    const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,

                                   &CLSID_AudioInputDeviceCategory };

    const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";



    r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[devtype],

                                             (IEnumMoniker **) &classenum, 0);

    if (r != S_OK) {

        av_log(avctx, AV_LOG_ERROR, "Could not enumerate %s devices.\n",

               devtypename);

        return AVERROR(EIO);

    }



    while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) {

        IPropertyBag *bag = NULL;

        char *buf = NULL;

        VARIANT var;



        r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag);

        if (r != S_OK)

            goto fail1;



        var.vt = VT_BSTR;

        r = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);

        if (r != S_OK)

            goto fail1;



        buf = dup_wchar_to_utf8(var.bstrVal);



        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:

        if (buf)

            av_free(buf);

        if (bag)

            IPropertyBag_Release(bag);

        IMoniker_Release(m);

    }



    IEnumMoniker_Release(classenum);



    if (pfilter) {

        if (!device_filter) {

            av_log(avctx, AV_LOG_ERROR, "Could not find %s device.\n",

                   devtypename);

            return AVERROR(EIO);

        }

        *pfilter = device_filter;

    }



    return 0;

}

dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,

                    enum dshowDeviceType devtype, IBaseFilter **pfilter)

{

    struct dshow_ctx *ctx = avctx->priv_data;

    IBaseFilter *device_filter = NULL;

    IEnumMoniker *classenum = NULL;

    IMoniker *m = NULL;

    const char *device_name = ctx->device_name[devtype];

    int skip = (devtype == VideoDevice) ? ctx->video_device_number

                                        : ctx->audio_device_number;

    int r;



    const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,

                                   &CLSID_AudioInputDeviceCategory };

    const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";



    r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[devtype],

                                             (IEnumMoniker **) &classenum, 0);

    if (r != S_OK) {

        av_log(avctx, AV_LOG_ERROR, "Could not enumerate %s devices.\n",

               devtypename);

        return AVERROR(EIO);

    }



    while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) {

        IPropertyBag *bag = NULL;

        char *buf = NULL;

        VARIANT var;



        r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag);

        if (r != S_OK)

            goto fail1;



        var.vt = VT_BSTR;

        r = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);

        if (r != S_OK)

            goto fail1;



        buf = dup_wchar_to_utf8(var.bstrVal);



        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:

        if (buf)

            av_free(buf);

        if (bag)

            IPropertyBag_Release(bag);

        IMoniker_Release(m);

    }



    IEnumMoniker_Release(classenum);



    if (pfilter) {

        if (!device_filter) {

            av_log(avctx, AV_LOG_ERROR, "Could not find %s device.\n",

                   devtypename);

            return AVERROR(EIO);

        }

        *pfilter = device_filter;

    }



    return 0;

}

FUNC_0(AVFormatContext *VAR_0, ICreateDevEnum *VAR_1,

                    enum dshowDeviceType VAR_2, IBaseFilter **VAR_3)

{

    struct dshow_ctx *VAR_4 = VAR_0->priv_data;

    IBaseFilter *device_filter = NULL;

    IEnumMoniker *classenum = NULL;

    IMoniker *m = NULL;

    const char *VAR_5 = VAR_4->VAR_5[VAR_2];

    int VAR_6 = (VAR_2 == VideoDevice) ? VAR_4->video_device_number

                                        : VAR_4->audio_device_number;

    int VAR_7;



    const GUID *VAR_8[2] = { &CLSID_VideoInputDeviceCategory,

                                   &CLSID_AudioInputDeviceCategory };

    const char *VAR_9 = (VAR_2 == VideoDevice) ? "video" : "audio";



    VAR_7 = ICreateDevEnum_CreateClassEnumerator(VAR_1, VAR_8[VAR_2],

                                             (IEnumMoniker **) &classenum, 0);

    if (VAR_7 != S_OK) {

        av_log(VAR_0, AV_LOG_ERROR, "Could not enumerate %s devices.\n",

               VAR_9);

        return AVERROR(EIO);

    }



    while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) {

        IPropertyBag *bag = NULL;

        char *VAR_10 = NULL;

        VARIANT var;



        VAR_7 = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag);

        if (VAR_7 != S_OK)

            goto fail1;



        var.vt = VT_BSTR;

        VAR_7 = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);

        if (VAR_7 != S_OK)

            goto fail1;



        VAR_10 = dup_wchar_to_utf8(var.bstrVal);



        if (VAR_3) {

            if (strcmp(VAR_5, VAR_10))

                goto fail1;



            if (!VAR_6--)

                IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter);

        } else {

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

        }



fail1:

        if (VAR_10)

            av_free(VAR_10);

        if (bag)

            IPropertyBag_Release(bag);

        IMoniker_Release(m);

    }



    IEnumMoniker_Release(classenum);



    if (VAR_3) {

        if (!device_filter) {

            av_log(VAR_0, AV_LOG_ERROR, "Could not find %s device.\n",

                   VAR_9);

            return AVERROR(EIO);

        }

        *VAR_3 = device_filter;

    }



    return 0;

}

FUNC_0(AVFormatContext *VAR_0, ICreateDevEnum *VAR_1,
enum dshowDeviceType VAR_2, IBaseFilter **VAR_3)
{ struct dshow_ctx *VAR_4 = VAR_0->priv_data; IBaseFilter *device_filter = NULL; IEnumMoniker *classenum = NULL; IMoniker *m = NULL; const char *VAR_5 = VAR_4->VAR_5[VAR_2]; int VAR_6 = (VAR_2 == VideoDevice) ? VAR_4->video_device_number
: VAR_4->audio_device_number; int VAR_7; const GUID *VAR_8[2] = { &CLSID_VideoInputDeviceCategory, &CLSID_AudioInputDeviceCategory }; const char *VAR_9 = (VAR_2 == VideoDevice) ? "video" : "audio"; VAR_7 = ICreateDevEnum_CreateClassEnumerator(VAR_1, VAR_8[VAR_2],
(IEnumMoniker **) &classenum, 0); if (VAR_7 != S_OK) { av_log(VAR_0, AV_LOG_ERROR, "Could not enumerate %s devices.\n",
VAR_9); return AVERROR(EIO); } while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) { IPropertyBag *bag = NULL; char *VAR_10 = NULL; VARIANT var; VAR_7 = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag); if (VAR_7 != S_OK)
goto fail1; var.vt = VT_BSTR; VAR_7 = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL); if (VAR_7 != S_OK)
goto fail1; VAR_10 = dup_wchar_to_utf8(var.bstrVal); if (VAR_3) { if (strcmp(VAR_5, VAR_10))
goto fail1; if (!VAR_6--)
IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter); } else { av_log(VAR_0, AV_LOG_INFO, " \"%s\"\n", VAR_10); } fail1:
if (VAR_10)
av_free(VAR_10); if (bag)
IPropertyBag_Release(bag); IMoniker_Release(m); } IEnumMoniker_Release(classenum); if (VAR_3) { if (!device_filter) { av_log(VAR_0, AV_LOG_ERROR, "Could not find %s device.\n",
VAR_9); return AVERROR(EIO); } *VAR_3 = device_filter; } return 0; }