static char *value_string(char *buf, int buf_size, struct unit_value uv)

{

    double vald;

    int show_float = 0;

    if (uv.unit == unit_second_str) {

        vald = uv.val.d;

        show_float = 1;

    } else {

        vald = uv.val.i;

    }

    if (uv.unit == unit_second_str && use_value_sexagesimal_format) {

        double secs;

        int hours, mins;

        secs  = vald;

        mins  = (int)secs / 60;

        secs  = secs - mins * 60;

        hours = mins / 60;

        mins %= 60;

        snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);

    } else {

        const char *prefix_string = "";

        int l;

        if (use_value_prefix && vald > 1) {

            long long int index;

            if (uv.unit == unit_byte_str && use_byte_value_binary_prefix) {

                index = (long long int) (log2(vald)) / 10;

                index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) - 1);

                vald /= exp2(index * 10);

                prefix_string = binary_unit_prefixes[index];

            } else {

                index = (long long int) (log10(vald)) / 3;

                index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) - 1);

                vald /= pow(10, index * 3);

                prefix_string = decimal_unit_prefixes[index];

            }

        }

        if (show_float || (use_value_prefix && vald != (long long int)vald))

            l = snprintf(buf, buf_size, "%f", vald);

        else

            l = snprintf(buf, buf_size, "%lld", (long long int)vald);

        snprintf(buf+l, buf_size-l, "%s%s%s", *prefix_string || show_value_unit ? " " : "",

                 prefix_string, show_value_unit ? uv.unit : "");

    }

    return buf;

}


static int mjpeg_decode_dht(MJpegDecodeContext *s)

{

    int len, index, i, class, n, v, code_max;

    uint8_t bits_table[17];

    uint8_t val_table[256];

    len = get_bits(&s->gb, 16) - 2;

    while (len > 0) {

        if (len < 17)

            return -1;

        class = get_bits(&s->gb, 4);

        if (class >= 2)

            return -1;

        index = get_bits(&s->gb, 4);

        if (index >= 4)

            return -1;

        n = 0;

        for(i=1;i<=16;i++) {

            bits_table[i] = get_bits(&s->gb, 8);

            n += bits_table[i];

        }

        len -= 17;

        if (len < n || n > 256)

            return -1;

        code_max = 0;

        for(i=0;i<n;i++) {

            v = get_bits(&s->gb, 8);

            if (v > code_max)

                code_max = v;

            val_table[i] = v;

        }

        len -= n;

        /* build VLC and flush previous vlc if present */

        free_vlc(&s->vlcs[class][index]);

        dprintf("class=%d index=%d nb_codes=%d\n",

               class, index, code_max + 1);

        if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1) < 0){

            return -1;

        }

    }

    return 0;

}