--- plugin_single.c 2003/06/09 13:55:07 1.1.2.3 +++ plugin_single.c 2003/12/17 13:15:33 1.1.2.10 @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: plugin_single.c,v 1.1.2.3 2003/06/09 13:55:07 edgomez Exp $ + * $Id: plugin_single.c,v 1.1.2.10 2003/12/17 13:15:33 chl Exp $ * ****************************************************************************/ @@ -30,7 +30,7 @@ #include "../xvid.h" #include "../image/image.h" -#define DEFAULT_INITIAL_QUANTIZER 5 +#define DEFAULT_INITIAL_QUANTIZER 4 #define DEFAULT_BITRATE 900000 /* 900kbps */ #define DEFAULT_DELAY_FACTOR 16 @@ -54,7 +54,7 @@ double avg_framesize; double quant_error[31]; - double fq_error; + double fq_error; } rc_single_t; @@ -64,7 +64,7 @@ { #if defined(DEFAULT_INITIAL_QUANTIZER) - return (DEFAULT_INITIAL_QUANTIZER); + return (DEFAULT_INITIAL_QUANTIZER); #else int i; @@ -120,7 +120,7 @@ rc->sequence_quality = 2.0 / (double) rc->rtn_quant; rc->avg_framesize = rc->target_framesize; - rc->fq_error = 0; + rc->fq_error = 0; /* Bind the RC */ *handle = rc; @@ -147,15 +147,24 @@ rc_single_before(rc_single_t * rc, xvid_plg_data_t * data) { - if (data->quant <= 0) { - if (data->zone && data->zone->mode == XVID_ZONE_QUANT) { - rc->fq_error += (double)data->zone->increment / (double)data->zone->base; - data->quant = (int)rc->fq_error; - rc->fq_error -= data->quant; - }else { - data->quant = rc->rtn_quant; - } - } + if (data->quant <= 0) { + if (data->zone && data->zone->mode == XVID_ZONE_QUANT) { + rc->fq_error += (double)data->zone->increment / (double)data->zone->base; + data->quant = (int)rc->fq_error; + rc->fq_error -= data->quant; + } else { + int q = rc->rtn_quant; + /* limit to min/max range + we don't know frame type of the next frame, so we just use + P-VOP's range... */ + if (q > data->max_quant[XVID_TYPE_PVOP-1]) + q = data->max_quant[XVID_TYPE_PVOP-1]; + else if (q < data->min_quant[XVID_TYPE_PVOP-1]) + q = data->min_quant[XVID_TYPE_PVOP-1]; + + data->quant = q; + } + } return 0; } @@ -173,14 +182,18 @@ double base_quality; double target_quality; - /* Update internal values */ rc->time += (double) data->fincr / data->fbase; rc->total_size += data->length; + if(data->type == XVID_TYPE_BVOP) + return (0); + + rc->rtn_quant = data->quant; + /* Compute the deviation from expected total size */ - deviation = (int64_t) - ((double) rc->total_size - (double) rc->bytes_per_sec * rc->time); + deviation = + rc->total_size - rc->bytes_per_sec * rc->time; if (data->quant >= 2) { @@ -235,18 +248,12 @@ } } - /* prevent rapid quantization change */ + /* prevent rapid quantization change */ if (rtn_quant > data->quant + 1) rtn_quant = data->quant + 1; else if (rtn_quant < data->quant - 1) rtn_quant = data->quant - 1; - /* limit to min/max range */ - if (rtn_quant > data->max_quant[data->type-1]) - rtn_quant = data->max_quant[data->type-1]; - else if (rtn_quant < data->min_quant[data->type-1]) - rtn_quant = data->min_quant[data->type-1]; - rc->rtn_quant = rtn_quant; return (0); @@ -262,6 +269,7 @@ { switch (opt) { case XVID_PLG_INFO: + case XVID_PLG_FRAME : return 0; case XVID_PLG_CREATE: