mirror of https://github.com/jetkvm/kvm.git
Fix buffer aliasing and cleanup unused fields in audio
- Copy opus data in ReadMessage to prevent aliasing with internal buffer - Remove unused ctx field from OutputRelay struct - Fix OPUS_BANDWIDTH comment accuracy (20kHz passband)
This commit is contained in:
parent
aeb68810ba
commit
fe940cd9ab
|
|
@ -88,7 +88,7 @@ static uint16_t max_packet_size = 1500;
|
||||||
#define OPUS_VBR 1 // Variable bitrate mode enabled
|
#define OPUS_VBR 1 // Variable bitrate mode enabled
|
||||||
#define OPUS_VBR_CONSTRAINT 1 // Constrained VBR maintains bitrate ceiling
|
#define OPUS_VBR_CONSTRAINT 1 // Constrained VBR maintains bitrate ceiling
|
||||||
#define OPUS_SIGNAL_TYPE 3002 // OPUS_SIGNAL_MUSIC (optimized for music/audio content)
|
#define OPUS_SIGNAL_TYPE 3002 // OPUS_SIGNAL_MUSIC (optimized for music/audio content)
|
||||||
#define OPUS_BANDWIDTH 1105 // OPUS_BANDWIDTH_FULLBAND (0-20kHz frequency range)
|
#define OPUS_BANDWIDTH 1105 // OPUS_BANDWIDTH_FULLBAND (20kHz passband)
|
||||||
#define OPUS_LSB_DEPTH 16 // 16-bit PCM sample depth (S16_LE format)
|
#define OPUS_LSB_DEPTH 16 // 16-bit PCM sample depth (S16_LE format)
|
||||||
|
|
||||||
static uint8_t opus_dtx_enabled = 1;
|
static uint8_t opus_dtx_enabled = 1;
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,11 @@ func (c *CgoSource) ReadMessage() (uint8, []byte, error) {
|
||||||
return 0, nil, fmt.Errorf("opus packet too large: %d > %d", opusSize, len(c.opusBuf))
|
return 0, nil, fmt.Errorf("opus packet too large: %d > %d", opusSize, len(c.opusBuf))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ipcMsgTypeOpus, c.opusBuf[:opusSize], nil
|
// Return a copy to prevent buffer aliasing - the caller may hold this slice
|
||||||
|
// while the next ReadMessage overwrites the internal buffer
|
||||||
|
result := make([]byte, opusSize)
|
||||||
|
copy(result, c.opusBuf[:opusSize])
|
||||||
|
return ipcMsgTypeOpus, result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CgoSource) WriteMessage(msgType uint8, payload []byte) error {
|
func (c *CgoSource) WriteMessage(msgType uint8, payload []byte) error {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import (
|
||||||
type OutputRelay struct {
|
type OutputRelay struct {
|
||||||
source *AudioSource
|
source *AudioSource
|
||||||
audioTrack *webrtc.TrackLocalStaticSample
|
audioTrack *webrtc.TrackLocalStaticSample
|
||||||
ctx context.Context
|
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
logger zerolog.Logger
|
logger zerolog.Logger
|
||||||
running atomic.Bool
|
running atomic.Bool
|
||||||
|
|
@ -27,13 +26,12 @@ type OutputRelay struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOutputRelay(source *AudioSource, audioTrack *webrtc.TrackLocalStaticSample) *OutputRelay {
|
func NewOutputRelay(source *AudioSource, audioTrack *webrtc.TrackLocalStaticSample) *OutputRelay {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
_, cancel := context.WithCancel(context.Background())
|
||||||
logger := logging.GetDefaultLogger().With().Str("component", "audio-output-relay").Logger()
|
logger := logging.GetDefaultLogger().With().Str("component", "audio-output-relay").Logger()
|
||||||
|
|
||||||
return &OutputRelay{
|
return &OutputRelay{
|
||||||
source: source,
|
source: source,
|
||||||
audioTrack: audioTrack,
|
audioTrack: audioTrack,
|
||||||
ctx: ctx,
|
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
stopped: make(chan struct{}),
|
stopped: make(chan struct{}),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue