Skip to content
Snippets Groups Projects
utils.c 92.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • Fabrice Bellard's avatar
    Fabrice Bellard committed
            p = url;
        } else {
    
            char *at,*slash; // PETR: position of '@' character and '/' character
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            p++;
            if (*p == '/')
                p++;
            if (*p == '/')
                p++;
    
            at = strchr(p,'@'); // PETR: get the position of '@'
            slash = strchr(p,'/');  // PETR: get position of '/' - end of hostname
            if (at && slash && at > slash) at = NULL; // PETR: not interested in '@' behind '/'
    
            q = at ? authorization : hostname;  // PETR: if '@' exists starting with auth.
    
             while ((at || *p != ':') && *p != '/' && *p != '?' && *p != '\0') { // PETR:
                if (*p == '@') {    // PETR: passed '@'
                  if (authorization_size > 0)
                      *q = '\0';
                  q = hostname;
                  at = NULL;
                } else if (!at) {   // PETR: hostname
                  if ((q - hostname) < hostname_size - 1)
                      *q++ = *p;
                } else {
                  if ((q - authorization) < authorization_size - 1)
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                    *q++ = *p;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                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);
    }
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    /**
    
     * @param s stream
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
     * @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)
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
     * @param pts_den denominator to convert to seconds (MPEG: 90000)
     */
    
    void av_set_pts_info(AVStream *s, int pts_wrap_bits,
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                         int pts_num, int pts_den)
    {
        s->pts_wrap_bits = pts_wrap_bits;
    
        s->time_base.num = pts_num;
        s->time_base.den = pts_den;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    }
    
    /* fraction handling */
    
    /**
    
     * f = val + (num / den) + 0.5.
     *
     * 'num' is normalized so that it is such as 0 <= num < den.
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
     *
     * @param f fractional number
     * @param val integer value
     * @param num must be >= 0
    
     * @param den must be >= 1
    
    static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    {
        num += (den >> 1);
        if (num >= den) {
            val += num / den;
            num = num % den;
        }
        f->val = val;
        f->num = num;
        f->den = den;
    }
    
    
    static void av_frac_set(AVFrac *f, int64_t val)
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    {
        f->val = val;
        f->num = f->den >> 1;
    }
    
    /**
    
     * Fractionnal addition to f: f = f + (incr / f->den).
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
     *
     * @param f fractional number
     * @param incr increment, can be positive or negative
     */
    
    static void av_frac_add(AVFrac *f, int64_t incr)
    
        int64_t num, den;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
        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;
    }