-
Notifications
You must be signed in to change notification settings - Fork 9
/
clientrackaudio.go
46 lines (39 loc) · 1.03 KB
/
clientrackaudio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package sfu
import (
"github.com/inlivedev/sfu/pkg/interceptors/voiceactivedetector"
"github.com/pion/webrtc/v4"
)
type clientTrackAudio struct {
*clientTrack
}
func newClientTrackAudio(c *Client, t ITrack) *clientTrackAudio {
var localTrack *webrtc.TrackLocalStaticRTP
audioTrack, ok := t.(*AudioTrack)
if !ok {
c.log.Errorf("clienttrackaudio: track is not audio")
return nil
}
if !c.receiveRED {
localTrack = audioTrack.createOpusLocalTrack()
} else {
localTrack = audioTrack.createLocalTrack()
}
ctBase := newClientTrack(c, audioTrack.Track, false, localTrack)
cta := &clientTrackAudio{
clientTrack: ctBase,
}
track := t.(*AudioTrack)
if c.options.EnableVoiceDetection {
track.OnVoiceDetected(func(pkts []voiceactivedetector.VoicePacketData) {
activity := voiceactivedetector.VoiceActivity{
TrackID: cta.id,
StreamID: cta.streamid,
SSRC: uint32(cta.ssrc),
ClockRate: cta.baseTrack.codec.ClockRate,
AudioLevels: pkts,
}
c.onVoiceSentDetected(activity)
})
}
return cta
}