|
|
|
@@ -109,24 +109,38 @@ func (s *StreamSource) Buffered() float64 { |
|
|
|
|
|
|
|
// Stats returns diagnostic counters. |
|
|
|
func (s *StreamSource) Stats() StreamStats { |
|
|
|
available := s.Available() |
|
|
|
buffered := 0.0 |
|
|
|
if s.size > 0 { |
|
|
|
buffered = float64(available) / float64(s.size) |
|
|
|
} |
|
|
|
return StreamStats{ |
|
|
|
Available: s.Available(), |
|
|
|
Capacity: s.size, |
|
|
|
Buffered: s.Buffered(), |
|
|
|
Written: s.Written.Load(), |
|
|
|
Underruns: s.Underruns.Load(), |
|
|
|
Overflows: s.Overflows.Load(), |
|
|
|
Available: available, |
|
|
|
Capacity: s.size, |
|
|
|
Buffered: buffered, |
|
|
|
BufferedDurationSeconds: s.bufferedDurationSeconds(available), |
|
|
|
Written: s.Written.Load(), |
|
|
|
Underruns: s.Underruns.Load(), |
|
|
|
Overflows: s.Overflows.Load(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// StreamStats exposes runtime telemetry for the stream buffer. |
|
|
|
type StreamStats struct { |
|
|
|
Available int `json:"available"` |
|
|
|
Capacity int `json:"capacity"` |
|
|
|
Buffered float64 `json:"buffered"` |
|
|
|
Written uint64 `json:"written"` |
|
|
|
Underruns uint64 `json:"underruns"` |
|
|
|
Overflows uint64 `json:"overflows"` |
|
|
|
Available int `json:"available"` |
|
|
|
Capacity int `json:"capacity"` |
|
|
|
Buffered float64 `json:"buffered"` |
|
|
|
BufferedDurationSeconds float64 `json:"bufferedDurationSeconds"` |
|
|
|
Written uint64 `json:"written"` |
|
|
|
Underruns uint64 `json:"underruns"` |
|
|
|
Overflows uint64 `json:"overflows"` |
|
|
|
} |
|
|
|
|
|
|
|
func (s *StreamSource) bufferedDurationSeconds(available int) float64 { |
|
|
|
if s.SampleRate <= 0 { |
|
|
|
return 0 |
|
|
|
} |
|
|
|
return float64(available) / float64(s.SampleRate) |
|
|
|
} |
|
|
|
|
|
|
|
// --- StreamResampler --- |
|
|
|
|