Changeset 4043


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).

Location:
pjproject/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/vid_stream.h

    r4012 r4043  
    7272 * #pjmedia_vid stream_info from local and remote SDP session descriptors. 
    7373 */ 
     74 
     75 
     76/** 
     77 * Enumeration of video stream sending rate control. 
     78 */ 
     79typedef enum pjmedia_vid_stream_rc_method 
     80{ 
     81    /** 
     82     * No sending rate control. All outgoing RTP packets will be transmitted 
     83     * immediately right after encoding process is done. 
     84     */ 
     85    PJMEDIA_VID_STREAM_RC_NONE              = 0, 
     86 
     87    /** 
     88     * Simple blocking. Each outgoing RTP packet transmission may be delayed 
     89     * to avoid peak bandwidth that is much higher than specified. The thread 
     90     * invoking the video stream put_frame(), e.g: video capture device thread, 
     91     * will be blocked whenever transmission delay takes place. 
     92     */ 
     93    PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING   = 1 
     94 
     95} pjmedia_vid_stream_rc_method; 
     96 
     97 
     98/** 
     99 * Structure of configuration settings for video stream sending rate control. 
     100 */ 
     101typedef struct pjmedia_vid_stream_rc_config 
     102{ 
     103    /** 
     104     * Rate control method. 
     105     * 
     106     * Default: PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING. 
     107     */ 
     108    pjmedia_vid_stream_rc_method    method; 
     109 
     110    /** 
     111     * Upstream/outgoing bandwidth. If this is set to zero, the video stream 
     112     * will use codec maximum bitrate setting. 
     113     * 
     114     * Default: 0 (follow codec maximum bitrate). 
     115     */ 
     116    unsigned                        bandwidth; 
     117 
     118} pjmedia_vid_stream_rc_config; 
    74119 
    75120 
     
    118163                                    /**< Disable automatic sending of RTCP 
    119164                                         SDES and BYE.                      */ 
     165 
     166    pjmedia_vid_stream_rc_config rc_cfg; 
     167                                    /**< Stream send rate control settings. */ 
    120168} pjmedia_vid_stream_info; 
    121169 
     
    144192                                 const pjmedia_sdp_session *remote, 
    145193                                 unsigned stream_idx); 
     194 
     195 
     196/** 
     197 * Initialize the video stream rate control with default settings. 
     198 * 
     199 * @param cfg           Video stream rate control structure to be initialized. 
     200 */ 
     201PJ_DECL(void) 
     202pjmedia_vid_stream_rc_config_default(pjmedia_vid_stream_rc_config *cfg); 
    146203 
    147204 
  • 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 */ 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r4016 r4043  
    28832883 
    28842884    /** 
     2885     * Specify the send rate control for video stream. 
     2886     * 
     2887     * Default: see #pjmedia_vid_stream_rc_config 
     2888     */ 
     2889    pjmedia_vid_stream_rc_config vid_stream_rc_cfg; 
     2890 
     2891    /** 
    28852892     * Media transport config. 
    28862893     */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r4001 r4043  
    219219    cfg->vid_cap_dev = PJMEDIA_VID_DEFAULT_CAPTURE_DEV; 
    220220    cfg->vid_rend_dev = PJMEDIA_VID_DEFAULT_RENDER_DEV; 
     221    pjmedia_vid_stream_rc_config_default(&cfg->vid_stream_rc_cfg); 
    221222    pjsua_transport_config_default(&cfg->rtp_cfg); 
    222223    cfg->use_srtp = pjsua_var.ua_cfg.use_srtp; 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c

    r4028 r4043  
    747747        si->rtp_seq = call_med->rtp_tx_seq; 
    748748        si->rtp_seq_ts_set = call_med->rtp_tx_seq_ts_set; 
     749 
     750        /* Set rate control config from account setting */ 
     751        si->rc_cfg = acc->cfg.vid_stream_rc_cfg; 
    749752 
    750753#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0 
Note: See TracChangeset for help on using the changeset viewer.