-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (40 loc) · 1.06 KB
/
main.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
47
48
49
package gst_audiomixer
import (
"context"
"fmt"
"github.com/notedit/gst"
"log"
)
func StartServer(ctx context.Context, portStart, portEnd int, sampleChan chan []byte) error {
if portEnd < portStart {
return fmt.Errorf("[AUDIOMIXER] invalid ports")
}
pipelineString := ""
for i := portStart; i <= portEnd; i++ {
pipelineString += fmt.Sprintf("udpsrc port=%d caps=\"application/x-rtp,media=audio,encoding-name=L16,clock-rate=48000,channels=2\" ! queue ! rtpL16depay ! adder.\n", i)
}
pipelineString += "liveadder name=adder ! opusenc ! appsink num-buffers=32 name=sink"
log.Print(pipelineString)
pipeline, err := gst.ParseLaunch(pipelineString)
if err != nil {
return fmt.Errorf("[AUDIOMIXER] error parsing pipeline")
}
pipeline.SetState(gst.StatePlaying)
sinkEl := pipeline.GetByName("sink")
if sinkEl == nil {
return fmt.Errorf("[AUDIOMIXER] sinkEl not found")
}
go func() {
for {
sample, _ := sinkEl.PullSample()
if sample != nil {
sampleChan <- sample.Data
}
}
}()
select {
case <-ctx.Done():
close(sampleChan)
return nil
}
}