static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)

{

    int ret = 0;



    /* apply the output bitstream filters, if any */

    if (ost->nb_bitstream_filters) {

        int idx;



        ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt);

        if (ret < 0)

            goto finish;



        idx = 1;

        while (idx) {

            /* get a packet from the previous filter up the chain */

            ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt);

            if (ret == AVERROR(EAGAIN)) {

                ret = 0;

                idx--;

                continue;

            } else if (ret < 0)

                goto finish;

            /* HACK! - aac_adtstoasc updates extradata after filtering the first frame when

             * the api states this shouldn't happen after init(). Propagate it here to the

             * muxer and to the next filters in the chain to workaround this.

             * TODO/FIXME - Make aac_adtstoasc use new packet side data instead of changing

             * par_out->extradata and adapt muxers accordingly to get rid of this. */

            if (!(ost->bsf_extradata_updated[idx - 1] & 1)) {

                ret = avcodec_parameters_copy(ost->st->codecpar, ost->bsf_ctx[idx - 1]->par_out);

                if (ret < 0)

                    goto finish;

                ost->bsf_extradata_updated[idx - 1] |= 1;

            }



            /* send it to the next filter down the chain or to the muxer */

            if (idx < ost->nb_bitstream_filters) {

                /* HACK/FIXME! - See above */

                if (!(ost->bsf_extradata_updated[idx] & 2)) {

                    ret = avcodec_parameters_copy(ost->bsf_ctx[idx]->par_out, ost->bsf_ctx[idx - 1]->par_out);

                    if (ret < 0)

                        goto finish;

                    ost->bsf_extradata_updated[idx] |= 2;

                }

                ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt);

                if (ret < 0)

                    goto finish;

                idx++;

            } else

                write_packet(of, pkt, ost);

        }

    } else

        write_packet(of, pkt, ost);



finish:

    if (ret < 0 && ret != AVERROR_EOF) {

        av_log(NULL, AV_LOG_ERROR, "Error applying bitstream filters to an output "

               "packet for stream #%d:%d.\n", ost->file_index, ost->index);

        if(exit_on_error)

            exit_program(1);

    }

}

static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)

{

    int ret = 0;



    

    if (ost->nb_bitstream_filters) {

        int idx;



        ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt);

        if (ret < 0)

            goto finish;



        idx = 1;

        while (idx) {

            

            ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt);

            if (ret == AVERROR(EAGAIN)) {

                ret = 0;

                idx--;

                continue;

            } else if (ret < 0)

                goto finish;

            









            if (!(ost->bsf_extradata_updated[idx - 1] & 1)) {

                ret = avcodec_parameters_copy(ost->st->codecpar, ost->bsf_ctx[idx - 1]->par_out);

                if (ret < 0)

                    goto finish;

                ost->bsf_extradata_updated[idx - 1] |= 1;

            }



            

            if (idx < ost->nb_bitstream_filters) {

                

                if (!(ost->bsf_extradata_updated[idx] & 2)) {

                    ret = avcodec_parameters_copy(ost->bsf_ctx[idx]->par_out, ost->bsf_ctx[idx - 1]->par_out);

                    if (ret < 0)

                        goto finish;

                    ost->bsf_extradata_updated[idx] |= 2;

                }

                ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt);

                if (ret < 0)

                    goto finish;

                idx++;

            } else

                write_packet(of, pkt, ost);

        }

    } else

        write_packet(of, pkt, ost);



finish:

    if (ret < 0 && ret != AVERROR_EOF) {

        av_log(NULL, AV_LOG_ERROR, "Error applying bitstream filters to an output "

               "packet for stream #%d:%d.\n", ost->file_index, ost->index);

        if(exit_on_error)

            exit_program(1);

    }

}

static void FUNC_0(OutputFile *VAR_0, AVPacket *VAR_1, OutputStream *VAR_2)

