Commit b1071db3 authored by Vignesh Venkatasubramanian's avatar Vignesh Venkatasubramanian Committed by Michael Niedermayer

lavf/webm_dash: Fix incorrect bandwidth computation

Fix incorrect bandwidth computation in some cases. When the cue end
descriptor is null (i.e.) start_time_ns == -1, existing bandwidth
computed (if any) should be returned rather than returning 0.
Signed-off-by: 's avatarVignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 8acb7656
...@@ -3188,55 +3188,57 @@ static int64_t webm_dash_manifest_compute_bandwidth(AVFormatContext *s, int64_t ...@@ -3188,55 +3188,57 @@ static int64_t webm_dash_manifest_compute_bandwidth(AVFormatContext *s, int64_t
} }
if (desc_end.start_time_ns == -1) { if (desc_end.start_time_ns == -1) {
// The prebuffer is larger than the duration. // The prebuffer is larger than the duration.
return (matroska->duration * matroska->time_scale >= prebuffered_ns) ? -1 : 0; if (matroska->duration * matroska->time_scale >= prebuffered_ns)
} return -1;
bits_per_second = 0.0;
// The prebuffer ends in the last Cue. Estimate how much data was } else {
// prebuffered. // The prebuffer ends in the last Cue. Estimate how much data was
pre_bytes = desc_end.end_offset - desc_end.start_offset; // prebuffered.
pre_ns = desc_end.end_time_ns - desc_end.start_time_ns; pre_bytes = desc_end.end_offset - desc_end.start_offset;
pre_sec = pre_ns / nano_seconds_per_second; pre_ns = desc_end.end_time_ns - desc_end.start_time_ns;
prebuffer_bytes += pre_sec = pre_ns / nano_seconds_per_second;
pre_bytes * ((temp_prebuffer_ns / nano_seconds_per_second) / pre_sec); prebuffer_bytes +=
pre_bytes * ((temp_prebuffer_ns / nano_seconds_per_second) / pre_sec);
prebuffer = prebuffer_ns / nano_seconds_per_second;
prebuffer = prebuffer_ns / nano_seconds_per_second;
// Set this to 0.0 in case our prebuffer buffers the entire video.
bits_per_second = 0.0; // Set this to 0.0 in case our prebuffer buffers the entire video.
do { bits_per_second = 0.0;
int64_t desc_bytes = desc_end.end_offset - desc_beg.start_offset; do {
int64_t desc_ns = desc_end.end_time_ns - desc_beg.start_time_ns; int64_t desc_bytes = desc_end.end_offset - desc_beg.start_offset;
double desc_sec = desc_ns / nano_seconds_per_second; int64_t desc_ns = desc_end.end_time_ns - desc_beg.start_time_ns;
double calc_bits_per_second = (desc_bytes * 8) / desc_sec; double desc_sec = desc_ns / nano_seconds_per_second;
double calc_bits_per_second = (desc_bytes * 8) / desc_sec;
// Drop the bps by the percentage of bytes buffered.
double percent = (desc_bytes - prebuffer_bytes) / desc_bytes; // Drop the bps by the percentage of bytes buffered.
double mod_bits_per_second = calc_bits_per_second * percent; double percent = (desc_bytes - prebuffer_bytes) / desc_bytes;
double mod_bits_per_second = calc_bits_per_second * percent;
if (prebuffer < desc_sec) {
double search_sec = if (prebuffer < desc_sec) {
(double)(matroska->duration * matroska->time_scale) / nano_seconds_per_second; double search_sec =
(double)(matroska->duration * matroska->time_scale) / nano_seconds_per_second;
// Add 1 so the bits per second should be a little bit greater than file
// datarate. // Add 1 so the bits per second should be a little bit greater than file
int64_t bps = (int64_t)(mod_bits_per_second) + 1; // datarate.
const double min_buffer = 0.0; int64_t bps = (int64_t)(mod_bits_per_second) + 1;
double buffer = prebuffer; const double min_buffer = 0.0;
double sec_to_download = 0.0; double buffer = prebuffer;
double sec_to_download = 0.0;
int rv = buffer_size_after_time_downloaded(prebuffered_ns, search_sec, bps,
min_buffer, &buffer, &sec_to_download, int rv = buffer_size_after_time_downloaded(prebuffered_ns, search_sec, bps,
s, cues_start); min_buffer, &buffer, &sec_to_download,
if (rv < 0) { s, cues_start);
return -1; if (rv < 0) {
} else if (rv == 0) { return -1;
bits_per_second = (double)(bps); } else if (rv == 0) {
break; bits_per_second = (double)(bps);
break;
}
} }
}
desc_end = get_cue_desc(s, desc_end.end_time_ns, cues_start); desc_end = get_cue_desc(s, desc_end.end_time_ns, cues_start);
} while (desc_end.start_time_ns != -1); } while (desc_end.start_time_ns != -1);
}
if (bandwidth < bits_per_second) bandwidth = bits_per_second; if (bandwidth < bits_per_second) bandwidth = bits_per_second;
} }
return (int64_t)bandwidth; return (int64_t)bandwidth;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment