Fix: linter errors

This commit is contained in:
Alex P 2025-08-22 22:23:50 +00:00
parent 3c1e9b8dc2
commit 1e1677b35a
2 changed files with 42 additions and 42 deletions

View File

@ -16,9 +16,9 @@ import (
const ( const (
inputMagicNumber uint32 = 0x4A4B4D49 // "JKMI" (JetKVM Microphone Input) inputMagicNumber uint32 = 0x4A4B4D49 // "JKMI" (JetKVM Microphone Input)
inputSocketName = "audio_input.sock" inputSocketName = "audio_input.sock"
maxFrameSize = 4096 // Maximum Opus frame size maxFrameSize = 4096 // Maximum Opus frame size
writeTimeout = 5 * time.Millisecond // Non-blocking write timeout writeTimeout = 5 * time.Millisecond // Non-blocking write timeout
maxDroppedFrames = 100 // Maximum consecutive dropped frames before reconnect maxDroppedFrames = 100 // Maximum consecutive dropped frames before reconnect
) )
// InputMessageType represents the type of IPC message // InputMessageType represents the type of IPC message
@ -62,10 +62,10 @@ type AudioInputServer struct {
running bool running bool
// Triple-goroutine architecture // Triple-goroutine architecture
messageChan chan *InputIPCMessage // Buffered channel for incoming messages messageChan chan *InputIPCMessage // Buffered channel for incoming messages
processChan chan *InputIPCMessage // Buffered channel for processing queue processChan chan *InputIPCMessage // Buffered channel for processing queue
stopChan chan struct{} // Stop signal for all goroutines stopChan chan struct{} // Stop signal for all goroutines
wg sync.WaitGroup // Wait group for goroutine coordination wg sync.WaitGroup // Wait group for goroutine coordination
} }
// NewAudioInputServer creates a new audio input server // NewAudioInputServer creates a new audio input server
@ -316,9 +316,9 @@ type AudioInputClient struct {
droppedFrames int64 // Atomic counter for dropped frames droppedFrames int64 // Atomic counter for dropped frames
totalFrames int64 // Atomic counter for total frames totalFrames int64 // Atomic counter for total frames
conn net.Conn conn net.Conn
mtx sync.Mutex mtx sync.Mutex
running bool running bool
} }
// NewAudioInputClient creates a new audio input client // NewAudioInputClient creates a new audio input client
@ -644,7 +644,7 @@ func (ais *AudioInputServer) startMonitorGoroutine() {
} }
} }
adaptiveBuffering: adaptiveBuffering:
// Adaptive buffer sizing based on processing time // Adaptive buffer sizing based on processing time
avgTime := atomic.LoadInt64(&ais.processingTime) avgTime := atomic.LoadInt64(&ais.processingTime)
currentSize := atomic.LoadInt64(&ais.bufferSize) currentSize := atomic.LoadInt64(&ais.bufferSize)

View File

@ -10,9 +10,9 @@ import (
// with reduced contention using atomic operations and conditional locking // with reduced contention using atomic operations and conditional locking
type MicrophoneContentionManager struct { type MicrophoneContentionManager struct {
// Atomic fields (must be 64-bit aligned on 32-bit systems) // Atomic fields (must be 64-bit aligned on 32-bit systems)
lastOpNano int64 // Unix nanoseconds of last operation lastOpNano int64 // Unix nanoseconds of last operation
cooldownNanos int64 // Cooldown duration in nanoseconds cooldownNanos int64 // Cooldown duration in nanoseconds
operationID int64 // Incremental operation ID for tracking operationID int64 // Incremental operation ID for tracking
// Lock-free state flags (using atomic.Pointer for lock-free updates) // Lock-free state flags (using atomic.Pointer for lock-free updates)
lockPtr unsafe.Pointer // *sync.Mutex - conditionally allocated lockPtr unsafe.Pointer // *sync.Mutex - conditionally allocated
@ -27,9 +27,9 @@ func NewMicrophoneContentionManager(cooldown time.Duration) *MicrophoneContentio
// OperationResult represents the result of attempting a microphone operation // OperationResult represents the result of attempting a microphone operation
type OperationResult struct { type OperationResult struct {
Allowed bool Allowed bool
RemainingCooldown time.Duration RemainingCooldown time.Duration
OperationID int64 OperationID int64
} }
// TryOperation attempts to perform a microphone operation with optimized contention handling // TryOperation attempts to perform a microphone operation with optimized contention handling
@ -46,9 +46,9 @@ func (mcm *MicrophoneContentionManager) TryOperation() OperationResult {
if atomic.CompareAndSwapInt64(&mcm.lastOpNano, lastOp, now) { if atomic.CompareAndSwapInt64(&mcm.lastOpNano, lastOp, now) {
opID := atomic.AddInt64(&mcm.operationID, 1) opID := atomic.AddInt64(&mcm.operationID, 1)
return OperationResult{ return OperationResult{
Allowed: true, Allowed: true,
RemainingCooldown: 0, RemainingCooldown: 0,
OperationID: opID, OperationID: opID,
} }
} }
} }
@ -63,9 +63,9 @@ func (mcm *MicrophoneContentionManager) TryOperation() OperationResult {
if atomic.CompareAndSwapInt64(&mcm.lastOpNano, currentLastOp, now) { if atomic.CompareAndSwapInt64(&mcm.lastOpNano, currentLastOp, now) {
opID := atomic.AddInt64(&mcm.operationID, 1) opID := atomic.AddInt64(&mcm.operationID, 1)
return OperationResult{ return OperationResult{
Allowed: true, Allowed: true,
RemainingCooldown: 0, RemainingCooldown: 0,
OperationID: opID, OperationID: opID,
} }
} }
// If CAS failed, fall through to cooldown calculation // If CAS failed, fall through to cooldown calculation
@ -79,9 +79,9 @@ func (mcm *MicrophoneContentionManager) TryOperation() OperationResult {
} }
return OperationResult{ return OperationResult{
Allowed: false, Allowed: false,
RemainingCooldown: remaining, RemainingCooldown: remaining,
OperationID: atomic.LoadInt64(&mcm.operationID), OperationID: atomic.LoadInt64(&mcm.operationID),
} }
} }