23 |
* |
* |
24 |
* History: |
* History: |
25 |
* |
* |
26 |
|
* 07.04.2002 added max bitrate constraint, overflow controls (foxer) |
27 |
* 31.03.2002 inital version; |
* 31.03.2002 inital version; |
28 |
* |
* |
29 |
*************************************************************************/ |
*************************************************************************/ |
701 |
int bytes1, bytes2; |
int bytes1, bytes2; |
702 |
int overflow; |
int overflow; |
703 |
int credits_pos; |
int credits_pos; |
704 |
|
int capped_to_max_framesize = 0; |
705 |
|
|
706 |
if (codec->framenum == 0) |
if (codec->framenum == 0) |
707 |
{ |
{ |
932 |
} |
} |
933 |
|
|
934 |
// Foxer: make sure overflow doesn't run away |
// Foxer: make sure overflow doesn't run away |
935 |
if (overflow > bytes2 * 6 / 10) |
if (overflow > bytes2 * codec->config.twopass_max_overflow_improvement / 100) |
936 |
{ |
{ |
937 |
bytes2 += (overflow <= bytes2) ? bytes2 * 6 / 10 : overflow * 6 / 10; |
bytes2 += (overflow <= bytes2) ? bytes2 * codec->config.twopass_max_overflow_improvement / 100 : |
938 |
|
overflow * codec->config.twopass_max_overflow_improvement / 100; |
939 |
} |
} |
940 |
else if (overflow < bytes2 * -6 / 10) |
else if (overflow < bytes2 * codec->config.twopass_max_overflow_degradation / -100) |
941 |
{ |
{ |
942 |
bytes2 += bytes2 * -6 / 10; |
bytes2 += bytes2 * codec->config.twopass_max_overflow_degradation / -100; |
943 |
} |
} |
944 |
else |
else |
945 |
{ |
{ |
946 |
bytes2 += overflow; |
bytes2 += overflow; |
947 |
} |
} |
948 |
|
|
949 |
|
if (bytes2 > twopass->max_framesize) |
950 |
|
{ |
951 |
|
capped_to_max_framesize = 1; |
952 |
|
bytes2 = twopass->max_framesize; |
953 |
|
} |
954 |
|
|
955 |
if (bytes2 < 1) |
if (bytes2 < 1) |
956 |
{ |
{ |
957 |
bytes2 = 1; |
bytes2 = 1; |
1015 |
} |
} |
1016 |
|
|
1017 |
// subsequent frame quants can only be +- 2 |
// subsequent frame quants can only be +- 2 |
1018 |
if (last_quant) |
if (last_quant && capped_to_max_framesize == 0) |
1019 |
{ |
{ |
1020 |
if (frame->quant > last_quant + 2) |
if (frame->quant > last_quant + 2) |
1021 |
{ |
{ |
1030 |
} |
} |
1031 |
} |
} |
1032 |
|
|
1033 |
|
if (capped_to_max_framesize == 0) |
1034 |
last_quant = frame->quant; |
last_quant = frame->quant; |
1035 |
|
|
1036 |
if (codec->config.quant_type == QUANT_MODE_MOD) |
if (codec->config.quant_type == QUANT_MODE_MOD) |