[Sumover-dev] [svn commit] r4782 - vic/branches/cc/codec
sumover-dev at cs.ucl.ac.uk
sumover-dev at cs.ucl.ac.uk
Tue Apr 27 16:38:33 BST 2010
Author: soohyunc
Date: Tue Apr 27 16:38:33 2010
New Revision: 4782
Modified:
vic/branches/cc/codec/encoder-h261.cpp
Log:
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.
Modified: vic/branches/cc/codec/encoder-h261.cpp
==============================================================================
--- vic/branches/cc/codec/encoder-h261.cpp (original)
+++ vic/branches/cc/codec/encoder-h261.cpp Tue Apr 27 16:38:33 2010
@@ -141,6 +141,8 @@
// should we suspend grabbing?
virtual bool suspend_grabbing(int m);
+ // adjust quantizer
+ void adjust_quantizer(int txq, int avg);
protected:
H261Encoder(int ft);
@@ -227,6 +229,11 @@
fprintf(stderr, "\tnow: %f\tppframe[%d]: %d\n",
get_now(), vfno_%FHSIZE, ppframe_[vfno_%FHSIZE]);
}
+ // print setq time
+ inline void print_time_setq(int quant, double time) {
+ fprintf(stderr, "now: %f duration: %f quant: %d\n",
+ get_now(), get_now() - time, quant);
+ }
private:
};
@@ -888,6 +895,9 @@
}
// ---------------------------------------------------------------*
+ // adjust quantizer
+ adjust_quantizer(txq_beg_, avg_packets_per_frame());
+
// increment frame number
if (vfno_++%FHSIZE == 0)
init_ppframe();
@@ -913,7 +923,35 @@
return(cc);
}
-
+
+/*
+ * adjust quantizer depending on the current tx queue size by comparing the
+ * average number of packets per frame
+ * @txq: tx queue size
+ * @avg: average number of packets per frame
+ * (most recent 10 frames only)
+ */
+void
+H261Encoder::adjust_quantizer(int txq, int avg)
+{
+ double time = get_now();
+
+ if (txq < avg) {
+ quantizer_ = (--quantizer_ < 3) ? 3 : quantizer_;
+ setq(quantizer_);
+ //print_time_setq(quantizer_, time);
+ }
+ else if (txq >= avg && txq < 3.5 * avg) {
+ quantizer_++;
+ setq(quantizer_);
+ //print_time_setq(quantizer_, time);
+ }
+ else {
+ quantizer_ += 2;
+ setq(quantizer_);
+ //print_time_setq(quantizer_, time);
+ }
+}
int
H261Encoder::encode(const VideoFrame* vf, const u_int8_t *crvec)
More information about the Sumover-dev
mailing list