Update wyoming producer and backchannel
This commit is contained in:
@@ -203,5 +203,6 @@ func ProducerCodecs() []*core.Codec {
|
|||||||
{Name: core.CodecPCM, ClockRate: 8000},
|
{Name: core.CodecPCM, ClockRate: 8000},
|
||||||
{Name: core.CodecPCMA, ClockRate: 8000},
|
{Name: core.CodecPCMA, ClockRate: 8000},
|
||||||
{Name: core.CodecPCMU, ClockRate: 8000},
|
{Name: core.CodecPCMU, ClockRate: 8000},
|
||||||
|
{Name: core.CodecPCML, ClockRate: 22050}, // wyoming-snd-external
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package wyoming
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||||
@@ -13,6 +14,26 @@ type Backchannel struct {
|
|||||||
api *API
|
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) {
|
func (b *Backchannel) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver, error) {
|
||||||
return nil, core.ErrCantGetTrack
|
return nil, core.ErrCantGetTrack
|
||||||
}
|
}
|
||||||
@@ -23,7 +44,7 @@ func (b *Backchannel) AddTrack(media *core.Media, codec *core.Codec, track *core
|
|||||||
ts := time.Now().Nanosecond()
|
ts := time.Now().Nanosecond()
|
||||||
evt := &Event{
|
evt := &Event{
|
||||||
Type: "audio-chunk",
|
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,
|
Payload: pkt.Payload,
|
||||||
}
|
}
|
||||||
_ = b.api.WriteEvent(evt)
|
_ = b.api.WriteEvent(evt)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package wyoming
|
package wyoming
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
)
|
)
|
||||||
@@ -10,6 +12,26 @@ type Producer struct {
|
|||||||
api *API
|
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 {
|
func (p *Producer) Start() error {
|
||||||
var seq uint16
|
var seq uint16
|
||||||
var ts uint32
|
var ts uint32
|
||||||
|
|||||||
+2
-18
@@ -18,25 +18,9 @@ func Dial(rawURL string) (core.Producer, error) {
|
|||||||
return nil, err
|
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" {
|
if u.Query().Get("backchannel") != "1" {
|
||||||
cc.Medias[0].Direction = core.DirectionRecvonly
|
return newProducer(conn), nil
|
||||||
return &Producer{cc, NewAPI(conn)}, nil
|
|
||||||
} else {
|
} else {
|
||||||
cc.Medias[0].Direction = core.DirectionSendonly
|
return newBackchannel(conn), nil
|
||||||
return &Backchannel{cc, NewAPI(conn)}, nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user