fix(stats): real encode thread timing via SwEncodeTiming + take_timing (#17)
encode_thread_loop hardcoded sws_us=0 and output_bytes=0, making the
stats dashboard show zeros for those columns. The previous encode_us
was measured around the entire encode_cpu_frame call, mixing sws +
encode work into one bucket.
Add SwEncodeTiming { sws_us, encode_us, output_bytes } to SwEncEncode.
- drain_encoder returns Result<usize> (total encoded bytes), accumulated
before the Muxer/Channel match so branch duplication and multi-packet
drain are both handled correctly. output_bytes = bytes produced by
libavcodec even if downstream delivery drops them.
- encode_cpu_frame resets last_timing to Default at entry (so early
returns from disconnect/pause/dedup never report stale prior values),
measures sws_us around sws_scale, measures encode_us around
avcodec_send_frame + drain, then stores the complete snapshot.
- take_timing() uses mem::take to return and clear in one step.
- flush() ignores the byte count from drain_encoder.
- state_portal encode_thread_loop calls take_timing() for real values.
This commit is contained in:
+4
-5
@@ -644,14 +644,13 @@ fn encode_thread_loop(
|
||||
loop {
|
||||
match input_rx.recv() {
|
||||
Ok(frame) => {
|
||||
let t_start = Instant::now();
|
||||
match encode.encode_cpu_frame(&frame) {
|
||||
Ok(()) => {
|
||||
let elapsed = t_start.elapsed().as_micros() as u64;
|
||||
let t = encode.take_timing();
|
||||
let _ = timing_tx.try_send(EncodeThreadTiming {
|
||||
sws_us: 0,
|
||||
encode_us: elapsed,
|
||||
output_bytes: 0,
|
||||
sws_us: t.sws_us,
|
||||
encode_us: t.encode_us,
|
||||
output_bytes: t.output_bytes,
|
||||
});
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user