static int audio_decode_frame(VideoState *is)

{

    int data_size, resampled_data_size;

    int64_t dec_channel_layout;

    int got_frame = 0;

    av_unused double audio_clock0;

    int wanted_nb_samples;

    AVRational tb;

    int ret;

    int reconfigure;



    if (!is->frame)

        if (!(is->frame = av_frame_alloc()))

            return AVERROR(ENOMEM);



    for (;;) {

        if (is->audioq.serial != is->auddec.pkt_serial)

            is->audio_buf_frames_pending = got_frame = 0;



        if (!got_frame)

            av_frame_unref(is->frame);



        if (is->paused)

            return -1;



        while (is->audio_buf_frames_pending || got_frame) {

            if (!is->audio_buf_frames_pending) {

                got_frame = 0;

                tb = (AVRational){1, is->frame->sample_rate};



#if CONFIG_AVFILTER

                dec_channel_layout = get_valid_channel_layout(is->frame->channel_layout, av_frame_get_channels(is->frame));



                reconfigure =

                    cmp_audio_fmts(is->audio_filter_src.fmt, is->audio_filter_src.channels,

                                   is->frame->format, av_frame_get_channels(is->frame))    ||

                    is->audio_filter_src.channel_layout != dec_channel_layout ||

                    is->audio_filter_src.freq           != is->frame->sample_rate ||

                    is->auddec.pkt_serial               != is->audio_last_serial;



                if (reconfigure) {

                    char buf1[1024], buf2[1024];

                    av_get_channel_layout_string(buf1, sizeof(buf1), -1, is->audio_filter_src.channel_layout);

                    av_get_channel_layout_string(buf2, sizeof(buf2), -1, dec_channel_layout);

                    av_log(NULL, AV_LOG_DEBUG,

                           "Audio frame changed from rate:%d ch:%d fmt:%s layout:%s serial:%d to rate:%d ch:%d fmt:%s layout:%s serial:%d\n",

                           is->audio_filter_src.freq, is->audio_filter_src.channels, av_get_sample_fmt_name(is->audio_filter_src.fmt), buf1, is->audio_last_serial,

                           is->frame->sample_rate, av_frame_get_channels(is->frame), av_get_sample_fmt_name(is->frame->format), buf2, is->auddec.pkt_serial);



                    is->audio_filter_src.fmt            = is->frame->format;

                    is->audio_filter_src.channels       = av_frame_get_channels(is->frame);

                    is->audio_filter_src.channel_layout = dec_channel_layout;

                    is->audio_filter_src.freq           = is->frame->sample_rate;

                    is->audio_last_serial               = is->auddec.pkt_serial;



                    if ((ret = configure_audio_filters(is, afilters, 1)) < 0)

                        return ret;

                }



                if ((ret = av_buffersrc_add_frame(is->in_audio_filter, is->frame)) < 0)

                    return ret;

#endif

            }

#if CONFIG_AVFILTER

            if ((ret = av_buffersink_get_frame_flags(is->out_audio_filter, is->frame, 0)) < 0) {

                if (ret == AVERROR(EAGAIN)) {

                    is->audio_buf_frames_pending = 0;

                    continue;

                }

                if (ret == AVERROR_EOF)

                    is->auddec.finished = is->auddec.pkt_serial;

                return ret;

            }

            is->audio_buf_frames_pending = 1;

            tb = is->out_audio_filter->inputs[0]->time_base;

#endif



            data_size = av_samples_get_buffer_size(NULL, av_frame_get_channels(is->frame),

                                                   is->frame->nb_samples,

                                                   is->frame->format, 1);



            dec_channel_layout =

                (is->frame->channel_layout && av_frame_get_channels(is->frame) == av_get_channel_layout_nb_channels(is->frame->channel_layout)) ?

                is->frame->channel_layout : av_get_default_channel_layout(av_frame_get_channels(is->frame));

            wanted_nb_samples = synchronize_audio(is, is->frame->nb_samples);



            if (is->frame->format        != is->audio_src.fmt            ||

                dec_channel_layout       != is->audio_src.channel_layout ||

                is->frame->sample_rate   != is->audio_src.freq           ||

                (wanted_nb_samples       != is->frame->nb_samples && !is->swr_ctx)) {

                swr_free(&is->swr_ctx);

                is->swr_ctx = swr_alloc_set_opts(NULL,

                                                 is->audio_tgt.channel_layout, is->audio_tgt.fmt, is->audio_tgt.freq,

                                                 dec_channel_layout,           is->frame->format, is->frame->sample_rate,

                                                 0, NULL);

                if (!is->swr_ctx || swr_init(is->swr_ctx) < 0) {

                    av_log(NULL, AV_LOG_ERROR,

                           "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n",

                            is->frame->sample_rate, av_get_sample_fmt_name(is->frame->format), av_frame_get_channels(is->frame),

                            is->audio_tgt.freq, av_get_sample_fmt_name(is->audio_tgt.fmt), is->audio_tgt.channels);

                    break;

                }

                is->audio_src.channel_layout = dec_channel_layout;

                is->audio_src.channels       = av_frame_get_channels(is->frame);

                is->audio_src.freq = is->frame->sample_rate;

                is->audio_src.fmt = is->frame->format;

            }



            if (is->swr_ctx) {

                const uint8_t **in = (const uint8_t **)is->frame->extended_data;

                uint8_t **out = &is->audio_buf1;

                int out_count = (int64_t)wanted_nb_samples * is->audio_tgt.freq / is->frame->sample_rate + 256;

                int out_size  = av_samples_get_buffer_size(NULL, is->audio_tgt.channels, out_count, is->audio_tgt.fmt, 0);

                int len2;

                if (out_size < 0) {

                    av_log(NULL, AV_LOG_ERROR, "av_samples_get_buffer_size() failed\n");

                    break;

                }

                if (wanted_nb_samples != is->frame->nb_samples) {

                    if (swr_set_compensation(is->swr_ctx, (wanted_nb_samples - is->frame->nb_samples) * is->audio_tgt.freq / is->frame->sample_rate,

                                                wanted_nb_samples * is->audio_tgt.freq / is->frame->sample_rate) < 0) {

                        av_log(NULL, AV_LOG_ERROR, "swr_set_compensation() failed\n");

                        break;

                    }

                }

                av_fast_malloc(&is->audio_buf1, &is->audio_buf1_size, out_size);

                if (!is->audio_buf1)

                    return AVERROR(ENOMEM);

                len2 = swr_convert(is->swr_ctx, out, out_count, in, is->frame->nb_samples);

                if (len2 < 0) {

                    av_log(NULL, AV_LOG_ERROR, "swr_convert() failed\n");

                    break;

                }

                if (len2 == out_count) {

                    av_log(NULL, AV_LOG_WARNING, "audio buffer is probably too small\n");

                    swr_init(is->swr_ctx);

                }

                is->audio_buf = is->audio_buf1;

                resampled_data_size = len2 * is->audio_tgt.channels * av_get_bytes_per_sample(is->audio_tgt.fmt);

            } else {

                is->audio_buf = is->frame->data[0];

                resampled_data_size = data_size;

            }



            audio_clock0 = is->audio_clock;

            /* update the audio clock with the pts */

            if (is->frame->pts != AV_NOPTS_VALUE)

                is->audio_clock = is->frame->pts * av_q2d(tb) + (double) is->frame->nb_samples / is->frame->sample_rate;

            else

                is->audio_clock = NAN;

            is->audio_clock_serial = is->auddec.pkt_serial;

#ifdef DEBUG

            {

                static double last_clock;

                printf("audio: delay=%0.3f clock=%0.3f clock0=%0.3f\n",

                       is->audio_clock - last_clock,

                       is->audio_clock, audio_clock0);

                last_clock = is->audio_clock;

            }

#endif

            return resampled_data_size;

        }



        if ((got_frame = decoder_decode_frame(&is->auddec, is->frame, NULL)) < 0)

            return -1;



        if (is->auddec.flushed)

            is->audio_buf_frames_pending = 0;

    }

}

