Example #1
0
void media::thread::run(void)
{
    fd_set session;
    socket_t max;

    shell::log(DEBUG1, "starting media thread");
    running = true;
    socket_t so;
    media::proxy *mp;
    time_t now;

    while(running) {
        lock.acquire();
        max = hiwater;
        memcpy(&session, &connections, sizeof(session));
        lock.release();
        select(max, &session, NULL, NULL, NULL);
        if(!running)
            break;

        time(&now);
        for(so = 0; so < max; ++so) {
#ifdef  _MSWINDOWS_
#else
            char buf[1];
            if(so == control[0] && FD_ISSET(so, &session)) {
                if(::read(so, buf, 1) < 1)
                    shell::log(shell::ERR, "media control failure");
                continue;
            }
#endif
            mp = NULL;
            if(!FD_ISSET(so, &session))
                continue;

            lock.acquire();
            mp = proxymap[so];
            if(mp->so == INVALID_SOCKET) {
                proxymap[so] = NULL;
                mp = NULL;
            }

            if(mp && mp->expires && mp->expires < now)
                mp->release(0);
            else if(mp)
                mp->copy();

            lock.release();
        }
    }

    shell::log(DEBUG1, "stopping media thread");
    running = true;
}
Example #2
0
void media::release(LinkedObject **nat, unsigned expires)
{
    assert(nat != NULL);

    proxy *member;
    time_t expire = 0;

    if(!*nat)
        return;

    if(expires) {
        time(&expire);
        expire += expires;
    }

    lock.acquire();
    linked_pointer<proxy> pp = *nat;
    while(is(pp)) {
        member = *pp;
        pp.next();
        member->release(expires);
        member->enlist(&runlist);
    }
    lock.release();

    *nat = NULL;
}
Example #3
0
void media::sdp::check_media(char *buffer, size_t len)
{
    char *cp, *ep, *sp;
    char tmp[128];
    char mtype[32];
    unsigned tport;
    unsigned count = 1;
    media::proxy *pp;

    if(strnicmp(buffer, "m=", 2))
        return;

    cp = sp = strchr(buffer, ' ');
    if(!cp)
        return;

    while(isspace(*cp))
        ++cp;

    tport = atoi(cp);
    if(!tport)
        return;

    ep = strchr(cp, '/');
    if(ep)
        count = atoi(ep + 1);

    // at the moment we can only do rtp/rtcp pairs...
    if(count > 2) {
        result = NULL;
        return;
    }

    mediacount = count;
    count = align(count);

    ep = strchr(cp, ' ');
    if(!ep)
        ep = (char *)"";
    else while(isspace(*ep))
            ++ep;

    mediaport = tport;
    mediacount = count;
    tport = 0;

    lock.acquire();
    String::set(tmp, sizeof(tmp), ep);
    while(count--) {
        pp = media::get(this);
        if(!pp) {
            result = NULL;
            lock.release();
            return;
        }
        if(!tport)
            tport = (pp->port / 2) * 2;
    }
    lock.release();

    *sp = 0;
    String::set(mtype, sizeof(mtype), buffer);
    if(mediacount > 1)
        snprintf(buffer, len, "%s %u/%u %s",
                 mtype, tport, mediacount, tmp);
    else
        snprintf(buffer, len, "%s %u %s",
                 mtype, tport, tmp);

    mediacount = align(mediacount);
}