static int select_reference_stream(AVFormatContext *s)

{

    SegmentContext *seg = s->priv_data;

    int ret, i;



    seg->reference_stream_index = -1;

    if (!strcmp(seg->reference_stream_specifier, "auto")) {

        /* select first index of type with highest priority */

        int type_index_map[AVMEDIA_TYPE_NB];

        static const enum AVMediaType type_priority_list[] = {

            AVMEDIA_TYPE_VIDEO,

            AVMEDIA_TYPE_AUDIO,

            AVMEDIA_TYPE_SUBTITLE,

            AVMEDIA_TYPE_DATA,

            AVMEDIA_TYPE_ATTACHMENT

        };

        enum AVMediaType type;



        for (i = 0; i < AVMEDIA_TYPE_NB; i++)

            type_index_map[i] = -1;



        /* select first index for each type */

        for (i = 0; i < s->nb_streams; i++) {

            type = s->streams[i]->codec->codec_type;

            if ((unsigned)type < AVMEDIA_TYPE_NB && type_index_map[type] == -1

                /* ignore attached pictures/cover art streams */

                && !(s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC))

                type_index_map[type] = i;

        }



        for (i = 0; i < FF_ARRAY_ELEMS(type_priority_list); i++) {

            type = type_priority_list[i];

            if ((seg->reference_stream_index = type_index_map[type]) >= 0)

                break;

        }

    } else {

        for (i = 0; i < s->nb_streams; i++) {

            ret = avformat_match_stream_specifier(s, s->streams[i],

                                                  seg->reference_stream_specifier);

            if (ret < 0)

                break;

            if (ret > 0) {

                seg->reference_stream_index = i;

                break;

            }

        }

    }



    if (seg->reference_stream_index < 0) {

        av_log(s, AV_LOG_ERROR, "Could not select stream matching identifier '%s'\n",

               seg->reference_stream_specifier);

        return AVERROR(EINVAL);

    }



    return 0;

}

static int select_reference_stream(AVFormatContext *s)

{

    SegmentContext *seg = s->priv_data;

    int ret, i;



    seg->reference_stream_index = -1;

    if (!strcmp(seg->reference_stream_specifier, "auto")) {

        

        int type_index_map[AVMEDIA_TYPE_NB];

        static const enum AVMediaType type_priority_list[] = {

            AVMEDIA_TYPE_VIDEO,

            AVMEDIA_TYPE_AUDIO,

            AVMEDIA_TYPE_SUBTITLE,

            AVMEDIA_TYPE_DATA,

            AVMEDIA_TYPE_ATTACHMENT

        };

        enum AVMediaType type;



        for (i = 0; i < AVMEDIA_TYPE_NB; i++)

            type_index_map[i] = -1;



        

        for (i = 0; i < s->nb_streams; i++) {

            type = s->streams[i]->codec->codec_type;

            if ((unsigned)type < AVMEDIA_TYPE_NB && type_index_map[type] == -1

                

                && !(s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC))

                type_index_map[type] = i;

        }



        for (i = 0; i < FF_ARRAY_ELEMS(type_priority_list); i++) {

            type = type_priority_list[i];

            if ((seg->reference_stream_index = type_index_map[type]) >= 0)

                break;

        }

    } else {

        for (i = 0; i < s->nb_streams; i++) {

            ret = avformat_match_stream_specifier(s, s->streams[i],

                                                  seg->reference_stream_specifier);

            if (ret < 0)

                break;

            if (ret > 0) {

                seg->reference_stream_index = i;

                break;

            }

        }

    }



    if (seg->reference_stream_index < 0) {

        av_log(s, AV_LOG_ERROR, "Could not select stream matching identifier '%s'\n",

               seg->reference_stream_specifier);

        return AVERROR(EINVAL);

    }



    return 0;

}

                break;
static int FUNC_0(AVFormatContext *VAR_0)

