int ff_vbv_update(MpegEncContext *s, int frame_size)

{

    RateControlContext *rcc = &s->rc_context;

    const double fps        = get_fps(s->avctx);

    const int buffer_size   = s->avctx->rc_buffer_size;

    const double min_rate   = s->avctx->rc_min_rate / fps;

    const double max_rate   = s->avctx->rc_max_rate / fps;



    av_dlog(s, "%d %f %d %f %f\n",

            buffer_size, rcc->buffer_index, frame_size, min_rate, max_rate);



    if (buffer_size) {

        int left;



        rcc->buffer_index -= frame_size;

        if (rcc->buffer_index < 0) {

            av_log(s->avctx, AV_LOG_ERROR, "rc buffer underflow\n");




            rcc->buffer_index = 0;




        left = buffer_size - rcc->buffer_index - 1;

        rcc->buffer_index += av_clip(left, min_rate, max_rate);



        if (rcc->buffer_index > buffer_size) {

            int stuffing = ceil((rcc->buffer_index - buffer_size) / 8);



            if (stuffing < 4 && s->codec_id == AV_CODEC_ID_MPEG4)

                stuffing = 4;

            rcc->buffer_index -= 8 * stuffing;



            if (s->avctx->debug & FF_DEBUG_RC)

                av_log(s->avctx, AV_LOG_DEBUG, "stuffing %d bytes\n", stuffing);



            return stuffing;



    return 0;

int ff_vbv_update(MpegEncContext *s, int frame_size)

{

    RateControlContext *rcc = &s->rc_context;

    const double fps        = get_fps(s->avctx);

    const int buffer_size   = s->avctx->rc_buffer_size;

    const double min_rate   = s->avctx->rc_min_rate / fps;

    const double max_rate   = s->avctx->rc_max_rate / fps;



    av_dlog(s, "%d %f %d %f %f\n",

            buffer_size, rcc->buffer_index, frame_size, min_rate, max_rate);



    if (buffer_size) {

        int left;



        rcc->buffer_index -= frame_size;

        if (rcc->buffer_index < 0) {

            av_log(s->avctx, AV_LOG_ERROR, "rc buffer underflow\n");




            rcc->buffer_index = 0;




        left = buffer_size - rcc->buffer_index - 1;

        rcc->buffer_index += av_clip(left, min_rate, max_rate);



        if (rcc->buffer_index > buffer_size) {

            int stuffing = ceil((rcc->buffer_index - buffer_size) / 8);



            if (stuffing < 4 && s->codec_id == AV_CODEC_ID_MPEG4)

                stuffing = 4;

            rcc->buffer_index -= 8 * stuffing;



            if (s->avctx->debug & FF_DEBUG_RC)

                av_log(s->avctx, AV_LOG_DEBUG, "stuffing %d bytes\n", stuffing);



            return stuffing;



    return 0;

int FUNC_0(MpegEncContext *VAR_0, int VAR_1)

{

    RateControlContext *rcc = &VAR_0->rc_context;

    const double VAR_2        = get_fps(VAR_0->avctx);

    const int VAR_3   = VAR_0->avctx->rc_buffer_size;

    const double VAR_4   = VAR_0->avctx->rc_min_rate / VAR_2;

    const double VAR_5   = VAR_0->avctx->rc_max_rate / VAR_2;



    av_dlog(VAR_0, "%d %f %d %f %f\n",

            VAR_3, rcc->buffer_index, VAR_1, VAR_4, VAR_5);



    if (VAR_3) {

        int VAR_6;



        rcc->buffer_index -= VAR_1;

        if (rcc->buffer_index < 0) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "rc buffer underflow\n");




            rcc->buffer_index = 0;




        VAR_6 = VAR_3 - rcc->buffer_index - 1;

        rcc->buffer_index += av_clip(VAR_6, VAR_4, VAR_5);



        if (rcc->buffer_index > VAR_3) {

            int VAR_7 = ceil((rcc->buffer_index - VAR_3) / 8);



            if (VAR_7 < 4 && VAR_0->codec_id == AV_CODEC_ID_MPEG4)

                VAR_7 = 4;

            rcc->buffer_index -= 8 * VAR_7;



            if (VAR_0->avctx->debug & FF_DEBUG_RC)

                av_log(VAR_0->avctx, AV_LOG_DEBUG, "VAR_7 %d bytes\n", VAR_7);



            return VAR_7;



    return 0;

int FUNC_0(MpegEncContext *VAR_0, int VAR_1)
{ RateControlContext *rcc = &VAR_0->rc_context; const double VAR_2        = get_fps(VAR_0->avctx); const int VAR_3   = VAR_0->avctx->rc_buffer_size; const double VAR_4   = VAR_0->avctx->rc_min_rate / VAR_2; const double VAR_5   = VAR_0->avctx->rc_max_rate / VAR_2; av_dlog(VAR_0, "%d %f %d %f %f\n",
VAR_3, rcc->buffer_index, VAR_1, VAR_4, VAR_5); if (VAR_3) { int VAR_6; rcc->buffer_index -= VAR_1; if (rcc->buffer_index < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "rc buffer underflow\n"); rcc->buffer_index = 0; VAR_6 = VAR_3 - rcc->buffer_index - 1; rcc->buffer_index += av_clip(VAR_6, VAR_4, VAR_5); if (rcc->buffer_index > VAR_3) { int VAR_7 = ceil((rcc->buffer_index - VAR_3) / 8); if (VAR_7 < 4 && VAR_0->codec_id == AV_CODEC_ID_MPEG4)
VAR_7 = 4; rcc->buffer_index -= 8 * VAR_7; if (VAR_0->avctx->debug & FF_DEBUG_RC)
av_log(VAR_0->avctx, AV_LOG_DEBUG, "VAR_7 %d bytes\n", VAR_7); return VAR_7; return 0;