static int filter_frame(AVFilterLink *inlink, AVFrame *in)

{

    AVFilterContext *ctx = inlink->dst;

    HDCDContext *s = ctx->priv;

    AVFilterLink *outlink = ctx->outputs[0];

    AVFrame *out;

    const int16_t *in_data;

    int32_t *out_data;

    int n, c;

    int detect, packets, pe_packets;



    out = ff_get_audio_buffer(outlink, in->nb_samples);

    if (!out) {

        av_frame_free(&in);

        return AVERROR(ENOMEM);

    }

    av_frame_copy_props(out, in);

    out->format = outlink->format;



    in_data  = (int16_t*)in->data[0];

    out_data = (int32_t*)out->data[0];

    for (n = 0; n < in->nb_samples * in->channels; n++) {

        out_data[n] = in_data[n];

    }



    detect = 0;

    packets = 0;

    pe_packets = 0;

    s->det_errors = 0;

    for (c = 0; c < inlink->channels; c++) {

        hdcd_state_t *state = &s->state[c];

        hdcd_process(s, state, out_data + c, in->nb_samples, out->channels);

        if (state->sustain) detect++;

        packets += state->code_counterA + state->code_counterB;

        pe_packets += state->count_peak_extend;

        s->uses_transient_filter |= !!state->count_transient_filter;

        s->max_gain_adjustment = FFMIN(s->max_gain_adjustment, GAINTOFLOAT(state->max_gain));

        s->det_errors += state->code_counterA_almost

            + state->code_counterB_checkfails

            + state->code_counterC_unmatched;

    }

    if (pe_packets) {

        /* if every valid packet has used PE, call it permanent */

        if (packets == pe_packets)

            s->peak_extend = HDCD_PE_PERMANENT;

        else

            s->peak_extend = HDCD_PE_INTERMITTENT;

    } else {

        s->peak_extend = HDCD_PE_NEVER;

    }

    /* HDCD is detected if a valid packet is active in all (both)

     * channels at the same time. */

    if (detect == inlink->channels) s->hdcd_detected = 1;



    s->sample_count += in->nb_samples * in->channels;



    av_frame_free(&in);

    return ff_filter_frame(outlink, out);

}

static int filter_frame(AVFilterLink *inlink, AVFrame *in)

{

    AVFilterContext *ctx = inlink->dst;

    HDCDContext *s = ctx->priv;

    AVFilterLink *outlink = ctx->outputs[0];

    AVFrame *out;

    const int16_t *in_data;

    int32_t *out_data;

    int n, c;

    int detect, packets, pe_packets;



    out = ff_get_audio_buffer(outlink, in->nb_samples);

    if (!out) {

        av_frame_free(&in);

        return AVERROR(ENOMEM);

    }

    av_frame_copy_props(out, in);

    out->format = outlink->format;



    in_data  = (int16_t*)in->data[0];

    out_data = (int32_t*)out->data[0];

    for (n = 0; n < in->nb_samples * in->channels; n++) {

        out_data[n] = in_data[n];

    }



    detect = 0;

    packets = 0;

    pe_packets = 0;

    s->det_errors = 0;

    for (c = 0; c < inlink->channels; c++) {

        hdcd_state_t *state = &s->state[c];

        hdcd_process(s, state, out_data + c, in->nb_samples, out->channels);

        if (state->sustain) detect++;

        packets += state->code_counterA + state->code_counterB;

        pe_packets += state->count_peak_extend;

        s->uses_transient_filter |= !!state->count_transient_filter;

        s->max_gain_adjustment = FFMIN(s->max_gain_adjustment, GAINTOFLOAT(state->max_gain));

        s->det_errors += state->code_counterA_almost

            + state->code_counterB_checkfails

            + state->code_counterC_unmatched;

    }

    if (pe_packets) {

        

        if (packets == pe_packets)

            s->peak_extend = HDCD_PE_PERMANENT;

        else

            s->peak_extend = HDCD_PE_INTERMITTENT;

    } else {

        s->peak_extend = HDCD_PE_NEVER;

    }

    



    if (detect == inlink->channels) s->hdcd_detected = 1;



    s->sample_count += in->nb_samples * in->channels;



    av_frame_free(&in);

    return ff_filter_frame(outlink, out);

}

static int FUNC_0(AVFilterLink *VAR_0, AVFrame *VAR_1)

