mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Tune prefetch, squish bugs.
This commit is contained in:
parent
6422dcef78
commit
c4e0f15eb3
3 changed files with 11 additions and 17 deletions
|
@ -541,7 +541,7 @@ impl Future for AudioFileFetchDataReceiver {
|
||||||
if 0.001 * (duration.as_millis() as f64) > MAXIMUM_ASSUMED_PING_TIME_SECONDS {
|
if 0.001 * (duration.as_millis() as f64) > MAXIMUM_ASSUMED_PING_TIME_SECONDS {
|
||||||
duration_ms = (MAXIMUM_ASSUMED_PING_TIME_SECONDS * 1000.0) as u64;
|
duration_ms = (MAXIMUM_ASSUMED_PING_TIME_SECONDS * 1000.0) as u64;
|
||||||
} else {
|
} else {
|
||||||
duration_ms = duration.as_secs() * 1000 + duration.subsec_millis() as u64;
|
duration_ms = duration.as_millis() as u64;
|
||||||
}
|
}
|
||||||
let _ = self.file_data_tx.unbounded_send(ReceivedData::ResponseTimeMs(duration_ms as usize));
|
let _ = self.file_data_tx.unbounded_send(ReceivedData::ResponseTimeMs(duration_ms as usize));
|
||||||
self.measure_ping_time = false;
|
self.measure_ping_time = false;
|
||||||
|
@ -896,15 +896,16 @@ impl Future for AudioFileFetch {
|
||||||
download_status.requested.minus(&download_status.downloaded).len()
|
download_status.requested.minus(&download_status.downloaded).len()
|
||||||
};
|
};
|
||||||
|
|
||||||
let ping_time_seconds = 0.0001 * self.shared.ping_time_ms.load(atomic::Ordering::Relaxed) as f64;
|
let ping_time_seconds = 0.001 * self.shared.ping_time_ms.load(atomic::Ordering::Relaxed) as f64;
|
||||||
|
let download_rate = self.session.channel().get_download_rate_estimate();
|
||||||
|
|
||||||
let desired_pending_bytes = max(
|
let desired_pending_bytes = max(
|
||||||
(PREFETCH_THRESHOLD_FACTOR * ping_time_seconds * self.shared.stream_data_rate as f64) as usize,
|
(PREFETCH_THRESHOLD_FACTOR * ping_time_seconds * self.shared.stream_data_rate as f64) as usize,
|
||||||
(FAST_PREFETCH_THRESHOLD_FACTOR * ping_time_seconds * self.session.channel().get_download_rate_estimate() as f64) as usize
|
(FAST_PREFETCH_THRESHOLD_FACTOR * ping_time_seconds * download_rate as f64) as usize
|
||||||
);
|
);
|
||||||
|
|
||||||
if bytes_pending < desired_pending_bytes {
|
if bytes_pending < desired_pending_bytes {
|
||||||
trace!("Prefetching more data. pending bytes({}) < {}",bytes_pending, desired_pending_bytes);
|
trace!("Prefetching more data. pending: {}, desired: {}, ping: {}, rate: {}", bytes_pending, desired_pending_bytes, ping_time_seconds, download_rate);
|
||||||
self.pre_fetch_more_data(desired_pending_bytes - bytes_pending);
|
self.pre_fetch_more_data(desired_pending_bytes - bytes_pending);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,6 +186,7 @@ impl RangeSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
if index < self.ranges.len() && self.ranges[index].start < range.end() {
|
if index < self.ranges.len() && self.ranges[index].start < range.end() {
|
||||||
|
self.ranges[index].length -= range.end() - self.ranges[index].start;
|
||||||
self.ranges[index].start = range.end();
|
self.ranges[index].start = range.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +200,7 @@ impl RangeSet {
|
||||||
length: range.start - self.ranges[index].start,
|
length: range.start - self.ranges[index].start,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.ranges[index].length -= range.end() - self.ranges[index].start;
|
||||||
self.ranges[index].start = range.end();
|
self.ranges[index].start = range.end();
|
||||||
|
|
||||||
self.ranges.insert(index, first_range);
|
self.ranges.insert(index, first_range);
|
||||||
|
|
|
@ -14,7 +14,6 @@ component! {
|
||||||
download_rate_estimate: usize = 0,
|
download_rate_estimate: usize = 0,
|
||||||
download_measurement_start: Option<Instant> = None,
|
download_measurement_start: Option<Instant> = None,
|
||||||
download_measurement_bytes: usize = 0,
|
download_measurement_bytes: usize = 0,
|
||||||
download_measurement_last_received: Option<Instant> = None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,23 +71,15 @@ impl ChannelManager {
|
||||||
|
|
||||||
let current_time = Instant::now();
|
let current_time = Instant::now();
|
||||||
if let Some(download_measurement_start) = inner.download_measurement_start {
|
if let Some(download_measurement_start) = inner.download_measurement_start {
|
||||||
if let Some(download_measurement_last_received) = inner.download_measurement_last_received {
|
|
||||||
if (current_time - download_measurement_start).as_millis() > 1000 {
|
if (current_time - download_measurement_start).as_millis() > 1000 {
|
||||||
if (current_time - download_measurement_last_received).as_millis() <= 500 {
|
|
||||||
inner.download_rate_estimate = 1000 * inner.download_measurement_bytes / (current_time - download_measurement_start).as_millis() as usize;
|
inner.download_rate_estimate = 1000 * inner.download_measurement_bytes / (current_time - download_measurement_start).as_millis() as usize;
|
||||||
} else {
|
|
||||||
inner.download_rate_estimate = 1000 * inner.download_measurement_bytes / (500+(download_measurement_last_received - download_measurement_start).as_millis() as usize);
|
|
||||||
}
|
|
||||||
|
|
||||||
inner.download_measurement_start = Some(current_time);
|
inner.download_measurement_start = Some(current_time);
|
||||||
inner.download_measurement_bytes = 0;
|
inner.download_measurement_bytes = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
inner.download_measurement_start = Some(current_time);
|
inner.download_measurement_start = Some(current_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
inner.download_measurement_last_received = Some(current_time);
|
|
||||||
inner.download_measurement_bytes += data.len();
|
inner.download_measurement_bytes += data.len();
|
||||||
|
|
||||||
if let Entry::Occupied(entry) = inner.channels.entry(id) {
|
if let Entry::Occupied(entry) = inner.channels.entry(id) {
|
||||||
|
|
Loading…
Reference in a new issue