static int device_try_init(AVFormatContext *ctx,

                           enum AVPixelFormat pix_fmt,

                           int *width,

                           int *height,

                           uint32_t *desired_format,

                           enum AVCodecID *codec_id)

{

    int ret, i;



    *desired_format = avpriv_fmt_ff2v4l(pix_fmt, ctx->video_codec_id);



    if (*desired_format) {

        ret = device_init(ctx, width, height, *desired_format);

        if (ret < 0) {

            *desired_format = 0;

            if (ret != AVERROR(EINVAL))

                return ret;

        }

    }



    if (!*desired_format) {

        for (i = 0; avpriv_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) {

            if (ctx->video_codec_id == AV_CODEC_ID_NONE ||

                avpriv_fmt_conversion_table[i].codec_id == ctx->video_codec_id) {

                av_log(ctx, AV_LOG_DEBUG, "Trying to set codec:%s pix_fmt:%s\n",

                       avcodec_get_name(avpriv_fmt_conversion_table[i].codec_id),

                       (char *)av_x_if_null(av_get_pix_fmt_name(avpriv_fmt_conversion_table[i].ff_fmt), "none"));



                *desired_format = avpriv_fmt_conversion_table[i].v4l2_fmt;

                ret = device_init(ctx, width, height, *desired_format);

                if (ret >= 0)

                    break;

                else if (ret != AVERROR(EINVAL))

                    return ret;

                *desired_format = 0;

            }

        }



        if (*desired_format == 0) {

            av_log(ctx, AV_LOG_ERROR, "Cannot find a proper format for "

                   "codec '%s' (id %d), pixel format '%s' (id %d)\n",

                   avcodec_get_name(ctx->video_codec_id), ctx->video_codec_id,

                   (char *)av_x_if_null(av_get_pix_fmt_name(pix_fmt), "none"), pix_fmt);

            ret = AVERROR(EINVAL);

        }

    }



    *codec_id = avpriv_fmt_v4l2codec(*desired_format);

    av_assert0(*codec_id != AV_CODEC_ID_NONE);

    return ret;

}

static int device_try_init(AVFormatContext *ctx,

                           enum AVPixelFormat pix_fmt,

                           int *width,

                           int *height,

                           uint32_t *desired_format,

                           enum AVCodecID *codec_id)

{

    int ret, i;



    *desired_format = avpriv_fmt_ff2v4l(pix_fmt, ctx->video_codec_id);



    if (*desired_format) {

        ret = device_init(ctx, width, height, *desired_format);

        if (ret < 0) {

            *desired_format = 0;

            if (ret != AVERROR(EINVAL))

                return ret;

        }

    }



    if (!*desired_format) {

        for (i = 0; avpriv_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) {

            if (ctx->video_codec_id == AV_CODEC_ID_NONE ||

                avpriv_fmt_conversion_table[i].codec_id == ctx->video_codec_id) {

                av_log(ctx, AV_LOG_DEBUG, "Trying to set codec:%s pix_fmt:%s\n",

                       avcodec_get_name(avpriv_fmt_conversion_table[i].codec_id),

                       (char *)av_x_if_null(av_get_pix_fmt_name(avpriv_fmt_conversion_table[i].ff_fmt), "none"));



                *desired_format = avpriv_fmt_conversion_table[i].v4l2_fmt;

                ret = device_init(ctx, width, height, *desired_format);

                if (ret >= 0)

                    break;

                else if (ret != AVERROR(EINVAL))

                    return ret;

                *desired_format = 0;

            }

        }



        if (*desired_format == 0) {

            av_log(ctx, AV_LOG_ERROR, "Cannot find a proper format for "

                   "codec '%s' (id %d), pixel format '%s' (id %d)\n",

                   avcodec_get_name(ctx->video_codec_id), ctx->video_codec_id,

                   (char *)av_x_if_null(av_get_pix_fmt_name(pix_fmt), "none"), pix_fmt);

            ret = AVERROR(EINVAL);

        }

    }



    *codec_id = avpriv_fmt_v4l2codec(*desired_format);

    av_assert0(*codec_id != AV_CODEC_ID_NONE);

    return ret;

}

static int FUNC_0(AVFormatContext *VAR_0,

                           enum AVPixelFormat VAR_1,

                           int *VAR_2,

                           int *VAR_3,

                           uint32_t *VAR_4,

                           enum AVCodecID *VAR_5)

{

    int VAR_6, VAR_7;