{

    AVFilterContext *ctx = VAR_0->dst;

    HDCDContext *s = ctx->priv;

    AVFilterLink *outlink = ctx->outputs[0];

    AVFrame *out;

    const int16_t *VAR_2;

    int32_t *out_data;

    int VAR_3, VAR_4;

    int VAR_5, VAR_6, VAR_7;



    out = ff_get_audio_buffer(outlink, VAR_1->nb_samples);

    if (!out) {

        av_frame_free(&VAR_1);

        return AVERROR(ENOMEM);

    }

    av_frame_copy_props(out, VAR_1);

    out->format = outlink->format;



    VAR_2  = (int16_t*)VAR_1->data[0];

    out_data = (int32_t*)out->data[0];

    for (VAR_3 = 0; VAR_3 < VAR_1->nb_samples * VAR_1->channels; VAR_3++) {

        out_data[VAR_3] = VAR_2[VAR_3];

    }



    VAR_5 = 0;

    VAR_6 = 0;

    VAR_7 = 0;

    s->det_errors = 0;

    for (VAR_4 = 0; VAR_4 < VAR_0->channels; VAR_4++) {

        hdcd_state_t *state = &s->state[VAR_4];

        hdcd_process(s, state, out_data + VAR_4, VAR_1->nb_samples, out->channels);

        if (state->sustain) VAR_5++;

        VAR_6 += state->code_counterA + state->code_counterB;

        VAR_7 += state->count_peak_extend;

        s->uses_transient_filter |= !!state->count_transient_filter;

        s->max_gain_adjustment = FFMIN(s->max_gain_adjustment, GAINTOFLOAT(state->max_gain));

        s->det_errors += state->code_counterA_almost

            + state->code_counterB_checkfails

            + state->code_counterC_unmatched;

    }

    if (VAR_7) {

        

        if (VAR_6 == VAR_7)

            s->peak_extend = HDCD_PE_PERMANENT;

        else

            s->peak_extend = HDCD_PE_INTERMITTENT;

    } else {

        s->peak_extend = HDCD_PE_NEVER;

    }

    



    if (VAR_5 == VAR_0->channels) s->hdcd_detected = 1;



    s->sample_count += VAR_1->nb_samples * VAR_1->channels;



    av_frame_free(&VAR_1);

    return ff_filter_frame(outlink, out);

}

static int FUNC_0(AVFilterLink *VAR_0, AVFrame *VAR_1)
{ AVFilterContext *ctx = VAR_0->dst; HDCDContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; AVFrame *out; const int16_t *VAR_2; int32_t *out_data; int VAR_3, VAR_4; int VAR_5, VAR_6, VAR_7; out = ff_get_audio_buffer(outlink, VAR_1->nb_samples); if (!out) { av_frame_free(&VAR_1); return AVERROR(ENOMEM); } av_frame_copy_props(out, VAR_1); out->format = outlink->format; VAR_2  = (int16_t*)VAR_1->data[0]; out_data = (int32_t*)out->data[0]; for (VAR_3 = 0; VAR_3 < VAR_1->nb_samples * VAR_1->channels; VAR_3++) { out_data[VAR_3] = VAR_2[VAR_3]; } VAR_5 = 0; VAR_6 = 0; VAR_7 = 0; s->det_errors = 0; for (VAR_4 = 0; VAR_4 < VAR_0->channels; VAR_4++) { hdcd_state_t *state = &s->state[VAR_4]; hdcd_process(s, state, out_data + VAR_4, VAR_1->nb_samples, out->channels); if (state->sustain) VAR_5++; VAR_6 += state->code_counterA + state->code_counterB; VAR_7 += state->count_peak_extend; s->uses_transient_filter |= !!state->count_transient_filter; s->max_gain_adjustment = FFMIN(s->max_gain_adjustment, GAINTOFLOAT(state->max_gain)); s->det_errors += state->code_counterA_almost
+ state->code_counterB_checkfails
+ state->code_counterC_unmatched; } if (VAR_7) { if (VAR_6 == VAR_7)
s->peak_extend = HDCD_PE_PERMANENT; else
s->peak_extend = HDCD_PE_INTERMITTENT; } else { s->peak_extend = HDCD_PE_NEVER; } if (VAR_5 == VAR_0->channels) s->hdcd_detected = 1; s->sample_count += VAR_1->nb_samples * VAR_1->channels; av_frame_free(&VAR_1); return ff_filter_frame(outlink, out); }