int av_find_best_stream(AVFormatContext *ic,

                        enum AVMediaType type,

                        int wanted_stream_nb,

                        int related_stream,

                        AVCodec **decoder_ret,

                        int flags)

{

    int i, nb_streams = ic->nb_streams, stream_number = 0;

    int ret = AVERROR_STREAM_NOT_FOUND, best_count = -1;

    unsigned *program = NULL;

    AVCodec *decoder = NULL, *best_decoder = NULL;



    if (related_stream >= 0 && wanted_stream_nb < 0) {

        AVProgram *p = find_program_from_stream(ic, related_stream);

        if (p) {

            program = p->stream_index;

            nb_streams = p->nb_stream_indexes;

        }

    }

    for (i = 0; i < nb_streams; i++) {

        AVStream *st = ic->streams[program ? program[i] : i];

        AVCodecContext *avctx = st->codec;

        if (avctx->codec_type != type)

            continue;

        if (wanted_stream_nb >= 0 && stream_number++ != wanted_stream_nb)

            continue;

        if (st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_VISUAL_IMPAIRED))

            continue;

        if (decoder_ret) {

            decoder = avcodec_find_decoder(st->codec->codec_id);

            if (!decoder) {

                if (ret < 0)

                    ret = AVERROR_DECODER_NOT_FOUND;

                continue;

            }

        }

        if (best_count >= st->codec_info_nb_frames)

            continue;

        best_count = st->codec_info_nb_frames;

        ret = program ? program[i] : i;

        best_decoder = decoder;

        if (program && i == nb_streams - 1 && ret < 0) {

            program = NULL;

            nb_streams = ic->nb_streams;

            i = 0; /* no related stream found, try again with everything */

        }

    }

    if (decoder_ret)

        *decoder_ret = best_decoder;

    return ret;

}

int av_find_best_stream(AVFormatContext *ic,

                        enum AVMediaType type,

                        int wanted_stream_nb,

                        int related_stream,

                        AVCodec **decoder_ret,

                        int flags)

{

    int i, nb_streams = ic->nb_streams, stream_number = 0;

    int ret = AVERROR_STREAM_NOT_FOUND, best_count = -1;

    unsigned *program = NULL;

    AVCodec *decoder = NULL, *best_decoder = NULL;



    if (related_stream >= 0 && wanted_stream_nb < 0) {

        AVProgram *p = find_program_from_stream(ic, related_stream);

        if (p) {

            program = p->stream_index;

            nb_streams = p->nb_stream_indexes;

        }

    }

    for (i = 0; i < nb_streams; i++) {

        AVStream *st = ic->streams[program ? program[i] : i];

        AVCodecContext *avctx = st->codec;

        if (avctx->codec_type != type)

            continue;

        if (wanted_stream_nb >= 0 && stream_number++ != wanted_stream_nb)

            continue;

        if (st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_VISUAL_IMPAIRED))

            continue;

        if (decoder_ret) {

            decoder = avcodec_find_decoder(st->codec->codec_id);

            if (!decoder) {

                if (ret < 0)

                    ret = AVERROR_DECODER_NOT_FOUND;

                continue;

            }

        }

        if (best_count >= st->codec_info_nb_frames)

            continue;

        best_count = st->codec_info_nb_frames;

        ret = program ? program[i] : i;

        best_decoder = decoder;

        if (program && i == nb_streams - 1 && ret < 0) {

            program = NULL;

            nb_streams = ic->nb_streams;

            i = 0; 

        }

    }

    if (decoder_ret)

        *decoder_ret = best_decoder;

    return ret;

}

int FUNC_0(AVFormatContext *VAR_0,

                        enum AVMediaType VAR_1,

                        int VAR_2,

                        int VAR_3,

                        AVCodec **VAR_4,

                        int VAR_5)

{

    int VAR_6, VAR_7 = VAR_0->VAR_7, VAR_8 = 0;

    int VAR_9 = AVERROR_STREAM_NOT_FOUND, VAR_10 = -1;

    unsigned *VAR_11 = NULL;

    AVCodec *decoder = NULL, *best_decoder = NULL;



    if (VAR_3 >= 0 && VAR_2 < 0) {

        AVProgram *p = find_program_from_stream(VAR_0, VAR_3);

        if (p) {

            VAR_11 = p->stream_index;

            VAR_7 = p->nb_stream_indexes;

        }

    }

    for (VAR_6 = 0; VAR_6 < VAR_7; VAR_6++) {

        AVStream *st = VAR_0->streams[VAR_11 ? VAR_11[VAR_6] : VAR_6];

        AVCodecContext *avctx = st->codec;

        if (avctx->codec_type != VAR_1)

            continue;

        if (VAR_2 >= 0 && VAR_8++ != VAR_2)

            continue;

        if (st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_VISUAL_IMPAIRED))

            continue;

        if (VAR_4) {

            decoder = avcodec_find_decoder(st->codec->codec_id);

            if (!decoder) {

                if (VAR_9 < 0)

                    VAR_9 = AVERROR_DECODER_NOT_FOUND;

                continue;

            }

        }

        if (VAR_10 >= st->codec_info_nb_frames)

            continue;

        VAR_10 = st->codec_info_nb_frames;

        VAR_9 = VAR_11 ? VAR_11[VAR_6] : VAR_6;

        best_decoder = decoder;

        if (VAR_11 && VAR_6 == VAR_7 - 1 && VAR_9 < 0) {

            VAR_11 = NULL;

            VAR_7 = VAR_0->VAR_7;

            VAR_6 = 0; 

        }

    }

    if (VAR_4)

        *VAR_4 = best_decoder;

    return VAR_9;

}

int FUNC_0(AVFormatContext *VAR_0,
enum AVMediaType VAR_1,
int VAR_2,
int VAR_3,
AVCodec **VAR_4,
int VAR_5)
{ int VAR_6, VAR_7 = VAR_0->VAR_7, VAR_8 = 0; int VAR_9 = AVERROR_STREAM_NOT_FOUND, VAR_10 = -1; unsigned *VAR_11 = NULL; AVCodec *decoder = NULL, *best_decoder = NULL; if (VAR_3 >= 0 && VAR_2 < 0) { AVProgram *p = find_program_from_stream(VAR_0, VAR_3); if (p) { VAR_11 = p->stream_index; VAR_7 = p->nb_stream_indexes; } } for (VAR_6 = 0; VAR_6 < VAR_7; VAR_6++) { AVStream *st = VAR_0->streams[VAR_11 ? VAR_11[VAR_6] : VAR_6]; AVCodecContext *avctx = st->codec; if (avctx->codec_type != VAR_1)
continue; if (VAR_2 >= 0 && VAR_8++ != VAR_2)
continue; if (st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_VISUAL_IMPAIRED))
continue; if (VAR_4) { decoder = avcodec_find_decoder(st->codec->codec_id); if (!decoder) { if (VAR_9 < 0)
VAR_9 = AVERROR_DECODER_NOT_FOUND; continue; } } if (VAR_10 >= st->codec_info_nb_frames)
continue; VAR_10 = st->codec_info_nb_frames; VAR_9 = VAR_11 ? VAR_11[VAR_6] : VAR_6; best_decoder = decoder; if (VAR_11 && VAR_6 == VAR_7 - 1 && VAR_9 < 0) { VAR_11 = NULL; VAR_7 = VAR_0->VAR_7; VAR_6 = 0; } } if (VAR_4)
*VAR_4 = best_decoder; return VAR_9; }