Changeset 1839


Ignore:
Timestamp:
Mar 3, 2008 1:25:17 PM (16 years ago)
Author:
bennylp
Message:

Ticket #499: NULL frame transmission in conference bridge is not clocked at the right interval

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/conference.c

    r1833 r1839  
    180180    unsigned             tx_buf_count;  /**< # of samples in the buffer.    */ 
    181181 
     182    /* When the port is not receiving signal from any other ports (e.g. when 
     183     * no other ports is transmitting to this port), the bridge periodically 
     184     * transmit NULL frame to the port to keep the port "alive" (for example, 
     185     * a stream port needs this heart-beat to periodically transmit silence 
     186     * frame to keep NAT binding alive). 
     187     * 
     188     * This NULL frame should be sent to the port at the port's ptime rate. 
     189     * So if the port's ptime is greater than the bridge's ptime, the bridge 
     190     * needs to delay the NULL frame until it's the right time to do so. 
     191     * 
     192     * This variable keeps track of how many pending NULL samples are being 
     193     * "held" for this port. Once this value reaches samples_per_frame 
     194     * value of the port, a NULL frame is sent. The samples value on this 
     195     * variable is clocked at the port's clock rate. 
     196     */ 
     197    unsigned             tx_heart_beat; 
     198 
    182199    /* Delay buffer is a special buffer for sound device port (port 0, master 
    183200     * port) and other passive ports (sound device port is also passive port). 
     
    13891406        pjmedia_frame frame; 
    13901407 
    1391         /* Adjust the timestamp */ 
     1408        /* Clear left-over samples in tx_buffer, if any, so that it won't 
     1409         * be transmitted next time we have audio signal. 
     1410         */ 
     1411        cport->tx_buf_count = 0; 
     1412 
     1413        /* Add sample counts to heart-beat samples */ 
     1414        cport->tx_heart_beat += conf->samples_per_frame * cport->clock_rate / 
     1415                                conf->clock_rate; 
     1416 
     1417        /* Set frame timestamp */ 
    13921418        frame.timestamp.u64 = timestamp->u64 * cport->clock_rate / 
    13931419                                conf->clock_rate; 
     
    13961422        frame.size = 0; 
    13971423 
     1424        /* Transmit heart-beat frames (may transmit more than one NULL frame 
     1425         * if port's ptime is less than bridge's ptime. 
     1426         */ 
    13981427        if (cport->port && cport->port->put_frame) { 
    1399             pjmedia_port_put_frame(cport->port, &frame); 
     1428            while (cport->tx_heart_beat >= cport->samples_per_frame) { 
     1429 
     1430                pjmedia_port_put_frame(cport->port, &frame); 
     1431 
     1432                cport->tx_heart_beat -= cport->samples_per_frame; 
     1433                frame.timestamp.u64 += cport->samples_per_frame; 
     1434            } 
    14001435        } 
    14011436 
     
    14091444        return PJ_SUCCESS; 
    14101445    } 
     1446 
     1447    /* Reset heart-beat sample count */ 
     1448    cport->tx_heart_beat = 0; 
    14111449 
    14121450    buf = (pj_int16_t*) cport->mix_buf; 
Note: See TracChangeset for help on using the changeset viewer.