⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.c

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 C
📖 第 1 页 / 共 4 页
字号:
{    const char *p;    int64_t t;    struct tm dt;    int i;    static const char *date_fmt[] = {        "%Y-%m-%d",        "%Y%m%d",    };    static const char *time_fmt[] = {        "%H:%M:%S",        "%H%M%S",    };    const char *q;    int is_utc, len;    char lastch;    time_t now = time(0);    len = strlen(datestr);    if (len > 0)        lastch = datestr[len - 1];    else        lastch = '\0';    is_utc = (lastch == 'z' || lastch == 'Z');    memset(&dt, 0, sizeof(dt));    p = datestr;    q = NULL;    if (!duration) {        for (i = 0; i < sizeof(date_fmt) / sizeof(date_fmt[0]); i++) {            q = small_strptime(p, date_fmt[i], &dt);            if (q) {                break;            }        }        if (!q) {            if (is_utc) {                dt = *gmtime(&now);            } else {                dt = *localtime(&now);            }            dt.tm_hour = dt.tm_min = dt.tm_sec = 0;        } else {            p = q;        }        if (*p == 'T' || *p == 't' || *p == ' ')            p++;        for (i = 0; i < sizeof(time_fmt) / sizeof(time_fmt[0]); i++) {            q = small_strptime(p, time_fmt[i], &dt);            if (q) {                break;            }        }    } else {        q = small_strptime(p, time_fmt[0], &dt);        if (!q) {            dt.tm_sec = strtol(p, (char **)&q, 10);            dt.tm_min = 0;            dt.tm_hour = 0;        }    }    /* Now we have all the fields that we can get */    if (!q) {        if (duration)            return 0;        else            return now * int64_t_C(1000000);    }    if (duration) {        t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;    } else {        dt.tm_isdst = -1;       /* unknown */        if (is_utc) {            t = mktimegm(&dt);        } else {            t = mktime(&dt);        }    }    t *= 1000000;    if (*q == '.') {        int val, n;        q++;        for (val = 0, n = 100000; n >= 1; n /= 10, q++) {            if (!isdigit(*q))                 break;            val += n * (*q - '0');        }        t += val;    }    return t;}/* syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. Return   1 if found */int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info){    const char *p;    char tag[128], *q;    p = info;    if (*p == '?')        p++;    for(;;) {        q = tag;        while (*p != '\0' && *p != '=' && *p != '&') {            if ((q - tag) < sizeof(tag) - 1)                *q++ = *p;            p++;        }        *q = '\0';        q = arg;        if (*p == '=') {            p++;            while (*p != '&' && *p != '\0') {                if ((q - arg) < arg_size - 1) {                    if (*p == '+')                        *q++ = ' ';                    else                        *q++ = *p;                }                p++;            }            *q = '\0';        }        if (!strcmp(tag, tag1))             return 1;        if (*p != '&')            break;        p++;    }    return 0;}/* Return in 'buf' the path with '%d' replaced by number. Also handles   the '%0nd' format where 'n' is the total number of digits and   '%%'. Return 0 if OK, and -1 if format error */int get_frame_filename(char *buf, int buf_size,                       const char *path, int number){    const char *p;    char *q, buf1[20], c;    int nd, len, percentd_found;    q = buf;    p = path;    percentd_found = 0;    for(;;) {        c = *p++;        if (c == '\0')            break;        if (c == '%') {            do {                nd = 0;                while (isdigit(*p)) {                    nd = nd * 10 + *p++ - '0';                }                c = *p++;            } while (isdigit(c));            switch(c) {            case '%':                goto addchar;            case 'd':                if (percentd_found)                    goto fail;                percentd_found = 1;                snprintf(buf1, sizeof(buf1), "%0*d", nd, number);                len = strlen(buf1);                if ((q - buf + len) > buf_size - 1)                    goto fail;                memcpy(q, buf1, len);                q += len;                break;            default:                goto fail;            }        } else {        addchar:            if ((q - buf) < buf_size - 1)                *q++ = c;        }    }    if (!percentd_found)        goto fail;    *q = '\0';    return 0; fail:    *q = '\0';    return -1;}/** * * Print on stdout a nice hexa dump of a buffer * @param buf buffer * @param size buffer size */void av_hex_dump(uint8_t *buf, int size){    int len, i, j, c;    for(i=0;i<size;i+=16) {        len = size - i;        if (len > 16)            len = 16;        printf("%08x ", i);        for(j=0;j<16;j++) {            if (j < len)                printf(" %02x", buf[i+j]);            else                printf("   ");        }        printf(" ");        for(j=0;j<len;j++) {            c = buf[i+j];            if (c < ' ' || c > '~')                c = '.';            printf("%c", c);        }        printf("\n");    }}void url_split(char *proto, int proto_size,               char *hostname, int hostname_size,               int *port_ptr,               char *path, int path_size,               const char *url){    const char *p;    char *q;    int port;    port = -1;    p = url;    q = proto;    while (*p != ':' && *p != '\0') {        if ((q - proto) < proto_size - 1)            *q++ = *p;        p++;    }    if (proto_size > 0)        *q = '\0';    if (*p == '\0') {        if (proto_size > 0)            proto[0] = '\0';        if (hostname_size > 0)            hostname[0] = '\0';        p = url;    } else {        p++;        if (*p == '/')            p++;        if (*p == '/')            p++;        q = hostname;        while (*p != ':' && *p != '/' && *p != '?' && *p != '\0') {            if ((q - hostname) < hostname_size - 1)                *q++ = *p;            p++;        }        if (hostname_size > 0)            *q = '\0';        if (*p == ':') {            p++;            port = strtoul(p, (char **)&p, 10);        }    }    if (port_ptr)        *port_ptr = port;    pstrcpy(path, path_size, p);}/** * Set the pts for a given stream * @param s stream  * @param pts_wrap_bits number of bits effectively used by the pts *        (used for wrap control, 33 is the value for MPEG)  * @param pts_num numerator to convert to seconds (MPEG: 1)  * @param pts_den denominator to convert to seconds (MPEG: 90000) */void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,                     int pts_num, int pts_den){    s->pts_wrap_bits = pts_wrap_bits;    s->pts_num = pts_num;    s->pts_den = pts_den;}/* fraction handling *//** * f = val + (num / den) + 0.5. 'num' is normalized so that it is such * as 0 <= num < den. * * @param f fractional number * @param val integer value * @param num must be >= 0 * @param den must be >= 1  */void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den){    num += (den >> 1);    if (num >= den) {        val += num / den;        num = num % den;    }    f->val = val;    f->num = num;    f->den = den;}/* set f to (val + 0.5) */void av_frac_set(AVFrac *f, int64_t val){    f->val = val;    f->num = f->den >> 1;}/** * Fractionnal addition to f: f = f + (incr / f->den) * * @param f fractional number * @param incr increment, can be positive or negative */void av_frac_add(AVFrac *f, int64_t incr){    int64_t num, den;    num = f->num + incr;    den = f->den;    if (num < 0) {        f->val += num / den;        num = num % den;        if (num < 0) {            num += den;            f->val--;        }    } else if (num >= den) {        f->val += num / den;        num = num % den;    }    f->num = num;}/** * register a new image format * @param img_fmt Image format descriptor */void av_register_image_format(AVImageFormat *img_fmt){    AVImageFormat **p;    p = &first_image_format;    while (*p != NULL) p = &(*p)->next;    *p = img_fmt;    img_fmt->next = NULL;}/* guess image format */AVImageFormat *av_probe_image_format(AVProbeData *pd){    AVImageFormat *fmt1, *fmt;    int score, score_max;    fmt = NULL;    score_max = 0;    for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {        if (fmt1->img_probe) {            score = fmt1->img_probe(pd);            if (score > score_max) {                score_max = score;                fmt = fmt1;            }        }    }    return fmt;}AVImageFormat *guess_image_format(const char *filename){    AVImageFormat *fmt1;    for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {        if (fmt1->extensions && match_ext(filename, fmt1->extensions))            return fmt1;    }    return NULL;}/** * Read an image from a stream.  * @param gb byte stream containing the image * @param fmt image format, NULL if probing is required */int av_read_image(ByteIOContext *pb, const char *filename,                  AVImageFormat *fmt,                  int (*alloc_cb)(void *, AVImageInfo *info), void *opaque){    char buf[PROBE_BUF_SIZE];    AVProbeData probe_data, *pd = &probe_data;    offset_t pos;    int ret;    if (!fmt) {        pd->filename = filename;        pd->buf = buf;        pos = url_ftell(pb);        pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);        url_fseek(pb, pos, SEEK_SET);        fmt = av_probe_image_format(pd);    }    if (!fmt)        return AVERROR_NOFMT;    ret = fmt->img_read(pb, alloc_cb, opaque);    return ret;}/** * Write an image to a stream. * @param pb byte stream for the image output * @param fmt image format * @param img image data and informations */int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img){    return fmt->img_write(pb, img);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -