mirror of https://github.com/jetkvm/kvm.git
[WIP] Updates: support in-process mode
This commit is contained in:
parent
58fad71112
commit
9d7fd878a1
|
|
@ -3,16 +3,17 @@
|
||||||
package audio
|
package audio
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo CFLAGS: -O3 -ffast-math
|
#cgo CFLAGS: -O3 -ffast-math -I/opt/jetkvm-audio-libs/alsa-lib-1.2.14/include -I/opt/jetkvm-audio-libs/opus-1.5.2/include
|
||||||
#cgo LDFLAGS: -lasound -lopus -lm
|
#cgo LDFLAGS: /opt/jetkvm-audio-libs/alsa-lib-1.2.14/src/.libs/libasound.a /opt/jetkvm-audio-libs/opus-1.5.2/.libs/libopus.a -lm -ldl -lpthread
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include "c/audio.c"
|
#include "c/audio.c"
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/jetkvm/kvm/internal/logging"
|
"github.com/jetkvm/kvm/internal/logging"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
|
@ -62,12 +63,10 @@ func (c *CgoSource) Connect() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set ALSA device via environment for C code
|
// Set ALSA device via environment for C code to read via init_alsa_devices_from_env()
|
||||||
if c.direction == "output" {
|
if c.direction == "output" {
|
||||||
// Set capture device for output path
|
// Set capture device for output path via environment variable
|
||||||
cDevice := C.CString(c.alsaDevice)
|
os.Setenv("ALSA_CAPTURE_DEVICE", c.alsaDevice)
|
||||||
defer C.free(unsafe.Pointer(cDevice))
|
|
||||||
C.alsa_capture_device = cDevice
|
|
||||||
|
|
||||||
// Initialize constants
|
// Initialize constants
|
||||||
C.update_audio_constants(
|
C.update_audio_constants(
|
||||||
|
|
@ -91,10 +90,8 @@ func (c *CgoSource) Connect() error {
|
||||||
|
|
||||||
c.logger.Debug().Str("device", c.alsaDevice).Msg("Audio capture initialized")
|
c.logger.Debug().Str("device", c.alsaDevice).Msg("Audio capture initialized")
|
||||||
} else {
|
} else {
|
||||||
// Set playback device for input path
|
// Set playback device for input path via environment variable
|
||||||
cDevice := C.CString(c.alsaDevice)
|
os.Setenv("ALSA_PLAYBACK_DEVICE", c.alsaDevice)
|
||||||
defer C.free(unsafe.Pointer(cDevice))
|
|
||||||
C.alsa_playback_device = cDevice
|
|
||||||
|
|
||||||
// Initialize decoder constants
|
// Initialize decoder constants
|
||||||
C.update_audio_decoder_constants(
|
C.update_audio_decoder_constants(
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,13 @@ type AudioSource interface {
|
||||||
// ReadMessage reads the next audio message
|
// ReadMessage reads the next audio message
|
||||||
// Returns message type, payload data, and error
|
// Returns message type, payload data, and error
|
||||||
// Blocks until data is available or error occurs
|
// Blocks until data is available or error occurs
|
||||||
|
// Used for output path (device → browser)
|
||||||
ReadMessage() (msgType uint8, payload []byte, err error)
|
ReadMessage() (msgType uint8, payload []byte, err error)
|
||||||
|
|
||||||
|
// WriteMessage writes an audio message
|
||||||
|
// Used for input path (browser → device)
|
||||||
|
WriteMessage(msgType uint8, payload []byte) error
|
||||||
|
|
||||||
// IsConnected returns true if the source is connected and ready
|
// IsConnected returns true if the source is connected and ready
|
||||||
IsConnected() bool
|
IsConnected() bool
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue