Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Xiph.Org
aom-rav1e
Commits
3cc5b92c
Commit
3cc5b92c
authored
Feb 24, 2012
by
Paul Wilkins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Further code simplification and clean up.
Change-Id: Ifdb17b56090a317b2aa82cf125d57934902c5298
parent
583f2d8f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
119 additions
and
599 deletions
+119
-599
vp8/common/onyx.h
vp8/common/onyx.h
+0
-5
vp8/encoder/firstpass.c
vp8/encoder/firstpass.c
+5
-163
vp8/encoder/onyx_if.c
vp8/encoder/onyx_if.c
+2
-120
vp8/encoder/onyx_int.h
vp8/encoder/onyx_int.h
+0
-2
vp8/encoder/ratectrl.c
vp8/encoder/ratectrl.c
+102
-263
vp8/encoder/rdopt.c
vp8/encoder/rdopt.c
+0
-7
vp8/vp8_cx_iface.c
vp8/vp8_cx_iface.c
+10
-39
No files found.
vp8/common/onyx.h
View file @
3cc5b92c
...
...
@@ -53,7 +53,6 @@ extern "C"
typedef
enum
{
MODE_REALTIME
=
0x0
,
MODE_GOODQUALITY
=
0x1
,
MODE_BESTQUALITY
=
0x2
,
MODE_FIRSTPASS
=
0x3
,
...
...
@@ -175,10 +174,6 @@ extern "C"
// these parameters aren't to be used in final build don't use!!!
int
play_alternate
;
int
alt_freq
;
int
alt_q
;
int
key_q
;
int
gold_q
;
int
multi_threaded
;
// how many threads to run the encoder on
int
token_partitions
;
// how many token partitions to create for multi core decoding
...
...
vp8/encoder/firstpass.c
View file @
3cc5b92c
...
...
@@ -349,33 +349,8 @@ static int frame_max_bits(VP8_COMP *cpi)
// Max allocation for a single frame based on the max section guidelines passed in and how many bits are left
int
max_bits
;
// For CBR we need to also consider buffer fullness.
// If we are running below the optimal level then we need to gradually tighten up on max_bits.
if
(
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
{
double
buffer_fullness_ratio
=
(
double
)
cpi
->
buffer_level
/
DOUBLE_DIVIDE_CHECK
((
double
)
cpi
->
oxcf
.
optimal_buffer_level
);
// For CBR base this on the target average bits per frame plus the maximum sedction rate passed in by the user
max_bits
=
(
int
)(
cpi
->
av_per_frame_bandwidth
*
((
double
)
cpi
->
oxcf
.
two_pass_vbrmax_section
/
100
.
0
));
// If our buffer is below the optimum level
if
(
buffer_fullness_ratio
<
1
.
0
)
{
// The lower of max_bits / 4 or cpi->av_per_frame_bandwidth / 4.
int
min_max_bits
=
((
cpi
->
av_per_frame_bandwidth
>>
2
)
<
(
max_bits
>>
2
))
?
cpi
->
av_per_frame_bandwidth
>>
2
:
max_bits
>>
2
;
max_bits
=
(
int
)(
max_bits
*
buffer_fullness_ratio
);
if
(
max_bits
<
min_max_bits
)
max_bits
=
min_max_bits
;
// Lowest value we will set ... which should allow the buffer to refil.
}
}
// VBR
else
{
// For VBR base this on the bits and frames left plus the two_pass_vbrmax_section rate passed in by the user
max_bits
=
(
int
)(((
double
)
cpi
->
twopass
.
bits_left
/
(
cpi
->
twopass
.
total_stats
->
count
-
(
double
)
cpi
->
common
.
current_video_frame
))
*
((
double
)
cpi
->
oxcf
.
two_pass_vbrmax_section
/
100
.
0
));
}
// For VBR base this on the bits and frames left plus the two_pass_vbrmax_section rate passed in by the user
max_bits
=
(
int
)(((
double
)
cpi
->
twopass
.
bits_left
/
(
cpi
->
twopass
.
total_stats
->
count
-
(
double
)
cpi
->
common
.
current_video_frame
))
*
((
double
)
cpi
->
oxcf
.
two_pass_vbrmax_section
/
100
.
0
));
// Trap case where we are out of bits
if
(
max_bits
<
0
)
...
...
@@ -1828,35 +1803,6 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
cpi
->
twopass
.
gf_decay_rate
=
(
i
>
0
)
?
(
int
)(
100
.
0
*
(
1
.
0
-
decay_accumulator
))
/
i
:
0
;
// When using CBR apply additional buffer related upper limits
if
(
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
{
double
max_boost
;
// For cbr apply buffer related limits
if
(
cpi
->
drop_frames_allowed
)
{
int
df_buffer_level
=
cpi
->
oxcf
.
drop_frames_water_mark
*
(
cpi
->
oxcf
.
optimal_buffer_level
/
100
);
if
(
cpi
->
buffer_level
>
df_buffer_level
)
max_boost
=
((
double
)((
cpi
->
buffer_level
-
df_buffer_level
)
*
2
/
3
)
*
16
.
0
)
/
DOUBLE_DIVIDE_CHECK
((
double
)
cpi
->
av_per_frame_bandwidth
);
else
max_boost
=
0
.
0
;
}
else
if
(
cpi
->
buffer_level
>
0
)
{
max_boost
=
((
double
)(
cpi
->
buffer_level
*
2
/
3
)
*
16
.
0
)
/
DOUBLE_DIVIDE_CHECK
((
double
)
cpi
->
av_per_frame_bandwidth
);
}
else
{
max_boost
=
0
.
0
;
}
if
(
boost_score
>
max_boost
)
boost_score
=
max_boost
;
}
// Dont allow conventional gf too near the next kf
if
((
cpi
->
twopass
.
frames_to_key
-
i
)
<
MIN_GF_INTERVAL
)
{
...
...
@@ -2175,13 +2121,6 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
}
}
// Apply an additional limit for CBR
if
(
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
{
if
(
cpi
->
twopass
.
gf_bits
>
(
cpi
->
buffer_level
>>
1
))
cpi
->
twopass
.
gf_bits
=
cpi
->
buffer_level
>>
1
;
}
// Dont allow a negative value for gf_bits
if
(
gf_bits
<
0
)
gf_bits
=
0
;
...
...
@@ -2839,51 +2778,6 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
max_grp_bits
=
(
int64_t
)
max_bits
*
(
int64_t
)
cpi
->
twopass
.
frames_to_key
;
if
(
cpi
->
twopass
.
kf_group_bits
>
max_grp_bits
)
cpi
->
twopass
.
kf_group_bits
=
max_grp_bits
;
// Additional special case for CBR if buffer is getting full.
if
(
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
{
int
opt_buffer_lvl
=
cpi
->
oxcf
.
optimal_buffer_level
;
int
buffer_lvl
=
cpi
->
buffer_level
;
// If the buffer is near or above the optimal and this kf group is
// not being allocated much then increase the allocation a bit.
if
(
buffer_lvl
>=
opt_buffer_lvl
)
{
int
high_water_mark
=
(
opt_buffer_lvl
+
cpi
->
oxcf
.
maximum_buffer_size
)
>>
1
;
int64_t
av_group_bits
;
// Av bits per frame * number of frames
av_group_bits
=
(
int64_t
)
cpi
->
av_per_frame_bandwidth
*
(
int64_t
)
cpi
->
twopass
.
frames_to_key
;
// We are at or above the maximum.
if
(
cpi
->
buffer_level
>=
high_water_mark
)
{
int64_t
min_group_bits
;
min_group_bits
=
av_group_bits
+
(
int64_t
)(
buffer_lvl
-
high_water_mark
);
if
(
cpi
->
twopass
.
kf_group_bits
<
min_group_bits
)
cpi
->
twopass
.
kf_group_bits
=
min_group_bits
;
}
// We are above optimal but below the maximum
else
if
(
cpi
->
twopass
.
kf_group_bits
<
av_group_bits
)
{
int64_t
bits_below_av
=
av_group_bits
-
cpi
->
twopass
.
kf_group_bits
;
cpi
->
twopass
.
kf_group_bits
+=
(
int64_t
)((
double
)
bits_below_av
*
(
double
)(
buffer_lvl
-
opt_buffer_lvl
)
/
(
double
)(
high_water_mark
-
opt_buffer_lvl
));
}
}
}
}
else
cpi
->
twopass
.
kf_group_bits
=
0
;
...
...
@@ -2963,33 +2857,6 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
// cpi->twopass.section_max_qfactor = 1.0;
}
// When using CBR apply additional buffer fullness related upper limits
if
(
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
{
double
max_boost
;
if
(
cpi
->
drop_frames_allowed
)
{
int
df_buffer_level
=
cpi
->
oxcf
.
drop_frames_water_mark
*
(
cpi
->
oxcf
.
optimal_buffer_level
/
100
);
if
(
cpi
->
buffer_level
>
df_buffer_level
)
max_boost
=
((
double
)((
cpi
->
buffer_level
-
df_buffer_level
)
*
2
/
3
)
*
16
.
0
)
/
DOUBLE_DIVIDE_CHECK
((
double
)
cpi
->
av_per_frame_bandwidth
);
else
max_boost
=
0
.
0
;
}
else
if
(
cpi
->
buffer_level
>
0
)
{
max_boost
=
((
double
)(
cpi
->
buffer_level
*
2
/
3
)
*
16
.
0
)
/
DOUBLE_DIVIDE_CHECK
((
double
)
cpi
->
av_per_frame_bandwidth
);
}
else
{
max_boost
=
0
.
0
;
}
if
(
boost_score
>
max_boost
)
boost_score
=
max_boost
;
}
// Reset the first pass file position
reset_fpf_position
(
cpi
,
start_position
);
...
...
@@ -3065,13 +2932,6 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
// Calculate the number of bits to be spent on the key frame
cpi
->
twopass
.
kf_bits
=
(
int
)((
double
)
kf_boost
*
((
double
)
cpi
->
twopass
.
kf_group_bits
/
(
double
)
allocation_chunks
));
// Apply an additional limit for CBR
if
(
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
{
if
(
cpi
->
twopass
.
kf_bits
>
((
3
*
cpi
->
buffer_level
)
>>
2
))
cpi
->
twopass
.
kf_bits
=
(
3
*
cpi
->
buffer_level
)
>>
2
;
}
// If the key frame is actually easier than the average for the
// kf group (which does sometimes happen... eg a blank intro frame)
// Then use an alternate calculation based on the kf error score
...
...
@@ -3154,15 +3014,10 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
//if ( av_bits_per_frame < 0.0 )
// av_bits_per_frame = 0.0
// CBR... Use the clip average as the target for deciding resample
if
(
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
{
bits_per_frame
=
av_bits_per_frame
;
}
// In VBR we want to avoid downsampling in easy section unless we are under extreme pressure
// So use the larger of target bitrate for this sectoion or average bitrate for sequence
else
//else
// TBD deprecatae spatial resampling for experminetal
{
bits_per_frame
=
cpi
->
twopass
.
kf_group_bits
/
cpi
->
twopass
.
frames_to_key
;
// This accounts for how hard the section is...
...
...
@@ -3197,20 +3052,7 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
fclose
(
f
);
}
// The trigger for spatial resampling depends on the various parameters such as whether we are streaming (CBR) or VBR.
if
(
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
{
// Trigger resample if we are projected to fall below down sample level or
// resampled last time and are projected to remain below the up sample level
if
((
projected_buffer_level
<
(
cpi
->
oxcf
.
resample_down_water_mark
*
cpi
->
oxcf
.
optimal_buffer_level
/
100
))
||
(
last_kf_resampled
&&
(
projected_buffer_level
<
(
cpi
->
oxcf
.
resample_up_water_mark
*
cpi
->
oxcf
.
optimal_buffer_level
/
100
))))
//( ((cpi->buffer_level < (cpi->oxcf.resample_down_water_mark * cpi->oxcf.optimal_buffer_level / 100))) &&
// ((projected_buffer_level < (cpi->oxcf.resample_up_water_mark * cpi->oxcf.optimal_buffer_level / 100))) ))
resample_trigger
=
TRUE
;
else
resample_trigger
=
FALSE
;
}
else
// The trigger for spatial resampling depends on the various parameters.
{
int64_t
clip_bits
=
(
int64_t
)(
cpi
->
twopass
.
total_stats
->
count
*
cpi
->
oxcf
.
target_bandwidth
/
DOUBLE_DIVIDE_CHECK
((
double
)
cpi
->
oxcf
.
frame_rate
));
int64_t
over_spend
=
cpi
->
oxcf
.
starting_buffer_level
-
cpi
->
buffer_level
;
...
...
vp8/encoder/onyx_if.c
View file @
3cc5b92c
...
...
@@ -1231,8 +1231,6 @@ static void init_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
cpi
->
oxcf
=
*
oxcf
;
cpi
->
auto_gold
=
1
;
cpi
->
auto_adjust_gold_quantizer
=
1
;
cpi
->
goldfreq
=
7
;
cm
->
version
=
oxcf
->
Version
;
...
...
@@ -1320,37 +1318,11 @@ void vp8_change_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
break
;
}
cpi
->
oxcf
.
worst_allowed_q
=
q_trans
[
oxcf
->
worst_allowed_q
];
cpi
->
oxcf
.
best_allowed_q
=
q_trans
[
oxcf
->
best_allowed_q
];
cpi
->
oxcf
.
cq_level
=
q_trans
[
cpi
->
oxcf
.
cq_level
];
if
(
oxcf
->
fixed_q
>=
0
)
{
if
(
oxcf
->
worst_allowed_q
<
0
)
cpi
->
oxcf
.
fixed_q
=
q_trans
[
0
];
else
cpi
->
oxcf
.
fixed_q
=
q_trans
[
oxcf
->
worst_allowed_q
];
if
(
oxcf
->
alt_q
<
0
)
cpi
->
oxcf
.
alt_q
=
q_trans
[
0
];
else
cpi
->
oxcf
.
alt_q
=
q_trans
[
oxcf
->
alt_q
];
if
(
oxcf
->
key_q
<
0
)
cpi
->
oxcf
.
key_q
=
q_trans
[
0
];
else
cpi
->
oxcf
.
key_q
=
q_trans
[
oxcf
->
key_q
];
if
(
oxcf
->
gold_q
<
0
)
cpi
->
oxcf
.
gold_q
=
q_trans
[
0
];
else
cpi
->
oxcf
.
gold_q
=
q_trans
[
oxcf
->
gold_q
];
}
cpi
->
baseline_gf_interval
=
cpi
->
oxcf
.
alt_freq
?
cpi
->
oxcf
.
alt_freq
:
DEFAULT_GF_INTERVAL
;
cpi
->
baseline_gf_interval
=
DEFAULT_GF_INTERVAL
;
cpi
->
ref_frame_flags
=
VP8_ALT_FLAG
|
VP8_GOLD_FLAG
|
VP8_LAST_FLAG
;
...
...
@@ -2434,10 +2406,6 @@ static void update_alt_ref_frame_stats(VP8_COMP *cpi)
{
VP8_COMMON
*
cm
=
&
cpi
->
common
;
// Select an interval before next GF or altref
if
(
!
cpi
->
auto_gold
)
cpi
->
frames_till_gf_update_due
=
cpi
->
goldfreq
;
// Update data structure that monitors level of reference to last GF
vpx_memset
(
cpi
->
gf_active_flags
,
1
,
(
cm
->
mb_rows
*
cm
->
mb_cols
));
cpi
->
gf_active_count
=
cm
->
mb_rows
*
cm
->
mb_cols
;
...
...
@@ -2460,10 +2428,6 @@ static void update_golden_frame_stats(VP8_COMP *cpi)
// Update the Golden frame usage counts.
if
(
cm
->
refresh_golden_frame
)
{
// Select an interval before next GF
if
(
!
cpi
->
auto_gold
)
cpi
->
frames_till_gf_update_due
=
cpi
->
goldfreq
;
// Update data structure that monitors level of reference to last GF
vpx_memset
(
cpi
->
gf_active_flags
,
1
,
(
cm
->
mb_rows
*
cm
->
mb_cols
));
cpi
->
gf_active_count
=
cm
->
mb_rows
*
cm
->
mb_cols
;
...
...
@@ -3110,37 +3074,6 @@ static void encode_frame_to_data_rate
return
;
}
// Reduce active_worst_allowed_q for CBR if our buffer is getting too full.
// This has a knock on effect on active best quality as well.
// For CBR if the buffer reaches its maximum level then we can no longer
// save up bits for later frames so we might as well use them up
// on the current frame.
if
((
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
&&
(
cpi
->
buffer_level
>=
cpi
->
oxcf
.
optimal_buffer_level
)
&&
cpi
->
buffered_mode
)
{
int
Adjustment
=
cpi
->
active_worst_quality
/
4
;
// Max adjustment is 1/4
if
(
Adjustment
)
{
int
buff_lvl_step
;
if
(
cpi
->
buffer_level
<
cpi
->
oxcf
.
maximum_buffer_size
)
{
buff_lvl_step
=
(
cpi
->
oxcf
.
maximum_buffer_size
-
cpi
->
oxcf
.
optimal_buffer_level
)
/
Adjustment
;
if
(
buff_lvl_step
)
Adjustment
=
(
cpi
->
buffer_level
-
cpi
->
oxcf
.
optimal_buffer_level
)
/
buff_lvl_step
;
else
Adjustment
=
0
;
}
cpi
->
active_worst_quality
-=
Adjustment
;
if
(
cpi
->
active_worst_quality
<
cpi
->
active_best_quality
)
cpi
->
active_worst_quality
=
cpi
->
active_best_quality
;
}
}
vp8_clear_system_state
();
// Set an active best quality and if necessary active worst quality
...
...
@@ -3221,24 +3154,6 @@ static void encode_frame_to_data_rate
}
}
// If CBR and the buffer is as full then it is reasonable to allow
// higher quality on the frames to prevent bits just going to waste.
if
(
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
{
// Note that the use of >= here elliminates the risk of a devide
// by 0 error in the else if clause
if
(
cpi
->
buffer_level
>=
cpi
->
oxcf
.
maximum_buffer_size
)
cpi
->
active_best_quality
=
cpi
->
best_quality
;
else
if
(
cpi
->
buffer_level
>
cpi
->
oxcf
.
optimal_buffer_level
)
{
int
Fraction
=
((
cpi
->
buffer_level
-
cpi
->
oxcf
.
optimal_buffer_level
)
*
128
)
/
(
cpi
->
oxcf
.
maximum_buffer_size
-
cpi
->
oxcf
.
optimal_buffer_level
);
int
min_qadjustment
=
((
cpi
->
active_best_quality
-
cpi
->
best_quality
)
*
Fraction
)
/
128
;
cpi
->
active_best_quality
-=
min_qadjustment
;
}
}
// Clip the active best and worst quality values to limits
if
(
cpi
->
active_worst_quality
>
cpi
->
worst_quality
)
cpi
->
active_worst_quality
=
cpi
->
worst_quality
;
...
...
@@ -3428,27 +3343,7 @@ static void encode_frame_to_data_rate
if
(
frame_over_shoot_limit
==
0
)
frame_over_shoot_limit
=
1
;
// Are we are overshooting and up against the limit of active max Q.
if
((
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
&&
(
Q
==
cpi
->
active_worst_quality
)
&&
(
cpi
->
active_worst_quality
<
cpi
->
worst_quality
)
&&
(
cpi
->
projected_frame_size
>
frame_over_shoot_limit
))
{
int
over_size_percent
=
((
cpi
->
projected_frame_size
-
frame_over_shoot_limit
)
*
100
)
/
frame_over_shoot_limit
;
// If so is there any scope for relaxing it
while
((
cpi
->
active_worst_quality
<
cpi
->
worst_quality
)
&&
(
over_size_percent
>
0
))
{
cpi
->
active_worst_quality
++
;
top_index
=
cpi
->
active_worst_quality
;
over_size_percent
=
(
int
)(
over_size_percent
*
0
.
96
);
// Assume 1 qstep = about 4% on frame size.
}
// If we have updated the active max Q do not call vp8_update_rate_correction_factors() this loop.
active_worst_qchanged
=
TRUE
;
}
else
active_worst_qchanged
=
FALSE
;
active_worst_qchanged
=
FALSE
;
// Special case handling for forced key frames
if
(
(
cm
->
frame_type
==
KEY_FRAME
)
&&
cpi
->
this_key_frame_forced
)
...
...
@@ -3804,19 +3699,6 @@ static void encode_frame_to_data_rate
cpi
->
ni_av_qi
=
(
cpi
->
ni_tot_qi
/
cpi
->
ni_frames
);
}
#if 0
// If the frame was massively oversize and we are below optimal buffer level drop next frame
if ((cpi->drop_frames_allowed) &&
(cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) &&
(cpi->buffer_level < cpi->oxcf.drop_frames_water_mark * cpi->oxcf.optimal_buffer_level / 100) &&
(cpi->projected_frame_size > (4 * cpi->this_frame_target)))
{
cpi->drop_frame = TRUE;
}
#endif
// Set the count for maximum consequative dropped frames based upon the ratio of
// this frame size to the target average per frame bandwidth.
// (cpi->av_per_frame_bandwidth > 0) is just a sanity check to prevent / 0.
...
...
vp8/encoder/onyx_int.h
View file @
3cc5b92c
...
...
@@ -486,8 +486,6 @@ typedef struct VP8_COMP
int
compressor_speed
;
int
interquantizer
;
int
auto_gold
;
int
auto_adjust_gold_quantizer
;
int
goldfreq
;
int
auto_worst_q
;
int
cpu_used
;
...
...
vp8/encoder/ratectrl.c
View file @
3cc5b92c
...
...
@@ -232,12 +232,8 @@ void vp8_setup_key_frame(VP8_COMP *cpi)
//cpi->common.filter_level = 0; // Reset every key frame.
cpi
->
common
.
filter_level
=
cpi
->
common
.
base_qindex
*
3
/
8
;
// Provisional interval before next GF
if
(
cpi
->
auto_gold
)
//cpi->frames_till_gf_update_due = DEFAULT_GF_INTERVAL;
cpi
->
frames_till_gf_update_due
=
cpi
->
baseline_gf_interval
;
else
cpi
->
frames_till_gf_update_due
=
cpi
->
goldfreq
;
// interval before next GF
cpi
->
frames_till_gf_update_due
=
cpi
->
baseline_gf_interval
;
cpi
->
common
.
refresh_golden_frame
=
TRUE
;
cpi
->
common
.
refresh_alt_ref_frame
=
TRUE
;
...
...
@@ -308,18 +304,8 @@ static void calc_iframe_target_size(VP8_COMP *cpi)
// Clear down mmx registers to allow floating point in what follows
vp8_clear_system_state
();
//__asm emms;
if
(
cpi
->
oxcf
.
fixed_q
>=
0
)
{
int
Q
=
cpi
->
oxcf
.
key_q
;
target
=
estimate_bits_at_q
(
INTRA_FRAME
,
Q
,
cpi
->
common
.
MBs
,
cpi
->
key_frame_rate_correction_factor
);
}
else
{
// New Two pass RC
target
=
cpi
->
per_frame_bandwidth
;
}
// New Two pass RC
target
=
cpi
->
per_frame_bandwidth
;
if
(
cpi
->
oxcf
.
rc_max_intra_bitrate_pct
)
{
...
...
@@ -337,29 +323,11 @@ static void calc_iframe_target_size(VP8_COMP *cpi)
// Do the best we can to define the parameteres for the next GF based
// on what information we have available.
// In this experimental code only two pass is supported.
//
// In this experimental code only two pass is supported
// so we just use the interval determined in the two pass code.
static
void
calc_gf_params
(
VP8_COMP
*
cpi
)
{
int
Q
=
(
cpi
->
oxcf
.
fixed_q
<
0
)
?
cpi
->
last_q
[
INTER_FRAME
]
:
cpi
->
oxcf
.
fixed_q
;
int
Boost
=
0
;
int
gf_frame_useage
=
0
;
// Golden frame useage since last GF
int
tot_mbs
=
cpi
->
recent_ref_frame_usage
[
INTRA_FRAME
]
+
cpi
->
recent_ref_frame_usage
[
LAST_FRAME
]
+
cpi
->
recent_ref_frame_usage
[
GOLDEN_FRAME
]
+
cpi
->
recent_ref_frame_usage
[
ALTREF_FRAME
];
int
pct_gf_active
=
(
100
*
cpi
->
gf_active_count
)
/
(
cpi
->
common
.
mb_rows
*
cpi
->
common
.
mb_cols
);
// Reset the last boost indicator
//cpi->last_boost = 100;
if
(
tot_mbs
)
gf_frame_useage
=
(
cpi
->
recent_ref_frame_usage
[
GOLDEN_FRAME
]
+
cpi
->
recent_ref_frame_usage
[
ALTREF_FRAME
])
*
100
/
tot_mbs
;
if
(
pct_gf_active
>
gf_frame_useage
)
gf_frame_useage
=
pct_gf_active
;
// Set the gf interval
cpi
->
frames_till_gf_update_due
=
cpi
->
baseline_gf_interval
;
}
...
...
@@ -404,112 +372,44 @@ static void calc_pframe_target_size(VP8_COMP *cpi)
// Note the baseline target data rate for this inter frame.
cpi
->
inter_frame_target
=
cpi
->
this_frame_target
;
// Test to see if we have to drop a frame
// The auto-drop frame code is only used in buffered mode.
// In unbufferd mode (eg vide conferencing) the descision to
// code or drop a frame is made outside the codec in response to real
// world comms or buffer considerations.
if
(
cpi
->
drop_frames_allowed
&&
cpi
->
buffered_mode
&&
(
cpi
->
oxcf
.
end_usage
==
USAGE_STREAM_FROM_SERVER
)
&&
((
cpi
->
common
.
frame_type
!=
KEY_FRAME
)))
//|| !cpi->oxcf.allow_spatial_resampling) )
{
// Check for a buffer underun-crisis in which case we have to drop a frame
if
((
cpi
->
buffer_level
<
0
))
{
#if 0
FILE *f = fopen("dec.stt", "a");
fprintf(f, "%10d %10d %10d %10d ***** BUFFER EMPTY\n",
(int) cpi->common.current_video_frame,
cpi->decimation_factor, cpi->common.horiz_scale,
(cpi->buffer_level * 100) / cpi->oxcf.optimal_buffer_level);
fclose(f);
#endif
//vpx_log("Decoder: Drop frame due to bandwidth: %d \n",cpi->buffer_level, cpi->av_per_frame_bandwidth);
cpi
->
drop_frame
=
TRUE
;
}
if
(
cpi
->
drop_frame
)
{
// Update the buffer level variable.
cpi
->
bits_off_target
+=
cpi
->
av_per_frame_bandwidth
;
// Clip the buffer level at the maximum buffer size
if
(
cpi
->
bits_off_target
>
cpi
->
oxcf
.
maximum_buffer_size
)
cpi
->
bits_off_target
=
cpi
->
oxcf
.
maximum_buffer_size
;
cpi
->
buffer_level
=
cpi
->
bits_off_target
;
}
else
cpi
->
drop_count
=
0
;
}
// Adjust target frame size for Golden Frames:
if
(
cpi
->
oxcf
.
error_resilient_mode
==
0
&&
(
cpi
->
frames_till_gf_update_due
==
0
)
&&
!
cpi
->
drop_frame
)
if
(
cpi
->
oxcf
.
error_resilient_mode
==
0
&&
(
cpi
->
frames_till_gf_update_due
==
0
)
)
{
//int Boost = 0;
int
Q
=
(
cpi
->
oxcf
.
fixed_q
<
0
)
?
cpi
->
last_q
[
INTER_FRAME
]
:
cpi
->
oxcf
.
fixed_q
;
int
gf_frame_useage
=
0
;
// Golden frame useage since last GF
int
tot_mbs
=
cpi
->
recent_ref_frame_usage
[
INTRA_FRAME
]
+
cpi
->
recent_ref_frame_usage
[
LAST_FRAME
]
+
cpi
->
recent_ref_frame_usage
[
GOLDEN_FRAME
]
+
cpi
->
recent_ref_frame_usage
[
ALTREF_FRAME
];
int
pct_gf_active
=
(
100
*
cpi
->
gf_active_count
)
/
(
cpi
->
common
.
mb_rows
*
cpi
->
common
.
mb_cols
);
cpi
->
common
.
refresh_golden_frame
=
TRUE
;
// Reset the last boost indicator
//cpi->last_boost = 100;
calc_gf_params
(
cpi
);
if
(
tot_mbs
)
gf_frame_useage
=
(
cpi
->
recent_ref_frame_usage
[
GOLDEN_FRAME
]
+
cpi
->
recent_ref_frame_usage
[
ALTREF_FRAME
])
*
100
/
tot_mbs
;
if
(
pct_gf_active
>
gf_frame_useage
)
gf_frame_useage
=
pct_gf_active
;
// Is a fixed manual GF frequency being used
if
(
cpi
->
auto_gold
)
// If we are using alternate ref instead of gf then do not apply the boost
// It will instead be applied to the altref update
// Jims modified boost
if
(
!
cpi
->
source_alt_ref_active
)
{
cpi
->
common
.
refresh_golden_frame
=
TRUE
;
}
if
(
cpi
->
common
.
refresh_golden_frame
==
TRUE
)
{
if
(
cpi
->
auto_adjust_gold_quantizer
)
{
calc_gf_params
(
cpi
);
}
// If we are using alternate ref instead of gf then do not apply the boost
// It will instead be applied to the altref update
// Jims modified boost
if
(
!
cpi
->
source_alt_ref_active
)
if
(
cpi
->
oxcf
.
fixed_q
<
0
)
{
if
(
cpi
->
oxcf
.
fixed_q
<
0
)
{
// The spend on the GF is defined in the two pass code
// for two pass encodes
cpi
->
this_frame_target
=
cpi
->
per_frame_bandwidth
;
}
else
cpi
->
this_frame_target
=
(
estimate_bits_at_q
(
1
,
Q
,
cpi
->
common
.
MBs
,
1
.
0
)
*
cpi
->
last_boost
)
/
100
;
// The spend on the GF is defined in the two pass code
// for two pass encodes
cpi
->
this_frame_target
=
cpi
->
per_frame_bandwidth
;
}
// If there is an active ARF at this location use the minimum
// bits on this frame even if it is a contructed arf.
// The active maximum quantizer insures that an appropriate
// number of bits will be spent if needed for contstructed ARFs.
else
{