Changeset 4782

Show
Ignore:
Timestamp:
04/27/10 16:38:33 (4 years ago)
Author:
soohyunc
Message:

added a mechanism to adjust "quantizer":

as long as cwnd allows:
decrease quantizer to increase encoding bit rate when tx queue is small
increase quantizer to decrease encoding bit rate as tx queue fills

this, however, doesn't solve the tx queue fluctuating feature: tx queue will
fluctuate in anyway (fills up and drains repeatedly).

the point here is that we get a lot better video quality with this mechanism.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vic/branches/cc/codec/encoder-h261.cpp

    r4760 r4782  
    142142        // should we suspend grabbing? 
    143143        virtual bool suspend_grabbing(int m); 
     144        // adjust quantizer 
     145        void adjust_quantizer(int txq, int avg); 
    144146 
    145147    protected: 
     
    227229        fprintf(stderr, "\tnow: %f\tppframe[%d]: %d\n", 
    228230        get_now(), vfno_%FHSIZE, ppframe_[vfno_%FHSIZE]); 
     231        } 
     232        // print setq time 
     233        inline void print_time_setq(int quant, double time) { 
     234        fprintf(stderr, "now: %f duration: %f quant: %d\n",  
     235        get_now(), get_now() - time, quant); 
    229236        } 
    230237 
     
    889896        // ---------------------------------------------------------------* 
    890897 
     898        // adjust quantizer 
     899        adjust_quantizer(txq_beg_, avg_packets_per_frame()); 
     900 
    891901        // increment frame number 
    892902        if (vfno_++%FHSIZE == 0)  
     
    914924        return(cc); 
    915925} 
    916                  
     926 
     927/* 
     928 * adjust quantizer depending on the current tx queue size by comparing the 
     929 * average number of packets per frame 
     930 * @txq: tx queue size 
     931 * @avg: average number of packets per frame  
     932 *       (most recent 10 frames only) 
     933 */ 
     934void 
     935H261Encoder::adjust_quantizer(int txq, int avg)  
     936{ 
     937        double time = get_now(); 
     938 
     939        if (txq < avg) { 
     940                quantizer_ = (--quantizer_ < 3) ? 3 : quantizer_; 
     941                setq(quantizer_); 
     942                //print_time_setq(quantizer_, time); 
     943        } 
     944        else if (txq >= avg && txq < 3.5 * avg) { 
     945                quantizer_++; 
     946                setq(quantizer_); 
     947                //print_time_setq(quantizer_, time); 
     948        } 
     949        else { 
     950                quantizer_ += 2; 
     951                setq(quantizer_); 
     952                //print_time_setq(quantizer_, time); 
     953        } 
     954} 
    917955 
    918956int