mirror of
https://github.com/jetkvm/kvm.git
synced 2025-09-16 08:38:14 +00:00
Rename audio server/client components to be more specific (AudioOutputServer/Client). Add new validation.go and ipc_common.go files for shared IPC functionality. Improve error handling and cleanup in input/output IPC components. Disable granular metrics logging to reduce log pollution. Reset metrics on failed start and ensure proper cleanup. Add common IPC message interface and optimized message pool for reuse.
73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
package audio
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"sync/atomic"
|
|
"unsafe"
|
|
)
|
|
|
|
var (
|
|
// Global audio output supervisor instance
|
|
globalOutputSupervisor unsafe.Pointer // *AudioOutputSupervisor
|
|
)
|
|
|
|
// isAudioServerProcess detects if we're running as the audio server subprocess
|
|
func isAudioServerProcess() bool {
|
|
for _, arg := range os.Args {
|
|
if strings.Contains(arg, "--audio-output-server") {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// StartAudioStreaming launches the audio stream.
|
|
// In audio server subprocess: uses CGO-based audio streaming
|
|
// In main process: this should not be called (use StartAudioRelay instead)
|
|
func StartAudioStreaming(send func([]byte)) error {
|
|
if isAudioServerProcess() {
|
|
// Audio server subprocess: use CGO audio processing
|
|
return StartAudioOutputStreaming(send)
|
|
} else {
|
|
// Main process: should use relay system instead
|
|
// This is kept for backward compatibility but not recommended
|
|
return StartAudioOutputStreaming(send)
|
|
}
|
|
}
|
|
|
|
// StopAudioStreaming stops the audio stream.
|
|
func StopAudioStreaming() {
|
|
if isAudioServerProcess() {
|
|
// Audio server subprocess: stop CGO audio processing
|
|
StopAudioOutputStreaming()
|
|
} else {
|
|
// Main process: stop relay if running
|
|
StopAudioRelay()
|
|
}
|
|
}
|
|
|
|
// StartNonBlockingAudioStreaming is an alias for backward compatibility
|
|
func StartNonBlockingAudioStreaming(send func([]byte)) error {
|
|
return StartAudioOutputStreaming(send)
|
|
}
|
|
|
|
// StopNonBlockingAudioStreaming is an alias for backward compatibility
|
|
func StopNonBlockingAudioStreaming() {
|
|
StopAudioOutputStreaming()
|
|
}
|
|
|
|
// SetAudioOutputSupervisor sets the global audio output supervisor
|
|
func SetAudioOutputSupervisor(supervisor *AudioOutputSupervisor) {
|
|
atomic.StorePointer(&globalOutputSupervisor, unsafe.Pointer(supervisor))
|
|
}
|
|
|
|
// GetAudioOutputSupervisor returns the global audio output supervisor
|
|
func GetAudioOutputSupervisor() *AudioOutputSupervisor {
|
|
ptr := atomic.LoadPointer(&globalOutputSupervisor)
|
|
if ptr == nil {
|
|
return nil
|
|
}
|
|
return (*AudioOutputSupervisor)(ptr)
|
|
}
|