-
-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed bitrate calculation #2018
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,6 +271,7 @@ fn connection_pipeline(capabilities: ClientCapabilities) -> ConResult { | |
stream_socket.subscribe_to_stream::<Haptics>(HAPTICS, MAX_UNREAD_PACKETS); | ||
let statistics_sender = stream_socket.request_stream(STATISTICS); | ||
|
||
let mut actual_throughput_inseconds: f32 = 30_000_000.0; | ||
let video_receive_thread = thread::spawn(move || { | ||
let mut stream_corrupted = false; | ||
while is_streaming() { | ||
|
@@ -283,8 +284,22 @@ fn connection_pipeline(capabilities: ClientCapabilities) -> ConResult { | |
return; | ||
}; | ||
|
||
let dt_throughput = data.get_throughput_timediff(); | ||
|
||
if dt_throughput != Duration::ZERO { | ||
// TODO: Assuming UDP for 42.0, for TCP it would be 54.0 instead. This loses a bit of accuracy for TCP (it's still a good estimate) but I could need to import session settings in the future | ||
Comment on lines
+289
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like you to make this correct for TCP from the start |
||
|
||
let data_including_headers = (data.get_size_frame_bytes()) as f32 | ||
+ 42.0 * (data.get_shards_in_frame() as f32); // UDP and IPv4 headers count as bytes for throughput too | ||
actual_throughput_inseconds = | ||
data_including_headers * 8.0 / dt_throughput.as_secs_f32(); // bitrate for encoder is in bits per second, here we had bytes; so we need to multiply by 8 the data size | ||
} else { | ||
actual_throughput_inseconds = 0.0; | ||
} | ||
|
||
if let Some(stats) = &mut *STATISTICS_MANAGER.lock() { | ||
stats.report_video_packet_received(header.timestamp); | ||
stats.report_throughput_client(header.timestamp, actual_throughput_inseconds) | ||
} | ||
|
||
if header.is_idr { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,15 @@ impl StatisticsManager { | |
} | ||
} | ||
|
||
pub fn report_throughput_client(&mut self, target_timestamp: Duration, throughput_client: f32) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to |
||
if let Some(frame) = self | ||
.history_buffer | ||
.iter_mut() | ||
.find(|frame| frame.client_stats.target_timestamp == target_timestamp) | ||
{ | ||
frame.client_stats.throughput_client = throughput_client; | ||
} | ||
} | ||
// vsync_queue is the latency between this call and the vsync. it cannot be measured by ALVR and | ||
// should be reported by the VR runtime | ||
pub fn report_submit(&mut self, target_timestamp: Duration, vsync_queue: Duration) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,6 +314,7 @@ pub struct ClientStatistics { | |
pub rendering: Duration, | ||
pub vsync_queue: Duration, | ||
pub total_pipeline_latency: Duration, | ||
pub throughput_client: f32, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before |
||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,7 @@ impl BitrateManager { | |
timestamp: Duration, | ||
network_latency: Duration, | ||
decoder_latency: Duration, | ||
throughput_reported_client: f32, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before |
||
) { | ||
if network_latency.is_zero() { | ||
return; | ||
|
@@ -109,7 +110,7 @@ impl BitrateManager { | |
while let Some(&(timestamp_, size_bits)) = self.packet_sizes_bits_history.front() { | ||
if timestamp_ == timestamp { | ||
self.bitrate_average | ||
.submit_sample(size_bits as f32 / network_latency.as_secs_f32()); | ||
.submit_sample(throughput_reported_client); | ||
|
||
self.packet_sizes_bits_history.pop_front(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to
actual_throughput_bps