{

    SegmentContext *seg = VAR_0->priv_data;

    int VAR_1, VAR_2;



    seg->reference_stream_index = -1;

    if (!strcmp(seg->reference_stream_specifier, "auto")) {

        

        int VAR_3[AVMEDIA_TYPE_NB];

        static const enum AVMediaType VAR_4[] = {

            AVMEDIA_TYPE_VIDEO,

            AVMEDIA_TYPE_AUDIO,

            AVMEDIA_TYPE_SUBTITLE,

            AVMEDIA_TYPE_DATA,

            AVMEDIA_TYPE_ATTACHMENT

        };

        enum AVMediaType VAR_5;



        for (VAR_2 = 0; VAR_2 < AVMEDIA_TYPE_NB; VAR_2++)

            VAR_3[VAR_2] = -1;



        

        for (VAR_2 = 0; VAR_2 < VAR_0->nb_streams; VAR_2++) {

            VAR_5 = VAR_0->streams[VAR_2]->codec->codec_type;

            if ((unsigned)VAR_5 < AVMEDIA_TYPE_NB && VAR_3[VAR_5] == -1

                

                && !(VAR_0->streams[VAR_2]->disposition & AV_DISPOSITION_ATTACHED_PIC))

                VAR_3[VAR_5] = VAR_2;

        }



        for (VAR_2 = 0; VAR_2 < FF_ARRAY_ELEMS(VAR_4); VAR_2++) {

            VAR_5 = VAR_4[VAR_2];

            if ((seg->reference_stream_index = VAR_3[VAR_5]) >= 0)

                break;

        }

    } else {

        for (VAR_2 = 0; VAR_2 < VAR_0->nb_streams; VAR_2++) {

            VAR_1 = avformat_match_stream_specifier(VAR_0, VAR_0->streams[VAR_2],

                                                  seg->reference_stream_specifier);

            if (VAR_1 < 0)

                break;

            if (VAR_1 > 0) {

                seg->reference_stream_index = VAR_2;

                break;

            }

        }

    }



    if (seg->reference_stream_index < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Could not select stream matching identifier '%VAR_0'\n",

               seg->reference_stream_specifier);

        return AVERROR(EINVAL);

    }



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0)
{ SegmentContext *seg = VAR_0->priv_data; int VAR_1, VAR_2; seg->reference_stream_index = -1; if (!strcmp(seg->reference_stream_specifier, "auto")) { int VAR_3[AVMEDIA_TYPE_NB]; static const enum AVMediaType VAR_4[] = { AVMEDIA_TYPE_VIDEO,
AVMEDIA_TYPE_AUDIO,
AVMEDIA_TYPE_SUBTITLE,
AVMEDIA_TYPE_DATA,
AVMEDIA_TYPE_ATTACHMENT
}; enum AVMediaType VAR_5; for (VAR_2 = 0; VAR_2 < AVMEDIA_TYPE_NB; VAR_2++) VAR_3[VAR_2] = -1; for (VAR_2 = 0; VAR_2 < VAR_0->nb_streams; VAR_2++) { VAR_5 = VAR_0->streams[VAR_2]->codec->codec_type; if ((unsigned)VAR_5 < AVMEDIA_TYPE_NB && VAR_3[VAR_5] == -1
&& !(VAR_0->streams[VAR_2]->disposition & AV_DISPOSITION_ATTACHED_PIC))
VAR_3[VAR_5] = VAR_2; } for (VAR_2 = 0; VAR_2 < FF_ARRAY_ELEMS(VAR_4); VAR_2++) { VAR_5 = VAR_4[VAR_2]; if ((seg->reference_stream_index = VAR_3[VAR_5]) >= 0)
break; } } else { for (VAR_2 = 0; VAR_2 < VAR_0->nb_streams; VAR_2++) { VAR_1 = avformat_match_stream_specifier(VAR_0, VAR_0->streams[VAR_2],
seg->reference_stream_specifier); if (VAR_1 < 0)
break; if (VAR_1 > 0) { seg->reference_stream_index = VAR_2; break; } } } if (seg->reference_stream_index < 0) { av_log(VAR_0, AV_LOG_ERROR, "Could not select stream matching identifier '%VAR_0'\n",
seg->reference_stream_specifier); return AVERROR(EINVAL); } return 0; }