static int audio_decode_frame(VideoState *is)

{

    int data_size, resampled_data_size;

    int64_t dec_channel_layout;

    int got_frame = 0;

    av_unused double audio_clock0;

    int wanted_nb_samples;

    AVRational tb;

    int ret;

    int reconfigure;



    if (!is->frame)

        if (!(is->frame = av_frame_alloc()))

            return AVERROR(ENOMEM);



    for (;;) {

        if (is->audioq.serial != is->auddec.pkt_serial)

            is->audio_buf_frames_pending = got_frame = 0;



        if (!got_frame)

            av_frame_unref(is->frame);



        if (is->paused)

            return -1;



        while (is->audio_buf_frames_pending || got_frame) {

            if (!is->audio_buf_frames_pending) {

                got_frame = 0;

                tb = (AVRational){1, is->frame->sample_rate};



#if CONFIG_AVFILTER

                dec_channel_layout = get_valid_channel_layout(is->frame->channel_layout, av_frame_get_channels(is->frame));



                reconfigure =

                    cmp_audio_fmts(is->audio_filter_src.fmt, is->audio_filter_src.channels,

                                   is->frame->format, av_frame_get_channels(is->frame))    ||

                    is->audio_filter_src.channel_layout != dec_channel_layout ||

                    is->audio_filter_src.freq           != is->frame->sample_rate ||

                    is->auddec.pkt_serial               != is->audio_last_serial;



                if (reconfigure) {

                    char buf1[1024], buf2[1024];

                    av_get_channel_layout_string(buf1, sizeof(buf1), -1, is->audio_filter_src.channel_layout);

                    av_get_channel_layout_string(buf2, sizeof(buf2), -1, dec_channel_layout);

                    av_log(NULL, AV_LOG_DEBUG,

                           "Audio frame changed from rate:%d ch:%d fmt:%s layout:%s serial:%d to rate:%d ch:%d fmt:%s layout:%s serial:%d\n",

                           is->audio_filter_src.freq, is->audio_filter_src.channels, av_get_sample_fmt_name(is->audio_filter_src.fmt), buf1, is->audio_last_serial,

                           is->frame->sample_rate, av_frame_get_channels(is->frame), av_get_sample_fmt_name(is->frame->format), buf2, is->auddec.pkt_serial);



                    is->audio_filter_src.fmt            = is->frame->format;

                    is->audio_filter_src.channels       = av_frame_get_channels(is->frame);

                    is->audio_filter_src.channel_layout = dec_channel_layout;

                    is->audio_filter_src.freq           = is->frame->sample_rate;

                    is->audio_last_serial               = is->auddec.pkt_serial;



                    if ((ret = configure_audio_filters(is, afilters, 1)) < 0)

                        return ret;

                }



                if ((ret = av_buffersrc_add_frame(is->in_audio_filter, is->frame)) < 0)

                    return ret;

#endif

            }

#if CONFIG_AVFILTER

            if ((ret = av_buffersink_get_frame_flags(is->out_audio_filter, is->frame, 0)) < 0) {

                if (ret == AVERROR(EAGAIN)) {

                    is->audio_buf_frames_pending = 0;

                    continue;

                }

                if (ret == AVERROR_EOF)

                    is->auddec.finished = is->auddec.pkt_serial;

                return ret;

            }

            is->audio_buf_frames_pending = 1;

            tb = is->out_audio_filter->inputs[0]->time_base;

#endif



            data_size = av_samples_get_buffer_size(NULL, av_frame_get_channels(is->frame),

                                                   is->frame->nb_samples,

                                                   is->frame->format, 1);



            dec_channel_layout =

                (is->frame->channel_layout && av_frame_get_channels(is->frame) == av_get_channel_layout_nb_channels(is->frame->channel_layout)) ?

                is->frame->channel_layout : av_get_default_channel_layout(av_frame_get_channels(is->frame));

            wanted_nb_samples = synchronize_audio(is, is->frame->nb_samples);



            if (is->frame->format        != is->audio_src.fmt            ||

                dec_channel_layout       != is->audio_src.channel_layout ||

                is->frame->sample_rate   != is->audio_src.freq           ||

                (wanted_nb_samples       != is->frame->nb_samples && !is->swr_ctx)) {

                swr_free(&is->swr_ctx);

                is->swr_ctx = swr_alloc_set_opts(NULL,

                                                 is->audio_tgt.channel_layout, is->audio_tgt.fmt, is->audio_tgt.freq,

                                                 dec_channel_layout,           is->frame->format, is->frame->sample_rate,

                                                 0, NULL);

                if (!is->swr_ctx || swr_init(is->swr_ctx) < 0) {

                    av_log(NULL, AV_LOG_ERROR,

                           "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n",

                            is->frame->sample_rate, av_get_sample_fmt_name(is->frame->format), av_frame_get_channels(is->frame),

                            is->audio_tgt.freq, av_get_sample_fmt_name(is->audio_tgt.fmt), is->audio_tgt.channels);

                    break;

                }

                is->audio_src.channel_layout = dec_channel_layout;

                is->audio_src.channels       = av_frame_get_channels(is->frame);

                is->audio_src.freq = is->frame->sample_rate;

                is->audio_src.fmt = is->frame->format;

            }



            if (is->swr_ctx) {

                const uint8_t **in = (const uint8_t **)is->frame->extended_data;

                uint8_t **out = &is->audio_buf1;

                int out_count = (int64_t)wanted_nb_samples * is->audio_tgt.freq / is->frame->sample_rate + 256;

                int out_size  = av_samples_get_buffer_size(NULL, is->audio_tgt.channels, out_count, is->audio_tgt.fmt, 0);

                int len2;

                if (out_size < 0) {

                    av_log(NULL, AV_LOG_ERROR, "av_samples_get_buffer_size() failed\n");

                    break;

                }

                if (wanted_nb_samples != is->frame->nb_samples) {

                    if (swr_set_compensation(is->swr_ctx, (wanted_nb_samples - is->frame->nb_samples) * is->audio_tgt.freq / is->frame->sample_rate,

                                                wanted_nb_samples * is->audio_tgt.freq / is->frame->sample_rate) < 0) {

                        av_log(NULL, AV_LOG_ERROR, "swr_set_compensation() failed\n");

                        break;

                    }

                }

                av_fast_malloc(&is->audio_buf1, &is->audio_buf1_size, out_size);

                if (!is->audio_buf1)

                    return AVERROR(ENOMEM);

                len2 = swr_convert(is->swr_ctx, out, out_count, in, is->frame->nb_samples);

                if (len2 < 0) {

                    av_log(NULL, AV_LOG_ERROR, "swr_convert() failed\n");

                    break;

                }

                if (len2 == out_count) {

                    av_log(NULL, AV_LOG_WARNING, "audio buffer is probably too small\n");

                    swr_init(is->swr_ctx);

                }

                is->audio_buf = is->audio_buf1;

                resampled_data_size = len2 * is->audio_tgt.channels * av_get_bytes_per_sample(is->audio_tgt.fmt);

            } else {

                is->audio_buf = is->frame->data[0];

                resampled_data_size = data_size;

            }



            audio_clock0 = is->audio_clock;

            

            if (is->frame->pts != AV_NOPTS_VALUE)

                is->audio_clock = is->frame->pts * av_q2d(tb) + (double) is->frame->nb_samples / is->frame->sample_rate;

            else

                is->audio_clock = NAN;

            is->audio_clock_serial = is->auddec.pkt_serial;

#ifdef DEBUG

            {

                static double last_clock;

                printf("audio: delay=%0.3f clock=%0.3f clock0=%0.3f\n",

                       is->audio_clock - last_clock,

                       is->audio_clock, audio_clock0);

                last_clock = is->audio_clock;

            }

#endif

            return resampled_data_size;

        }



        if ((got_frame = decoder_decode_frame(&is->auddec, is->frame, NULL)) < 0)

            return -1;



        if (is->auddec.flushed)

            is->audio_buf_frames_pending = 0;

    }

}

                    swr_init(is->swr_ctx);
