Update wyoming producer and backchannel

This commit is contained in:
Alex X
2025-04-22 10:26:00 +03:00
parent df2e982090
commit 6df1e68a5f
4 changed files with 47 additions and 19 deletions

View File

@@ -203,5 +203,6 @@ func ProducerCodecs() []*core.Codec {
{Name: core.CodecPCM, ClockRate: 8000},
{Name: core.CodecPCMA, ClockRate: 8000},
{Name: core.CodecPCMU, ClockRate: 8000},
{Name: core.CodecPCML, ClockRate: 22050}, // wyoming-snd-external
}
}

View File

@@ -2,6 +2,7 @@ package wyoming
import (
"fmt"
"net"
"time"
"github.com/AlexxIT/go2rtc/pkg/core"
@@ -13,6 +14,26 @@ type Backchannel struct {
api *API
}
func newBackchannel(conn net.Conn) *Backchannel {
return &Backchannel{
core.Connection{
ID: core.NewID(),
FormatName: "wyoming",
Medias: []*core.Media{
{
Kind: core.KindAudio,
Direction: core.DirectionSendonly,
Codecs: []*core.Codec{
{Name: core.CodecPCML, ClockRate: 22050},
},
},
},
Transport: conn,
},
NewAPI(conn),
}
}
func (b *Backchannel) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver, error) {
return nil, core.ErrCantGetTrack
}
@@ -23,7 +44,7 @@ func (b *Backchannel) AddTrack(media *core.Media, codec *core.Codec, track *core
ts := time.Now().Nanosecond()
evt := &Event{
Type: "audio-chunk",
Data: []byte(fmt.Sprintf(`{"rate":16000,"width":2,"channels":1,"timestamp":%d}`, ts)),
Data: []byte(fmt.Sprintf(`{"rate":22050,"width":2,"channels":1,"timestamp":%d}`, ts)),
Payload: pkt.Payload,
}
_ = b.api.WriteEvent(evt)

View File

@@ -1,6 +1,8 @@
package wyoming
import (
"net"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtp"
)
@@ -10,6 +12,26 @@ type Producer struct {
api *API
}
func newProducer(conn net.Conn) *Producer {
return &Producer{
core.Connection{
ID: core.NewID(),
FormatName: "wyoming",
Medias: []*core.Media{
{
Kind: core.KindAudio,
Direction: core.DirectionRecvonly,
Codecs: []*core.Codec{
{Name: core.CodecPCML, ClockRate: 16000},
},
},
},
Transport: conn,
},
NewAPI(conn),
}
}
func (p *Producer) Start() error {
var seq uint16
var ts uint32

View File

@@ -18,25 +18,9 @@ func Dial(rawURL string) (core.Producer, error) {
return nil, err
}
cc := core.Connection{
ID: core.NewID(),
FormatName: "wyoming",
Medias: []*core.Media{
{
Kind: core.KindAudio,
Codecs: []*core.Codec{
{Name: core.CodecPCML, ClockRate: 16000},
},
},
},
Transport: conn,
}
if u.Query().Get("backchannel") != "1" {
cc.Medias[0].Direction = core.DirectionRecvonly
return &Producer{cc, NewAPI(conn)}, nil
return newProducer(conn), nil
} else {
cc.Medias[0].Direction = core.DirectionSendonly
return &Backchannel{cc, NewAPI(conn)}, nil
return newBackchannel(conn), nil
}
}