{

    int VAR_3 = 0;



    

    if (VAR_2->nb_bitstream_filters) {

        int VAR_4;



        VAR_3 = av_bsf_send_packet(VAR_2->bsf_ctx[0], VAR_1);

        if (VAR_3 < 0)

            goto finish;



        VAR_4 = 1;

        while (VAR_4) {

            

            VAR_3 = av_bsf_receive_packet(VAR_2->bsf_ctx[VAR_4 - 1], VAR_1);

            if (VAR_3 == AVERROR(EAGAIN)) {

                VAR_3 = 0;

                VAR_4--;

                continue;

            } else if (VAR_3 < 0)

                goto finish;

            









            if (!(VAR_2->bsf_extradata_updated[VAR_4 - 1] & 1)) {

                VAR_3 = avcodec_parameters_copy(VAR_2->st->codecpar, VAR_2->bsf_ctx[VAR_4 - 1]->par_out);

                if (VAR_3 < 0)

                    goto finish;

                VAR_2->bsf_extradata_updated[VAR_4 - 1] |= 1;

            }



            

            if (VAR_4 < VAR_2->nb_bitstream_filters) {

                

                if (!(VAR_2->bsf_extradata_updated[VAR_4] & 2)) {

                    VAR_3 = avcodec_parameters_copy(VAR_2->bsf_ctx[VAR_4]->par_out, VAR_2->bsf_ctx[VAR_4 - 1]->par_out);

                    if (VAR_3 < 0)

                        goto finish;

                    VAR_2->bsf_extradata_updated[VAR_4] |= 2;

                }

                VAR_3 = av_bsf_send_packet(VAR_2->bsf_ctx[VAR_4], VAR_1);

                if (VAR_3 < 0)

                    goto finish;

                VAR_4++;

            } else

                write_packet(VAR_0, VAR_1, VAR_2);

        }

    } else

        write_packet(VAR_0, VAR_1, VAR_2);



finish:

    if (VAR_3 < 0 && VAR_3 != AVERROR_EOF) {

        av_log(NULL, AV_LOG_ERROR, "Error applying bitstream filters to an output "

               "packet for stream #%d:%d.\n", VAR_2->file_index, VAR_2->index);

        if(exit_on_error)

            exit_program(1);

    }

}

static void FUNC_0(OutputFile *VAR_0, AVPacket *VAR_1, OutputStream *VAR_2)
{ int VAR_3 = 0; if (VAR_2->nb_bitstream_filters) { int VAR_4; VAR_3 = av_bsf_send_packet(VAR_2->bsf_ctx[0], VAR_1); if (VAR_3 < 0)
goto finish; VAR_4 = 1; while (VAR_4) { VAR_3 = av_bsf_receive_packet(VAR_2->bsf_ctx[VAR_4 - 1], VAR_1); if (VAR_3 == AVERROR(EAGAIN)) { VAR_3 = 0; VAR_4--; continue; } else if (VAR_3 < 0) goto finish; if (!(VAR_2->bsf_extradata_updated[VAR_4 - 1] & 1)) { VAR_3 = avcodec_parameters_copy(VAR_2->st->codecpar, VAR_2->bsf_ctx[VAR_4 - 1]->par_out); if (VAR_3 < 0)
goto finish; VAR_2->bsf_extradata_updated[VAR_4 - 1] |= 1; } if (VAR_4 < VAR_2->nb_bitstream_filters) { if (!(VAR_2->bsf_extradata_updated[VAR_4] & 2)) { VAR_3 = avcodec_parameters_copy(VAR_2->bsf_ctx[VAR_4]->par_out, VAR_2->bsf_ctx[VAR_4 - 1]->par_out); if (VAR_3 < 0)
goto finish; VAR_2->bsf_extradata_updated[VAR_4] |= 2; } VAR_3 = av_bsf_send_packet(VAR_2->bsf_ctx[VAR_4], VAR_1); if (VAR_3 < 0)
goto finish; VAR_4++; } else write_packet(VAR_0, VAR_1, VAR_2); } } else write_packet(VAR_0, VAR_1, VAR_2); finish:
if (VAR_3 < 0 && VAR_3 != AVERROR_EOF) { av_log(NULL, AV_LOG_ERROR, "Error applying bitstream filters to an output "
"packet for stream #%d:%d.\n", VAR_2->file_index, VAR_2->index); if(exit_on_error)
exit_program(1); } }