static int FUNC_0(VideoState *VAR_0)

{

    int VAR_1, VAR_2;

    int64_t dec_channel_layout;

    int VAR_3 = 0;

    av_unused double audio_clock0;

    int VAR_4;

    AVRational tb;

    int VAR_5;

    int VAR_6;



    if (!VAR_0->frame)

        if (!(VAR_0->frame = av_frame_alloc()))

            return AVERROR(ENOMEM);



    for (;;) {

        if (VAR_0->audioq.serial != VAR_0->auddec.pkt_serial)

            VAR_0->audio_buf_frames_pending = VAR_3 = 0;



        if (!VAR_3)

            av_frame_unref(VAR_0->frame);



        if (VAR_0->paused)

            return -1;



        while (VAR_0->audio_buf_frames_pending || VAR_3) {

            if (!VAR_0->audio_buf_frames_pending) {

                VAR_3 = 0;

                tb = (AVRational){1, VAR_0->frame->sample_rate};



#if CONFIG_AVFILTER

                dec_channel_layout = get_valid_channel_layout(VAR_0->frame->channel_layout, av_frame_get_channels(VAR_0->frame));



                VAR_6 =

                    cmp_audio_fmts(VAR_0->audio_filter_src.fmt, VAR_0->audio_filter_src.channels,

                                   VAR_0->frame->format, av_frame_get_channels(VAR_0->frame))    ||

                    VAR_0->audio_filter_src.channel_layout != dec_channel_layout ||

                    VAR_0->audio_filter_src.freq           != VAR_0->frame->sample_rate ||

                    VAR_0->auddec.pkt_serial               != VAR_0->audio_last_serial;



                if (VAR_6) {

                    char buf1[1024], buf2[1024];

                    av_get_channel_layout_string(buf1, sizeof(buf1), -1, VAR_0->audio_filter_src.channel_layout);

                    av_get_channel_layout_string(buf2, sizeof(buf2), -1, dec_channel_layout);

                    av_log(NULL, AV_LOG_DEBUG,

                           "Audio frame changed from rate:%d ch:%d fmt:%s layout:%s serial:%d to rate:%d ch:%d fmt:%s layout:%s serial:%d\n",

                           VAR_0->audio_filter_src.freq, VAR_0->audio_filter_src.channels, av_get_sample_fmt_name(VAR_0->audio_filter_src.fmt), buf1, VAR_0->audio_last_serial,

                           VAR_0->frame->sample_rate, av_frame_get_channels(VAR_0->frame), av_get_sample_fmt_name(VAR_0->frame->format), buf2, VAR_0->auddec.pkt_serial);



                    VAR_0->audio_filter_src.fmt            = VAR_0->frame->format;

                    VAR_0->audio_filter_src.channels       = av_frame_get_channels(VAR_0->frame);

                    VAR_0->audio_filter_src.channel_layout = dec_channel_layout;

                    VAR_0->audio_filter_src.freq           = VAR_0->frame->sample_rate;

                    VAR_0->audio_last_serial               = VAR_0->auddec.pkt_serial;



                    if ((VAR_5 = configure_audio_filters(VAR_0, afilters, 1)) < 0)

                        return VAR_5;

                }



                if ((VAR_5 = av_buffersrc_add_frame(VAR_0->in_audio_filter, VAR_0->frame)) < 0)

                    return VAR_5;

#endif

            }

#if CONFIG_AVFILTER

            if ((VAR_5 = av_buffersink_get_frame_flags(VAR_0->out_audio_filter, VAR_0->frame, 0)) < 0) {

                if (VAR_5 == AVERROR(EAGAIN)) {

                    VAR_0->audio_buf_frames_pending = 0;

                    continue;

                }

                if (VAR_5 == AVERROR_EOF)

                    VAR_0->auddec.finished = VAR_0->auddec.pkt_serial;

                return VAR_5;

            }

            VAR_0->audio_buf_frames_pending = 1;

            tb = VAR_0->out_audio_filter->inputs[0]->time_base;

#endif



            VAR_1 = av_samples_get_buffer_size(NULL, av_frame_get_channels(VAR_0->frame),

                                                   VAR_0->frame->nb_samples,

                                                   VAR_0->frame->format, 1);



            dec_channel_layout =

                (VAR_0->frame->channel_layout && av_frame_get_channels(VAR_0->frame) == av_get_channel_layout_nb_channels(VAR_0->frame->channel_layout)) ?

                VAR_0->frame->channel_layout : av_get_default_channel_layout(av_frame_get_channels(VAR_0->frame));

            VAR_4 = synchronize_audio(VAR_0, VAR_0->frame->nb_samples);



            if (VAR_0->frame->format        != VAR_0->audio_src.fmt            ||

                dec_channel_layout       != VAR_0->audio_src.channel_layout ||

                VAR_0->frame->sample_rate   != VAR_0->audio_src.freq           ||

                (VAR_4       != VAR_0->frame->nb_samples && !VAR_0->swr_ctx)) {

                swr_free(&VAR_0->swr_ctx);

                VAR_0->swr_ctx = swr_alloc_set_opts(NULL,

                                                 VAR_0->audio_tgt.channel_layout, VAR_0->audio_tgt.fmt, VAR_0->audio_tgt.freq,

                                                 dec_channel_layout,           VAR_0->frame->format, VAR_0->frame->sample_rate,

                                                 0, NULL);

                if (!VAR_0->swr_ctx || swr_init(VAR_0->swr_ctx) < 0) {

                    av_log(NULL, AV_LOG_ERROR,

                           "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n",

                            VAR_0->frame->sample_rate, av_get_sample_fmt_name(VAR_0->frame->format), av_frame_get_channels(VAR_0->frame),

                            VAR_0->audio_tgt.freq, av_get_sample_fmt_name(VAR_0->audio_tgt.fmt), VAR_0->audio_tgt.channels);

                    break;

                }

                VAR_0->audio_src.channel_layout = dec_channel_layout;

                VAR_0->audio_src.channels       = av_frame_get_channels(VAR_0->frame);

                VAR_0->audio_src.freq = VAR_0->frame->sample_rate;

                VAR_0->audio_src.fmt = VAR_0->frame->format;

            }



            if (VAR_0->swr_ctx) {

                const uint8_t **VAR_7 = (const uint8_t **)VAR_0->frame->extended_data;

                uint8_t **out = &VAR_0->audio_buf1;

                int VAR_8 = (int64_t)VAR_4 * VAR_0->audio_tgt.freq / VAR_0->frame->sample_rate + 256;

                int VAR_9  = av_samples_get_buffer_size(NULL, VAR_0->audio_tgt.channels, VAR_8, VAR_0->audio_tgt.fmt, 0);

                int VAR_10;

                if (VAR_9 < 0) {

                    av_log(NULL, AV_LOG_ERROR, "av_samples_get_buffer_size() failed\n");

                    break;

                }

                if (VAR_4 != VAR_0->frame->nb_samples) {

                    if (swr_set_compensation(VAR_0->swr_ctx, (VAR_4 - VAR_0->frame->nb_samples) * VAR_0->audio_tgt.freq / VAR_0->frame->sample_rate,

                                                VAR_4 * VAR_0->audio_tgt.freq / VAR_0->frame->sample_rate) < 0) {

                        av_log(NULL, AV_LOG_ERROR, "swr_set_compensation() failed\n");

                        break;

                    }

                }

                av_fast_malloc(&VAR_0->audio_buf1, &VAR_0->audio_buf1_size, VAR_9);

                if (!VAR_0->audio_buf1)

                    return AVERROR(ENOMEM);

                VAR_10 = swr_convert(VAR_0->swr_ctx, out, VAR_8, VAR_7, VAR_0->frame->nb_samples);

                if (VAR_10 < 0) {

                    av_log(NULL, AV_LOG_ERROR, "swr_convert() failed\n");

                    break;

                }

                if (VAR_10 == VAR_8) {

                    av_log(NULL, AV_LOG_WARNING, "audio buffer VAR_0 probably too small\n");

                    swr_init(VAR_0->swr_ctx);

                }

                VAR_0->audio_buf = VAR_0->audio_buf1;

                VAR_2 = VAR_10 * VAR_0->audio_tgt.channels * av_get_bytes_per_sample(VAR_0->audio_tgt.fmt);

            } else {

                VAR_0->audio_buf = VAR_0->frame->data[0];

                VAR_2 = VAR_1;

            }



            audio_clock0 = VAR_0->audio_clock;

            

            if (VAR_0->frame->pts != AV_NOPTS_VALUE)

                VAR_0->audio_clock = VAR_0->frame->pts * av_q2d(tb) + (double) VAR_0->frame->nb_samples / VAR_0->frame->sample_rate;

            else

                VAR_0->audio_clock = NAN;

            VAR_0->audio_clock_serial = VAR_0->auddec.pkt_serial;

#ifdef DEBUG

            {

                static double last_clock;

                printf("audio: delay=%0.3f clock=%0.3f clock0=%0.3f\n",

                       VAR_0->audio_clock - last_clock,

                       VAR_0->audio_clock, audio_clock0);

                last_clock = VAR_0->audio_clock;

            }

#endif

            return VAR_2;

        }



        if ((VAR_3 = decoder_decode_frame(&VAR_0->auddec, VAR_0->frame, NULL)) < 0)

            return -1;



        if (VAR_0->auddec.flushed)

            VAR_0->audio_buf_frames_pending = 0;

    }

}

