fix: Address linting errors in audio code

- Check SetReadDeadline error in IPC client
- Explicitly ignore Kill() error (process may be dead)
- Remove init() function and rely on explicit ExtractEmbeddedBinaries() call
This commit is contained in:
Alex P 2025-10-06 22:12:20 +03:00
parent 7872ddc8fc
commit 141e2f9099
4 changed files with 31 additions and 39 deletions

View File

@ -15,10 +15,10 @@ var audioOutputBinary []byte
var audioInputBinary []byte
const (
audioBinDir = "/userdata/jetkvm/bin"
audioOutputBinPath = audioBinDir + "/jetkvm_audio_output"
audioInputBinPath = audioBinDir + "/jetkvm_audio_input"
binaryFileMode = 0755 // rwxr-xr-x
audioBinDir = "/userdata/jetkvm/bin"
audioOutputBinPath = audioBinDir + "/jetkvm_audio_output"
audioInputBinPath = audioBinDir + "/jetkvm_audio_input"
binaryFileMode = 0755 // rwxr-xr-x
)
// ExtractEmbeddedBinaries extracts the embedded C audio binaries to disk
@ -78,13 +78,3 @@ func GetAudioOutputBinaryPath() string {
func GetAudioInputBinaryPath() string {
return audioInputBinPath
}
// init ensures binaries are extracted when package is imported
func init() {
// Extract binaries on package initialization
// This ensures binaries are available before supervisors start
if err := ExtractEmbeddedBinaries(); err != nil {
// Log error but don't panic - let caller handle initialization failure
fmt.Fprintf(os.Stderr, "Warning: Failed to extract embedded audio binaries: %v\n", err)
}
}

View File

@ -22,15 +22,15 @@ var writeBufferPool = sync.Pool{
// IPC Protocol constants (matches C implementation in ipc_protocol.h)
const (
ipcMagicOutput = 0x4A4B4F55 // "JKOU" - Output (device → browser)
ipcMagicInput = 0x4A4B4D49 // "JKMI" - Input (browser → device)
ipcHeaderSize = 9 // Reduced from 17 (removed 8-byte timestamp)
ipcMaxFrameSize = 1024 // 128kbps @ 20ms = ~600 bytes worst case with VBR+FEC
ipcMsgTypeOpus = 0
ipcMsgTypeConfig = 1
ipcMsgTypeStop = 3
connectTimeout = 5 * time.Second
readTimeout = 2 * time.Second
ipcMagicOutput = 0x4A4B4F55 // "JKOU" - Output (device → browser)
ipcMagicInput = 0x4A4B4D49 // "JKMI" - Input (browser → device)
ipcHeaderSize = 9 // Reduced from 17 (removed 8-byte timestamp)
ipcMaxFrameSize = 1024 // 128kbps @ 20ms = ~600 bytes worst case with VBR+FEC
ipcMsgTypeOpus = 0
ipcMsgTypeConfig = 1
ipcMsgTypeStop = 3
connectTimeout = 5 * time.Second
readTimeout = 2 * time.Second
)
// IPCClient manages Unix socket communication with audio subprocess
@ -109,7 +109,9 @@ func (c *IPCClient) ReadMessage() (uint8, []byte, error) {
}
// Set read deadline
c.conn.SetReadDeadline(time.Now().Add(readTimeout))
if err := c.conn.SetReadDeadline(time.Now().Add(readTimeout)); err != nil {
return 0, nil, fmt.Errorf("failed to set read deadline: %w", err)
}
// Read 9-byte header
var header [ipcHeaderSize]byte

View File

@ -21,12 +21,12 @@ type Supervisor struct {
socketPath string
env []string
cmd *exec.Cmd
ctx context.Context
cancel context.CancelFunc
running atomic.Bool
done chan struct{} // Closed when supervision loop exits
logger zerolog.Logger
cmd *exec.Cmd
ctx context.Context
cancel context.CancelFunc
running atomic.Bool
done chan struct{} // Closed when supervision loop exits
logger zerolog.Logger
// Restart state
restartCount uint8
@ -81,7 +81,7 @@ func (s *Supervisor) Stop() {
// Kill process if running
if s.cmd != nil && s.cmd.Process != nil {
s.cmd.Process.Kill()
_ = s.cmd.Process.Kill() // Ignore error, process may already be dead
}
// Wait for supervision loop to exit

View File

@ -66,14 +66,14 @@ var defaultGadgetConfig = map[string]gadgetConfigItem{
path: []string{"functions", "uac1.usb0"},
configPath: []string{"uac1.usb0"},
attrs: gadgetAttributes{
"p_chmask": "3", // Playback: stereo (2 channels)
"p_srate": "48000", // Playback: 48kHz sample rate
"p_ssize": "2", // Playback: 16-bit (2 bytes)
"p_volume_present": "0", // Playback: no volume control
"c_chmask": "3", // Capture: stereo (2 channels)
"c_srate": "48000", // Capture: 48kHz sample rate
"c_ssize": "2", // Capture: 16-bit (2 bytes)
"c_volume_present": "0", // Capture: no volume control
"p_chmask": "3", // Playback: stereo (2 channels)
"p_srate": "48000", // Playback: 48kHz sample rate
"p_ssize": "2", // Playback: 16-bit (2 bytes)
"p_volume_present": "0", // Playback: no volume control
"c_chmask": "3", // Capture: stereo (2 channels)
"c_srate": "48000", // Capture: 48kHz sample rate
"c_ssize": "2", // Capture: 16-bit (2 bytes)
"c_volume_present": "0", // Capture: no volume control
},
},
}