int ff_mjpeg_encode_stuffing(MpegEncContext *s)

{

    int i;

    PutBitContext *pbc = &s->pb;

    int mb_y = s->mb_y - !s->mb_x;

    int ret;

    MJpegContext *m;



    m = s->mjpeg_ctx;



    if (s->huffman == HUFFMAN_TABLE_OPTIMAL) {

        ff_mjpeg_build_optimal_huffman(m);



        // Replace the VLCs with the optimal ones.

        // The default ones may be used for trellis during quantization.

        ff_init_uni_ac_vlc(m->huff_size_ac_luminance,   m->uni_ac_vlc_len);

        ff_init_uni_ac_vlc(m->huff_size_ac_chrominance, m->uni_chroma_ac_vlc_len);

        s->intra_ac_vlc_length      =

        s->intra_ac_vlc_last_length = m->uni_ac_vlc_len;

        s->intra_chroma_ac_vlc_length      =

        s->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len;

    }



    ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable,

                                   s->pred, s->intra_matrix, s->chroma_intra_matrix);

    ff_mjpeg_encode_picture_frame(s);



    ret = ff_mpv_reallocate_putbitbuffer(s, put_bits_count(&s->pb) / 8 + 100,

                                            put_bits_count(&s->pb) / 4 + 1000);



    if (ret < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "Buffer reallocation failed\n");

        goto fail;

    }



    ff_mjpeg_escape_FF(pbc, s->esc_pos);



    if((s->avctx->active_thread_type & FF_THREAD_SLICE) && mb_y < s->mb_height)

        put_marker(pbc, RST0 + (mb_y&7));

    s->esc_pos = put_bits_count(pbc) >> 3;

fail:



    for(i=0; i<3; i++)

        s->last_dc[i] = 128 << s->intra_dc_precision;



    return ret;

}

int ff_mjpeg_encode_stuffing(MpegEncContext *s)

{

    int i;

    PutBitContext *pbc = &s->pb;

    int mb_y = s->mb_y - !s->mb_x;

    int ret;

    MJpegContext *m;



    m = s->mjpeg_ctx;



    if (s->huffman == HUFFMAN_TABLE_OPTIMAL) {

        ff_mjpeg_build_optimal_huffman(m);



        

        

        ff_init_uni_ac_vlc(m->huff_size_ac_luminance,   m->uni_ac_vlc_len);

        ff_init_uni_ac_vlc(m->huff_size_ac_chrominance, m->uni_chroma_ac_vlc_len);

        s->intra_ac_vlc_length      =

        s->intra_ac_vlc_last_length = m->uni_ac_vlc_len;

        s->intra_chroma_ac_vlc_length      =

        s->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len;

    }



    ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable,

                                   s->pred, s->intra_matrix, s->chroma_intra_matrix);

    ff_mjpeg_encode_picture_frame(s);



    ret = ff_mpv_reallocate_putbitbuffer(s, put_bits_count(&s->pb) / 8 + 100,

                                            put_bits_count(&s->pb) / 4 + 1000);



    if (ret < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "Buffer reallocation failed\n");

        goto fail;

    }



    ff_mjpeg_escape_FF(pbc, s->esc_pos);



    if((s->avctx->active_thread_type & FF_THREAD_SLICE) && mb_y < s->mb_height)

        put_marker(pbc, RST0 + (mb_y&7));

    s->esc_pos = put_bits_count(pbc) >> 3;

fail:



    for(i=0; i<3; i++)

        s->last_dc[i] = 128 << s->intra_dc_precision;



    return ret;

}

int FUNC_0(MpegEncContext *VAR_0)

{

    int VAR_1;

    PutBitContext *pbc = &VAR_0->pb;

    int VAR_2 = VAR_0->VAR_2 - !VAR_0->mb_x;

    int VAR_3;

    MJpegContext *m;



    m = VAR_0->mjpeg_ctx;



    if (VAR_0->huffman == HUFFMAN_TABLE_OPTIMAL) {

        ff_mjpeg_build_optimal_huffman(m);



        

        

        ff_init_uni_ac_vlc(m->huff_size_ac_luminance,   m->uni_ac_vlc_len);

        ff_init_uni_ac_vlc(m->huff_size_ac_chrominance, m->uni_chroma_ac_vlc_len);

        VAR_0->intra_ac_vlc_length      =

        VAR_0->intra_ac_vlc_last_length = m->uni_ac_vlc_len;

        VAR_0->intra_chroma_ac_vlc_length      =

        VAR_0->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len;

    }



    ff_mjpeg_encode_picture_header(VAR_0->avctx, &VAR_0->pb, &VAR_0->intra_scantable,

                                   VAR_0->pred, VAR_0->intra_matrix, VAR_0->chroma_intra_matrix);

    ff_mjpeg_encode_picture_frame(VAR_0);



    VAR_3 = ff_mpv_reallocate_putbitbuffer(VAR_0, put_bits_count(&VAR_0->pb) / 8 + 100,

                                            put_bits_count(&VAR_0->pb) / 4 + 1000);



    if (VAR_3 < 0) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Buffer reallocation failed\n");

        goto fail;

    }



    ff_mjpeg_escape_FF(pbc, VAR_0->esc_pos);



    if((VAR_0->avctx->active_thread_type & FF_THREAD_SLICE) && VAR_2 < VAR_0->mb_height)

        put_marker(pbc, RST0 + (VAR_2&7));

    VAR_0->esc_pos = put_bits_count(pbc) >> 3;

fail:



    for(VAR_1=0; VAR_1<3; VAR_1++)

        VAR_0->last_dc[VAR_1] = 128 << VAR_0->intra_dc_precision;



    return VAR_3;

}

int FUNC_0(MpegEncContext *VAR_0)
{ int VAR_1; PutBitContext *pbc = &VAR_0->pb; int VAR_2 = VAR_0->VAR_2 - !VAR_0->mb_x; int VAR_3; MJpegContext *m; m = VAR_0->mjpeg_ctx; if (VAR_0->huffman == HUFFMAN_TABLE_OPTIMAL) { ff_mjpeg_build_optimal_huffman(m); ff_init_uni_ac_vlc(m->huff_size_ac_luminance,   m->uni_ac_vlc_len); ff_init_uni_ac_vlc(m->huff_size_ac_chrominance, m->uni_chroma_ac_vlc_len); VAR_0->intra_ac_vlc_length      =
VAR_0->intra_ac_vlc_last_length = m->uni_ac_vlc_len; VAR_0->intra_chroma_ac_vlc_length      =
VAR_0->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len; } ff_mjpeg_encode_picture_header(VAR_0->avctx, &VAR_0->pb, &VAR_0->intra_scantable,
VAR_0->pred, VAR_0->intra_matrix, VAR_0->chroma_intra_matrix); ff_mjpeg_encode_picture_frame(VAR_0); VAR_3 = ff_mpv_reallocate_putbitbuffer(VAR_0, put_bits_count(&VAR_0->pb) / 8 + 100,
put_bits_count(&VAR_0->pb) / 4 + 1000); if (VAR_3 < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Buffer reallocation failed\n"); goto fail; } ff_mjpeg_escape_FF(pbc, VAR_0->esc_pos); if((VAR_0->avctx->active_thread_type & FF_THREAD_SLICE) && VAR_2 < VAR_0->mb_height)
put_marker(pbc, RST0 + (VAR_2&7)); VAR_0->esc_pos = put_bits_count(pbc) >> 3; fail:
for(VAR_1=0; VAR_1<3; VAR_1++) VAR_0->last_dc[VAR_1] = 128 << VAR_0->intra_dc_precision; return VAR_3; }