Ignore:
Timestamp:
Jan 20, 2007 5:18:14 AM (14 years ago)
Author:
bennylp
Message:

Implement ticket #56: Periodically transmit RTP packet on silence, to maintain NAT binding etc.

File:
1 edited

Legend:

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

    r874 r888  
    562562 
    563563    } else if (frame->type != PJMEDIA_FRAME_TYPE_NONE) { 
    564         unsigned ts; 
     564        unsigned ts, codec_samples_per_frame; 
    565565 
    566566        /* Repeatedly call encode if there are multiple frames to be 
    567567         * sent. 
    568568         */ 
    569  
    570         for (ts=0; ts<ts_len; ts += samples_per_frame) { 
     569        codec_samples_per_frame = stream->codec_param.info.enc_ptime * 
     570                                  stream->codec_param.info.clock_rate / 
     571                                  1000; 
     572        if (codec_samples_per_frame == 0) { 
     573            codec_samples_per_frame = stream->codec_param.info.frm_ptime * 
     574                                      stream->codec_param.info.clock_rate / 
     575                                      1000; 
     576        } 
     577 
     578        for (ts=0; ts<ts_len; ts += codec_samples_per_frame) { 
    571579            pjmedia_frame tmp_out_frame, tmp_in_frame; 
    572580            unsigned bytes_per_sample, max_size; 
     
    576584 
    577585            /* Split original PCM input frame into base frame size */ 
     586            tmp_in_frame.timestamp.u64 = frame->timestamp.u64 + ts; 
    578587            tmp_in_frame.buf = ((char*)frame->buf) + ts * bytes_per_sample; 
    579             tmp_in_frame.size = samples_per_frame * bytes_per_sample; 
     588            tmp_in_frame.size = codec_samples_per_frame * bytes_per_sample; 
    580589            tmp_in_frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 
    581590 
     
    690699{ 
    691700    pjmedia_stream *stream = port->port_data.pdata; 
    692     pjmedia_frame tmp_in_frame; 
     701    pjmedia_frame tmp_zero_frame; 
    693702    unsigned samples_per_frame; 
    694703 
    695704    samples_per_frame = stream->enc_samples_per_frame; 
     705 
     706    /* http://www.pjsip.org/trac/ticket/56: 
     707     *  when input is PJMEDIA_FRAME_TYPE_NONE, feed zero PCM frame 
     708     *  instead so that encoder can decide whether or not to transmit 
     709     *  silence frame. 
     710     */ 
     711    if (frame->type == PJMEDIA_FRAME_TYPE_NONE && 
     712        samples_per_frame <= ZERO_PCM_MAX_SIZE)  
     713    { 
     714        pj_memcpy(&tmp_zero_frame, frame, sizeof(pjmedia_frame)); 
     715        frame = &tmp_zero_frame; 
     716 
     717        tmp_zero_frame.buf = zero_frame; 
     718        tmp_zero_frame.size = samples_per_frame * 2; 
     719        tmp_zero_frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 
     720    } 
     721 
     722#if 0 
     723    // This is no longer needed because each TYPE_NONE frame will 
     724    // be converted into zero frame above 
    696725 
    697726    /* If VAD is temporarily disabled during creation, feed zero PCM frame 
     
    710739        tmp_in_frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 
    711740    } 
     741#endif 
    712742 
    713743    /* If VAD is temporarily disabled during creation, enable it 
Note: See TracChangeset for help on using the changeset viewer.