Fix: audio subprocess handling, avg atency audio metric

This commit is contained in:
Alex P 2025-08-22 22:21:41 +00:00
parent 62d4ec2f89
commit 3c1e9b8dc2
4 changed files with 13 additions and 19 deletions

View File

@ -38,13 +38,13 @@ type BatchAudioProcessor struct {
type BatchAudioStats struct { type BatchAudioStats struct {
// int64 fields MUST be first for ARM32 alignment // int64 fields MUST be first for ARM32 alignment
BatchedReads int64 BatchedReads int64
SingleReads int64 SingleReads int64
BatchedFrames int64 BatchedFrames int64
SingleFrames int64 SingleFrames int64
CGOCallsReduced int64 CGOCallsReduced int64
OSThreadPinTime time.Duration // time.Duration is int64 internally OSThreadPinTime time.Duration // time.Duration is int64 internally
LastBatchTime time.Time LastBatchTime time.Time
} }
type batchReadRequest struct { type batchReadRequest struct {
@ -153,8 +153,6 @@ func (bap *BatchAudioProcessor) BatchReadEncode(buffer []byte) (int, error) {
} }
} }
// batchReadProcessor processes batched read operations // batchReadProcessor processes batched read operations
func (bap *BatchAudioProcessor) batchReadProcessor() { func (bap *BatchAudioProcessor) batchReadProcessor() {
defer bap.logger.Debug().Msg("batch read processor stopped") defer bap.logger.Debug().Msg("batch read processor stopped")
@ -191,8 +189,6 @@ func (bap *BatchAudioProcessor) batchReadProcessor() {
} }
} }
// processBatchRead processes a batch of read requests efficiently // processBatchRead processes a batch of read requests efficiently
func (bap *BatchAudioProcessor) processBatchRead(batch []batchReadRequest) { func (bap *BatchAudioProcessor) processBatchRead(batch []batchReadRequest) {
if len(batch) == 0 { if len(batch) == 0 {
@ -236,8 +232,6 @@ func (bap *BatchAudioProcessor) processBatchRead(batch []batchReadRequest) {
bap.stats.LastBatchTime = time.Now() bap.stats.LastBatchTime = time.Now()
} }
// GetStats returns current batch processor statistics // GetStats returns current batch processor statistics
func (bap *BatchAudioProcessor) GetStats() BatchAudioStats { func (bap *BatchAudioProcessor) GetStats() BatchAudioStats {
return BatchAudioStats{ return BatchAudioStats{
@ -258,7 +252,7 @@ func (bap *BatchAudioProcessor) IsRunning() bool {
// Global batch processor instance // Global batch processor instance
var ( var (
globalBatchProcessor unsafe.Pointer // *BatchAudioProcessor globalBatchProcessor unsafe.Pointer // *BatchAudioProcessor
batchProcessorInitialized int32 batchProcessorInitialized int32
) )
@ -308,4 +302,4 @@ func BatchCGOAudioReadEncode(buffer []byte) (int, error) {
return processor.BatchReadEncode(buffer) return processor.BatchReadEncode(buffer)
} }
return CGOAudioReadEncode(buffer) return CGOAudioReadEncode(buffer)
} }

View File

@ -65,4 +65,4 @@ func GetAudioControlBuffer() []byte {
// PutAudioControlBuffer returns a buffer to the control pool // PutAudioControlBuffer returns a buffer to the control pool
func PutAudioControlBuffer(buf []byte) { func PutAudioControlBuffer(buf []byte) {
audioControlPool.Put(buf) audioControlPool.Put(buf)
} }

View File

@ -2,6 +2,7 @@ package audio
import ( import (
"context" "context"
"fmt"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -286,7 +287,7 @@ func (aeb *AudioEventBroadcaster) startMetricsBroadcasting() {
BytesProcessed: audioMetrics.BytesProcessed, BytesProcessed: audioMetrics.BytesProcessed,
LastFrameTime: audioMetrics.LastFrameTime.Format("2006-01-02T15:04:05.000Z"), LastFrameTime: audioMetrics.LastFrameTime.Format("2006-01-02T15:04:05.000Z"),
ConnectionDrops: audioMetrics.ConnectionDrops, ConnectionDrops: audioMetrics.ConnectionDrops,
AverageLatency: audioMetrics.AverageLatency.String(), AverageLatency: fmt.Sprintf("%.1fms", float64(audioMetrics.AverageLatency.Nanoseconds())/1e6),
}, },
} }
aeb.broadcast(audioMetricsEvent) aeb.broadcast(audioMetricsEvent)
@ -304,7 +305,7 @@ func (aeb *AudioEventBroadcaster) startMetricsBroadcasting() {
BytesProcessed: micMetrics.BytesProcessed, BytesProcessed: micMetrics.BytesProcessed,
LastFrameTime: micMetrics.LastFrameTime.Format("2006-01-02T15:04:05.000Z"), LastFrameTime: micMetrics.LastFrameTime.Format("2006-01-02T15:04:05.000Z"),
ConnectionDrops: micMetrics.ConnectionDrops, ConnectionDrops: micMetrics.ConnectionDrops,
AverageLatency: micMetrics.AverageLatency.String(), AverageLatency: fmt.Sprintf("%.1fms", float64(micMetrics.AverageLatency.Nanoseconds())/1e6),
}, },
} }
aeb.broadcast(micMetricsEvent) aeb.broadcast(micMetricsEvent)

View File

@ -154,7 +154,6 @@ func (aim *AudioInputIPCManager) GetDetailedMetrics() (AudioInputMetrics, map[st
// Get server statistics if available // Get server statistics if available
serverStats := make(map[string]interface{}) serverStats := make(map[string]interface{})
if aim.supervisor.IsRunning() { if aim.supervisor.IsRunning() {
serverStats["status"] = "running" serverStats["status"] = "running"
} else { } else {
serverStats["status"] = "stopped" serverStats["status"] = "stopped"