    *VAR_4 = avpriv_fmt_ff2v4l(VAR_1, VAR_0->video_codec_id);



    if (*VAR_4) {

        VAR_6 = device_init(VAR_0, VAR_2, VAR_3, *VAR_4);

        if (VAR_6 < 0) {

            *VAR_4 = 0;

            if (VAR_6 != AVERROR(EINVAL))

                return VAR_6;

        }

    }



    if (!*VAR_4) {

        for (VAR_7 = 0; avpriv_fmt_conversion_table[VAR_7].VAR_5 != AV_CODEC_ID_NONE; VAR_7++) {

            if (VAR_0->video_codec_id == AV_CODEC_ID_NONE ||

                avpriv_fmt_conversion_table[VAR_7].VAR_5 == VAR_0->video_codec_id) {

                av_log(VAR_0, AV_LOG_DEBUG, "Trying to set codec:%s VAR_1:%s\n",

                       avcodec_get_name(avpriv_fmt_conversion_table[VAR_7].VAR_5),

                       (char *)av_x_if_null(av_get_pix_fmt_name(avpriv_fmt_conversion_table[VAR_7].ff_fmt), "none"));



                *VAR_4 = avpriv_fmt_conversion_table[VAR_7].v4l2_fmt;

                VAR_6 = device_init(VAR_0, VAR_2, VAR_3, *VAR_4);

                if (VAR_6 >= 0)

                    break;

                else if (VAR_6 != AVERROR(EINVAL))

                    return VAR_6;

                *VAR_4 = 0;

            }

        }



        if (*VAR_4 == 0) {

            av_log(VAR_0, AV_LOG_ERROR, "Cannot find a proper format for "

                   "codec '%s' (id %d), pixel format '%s' (id %d)\n",

                   avcodec_get_name(VAR_0->video_codec_id), VAR_0->video_codec_id,

                   (char *)av_x_if_null(av_get_pix_fmt_name(VAR_1), "none"), VAR_1);

            VAR_6 = AVERROR(EINVAL);

        }

    }



    *VAR_5 = avpriv_fmt_v4l2codec(*VAR_4);

    av_assert0(*VAR_5 != AV_CODEC_ID_NONE);

    return VAR_6;

}

static int FUNC_0(AVFormatContext *VAR_0,
enum AVPixelFormat VAR_1,
int *VAR_2,
int *VAR_3,
uint32_t *VAR_4,
enum AVCodecID *VAR_5)
{ int VAR_6, VAR_7; *VAR_4 = avpriv_fmt_ff2v4l(VAR_1, VAR_0->video_codec_id); if (*VAR_4) { VAR_6 = device_init(VAR_0, VAR_2, VAR_3, *VAR_4); if (VAR_6 < 0) { *VAR_4 = 0; if (VAR_6 != AVERROR(EINVAL))
return VAR_6; } } if (!*VAR_4) { for (VAR_7 = 0; avpriv_fmt_conversion_table[VAR_7].VAR_5 != AV_CODEC_ID_NONE; VAR_7++) { if (VAR_0->video_codec_id == AV_CODEC_ID_NONE ||
avpriv_fmt_conversion_table[VAR_7].VAR_5 == VAR_0->video_codec_id) { av_log(VAR_0, AV_LOG_DEBUG, "Trying to set codec:%s VAR_1:%s\n",
avcodec_get_name(avpriv_fmt_conversion_table[VAR_7].VAR_5),
(char *)av_x_if_null(av_get_pix_fmt_name(avpriv_fmt_conversion_table[VAR_7].ff_fmt), "none")); *VAR_4 = avpriv_fmt_conversion_table[VAR_7].v4l2_fmt; VAR_6 = device_init(VAR_0, VAR_2, VAR_3, *VAR_4); if (VAR_6 >= 0)
break; else if (VAR_6 != AVERROR(EINVAL))
return VAR_6; *VAR_4 = 0; } } if (*VAR_4 == 0) { av_log(VAR_0, AV_LOG_ERROR, "Cannot find a proper format for "
"codec '%s' (id %d), pixel format '%s' (id %d)\n",
avcodec_get_name(VAR_0->video_codec_id), VAR_0->video_codec_id,
(char *)av_x_if_null(av_get_pix_fmt_name(VAR_1), "none"), VAR_1); VAR_6 = AVERROR(EINVAL); } } *VAR_5 = avpriv_fmt_v4l2codec(*VAR_4); av_assert0(*VAR_5 != AV_CODEC_ID_NONE); return VAR_6; }