static int FUNC_0(VideoState *VAR_0)
{ int VAR_1, VAR_2; int64_t dec_channel_layout; int VAR_3 = 0; av_unused double audio_clock0; int VAR_4; AVRational tb; int VAR_5; int VAR_6; if (!VAR_0->frame)
if (!(VAR_0->frame = av_frame_alloc()))
return AVERROR(ENOMEM); for (;;) { if (VAR_0->audioq.serial != VAR_0->auddec.pkt_serial)
VAR_0->audio_buf_frames_pending = VAR_3 = 0; if (!VAR_3)
av_frame_unref(VAR_0->frame); if (VAR_0->paused)
return -1; while (VAR_0->audio_buf_frames_pending || VAR_3) { if (!VAR_0->audio_buf_frames_pending) { VAR_3 = 0; tb = (AVRational){1, VAR_0->frame->sample_rate}; #if CONFIG_AVFILTER
dec_channel_layout = get_valid_channel_layout(VAR_0->frame->channel_layout, av_frame_get_channels(VAR_0->frame)); VAR_6 =
cmp_audio_fmts(VAR_0->audio_filter_src.fmt, VAR_0->audio_filter_src.channels,
VAR_0->frame->format, av_frame_get_channels(VAR_0->frame))    ||
VAR_0->audio_filter_src.channel_layout != dec_channel_layout ||
VAR_0->audio_filter_src.freq           != VAR_0->frame->sample_rate ||
VAR_0->auddec.pkt_serial               != VAR_0->audio_last_serial; if (VAR_6) { char buf1[1024], buf2[1024]; av_get_channel_layout_string(buf1, sizeof(buf1), -1, VAR_0->audio_filter_src.channel_layout); av_get_channel_layout_string(buf2, sizeof(buf2), -1, dec_channel_layout); av_log(NULL, AV_LOG_DEBUG,
"Audio frame changed from rate:%d ch:%d fmt:%s layout:%s serial:%d to rate:%d ch:%d fmt:%s layout:%s serial:%d\n",
VAR_0->audio_filter_src.freq, VAR_0->audio_filter_src.channels, av_get_sample_fmt_name(VAR_0->audio_filter_src.fmt), buf1, VAR_0->audio_last_serial,
VAR_0->frame->sample_rate, av_frame_get_channels(VAR_0->frame), av_get_sample_fmt_name(VAR_0->frame->format), buf2, VAR_0->auddec.pkt_serial); VAR_0->audio_filter_src.fmt            = VAR_0->frame->format; VAR_0->audio_filter_src.channels       = av_frame_get_channels(VAR_0->frame); VAR_0->audio_filter_src.channel_layout = dec_channel_layout; VAR_0->audio_filter_src.freq           = VAR_0->frame->sample_rate; VAR_0->audio_last_serial               = VAR_0->auddec.pkt_serial; if ((VAR_5 = configure_audio_filters(VAR_0, afilters, 1)) < 0)
return VAR_5; } if ((VAR_5 = av_buffersrc_add_frame(VAR_0->in_audio_filter, VAR_0->frame)) < 0)
return VAR_5; #endif
} #if CONFIG_AVFILTER
if ((VAR_5 = av_buffersink_get_frame_flags(VAR_0->out_audio_filter, VAR_0->frame, 0)) < 0) { if (VAR_5 == AVERROR(EAGAIN)) { VAR_0->audio_buf_frames_pending = 0; continue; } if (VAR_5 == AVERROR_EOF)
VAR_0->auddec.finished = VAR_0->auddec.pkt_serial; return VAR_5; } VAR_0->audio_buf_frames_pending = 1; tb = VAR_0->out_audio_filter->inputs[0]->time_base; #endif
VAR_1 = av_samples_get_buffer_size(NULL, av_frame_get_channels(VAR_0->frame),
VAR_0->frame->nb_samples,
VAR_0->frame->format, 1); dec_channel_layout =
(VAR_0->frame->channel_layout && av_frame_get_channels(VAR_0->frame) == av_get_channel_layout_nb_channels(VAR_0->frame->channel_layout)) ?
VAR_0->frame->channel_layout : av_get_default_channel_layout(av_frame_get_channels(VAR_0->frame)); VAR_4 = synchronize_audio(VAR_0, VAR_0->frame->nb_samples); if (VAR_0->frame->format        != VAR_0->audio_src.fmt            ||
dec_channel_layout       != VAR_0->audio_src.channel_layout ||
VAR_0->frame->sample_rate   != VAR_0->audio_src.freq           ||
(VAR_4       != VAR_0->frame->nb_samples && !VAR_0->swr_ctx)) { swr_free(&VAR_0->swr_ctx); VAR_0->swr_ctx = swr_alloc_set_opts(NULL,
VAR_0->audio_tgt.channel_layout, VAR_0->audio_tgt.fmt, VAR_0->audio_tgt.freq,
dec_channel_layout,           VAR_0->frame->format, VAR_0->frame->sample_rate,
0, NULL); if (!VAR_0->swr_ctx || swr_init(VAR_0->swr_ctx) < 0) { av_log(NULL, AV_LOG_ERROR,
"Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n",
VAR_0->frame->sample_rate, av_get_sample_fmt_name(VAR_0->frame->format), av_frame_get_channels(VAR_0->frame),
VAR_0->audio_tgt.freq, av_get_sample_fmt_name(VAR_0->audio_tgt.fmt), VAR_0->audio_tgt.channels); break; } VAR_0->audio_src.channel_layout = dec_channel_layout; VAR_0->audio_src.channels       = av_frame_get_channels(VAR_0->frame); VAR_0->audio_src.freq = VAR_0->frame->sample_rate; VAR_0->audio_src.fmt = VAR_0->frame->format; } if (VAR_0->swr_ctx) { const uint8_t **VAR_7 = (const uint8_t **)VAR_0->frame->extended_data; uint8_t **out = &VAR_0->audio_buf1; int VAR_8 = (int64_t)VAR_4 * VAR_0->audio_tgt.freq / VAR_0->frame->sample_rate + 256; int VAR_9  = av_samples_get_buffer_size(NULL, VAR_0->audio_tgt.channels, VAR_8, VAR_0->audio_tgt.fmt, 0); int VAR_10; if (VAR_9 < 0) { av_log(NULL, AV_LOG_ERROR, "av_samples_get_buffer_size() failed\n"); break; } if (VAR_4 != VAR_0->frame->nb_samples) { if (swr_set_compensation(VAR_0->swr_ctx, (VAR_4 - VAR_0->frame->nb_samples) * VAR_0->audio_tgt.freq / VAR_0->frame->sample_rate,
VAR_4 * VAR_0->audio_tgt.freq / VAR_0->frame->sample_rate) < 0) { av_log(NULL, AV_LOG_ERROR, "swr_set_compensation() failed\n"); break; } } av_fast_malloc(&VAR_0->audio_buf1, &VAR_0->audio_buf1_size, VAR_9); if (!VAR_0->audio_buf1)
return AVERROR(ENOMEM); VAR_10 = swr_convert(VAR_0->swr_ctx, out, VAR_8, VAR_7, VAR_0->frame->nb_samples); if (VAR_10 < 0) { av_log(NULL, AV_LOG_ERROR, "swr_convert() failed\n"); break; } if (VAR_10 == VAR_8) { av_log(NULL, AV_LOG_WARNING, "audio buffer VAR_0 probably too small\n"); swr_init(VAR_0->swr_ctx); } VAR_0->audio_buf = VAR_0->audio_buf1; VAR_2 = VAR_10 * VAR_0->audio_tgt.channels * av_get_bytes_per_sample(VAR_0->audio_tgt.fmt); } else { VAR_0->audio_buf = VAR_0->frame->data[0]; VAR_2 = VAR_1; } audio_clock0 = VAR_0->audio_clock; if (VAR_0->frame->pts != AV_NOPTS_VALUE)
VAR_0->audio_clock = VAR_0->frame->pts * av_q2d(tb) + (double) VAR_0->frame->nb_samples / VAR_0->frame->sample_rate; else
VAR_0->audio_clock = NAN; VAR_0->audio_clock_serial = VAR_0->auddec.pkt_serial; #ifdef DEBUG
{ static double last_clock; printf("audio: delay=%0.3f clock=%0.3f clock0=%0.3f\n",
VAR_0->audio_clock - last_clock,
VAR_0->audio_clock, audio_clock0); last_clock = VAR_0->audio_clock; } #endif
return VAR_2; } if ((VAR_3 = decoder_decode_frame(&VAR_0->auddec, VAR_0->frame, NULL)) < 0)
return -1; if (VAR_0->auddec.flushed)
VAR_0->audio_buf_frames_pending = 0; } }