Ignore:
Timestamp:
Apr 12, 2012 1:41:50 PM (12 years ago)
Author:
nanang
Message:

Re #1476: Initial version of send rate control in video stream, added simple blocking method (block application thread to make send delay when delay is needed).

File:
1 edited

Legend:

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

    r4022 r4043  
    154154 
    155155    pjmedia_vid_codec       *codec;         /**< Codec instance being used. */ 
    156     pj_uint32_t              last_dec_ts;    /**< Last decoded timestamp.   */ 
    157     int                      last_dec_seq;   /**< Last decoded sequence.    */ 
     156    pj_uint32_t              last_dec_ts;   /**< Last decoded timestamp.    */ 
     157    int                      last_dec_seq;  /**< Last decoded sequence.     */ 
     158 
     159 
     160    pj_timestamp             ts_freq;       /**< Timestamp frequency.       */ 
    158161}; 
    159162 
     
    769772    pj_size_t total_sent = 0; 
    770773    pjmedia_vid_encode_opt enc_opt; 
     774    unsigned pkt_cnt = 0; 
     775    pj_timestamp initial_time; 
    771776 
    772777#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA != 0 
     
    827832        return status; 
    828833    } 
     834     
     835    pj_get_timestamp(&initial_time); 
    829836 
    830837    /* Loop while we have frame to send */ 
     
    865872        pjmedia_rtcp_tx_rtp(&stream->rtcp, frame_out.size); 
    866873        total_sent += frame_out.size; 
     874        pkt_cnt++; 
    867875 
    868876        if (!has_more_data) 
     
    886894            break; 
    887895        } 
    888     } 
     896 
     897        /* Send rate control */ 
     898        if (stream->info.rc_cfg.method==PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING) 
     899        { 
     900            pj_timestamp now, next_send_ts, total_send_ts; 
     901 
     902            total_send_ts.u64 = total_sent * stream->ts_freq.u64 * 8 / 
     903                                stream->info.rc_cfg.bandwidth; 
     904            next_send_ts = initial_time; 
     905            pj_add_timestamp(&next_send_ts, &total_send_ts); 
     906 
     907            pj_get_timestamp(&now); 
     908            if (pj_cmp_timestamp(&now, &next_send_ts) < 0) { 
     909                unsigned ms_sleep; 
     910                ms_sleep = pj_elapsed_msec(&now, &next_send_ts); 
     911 
     912                if (ms_sleep > 10) 
     913                    ms_sleep = 10; 
     914 
     915                pj_thread_sleep(ms_sleep); 
     916            } 
     917        } 
     918    } 
     919 
     920#if 0 
     921    /* Trace log for rate control */ 
     922    { 
     923        pj_timestamp end_time; 
     924        pj_get_timestamp(&end_time); 
     925        PJ_LOG(5, (stream->name.ptr, "total pkt=%d size=%d sleep=%d", 
     926                   pkt_cnt, total_sent, 
     927                   pj_elapsed_msec(&initial_time, &end_time))); 
     928    } 
     929#endif 
    889930 
    890931    /* Check if now is the time to transmit RTCP SR/RR report.  
     
    14141455                           vfd_enc->fps.denum / vfd_enc->fps.num; 
    14151456 
     1457    /* Initialize send rate states */ 
     1458    pj_get_timestamp_freq(&stream->ts_freq); 
     1459    if (info->rc_cfg.bandwidth == 0) 
     1460        info->rc_cfg.bandwidth = vfd_enc->max_bps * 150 / 100; 
     1461 
    14161462    /* Override the initial framerate in the decoding direction. This initial 
    14171463     * value will be used by the renderer to configure its clock, and setting 
     
    18681914 
    18691915 
     1916/* 
     1917 * Initialize the video stream rate control with default settings. 
     1918 */ 
     1919PJ_DEF(void) 
     1920pjmedia_vid_stream_rc_config_default(pjmedia_vid_stream_rc_config *cfg) 
     1921{ 
     1922    pj_bzero(cfg, sizeof(*cfg)); 
     1923    cfg->method = PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING; 
     1924} 
     1925 
     1926 
    18701927#endif /* PJMEDIA_HAS_VIDEO */ 
Note: See TracChangeset for help on using the changeset viewer.